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
This commit is contained in:
parent
11ef560c5c
commit
bec4de5fab
|
@ -126,9 +126,18 @@ gtable.crush(naughty, require("naughty.constants"))
|
||||||
-- @property has_display_handler
|
-- @property has_display_handler
|
||||||
-- @param boolean
|
-- @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 = {
|
local properties = {
|
||||||
suspended = false,
|
suspended = false,
|
||||||
expiration_paused = false
|
expiration_paused = false,
|
||||||
|
auto_reset_timeout= true,
|
||||||
}
|
}
|
||||||
|
|
||||||
--TODO v5 Deprecate the public `naughty.notifications` (to make it private)
|
--TODO v5 Deprecate the public `naughty.notifications` (to make it private)
|
||||||
|
|
|
@ -236,6 +236,9 @@ function notif_methods.Notify(sender, object_path, interface, method, parameters
|
||||||
if k == "destroy" then k = "destroy_cb" end
|
if k == "destroy" then k = "destroy_cb" end
|
||||||
notification[k] = v
|
notification[k] = v
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Even if no property changed, restart the timeout.
|
||||||
|
notification:reset_timeout()
|
||||||
else
|
else
|
||||||
notification = nnotif(args)
|
notification = nnotif(args)
|
||||||
end
|
end
|
||||||
|
|
|
@ -267,6 +267,14 @@ local notification = {}
|
||||||
-- @param boolean
|
-- @param boolean
|
||||||
-- @see naughty.expiration_paused
|
-- @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.
|
--- Emitted when the notification is destroyed.
|
||||||
-- @signal destroyed
|
-- @signal destroyed
|
||||||
-- @tparam number reason Why it was destroyed
|
-- @tparam number reason Why it was destroyed
|
||||||
|
@ -391,7 +399,7 @@ local properties = {
|
||||||
"fg" , "bg" , "height" , "border_color" ,
|
"fg" , "bg" , "height" , "border_color" ,
|
||||||
"shape" , "opacity" , "margin" , "ignore_suspend",
|
"shape" , "opacity" , "margin" , "ignore_suspend",
|
||||||
"destroy" , "preset" , "callback", "actions" ,
|
"destroy" , "preset" , "callback", "actions" ,
|
||||||
"run" , "id" , "ignore",
|
"run" , "id" , "ignore" , "auto_reset_timeout"
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, prop in ipairs(properties) do
|
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)
|
notification["set_"..prop] = notification["set_"..prop] or function(self, value)
|
||||||
self._private[prop] = value
|
self._private[prop] = value
|
||||||
self:emit_signal("property::"..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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue