From: Hugo Villeneuve Date: Sun, 21 Dec 2014 21:41:19 +0000 (-0500) Subject: Update clock only when time changes X-Git-Url: http://gitweb.hugovil.com/?a=commitdiff_plain;h=9083fb852f001b2e2210dbe92c688bc3d34f8da6;p=dockapps%2Fhvclock.git Update clock only when time changes --- 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 */ }