Created
October 27, 2011 18:55
-
-
Save whit/1320472 to your computer and use it in GitHub Desktop.
Simple awesome battery widget for notebooks with SMAPI (IBM/Lenovo).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- register widget | |
batterywidget = widget({type = "textbox", name = "batterywidget", align = "right" }) | |
-- timer | |
awful.hooks.timer.register(10, function() | |
battery('BAT0') | |
end) | |
-- widget function | |
function battery(adapter) | |
spacer = " " | |
local fcur = io.open("/sys/devices/platform/smapi/"..adapter.."/remaining_percent") | |
local fsta = io.open("/sys/devices/platform/smapi/"..adapter.."/state") | |
local cur_percent = tonumber(fcur:read()) | |
local sta = fsta:read() | |
fcur:close() | |
fsta:close() | |
if sta:match("discharging") then | |
dir = "↘" | |
if cur_percent < 20 then | |
color = "orange" | |
elseif cur_percent < 7 then | |
color = "red" | |
naughty.notify({ title = "Battery Warning", | |
text = "Battery low!"..spacer..cur_percent.."%"..spacer.."left!", | |
timeout = 5, | |
position = "top_right", | |
fg = beautiful.fg_focus, | |
bg = beautiful.bg_focus | |
}) | |
end | |
elseif sta:match("charging") then | |
dir = "↗" | |
color = "green" | |
else | |
dir = "" | |
color = nil | |
end | |
widget_text = spacer..cur_percent.."%"..dir..spacer | |
if color then | |
batterywidget.text = '<span color="'..color..'">'..widget_text.."</span>" | |
else | |
batterywidget.text = widget_text | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment