update API to match awesome-fswidget

This commit is contained in:
Izaya 2022-09-12 00:44:30 +10:00
parent 897cce3241
commit 23a1252011

View File

@ -62,7 +62,7 @@ local function getBatteryState(path)
percent = tonumber(f:read("*a"):match("%S+"))
f:close()
end
return state, percent
return state, tonumber(percent)
end
function batterystat.scan()
@ -78,15 +78,21 @@ function batterystat.scan()
end
end
local function bwidgetUpdate(self)
self:reset()
for k,v in pairs(batterystat.batteries) do
local name = v:match("/([^/]+)/$")
local state, percent = getBatteryState(v)
local function updateBatteryWidget(self)
local state, percent = getBatteryState(self.path)
local colour = (state == "Charging") and "lime" or "red"
local sbwidget = (wibox.widget{
self:set(1,icons[chooseIcon(state, percent)])
self.children[3].markup = string.format('<span foreground="%s" size="x-large">%d%%</span>',colour,percent)
end
function batterystat.new(path)
local state, percent = getBatteryState(path)
local name = path:match("/([^/]+)/$")
local sbwidget = wibox.widget{
layout = wibox.layout.stack,
forced_width = batterystat.iconSize,
path = path,
update = updateBatteryWidget,
icons[chooseIcon(state,percent)],
wibox.widget{
widget = wibox.widget.textbox,
@ -98,20 +104,19 @@ local function bwidgetUpdate(self)
widget = wibox.widget.textbox,
align = "right",
valign = "bottom",
markup = string.format('<span foreground="%s" size="x-large">%d%%</span>',colour,percent)
}
})
self:add(sbwidget)
end
}
sbwidget:update()
return sbwidget
end
function batterystat.new()
local bwidget = wibox.widget{
layout = wibox.layout.grid.horizontal,
update = bwidgetUpdate
}
function batterystat.all()
local rt = {}
batterystat.scan()
return bwidget
for k,v in pairs(batterystat.batteries) do
rt[#rt+1] = batterystat.new(v)
end
return rt
end
return batterystat