Prevent volume notifications from stacking

Feature requested originally by p-conrad in
https://github.com/stefano-m/awesome-pulseaudio_widget/pull/4
This commit is contained in:
Stefano Mazzucco 2018-12-02 21:43:15 +00:00
parent fb8a6f4e5c
commit 948d98be90
1 changed files with 10 additions and 4 deletions

View File

@ -67,9 +67,15 @@ function widget:update_appearance(v)
end
function widget.notify(v)
function widget:notify(v)
local msg = tonumber(v) and string.format("%d%%", v) or v
naughty.notify({text=msg, timeout=1})
if self.notification then
naughty.destroy(self.notification, naughty.notificationClosedReason.dismissedByCommand)
end
self.notification = naughty.notify({text=msg, timeout=1})
end
function widget:update_sink(object_path)
@ -140,7 +146,7 @@ function widget:connect_device(device)
local v = math.ceil(tonumber(volume[1]) / this.BaseVolume * 100)
if this.object_path == self.sink.object_path then
self:update_appearance(v)
self.notify(v)
self:notify(v)
end
end,
"VolumeUpdated"
@ -153,7 +159,7 @@ function widget:connect_device(device)
local m = is_mute and "Muted" or "Unmuted"
if this.object_path == self.sink.object_path then
self:update_appearance(m)
self.notify(m)
self:notify(m)
end
end,
"MuteUpdated"