aboutsummaryrefslogtreecommitdiff
path: root/init.lua
diff options
context:
space:
mode:
authorDodo <dodo.the.last@gmail.com>2013-11-07 05:11:49 +0100
committerAdrian C. (anrxc) <anrxc@sysphere.org>2013-11-23 20:36:50 +0100
commit211d4509c146a3224b859c3e16b609a1f769d568 (patch)
treee2bb1689c4094cdf1ad625913b4ddb6f811fb998 /init.lua
parent75cd1039cfa33f502485c6a7f70be747213bfe84 (diff)
downloadvicious-legacy-211d4509c146a3224b859c3e16b609a1f769d568.tar.xz
init: share timers when possible
We need time to give this a proper test with various usage scenarios; multiple screens (and thus widget object instances), widgets suspending and resuming and so on. Most benefits should come from running on battery power (and if not suspending all widgets but Battery it self on battery power), with less wake-ups. Signed-off-by: Adrian C. (anrxc) <anrxc@sysphere.org>
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua35
1 files changed, 25 insertions, 10 deletions
diff --git a/init.lua b/init.lua
index 275799a..46fdec5 100644
--- a/init.lua
+++ b/init.lua
@@ -116,18 +116,21 @@ local function regregister(reg)
-- Start the timer
if reg.timer > 0 then
- timers[reg.update] = {
- timer = capi.timer({ timeout = reg.timer })
- }
-
- local tm = timers[reg.update].timer
+ local tm = timers[reg.timer] and timers[reg.timer].timer
+ tm = tm or capi.timer({ timeout = reg.timer })
if tm.connect_signal then
tm:connect_signal("timeout", reg.update)
else
tm:add_signal("timeout", reg.update)
end
- tm:start()
-
+ if not timers[reg.timer] then
+ timers[reg.timer] = { timer = tm, refs = 1 }
+ else
+ timers[reg.timer].refs = timers[reg.timer].refs + 1
+ end
+ if not tm.started then
+ tm:start()
+ end
-- Initial update
tm:emit_signal("timeout")
end
@@ -195,11 +198,23 @@ function vicious.unregister(widget, keep, reg)
end
end
- -- Stop the timer
- if timers[reg.update].timer.started then
- timers[reg.update].timer:stop()
+ if not reg.running then
+ return reg
+ end
+
+ -- Disconnect from timer
+ local tm = timers[reg.timer]
+ if tm.timer.disconnect_signal then
+ tm.timer:disconnect_signal("timeout", reg.update)
+ else
+ tm.timer:remove_signal("timeout", reg.update)
end
reg.running = false
+ -- Stop the timer
+ tm.refs = tm.refs - 1
+ if tm.refs == 0 and tm.timer.started then
+ tm.timer:stop()
+ end
return reg
end