From 62f5e59497a74c921e2ef1b93a07594d192ec450 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 12 Jul 2015 17:20:05 +0200 Subject: [PATCH] naughty: skip permanent notifications when there is no more room This skips permanent notifications (with timeout=0) in `get_offset` when there is not enough room for a new notification. It will still fallback to removing the first/oldest one. Closes https://github.com/awesomeWM/awesome/pull/306. --- lib/naughty/core.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/naughty/core.lua b/lib/naughty/core.lua index 10f218af6..11bd52b65 100644 --- a/lib/naughty/core.lua +++ b/lib/naughty/core.lua @@ -209,10 +209,24 @@ local function get_offset(screen, position, idx, width, height) v.y = ws.y + ws.height - (naughty.config.padding + height + existing) end + -- Find old notification to replace in case there is not enough room. + -- This tries to skip permanent notifications (without a timeout), + -- e.g. critical ones. + local find_old_to_replace = function() + for i = 1, idx-1 do + local n = naughty.notifications[screen][position][i] + if n.timeout > 0 then + return n + end + end + -- Fallback to first one. + return naughty.notifications[screen][position][1] + end + -- if positioned outside workarea, destroy oldest popup and recalculate if v.y + height > ws.y + ws.height or v.y < ws.y then + naughty.destroy(find_old_to_replace()) idx = idx - 1 - naughty.destroy(naughty.notifications[screen][position][1]) v = get_offset(screen, position, idx, width, height) end if not v.idx then v.idx = idx end