Merge lp:~robert-ancell/unity-settings-daemon/idle into lp:unity-settings-daemon

Proposed by Robert Ancell
Status: Rejected
Rejected by: Robert Ancell
Proposed branch: lp:~robert-ancell/unity-settings-daemon/idle
Merge into: lp:unity-settings-daemon
Diff against target: 950 lines (+734/-37)
6 files modified
configure.ac (+2/-2)
plugins/common/Makefile.am (+2/-0)
plugins/common/gsd-idle-monitor.c (+616/-0)
plugins/common/gsd-idle-monitor.h (+81/-0)
plugins/cursor/gsd-cursor-manager.c (+8/-10)
plugins/power/gsd-power-manager.c (+25/-25)
To merge this branch: bzr merge lp:~robert-ancell/unity-settings-daemon/idle
Reviewer Review Type Date Requested Status
Robert Ancell Needs Fixing
Sebastien Bacher Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+228953@code.launchpad.net

Commit message

Bring unstable idle timer code from gnome-desktop into unity-settings-daemon

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Sebastien Bacher (seb128) wrote :

That's quite some changes to review, but mostly a copy of existing code, not I don't think it needs a detailled code review. The changes look fine to me on principle but we should give that a proper round of testing, including multimonitor setups and screensaver/idle usecases

review: Approve
Revision history for this message
Tim Lunn (darkxst) wrote :

This lgtm, lots of cut+paste and a bit of renaming, don't think it will cause any issues

Revision history for this message
Robert Ancell (robert-ancell) wrote :

This doesn't work because the two plugins both have copies of the GsdIdleMonitor class and try and register it twice. If the code is to be shared it needs to go into a shared library or two copies with different names.

review: Needs Fixing
Revision history for this message
Robert Ancell (robert-ancell) wrote :

Unmerged revisions

4045. By Robert Ancell

Bring unstable idle timer code from gnome-desktop into unity-settings-daemon

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'configure.ac'
2--- configure.ac 2014-02-15 08:33:21 +0000
3+++ configure.ac 2014-07-30 22:27:08 +0000
4@@ -137,7 +137,7 @@
5 dnl - common
6 dnl ---------------------------------------------------------------------------
7
8-PKG_CHECK_MODULES(COMMON, x11 kbproto xi)
9+PKG_CHECK_MODULES(COMMON, x11 kbproto xi xext)
10
11 dnl ---------------------------------------------------------------------------
12 dnl - automount
13@@ -169,7 +169,7 @@
14 dnl - cursor
15 dnl ---------------------------------------------------------------------------
16
17-PKG_CHECK_MODULES(CURSOR, xfixes gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED_VERSION)
18+PKG_CHECK_MODULES(CURSOR, xfixes)
19
20 dnl ---------------------------------------------------------------------------
21 dnl - xsettings
22
23=== modified file 'plugins/common/Makefile.am'
24--- plugins/common/Makefile.am 2013-12-04 23:55:26 +0000
25+++ plugins/common/Makefile.am 2014-07-30 22:27:08 +0000
26@@ -5,6 +5,8 @@
27 libcommon_la_SOURCES = \
28 gsd-keygrab.c \
29 gsd-keygrab.h \
30+ gsd-idle-monitor.c \
31+ gsd-idle-monitor.h \
32 gsd-input-helper.c \
33 gsd-input-helper.h
34
35
36=== added file 'plugins/common/gsd-idle-monitor.c'
37--- plugins/common/gsd-idle-monitor.c 1970-01-01 00:00:00 +0000
38+++ plugins/common/gsd-idle-monitor.c 2014-07-30 22:27:08 +0000
39@@ -0,0 +1,616 @@
40+/* -*- mode: C; c-file-style: "linux"; indent-tabs-mode: t -*-
41+ *
42+ * Adapted from gnome-session/gnome-session/gs-idle-monitor.c
43+ *
44+ * Copyright (C) 2012 Red Hat, Inc.
45+ *
46+ * This program is free software; you can redistribute it and/or modify
47+ * it under the terms of the GNU General Public License as published by
48+ * the Free Software Foundation; either version 2 of the License, or
49+ * (at your option) any later version.
50+ *
51+ * This program is distributed in the hope that it will be useful,
52+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
53+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
54+ * GNU General Public License for more details.
55+ *
56+ * You should have received a copy of the GNU General Public License
57+ * along with this program; if not, write to the Free Software
58+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
59+ */
60+
61+#include "config.h"
62+
63+#include <time.h>
64+#include <string.h>
65+
66+#include <X11/Xlib.h>
67+#include <X11/extensions/sync.h>
68+
69+#include <glib.h>
70+#include <gdk/gdkx.h>
71+#include <gdk/gdk.h>
72+
73+#include "gsd-idle-monitor.h"
74+
75+#define GSD_IDLE_MONITOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_IDLE_MONITOR, GsdIdleMonitorPrivate))
76+
77+G_STATIC_ASSERT(sizeof(unsigned long) == sizeof(gpointer));
78+
79+struct _GsdIdleMonitorPrivate
80+{
81+ Display *display;
82+
83+ GHashTable *watches;
84+ GHashTable *alarms;
85+ int sync_event_base;
86+ XSyncCounter counter;
87+
88+ XSyncAlarm user_active_alarm;
89+
90+ GdkDevice *device;
91+};
92+
93+typedef struct
94+{
95+ GsdIdleMonitor *monitor;
96+ guint id;
97+ GsdIdleMonitorWatchFunc callback;
98+ gpointer user_data;
99+ GDestroyNotify notify;
100+ XSyncAlarm xalarm;
101+} GsdIdleMonitorWatch;
102+
103+enum
104+{
105+ PROP_0,
106+ PROP_DEVICE,
107+ PROP_LAST,
108+};
109+
110+static GParamSpec *obj_props[PROP_LAST];
111+
112+static void gsd_idle_monitor_initable_iface_init (GInitableIface *iface);
113+
114+G_DEFINE_TYPE_WITH_CODE (GsdIdleMonitor, gsd_idle_monitor, G_TYPE_OBJECT,
115+ G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
116+ gsd_idle_monitor_initable_iface_init))
117+
118+static gint64
119+_xsyncvalue_to_int64 (XSyncValue value)
120+{
121+ return ((guint64) XSyncValueHigh32 (value)) << 32
122+ | (guint64) XSyncValueLow32 (value);
123+}
124+
125+#define GINT64_TO_XSYNCVALUE(value, ret) XSyncIntsToValue (ret, value, ((guint64)value) >> 32)
126+
127+static XSyncAlarm
128+_xsync_alarm_set (GsdIdleMonitor *monitor,
129+ XSyncTestType test_type,
130+ guint64 interval,
131+ gboolean want_events)
132+{
133+ XSyncAlarmAttributes attr;
134+ XSyncValue delta;
135+ guint flags;
136+
137+ flags = XSyncCACounter | XSyncCAValueType | XSyncCATestType |
138+ XSyncCAValue | XSyncCADelta | XSyncCAEvents;
139+
140+ XSyncIntToValue (&delta, 0);
141+ attr.trigger.counter = monitor->priv->counter;
142+ attr.trigger.value_type = XSyncAbsolute;
143+ attr.delta = delta;
144+ attr.events = want_events;
145+
146+ GINT64_TO_XSYNCVALUE (interval, &attr.trigger.wait_value);
147+ attr.trigger.test_type = test_type;
148+ return XSyncCreateAlarm (monitor->priv->display, flags, &attr);
149+}
150+
151+static void
152+ensure_alarm_rescheduled (Display *dpy,
153+ XSyncAlarm alarm)
154+{
155+ XSyncAlarmAttributes attr;
156+
157+ /* Some versions of Xorg have an issue where alarms aren't
158+ * always rescheduled. Calling XSyncChangeAlarm, even
159+ * without any attributes, will reschedule the alarm. */
160+ XSyncChangeAlarm (dpy, alarm, 0, &attr);
161+}
162+
163+static void
164+set_alarm_enabled (Display *dpy,
165+ XSyncAlarm alarm,
166+ gboolean enabled)
167+{
168+ XSyncAlarmAttributes attr;
169+ attr.events = enabled;
170+ XSyncChangeAlarm (dpy, alarm, XSyncCAEvents, &attr);
171+}
172+
173+static void
174+fire_watch (gpointer data,
175+ gpointer user_data)
176+{
177+ GsdIdleMonitorWatch *watch = data;
178+ XSyncAlarm alarm = (XSyncAlarm) user_data;
179+ GsdIdleMonitor *monitor;
180+
181+ if (watch->xalarm != alarm) {
182+ return;
183+ }
184+
185+ monitor = watch->monitor;
186+ g_object_ref (monitor);
187+
188+ if (watch->callback) {
189+ watch->callback (watch->monitor,
190+ watch->id,
191+ watch->user_data);
192+ }
193+
194+ if (watch->xalarm == monitor->priv->user_active_alarm) {
195+ gsd_idle_monitor_remove_watch (monitor, watch->id);
196+ }
197+
198+ g_object_unref (monitor);
199+}
200+
201+static void
202+handle_alarm_notify_event (GsdIdleMonitor *monitor,
203+ XSyncAlarmNotifyEvent *alarm_event)
204+{
205+ XSyncAlarm alarm;
206+ GList *watches;
207+ gboolean has_alarm;
208+
209+ if (alarm_event->state != XSyncAlarmActive) {
210+ return;
211+ }
212+
213+ alarm = alarm_event->alarm;
214+
215+ has_alarm = FALSE;
216+
217+ if (alarm == monitor->priv->user_active_alarm) {
218+ set_alarm_enabled (monitor->priv->display,
219+ alarm,
220+ FALSE);
221+ has_alarm = TRUE;
222+ } else if (g_hash_table_contains (monitor->priv->alarms, (gpointer) alarm)) {
223+ ensure_alarm_rescheduled (monitor->priv->display,
224+ alarm);
225+ has_alarm = TRUE;
226+ }
227+
228+ if (has_alarm) {
229+ watches = g_hash_table_get_values (monitor->priv->watches);
230+
231+ g_list_foreach (watches,
232+ fire_watch,
233+ (gpointer) alarm);
234+
235+ g_list_free (watches);
236+ }
237+}
238+
239+static GdkFilterReturn
240+xevent_filter (GdkXEvent *xevent,
241+ GdkEvent *event,
242+ GsdIdleMonitor *monitor)
243+{
244+ XEvent *ev;
245+ XSyncAlarmNotifyEvent *alarm_event;
246+
247+ ev = xevent;
248+ if (ev->xany.type != monitor->priv->sync_event_base + XSyncAlarmNotify) {
249+ return GDK_FILTER_CONTINUE;
250+ }
251+
252+ alarm_event = xevent;
253+ handle_alarm_notify_event (monitor, alarm_event);
254+
255+ return GDK_FILTER_CONTINUE;
256+}
257+
258+static char *
259+counter_name_for_device (GdkDevice *device)
260+{
261+ if (device) {
262+ gint device_id = gdk_x11_device_get_id (device);
263+ if (device_id > 0)
264+ return g_strdup_printf ("DEVICEIDLETIME %d", device_id);
265+ }
266+
267+ return g_strdup ("IDLETIME");
268+}
269+
270+static XSyncCounter
271+find_idletime_counter (GsdIdleMonitor *monitor)
272+{
273+ int i;
274+ int ncounters;
275+ XSyncSystemCounter *counters;
276+ XSyncCounter counter = None;
277+ char *counter_name;
278+
279+ counter_name = counter_name_for_device (monitor->priv->device);
280+ counters = XSyncListSystemCounters (monitor->priv->display, &ncounters);
281+ for (i = 0; i < ncounters; i++) {
282+ if (counters[i].name != NULL && strcmp (counters[i].name, counter_name) == 0) {
283+ counter = counters[i].counter;
284+ break;
285+ }
286+ }
287+ XSyncFreeSystemCounterList (counters);
288+ g_free (counter_name);
289+
290+ return counter;
291+}
292+
293+static guint32
294+get_next_watch_serial (void)
295+{
296+ static guint32 serial = 0;
297+ g_atomic_int_inc (&serial);
298+ return serial;
299+}
300+
301+static void
302+idle_monitor_watch_free (GsdIdleMonitorWatch *watch)
303+{
304+ GsdIdleMonitor *monitor;
305+
306+ if (watch == NULL) {
307+ return;
308+ }
309+
310+ monitor = watch->monitor;
311+
312+ if (watch->notify != NULL) {
313+ watch->notify (watch->user_data);
314+ }
315+
316+ if (watch->xalarm != monitor->priv->user_active_alarm) {
317+ XSyncDestroyAlarm (monitor->priv->display, watch->xalarm);
318+ g_hash_table_remove (monitor->priv->alarms, (gpointer) watch->xalarm);
319+ }
320+
321+ g_slice_free (GsdIdleMonitorWatch, watch);
322+}
323+
324+static void
325+init_xsync (GsdIdleMonitor *monitor)
326+{
327+ int sync_error_base;
328+ int res;
329+ int major;
330+ int minor;
331+
332+ res = XSyncQueryExtension (monitor->priv->display,
333+ &monitor->priv->sync_event_base,
334+ &sync_error_base);
335+ if (! res) {
336+ g_warning ("GsdIdleMonitor: Sync extension not present");
337+ return;
338+ }
339+
340+ res = XSyncInitialize (monitor->priv->display, &major, &minor);
341+ if (! res) {
342+ g_warning ("GsdIdleMonitor: Unable to initialize Sync extension");
343+ return;
344+ }
345+
346+ monitor->priv->counter = find_idletime_counter (monitor);
347+ /* IDLETIME counter not found? */
348+ if (monitor->priv->counter == None)
349+ return;
350+
351+ monitor->priv->user_active_alarm = _xsync_alarm_set (monitor, XSyncNegativeTransition, 1, FALSE);
352+
353+ gdk_window_add_filter (NULL, (GdkFilterFunc)xevent_filter, monitor);
354+}
355+
356+static void
357+gsd_idle_monitor_dispose (GObject *object)
358+{
359+ GsdIdleMonitor *monitor;
360+
361+ monitor = GSD_IDLE_MONITOR (object);
362+
363+ g_clear_pointer (&monitor->priv->watches, g_hash_table_destroy);
364+ g_clear_pointer (&monitor->priv->alarms, g_hash_table_destroy);
365+ g_clear_object (&monitor->priv->device);
366+
367+ if (monitor->priv->user_active_alarm != None) {
368+ XSyncDestroyAlarm (monitor->priv->display, monitor->priv->user_active_alarm);
369+ monitor->priv->user_active_alarm = None;
370+ }
371+
372+ gdk_window_remove_filter (NULL, (GdkFilterFunc)xevent_filter, monitor);
373+
374+ G_OBJECT_CLASS (gsd_idle_monitor_parent_class)->dispose (object);
375+}
376+
377+static void
378+gsd_idle_monitor_get_property (GObject *object,
379+ guint prop_id,
380+ GValue *value,
381+ GParamSpec *pspec)
382+{
383+ GsdIdleMonitor *monitor = GSD_IDLE_MONITOR (object);
384+ switch (prop_id)
385+ {
386+ case PROP_DEVICE:
387+ g_value_set_object (value, monitor->priv->device);
388+ break;
389+ default:
390+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
391+ break;
392+ }
393+}
394+
395+static void
396+gsd_idle_monitor_set_property (GObject *object,
397+ guint prop_id,
398+ const GValue *value,
399+ GParamSpec *pspec)
400+{
401+ GsdIdleMonitor *monitor = GSD_IDLE_MONITOR (object);
402+ switch (prop_id)
403+ {
404+ case PROP_DEVICE:
405+ monitor->priv->device = g_value_dup_object (value);
406+ break;
407+ default:
408+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
409+ break;
410+ }
411+}
412+
413+static void
414+gsd_idle_monitor_constructed (GObject *object)
415+{
416+ GsdIdleMonitor *monitor = GSD_IDLE_MONITOR (object);
417+
418+ monitor->priv->display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
419+ init_xsync (monitor);
420+}
421+
422+static gboolean
423+gsd_idle_monitor_initable_init (GInitable *initable,
424+ GCancellable *cancellable,
425+ GError **error)
426+{
427+ GsdIdleMonitor *monitor;
428+
429+ monitor = GSD_IDLE_MONITOR (initable);
430+
431+ if (monitor->priv->counter == None) {
432+ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
433+ "Per-device idletime is not supported");
434+ return FALSE;
435+ }
436+
437+ return TRUE;
438+}
439+
440+static void
441+gsd_idle_monitor_initable_iface_init (GInitableIface *iface)
442+{
443+ iface->init = gsd_idle_monitor_initable_init;
444+}
445+
446+static void
447+gsd_idle_monitor_class_init (GsdIdleMonitorClass *klass)
448+{
449+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
450+
451+ object_class->dispose = gsd_idle_monitor_dispose;
452+ object_class->constructed = gsd_idle_monitor_constructed;
453+ object_class->get_property = gsd_idle_monitor_get_property;
454+ object_class->set_property = gsd_idle_monitor_set_property;
455+
456+ /**
457+ * GsdIdleMonitor:device:
458+ *
459+ * The device to listen to idletime on.
460+ */
461+ obj_props[PROP_DEVICE] =
462+ g_param_spec_object ("device",
463+ "Device",
464+ "The device to listen to idletime on",
465+ GDK_TYPE_DEVICE,
466+ G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
467+ g_object_class_install_property (object_class, PROP_DEVICE, obj_props[PROP_DEVICE]);
468+
469+ g_type_class_add_private (klass, sizeof (GsdIdleMonitorPrivate));
470+}
471+
472+static void
473+gsd_idle_monitor_init (GsdIdleMonitor *monitor)
474+{
475+ monitor->priv = GSD_IDLE_MONITOR_GET_PRIVATE (monitor);
476+
477+ monitor->priv->watches = g_hash_table_new_full (NULL,
478+ NULL,
479+ NULL,
480+ (GDestroyNotify)idle_monitor_watch_free);
481+
482+ monitor->priv->alarms = g_hash_table_new (NULL, NULL);
483+}
484+
485+/**
486+ * gsd_idle_monitor_new:
487+ *
488+ * Returns: a new #GsdIdleMonitor that tracks the server-global
489+ * idletime for all devices. To track device-specific idletime,
490+ * use gsd_idle_monitor_new_for_device().
491+ */
492+GsdIdleMonitor *
493+gsd_idle_monitor_new (void)
494+{
495+ return GSD_IDLE_MONITOR (g_initable_new (GSD_TYPE_IDLE_MONITOR, NULL, NULL, NULL));
496+}
497+
498+/**
499+ * gsd_idle_monitor_new_for_device:
500+ * @device: A #GdkDevice to get the idle time for.
501+ *
502+ * Returns: a new #GsdIdleMonitor that tracks the device-specific
503+ * idletime for @device. If device-specific idletime is not available,
504+ * %NULL is returned, and @error is set. To track server-global
505+ * idletime for all devices, use gsd_idle_monitor_new().
506+ */
507+GsdIdleMonitor *
508+gsd_idle_monitor_new_for_device (GdkDevice *device)
509+{
510+ return GSD_IDLE_MONITOR (g_initable_new (GSD_TYPE_IDLE_MONITOR, NULL, NULL,
511+ "device", device, NULL));
512+}
513+
514+static GsdIdleMonitorWatch *
515+make_watch (GsdIdleMonitor *monitor,
516+ XSyncAlarm xalarm,
517+ GsdIdleMonitorWatchFunc callback,
518+ gpointer user_data,
519+ GDestroyNotify notify)
520+{
521+ GsdIdleMonitorWatch *watch;
522+
523+ watch = g_slice_new0 (GsdIdleMonitorWatch);
524+ watch->monitor = monitor;
525+ watch->id = get_next_watch_serial ();
526+ watch->callback = callback;
527+ watch->user_data = user_data;
528+ watch->notify = notify;
529+ watch->xalarm = xalarm;
530+
531+ g_hash_table_insert (monitor->priv->watches,
532+ GUINT_TO_POINTER (watch->id),
533+ watch);
534+ return watch;
535+}
536+
537+/**
538+ * gsd_idle_monitor_add_idle_watch:
539+ * @monitor: A #GsdIdleMonitor
540+ * @interval_msec: The idletime interval, in milliseconds
541+ * @callback: (allow-none): The callback to call when the user has
542+ * accumulated @interval_msec milliseconds of idle time.
543+ * @user_data: (allow-none): The user data to pass to the callback
544+ * @notify: A #GDestroyNotify
545+ *
546+ * Returns: a watch id
547+ *
548+ * Adds a watch for a specific idle time. The callback will be called
549+ * when the user has accumulated @interval_msec milliseconds of idle time.
550+ * This function will return an ID that can either be passed to
551+ * gsd_idle_monitor_remove_watch(), or can be used to tell idle time
552+ * watches apart if you have more than one.
553+ *
554+ * Also note that this function will only care about positive transitions
555+ * (user's idle time exceeding a certain time). If you want to know about
556+ * when the user has become active, use
557+ * gsd_idle_monitor_add_user_active_watch().
558+ */
559+guint
560+gsd_idle_monitor_add_idle_watch (GsdIdleMonitor *monitor,
561+ guint64 interval_msec,
562+ GsdIdleMonitorWatchFunc callback,
563+ gpointer user_data,
564+ GDestroyNotify notify)
565+{
566+ GsdIdleMonitorWatch *watch;
567+
568+ g_return_val_if_fail (GSD_IS_IDLE_MONITOR (monitor), 0);
569+
570+ watch = make_watch (monitor,
571+ _xsync_alarm_set (monitor, XSyncPositiveTransition, interval_msec, TRUE),
572+ callback,
573+ user_data,
574+ notify);
575+
576+ g_hash_table_add (monitor->priv->alarms,
577+ (gpointer) watch->xalarm);
578+
579+ return watch->id;
580+}
581+
582+/**
583+ * gsd_idle_monitor_add_user_active_watch:
584+ * @monitor: A #GsdIdleMonitor
585+ * @callback: (allow-none): The callback to call when the user is
586+ * active again.
587+ * @user_data: (allow-none): The user data to pass to the callback
588+ * @notify: A #GDestroyNotify
589+ *
590+ * Returns: a watch id
591+ *
592+ * Add a one-time watch to know when the user is active again.
593+ * Note that this watch is one-time and will de-activate after the
594+ * function is called, for efficiency purposes. It's most convenient
595+ * to call this when an idle watch, as added by
596+ * gsd_idle_monitor_add_idle_watch(), has triggered.
597+ */
598+guint
599+gsd_idle_monitor_add_user_active_watch (GsdIdleMonitor *monitor,
600+ GsdIdleMonitorWatchFunc callback,
601+ gpointer user_data,
602+ GDestroyNotify notify)
603+{
604+ GsdIdleMonitorWatch *watch;
605+
606+ g_return_val_if_fail (GSD_IS_IDLE_MONITOR (monitor), 0);
607+
608+ set_alarm_enabled (monitor->priv->display,
609+ monitor->priv->user_active_alarm,
610+ TRUE);
611+
612+ watch = make_watch (monitor,
613+ monitor->priv->user_active_alarm,
614+ callback,
615+ user_data,
616+ notify);
617+
618+ return watch->id;
619+}
620+
621+/**
622+ * gsd_idle_monitor_remove_watch:
623+ * @monitor: A #GsdIdleMonitor
624+ * @id: A watch ID
625+ *
626+ * Removes an idle time watcher, previously added by
627+ * gsd_idle_monitor_add_idle_watch() or
628+ * gsd_idle_monitor_add_user_active_watch().
629+ */
630+void
631+gsd_idle_monitor_remove_watch (GsdIdleMonitor *monitor,
632+ guint id)
633+{
634+ g_return_if_fail (GSD_IS_IDLE_MONITOR (monitor));
635+
636+ g_hash_table_remove (monitor->priv->watches,
637+ GUINT_TO_POINTER (id));
638+}
639+
640+/**
641+ * gsd_idle_monitor_get_idletime:
642+ * @monitor: A #GsdIdleMonitor
643+ *
644+ * Returns: The current idle time, in milliseconds, or -1 for not supported
645+ */
646+gint64
647+gsd_idle_monitor_get_idletime (GsdIdleMonitor *monitor)
648+{
649+ XSyncValue value;
650+
651+ if (!XSyncQueryCounter (monitor->priv->display, monitor->priv->counter, &value))
652+ return -1;
653+
654+ return _xsyncvalue_to_int64 (value);
655+}
656
657=== added file 'plugins/common/gsd-idle-monitor.h'
658--- plugins/common/gsd-idle-monitor.h 1970-01-01 00:00:00 +0000
659+++ plugins/common/gsd-idle-monitor.h 2014-07-30 22:27:08 +0000
660@@ -0,0 +1,81 @@
661+/* -*- mode: C; c-file-style: "linux"; indent-tabs-mode: t -*-
662+ *
663+ * Adapted from gnome-session/gnome-session/gs-idle-monitor.h
664+ *
665+ * Copyright (C) 2012 Red Hat, Inc.
666+ *
667+ * This program is free software; you can redistribute it and/or modify
668+ * it under the terms of the GNU General Public License as published by
669+ * the Free Software Foundation; either version 2 of the License, or
670+ * (at your option) any later version.
671+ *
672+ * This program is distributed in the hope that it will be useful,
673+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
674+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
675+ * GNU General Public License for more details.
676+ *
677+ * You should have received a copy of the GNU General Public License
678+ * along with this program; if not, write to the Free Software
679+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
680+ *
681+ * Authors: William Jon McCann <mccann@jhu.edu>
682+ */
683+
684+#ifndef __GSD_IDLE_MONITOR_H__
685+#define __GSD_IDLE_MONITOR_H__
686+
687+#include <glib-object.h>
688+#include <gdk/gdk.h>
689+
690+G_BEGIN_DECLS
691+
692+#define GSD_TYPE_IDLE_MONITOR (gsd_idle_monitor_get_type ())
693+#define GSD_IDLE_MONITOR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_IDLE_MONITOR, GsdIdleMonitor))
694+#define GSD_IDLE_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_IDLE_MONITOR, GsdIdleMonitorClass))
695+#define GSD_IS_IDLE_MONITOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_IDLE_MONITOR))
696+#define GSD_IS_IDLE_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_IDLE_MONITOR))
697+#define GSD_IDLE_MONITOR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_IDLE_MONITOR, GsdIdleMonitorClass))
698+
699+typedef struct _GsdIdleMonitor GsdIdleMonitor;
700+typedef struct _GsdIdleMonitorClass GsdIdleMonitorClass;
701+typedef struct _GsdIdleMonitorPrivate GsdIdleMonitorPrivate;
702+
703+struct _GsdIdleMonitor
704+{
705+ GObject parent;
706+ GsdIdleMonitorPrivate *priv;
707+};
708+
709+struct _GsdIdleMonitorClass
710+{
711+ GObjectClass parent_class;
712+};
713+
714+typedef void (*GsdIdleMonitorWatchFunc) (GsdIdleMonitor *monitor,
715+ guint id,
716+ gpointer user_data);
717+
718+GType gsd_idle_monitor_get_type (void);
719+
720+GsdIdleMonitor * gsd_idle_monitor_new (void);
721+GsdIdleMonitor * gsd_idle_monitor_new_for_device (GdkDevice *device);
722+
723+guint gsd_idle_monitor_add_idle_watch (GsdIdleMonitor *monitor,
724+ guint64 interval_msec,
725+ GsdIdleMonitorWatchFunc callback,
726+ gpointer user_data,
727+ GDestroyNotify notify);
728+
729+guint gsd_idle_monitor_add_user_active_watch (GsdIdleMonitor *monitor,
730+ GsdIdleMonitorWatchFunc callback,
731+ gpointer user_data,
732+ GDestroyNotify notify);
733+
734+void gsd_idle_monitor_remove_watch (GsdIdleMonitor *monitor,
735+ guint id);
736+
737+gint64 gsd_idle_monitor_get_idletime (GsdIdleMonitor *monitor);
738+
739+G_END_DECLS
740+
741+#endif /* __GSD_IDLE_MONITOR_H__ */
742
743=== modified file 'plugins/cursor/gsd-cursor-manager.c'
744--- plugins/cursor/gsd-cursor-manager.c 2013-04-15 11:23:06 +0000
745+++ plugins/cursor/gsd-cursor-manager.c 2014-07-30 22:27:08 +0000
746@@ -38,12 +38,10 @@
747 #include <X11/Xatom.h>
748 #include <X11/extensions/Xfixes.h>
749
750-#define GNOME_DESKTOP_USE_UNSTABLE_API
751-#include <libgnome-desktop/gnome-idle-monitor.h>
752-
753 #include "gnome-settings-profile.h"
754 #include "gsd-cursor-manager.h"
755 #include "gsd-input-helper.h"
756+#include "gsd-idle-monitor.h"
757
758 #define XFIXES_CURSOR_HIDING_MAJOR 4
759
760@@ -126,7 +124,7 @@
761 }
762
763 static void
764-monitor_became_active (GnomeIdleMonitor *monitor,
765+monitor_became_active (GsdIdleMonitor *monitor,
766 guint watch_id,
767 gpointer user_data)
768 {
769@@ -155,7 +153,7 @@
770 GsdCursorManager *manager,
771 GError **error)
772 {
773- GnomeIdleMonitor *monitor;
774+ GsdIdleMonitor *monitor;
775
776 if (g_hash_table_lookup (manager->priv->monitors, device) != NULL)
777 return TRUE;
778@@ -167,7 +165,7 @@
779 return TRUE;
780
781 /* Create IdleMonitors for each pointer device */
782- monitor = gnome_idle_monitor_new_for_device (device);
783+ monitor = gsd_idle_monitor_new_for_device (device);
784 if (!monitor) {
785 g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
786 "Per-device idletime monitor not available");
787@@ -176,10 +174,10 @@
788 g_hash_table_insert (manager->priv->monitors,
789 device,
790 monitor);
791- gnome_idle_monitor_add_user_active_watch (monitor,
792- monitor_became_active,
793- manager,
794- NULL);
795+ gsd_idle_monitor_add_user_active_watch (monitor,
796+ monitor_became_active,
797+ manager,
798+ NULL);
799
800 return TRUE;
801 }
802
803=== modified file 'plugins/power/gsd-power-manager.c'
804--- plugins/power/gsd-power-manager.c 2014-02-08 20:53:08 +0000
805+++ plugins/power/gsd-power-manager.c 2014-07-30 22:27:08 +0000
806@@ -36,7 +36,6 @@
807
808 #define GNOME_DESKTOP_USE_UNSTABLE_API
809 #include <libgnome-desktop/gnome-rr.h>
810-#include <libgnome-desktop/gnome-idle-monitor.h>
811
812 #include <gsd-input-helper.h>
813
814@@ -50,6 +49,7 @@
815 #include "gnome-settings-session.h"
816 #include "gsd-enums.h"
817 #include "gsd-power-manager.h"
818+#include "gsd-idle-monitor.h"
819
820 #define GNOME_SESSION_DBUS_NAME "org.gnome.SessionManager"
821 #define GNOME_SESSION_DBUS_PATH_PRESENCE "/org/gnome/SessionManager/Presence"
822@@ -214,7 +214,7 @@
823 gboolean is_virtual_machine;
824
825 /* Idles */
826- GnomeIdleMonitor *idle_monitor;
827+ GsdIdleMonitor *idle_monitor;
828 guint idle_dim_id;
829 guint idle_blank_id;
830 guint idle_sleep_warning_id;
831@@ -246,8 +246,8 @@
832 static void main_battery_or_ups_low_changed (GsdPowerManager *manager, gboolean is_low);
833 static gboolean idle_is_session_inhibited (GsdPowerManager *manager, guint mask, gboolean *is_inhibited);
834 static void idle_set_mode (GsdPowerManager *manager, GsdPowerIdleMode mode);
835-static void idle_triggered_idle_cb (GnomeIdleMonitor *monitor, guint watch_id, gpointer user_data);
836-static void idle_became_active_cb (GnomeIdleMonitor *monitor, guint watch_id, gpointer user_data);
837+static void idle_triggered_idle_cb (GsdIdleMonitor *monitor, guint watch_id, gpointer user_data);
838+static void idle_became_active_cb (GsdIdleMonitor *monitor, guint watch_id, gpointer user_data);
839
840 G_DEFINE_TYPE (GsdPowerManager, gsd_power_manager, G_TYPE_OBJECT)
841
842@@ -2501,10 +2501,10 @@
843 /* if we're moving to an idle mode, make sure
844 * we add a watch to take us back to normal */
845 if (mode != GSD_POWER_IDLE_MODE_NORMAL) {
846- gnome_idle_monitor_add_user_active_watch (manager->priv->idle_monitor,
847- idle_became_active_cb,
848- manager,
849- NULL);
850+ gsd_idle_monitor_add_user_active_watch (manager->priv->idle_monitor,
851+ idle_became_active_cb,
852+ manager,
853+ NULL);
854 }
855
856 /* save current brightness, and set dim level */
857@@ -2631,12 +2631,12 @@
858 }
859
860 static void
861-clear_idle_watch (GnomeIdleMonitor *monitor,
862+clear_idle_watch (GsdIdleMonitor *monitor,
863 guint *id)
864 {
865 if (*id == 0)
866 return;
867- gnome_idle_monitor_remove_watch (monitor, *id);
868+ gsd_idle_monitor_remove_watch (monitor, *id);
869 *id = 0;
870 }
871
872@@ -2692,9 +2692,9 @@
873 if (timeout_blank != 0) {
874 g_debug ("setting up blank callback for %is", timeout_blank);
875
876- manager->priv->idle_blank_id = gnome_idle_monitor_add_idle_watch (manager->priv->idle_monitor,
877- timeout_blank * 1000,
878- idle_triggered_idle_cb, manager, NULL);
879+ manager->priv->idle_blank_id = gsd_idle_monitor_add_idle_watch (manager->priv->idle_monitor,
880+ timeout_blank * 1000,
881+ idle_triggered_idle_cb, manager, NULL);
882 }
883
884 /* only do the sleep timeout when the session is idle
885@@ -2715,9 +2715,9 @@
886 if (timeout_sleep != 0) {
887 g_debug ("setting up sleep callback %is", timeout_sleep);
888
889- manager->priv->idle_sleep_id = gnome_idle_monitor_add_idle_watch (manager->priv->idle_monitor,
890- timeout_sleep * 1000,
891- idle_triggered_idle_cb, manager, NULL);
892+ manager->priv->idle_sleep_id = gsd_idle_monitor_add_idle_watch (manager->priv->idle_monitor,
893+ timeout_sleep * 1000,
894+ idle_triggered_idle_cb, manager, NULL);
895 if (action_type == GSD_POWER_ACTION_LOGOUT ||
896 action_type == GSD_POWER_ACTION_SUSPEND ||
897 action_type == GSD_POWER_ACTION_HIBERNATE) {
898@@ -2730,9 +2730,9 @@
899
900 g_debug ("setting up sleep warning callback %is", timeout_sleep_warning);
901
902- manager->priv->idle_sleep_warning_id = gnome_idle_monitor_add_idle_watch (manager->priv->idle_monitor,
903- timeout_sleep_warning * 1000,
904- idle_triggered_idle_cb, manager, NULL);
905+ manager->priv->idle_sleep_warning_id = gsd_idle_monitor_add_idle_watch (manager->priv->idle_monitor,
906+ timeout_sleep_warning * 1000,
907+ idle_triggered_idle_cb, manager, NULL);
908 }
909 }
910
911@@ -2772,9 +2772,9 @@
912 if (timeout_dim != 0) {
913 g_debug ("setting up dim callback for %is", timeout_dim);
914
915- manager->priv->idle_dim_id = gnome_idle_monitor_add_idle_watch (manager->priv->idle_monitor,
916- timeout_dim * 1000,
917- idle_triggered_idle_cb, manager, NULL);
918+ manager->priv->idle_dim_id = gsd_idle_monitor_add_idle_watch (manager->priv->idle_monitor,
919+ timeout_dim * 1000,
920+ idle_triggered_idle_cb, manager, NULL);
921 }
922 }
923
924@@ -3106,7 +3106,7 @@
925 }
926
927 static void
928-idle_triggered_idle_cb (GnomeIdleMonitor *monitor,
929+idle_triggered_idle_cb (GsdIdleMonitor *monitor,
930 guint watch_id,
931 gpointer user_data)
932 {
933@@ -3131,7 +3131,7 @@
934 }
935
936 static void
937-idle_became_active_cb (GnomeIdleMonitor *monitor,
938+idle_became_active_cb (GsdIdleMonitor *monitor,
939 guint watch_id,
940 gpointer user_data)
941 {
942@@ -3550,7 +3550,7 @@
943 "use-time-for-policy");
944
945 /* create IDLETIME watcher */
946- manager->priv->idle_monitor = gnome_idle_monitor_new ();
947+ manager->priv->idle_monitor = gsd_idle_monitor_new ();
948
949 /* set up the screens */
950 g_signal_connect (manager->priv->rr_screen, "changed", G_CALLBACK (on_randr_event), manager);

Subscribers

People subscribed via source and target branches