diff -u trunk/panel-plugin/datetime.c exp2/panel-plugin/datetime.c --- trunk/panel-plugin/datetime.c 2008-06-08 19:17:04.000000000 -0700 +++ exp2/panel-plugin/datetime.c 2008-06-10 13:11:03.000000000 -0700 @@ -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,46 +157,28 @@ 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; +#if USE_GTK_TOOLTIP_API + if (datetime->tooltip_handler_id != 0) + { + datetime->current_time = current; /* pass current time to tooltip handler */ + gtk_widget_trigger_tooltip_query(GTK_WIDGET(datetime->button)); + } +#endif + + /* 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; } #if USE_GTK_TOOLTIP_API -static gboolean datetime_tooltip_timer(t_datetime *datetime) -{ - - /* flag to datetime_query_tooltip that there is no longer an active timeout */ - datetime->tooltip_timeout_id = 0; - - /* - * Run datetime_query_tooltip if the mouse is still there. - * If it is run, it'll register *this* function to be called after another - * timeout. If not, *this* function won't run again. - */ - gtk_widget_trigger_tooltip_query(GTK_WIDGET(datetime->button)); - - /* we don't want to automatically run again */ - return FALSE; -} - static gboolean datetime_query_tooltip(GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, GtkTooltip *tooltip, t_datetime *datetime) { - GTimeVal timeval; - struct tm *current; gchar *utf8str; gchar *format = NULL; @@ -201,24 +197,10 @@ if (format == NULL) return FALSE; - g_get_current_time(&timeval); - current = localtime((time_t *)&timeval.tv_sec); - - utf8str = datetime_do_utf8strftime(format, current); + utf8str = datetime_do_utf8strftime(format, datetime->current_time); gtk_tooltip_set_text(tooltip, utf8str); g_free(utf8str); - /* 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, - (GSourceFunc) datetime_tooltip_timer, datetime); - } - return TRUE; } #endif @@ -694,7 +676,6 @@ { /* stop timeouts */ g_source_remove(datetime->timeout_id); - g_source_remove(datetime->tooltip_timeout_id); /* destroy widget */ gtk_widget_destroy(datetime->button); diff -u trunk/panel-plugin/datetime.h exp2/panel-plugin/datetime.h --- trunk/panel-plugin/datetime.h 2008-06-08 19:17:04.000000000 -0700 +++ exp2/panel-plugin/datetime.h 2008-06-10 13:27:16.000000000 -0700 @@ -49,8 +49,8 @@ guint update_interval; /* time between updates in milliseconds */ guint timeout_id; #if USE_GTK_TOOLTIP_API - guint tooltip_timeout_id; - gulong tooltip_handler_id; + gulong tooltip_handler_id; + struct tm *current_time; #endif /* settings */