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)

This entry was posted in Linux and tagged , , , . Bookmark the permalink.