From 1c3b5c784f258f842a8f5ddc8eb6e50a544b5aff Mon Sep 17 00:00:00 2001 From: Reiner Herrmann Date: Mon, 21 Nov 2016 02:36:54 +0100 Subject: awesome: highlight battery widget with urgent color if state drops below 10% --- awesome/rc.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'awesome/rc.lua') diff --git a/awesome/rc.lua b/awesome/rc.lua index f43a08c..a2d032d 100644 --- a/awesome/rc.lua +++ b/awesome/rc.lua @@ -128,7 +128,9 @@ for bat = 0, 1 do local batexists = io.open(batpath) if batexists~=nil then io.close(batexists) - batwidget = wibox.widget.textbox() + batwidget_text = wibox.widget.textbox() + batwidget = wibox.widget.background() + batwidget:set_widget(batwidget_text) function batstate() local fcur = io.open(batpath .. '/charge_now') if not fcur then fcur = io.open(batpath .. '/energy_now') end @@ -152,10 +154,17 @@ for bat = 0, 1 do elseif ac:match("0") then acwidget.visible = false end + local battery = math.floor(cur*100/full) + if battery < 10 then + batwidget:set_bg(beautiful.bg_urgent) + else + batwidget:set_bg(beautiful.bg_normal) + end + return {battery} end - vicious.register(batwidget, batstate, ' Bat:$1% ', 60) + vicious.register(batwidget_text, batstate, ' Bat:$1% ', 60) end end -- cgit v1.2.3