Author: juha Date: 2008-11-16 10:29:43 +0000 (Sun, 16 Nov 2008) New Revision: 28827
Modified: xfcalendar/trunk/configure.in.in xfcalendar/trunk/panel-plugin/orageclock.c xfcalendar/trunk/panel-plugin/orageclock.h Log: more efficient fix for suspend / hibernate time adjustment Modified: xfcalendar/trunk/configure.in.in =================================================================== --- xfcalendar/trunk/configure.in.in 2008-11-15 20:53:38 UTC (rev 28826) +++ xfcalendar/trunk/configure.in.in 2008-11-16 10:29:43 UTC (rev 28827) @@ -9,7 +9,7 @@ dnl dnl Version information -m4_define([orage_version], [4.5.92.4-svn]) +m4_define([orage_version], [4.5.92.5-svn]) m4_define([gtk_minimum_version], [2.6.0]) m4_define([xfce_minimum_version], [4.4.0]) Modified: xfcalendar/trunk/panel-plugin/orageclock.c =================================================================== --- xfcalendar/trunk/panel-plugin/orageclock.c 2008-11-15 20:53:38 UTC (rev 28826) +++ xfcalendar/trunk/panel-plugin/orageclock.c 2008-11-16 10:29:43 UTC (rev 28827) @@ -96,7 +96,8 @@ * 100 % of the time wasted in this procedure * Note that even though we only wake up when needed, we * may not have to update all lines, so this check still - * probably is worth doing + * probably is worth doing. Specially after we added the + * hibernate update option. * */ if (strcmp(res, line->prev)) { gtk_label_set_text(GTK_LABEL(line->label), res); @@ -109,18 +110,29 @@ return(TRUE); } +static gboolean oc_get_time_and_tune(Clock *clock) +{ + oc_get_time(clock); + if (clock->now.tm_sec > 1 && clock->now.tm_sec < 59) { + /* we are more than 1 sec off => fix the timing + * FIXME: we might be 59 secs off and will not see that! */ + oc_start_timer(clock); + } + + return(TRUE); +} + static gboolean oc_get_time_delay(Clock *clock) { + oc_get_time(clock); /* update clock */ /* now we really start the clock */ - oc_get_time(clock); clock->timeout_id = g_timeout_add_full(G_PRIORITY_DEFAULT_IDLE - , clock->interval, (GSourceFunc)oc_get_time, clock, NULL); + , clock->interval, (GSourceFunc)oc_get_time_and_tune, clock, NULL); return(FALSE); /* this is one time only timer */ } -gboolean oc_start_timer(Clock *clock) +void oc_start_timer(Clock *clock) { - time_t t; gint delay_time; /* this is used to set the clock start tie correct */ /* @@ -131,29 +143,28 @@ g_source_remove(clock->timeout_id); clock->timeout_id = 0; } + if (clock->delay_timeout_id) { + g_source_remove(clock->delay_timeout_id); + clock->delay_timeout_id = 0; + } oc_get_time(clock); /* put time on the clock and also fill clock->now */ /* if we are using longer than 1 second (== 1000) interval, we need * to delay the first start so that clock changes when minute or hour * changes */ - if (clock->interval <= 1000) /* no adjustment needed, we show seconds */ - delay_time = 100; /* small delay since 0 is a bit scary */ - else if (clock->interval <= 60000) /* adjust to next full minute */ - delay_time = (clock->interval - clock->now.tm_sec*1000); - else /* if (clock->interval <= 3600000) */ /* adjust to next full hour */ - delay_time = (clock->interval - + if (clock->interval <= 1000) { /* no adjustment needed, we show seconds */ + clock->timeout_id = g_timeout_add_full(G_PRIORITY_DEFAULT_IDLE + , clock->interval, (GSourceFunc)oc_get_time, clock, NULL); + } + else { /* need to tune time */ + if (clock->interval <= 60000) /* adjust to next full minute */ + delay_time = (clock->interval - clock->now.tm_sec*1000); + else /* if (clock->interval <= 3600000) *//* adjust to next full hour */ + delay_time = (clock->interval - (clock->now.tm_min*60000 + clock->now.tm_sec*1000)); - if (clock->delay_timeout_id) { - g_source_remove(clock->delay_timeout_id); - clock->delay_timeout_id = 0; + clock->delay_timeout_id = g_timeout_add_full(G_PRIORITY_DEFAULT_IDLE + , delay_time, (GSourceFunc)oc_get_time_delay, clock, NULL); } - clock->delay_timeout_id = g_timeout_add_full(G_PRIORITY_DEFAULT_IDLE - , delay_time, (GSourceFunc)oc_get_time_delay, clock, NULL); - - /* if we have longer than 1 sec timer, we need to reschedule - * it regularly since it will fall wrong slowly but surely, so - * we keep this running. */ - return(TRUE); } gboolean oc_check_if_same(Clock *clock, int diff) @@ -214,17 +225,11 @@ void oc_tune_interval(Clock *clock) { - gboolean same_time; - - if (clock->adjust_timeout_id) { - g_source_remove(clock->adjust_timeout_id); - clock->adjust_timeout_id = 0; - } /* check if clock changes after 2 secs */ - if ((same_time = oc_check_if_same(clock, 2))) { /* Continue checking */ + if (oc_check_if_same(clock, 2)) { /* Continue checking */ /* We know now that clock does not change every second. * Let's check 2 minutes next: */ - if ((same_time = oc_check_if_same(clock, 2*60))) { + if (oc_check_if_same(clock, 2*60)) { /* We know now that clock does not change every minute. * We could check hours next, but cpu saving between 1 hour and 24 * hours would be minimal. But keeping 24 hour wake up time clock @@ -235,10 +240,6 @@ else { /* we schedule clock to fire every minute */ clock->interval = 60000; } - /* Our timer runs slow ( every minute or every hour only), so we need - * to resync time regularly (every 4 hours) to keep clock in time: */ - clock->adjust_timeout_id = g_timeout_add_full(G_PRIORITY_DEFAULT_IDLE - , 4*60*60*1000, (GSourceFunc)oc_start_timer, clock, NULL); } } Modified: xfcalendar/trunk/panel-plugin/orageclock.h =================================================================== --- xfcalendar/trunk/panel-plugin/orageclock.h 2008-11-15 20:53:38 UTC (rev 28826) +++ xfcalendar/trunk/panel-plugin/orageclock.h 2008-11-16 10:29:43 UTC (rev 28827) @@ -59,7 +59,6 @@ GtkTooltips *tips; int timeout_id; /* timer id for the clock */ int delay_timeout_id; - int adjust_timeout_id; int interval; struct tm now; } Clock; @@ -75,6 +74,6 @@ void oc_line_font_set(Clock *clock, gint lno); void oc_hib_timing_set(Clock *clock); void oc_write_rc_file(XfcePanelPlugin *plugin, Clock *clock); -gboolean oc_start_timer(Clock *clock); +void oc_start_timer(Clock *clock); void oc_init_timer(Clock *clock); _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org http://foo-projects.org/mailman/listinfo/xfce4-commits