From 9083fb852f001b2e2210dbe92c688bc3d34f8da6 Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Sun, 21 Dec 2014 16:41:19 -0500 Subject: [PATCH] Update clock only when time changes --- src/clock.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/clock.c b/src/clock.c index b26d125..05964b5 100644 --- a/src/clock.c +++ b/src/clock.c @@ -447,8 +447,29 @@ static gboolean hvclock_update(gpointer data) { GtkWidget *clock = GTK_WIDGET(data); + static struct tm previous; + struct tm *now; + int update = false; - hvclock_redraw_canvas(clock); + now = clock_get_time(); + + /* Update only if time has changed. If the hours or minutes have + * changed, force update. */ + if ((now->tm_hour != previous.tm_hour) || + (now->tm_min != previous.tm_min)) { + update = true; + } + + /* If the seconds have changed, force update only if displaying of + * the seconds hand is requested. */ + if (hvclock_infos.show_seconds && (now->tm_sec != previous.tm_sec)) { + update = true; + } + + if (update) { + hvclock_redraw_canvas(clock); + previous = *now; + } return TRUE; /* keep running this event */ } -- 2.20.1