This repository has been archived on 2021-04-06. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/home/.config/awesome/battery.lua
2018-10-10 15:30:17 +00:00

40 lines
916 B
Lua

local timer = require("gears.timer")
local wibox = require("wibox")
local function readfile(command)
local file = io.open(command)
if not file then return nil end
local text = file:read('*all')
file:close()
return text:gsub("^%s*(.-)%s*$", "%1")
end
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 = readfile("/sys/class/power_supply/BAT1/capacity")
local status = 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)