1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
From 9f98f3a20b5eec6a1fa13e5a4972eadc2d728acf Mon Sep 17 00:00:00 2001
From: Alexandre Rostovtsev <tetromino@gmail.com>
Date: Wed, 20 Jul 2011 18:00:43 +0000
Subject: gs-window-x11: shorten clock timeout to detect skew
The timer for the panel clock currently wakes up once a minute in
the default case. This means, if the clock changes while the
screen is locked (say from a resume following suspend, or from
ntp) then it becomes out of date for up to a minute.
There's no good way right now to detect when clock skew happens,
so this commit changes the timeout to expire every couple of
seconds instead of once a minute.
Minor-Updates-By: Ray Strode <rstrode@redhat.com>
http://bugzilla.gnome.org/show_bug.cgi?id=648145
---
diff --git a/src/gs-window-x11.c b/src/gs-window-x11.c
index e7a475e..a723c4d 100644
--- a/src/gs-window-x11.c
+++ b/src/gs-window-x11.c
@@ -26,6 +26,7 @@
#include <errno.h>
#include <sys/wait.h>
#include <string.h>
+#include <stdlib.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
@@ -101,6 +102,8 @@ struct GSWindowPrivate
guint info_bar_timer_id;
guint clock_update_id;
+ gint64 clock_update_time;
+
gint lock_pid;
gint lock_watch_id;
gint dialog_response;
@@ -2201,7 +2204,8 @@ update_clock (GSWindow *window)
/* Translators, this is the 12h date format used in the panel clock */
clock_format = _("%a %l:%M %p");
- dt = g_date_time_new_now_local ();
+ window->priv->clock_update_time = g_get_real_time ();
+ dt = g_date_time_new_from_unix_local (window->priv->clock_update_time / G_USEC_PER_SEC);
text = g_date_time_format (dt, clock_format);
markup = g_strdup_printf ("<b><span foreground=\"#ccc\">%s</span></b>", text);
gtk_label_set_markup (GTK_LABEL (window->priv->clock), markup);
@@ -2219,6 +2223,28 @@ update_clock_timer (GSWindow *window)
return FALSE;
}
+static gboolean
+check_clock_timer (GSWindow *window)
+{
+ /* Update the panel clock when necessary.
+ This happens:
+
+ - Once a minute in the normal case
+ - When the machine resumes from suspend
+ - When the system time is adjusted
+
+ Right now this function is called much more frequently than any of the
+ above 3 events happen (see queue_clock_update ()).
+
+ We can wake up less often if bug 655129 gets fixed. */
+ if (ABS (g_get_real_time () - window->priv->clock_update_time) > 60 * G_USEC_PER_SEC) {
+ update_clock (window);
+ }
+
+ queue_clock_update (window);
+ return FALSE;
+}
+
static void
queue_clock_update (GSWindow *window)
{
@@ -2228,10 +2254,17 @@ queue_clock_update (GSWindow *window)
gettimeofday (&tv, NULL);
timeouttime = (G_USEC_PER_SEC - tv.tv_usec) / 1000 + 1;
- /* timeout of one minute if we don't care about the seconds */
+ /* time until next minute */
timeouttime += 1000 * (59 - tv.tv_sec % 60);
- window->priv->clock_update_id = g_timeout_add (timeouttime, (GSourceFunc)update_clock_timer, window);
+ /* If we are more than 2.5 seconds from the start of the next minute,
+ schedule less precise but more power friendly 2 second add_seconds
+ timeout to check if the system realtime clock has changed under us. */
+ if (timeouttime > 2500) {
+ window->priv->clock_update_id = g_timeout_add_seconds (2, (GSourceFunc)check_clock_timer, window);
+ } else {
+ window->priv->clock_update_id = g_timeout_add (timeouttime, (GSourceFunc)update_clock_timer, window);
+ }
}
static char *
--
cgit v0.9
|