File: | rc/gs-watcher-x11.c |
Warning: | line 596, column 2 Value stored to 'desired_server_interval' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- |
2 | * |
3 | * Copyright (C) 2004-2006 William Jon McCann <mccann@jhu.edu> |
4 | * Copyright (C) 2008 Red Hat, Inc. |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation; either version 2 of the License, or |
9 | * (at your option) any later version. |
10 | * |
11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU General Public License |
17 | * along with this program; if not, write to the Free Software |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. |
19 | * |
20 | * Authors: William Jon McCann <mccann@jhu.edu> |
21 | * |
22 | */ |
23 | |
24 | #include "config.h" |
25 | #include <stdlib.h> |
26 | #include <stdio.h> |
27 | #include <time.h> |
28 | #include <errno(*__errno_location ()).h> |
29 | |
30 | #include <string.h> |
31 | #include <cdk/cdkx.h> |
32 | |
33 | #include <dbus/dbus.h> |
34 | #include <dbus/dbus-glib.h> |
35 | |
36 | #include "gs-watcher.h" |
37 | #include "gs-marshal.h" |
38 | #include "gs-debug.h" |
39 | |
40 | static void gs_watcher_finalize (GObject *object); |
41 | |
42 | static gboolean watchdog_timer (GSWatcher *watcher); |
43 | |
44 | struct GSWatcherPrivate |
45 | { |
46 | /* settings */ |
47 | guint enabled : 1; |
48 | guint delta_notice_timeout; |
49 | |
50 | /* state */ |
51 | guint active : 1; |
52 | guint idle : 1; |
53 | guint idle_notice : 1; |
54 | |
55 | guint idle_id; |
56 | char *status_message; |
57 | |
58 | DBusGProxy *presence_proxy; |
59 | guint watchdog_timer_id; |
60 | }; |
61 | |
62 | enum |
63 | { |
64 | PROP_0, |
65 | PROP_STATUS_MESSAGE |
66 | }; |
67 | |
68 | enum |
69 | { |
70 | IDLE_CHANGED, |
71 | IDLE_NOTICE_CHANGED, |
72 | LAST_SIGNAL |
73 | }; |
74 | |
75 | static guint signals [LAST_SIGNAL] = { 0, }; |
76 | |
77 | G_DEFINE_TYPE_WITH_PRIVATE (GSWatcher, gs_watcher, G_TYPE_OBJECT)static void gs_watcher_init (GSWatcher *self); static void gs_watcher_class_init (GSWatcherClass *klass); static GType gs_watcher_get_type_once (void); static gpointer gs_watcher_parent_class = ((void*)0) ; static gint GSWatcher_private_offset; static void gs_watcher_class_intern_init (gpointer klass) { gs_watcher_parent_class = g_type_class_peek_parent (klass); if (GSWatcher_private_offset != 0) g_type_class_adjust_private_offset (klass, &GSWatcher_private_offset); gs_watcher_class_init ((GSWatcherClass*) klass); } __attribute__ ((__unused__)) static inline gpointer gs_watcher_get_instance_private (GSWatcher * self) { return (((gpointer) ((guint8*) (self) + (glong) (GSWatcher_private_offset )))); } GType gs_watcher_get_type (void) { static gsize static_g_define_type_id = 0; if ((__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id ) == sizeof (gpointer), "Expression evaluates to false"); (void ) (0 ? (gpointer) *(&static_g_define_type_id) : ((void*)0 )); (!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id ) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (*(&static_g_define_type_id)) gapg_temp_newval; __typeof__ ((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id ); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5) ; gapg_temp_newval; })) && g_once_init_enter (&static_g_define_type_id )); }))) { GType g_define_type_id = gs_watcher_get_type_once ( ); (__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id ) == sizeof (gpointer), "Expression evaluates to false"); 0 ? (void) (*(&static_g_define_type_id) = (g_define_type_id) ) : (void) 0; g_once_init_leave ((&static_g_define_type_id ), (gsize) (g_define_type_id)); })); } return static_g_define_type_id ; } __attribute__ ((__noinline__)) static GType gs_watcher_get_type_once (void) { GType g_define_type_id = g_type_register_static_simple (((GType) ((20) << (2))), g_intern_static_string ("GSWatcher" ), sizeof (GSWatcherClass), (GClassInitFunc)(void (*)(void)) gs_watcher_class_intern_init , sizeof (GSWatcher), (GInstanceInitFunc)(void (*)(void)) gs_watcher_init , (GTypeFlags) 0); { {{ GSWatcher_private_offset = g_type_add_instance_private (g_define_type_id, sizeof (GSWatcherPrivate)); };} } return g_define_type_id ; } |
78 | |
79 | static void |
80 | remove_watchdog_timer (GSWatcher *watcher) |
81 | { |
82 | if (watcher->priv->watchdog_timer_id != 0) |
83 | { |
84 | g_source_remove (watcher->priv->watchdog_timer_id); |
85 | watcher->priv->watchdog_timer_id = 0; |
86 | } |
87 | } |
88 | |
89 | static void |
90 | add_watchdog_timer (GSWatcher *watcher, |
91 | glong timeout) |
92 | { |
93 | watcher->priv->watchdog_timer_id = g_timeout_add (timeout, |
94 | (GSourceFunc)watchdog_timer, |
95 | watcher); |
96 | } |
97 | |
98 | static void |
99 | gs_watcher_get_property (GObject *object, |
100 | guint prop_id, |
101 | GValue *value, |
102 | GParamSpec *pspec) |
103 | { |
104 | GSWatcher *self; |
105 | |
106 | self = GS_WATCHER (object)((((GSWatcher*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((object)), ((gs_watcher_get_type ())))))); |
107 | |
108 | switch (prop_id) |
109 | { |
110 | case PROP_STATUS_MESSAGE: |
111 | g_value_set_string (value, self->priv->status_message); |
112 | break; |
113 | default: |
114 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec)do { GObject *_glib__object = (GObject*) ((object)); GParamSpec *_glib__pspec = (GParamSpec*) ((pspec)); guint _glib__property_id = ((prop_id)); g_warning ("%s:%d: invalid %s id %u for \"%s\" of type '%s' in '%s'" , "gs-watcher-x11.c", 114, ("property"), _glib__property_id, _glib__pspec ->name, g_type_name ((((((GTypeClass*) (((GTypeInstance*) ( _glib__pspec))->g_class))->g_type)))), (g_type_name ((( (((GTypeClass*) (((GTypeInstance*) (_glib__object))->g_class ))->g_type)))))); } while (0); |
115 | break; |
116 | } |
117 | } |
118 | |
119 | static void |
120 | set_status_text (GSWatcher *watcher, |
121 | const char *text) |
122 | { |
123 | g_free (watcher->priv->status_message); |
124 | |
125 | watcher->priv->status_message = g_strdup (text)g_strdup_inline (text); |
126 | g_object_notify (G_OBJECT (watcher)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((watcher)), (((GType) ((20) << (2)))))))), "status-message"); |
127 | } |
128 | |
129 | static void |
130 | gs_watcher_set_property (GObject *object, |
131 | guint prop_id, |
132 | const GValue *value, |
133 | GParamSpec *pspec) |
134 | { |
135 | GSWatcher *self; |
136 | |
137 | self = GS_WATCHER (object)((((GSWatcher*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((object)), ((gs_watcher_get_type ())))))); |
138 | |
139 | switch (prop_id) |
140 | { |
141 | case PROP_STATUS_MESSAGE: |
142 | set_status_text (self, g_value_get_string (value)); |
143 | break; |
144 | default: |
145 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec)do { GObject *_glib__object = (GObject*) ((object)); GParamSpec *_glib__pspec = (GParamSpec*) ((pspec)); guint _glib__property_id = ((prop_id)); g_warning ("%s:%d: invalid %s id %u for \"%s\" of type '%s' in '%s'" , "gs-watcher-x11.c", 145, ("property"), _glib__property_id, _glib__pspec ->name, g_type_name ((((((GTypeClass*) (((GTypeInstance*) ( _glib__pspec))->g_class))->g_type)))), (g_type_name ((( (((GTypeClass*) (((GTypeInstance*) (_glib__object))->g_class ))->g_type)))))); } while (0); |
146 | break; |
147 | } |
148 | } |
149 | |
150 | static void |
151 | gs_watcher_class_init (GSWatcherClass *klass) |
152 | { |
153 | GObjectClass *object_class = G_OBJECT_CLASS (klass)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((klass)), (((GType) ((20) << (2)))))))); |
154 | |
155 | object_class->finalize = gs_watcher_finalize; |
156 | object_class->get_property = gs_watcher_get_property; |
157 | object_class->set_property = gs_watcher_set_property; |
158 | |
159 | g_object_class_install_property (object_class, |
160 | PROP_STATUS_MESSAGE, |
161 | g_param_spec_string ("status-message", |
162 | NULL((void*)0), |
163 | NULL((void*)0), |
164 | NULL((void*)0), |
165 | G_PARAM_READWRITE)); |
166 | |
167 | signals [IDLE_CHANGED] = |
168 | g_signal_new ("idle-changed", |
169 | G_TYPE_FROM_CLASS (object_class)(((GTypeClass*) (object_class))->g_type), |
170 | G_SIGNAL_RUN_LAST, |
171 | G_STRUCT_OFFSET (GSWatcherClass, idle_changed)((glong) __builtin_offsetof(GSWatcherClass, idle_changed)), |
172 | NULL((void*)0), |
173 | NULL((void*)0), |
174 | gs_marshal_BOOLEAN__BOOLEAN, |
175 | G_TYPE_BOOLEAN((GType) ((5) << (2))), |
176 | 1, G_TYPE_BOOLEAN((GType) ((5) << (2)))); |
177 | signals [IDLE_NOTICE_CHANGED] = |
178 | g_signal_new ("idle-notice-changed", |
179 | G_TYPE_FROM_CLASS (object_class)(((GTypeClass*) (object_class))->g_type), |
180 | G_SIGNAL_RUN_LAST, |
181 | G_STRUCT_OFFSET (GSWatcherClass, idle_notice_changed)((glong) __builtin_offsetof(GSWatcherClass, idle_notice_changed )), |
182 | NULL((void*)0), |
183 | NULL((void*)0), |
184 | gs_marshal_BOOLEAN__BOOLEAN, |
185 | G_TYPE_BOOLEAN((GType) ((5) << (2))), |
186 | 1, G_TYPE_BOOLEAN((GType) ((5) << (2)))); |
187 | } |
188 | |
189 | static gboolean |
190 | _gs_watcher_set_session_idle_notice (GSWatcher *watcher, |
191 | gboolean in_effect) |
192 | { |
193 | gboolean res; |
194 | |
195 | res = FALSE(0); |
196 | |
197 | if (in_effect != watcher->priv->idle_notice) |
198 | { |
199 | |
200 | g_signal_emit (watcher, signals [IDLE_NOTICE_CHANGED], 0, in_effect, &res); |
201 | if (res) |
202 | { |
203 | gs_debug ("Changing idle notice state: %d", in_effect)gs_debug_real (__func__, "gs-watcher-x11.c", 203, "Changing idle notice state: %d" , in_effect); |
204 | |
205 | watcher->priv->idle_notice = in_effect; |
206 | } |
207 | else |
208 | { |
209 | gs_debug ("Idle notice signal not handled: %d", in_effect)gs_debug_real (__func__, "gs-watcher-x11.c", 209, "Idle notice signal not handled: %d" , in_effect); |
210 | } |
211 | } |
212 | |
213 | return res; |
214 | } |
215 | |
216 | static gboolean |
217 | _gs_watcher_set_session_idle (GSWatcher *watcher, |
218 | gboolean is_idle) |
219 | { |
220 | gboolean res; |
221 | |
222 | res = FALSE(0); |
223 | |
224 | if (is_idle != watcher->priv->idle) |
225 | { |
226 | |
227 | g_signal_emit (watcher, signals [IDLE_CHANGED], 0, is_idle, &res); |
228 | if (res) |
229 | { |
230 | gs_debug ("Changing idle state: %d", is_idle)gs_debug_real (__func__, "gs-watcher-x11.c", 230, "Changing idle state: %d" , is_idle); |
231 | |
232 | watcher->priv->idle = is_idle; |
233 | } |
234 | else |
235 | { |
236 | gs_debug ("Idle changed signal not handled: %d", is_idle)gs_debug_real (__func__, "gs-watcher-x11.c", 236, "Idle changed signal not handled: %d" , is_idle); |
237 | } |
238 | } |
239 | |
240 | return res; |
241 | } |
242 | |
243 | gboolean |
244 | gs_watcher_get_active (GSWatcher *watcher) |
245 | { |
246 | gboolean active; |
247 | |
248 | g_return_val_if_fail (GS_IS_WATCHER (watcher), FALSE)do{ (void)0; }while (0); |
249 | |
250 | active = watcher->priv->active; |
251 | |
252 | return active; |
253 | } |
254 | |
255 | static void |
256 | _gs_watcher_reset_state (GSWatcher *watcher) |
257 | { |
258 | watcher->priv->idle = FALSE(0); |
259 | watcher->priv->idle_notice = FALSE(0); |
260 | } |
261 | |
262 | static gboolean |
263 | _gs_watcher_set_active_internal (GSWatcher *watcher, |
264 | gboolean active) |
265 | { |
266 | if (active != watcher->priv->active) |
267 | { |
268 | /* reset state */ |
269 | _gs_watcher_reset_state (watcher); |
270 | |
271 | watcher->priv->active = active; |
272 | } |
273 | |
274 | return TRUE(!(0)); |
275 | } |
276 | |
277 | gboolean |
278 | gs_watcher_set_active (GSWatcher *watcher, |
279 | gboolean active) |
280 | { |
281 | g_return_val_if_fail (GS_IS_WATCHER (watcher), FALSE)do{ (void)0; }while (0); |
282 | |
283 | gs_debug ("turning watcher: %s", active ? "ON" : "OFF")gs_debug_real (__func__, "gs-watcher-x11.c", 283, "turning watcher: %s" , active ? "ON" : "OFF"); |
284 | |
285 | if (watcher->priv->active == active) |
286 | { |
287 | gs_debug ("Idle detection is already %s",gs_debug_real (__func__, "gs-watcher-x11.c", 288, "Idle detection is already %s" , active ? "active" : "inactive") |
288 | active ? "active" : "inactive")gs_debug_real (__func__, "gs-watcher-x11.c", 288, "Idle detection is already %s" , active ? "active" : "inactive"); |
289 | return FALSE(0); |
290 | } |
291 | |
292 | if (! watcher->priv->enabled) |
293 | { |
294 | gs_debug ("Idle detection is disabled, cannot activate")gs_debug_real (__func__, "gs-watcher-x11.c", 294, "Idle detection is disabled, cannot activate" ); |
295 | return FALSE(0); |
296 | } |
297 | |
298 | return _gs_watcher_set_active_internal (watcher, active); |
299 | } |
300 | |
301 | gboolean |
302 | gs_watcher_set_enabled (GSWatcher *watcher, |
303 | gboolean enabled) |
304 | { |
305 | g_return_val_if_fail (GS_IS_WATCHER (watcher), FALSE)do{ (void)0; }while (0); |
306 | |
307 | if (watcher->priv->enabled != enabled) |
308 | { |
309 | gboolean is_active = gs_watcher_get_active (watcher); |
310 | |
311 | watcher->priv->enabled = enabled; |
312 | |
313 | /* if we are disabling the watcher and we are |
314 | active shut it down */ |
315 | if (! enabled && is_active) |
316 | { |
317 | _gs_watcher_set_active_internal (watcher, FALSE(0)); |
318 | } |
319 | } |
320 | |
321 | return TRUE(!(0)); |
322 | } |
323 | |
324 | gboolean |
325 | gs_watcher_get_enabled (GSWatcher *watcher) |
326 | { |
327 | gboolean enabled; |
328 | |
329 | g_return_val_if_fail (GS_IS_WATCHER (watcher), FALSE)do{ (void)0; }while (0); |
330 | |
331 | enabled = watcher->priv->enabled; |
332 | |
333 | return enabled; |
334 | } |
335 | |
336 | static gboolean |
337 | on_idle_timeout (GSWatcher *watcher) |
338 | { |
339 | gboolean res; |
340 | |
341 | res = _gs_watcher_set_session_idle (watcher, TRUE(!(0))); |
342 | |
343 | _gs_watcher_set_session_idle_notice (watcher, FALSE(0)); |
344 | |
345 | /* try again if we failed i guess */ |
346 | return !res; |
347 | } |
348 | |
349 | static void |
350 | set_status (GSWatcher *watcher, |
351 | guint status) |
352 | { |
353 | gboolean is_idle; |
354 | |
355 | if (! watcher->priv->active) |
356 | { |
357 | gs_debug ("GSWatcher: not active, ignoring status changes")gs_debug_real (__func__, "gs-watcher-x11.c", 357, "GSWatcher: not active, ignoring status changes" ); |
358 | return; |
359 | } |
360 | |
361 | is_idle = (status == 3); |
362 | |
363 | if (!is_idle && !watcher->priv->idle_notice) |
364 | { |
365 | /* no change in idleness */ |
366 | return; |
367 | } |
368 | |
369 | if (is_idle) |
370 | { |
371 | _gs_watcher_set_session_idle_notice (watcher, is_idle); |
372 | /* queue an activation */ |
373 | if (watcher->priv->idle_id > 0) |
374 | { |
375 | g_source_remove (watcher->priv->idle_id); |
376 | } |
377 | watcher->priv->idle_id = g_timeout_add (watcher->priv->delta_notice_timeout, |
378 | (GSourceFunc)on_idle_timeout, |
379 | watcher); |
380 | } |
381 | else |
382 | { |
383 | /* cancel notice too */ |
384 | if (watcher->priv->idle_id > 0) |
385 | { |
386 | g_source_remove (watcher->priv->idle_id); |
387 | watcher->priv->idle_id = 0; |
388 | } |
389 | _gs_watcher_set_session_idle (watcher, FALSE(0)); |
390 | _gs_watcher_set_session_idle_notice (watcher, FALSE(0)); |
391 | } |
392 | } |
393 | |
394 | static void |
395 | on_presence_status_changed (DBusGProxy *presence_proxy, |
396 | guint status, |
397 | GSWatcher *watcher) |
398 | { |
399 | set_status (watcher, status); |
400 | } |
401 | |
402 | static void |
403 | on_presence_status_text_changed (DBusGProxy *presence_proxy, |
404 | const char *status_text, |
405 | GSWatcher *watcher) |
406 | { |
407 | set_status_text (watcher, status_text); |
408 | } |
409 | |
410 | static gboolean |
411 | connect_presence_watcher (GSWatcher *watcher) |
412 | { |
413 | DBusGConnection *bus; |
414 | GError *error; |
415 | gboolean ret; |
416 | |
417 | ret = FALSE(0); |
418 | |
419 | error = NULL((void*)0); |
420 | bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); |
421 | if (bus == NULL((void*)0)) |
422 | { |
423 | g_warning ("Unable to get session bus: %s", error->message); |
424 | g_error_free (error); |
425 | goto done; |
426 | } |
427 | |
428 | error = NULL((void*)0); |
429 | watcher->priv->presence_proxy = dbus_g_proxy_new_for_name_owner (bus, |
430 | "org.gnome.SessionManager", |
431 | "/org/gnome/SessionManager/Presence", |
432 | "org.gnome.SessionManager.Presence", |
433 | &error); |
434 | if (watcher->priv->presence_proxy != NULL((void*)0)) |
435 | { |
436 | DBusGProxy *proxy; |
437 | |
438 | dbus_g_proxy_add_signal (watcher->priv->presence_proxy, |
439 | "StatusChanged", |
440 | G_TYPE_UINT((GType) ((7) << (2))), |
441 | G_TYPE_INVALID((GType) ((0) << (2)))); |
442 | dbus_g_proxy_connect_signal (watcher->priv->presence_proxy, |
443 | "StatusChanged", |
444 | G_CALLBACK (on_presence_status_changed)((GCallback) (on_presence_status_changed)), |
445 | watcher, |
446 | NULL((void*)0)); |
447 | dbus_g_proxy_add_signal (watcher->priv->presence_proxy, |
448 | "StatusTextChanged", |
449 | G_TYPE_STRING((GType) ((16) << (2))), |
450 | G_TYPE_INVALID((GType) ((0) << (2)))); |
451 | dbus_g_proxy_connect_signal (watcher->priv->presence_proxy, |
452 | "StatusTextChanged", |
453 | G_CALLBACK (on_presence_status_text_changed)((GCallback) (on_presence_status_text_changed)), |
454 | watcher, |
455 | NULL((void*)0)); |
456 | |
457 | proxy = dbus_g_proxy_new_from_proxy (watcher->priv->presence_proxy, |
458 | "org.freedesktop.DBus.Properties", |
459 | "/org/gnome/SessionManager/Presence"); |
460 | if (proxy != NULL((void*)0)) |
461 | { |
462 | guint status; |
463 | const char *status_text; |
464 | GValue value = { 0, }; |
465 | |
466 | status = 0; |
467 | status_text = NULL((void*)0); |
468 | |
469 | error = NULL((void*)0); |
470 | dbus_g_proxy_call (proxy, |
471 | "Get", |
472 | &error, |
473 | G_TYPE_STRING((GType) ((16) << (2))), "org.gnome.SessionManager.Presence", |
474 | G_TYPE_STRING((GType) ((16) << (2))), "status", |
475 | G_TYPE_INVALID((GType) ((0) << (2))), |
476 | G_TYPE_VALUE(g_value_get_type ()), &value, |
477 | G_TYPE_INVALID((GType) ((0) << (2)))); |
478 | |
479 | if (error != NULL((void*)0)) |
480 | { |
481 | g_warning ("Couldn't get presence status: %s", error->message); |
482 | g_error_free (error); |
483 | goto done; |
484 | } |
485 | else |
486 | { |
487 | status = g_value_get_uint (&value); |
488 | } |
489 | |
490 | g_value_unset (&value); |
491 | |
492 | error = NULL((void*)0); |
493 | dbus_g_proxy_call (proxy, |
494 | "Get", |
495 | &error, |
496 | G_TYPE_STRING((GType) ((16) << (2))), "org.gnome.SessionManager.Presence", |
497 | G_TYPE_STRING((GType) ((16) << (2))), "status-text", |
498 | G_TYPE_INVALID((GType) ((0) << (2))), |
499 | G_TYPE_VALUE(g_value_get_type ()), &value, |
500 | G_TYPE_INVALID((GType) ((0) << (2)))); |
501 | |
502 | if (error != NULL((void*)0)) |
503 | { |
504 | g_warning ("Couldn't get presence status text: %s", error->message); |
505 | g_error_free (error); |
506 | } |
507 | else |
508 | { |
509 | status_text = g_value_get_string (&value); |
510 | } |
511 | |
512 | set_status (watcher, status); |
513 | set_status_text (watcher, status_text); |
514 | } |
515 | } |
516 | else |
517 | { |
518 | g_warning ("Failed to get session presence proxy: %s", error->message); |
519 | g_error_free (error); |
520 | goto done; |
521 | } |
522 | |
523 | ret = TRUE(!(0)); |
524 | |
525 | done: |
526 | return ret; |
527 | } |
528 | |
529 | static void |
530 | gs_watcher_init (GSWatcher *watcher) |
531 | { |
532 | watcher->priv = gs_watcher_get_instance_private (watcher); |
533 | |
534 | watcher->priv->enabled = TRUE(!(0)); |
535 | watcher->priv->active = FALSE(0); |
536 | |
537 | connect_presence_watcher (watcher); |
538 | |
539 | /* time before idle signal to send notice signal */ |
540 | watcher->priv->delta_notice_timeout = 10000; |
541 | |
542 | add_watchdog_timer (watcher, 600000); |
543 | } |
544 | |
545 | static void |
546 | gs_watcher_finalize (GObject *object) |
547 | { |
548 | GSWatcher *watcher; |
549 | |
550 | g_return_if_fail (object != NULL)do{ (void)0; }while (0); |
551 | g_return_if_fail (GS_IS_WATCHER (object))do{ (void)0; }while (0); |
552 | |
553 | watcher = GS_WATCHER (object)((((GSWatcher*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((object)), ((gs_watcher_get_type ())))))); |
554 | |
555 | g_return_if_fail (watcher->priv != NULL)do{ (void)0; }while (0); |
556 | |
557 | remove_watchdog_timer (watcher); |
558 | |
559 | if (watcher->priv->idle_id > 0) |
560 | { |
561 | g_source_remove (watcher->priv->idle_id); |
562 | watcher->priv->idle_id = 0; |
563 | } |
564 | |
565 | watcher->priv->active = FALSE(0); |
566 | |
567 | if (watcher->priv->presence_proxy != NULL((void*)0)) |
568 | { |
569 | g_object_unref (watcher->priv->presence_proxy); |
570 | } |
571 | |
572 | g_free (watcher->priv->status_message); |
573 | |
574 | G_OBJECT_CLASS (gs_watcher_parent_class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((gs_watcher_parent_class)), (((GType) ((20) << (2)) ))))))->finalize (object); |
575 | } |
576 | |
577 | /* Figuring out what the appropriate XSetScreenSaver() parameters are |
578 | (one wouldn't expect this to be rocket science.) |
579 | */ |
580 | static void |
581 | disable_builtin_screensaver (GSWatcher *watcher, |
582 | gboolean unblank_screen) |
583 | { |
584 | int current_server_timeout, current_server_interval; |
585 | int current_prefer_blank, current_allow_exp; |
586 | int desired_server_timeout, desired_server_interval; |
587 | int desired_prefer_blank, desired_allow_exp; |
588 | |
589 | XGetScreenSaver (CDK_DISPLAY_XDISPLAY (cdk_display_get_default ())(cdk_x11_display_get_xdisplay (cdk_display_get_default ())), |
590 | ¤t_server_timeout, |
591 | ¤t_server_interval, |
592 | ¤t_prefer_blank, |
593 | ¤t_allow_exp); |
594 | |
595 | desired_server_timeout = current_server_timeout; |
596 | desired_server_interval = current_server_interval; |
Value stored to 'desired_server_interval' is never read | |
597 | desired_prefer_blank = current_prefer_blank; |
598 | desired_allow_exp = current_allow_exp; |
599 | |
600 | desired_server_interval = 0; |
601 | |
602 | /* I suspect (but am not sure) that DontAllowExposures might have |
603 | something to do with powering off the monitor as well, at least |
604 | on some systems that don't support XDPMS? Who know... */ |
605 | desired_allow_exp = AllowExposures1; |
606 | |
607 | /* When we're not using an extension, set the server-side timeout to 0, |
608 | so that the server never gets involved with screen blanking, and we |
609 | do it all ourselves. (However, when we *are* using an extension, |
610 | we tell the server when to notify us, and rather than blanking the |
611 | screen, the server will send us an X event telling us to blank.) |
612 | */ |
613 | desired_server_timeout = 0; |
614 | |
615 | if (desired_server_timeout != current_server_timeout |
616 | || desired_server_interval != current_server_interval |
617 | || desired_prefer_blank != current_prefer_blank |
618 | || desired_allow_exp != current_allow_exp) |
619 | { |
620 | |
621 | gs_debug ("disabling server builtin screensaver:"gs_debug_real (__func__, "gs-watcher-x11.c", 626, "disabling server builtin screensaver:" " (xset s %d %d; xset s %s; xset s %s)", desired_server_timeout , desired_server_interval, (desired_prefer_blank ? "blank" : "noblank" ), (desired_allow_exp ? "expose" : "noexpose")) |
622 | " (xset s %d %d; xset s %s; xset s %s)",gs_debug_real (__func__, "gs-watcher-x11.c", 626, "disabling server builtin screensaver:" " (xset s %d %d; xset s %s; xset s %s)", desired_server_timeout , desired_server_interval, (desired_prefer_blank ? "blank" : "noblank" ), (desired_allow_exp ? "expose" : "noexpose")) |
623 | desired_server_timeout,gs_debug_real (__func__, "gs-watcher-x11.c", 626, "disabling server builtin screensaver:" " (xset s %d %d; xset s %s; xset s %s)", desired_server_timeout , desired_server_interval, (desired_prefer_blank ? "blank" : "noblank" ), (desired_allow_exp ? "expose" : "noexpose")) |
624 | desired_server_interval,gs_debug_real (__func__, "gs-watcher-x11.c", 626, "disabling server builtin screensaver:" " (xset s %d %d; xset s %s; xset s %s)", desired_server_timeout , desired_server_interval, (desired_prefer_blank ? "blank" : "noblank" ), (desired_allow_exp ? "expose" : "noexpose")) |
625 | (desired_prefer_blank ? "blank" : "noblank"),gs_debug_real (__func__, "gs-watcher-x11.c", 626, "disabling server builtin screensaver:" " (xset s %d %d; xset s %s; xset s %s)", desired_server_timeout , desired_server_interval, (desired_prefer_blank ? "blank" : "noblank" ), (desired_allow_exp ? "expose" : "noexpose")) |
626 | (desired_allow_exp ? "expose" : "noexpose"))gs_debug_real (__func__, "gs-watcher-x11.c", 626, "disabling server builtin screensaver:" " (xset s %d %d; xset s %s; xset s %s)", desired_server_timeout , desired_server_interval, (desired_prefer_blank ? "blank" : "noblank" ), (desired_allow_exp ? "expose" : "noexpose")); |
627 | |
628 | XSetScreenSaver (CDK_DISPLAY_XDISPLAY (cdk_display_get_default ())(cdk_x11_display_get_xdisplay (cdk_display_get_default ())), |
629 | desired_server_timeout, |
630 | desired_server_interval, |
631 | desired_prefer_blank, |
632 | desired_allow_exp); |
633 | |
634 | XSync (CDK_DISPLAY_XDISPLAY (cdk_display_get_default ())(cdk_x11_display_get_xdisplay (cdk_display_get_default ())), FALSE(0)); |
635 | } |
636 | |
637 | if (unblank_screen) |
638 | { |
639 | /* Turn off the server builtin saver if it is now running. */ |
640 | XForceScreenSaver (CDK_DISPLAY_XDISPLAY (cdk_display_get_default ())(cdk_x11_display_get_xdisplay (cdk_display_get_default ())), ScreenSaverReset0); |
641 | } |
642 | } |
643 | |
644 | |
645 | /* This timer goes off every few minutes, whether the user is idle or not, |
646 | to try and clean up anything that has gone wrong. |
647 | |
648 | It calls disable_builtin_screensaver() so that if xset has been used, |
649 | or some other program (like xlock) has messed with the XSetScreenSaver() |
650 | settings, they will be set back to sensible values (if a server extension |
651 | is in use, messing with xlock can cause the screensaver to never get a wakeup |
652 | event, and could cause monitor power-saving to occur, and all manner of |
653 | heinousness.) |
654 | |
655 | */ |
656 | |
657 | static gboolean |
658 | watchdog_timer (GSWatcher *watcher) |
659 | { |
660 | |
661 | disable_builtin_screensaver (watcher, FALSE(0)); |
662 | |
663 | return TRUE(!(0)); |
664 | } |
665 | |
666 | GSWatcher * |
667 | gs_watcher_new (void) |
668 | { |
669 | GSWatcher *watcher; |
670 | |
671 | watcher = g_object_new (GS_TYPE_WATCHER(gs_watcher_get_type ()), |
672 | NULL((void*)0)); |
673 | |
674 | return GS_WATCHER (watcher)((((GSWatcher*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((watcher)), ((gs_watcher_get_type ())))))); |
675 | } |