From b04b1b27af84fc892c63ee428d4c623a829e4036 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 10 Sep 2017 20:12:25 +0200 Subject: [PATCH] Add a force_update() method to the textclock (#2034) Reference: https://github.com/awesomeWM/awesome/issues/344 Signed-off-by: Uli Schlachter --- lib/wibox/widget/textclock.lua | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/wibox/widget/textclock.lua b/lib/wibox/widget/textclock.lua index 59bc3107..7b562515 100644 --- a/lib/wibox/widget/textclock.lua +++ b/lib/wibox/widget/textclock.lua @@ -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