From 4aaf6ea73080ac407b289e4e44dc633ca0e98f7f Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Fri, 8 Mar 2019 14:39:38 -0500 Subject: [PATCH] naughty: Only enable the legacy mode when there is no other handlers. It was called legacy for a reason, it is meant to be used only when the rc.lua doesn't have the newer notification section. --- lib/naughty/core.lua | 10 +++++++++- lib/naughty/layout/legacy.lua | 21 ++++----------------- lib/naughty/notification.lua | 3 ++- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/lib/naughty/core.lua b/lib/naughty/core.lua index 3b93f7745..f57a51d08 100644 --- a/lib/naughty/core.lua +++ b/lib/naughty/core.lua @@ -122,6 +122,10 @@ gtable.crush(naughty, require("naughty.constants")) -- @property active -- @param table +--- True when there is a handler connected to `request::display`. +-- @property has_display_handler +-- @param boolean + local properties = { suspended = false, expiration_paused = false @@ -346,6 +350,10 @@ function naughty.get_active() return naughty._active end +function naughty.get_has_display_handler() + return conns["request::display"] and #conns["request::display"] > 0 or false +end + --- Set new notification timeout. -- -- This function is deprecated, use `notification:reset_timeout(new_timeout)`. @@ -454,7 +462,7 @@ end --- Emitted when a notification has to be displayed. -- --- To add an handler, use: +-- To add a handler, use: -- -- naughty.connect_signal("request::display", function(notification, args) -- -- do something diff --git a/lib/naughty/layout/legacy.lua b/lib/naughty/layout/legacy.lua index c09732906..f374ed0fc 100644 --- a/lib/naughty/layout/legacy.lua +++ b/lib/naughty/layout/legacy.lua @@ -279,23 +279,10 @@ end naughty.connect_signal("destroyed", cleanup) ---- The default notification GUI handler. --- --- To disable this handler, use: --- --- naughty.disconnect_signal( --- "request::display", naughty.default_notification_handler --- ) --- --- It looks like: --- ---@DOC_naughty_actions_EXAMPLE@ --- --- @tparam table notification The `naughty.notification` object. --- @tparam table args Any arguments passed to the `naughty.notify` function, --- including, but not limited to all `naughty.notification` properties. --- @signalhandler naughty.default_notification_handler function naughty.default_notification_handler(notification, args) + -- This is a fallback for users whose config doesn't have the newer + -- `request::display` section. + if naughty.has_display_handler then return end -- If request::display is called more than once, simply make sure the wibox -- is visible. @@ -561,4 +548,4 @@ function naughty.default_notification_handler(notification, args) end end -naughty.connect_signal("request::display", naughty.default_notification_handler) +naughty.connect_signal("request::fallback", naughty.default_notification_handler) diff --git a/lib/naughty/notification.lua b/lib/naughty/notification.lua index fed40fa8b..7fd39a87d 100644 --- a/lib/naughty/notification.lua +++ b/lib/naughty/notification.lua @@ -551,7 +551,8 @@ local function create(args) -- Let all listeners handle the actual visual aspects if (not n.ignore) and (not n.preset.ignore) then - naughty.emit_signal("request::display", n, args) + naughty.emit_signal("request::display" , n, args) + naughty.emit_signal("request::fallback", n, args) end -- Because otherwise the setter logic would not be executed