diff options
Diffstat (limited to 'config/awesome/battery.lua')
-rw-r--r-- | config/awesome/battery.lua | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/config/awesome/battery.lua b/config/awesome/battery.lua index 988f9fa..a76ce29 100644 --- a/config/awesome/battery.lua +++ b/config/awesome/battery.lua @@ -1,3 +1,6 @@ +local naughty = require("naughty") +local beautiful = require("beautiful") + function batteryInfoUpdate(adapter, warn, widget) spacer = " " local fcap = io.open("/sys/class/power_supply/"..adapter.."/capacity") @@ -8,31 +11,44 @@ function batteryInfoUpdate(adapter, warn, widget) fsta:close() if sta:match("Charging") then - state = 1 icon = "▴" - else - state = -1 + elseif sta:match("Discharging") then icon = "▾" + else + icon = "‐" end if tonumber(cap) < 10 and warn then + local bg = beautiful.bg_focus + local fg = beautiful.fg_focus + if tonumber(cap) <= 5 then + bg = beautiful.bg_urgent + fg = beautiful.fg_urgent + end + naughty.notify({ title = "Battery Warning", text = "Battery "..adapter.." low at "..cap.."%!", timeout = 15, position = "top_right", - fg = beautiful.fg_focus, - bg = beautiful.bg_focus, + fg = fg, + bg = bg }) end - if tonumber(cap) < 10 then - color='red' - elseif tonumber(cap) < 25 then - color='orange' - else - color='green' + local color=nil + if warn then + if tonumber(cap) < 10 then + color='red' + elseif tonumber(cap) < 20 then + color='orange' + end + end + + local s = cap..'%'..icon + if color then + s = "<span color='"..color.."'>"..s..'</span>' end - widget:set_markup(spacer.."<span color='"..color.."'>"..icon..cap..'%</span>'..spacer) + widget:set_markup(spacer..s..spacer) end local wibox = require("wibox") @@ -43,6 +59,9 @@ bat0_widget:set_align("right") bat1_widget = wibox.widget.textbox() bat1_widget:set_align("right") +batteryInfoUpdate("BAT0", true, bat0_widget) +batteryInfoUpdate("BAT1", false, bat1_widget) + battery_timer = timer({timeout = 20}) battery_timer:connect_signal("timeout", function() batteryInfoUpdate("BAT0", true, bat0_widget) |