summaryrefslogtreecommitdiff
path: root/config/awesome/battery.lua
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2016-12-17 17:48:35 +0100
committerPeter Palfrader <peter@palfrader.org>2016-12-19 08:50:01 +0100
commitb767be3ffd3e858c54951a67eacd5b5eadf8c7c6 (patch)
treea1644d459481e4b75395cd068c37eb20f01e3aeb /config/awesome/battery.lua
parentc1e6f7f09b37e4ece220822887ad80cd6055dfbd (diff)
updates
Diffstat (limited to 'config/awesome/battery.lua')
-rw-r--r--config/awesome/battery.lua43
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)