From 14fa66c63f8fdeba81e3fad75b6ca777bf7ef71f Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 3 Nov 2012 19:43:31 +0100 Subject: [PATCH] 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 --- lib/wibox/drawable.lua.in | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/wibox/drawable.lua.in b/lib/wibox/drawable.lua.in index 5cee40996..8f019f593 100644 --- a/lib/wibox/drawable.lua.in +++ b/lib/wibox/drawable.lua.in @@ -16,6 +16,8 @@ local object = require("gears.object") local sort = require("gears.sort") local surface = require("gears.surface") +local drawables = setmetatable({}, { __mode = 'k' }) + local function do_redraw(self) local cr = cairo.Context(surface(self.drawable.surface)) local geom = self.drawable:geometry(); @@ -224,7 +226,7 @@ function drawable.new(d, widget_arg, redraw_hook) ret._redraw_pending = true end end - capi.awesome.connect_signal("wallpaper_changed", ret.draw) + drawables[ret.draw] = true d:connect_signal("property::surface", ret.draw) -- Set the default background @@ -258,6 +260,14 @@ function drawable.new(d, widget_arg, redraw_hook) return ret 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. -- @class table -- @name drawable