From e13b9a48fffa5fdd99b6f676a2389a0b3ff15f45 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 13 Aug 2017 21:21:01 -0400 Subject: [PATCH] naughty: Use same object when the remote source request a replacement Previously, it would create a new object. The leaves the old `replaces_id` logic mostly intact for now to keep the full backward compatibility. I don't think anybody would have noticed the changed, by time and time again we had proof that some silent users have some amazing and advanced code hidden somewhere. It could be cleaned later when breaking compatibility isn't an issue. --- lib/naughty/dbus.lua | 21 +++++++++++++++++++-- lib/naughty/layout/legacy.lua | 30 ------------------------------ 2 files changed, 19 insertions(+), 32 deletions(-) diff --git a/lib/naughty/dbus.lua b/lib/naughty/dbus.lua index 8b86cd1b..639b0dbc 100644 --- a/lib/naughty/dbus.lua +++ b/lib/naughty/dbus.lua @@ -73,6 +73,9 @@ 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 @@ -201,10 +204,24 @@ capi.dbus.connect_signal("org.freedesktop.Notifications", args.timeout = expire / 1000 end args.freedesktop_hints = hints - notification = nnotif(args) + + -- Try to update existing objects when possible + notification = naughty.get_by_id(replaces_id) + + if notification then + for k, v in pairs(args) do + notification[k] = v + end + else + counter = counter+1 + args.id = counter + notification = nnotif(args) + end + return "u", notification.id end - return "u", "0" + counter = counter+1 + return "u", counter elseif data.member == "CloseNotification" then local obj = naughty.get_by_id(appname) if obj then diff --git a/lib/naughty/layout/legacy.lua b/lib/naughty/layout/legacy.lua index 0e20f066..b8d1be90 100644 --- a/lib/naughty/layout/legacy.lua +++ b/lib/naughty/layout/legacy.lua @@ -57,10 +57,6 @@ screen.connect_for_each_screen(function(s) } end) --- Counter for the notifications --- Required for later access via DBUS -local counter = 1 - --- Evaluate desired position of the notification by index - internal -- -- @param s Screen to use @@ -342,28 +338,6 @@ function naughty.default_notification_handler(notification, args) local opacity = args.opacity or preset.opacity or beautiful.notification_opacity - -- replace notification if needed - local reuse_box - if args.replaces_id then - local obj = naughty.get_by_id(args.replaces_id) - if obj then - -- destroy this and ... - naughty.destroy(obj, naughty.notification_closed_reason.silent, true) - reuse_box = obj.box - end - -- ... may use its ID - if args.replaces_id <= counter then - notification.id = args.replaces_id - else - counter = counter + 1 - notification.id = counter - end - else - -- get a brand new ID - counter = counter + 1 - notification.id = counter - end - notification.position = position -- hook destroy @@ -515,10 +489,6 @@ function naughty.default_notification_handler(notification, args) shape = shape, type = "notification" }) - if reuse_box then - notification.box = reuse_box - end - if hover_timeout then notification.box:connect_signal("mouse::enter", hover_destroy) end notification.size_info = size_info