From f25866f4e57270610b0419761277a9ff2ef55de2 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 19 Jul 2015 17:47:44 +0200 Subject: [PATCH 1/2] Add vicious.change_timer: a helper to change the timeout This is useful in case you want to change the timeout value for a registered widget, e.g. from the format callback function. I am using this to have a shorter timeout interval for the temperature widget when its value is above some threshold. Signed-off-by: Daniel Hahler --- init.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/init.lua b/init.lua index d8a293a..074d883 100644 --- a/init.lua +++ b/init.lua @@ -352,5 +352,16 @@ function vicious.call_async(wtype, format, warg, callback) end -- }}} +-- {{{ Change the timer of a registered widget. +function vicious.change_timer(reg, timer_) + if not reg then return end + if timer_ ~= reg.timer then + vicious.unregister(nil, true, reg) + reg.timer = timer_ + regregister(reg) + end +end +-- }}} + return vicious -- }}} From 9301e186efe834f089d4fca42d68f43038ff4891 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 19 Mar 2021 08:36:29 +0100 Subject: [PATCH 2/2] s/timer/timeout, return cur --- init.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/init.lua b/init.lua index 074d883..87dad54 100644 --- a/init.lua +++ b/init.lua @@ -353,13 +353,15 @@ end -- }}} -- {{{ Change the timer of a registered widget. -function vicious.change_timer(reg, timer_) +function vicious.change_timer(reg, timeout) if not reg then return end - if timer_ ~= reg.timer then + local cur = reg.timeout + if timeout ~= cur then vicious.unregister(nil, true, reg) - reg.timer = timer_ + reg.timeout = timeout regregister(reg) end + return cur end -- }}}