naughty.notification: Do not hold a strong reference to the screen.

The screen will leak if there is active notifications when the screen
is removed. Note that as of this commit, it still does, but "less".
This commit is contained in:
Emmanuel Lepage Vallee 2020-02-10 01:51:29 -05:00
parent 523e7dc6ba
commit 720bef0b02
1 changed files with 26 additions and 4 deletions

View File

@ -15,6 +15,7 @@
-- @copyright 2017 Emmanuel Lepage Vallee
-- @coreclassmod naughty.notification
---------------------------------------------------------------------------
local capi = { screen = screen }
local gobject = require("gears.object")
local gtable = require("gears.table")
local gsurface = require("gears.surface")
@ -579,14 +580,14 @@ end
local properties = {
"message" , "title" , "timeout" , "hover_timeout" ,
"screen" , "position", "ontop" , "border_width" ,
"app_name", "position", "ontop" , "border_width" ,
"width" , "font" , "icon" , "icon_size" ,
"fg" , "bg" , "height" , "border_color" ,
"shape" , "opacity" , "margin" , "ignore_suspend",
"destroy" , "preset" , "callback", "actions" ,
"run" , "id" , "ignore" , "auto_reset_timeout",
"urgency" , "image" , "images" , "widget_template",
"max_width", "app_name",
"max_width",
}
for _, prop in ipairs(properties) do
@ -718,6 +719,23 @@ function notification:append_actions(new_actions)
end
function notification:set_screen(s)
assert(not self._private.screen)
s = s and capi.screen[s] or nil
-- Avoid an infinite loop in the management code.
if s == self._private.weak_screen[1] then return end
self._private.weak_screen = setmetatable({s}, {__mode="v"})
self:emit_signal("property::screen", s)
end
function notification:get_screen()
return self._private.weak_screen[1]
end
--TODO v6: remove this
local function convert_actions(actions)
gdebug.deprecate(
@ -869,7 +887,7 @@ local function create(args)
n:_connect_everything(naughty.emit_signal)
-- Avoid modifying the original table
local private = {}
local private = {weak_screen = setmetatable({}, {__mode="v"})}
rawset(n, "_private", private)
-- Allow extensions to create override the preset with custom data
@ -882,8 +900,12 @@ local function create(args)
end
for k, v in pairs(args) do
-- Don't keep a strong reference to the screen, Lua 5.1 GC wont be
-- smart enough to unwind the mess of circular weak references.
if k ~= "screen" then
private[k] = v
end
end
-- It's an automatic property
n.is_expired = false