wibox.drawables: Fix a memleak

Drawables could never be garbage-collected, because of the "wallpaper_changed"
signal. The callback function for this signal kept a strong reference to the
drawable.

Fix this by putting all drawable's draw() methods into a weakly keyed tabled so
that the strong reference to them disappears.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2012-11-03 19:43:31 +01:00
parent 3c320927f8
commit 14fa66c63f
1 changed files with 11 additions and 1 deletions

View File

@ -16,6 +16,8 @@ local object = require("gears.object")
local sort = require("gears.sort") local sort = require("gears.sort")
local surface = require("gears.surface") local surface = require("gears.surface")
local drawables = setmetatable({}, { __mode = 'k' })
local function do_redraw(self) local function do_redraw(self)
local cr = cairo.Context(surface(self.drawable.surface)) local cr = cairo.Context(surface(self.drawable.surface))
local geom = self.drawable:geometry(); local geom = self.drawable:geometry();
@ -224,7 +226,7 @@ function drawable.new(d, widget_arg, redraw_hook)
ret._redraw_pending = true ret._redraw_pending = true
end end
end end
capi.awesome.connect_signal("wallpaper_changed", ret.draw) drawables[ret.draw] = true
d:connect_signal("property::surface", ret.draw) d:connect_signal("property::surface", ret.draw)
-- Set the default background -- Set the default background
@ -258,6 +260,14 @@ function drawable.new(d, widget_arg, redraw_hook)
return ret return ret
end end
-- Redraw all drawables when the wallpaper changes
capi.awesome.connect_signal("wallpaper_changed", function()
local k
for k in pairs(drawables) do
k()
end
end)
--- Handling of drawables. A drawable is something that can be drawn to. --- Handling of drawables. A drawable is something that can be drawn to.
-- @class table -- @class table
-- @name drawable -- @name drawable