Lain widgets

Lain

Some time ago I made two additional widgets for the Lain widget library used by the Awesome window manager. You could place them in ~/.config/awesome/lain/widget/, or somewhere else in your lua search path.

  1. ryzen.lua [Download]
    The original temp.lua widget seemed to work only on Intel processors, at least on my AMD Ryzen processor it was a total no-go. So I modified it to use lm_sensors for temperature information instead of /sys pseudofiles. The use of this widget is of course not restricted to AMD Ryzen processors only, and can be easily modified to read other values from lm_sensors.

    1. --[[
    2.  
    3.      System temperature widget | AMD Ryzen
    4.      Using lm_sensors instead of /sys/devices
    5.  
    6. --]]
    7.  
    8. local helpers  = require("lain.helpers")
    9. local wibox    = require("wibox")
    10. local tonumber = tonumber
    11.  
    12. -- {thermal,core} temperature info
    13. -- lain.widget.ryzen
    14.  
    15. local function factory(args)
    16.     local ryzen    = { widget = wibox.widget.textbox() }
    17.     local args     = args or {}
    18.     local dev      = args.dev or ""
    19.     local sensor   = args.sensor
    20.     local timeout  = args.timeout or 2
    21.     local settings = args.settings or function() end
    22.  
    23.     function ryzen.update()
    24.         local sensors_cmd = "/usr/bin/sensors -A " .. dev .. " | grep " .. sensor .. " | cut -c16-19"
    25. 	    helpers.async_with_shell(sensors_cmd, function(stdout, exit_code)
    26. 		coretemp_now = tonumber(stdout)
    27. 		if (exit_code ~= 0) or (coretemp_now == nil) then coretemp_now = "N/A" end
    28. 		widget = ryzen.widget
    29. 		settings()
    30.             end)
    31.     end
    32.  
    33.     helpers.newtimer("thermal", timeout, ryzen.update)
    34.  
    35.     return ryzen
    36. end
    37.  
    38. return factory

    An usage example. Please see the output of sensors for the dev and sensor values of your system.

    1. local ryzen = lain.widget.ryzen({
    2.     dev = "k10temp-pci-00c3",
    3.     sensor = "Tctl",
    4.     timeout = 10,
    5.     settings = function()
    6.         widget:set_markup(markup.fontfg(myfont, mycolor, coretemp_now .. "°C "))
    7.     end
    8. })
  2. mouse.lua [Download]
    This widget reads the battery status of a wireless mouse. It can also be used to observe any other device supported by UPower. See the output of upower --dump for the supported devices on your system.

    1. --[[
    2.  
    3.      Mouse, kbd etc. wireless HID device battery
    4.      state reading using UPower
    5.  
    6. --]]
    7.  
    8. local helpers  = require("lain.helpers")
    9. local wibox    = require("wibox")
    10. local tonumber = tonumber
    11.  
    12. -- Wireless HID device battery info
    13. -- lain.widget.mouse
    14.  
    15. local function factory(args)
    16.     local mouse    = { widget = wibox.widget.textbox() }
    17.     local args     = args or {}
    18.     local dev      = args.dev or ""
    19.     local timeout  = args.timeout or 60
    20.     local settings = args.settings or function() end
    21.  
    22.     function mouse.update()
    23.         local upower_cmd = "upower -i " .. dev .. " | grep percentage | grep -E -o '[0-9]+'"
    24. 	    helpers.async_with_shell(upower_cmd, function(stdout, exit_code)
    25. 		mousebatt = tonumber(stdout)
    26. 		if (exit_code ~= 0) or (mousebatt == nil) then mousebatt = "N/A" end
    27. 		widget = mouse.widget
    28. 		settings()
    29. 	    end)
    30.     end
    31.  
    32.     helpers.newtimer("battery", timeout, mouse.update)
    33.  
    34.     return mouse
    35. end
    36.  
    37. return factory

    An usage example for a Logitech Trackball M570

    1. local mouse = lain.widget.mouse({
    2.     dev = "/org/freedesktop/UPower/devices/mouse_hidpp_battery_0",
    3.     timeout = 3600,
    4.     settings = function()
    5.         widget:set_markup(markup.fontfg(myfont, mycolor, mousebatt .. "% "))
    6.     end
    7. })

(EDIT 18.5.2022: If this suddenly stops working, please recheck the device file path. For example, on kernel 5.17.8 the device file mouse_hidpp_battery_0 was changed to battery_hidpp_battery_0)

Posted in Linux | Tagged , , , | Comments Off on Lain widgets

Raspberry Pi 4 bluetooth madness, part 2

Well, that obsoleted quickly!

I mean the alarm-bluetooth-raspberrypi package. There’s finally a more or less native support for bluetooth in Arch ARM kernel and libraries, so there’s no need for external packages or weird configurations any more. Here’s how to take it in use:

  1. Remove alarm-bluetooth-raspberrypi and/or pi-bluetooth packages.
  2. Remove the line dtoverlay=bcmbt (if present) from /boot/config.txt and add the following line to the same file.

    dtparam=krnbt=on
  3. Make sure that enable_uart=0 is also in /boot/config.txt.
  4. In /boot/cmdline.txt, remove all references to ttyAMA0.
  5. Replace bluez-utils-compat package with standard bluez-utils, unless you really need the old utilities. The system does not need them anymore to work.
  6. Reboot.
  7. Enjoy the working bluetooth!
Posted in Linux | Tagged , , , , | Comments Off on Raspberry Pi 4 bluetooth madness, part 2

Raspberry Pi 4 bluetooth madness

There seems to be a lot of problems in getting a working bluetooth system on Raspberry Pi’s with Arch Linux, and the solutions are as numerous as the problems.

When I originally installed Arch on my RPi4, I was able to make bluetooth working by some little tweaks to pi-bluetooth AUR package – or, at least bluetooth keyboard and mouse worked. I didn’t have any bluetooth-enabled audio devices, so I couldn’t test those. That situation continued as such for some half an year until a recent big update including a 5.*.* series kernel. After a reboot, no bluetooth… and kernel and other messages saying they don’t recognize any bluetooth adapters. I still don’t know which update actually broke bluetooth then, I tried downgrading some relevant packages, with no effect.

I found a working solution via a discussion in pi-bluetooth AUR pages. Instead of pi-bluetooth, which seems to be outdated, I chose to use alarm-bluetooth-raspberrypi. Let’s start the installation process (use sudo or su where applicable):

  1. #Next step should remove bluez-utils* too, you don't really need it anymore.
  2. pacman -Rs pi-bluetooth
  3. git clone https://github.com/RoEdAl/alarm-bluetooth-raspberrypi.git
  4. cd alarm-bluetooth-raspberrypi
  5. #If you are using RPi4, you need to change "depends=*linux-raspberrypi*"
  6. #to "linux-raspberrypi4" in PKGBUILD. Otherwise, skip next step.
  7. nano PKGBUILD
  8. makepkg -sc
  9. pacman -U bluetooth-raspberrypi-6-2-any.pkg.tar.xz

Then, edit /boot/config.txt and add a line

dtoverlay=bcmbt

and reboot. That’s it!

It is also advisable to install and configure rpi-eeprom (AUR) to ensure that your EEPROM firmware is up-to-date.


UPDATE June 8th, 2020: I ended up modifying and cleaning up the original PKGBUILD to make an AUR version of alarm-bluetooth-raspberrypi. See next post.

Posted in Linux | Tagged , , , , | Comments Off on Raspberry Pi 4 bluetooth madness

Useful snippets #3: dual wallpapers on Awesome window manager

The main configuration file of Awesome wm is ~/.config/awesome/rc.lua. The default function in rc.lua on multihead systems is to install the same, maximized, theme.lua-defined wallpaper to all screens. That is all well, if a) you really want the same wallpaper on all screens, and b) if all of your screens are of the same aspect ratio. But if, for example, your main screen is 16:9 and secondary 4:3, or, like in my case, the secondary screen is in portrait mode, the default function creates a mess.

I didn’t find any example code anywhere, so I had to figure it out for myself. This is the lua code I ended up with:

  1. local function set_d_wallpaper()
  2.     themes_path = gears.filesystem.get_configuration_dir() .. "themes/dualhead/"
  3.     d_wallpaper = themes_path .. "right.jpg"
  4.     gears.wallpaper.maximized(d_wallpaper, 1, true)
  5.     d_wallpaper = themes_path .. "left.jpg"
  6.     gears.wallpaper.maximized(d_wallpaper, 2, true)
  7. end

Insert it after the original set_wallpaper(s)-function in rc.lua. After that, edit the two calls to set_wallpaper() below it to use set_d_wallpaper() instead. In my case, the secondary screen is to the left of the main screen, so adjust the above code accordingly to suit your layout.

Posted in Linux | Tagged , , , | Comments Off on Useful snippets #3: dual wallpapers on Awesome window manager

Useful snippets #2: rc.local support on systemd

Systemd-using Linuxes like Arch Linux does not generally support the old SysV init functions like rc.local. The support is easy to add, though.

Edit /usr/lib/systemd/system/rc-local.service:

  1. [Unit]
  2. Description=/etc/rc.local compatibility
  3.  
  4. [Service]
  5. Type=oneshot
  6. ExecStart=/etc/rc.local
  7. RemainAfterExit=yes
  8.  
  9. [Install]
  10. WantedBy=multi-user.target

Enable it:

systemctl enable rc-local.service

Original source: Raymii

Posted in Linux | Tagged , | Comments Off on Useful snippets #2: rc.local support on systemd