From aabbb412fe0aa135fb656d5aab674c44fac5fb7d Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 7 Jul 2019 16:04:17 -0400 Subject: [PATCH 1/5] naughty.action: Fix icon_only. It could not be specified in the contructor. Fix #2815 --- lib/naughty/action.lua | 6 +++ .../wibox/nwidget/actionlist/icon_only.lua | 40 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 tests/examples/wibox/nwidget/actionlist/icon_only.lua diff --git a/lib/naughty/action.lua b/lib/naughty/action.lua index abc24c4da..17d7874fe 100644 --- a/lib/naughty/action.lua +++ b/lib/naughty/action.lua @@ -44,6 +44,9 @@ local action = {} -- @tparam gears.surface|string icon --- If the action should hide the label and only display the icon. +-- +-- @DOC_wibox_nwidget_actionlist_icon_only_EXAMPLE@ +-- -- @property icon_only -- @param[opt=false] boolean @@ -125,10 +128,13 @@ local function new(_, args) position = args.position, icon = args.icon, notification = args.notification, + icon_only = args.icon_only or false, } rawset(ret, "_private", default) + gtable.crush(ret, args) + return ret end diff --git a/tests/examples/wibox/nwidget/actionlist/icon_only.lua b/tests/examples/wibox/nwidget/actionlist/icon_only.lua new file mode 100644 index 000000000..483d5ba10 --- /dev/null +++ b/tests/examples/wibox/nwidget/actionlist/icon_only.lua @@ -0,0 +1,40 @@ +--DOC_GEN_IMAGE +local parent = ... --DOC_HIDE --DOC_NO_USAGE +local naughty = { --DOC_HIDE + list = {actions = require("naughty.list.actions")}, --DOC_HIDE + notification = require("naughty.notification"), --DOC_HIDE + action = require("naughty.action") --DOC_HIDE +} --DOC_HIDE +local wibox = require("wibox") --DOC_HIDE +local beautiful = require("beautiful") --DOC_HIDE + + local notif = naughty.notification { + title = "A notification", + message = "This notification has actions!", + actions = { + naughty.action { + name = "Accept", + icon = beautiful.awesome_icon, + icon_only = true, + }, + naughty.action { + name = "Refuse", + icon = beautiful.awesome_icon, + icon_only = true, + }, + naughty.action { + name = "Ignore", + icon = beautiful.awesome_icon, + icon_only = true, + }, + } + } + +--DOC_NEWLINE + +parent:add( wibox.container.background(--DOC_HIDE + wibox.widget { + notification = notif, + widget = naughty.list.actions, + } +,beautiful.bg_normal)) --DOC_HIDE From a91e2e7378d7d4bcb8b174f49d6432ed37686c4d Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Tue, 9 Jul 2019 01:23:11 -0400 Subject: [PATCH 2/5] notification: Fix typos in signal names. Updating notifications would not work because, among other things, the signals names had a typo (all of them...). --- lib/naughty/container/background.lua | 16 ++++++++-------- lib/naughty/widget/icon.lua | 2 +- lib/naughty/widget/message.lua | 8 ++++---- lib/naughty/widget/title.lua | 8 ++++---- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/naughty/container/background.lua b/lib/naughty/container/background.lua index 5bc97fa06..b6896b307 100644 --- a/lib/naughty/container/background.lua +++ b/lib/naughty/container/background.lua @@ -48,13 +48,13 @@ function background:set_notification(notif) if self._private.notification == notif then return end if self._private.notification then - self._private.notification:disconnect_signal("poperty::bg", + self._private.notification:disconnect_signal("property::bg", self._private.background_changed_callback) - self._private.notification:disconnect_signal("poperty::border_width", + self._private.notification:disconnect_signal("property::border_width", self._private.background_changed_callback) - self._private.notification:disconnect_signal("poperty::border_color", + self._private.notification:disconnect_signal("property::border_color", self._private.background_changed_callback) - self._private.notification:disconnect_signal("poperty::shape", + self._private.notification:disconnect_signal("property::shape", self._private.background_changed_callback) end @@ -62,10 +62,10 @@ function background:set_notification(notif) self._private.notification = notif - notif:connect_signal("poperty::bg" , self._private.background_changed_callback) - notif:connect_signal("poperty::border_width", self._private.background_changed_callback) - notif:connect_signal("poperty::border_color", self._private.background_changed_callback) - notif:connect_signal("poperty::shape" , self._private.background_changed_callback) + notif:connect_signal("property::bg" , self._private.background_changed_callback) + notif:connect_signal("property::border_width", self._private.background_changed_callback) + notif:connect_signal("property::border_color", self._private.background_changed_callback) + notif:connect_signal("property::shape" , self._private.background_changed_callback) end --- Create a new naughty.container.background. diff --git a/lib/naughty/widget/icon.lua b/lib/naughty/widget/icon.lua index cac135645..ccb60b6b1 100644 --- a/lib/naughty/widget/icon.lua +++ b/lib/naughty/widget/icon.lua @@ -89,7 +89,7 @@ function icon:set_notification(notif) self._private.notification = notif - notif:connect_signal("poperty::icon", self._private.icon_changed_callback) + notif:connect_signal("property::icon", self._private.icon_changed_callback) end local valid_strategies = { diff --git a/lib/naughty/widget/message.lua b/lib/naughty/widget/message.lua index 8a151b87c..350afcc95 100644 --- a/lib/naughty/widget/message.lua +++ b/lib/naughty/widget/message.lua @@ -41,9 +41,9 @@ function message:set_notification(notif) if self._private.notification == notif then return end if self._private.notification then - self._private.notification:disconnect_signal("poperty::message", + self._private.notification:disconnect_signal("property::message", self._private.message_changed_callback) - self._private.notification:disconnect_signal("poperty::fg", + self._private.notification:disconnect_signal("property::fg", self._private.message_changed_callback) end @@ -51,8 +51,8 @@ function message:set_notification(notif) self._private.notification = notif - notif:connect_signal("poperty::message", self._private.message_changed_callback) - notif:connect_signal("poperty::fg" , self._private.message_changed_callback) + notif:connect_signal("property::message", self._private.message_changed_callback) + notif:connect_signal("property::fg" , self._private.message_changed_callback) end --- Create a new naughty.widget.message. diff --git a/lib/naughty/widget/title.lua b/lib/naughty/widget/title.lua index 92bf4763f..78a804baa 100644 --- a/lib/naughty/widget/title.lua +++ b/lib/naughty/widget/title.lua @@ -41,9 +41,9 @@ function title:set_notification(notif) if self._private.notification == notif then return end if self._private.notification then - self._private.notification:disconnect_signal("poperty::message", + self._private.notification:disconnect_signal("property::message", self._private.title_changed_callback) - self._private.notification:disconnect_signal("poperty::fg", + self._private.notification:disconnect_signal("property::fg", self._private.title_changed_callback) end @@ -52,8 +52,8 @@ function title:set_notification(notif) self._private.notification = notif self._private.title_changed_callback() - notif:connect_signal("poperty::title", self._private.title_changed_callback) - notif:connect_signal("poperty::fg" , self._private.title_changed_callback) + notif:connect_signal("property::title", self._private.title_changed_callback) + notif:connect_signal("property::fg" , self._private.title_changed_callback) end --- Create a new naughty.widget.title. From 4df8120acbfd57004f2826ad12398d633b29dc33 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Tue, 9 Jul 2019 01:25:00 -0400 Subject: [PATCH 3/5] notification: Set the ID earlier. Otherwise the signals were sent and the widgets created before the ID was set. This makes some attempt at detecting updated notifications error prone. --- lib/naughty/notification.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/naughty/notification.lua b/lib/naughty/notification.lua index 5004cfc71..64c9e1845 100644 --- a/lib/naughty/notification.lua +++ b/lib/naughty/notification.lua @@ -580,6 +580,8 @@ local function create(args) gtable.crush(n, notification, true) + n.id = n.id or notification._gen_next_id() + -- Allow extensions to create override the preset with custom data naughty.emit_signal("request::preset", n, args) @@ -597,8 +599,6 @@ local function create(args) n:set_timeout(n._private.timeout or n.preset.timeout) end - n.id = notification._gen_next_id() - return n end From 12f1908ef88d577186e33578c88858d604f58fa6 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Tue, 9 Jul 2019 01:29:33 -0400 Subject: [PATCH 4/5] notification: Make the position index more robust. If the notification screen or position changed, it would end up in the wrong index and removing it would fail. This cannot happen anymore. --- lib/naughty/core.lua | 39 +++++++++++++++++++++++++++++------ lib/naughty/layout/legacy.lua | 17 +++++++++++++-- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/lib/naughty/core.lua b/lib/naughty/core.lua index f57a51d08..266db95ee 100644 --- a/lib/naughty/core.lua +++ b/lib/naughty/core.lua @@ -165,6 +165,35 @@ capi.screen.connect_signal("removed", function(scr) naughty.notifications[scr] = nil end) +local function get_screen(s) + return s and capi.screen[s] +end + +local function remove_from_index(n) + for _, positions in pairs(naughty.notifications) do + for _, ns in pairs(positions) do + for k, n2 in ipairs(ns) do + if n2 == n then + table.remove(ns, k) + return + end + end + end + end +end + +-- When id or screen are set after the object is created, update the indexing. +local function update_index(n) + -- Find the only index and remove it (there's an useless loop, but it's small). + remove_from_index(n) + + -- Add to the index again + local s = get_screen(n.screen or n.preset.screen or screen.focused()) + naughty.notifications[s] = naughty.notifications[s] or {} + table.insert(naughty.notifications[s][n.position], n) +end + + --- Notification state. -- -- This function is deprecated, use `naughty.suspended`. @@ -406,7 +435,7 @@ local function cleanup(self, reason) local scr = self.screen assert(naughty.notifications[scr][self.position][self.idx] == self) - table.remove(naughty.notifications[scr][self.position], self.idx) + remove_from_index(self) -- Update all indices for k, n in ipairs(naughty.notifications[scr][self.position]) do @@ -433,10 +462,6 @@ end naughty.connect_signal("destroyed", cleanup) -local function get_screen(s) - return s and capi.screen[s] -end - -- Proxy the global suspension state on all notification objects local function get_suspended(self) return properties.suspended and not self.ignore_suspend @@ -482,7 +507,6 @@ end -- Register a new notification object. local function register(notification, args) - -- Add the some more properties rawset(notification, "get_suspended", get_suspended) @@ -611,6 +635,9 @@ function naughty.notify(args) return nnotif(args) end +naughty.connect_signal("property::screen" , update_index) +naughty.connect_signal("property::position", update_index) + return setmetatable(naughty, {__index = index_miss, __newindex = set_index_miss}) -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/lib/naughty/layout/legacy.lua b/lib/naughty/layout/legacy.lua index 745ae6de7..a2b791490 100644 --- a/lib/naughty/layout/legacy.lua +++ b/lib/naughty/layout/legacy.lua @@ -266,14 +266,27 @@ local function set_escaped_text(self) if self.size_info then update_size(self) end end +local function seek_and_destroy(n) + for _, positions in pairs(current_notifications) do + for _, pos in pairs(positions) do + for k, n2 in ipairs(pos) do + if n == n2 then + table.remove(pos, k) + return + end + end + end + end +end + local function cleanup(self, _ --[[reason]], keep_visible) -- It is not a legacy notification if not self.box then return end local scr = self.screen - assert(current_notifications[scr][self.position][self.idx] == self) - table.remove(current_notifications[scr][self.position], self.idx) + -- Brute force find it, the position could have been replaced. + seek_and_destroy(self) if (not keep_visible) or (not scr) then self.box.visible = false From 7fb6883cac2103978a4b5308b3cbadec233409f7 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Tue, 9 Jul 2019 01:35:03 -0400 Subject: [PATCH 5/5] notifications: Send more signals when changing an action. If the action own `notification` object changes, also emit the signal on the old one. --- lib/naughty/action.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/naughty/action.lua b/lib/naughty/action.lua index 17d7874fe..dcd234096 100644 --- a/lib/naughty/action.lua +++ b/lib/naughty/action.lua @@ -103,6 +103,16 @@ for _, prop in ipairs { "name", "icon", "notification", "icon_only" } do end end +local set_notif = action.set_notification + +function action.set_notification(self, value) + local old = self._private.notification + set_notif(self, value) + if old then + old:emit_signal("property::actions") + end +end + --- Execute this action. -- -- This only emits the `invoked` signal.