summaryrefslogtreecommitdiff
path: root/MouseBatteryWidget
diff options
context:
space:
mode:
authorPavel Makhov <pavel.makhov@savoirfairelinux.com>2017-01-19 17:18:53 -0500
committerPavel Makhov <pavel.makhov@savoirfairelinux.com>2017-01-19 17:18:53 -0500
commitc6089636e9bb85794814f013f9a653c0c7bc003e (patch)
tree1ede7e0333641d6725e5782840c732b1f6270c96 /MouseBatteryWidget
parent8c3395a4f6958adefa0e4b5fdc57e6eccd204f2d (diff)
Add mouse battery widget
Diffstat (limited to 'MouseBatteryWidget')
-rw-r--r--MouseBatteryWidget/mouse-battery.lua33
-rw-r--r--MouseBatteryWidget/mouse-battery.pngbin0 -> 972 bytes
2 files changed, 33 insertions, 0 deletions
diff --git a/MouseBatteryWidget/mouse-battery.lua b/MouseBatteryWidget/mouse-battery.lua
new file mode 100644
index 0000000..7b3fd4c
--- /dev/null
+++ b/MouseBatteryWidget/mouse-battery.lua
@@ -0,0 +1,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")
diff --git a/MouseBatteryWidget/mouse-battery.png b/MouseBatteryWidget/mouse-battery.png
new file mode 100644
index 0000000..70a721a
--- /dev/null
+++ b/MouseBatteryWidget/mouse-battery.png
Binary files differ