From c6089636e9bb85794814f013f9a653c0c7bc003e Mon Sep 17 00:00:00 2001 From: Pavel Makhov Date: Thu, 19 Jan 2017 17:18:53 -0500 Subject: [PATCH] Add mouse battery widget --- MouseBatteryWidget/mouse-battery.lua | 33 +++++++++++++++++++++++++++ MouseBatteryWidget/mouse-battery.png | Bin 0 -> 972 bytes README.md | 24 +++++++++++++++++-- 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 MouseBatteryWidget/mouse-battery.lua create mode 100644 MouseBatteryWidget/mouse-battery.png 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 0000000000000000000000000000000000000000..70a721ad194d9109a1b08d269f5b36859d604022 GIT binary patch literal 972 zcmV;-12g=IP)eRVSEyYI<5(Bdt1kpPxq6h+mBJdBRKgFO2{b5j)SXBQMK@<_a$jsDy zftn_6%N~ZhoHpn6zVAK#F&nkJEw!}y`|EeU=N#_moclZH_d5u#)POlzL0<0K)%iMI znoJht79oTz!*=)dHoa}_?CJ*dX0kcYG#d388HS~5HG&|&>VhE1FpQ$8z~YXNUvAW= z0{}7%dbLXBbWS$6v_c47y(o$n&BjMzL? z1dlQ8Dacj<9tH)YlP!1Zo_^sFMckHs1)1RjE246As`EkpBQq_|Gxw|vQDv{&tn8|| zU~xiZ$?C0@+Y_5Eeo$^GEMyx_ogbtiP-K->?KZSmbqw*d=0>9nO~-P+)l_%TYg|s- zXU^B;H;v5$A3sU;p`qdAq(o2d5GBSrNCpA`Anl+;91lTJMPx8zCpicJ0Ib8w;1OZy zOkg~@AvOHDt&5lxAwTW-S+qu@Ht2OyonaU+qXibq!$X4+z`)-Z02fw-E?-_zr0V7kmzM;YTDXAE=0PVu_>RS^1899uiwi*8MWI}wOW5?6ki&K zu{0|}juwJKWv-A$Fu9ClI5-m+$+^_z7oAu?RCTJJns#1VSYMxyi;d08&5`P@Z5`fH zvnu7#0Ub^DSPJDIq(*)$nx^7!pakse+2AORgYbq&r)hCr_ z&c(*Y__@DNSCqTzlPAw!`~;CjLu2>5Ua9`w;V`7@0yNK;ZrYfWz0y~2bW~J;a%Zo~T1<5; uMbo2p`>e*#OSMx}RJ17H4eqDm;<6uikFaL-G2o{F0000