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.
This commit is contained in:
elenapan 2024-07-17 08:43:02 +03:00
parent 3013bd3992
commit 20c7a8b4c1

View file

@ -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