--- trunk/panel-plugin/datetime.c 2008-06-08 19:17:04.000000000 -0700 +++ exp2/panel-plugin/datetime.c 2008-06-10 03:20:41.000000000 -0700 @@ -1,4 +1,4 @@ -/* $Id$ +/* $Id: datetime.c,v 1.3 2008/06/10 10:08:58 stephent Exp stephent $ * * Copyright (C) 2003 Choe Hwanjin(krisna@kldp.org) * Copyright (c) 2006 Remco den Breeje @@ -51,6 +51,20 @@ } /* + * Compute the wake interval, + * which is the time remaining from the current time + * to the next larger integral multiple of the update interval. + * Setting a timer to this value schedules the next update + * to occur on the next second or minute + * when the given update interval is 1000 or 60000 milliseconds, respectively. + */ +static inline guint datetime_wake_interval_from_current_time(const GTimeVal current_time, + const guint update_interval_ms) +{ + return (update_interval_ms - datetime_gtimeval_to_ms(current_time) % update_interval_ms); +} + +/* * Get date/time string */ gchar * datetime_do_utf8strftime(const char *format, const struct tm *tm) @@ -143,15 +157,8 @@ g_free(utf8str); } - /* - * Compute the time to the next update and start the timer. - * The wake interval is the time remaining - * to the next larger integral multiple of the update interval. - * Setting the timer to this value schedules the next update - * to occur on the next second or minute - * when the update interval is 1 or 60 seconds, respectively. - */ - wake_interval = datetime->update_interval - datetime_gtimeval_to_ms(timeval) % datetime->update_interval; + /* Compute the time to the next update and start the timer. */ + wake_interval = datetime_wake_interval_from_current_time(timeval, datetime->update_interval); datetime->timeout_id = g_timeout_add(wake_interval, (GSourceFunc) datetime_update, datetime); return TRUE; @@ -185,6 +192,7 @@ struct tm *current; gchar *utf8str; gchar *format = NULL; + guint wake_interval; /* milliseconds to next update */ switch(datetime->layout) { @@ -211,11 +219,9 @@ /* if there is no active timeout to update the tooltip, register one */ if (!datetime->tooltip_timeout_id) { - /* - * I think we can afford to inefficiently poll every - * second while the user keeps the mouse here. - */ - datetime->tooltip_timeout_id = g_timeout_add(1000, + /* Compute the time to the next update and start the timer. */ + wake_interval = datetime_wake_interval_from_current_time(timeval, datetime->update_interval); + datetime->tooltip_timeout_id = g_timeout_add(wake_interval, (GSourceFunc) datetime_tooltip_timer, datetime); }