From 347d87418b11f896f6beecec187cbc53fd0c450a Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Fri, 22 Feb 2019 11:14:50 -0500 Subject: [PATCH] naughty: Always have an id. Fixes #2678 --- lib/naughty/dbus.lua | 9 ++------- lib/naughty/notification.lua | 13 +++++++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/naughty/dbus.lua b/lib/naughty/dbus.lua index 639b0dbc4..7218f1e35 100644 --- a/lib/naughty/dbus.lua +++ b/lib/naughty/dbus.lua @@ -73,9 +73,6 @@ local function sendNotificationClosed(notificationId, reason) end end --- This allow notification to be upadated later. -local counter = 1 - local function convert_icon(w, h, rowstride, channels, data) -- Do the arguments look sane? (e.g. we have enough data) local expected_length = rowstride * (h - 1) + w * channels @@ -213,15 +210,13 @@ capi.dbus.connect_signal("org.freedesktop.Notifications", notification[k] = v end else - counter = counter+1 - args.id = counter notification = nnotif(args) end return "u", notification.id end - counter = counter+1 - return "u", counter + + return "u", nnotif._gen_next_id() elseif data.member == "CloseNotification" then local obj = naughty.get_by_id(appname) if obj then diff --git a/lib/naughty/notification.lua b/lib/naughty/notification.lua index fee8d0115..7456db84e 100644 --- a/lib/naughty/notification.lua +++ b/lib/naughty/notification.lua @@ -453,6 +453,8 @@ local function create(args) if not args then return end end + assert(not args.id, "Identifiers cannot be specified externally") + args = args or {} -- Old actions usually have callbacks and names. But this isn't non @@ -524,7 +526,18 @@ local function create(args) n:set_timeout(n._private.timeout or n.preset.timeout) end + n.id = notification._gen_next_id() + return n end +-- This allows notification to be updated later. +local counter = 1 + +-- Identifier support. +function notification._gen_next_id() + counter = counter+1 + return counter +end + return setmetatable(notification, {__call = function(_, ...) return create(...) end})