Last active
December 19, 2015 00:18
-
-
Save chiangbing/5867414 to your computer and use it in GitHub Desktop.
a battery widget for awesome wm.
This file contains 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
-- {{{ Battery bar | |
mybatterybar = awful.widget.progressbar() | |
mybatterybar:set_border_color(theme.border_normal) | |
mybatterybar:set_background_color(theme.bg_normal) | |
mybatterybar:set_color(theme.bg_focus) | |
mybatterybar:set_width(50) | |
mytimer = timer({ timeout = 30 }) | |
mytimer:connect_signal("timeout", function() | |
f = io.popen('acpi -b', r) | |
state, percent = string.match(f:read(), 'Battery %d: (%w+), (%d+)%%') | |
f:close() | |
percent = tonumber(percent)/100 | |
if state == 'Discharging' then | |
mybatterybar:set_color('#CCCC00') | |
if percent < 0.2 then | |
mybatterybar:set_color(theme.bg_urgent) | |
end | |
elseif state == 'Charging' then | |
mybatterybar:set_color('#66CC00') | |
else | |
mybatterybar:set_color(theme.bg_focus) | |
end | |
mybatterybar:set_value(percent) | |
end) | |
mytimer:start() | |
mytimer:emit_signal("timeout") | |
-- }}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment