diff options
author | Peter Palfrader <peter@palfrader.org> | 2016-12-16 22:01:26 +0100 |
---|---|---|
committer | Peter Palfrader <peter@palfrader.org> | 2016-12-19 08:50:01 +0100 |
commit | c1e6f7f09b37e4ece220822887ad80cd6055dfbd (patch) | |
tree | 58e56f334292ef3fe86a2fea7d58472e4e7f97ac /config/awesome/battery.lua | |
parent | 5fff79f1ed33f6d185bdc1b73fbdb0d2c68d4ff7 (diff) |
add a battery widget
Diffstat (limited to 'config/awesome/battery.lua')
-rw-r--r-- | config/awesome/battery.lua | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/config/awesome/battery.lua b/config/awesome/battery.lua new file mode 100644 index 0000000..988f9fa --- /dev/null +++ b/config/awesome/battery.lua @@ -0,0 +1,53 @@ +function batteryInfoUpdate(adapter, warn, widget) + spacer = " " + local fcap = io.open("/sys/class/power_supply/"..adapter.."/capacity") + local fsta = io.open("/sys/class/power_supply/"..adapter.."/status") + local cap = fcap:read() + local sta = fsta:read() + fcap:close() + fsta:close() + + if sta:match("Charging") then + state = 1 + icon = "▴" + else + state = -1 + icon = "▾" + end + + if tonumber(cap) < 10 and warn then + naughty.notify({ title = "Battery Warning", + text = "Battery "..adapter.." low at "..cap.."%!", + timeout = 15, + position = "top_right", + fg = beautiful.fg_focus, + bg = beautiful.bg_focus, + }) + end + if tonumber(cap) < 10 then + color='red' + elseif tonumber(cap) < 25 then + color='orange' + else + color='green' + end + + widget:set_markup(spacer.."<span color='"..color.."'>"..icon..cap..'%</span>'..spacer) +end + +local wibox = require("wibox") + +bat0_widget = wibox.widget.textbox() +bat0_widget:set_align("right") + +bat1_widget = wibox.widget.textbox() +bat1_widget:set_align("right") + +battery_timer = timer({timeout = 20}) +battery_timer:connect_signal("timeout", function() + batteryInfoUpdate("BAT0", true, bat0_widget) + batteryInfoUpdate("BAT1", false, bat1_widget) +end) +battery_timer:start() + +-- vim:set softtabstop=4:ts=4:shiftwidth=4:et=1: |