From 800d1cbbc0d88a36d5019a39d6d3a8c2c12dda7f Mon Sep 17 00:00:00 2001 From: zachir Date: Thu, 19 Oct 2023 17:17:58 -0500 Subject: [PATCH 1/3] Add support for multiple batteries in batteryarc. For multiple batteries, each percentage gets added into "charge", and then divided by the number of batteries. Batteries with status "Unknown" don't get counted. --- batteryarc-widget/batteryarc.lua | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/batteryarc-widget/batteryarc.lua b/batteryarc-widget/batteryarc.lua index 55a76940..1702b88b 100644 --- a/batteryarc-widget/batteryarc.lua +++ b/batteryarc-widget/batteryarc.lua @@ -88,18 +88,30 @@ local function worker(user_args) local function update_widget(widget, stdout) local charge = 0 - local status + local batteries = 0 + local status = 'Unknown' for s in stdout:gmatch("[^\r\n]+") do local cur_status, charge_str, _ = string.match(s, '.+: ([%a%s]+), (%d?%d?%d)%%,?(.*)') if cur_status ~= nil and charge_str ~=nil then local cur_charge = tonumber(charge_str) - if cur_charge > charge then - status = cur_status - charge = cur_charge + if cur_status ~= 'Unknown' then + if status == 'Charging' or cur_status == 'Charging' then + status = 'Charging' + else + status = cur_status + end + charge = charge + cur_charge + batteries = batteries + 1 end end end + if batteries > 0 then + charge = charge // batteries + else + charge = 0 + end + widget.value = charge if status == 'Charging' then From a54f4dbc4c0358291fd16454b0dad2db5358a281 Mon Sep 17 00:00:00 2001 From: zachir Date: Sat, 18 Nov 2023 14:50:59 -0600 Subject: [PATCH 2/3] mpdarc: hack fix for memory leak issues Add in reset_garbage_collector variable as a hack fix for a memory leak caused when memory is allocated for certain widgets faster than it is consumed (by triggering the garbage collector frequently). --- mpdarc-widget/mpdarc.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mpdarc-widget/mpdarc.lua b/mpdarc-widget/mpdarc.lua index f1d69308..21a51987 100644 --- a/mpdarc-widget/mpdarc.lua +++ b/mpdarc-widget/mpdarc.lua @@ -87,13 +87,20 @@ mpdarc:connect_signal("button::press", function(_, _, _, button) elseif (button == 5) then awful.spawn(PREV_MPD_CMD, false) -- scroll down end + local reset_garbage_collector = 0 spawn.easy_async(GET_MPD_CMD, function(stdout, stderr, exitreason, exitcode) update_graphic(mpdarc, stdout, stderr, exitreason, exitcode) + reset_garbage_collector = reset_garbage_collector + 1 + if (reset_garbage_collector > 10) then + collectgarbage() + reset_garbage_collector = 0 + end end) end) local notification local function show_MPD_status() + local reset_garbage_collector = 0 spawn.easy_async(GET_MPD_CMD, function(stdout, _, _, _) notification = naughty.notify { @@ -103,6 +110,11 @@ local function show_MPD_status() hover_timeout = 0.5, width = 600, } + reset_garbage_collector = reset_garbage_collector + 1 + if (reset_garbage_collector > 10) then + collectgarbage() + reset_garbage_collector = 0 + end end) end From f452e3ce0b02ef6f4b4ca514dd225fd39727b17b Mon Sep 17 00:00:00 2001 From: zachir Date: Sat, 18 Nov 2023 14:53:21 -0600 Subject: [PATCH 3/3] mpdarc: use theme font Default to beautiful.font, and use 'Play 9' as a backup. --- mpdarc-widget/mpdarc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mpdarc-widget/mpdarc.lua b/mpdarc-widget/mpdarc.lua index 21a51987..d643725f 100644 --- a/mpdarc-widget/mpdarc.lua +++ b/mpdarc-widget/mpdarc.lua @@ -50,7 +50,7 @@ local mpdarc_icon_widget = wibox.container.mirror(mpdarc, { horizontal = true }) local mpdarc_current_song_widget = wibox.widget { id = 'current_song', widget = wibox.widget.textbox, - font = 'Play 9' + font = beautiful.font or 'Play 9' } local update_graphic = function(widget, stdout, _, _, _)