From bec4de5fabd35863c756d86e8abb569e97251418 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Thu, 11 Jul 2019 00:45:55 -0400 Subject: [PATCH] naughty: Auto-reset the timeout when notifications are modified. This is configurable globally or per-notification. When it is replaced over dbus, it has a new timeout and *that* should be the new timeout (starting when the notification is replaced). Closes #2821 --- lib/naughty/core.lua | 11 ++++++++++- lib/naughty/dbus.lua | 3 +++ lib/naughty/notification.lua | 21 ++++++++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/naughty/core.lua b/lib/naughty/core.lua index 266db95ee..4985ade5e 100644 --- a/lib/naughty/core.lua +++ b/lib/naughty/core.lua @@ -126,9 +126,18 @@ gtable.crush(naughty, require("naughty.constants")) -- @property has_display_handler -- @param boolean +--- If the timeout needs to be reset when a property changes. +-- +-- This is the global variant of the `naughty.notification` `auto_reset_timeout` +-- property. +-- +-- @property auto_reset_timeout +-- @tparam[opt=true] boolean auto_reset_timeout + local properties = { suspended = false, - expiration_paused = false + expiration_paused = false, + auto_reset_timeout= true, } --TODO v5 Deprecate the public `naughty.notifications` (to make it private) diff --git a/lib/naughty/dbus.lua b/lib/naughty/dbus.lua index 20dc0d50e..6672de971 100644 --- a/lib/naughty/dbus.lua +++ b/lib/naughty/dbus.lua @@ -236,6 +236,9 @@ function notif_methods.Notify(sender, object_path, interface, method, parameters if k == "destroy" then k = "destroy_cb" end notification[k] = v end + + -- Even if no property changed, restart the timeout. + notification:reset_timeout() else notification = nnotif(args) end diff --git a/lib/naughty/notification.lua b/lib/naughty/notification.lua index 3b0da1f4d..5ad11de6f 100644 --- a/lib/naughty/notification.lua +++ b/lib/naughty/notification.lua @@ -267,6 +267,14 @@ local notification = {} -- @param boolean -- @see naughty.expiration_paused +--- If the timeout needs to be reset when a property changes. +-- +-- By default it fallsback to `naughty.auto_reset_timeout`, which itself is +-- true by default. +-- +-- @property auto_reset_timeout +-- @tparam[opt=true] boolean auto_reset_timeout + --- Emitted when the notification is destroyed. -- @signal destroyed -- @tparam number reason Why it was destroyed @@ -391,7 +399,7 @@ local properties = { "fg" , "bg" , "height" , "border_color" , "shape" , "opacity" , "margin" , "ignore_suspend", "destroy" , "preset" , "callback", "actions" , - "run" , "id" , "ignore", + "run" , "id" , "ignore" , "auto_reset_timeout" } for _, prop in ipairs(properties) do @@ -408,6 +416,17 @@ for _, prop in ipairs(properties) do notification["set_"..prop] = notification["set_"..prop] or function(self, value) self._private[prop] = value self:emit_signal("property::"..prop, value) + + -- When a notification is updated over dbus or by setting a property, + -- it is usually convenient to reset the timeout. + local reset = ((not self.suspended) + and self.auto_reset_timeout ~= false + and naughty.auto_reset_timeout) + + if reset then + self:reset_timeout() + end + return end