update API to match awesome-fswidget
This commit is contained in:
parent
897cce3241
commit
23a1252011
39
init.lua
39
init.lua
@ -62,7 +62,7 @@ local function getBatteryState(path)
|
|||||||
percent = tonumber(f:read("*a"):match("%S+"))
|
percent = tonumber(f:read("*a"):match("%S+"))
|
||||||
f:close()
|
f:close()
|
||||||
end
|
end
|
||||||
return state, percent
|
return state, tonumber(percent)
|
||||||
end
|
end
|
||||||
|
|
||||||
function batterystat.scan()
|
function batterystat.scan()
|
||||||
@ -78,15 +78,21 @@ function batterystat.scan()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function bwidgetUpdate(self)
|
local function updateBatteryWidget(self)
|
||||||
self:reset()
|
local state, percent = getBatteryState(self.path)
|
||||||
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 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,
|
layout = wibox.layout.stack,
|
||||||
forced_width = batterystat.iconSize,
|
forced_width = batterystat.iconSize,
|
||||||
|
path = path,
|
||||||
|
update = updateBatteryWidget,
|
||||||
icons[chooseIcon(state,percent)],
|
icons[chooseIcon(state,percent)],
|
||||||
wibox.widget{
|
wibox.widget{
|
||||||
widget = wibox.widget.textbox,
|
widget = wibox.widget.textbox,
|
||||||
@ -98,20 +104,19 @@ local function bwidgetUpdate(self)
|
|||||||
widget = wibox.widget.textbox,
|
widget = wibox.widget.textbox,
|
||||||
align = "right",
|
align = "right",
|
||||||
valign = "bottom",
|
valign = "bottom",
|
||||||
markup = string.format('<span foreground="%s" size="x-large">%d%%</span>',colour,percent)
|
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
self:add(sbwidget)
|
sbwidget:update()
|
||||||
end
|
return sbwidget
|
||||||
end
|
end
|
||||||
|
|
||||||
function batterystat.new()
|
function batterystat.all()
|
||||||
local bwidget = wibox.widget{
|
local rt = {}
|
||||||
layout = wibox.layout.grid.horizontal,
|
|
||||||
update = bwidgetUpdate
|
|
||||||
}
|
|
||||||
batterystat.scan()
|
batterystat.scan()
|
||||||
return bwidget
|
for k,v in pairs(batterystat.batteries) do
|
||||||
|
rt[#rt+1] = batterystat.new(v)
|
||||||
|
end
|
||||||
|
return rt
|
||||||
end
|
end
|
||||||
|
|
||||||
return batterystat
|
return batterystat
|
||||||
|
Loading…
Reference in New Issue
Block a user