changed battery widget

master
mark 2023-08-26 18:05:21 -07:00
parent 7a34cbe48d
commit 003aa55726
1 changed files with 26 additions and 104 deletions

View File

@ -1,5 +1,6 @@
local battery = req_rel(..., "util") local battery = req_rel(..., "util")
local widget = {} local widget = {}
local dotgrid = require("widgets.dotgrid")
-- Percentages to warn at -- Percentages to warn at
-- (must be in order least -> greatest) -- (must be in order least -> greatest)
@ -13,76 +14,25 @@ for i=1, #widget.warnings do
widget.warninglog[i] = false widget.warninglog[i] = false
end end
widget.image_path = beautiful.icons.battery.missing
widget.icon = wibox.widget {
image = beautiful.icons.battery.missing,
resize = true,
widget = wibox.widget.imagebox,
}
widget.progressbar = wibox.widget {
max_value = 100,
widget = wibox.widget.progressbar,
paddings = beautiful.dpi(2),
color = beautiful.color.bar.active,
background_color = beautiful.color.transparent,
border_color = beautiful.color.bar.active,
border_width = beautiful.dpi(1),
margins = beautiful.dpi(3)
}
widget.arc = wibox.widget {
{
widget.icon,
top = beautiful.dpi(1),
bottom = beautiful.dpi(1),
layout = wibox.container.margin,
},
max_value = 100,
thickness = beautiful.dpi(4),
start_angle = 4.71238898, -- 2pi*3/4
--forced_height = beautiful.dpi(16),
--forced_width = beautiful.dpi(16),
colors = {"#27D4CC", "#00446B"},
bg = "#FFFFFF30",
paddings = beautiful.dpi(2),
widget = wibox.container.arcchart
}
widget.rotator = wibox.widget {
widget.progressbar,
forced_width = beautiful.dpi(15),
direction = "east",
layout = wibox.container.rotate,
}
widget.dots = dotgrid:new();
widget.dots.on_color = {1, 0, 0}
widget.dots.off_color = {0.5, 0, 0}
widget.dots.spacing = beautiful.dpi(2)
widget.widget = wibox.widget { widget.widget = wibox.widget {
{ {
{ -- Right space widget.dots,
widget = wibox.widget.separator,
color = beautiful.color.transparent,
forced_width = beautiful.dpi(3)
},
{
widget.arc,
top = beautiful.dpi(2), top = beautiful.dpi(2),
bottom = beautiful.dpi(2), bottom = beautiful.dpi(2),
left = beautiful.dpi(2),
right = beautiful.dpi(2),
layout = wibox.container.margin, layout = wibox.container.margin,
}, },
{ -- Left space
widget = wibox.widget.separator,
color = beautiful.color.transparent,
forced_width = beautiful.dpi(3)
},
layout = wibox.layout.align.horizontal,
},
layout = wibox.container.background, layout = wibox.container.background,
} }
widget.widget:connect_signal("mouse::enter", function(result) widget.widget:connect_signal("mouse::enter", function(result)
widget.widget.bg = beautiful.color.bar.hover_bg widget.widget.bg = beautiful.color.bar.hover_bg
end) end)
@ -126,49 +76,17 @@ widget.update = function(stdout)
end end
end end
widget.dots.value = batpec
widget.progressbar.value = batpec
widget.arc.value = batpec
if batpec > 60 then
widget.progressbar.color = beautiful.color.battery.good
elseif batpec > 40 then
widget.progressbar.color = beautiful.color.battery.low
elseif batpec <= 40 then
widget.progressbar.color = beautiful.color.battery.danger
end
widget.image_path = beautiful.icons.battery.missing
-- Set current battery icon
if (not discharging) then
if batpec > 80 then widget.image_path = beautiful.icons.battery.charging.full
elseif batpec > 60 then widget.image_path = beautiful.icons.battery.charging.good
elseif batpec > 40 then widget.image_path = beautiful.icons.battery.charging.low
elseif batpec > 20 then widget.image_path = beautiful.icons.battery.charging.caution
elseif batpec <= 20 then widget.image_path = beautiful.icons.battery.charging.empty end
else
if batpec > 80 then widget.image_path = beautiful.icons.battery.full
elseif batpec > 60 then widget.image_path = beautiful.icons.battery.good
elseif batpec > 40 then widget.image_path = beautiful.icons.battery.low
elseif batpec > 20 then widget.image_path = beautiful.icons.battery.caution
elseif batpec <= 20 then widget.image_path = beautiful.icons.battery.empty end
end
widget.icon.image = widget.image_path
if (not discharging) and (batpec > 90) then
widget.progressbar.border_color = beautiful.color.battery.good
elseif (discharging) and (batpec <= 25) then
widget.progressbar.border_color = beautiful.color.battery.danger
else
widget.progressbar.border_color = beautiful.color.bar.active
end
if discharging then if discharging then
widget.rotator.direction = "east" widget.dots.on_color = {1, 0, 0}
widget.dots.off_color = {0.5, 0, 0}
else else
widget.rotator.direction = "west" widget.dots.on_color = {1, 1, 0}
widget.dots.off_color = {0.5, 0.5, 0}
end end
widget.dots:emit_signal("widget::redraw_needed")
end end
widget.readupdate = function() widget.readupdate = function()
@ -185,8 +103,12 @@ widget.widget:connect_signal("button::press",
if (button == 1) then if (button == 1) then
battery.status( battery.status(
function(stdout, stderr, exitreason, exitcode) function(stdout, stderr, exitreason, exitcode)
local batpec = string.match(stdout, "(%d?%d?%d)%%") -- (\d?\d?\d)\%) local batpec = string.match(stdout, "(%d?%d?%d)%%")
local batstat = string.match(stdout, "discharging") or false batpec = tonumber(string.format("% 3d", batpec))
local batstat = string.match(stdout, "Discharging") or false
debug_message(batpec)
if batstat then if batstat then
batstat = "Discharging, " batstat = "Discharging, "
@ -211,7 +133,7 @@ widget.widget:connect_signal("button::press",
) )
battery.watch( battery.watch(
10, 2,
function(_, stdout) function(_, stdout)
widget.update(stdout) widget.update(stdout)
end, end,