From 3458c89040db25135348c1d93ec39a67bd975381 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 19 Sep 2021 21:52:47 -0700 Subject: [PATCH] naughty: Suspend existing notifications. Previously, it would just suspend new notification, but do nothing about the existing ones. --- lib/naughty/core.lua | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/lib/naughty/core.lua b/lib/naughty/core.lua index a5010422..eead8401 100644 --- a/lib/naughty/core.lua +++ b/lib/naughty/core.lua @@ -292,14 +292,20 @@ local conns = gobject._setup_class_signals( local function resume() properties.suspended = false - for _, v in pairs(naughty.notifications.suspended) do + for _, v in ipairs(naughty.notifications.suspended) do local args = v._private.args assert(args) v._private.args = nil + v:emit_signal("property::suspended", false) + naughty.emit_signal("added", v, args) naughty.emit_signal("request::display", v, "resume", args) if v.timer then v.timer:start() end + + if not v._private.args then + v._private.args = args + end end naughty.notifications.suspended = { } end @@ -465,7 +471,7 @@ local function cleanup(self, reason) assert(reason, "Use n:destroy() instead of emitting the signal directly") if properties.suspended then - for k, v in pairs(naughty.notifications.suspended) do + for k, v in ipairs(naughty.notifications.suspended) do if v == self then table.remove(naughty.notifications.suspended, k) break @@ -507,6 +513,25 @@ local function get_suspended(self) return properties.suspended and not self.ignore_suspend end +function naughty.set_suspended(value) + if properties["suspended"] == value then return end + + properties["suspended"] = value + + if value then + for _, n in pairs(naughty._active) do + if n.timer and n.timer.started then + n.timer:stop() + end + + n:emit_signal("property::suspended", true) + table.insert(naughty.notifications.suspended, n) + end + else + resume() + end +end + function naughty.set_expiration_paused(p) properties.expiration_paused = p @@ -669,8 +694,9 @@ local function register(notification, args) notification._private.registered = true + notification._private.args = args + if properties.suspended and not args.ignore_suspend then - notification._private.args = args table.insert(naughty.notifications.suspended, notification) else naughty.emit_signal("added", notification, args) @@ -702,9 +728,6 @@ local function set_index_miss(_, key, value) elseif properties[key] ~= nil then assert(type(value) == "boolean") properties[key] = value - if not value then - resume() - end naughty.emit_signal("property::"..key, value) else