Merge pull request #2816 from Elv13/more_notif_fix

Fix 4 "new API" notification bugs
This commit is contained in:
Emmanuel Lepage Vallée 2019-07-10 17:27:27 -04:00 committed by GitHub
commit f3ee880bd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 123 additions and 27 deletions

View File

@ -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
@ -100,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.
@ -125,10 +138,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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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