From c1e6f7f09b37e4ece220822887ad80cd6055dfbd Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Fri, 16 Dec 2016 22:01:26 +0100 Subject: add a battery widget --- config/awesome/battery.lua | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 config/awesome/battery.lua (limited to 'config/awesome/battery.lua') 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..""..icon..cap..'%'..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: -- cgit v1.2.3