From cbb8fd7ac408d229233a3b5490adf35d58a85d79 Mon Sep 17 00:00:00 2001 From: morethanoneanimal Date: Wed, 28 Jun 2017 15:11:07 -0700 Subject: [PATCH] Add naughty.destroy_all_notifications (#1871) Also updates connect_signal in naughty lib to use destroy_all_notifications(). --- lib/naughty/core.lua | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/lib/naughty/core.lua b/lib/naughty/core.lua index 5ea59e4ab..7c6b2273c 100644 --- a/lib/naughty/core.lua +++ b/lib/naughty/core.lua @@ -221,11 +221,7 @@ end) capi.screen.connect_signal("removed", function(scr) -- Destroy all notifications on this screen - for _, list in pairs(naughty.notifications[scr]) do - while #list > 0 do - naughty.destroy(list[1]) - end - end + naughty.destroy_all_notifications({scr}) naughty.notifications[scr] = nil end) @@ -368,6 +364,32 @@ function naughty.destroy(notification, reason, keep_visible) end end +--- Destroy all notifications on given screens. +-- +-- @tparam table screens Table of screens on which notifications should be +-- destroyed. If nil, destroy notifications on all screens. +-- @tparam naughty.notificationClosedReason reason Reason for closing +-- notifications. +-- @treturn true|nil True if all notifications were successfully destroyed, nil +-- otherwise. +function naughty.destroy_all_notifications(screens, reason) + if not screens then + screens = {} + for key, _ in pairs(naughty.notifications) do + table.insert(screens, key) + end + end + local ret = true + for _, scr in pairs(screens) do + for _, list in pairs(naughty.notifications[scr]) do + while #list > 0 do + ret = ret and naughty.destroy(list[1], reason) + end + end + end + return ret +end + --- Get notification by ID -- -- @param id ID of the notification