From 01a725757adfa45ea9c09738dec27f42f89c81cf Mon Sep 17 00:00:00 2001 From: Gregor Best Date: Fri, 20 Feb 2009 22:34:19 +0100 Subject: [PATCH] awful.hooks: replace already existing timer hooks instead of creating new ones Signed-off-by: Gregor Best Signed-off-by: Julien Danjou --- lib/awful/hooks.lua.in | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/awful/hooks.lua.in b/lib/awful/hooks.lua.in index 721dfcd78..ac469fd92 100644 --- a/lib/awful/hooks.lua.in +++ b/lib/awful/hooks.lua.in @@ -57,6 +57,19 @@ for name, hook in pairs(capi.hooks) do if type(time) ~= 'number' or type(f) ~= 'function' or time <= 0 then return end + + if not _M[name].callbacks then + _M[name].callbacks = {} + end + + for k, v in pairs(_M[name].callbacks) do + if v.callback == f then + _M[name].unregister(f) + _M[name].register(time, f, runnow) + return + end + end + local new_timer if _M[name].timer then -- Take the smallest between current and new @@ -64,12 +77,11 @@ for name, hook in pairs(capi.hooks) do else new_timer = time end - if not _M[name].callbacks then - _M[name].callbacks = {} - end + if _M[name].timer ~= new_timer then _M[name].timer = new_timer end + hook(_M[name].timer, function (...) for i, callback in ipairs(_M[name].callbacks) do callback['counter'] = callback['counter'] + _M[name].timer