summaryrefslogtreecommitdiff
path: root/awesome
diff options
context:
space:
mode:
authorReiner Herrmann <reiner@reiner-h.de>2017-09-10 14:23:06 +0200
committerReiner Herrmann <reiner@reiner-h.de>2017-09-10 14:23:06 +0200
commit588e21b063279ce8ab8f255d3d6aff4ff1e129c5 (patch)
treefe5b68201b031288d701e6feae24a61f5b3e5805 /awesome
parentc63aa74f6e5a989e0441024869c2918dde3325ea (diff)
awesome: simplify battery widget
Diffstat (limited to 'awesome')
-rw-r--r--awesome/rc.lua49
1 files changed, 9 insertions, 40 deletions
diff --git a/awesome/rc.lua b/awesome/rc.lua
index 641ed84..c875777 100644
--- a/awesome/rc.lua
+++ b/awesome/rc.lua
@@ -127,51 +127,20 @@ acwidget = wibox.widget.imagebox()
acwidget:set_image(awful.util.getdir("config") .. "/power-ac.png")
acwidget.visible = false
-for bat = 0, 1 do
- local batpath = '/sys/class/power_supply/BAT' .. bat
- local batexists = io.open(batpath)
- if batexists~=nil then
- io.close(batexists)
- batwidget_text = wibox.widget.textbox()
- batwidget = wibox.container.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
-
- local ffull = io.open(batpath .. '/charge_full')
- if not ffull then ffull = io.open(batpath .. '/energy_full') end
-
- local acstate = io.open('/sys/class/power_supply/AC0/online')
- if not acstate then acstate = io.open('/sys/class/power_supply/ACAD/online') end
- if not acstate then acstate = io.open('/sys/class/power_supply/AC/online') end
-
- local cur = fcur:read()
- local full = ffull:read()
- local ac = acstate:read()
- fcur:close()
- ffull:close()
- acstate:close()
-
- if ac:match("1") then
- acwidget.visible = true
- 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
+function bat_string(widget, state)
+ local charge = ' Bat:' .. state[2] .. '% '
- return {battery}
- end
- vicious.register(batwidget_text, batstate, ' Bat:$1% ', 60)
+ if state[2] < 10 then
+ charge = '<span background="' .. beautiful.bg_urgent .. '">' .. charge .. '</span>'
end
+
+ return charge
end
+batwidget = wibox.widget.textbox()
+vicious.register(batwidget, vicious.widgets.bat, bat_string, 60, "BAT0")
+
function cpu_string(widget, loads)
local result = " CPU:" .. loads[2] .. "%"
for cpu = 3, #loads do