Add a force_update() method to the textclock (#2034)

Reference: https://github.com/awesomeWM/awesome/issues/344
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2017-09-10 20:12:25 +02:00 committed by Daniel Hahler
parent ebcc19844e
commit b04b1b27af
1 changed files with 10 additions and 5 deletions

View File

@ -16,6 +16,11 @@ local TimeZone = glib.TimeZone
local textclock = { mt = {} }
--- Force a textclock to update now.
function textclock:force_update()
self._timer:emit_signal("timeout")
end
--- This lowers the timeout so that it occurs "correctly". For example, a timeout
-- of 60 is rounded so that it occurs the next time the clock reads ":00 seconds".
local function calc_timeout(real_timeout)
@ -37,15 +42,15 @@ function textclock.new(format, timeout, timezone)
timezone = timezone and TimeZone.new(timezone) or TimeZone.new_local()
local w = textbox()
local t
w.force_update = textclock.force_update
function w._private.textclock_update_cb()
w:set_markup(DateTime.new_now(timezone):format(format))
t.timeout = calc_timeout(timeout)
t:again()
w._timer.timeout = calc_timeout(timeout)
w._timer:again()
return true -- Continue the timer
end
t = timer.weak_start_new(timeout, w._private.textclock_update_cb)
t:emit_signal("timeout")
w._timer = timer.weak_start_new(timeout, w._private.textclock_update_cb)
w:force_update()
return w
end