naughty: Always have an id.

Fixes #2678
This commit is contained in:
Emmanuel Lepage Vallee 2019-02-22 11:14:50 -05:00
parent ecec00f425
commit 347d87418b
2 changed files with 15 additions and 7 deletions

View File

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

View File

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