@@ -46,8 +46,7 @@ local function update(widget, reg, disablecache)
4646 return
4747 end
4848
49- local t = os.time ()
50- local data = {}
49+ local update_time = os.time ()
5150
5251 local function format_data (data )
5352 local ret
@@ -100,7 +99,7 @@ local function update(widget, reg, disablecache)
10099
101100 -- Check for cached output newer than the last update
102101 local c = widget_cache [reg .wtype ]
103- if c and t < c .time + reg .timer and not disablecache then
102+ if c and update_time < c .time + reg .timeout and not disablecache then
104103 update_value (c .data )
105104 elseif reg .wtype then
106105 if type (reg .wtype ) == " table" and reg .wtype .async then
@@ -109,14 +108,14 @@ local function update(widget, reg, disablecache)
109108 return reg .wtype .async (reg .format ,
110109 reg .warg ,
111110 function (data )
112- update_cache (data , t , c )
111+ update_cache (data , update_time , c )
113112 update_value (data )
114113 reg .lock = false
115114 end )
116115 end
117116 else
118117 local data = reg .wtype (reg .format , reg .warg )
119- update_cache (data , t , c )
118+ update_cache (data , update_time , c )
120119 update_value (data )
121120 end
122121 end
@@ -153,18 +152,18 @@ local function regregister(reg)
153152 end
154153
155154 -- Start the timer
156- if reg .timer > 0 then
157- local tm = timers [reg .timer ] and timers [reg .timer ].timer
158- tm = tm or timer ({ timeout = reg .timer })
155+ if reg .timeout > 0 then
156+ local tm = timers [reg .timeout ] and timers [reg .timeout ].timer
157+ tm = tm or timer ({ timeout = reg .timeout })
159158 if tm .connect_signal then
160159 tm :connect_signal (" timeout" , reg .update )
161160 else
162161 tm :add_signal (" timeout" , reg .update )
163162 end
164- if not timers [reg .timer ] then
165- timers [reg .timer ] = { timer = tm , refs = 1 }
163+ if not timers [reg .timeout ] then
164+ timers [reg .timeout ] = { timer = tm , refs = 1 }
166165 else
167- timers [reg .timer ].refs = timers [reg .timer ].refs + 1
166+ timers [reg .timeout ].refs = timers [reg .timeout ].refs + 1
168167 end
169168 if not tm .started then
170169 tm :start ()
@@ -181,16 +180,18 @@ end
181180
182181-- {{{ Global functions
183182-- {{{ Register a widget
184- function vicious .register (widget , wtype , format , timer , warg )
183+ function vicious .register (widget , wtype , format , timeout , warg )
185184 local reg = {
186185 -- Set properties
187- wtype = wtype ,
188- lock = false ,
189- format = format ,
190- timer = timer or 2 ,
191- warg = warg ,
192- widget = widget ,
186+ wtype = wtype ,
187+ lock = false ,
188+ format = format ,
189+ timeout = timeout or 2 ,
190+ warg = warg ,
191+ widget = widget ,
193192 }
193+ reg .timer = timeout -- For backward compatibility.
194+
194195 -- Set functions
195196 function reg .update ()
196197 update (widget , reg )
@@ -235,7 +236,7 @@ function vicious.unregister(widget, keep, reg)
235236 end
236237
237238 -- Disconnect from timer
238- local tm = timers [reg .timer ]
239+ local tm = timers [reg .timeout ]
239240 if tm .timer .disconnect_signal then
240241 tm .timer :disconnect_signal (" timeout" , reg .update )
241242 else
0 commit comments