Skip to content

Instantly share code, notes, and snippets.

@chiangbing
Last active December 19, 2015 00:18
Show Gist options
  • Save chiangbing/5867414 to your computer and use it in GitHub Desktop.
Save chiangbing/5867414 to your computer and use it in GitHub Desktop.
a battery widget for awesome wm.
-- {{{ 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