From 11ef560c5c5025463c7870851b4cebf6ff1ae52f Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Thu, 11 Jul 2019 00:06:24 -0400 Subject: [PATCH 1/2] naughty: Un-document naughty.notification.replaces_id. It doesn't and cannot exists within `naughty.notification()` since it is a constructor and that's way too late. Ref #2816 --- lib/naughty/notification.lua | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/naughty/notification.lua b/lib/naughty/notification.lua index 64c9e1845..3b0da1f4d 100644 --- a/lib/naughty/notification.lua +++ b/lib/naughty/notification.lua @@ -235,10 +235,6 @@ local notification = {} -- @property preset -- @param table ---- Replace the notification with the given ID. --- @property replaces_id --- @param number - --- Function that will be called with all arguments. -- The notification will only be displayed if the function returns true. -- Note: this function is only relevant to notifications sent via dbus. @@ -394,8 +390,8 @@ local properties = { "width" , "font" , "icon" , "icon_size" , "fg" , "bg" , "height" , "border_color" , "shape" , "opacity" , "margin" , "ignore_suspend", - "destroy" , "preset" , "callback", "replaces_id" , - "actions" , "run" , "id" , "ignore" , + "destroy" , "preset" , "callback", "actions" , + "run" , "id" , "ignore", } for _, prop in ipairs(properties) do @@ -496,7 +492,6 @@ end -- @tparam[opt] table args.preset Table with any of the above parameters. -- Note: Any parameters specified directly in args will override ones defined -- in the preset. --- @tparam[opt] int args.replaces_id Replace the notification with the given ID. -- @tparam[opt] func args.callback Function that will be called with all arguments. -- The notification will only be displayed if the function returns true. -- Note: this function is only relevant to notifications sent via dbus. From bec4de5fabd35863c756d86e8abb569e97251418 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Thu, 11 Jul 2019 00:45:55 -0400 Subject: [PATCH 2/2] 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