From 20c7a8b4c15d32ac9cc369340e5850732847a4f4 Mon Sep 17 00:00:00 2001 From: elenapan Date: Wed, 17 Jul 2024 08:43:02 +0300 Subject: [PATCH] battery: Only send charger update when status changes On some laptops, `acpi_listen` sometimes prints charger updates even if there was no change. This commit ensures that no unneeded updates will be sent with the `evil::charger` signal. --- config/awesome/evil/battery.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/config/awesome/evil/battery.lua b/config/awesome/evil/battery.lua index f7f8a17..2cf7775 100644 --- a/config/awesome/evil/battery.lua +++ b/config/awesome/evil/battery.lua @@ -29,6 +29,7 @@ awful.spawn.easy_async_with_shell("sh -c 'out=\"$(find /sys/class/power_supply/B end) end) +local status_old = -1 -- First get charger file path awful.spawn.easy_async_with_shell("sh -c 'out=\"$(find /sys/class/power_supply/*/online)\" && (echo \"$out\" | head -1) || false' ", function (charger_file, _, __, exit_code) -- No charger file found @@ -39,7 +40,10 @@ awful.spawn.easy_async_with_shell("sh -c 'out=\"$(find /sys/class/power_supply/* local emit_charger_info = function() awful.spawn.easy_async_with_shell("cat "..charger_file, function (out) local status = tonumber(out) == 1 - awesome.emit_signal("evil::charger", status) + if not (status == status_old) then + awesome.emit_signal("evil::charger", status) + status_old = status + end end) end