From e9377c480857c3edbd6bdf1d97c25690f62273e7 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 27 Sep 2015 12:38:57 +0200 Subject: [PATCH] Make textclock garbage-collectable This fixes the textclock-specific part of the test that the previous commit added. To fix this, gears.timer.weak_start_new() is used. This function creates a timer that is automatically stopped when its callback function is garbage collected. The callback function is saved as a member of the texbox widget that is the "widget behind the textclock". Thus, the timer can only be stopped after the widget is garbage-collected, but the timer does not keep the widget alive. Signed-off-by: Uli Schlachter --- lib/awful/widget/textclock.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/awful/widget/textclock.lua b/lib/awful/widget/textclock.lua index 22989a84..6b5d708e 100644 --- a/lib/awful/widget/textclock.lua +++ b/lib/awful/widget/textclock.lua @@ -31,13 +31,14 @@ function textclock.new(format, timeout) local timeout = timeout or 60 local w = textbox() - local t = timer { timeout = timeout } - t:connect_signal("timeout", function() + local t + function w._textclock_update_cb() w:set_markup(DateTime.new_now_local():format(format)) t.timeout = calc_timeout(timeout) t:again() - end) - t:start() + return true -- Continue the timer + end + t = timer.weak_start_new(timeout, w._textclock_update_cb) t:emit_signal("timeout") return w end