33 lines
756 B
Lua
33 lines
756 B
Lua
local timer = require("gears.timer")
|
|
local wibox = require("wibox")
|
|
local utils = require("utils")
|
|
|
|
local battery_widget = wibox.widget{
|
|
markup = 'U00',
|
|
align = 'center',
|
|
widget = wibox.widget.textbox
|
|
}
|
|
|
|
timer = timer({ timeout = 10 })
|
|
timer:connect_signal("timeout", function() update() end)
|
|
timer:start()
|
|
|
|
function update()
|
|
local percent = utils.readfile("/sys/class/power_supply/BAT1/capacity")
|
|
local status = utils.readfile("/sys/class/power_supply/BAT1/status")
|
|
|
|
if status == "Charging" then
|
|
prefix = "C"
|
|
elseif status == "Discharging" then
|
|
prefix = "D"
|
|
else
|
|
prefix = "F"
|
|
end
|
|
|
|
battery_widget:set_markup(prefix .. percent)
|
|
end
|
|
|
|
update()
|
|
|
|
return wibox.container.margin(battery_widget, 4)
|