Merge pull request #2689 from blueyed/naughty-legacy

Fix naughty legacy wrt to id
This commit is contained in:
mergify[bot] 2019-02-24 17:46:32 +00:00 committed by GitHub
commit d119a9a20a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 11 deletions

View File

@ -73,9 +73,6 @@ local function sendNotificationClosed(notificationId, reason)
end end
end end
-- This allow notification to be upadated later.
local counter = 1
local function convert_icon(w, h, rowstride, channels, data) local function convert_icon(w, h, rowstride, channels, data)
-- Do the arguments look sane? (e.g. we have enough data) -- Do the arguments look sane? (e.g. we have enough data)
local expected_length = rowstride * (h - 1) + w * channels local expected_length = rowstride * (h - 1) + w * channels
@ -213,15 +210,13 @@ capi.dbus.connect_signal("org.freedesktop.Notifications",
notification[k] = v notification[k] = v
end end
else else
counter = counter+1
args.id = counter
notification = nnotif(args) notification = nnotif(args)
end end
return "u", notification.id return "u", notification.id
end end
counter = counter+1
return "u", counter return "u", nnotif._gen_next_id()
elseif data.member == "CloseNotification" then elseif data.member == "CloseNotification" then
local obj = naughty.get_by_id(appname) local obj = naughty.get_by_id(appname)
if obj then if obj then

View File

@ -453,6 +453,8 @@ local function create(args)
if not args then return end if not args then return end
end end
assert(not args.id, "Identifiers cannot be specified externally")
args = args or {} args = args or {}
-- Old actions usually have callbacks and names. But this isn't non -- 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) n:set_timeout(n._private.timeout or n.preset.timeout)
end end
n.id = notification._gen_next_id()
return n return n
end 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}) return setmetatable(notification, {__call = function(_, ...) return create(...) end})

View File

@ -257,6 +257,7 @@ local function test_overlap()
for _, n1 in ipairs(active) do for _, n1 in ipairs(active) do
assert(n1.box) assert(n1.box)
assert(n1.id)
-- Check for overlapping the workarea -- Check for overlapping the workarea
assert(n1.box.y+default_height < wa.y+wa.height) assert(n1.box.y+default_height < wa.y+wa.height)
@ -405,6 +406,7 @@ table.insert(steps, function()
timeout = 25000, timeout = 25000,
} }
assert(n1.id)
assert(n1.iconbox) assert(n1.iconbox)
assert(n1.iconbox._private.image:get_width () == beautiful.notification_icon_size) assert(n1.iconbox._private.image:get_width () == beautiful.notification_icon_size)
assert(n1.iconbox._private.image:get_height() == beautiful.notification_icon_size) assert(n1.iconbox._private.image:get_height() == beautiful.notification_icon_size)
@ -420,6 +422,7 @@ table.insert(steps, function()
timeout = 25000, timeout = 25000,
} }
assert(n2.id)
assert(n2.iconbox) assert(n2.iconbox)
assert(n2.iconbox._private.image:get_width () == 32) assert(n2.iconbox._private.image:get_width () == 32)
assert(n2.iconbox._private.image:get_height() == 32) assert(n2.iconbox._private.image:get_height() == 32)
@ -655,6 +658,49 @@ table.insert(steps, function()
return true return true
end) end)
local int_n = nil
-- Test replace_id with internally generated notifications.
-- Even if it makes little sense, it should work and is used in the wild.
table.insert(steps, function()
int_n = naughty.notification {
title = "foo",
message = "bar",
timeout = 25000,
}
local nid2 = int_n.id
assert(int_n.id)
local res, err = pcall(function()
int_n.id = 1337
end)
assert(err:match("Notification identifier can only be set once"))
assert(not res)
assert(int_n.id == nid2)
-- watch out, capi.dbus signals are not normal object signals
send_notify("Awesome test", nid2, "", "title2", "text2",
{ "the one action" }, {}, 123)
return true
end)
-- Test that the values were replaced
table.insert(steps, function()
if int_n.title ~= "title2" then return end
assert(int_n.title == "title2")
assert(int_n.message == "text2" )
--assert(int_n.timeout == 123 ) --FIXME
int_n:destroy()
--TODO test what happens when updating a destroyed notification
-- There is currently no API to resurrect notifications.
return true
end)
-- Now check if the old deprecated (but still supported) APIs don't have errors. -- Now check if the old deprecated (but still supported) APIs don't have errors.
table.insert(steps, function() table.insert(steps, function()
-- Tests are (by default) not allowed to call deprecated APIs -- Tests are (by default) not allowed to call deprecated APIs
@ -698,10 +744,9 @@ table.insert(steps, function()
assert(n.text == "baz") assert(n.text == "baz")
-- Test the ID system -- Test the ID system
n.id = 1337 local id = n.id
assert(n.id == 1337) assert(naughty.getById(id) == n)
assert(naughty.getById(1337) == n) assert(naughty.get_by_id(id) == n)
assert(naughty.get_by_id(1337) == n)
assert(naughty.getById(42) ~= n) assert(naughty.getById(42) ~= n)
assert(naughty.get_by_id(42) ~= n) assert(naughty.get_by_id(42) ~= n)