Created
September 25, 2013 19:32
-
-
Save yfyf/6704830 to your computer and use it in GitHub Desktop.
awesomewm battery widget with colour reflecting the remaining battery life and a notification for low battery
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
-- Tooltip comes from: https://github.com/liliff/web/blob/master/_posts/2012-04-05-first-dive-into-lua-battery-widget.md | |
function rgbToHex(r, g, b) | |
return string.format("#%0.2X%0.2X%0.2X", r, g, b) | |
end | |
function chargeToColour(charge) | |
local unit = 255 / 100 | |
local amount = math.floor(unit * charge) | |
return rgbToHex(255 - amount, amount, 25) | |
end | |
-- {{{ Battery status | |
batwidget = awful.widget.progressbar() | |
batwidget:set_width(10) | |
batwidget:set_height(10) | |
batwidget:set_vertical(true) | |
batwidget:set_background_color('#494B4F') | |
batwidget_t = awful.tooltip({ objects = { batwidget },}) | |
vicious.register(batwidget, vicious.widgets.bat, function (widget, args) | |
batwidget_t:set_text( | |
"State: " .. args[1] .. " | " .. | |
"Charge: " .. args[2] .. "% | " .. | |
"Remaining: " .. args[3] | |
) | |
local charge = args[2] | |
local colour = chargeToColour(charge) | |
batwidget:set_color(colour) | |
if charge <= 5 then | |
naughty.notify({ text="Battery is low! " | |
.. charge .." percent remaining." }) | |
end | |
return charge | |
end , 60, "BAT0") | |
-- }}} |
OK, found the docs (doh google). Nevermind.
Thanks for the rgb.hex :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This looks like an awesome widget.
However, in my
rc.lua
I cannot seevicious
defined. Can you show how that variable is defined in your setup?