From 948d98be90b361a32cd85242f797e00a6860f63b Mon Sep 17 00:00:00 2001 From: Stefano Mazzucco Date: Sun, 2 Dec 2018 21:43:15 +0000 Subject: [PATCH] Prevent volume notifications from stacking Feature requested originally by p-conrad in https://github.com/stefano-m/awesome-pulseaudio_widget/pull/4 --- pulseaudio_widget.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pulseaudio_widget.lua b/pulseaudio_widget.lua index 22302c2..71eaf92 100644 --- a/pulseaudio_widget.lua +++ b/pulseaudio_widget.lua @@ -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"