update API to match awesome-fswidget
This commit is contained in:
parent
897cce3241
commit
23a1252011
67
init.lua
67
init.lua
@ -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,40 +78,45 @@ 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 colour = (state == "Charging") and "lime" or "red"
|
||||
local sbwidget = (wibox.widget{
|
||||
layout = wibox.layout.stack,
|
||||
forced_width = batterystat.iconSize,
|
||||
icons[chooseIcon(state,percent)],
|
||||
wibox.widget{
|
||||
widget = wibox.widget.textbox,
|
||||
align = "center",
|
||||
valign = "top",
|
||||
text = name
|
||||
},
|
||||
wibox.widget{
|
||||
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
|
||||
local function updateBatteryWidget(self)
|
||||
local state, percent = getBatteryState(self.path)
|
||||
local colour = (state == "Charging") and "lime" or "red"
|
||||
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()
|
||||
local bwidget = wibox.widget{
|
||||
layout = wibox.layout.grid.horizontal,
|
||||
update = bwidgetUpdate
|
||||
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,
|
||||
align = "center",
|
||||
valign = "top",
|
||||
text = name
|
||||
},
|
||||
wibox.widget{
|
||||
widget = wibox.widget.textbox,
|
||||
align = "right",
|
||||
valign = "bottom",
|
||||
}
|
||||
}
|
||||
sbwidget:update()
|
||||
return sbwidget
|
||||
end
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user