This is a small lua function that returns a formatted string with the current battery status. It can be used to populate a text widget in the awesome window manager. Based on the "Gigamo Battery Widget" found in the wiki at awesome.naquadah.org
Place the battery.lua
file in the same directory as your main config file (e.g. rc.lua
), and require it:
awesome < 3.5
require("battery")
awesome >= 3.5
local battery = require("battery")
awesome < 3.5
batterywidget = widget({type = "textbox", name = "batterywidget", align = "right" })
(...)
mytextclock,
batterywidget,
s == 1 and mysystray or nil,
(...)
awesome >= 3.5
batterywidget = wibox.widget.textbox()
(...)
local right_layout = wibox.layout.fixed.horizontal()
right_layout:add(batterywidget)
if s == 1 then right_layout:add(wibox.widget.systray()) end
(...)
awesome < 3.5
awful.hooks.timer.register(60, function()
batterywidget.text = batteryInfo("BAT0")
end)
awesome >= 3.5
batterywidget_timer = timer({timeout = 1})
batterywidget_timer:connect_signal("timeout", function()
batterywidget:set_text(batteryInfo("BAT0"))
end)
batterywidget_timer:start()
If you don't want to wait for the battery status to appear until the function gets called by the hook, add the following somewhere after the declaration of the batterywidget.
awesome < 3.5
batterywidget.text = batteryInfo("BAT0")
awesome >= 3.5
batterywidget:set_text(batteryInfo("BAT0"))