From 6145a631d5d1095ac937d28ba812f7e3cb315c1c Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 19 Sep 2012 21:13:15 -0500 Subject: in datetime-service, add a seconds timer that watches for clock skew and rebuilds the labels when it finds it --- src/datetime-service.c | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/datetime-service.c b/src/datetime-service.c index 453bb9b..88689b7 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -1106,14 +1106,26 @@ build_menus (DbusmenuMenuitem * root) return; } +static void +on_clock_skew (void) +{ + /* tell the indicators to refresh */ + if (IS_DATETIME_INTERFACE (dbus)) + datetime_interface_update (DATETIME_INTERFACE(dbus)); + + /* update our day label */ + update_datetime (NULL); + day_timer_reset(); + + return; +} + /* Run when the timezone file changes */ static void timezone_changed (GFileMonitor * monitor, GFile * file, GFile * otherfile, GFileMonitorEvent event, gpointer user_data) { update_current_timezone(); - datetime_interface_update(DATETIME_INTERFACE(user_data)); - update_datetime(NULL); - day_timer_reset(); + on_clock_skew(); return; } @@ -1169,6 +1181,23 @@ day_timer_reset (void) return; } +static guint second_timer = 0; + +static gboolean +second_timer_func (gpointer unused G_GNUC_UNUSED) +{ + static time_t prev_time =0; + const time_t cur_time = time (NULL); + + if (prev_time && (fabs (difftime (cur_time, prev_time)) > 5)) { + g_debug (G_STRLOC" clock skew detected"); + on_clock_skew (); + } + + prev_time = cur_time; + return G_SOURCE_CONTINUE; +} + static void session_active_change_cb (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, gpointer user_data) @@ -1178,9 +1207,7 @@ session_active_change_cb (GDBusProxy * proxy, gchar * sender_name, gchar * signa gboolean idle = FALSE; g_variant_get(parameters, "(b)", &idle); if (!idle) { - datetime_interface_update(DATETIME_INTERFACE(user_data)); - update_datetime(NULL); - day_timer_reset(); + on_clock_skew (); } } return; @@ -1427,9 +1454,12 @@ main (int argc, char ** argv) /* Setup timezone watch */ build_timezone(dbus); - /* Setup the timer */ + /* Set up the day timer */ day_timer_reset(); + /* Set up the second timer */ + second_timer = g_timeout_add_seconds_full (G_PRIORITY_LOW, 1, second_timer_func, NULL, NULL); + /* And watch for system resumes */ g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, -- cgit v1.2.3