Sorry for not replying that long, I had some stuff to do for uni :) As
promised, here is a patch. It adds naughty.suspend() and
naughty.resume(), which can be called either via awesome-client, dbus
(kind of replicating awesome-client) and keybindings, signal handlers,
timers, whatever.

As long as suspend() has been called without a subsequent resume(),
notifications are collected and their timers disabled. Once resume() is
called, all notifications are shown and their timers are re-enabled to
make them disappear after their timeout value.

-- 
GCS/IT/M d- s+:- a-- C++ UL+++ US UB++ P+++ L+++ E--- W+ N+ o--
K- w--- ?O M-- ?V PS++ PE- Y++ PGP+++ t+ 5 X+ R tv b+++ DI+++
D+++ G+ e h! r y+

    Gregor Best
From 19ad8adc9eefb5c9db108c63afa32b8897d52da5 Mon Sep 17 00:00:00 2001
From: Gregor Best <[email protected]>
Date: Tue, 16 Feb 2010 17:54:45 +0100
Subject: [PATCH] naughty: add suspend() and resume()

This commit adds naughty.suspend() and naughy.resume() which allow
suspension of notifications, which is useful e.g. when watching a movie,
where notifications popping up all the time would be disturbing.

While suspended, notifications are collected and displayed after
naughty.resume() is called.

Signed-off-by: Gregor Best <[email protected]>
---
 lib/naughty.lua.in |   37 +++++++++++++++++++++++++++++++++++--
 1 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/lib/naughty.lua.in b/lib/naughty.lua.in
index 24c4918..4124d48 100644
--- a/lib/naughty.lua.in
+++ b/lib/naughty.lua.in
@@ -92,6 +92,9 @@ config.mapping = {
 -- Required for later access via DBUS
 local counter = 1
 
+-- True if notifying is suspended
+local suspended = false
+
 --- Index of notifications. See config table for valid 'position' values.
 -- Each element is a table consisting of:
 -- @field box Wibox object containing the popup
@@ -102,7 +105,7 @@ local counter = 1
 -- @name notifications[screen][position]
 -- @class table
 
-notifications = {}
+notifications = { suspended = { } }
 for s = 1, capi.screen.count() do
     notifications[s] = {
         top_left = {},
@@ -112,6 +115,21 @@ for s = 1, capi.screen.count() do
     }
 end
 
+--- Suspend notifications
+function suspend()
+    suspended = true
+end
+
+--- Resume notifications
+function resume()
+    suspended = false
+    for i, v in pairs(notifications.suspended) do
+        v.box.visible = true
+        if v.timer then v.timer:start() end
+    end
+    notifications.suspended = { }
+end
+
 -- Evaluate desired position of the notification by index - internal
 -- @param idx Index of the notification
 -- @param position top_right | top_left | bottom_right | bottom_left
@@ -172,6 +190,14 @@ end
 -- @return True if the popup was successfully destroyed, nil otherwise
 function destroy(notification)
     if notification and notification.box.screen then
+        if suspended then
+            for k, v in pairs(notifications.suspended) do
+                if v.box == notification.box then
+                    table.remove(notifications.suspended, k)
+                    break
+                end
+            end
+        end
         local scr = notification.box.screen
         
table.remove(notifications[notification.box.screen][notification.position], 
notification.idx)
         if notification.timer then
@@ -298,7 +324,9 @@ function notify(args)
     if timeout > 0 then
         local timer_die = capi.timer { timeout = timeout }
         timer_die:add_signal("timeout", die)
-        timer_die:start()
+        if not suspended then
+            timer_die:start()
+        end
         notification.timer = timer_die
     end
     notification.die = die
@@ -412,6 +440,11 @@ function notify(args)
     -- insert the notification to the table
     table.insert(notifications[screen][notification.position], notification)
 
+    if suspended then
+        notification.box.visible = false
+        table.insert(notifications.suspended, notification)
+    end
+
     -- return the notification
     return notification
 end
-- 
1.7.0

Attachment: pgp6Gzf8fJH7F.pgp
Description: PGP signature

Reply via email to