Add naughty.destroy_all_notifications (#1871)

Also updates connect_signal in naughty lib to use destroy_all_notifications().
This commit is contained in:
morethanoneanimal 2017-06-28 15:11:07 -07:00 committed by Daniel Hahler
parent 71548de903
commit cbb8fd7ac4
1 changed files with 27 additions and 5 deletions

View File

@ -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