2021-11-14 10:28:13 +00:00
|
|
|
local awful = require("awful")
|
|
|
|
local gears = require("gears")
|
|
|
|
local wibox = require("wibox")
|
|
|
|
local awmtk = require("awmtk")
|
|
|
|
|
|
|
|
return function(args)
|
|
|
|
local style = awmtk.style(awmtk.defaults, args.style or {},"battery_")
|
|
|
|
local device = args.device or "default"
|
2021-11-17 22:03:04 +00:00
|
|
|
local power_command = args.command or {"upower", "-d"}
|
2021-11-14 10:28:13 +00:00
|
|
|
local icon = style.icon({
|
|
|
|
{
|
|
|
|
widget = wibox.widget.imagebox,
|
2021-11-17 22:03:04 +00:00
|
|
|
image = style["battery_missing_symbolic"],
|
2021-11-14 10:28:13 +00:00
|
|
|
id = "widget_icon",
|
|
|
|
resize = true
|
|
|
|
},
|
|
|
|
(args.percentage and {
|
|
|
|
widget = wibox.widget.textbox,
|
|
|
|
markup = "0%",
|
|
|
|
id = "widget_text"
|
|
|
|
}),
|
|
|
|
layout = wibox.layout.fixed.horizontal,
|
|
|
|
spacing = style.battery_container_spacing_horizontal
|
|
|
|
})
|
|
|
|
gears.timer {
|
|
|
|
autostart = true,
|
|
|
|
timeout = 10,
|
|
|
|
call_now = true,
|
|
|
|
callback = function()
|
2021-11-17 22:03:04 +00:00
|
|
|
awful.spawn.easy_async(power_command, function(out)
|
2021-11-14 10:28:13 +00:00
|
|
|
local icon_name = out:match("icon%-name:%s+'(battery%-[^']+)'")
|
|
|
|
local value = out:match("percentage:%s+(%d+%%)")
|
|
|
|
icon:get_children_by_id("widget_icon")[1].image =
|
2022-04-15 16:46:47 +00:00
|
|
|
style[(icon_name or ""):gsub("%-","_")] or
|
2022-04-15 10:02:00 +00:00
|
|
|
style["battery_missing_symbolic"]
|
2021-11-14 10:28:13 +00:00
|
|
|
if args.percentage and value then
|
|
|
|
icon:get_children_by_id("widget_text")[1].markup = value
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
return icon
|
|
|
|
end
|