summaryrefslogtreecommitdiff
path: root/MouseBatteryWidget/mouse-battery.lua
blob: 7b3fd4c38050cf3bece03c14254169d39a5b8481 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
local wibox = require("wibox")
local awful = require("awful")

-- text widget
mouse_widget = wibox.widget.textbox()
mouse_widget:set_font('Play 9')

function update_mouse_widget(widget)
 local current = awful.util.pread(
   "upower -i /org/freedesktop/UPower/devices/mouse_0003o046Do101Ax0006 " ..
   "| grep percentage | grep -E -o '[0-9]+'")
  widget:set_text(current)
end

mouse_timer = timer({ timeout = 3600 })
mouse_timer:connect_signal("timeout", function () update_mouse_widget(mouse_widget) end)
mouse_timer:start()
mouse_timer:emit_signal("timeout")

-- icon widget
mouse_battery_icon = wibox.widget.imagebox()

function update_mouse_battery_icon(icon)
    local iconName = awful.util.pread("upower -i /org/freedesktop/UPower/devices/mouse_0003o046Do101Ax0006 " ..
    "| grep icon-name | grep -oP \"(?<=').*(?=')\"")
    icon:set_image("/usr/share/icons/gnome/scalable/status/" .. string.gsub(iconName, "\n", "") .. ".svg")
end

mouse_battery_timer = timer({ timeout = 60 })
mouse_battery_timer:connect_signal("timeout",  function() update_mouse_battery_icon(mouse_battery_icon) end)
mouse_battery_timer:start()

mouse_battery_timer:emit_signal("timeout")