Merge lp:~darkxst/unity-settings-daemon/lp1377847 into lp:unity-settings-daemon
- lp1377847
- Merge into trunk
Status: | Rejected |
---|---|
Rejected by: | Sebastien Bacher |
Proposed branch: | lp:~darkxst/unity-settings-daemon/lp1377847 |
Merge into: | lp:unity-settings-daemon |
Diff against target: |
1734 lines (+931/-494) 9 files modified
debian/libunity-settings-daemon1.symbols (+4/-2) gnome-settings-daemon/Makefile.am (+19/-2) gnome-settings-daemon/gsd-idle-monitor-private.h (+29/-0) gnome-settings-daemon/gsd-idle-monitor.c (+774/-413) gnome-settings-daemon/gsd-idle-monitor.h (+54/-74) gnome-settings-daemon/idle-monitor.xml (+35/-0) gnome-settings-daemon/main.c (+7/-0) plugins/cursor/gsd-cursor-manager.c (+8/-2) plugins/power/gsd-power-manager.c (+1/-1) |
To merge this branch: | bzr merge lp:~darkxst/unity-settings-daemon/lp1377847 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Sebastien Bacher | Needs Fixing | ||
Iain Lane | Needs Fixing | ||
Review via email: mp+237507@code.launchpad.net |
Commit message
Copy in Idle Monitor from 3.10 and hook up dbus interface
Description of the change
Iain Lane (laney) wrote : | # |
Also would you please remove the d/changelog editing? We'll upload this through CI train which will do that automatically from the commit message and I'm not sure if it'll add the bug reference with the manually edited version.
Tim Lunn (darkxst) wrote : | # |
Laney, existing programs access the idle monitor through gnome-desktop (or gnome-session). gnome-shell does although its been using the new api for ages, and besides that is provided by mutter. which only leaves u-s-d (previously before roberts patches it would have called through via gnome-desktop as well), but there is little point for it to call out over dbus only to get itself.
Sebastien Bacher (seb128) wrote : | # |
Using this version I just had a segfault in gsd_idle_
since the ppa doesn't have ddebs I can get a debug backtrace, but it segfaults in a call to g_hash_
what I did
- using unity, lock the screen manually
- walk away from the computer for half an hour
- come back and move the mouse to get the lock screen/unlock
It doesn't seem to happen every time with those steps though (or the time without touching the computer matters, I tried just waiting for the screen to dim/turn off when I did testing)
Iain Lane (laney) wrote : | # |
That was the bug with the previous version, can you try building the package yourself and see if you can reproduce it using this branch? I didn't get a crash all day yesterday. At least if you do your own build you'll get a ddeb for a better backtrace.
Sebastien Bacher (seb128) wrote : | # |
The build is the current version from https:/
Got the ddeb from http://
the bt is
"#0 0x206b6e61 in ?? ()
#1 0xb6d687f8 in g_hash_
key=0xe00015, hash_table=
at /build/
#2 g_hash_
at /build/
#3 0xb76b01f4 in gsd_idle_
alarm_
#4 gsd_idle_
at gsd-idle-
..."
Iain Lane (laney) wrote : | # |
On Thu, Oct 09, 2014 at 09:14:57AM -0000, Sebastien Bacher wrote:
> The build is the current version from https:/
>
> Got the ddeb from http://
>
> the bt is
>
> "#0 0x206b6e61 in ?? ()
> #1 0xb6d687f8 in g_hash_
> key=0xe00015, hash_table=
> at /build/
> #2 g_hash_
> at /build/
> #3 0xb76b01f4 in gsd_idle_
> alarm_event=
> #4 gsd_idle_
> at gsd-idle-
> ..."
It's the same as what we had before with earlier PPA versions - I think
that somehow the device monitor wasn't being disposed properly so we
were accessing some random bit of memory which was crashing inside glib.
With the current version I can't get this crash any more. Previously if
I used the mouse it was quite likely to crash while fading, but now this
never happens for me.
Have you managed to make it happen again?
--
Iain Lane [ <email address hidden> ]
Debian Developer [ <email address hidden> ]
Ubuntu Developer [ <email address hidden> ]
Sebastien Bacher (seb128) wrote : | # |
no, it's a one time thing from this morning, I tried to run under valgrind as well, no error there
Iain Lane (laney) wrote : | # |
On Thu, Oct 09, 2014 at 10:29:01AM -0000, Sebastien Bacher wrote:
> no, it's a one time thing from this morning, I tried to run under valgrind as well, no error there
I'll keep trying all day. Not sure what we should do, the bug this is
fixing is important but this crash might happen more often across all
users and will be hard to fix if it's very difficult to reproduce. :(
--
Iain Lane [ <email address hidden> ]
Debian Developer [ <email address hidden> ]
Ubuntu Developer [ <email address hidden> ]
Sebastien Bacher (seb128) wrote : | # |
seems to trigger when going to unity-greeter (e.g try selecting another user from the indicator)
Iain Lane (laney) wrote : | # |
Different problem, but I think I fixed this in https:/
hopefully... it's hard to gdb these refcounting bugs, I should learn to use refdbg. :)
- 4057. By Tim Lunn
-
Move gdk_window_
add_filter up a level This only needs to be called once, not when creating each device
- 4058. By Tim Lunn
-
clear device_monitors pointer when disposing monitor
This is not happening when g_object_clear gets called, so we ended up with
a stale pointer here. - 4059. By Tim Lunn
-
Take a ref on the GdkDevice to avoid a double free, to be safe also
take a ref on the gdk device_manager to ensure that doesnt get disposed. - 4060. By Tim Lunn
-
fix build
Sebastien Bacher (seb128) wrote : | # |
thanks for the update, triggering a silo rebuild with r4060.
The changes look fine, small nitpick, some g_object_(un)ref calls lack a space before the '('
Tim Lunn (darkxst) wrote : | # |
fixed the spaces
Sebastien Bacher (seb128) wrote : | # |
not sure why that merge request is still open but the change have been merged previous cycle
Preview Diff
1 | === modified file 'debian/libunity-settings-daemon1.symbols' |
2 | --- debian/libunity-settings-daemon1.symbols 2014-08-29 10:24:00 +0000 |
3 | +++ debian/libunity-settings-daemon1.symbols 2014-10-10 08:23:44 +0000 |
4 | @@ -1,10 +1,12 @@ |
5 | libunity-settings-daemon.so.1 libunity-settings-daemon1 #MINVER# |
6 | gsd_idle_monitor_add_idle_watch@Base 14.04.0 |
7 | gsd_idle_monitor_add_user_active_watch@Base 14.04.0 |
8 | + gsd_idle_monitor_get_core@Base 14.10 |
9 | + gsd_idle_monitor_get_for_device@Base 14.10 |
10 | gsd_idle_monitor_get_idletime@Base 14.04.0 |
11 | gsd_idle_monitor_get_type@Base 14.04.0 |
12 | - gsd_idle_monitor_new@Base 14.04.0 |
13 | - gsd_idle_monitor_new_for_device@Base 14.04.0 |
14 | + gsd_idle_monitor_handle_xevent_all@Base 14.10 |
15 | + gsd_idle_monitor_init_dbus@Base 14.10 |
16 | gsd_idle_monitor_remove_watch@Base 14.04.0 |
17 | gsd_pnp_ids_get_pnp_id@Base 14.04.0 |
18 | gsd_pnp_ids_get_type@Base 14.04.0 |
19 | |
20 | === modified file 'gnome-settings-daemon/Makefile.am' |
21 | --- gnome-settings-daemon/Makefile.am 2014-08-29 10:24:00 +0000 |
22 | +++ gnome-settings-daemon/Makefile.am 2014-10-10 08:23:44 +0000 |
23 | @@ -33,6 +33,9 @@ |
24 | gsd-idle-monitor.c \ |
25 | gsd-idle-monitor.h |
26 | |
27 | +nodist_libunity_settings_daemon_la_SOURCES = \ |
28 | + $(dbus_idle_built_sources) |
29 | + |
30 | libunity_settings_daemon_include_HEADERS = \ |
31 | gsd-pnp-ids.h \ |
32 | gsd-rr.h \ |
33 | @@ -55,6 +58,18 @@ |
34 | -version-info 1:0:0 \ |
35 | -export-symbols-regex \^gsd_.* |
36 | |
37 | +BUILT_SOURCES = $(dbus_idle_built_sources) |
38 | + |
39 | +dbus_idle_built_sources = meta-dbus-idle-monitor.c meta-dbus-idle-monitor.h |
40 | + |
41 | +$(dbus_idle_built_sources) : Makefile.am idle-monitor.xml |
42 | + $(AM_V_GEN)gdbus-codegen \ |
43 | + --interface-prefix org.gnome.Mutter \ |
44 | + --c-namespace MetaDBus \ |
45 | + --generate-c-code meta-dbus-idle-monitor \ |
46 | + --c-generate-object-manager \ |
47 | + $(srcdir)/idle-monitor.xml |
48 | + |
49 | check_gl_texture_size_CPPFLAGS = \ |
50 | $(CHECK_GL_TEXTURE_SIZE_CFLAGS) |
51 | |
52 | @@ -99,7 +114,8 @@ |
53 | unity-settings-daemon-localeexec |
54 | |
55 | EXTRA_DIST = \ |
56 | - unity-settings-daemon-localeexec.in |
57 | + unity-settings-daemon-localeexec.in \ |
58 | + idle-monitor.xml |
59 | |
60 | unity-settings-daemon-localeexec: unity-settings-daemon-localeexec.in |
61 | $(AM_V_GEN) sed -e "s|\@libexecdir\@|$(libexecdir)|" -e "s|\@prefix\@|$(prefix)|" $< > $@.tmp && mv $@.tmp $@ |
62 | @@ -137,6 +153,7 @@ |
63 | $(GNOME_DESKTOP_LIBS) \ |
64 | $(NULL) |
65 | |
66 | -CLEANFILES = $(gsd_SCRIPTS) |
67 | +CLEANFILES = $(gsd_SCRIPTS) \ |
68 | + $(dbus_idle_built_sources) |
69 | |
70 | # vim: ts=8 |
71 | |
72 | === added file 'gnome-settings-daemon/gsd-idle-monitor-private.h' |
73 | --- gnome-settings-daemon/gsd-idle-monitor-private.h 1970-01-01 00:00:00 +0000 |
74 | +++ gnome-settings-daemon/gsd-idle-monitor-private.h 2014-10-10 08:23:44 +0000 |
75 | @@ -0,0 +1,29 @@ |
76 | +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ |
77 | + |
78 | +/* |
79 | + * Copyright 2013 Red Hat, Inc. |
80 | + * |
81 | + * This program is free software; you can redistribute it and/or |
82 | + * modify it under the terms of the GNU General Public License as |
83 | + * published by the Free Software Foundation; either version 2 of the |
84 | + * License, or (at your option) any later version. |
85 | + * |
86 | + * This program is distributed in the hope that it will be useful, but |
87 | + * WITHOUT ANY WARRANTY; without even the implied warranty of |
88 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
89 | + * General Public License for more details. |
90 | + * |
91 | + * You should have received a copy of the GNU General Public License |
92 | + * along with this program; if not, see <http://www.gnu.org/licenses/>. |
93 | + * |
94 | + * Adapted from gnome-session/gnome-session/gs-idle-monitor.c and |
95 | + * from gnome-desktop/libgnome-desktop/gnome-idle-monitor.c |
96 | + */ |
97 | + |
98 | +#include <X11/Xlib.h> |
99 | +#include <gsd-idle-monitor.h> |
100 | + |
101 | +void gsd_idle_monitor_handle_xevent_all (XEvent *xevent); |
102 | + |
103 | + |
104 | +void gsd_idle_monitor_init_dbus (gboolean replace); |
105 | |
106 | === modified file 'gnome-settings-daemon/gsd-idle-monitor.c' |
107 | --- gnome-settings-daemon/gsd-idle-monitor.c 2014-08-29 04:27:34 +0000 |
108 | +++ gnome-settings-daemon/gsd-idle-monitor.c 2014-10-10 08:23:44 +0000 |
109 | @@ -1,89 +1,144 @@ |
110 | -/* -*- mode: C; c-file-style: "linux"; indent-tabs-mode: t -*- |
111 | - * |
112 | - * Adapted from gnome-session/gnome-session/gs-idle-monitor.c |
113 | - * |
114 | - * Copyright (C) 2012 Red Hat, Inc. |
115 | - * |
116 | - * This program is free software; you can redistribute it and/or modify |
117 | - * it under the terms of the GNU General Public License as published by |
118 | - * the Free Software Foundation; either version 2 of the License, or |
119 | - * (at your option) any later version. |
120 | - * |
121 | - * This program is distributed in the hope that it will be useful, |
122 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
123 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
124 | - * GNU General Public License for more details. |
125 | +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ |
126 | + |
127 | +/* |
128 | + * Copyright 2013 Red Hat, Inc. |
129 | + * |
130 | + * This program is free software; you can redistribute it and/or |
131 | + * modify it under the terms of the GNU General Public License as |
132 | + * published by the Free Software Foundation; either version 2 of the |
133 | + * License, or (at your option) any later version. |
134 | + * |
135 | + * This program is distributed in the hope that it will be useful, but |
136 | + * WITHOUT ANY WARRANTY; without even the implied warranty of |
137 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
138 | + * General Public License for more details. |
139 | * |
140 | * You should have received a copy of the GNU General Public License |
141 | * along with this program; if not, write to the Free Software |
142 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
143 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
144 | + * 02111-1307, USA. |
145 | + * |
146 | + * Adapted from gnome-session/gnome-session/gs-idle-monitor.c and |
147 | + * from gnome-desktop/libgnome-desktop/gnome-idle-monitor.c |
148 | + */ |
149 | + |
150 | +/** |
151 | + * SECTION:idle-monitor |
152 | + * @title: GsdIdleMonitor |
153 | + * @short_description: Mutter idle counter (similar to X's IDLETIME) |
154 | */ |
155 | |
156 | #include "config.h" |
157 | |
158 | -#include <time.h> |
159 | #include <string.h> |
160 | - |
161 | #include <X11/Xlib.h> |
162 | #include <X11/extensions/sync.h> |
163 | - |
164 | -#include <glib.h> |
165 | +#include <gdk/gdk.h> |
166 | #include <gdk/gdkx.h> |
167 | -#include <gdk/gdk.h> |
168 | |
169 | #include "gsd-idle-monitor.h" |
170 | - |
171 | -#define GSD_IDLE_MONITOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_IDLE_MONITOR, GsdIdleMonitorPrivate)) |
172 | +#include "gsd-idle-monitor-private.h" |
173 | +#include "meta-dbus-idle-monitor.h" |
174 | |
175 | G_STATIC_ASSERT(sizeof(unsigned long) == sizeof(gpointer)); |
176 | |
177 | -struct _GsdIdleMonitorPrivate |
178 | -{ |
179 | - Display *display; |
180 | - |
181 | - GHashTable *watches; |
182 | - GHashTable *alarms; |
183 | - int sync_event_base; |
184 | - XSyncCounter counter; |
185 | - |
186 | - XSyncAlarm user_active_alarm; |
187 | - |
188 | - GdkDevice *device; |
189 | +struct _GsdIdleMonitor |
190 | +{ |
191 | + GObject parent_instance; |
192 | + |
193 | + GHashTable *watches; |
194 | + GHashTable *alarms; |
195 | + int device_id; |
196 | + |
197 | + /* X11 implementation */ |
198 | + Display *display; |
199 | + int sync_event_base; |
200 | + |
201 | + XSyncCounter counter; |
202 | + XSyncAlarm user_active_alarm; |
203 | +}; |
204 | + |
205 | +struct _GsdIdleMonitorClass |
206 | +{ |
207 | + GObjectClass parent_class; |
208 | }; |
209 | |
210 | typedef struct |
211 | { |
212 | - GsdIdleMonitor *monitor; |
213 | - guint id; |
214 | - GsdIdleMonitorWatchFunc callback; |
215 | - gpointer user_data; |
216 | - GDestroyNotify notify; |
217 | - XSyncAlarm xalarm; |
218 | + GsdIdleMonitor *monitor; |
219 | + guint id; |
220 | + GsdIdleMonitorWatchFunc callback; |
221 | + gpointer user_data; |
222 | + GDestroyNotify notify; |
223 | + guint64 timeout_msec; |
224 | + |
225 | + /* x11 */ |
226 | + XSyncAlarm xalarm; |
227 | + int idle_source_id; |
228 | } GsdIdleMonitorWatch; |
229 | |
230 | +typedef struct |
231 | +{ |
232 | + /* X11 implementation */ |
233 | + Display *display; |
234 | + int sync_event_base; |
235 | + int sync_error_base; |
236 | + unsigned int have_xsync : 1; |
237 | + |
238 | +}GsdXSync; |
239 | + |
240 | +static GsdXSync *xsync; |
241 | + |
242 | enum |
243 | { |
244 | - PROP_0, |
245 | - PROP_DEVICE, |
246 | - PROP_LAST, |
247 | + PROP_0, |
248 | + PROP_DEVICE_ID, |
249 | + PROP_LAST, |
250 | }; |
251 | |
252 | static GParamSpec *obj_props[PROP_LAST]; |
253 | |
254 | -static void gsd_idle_monitor_initable_iface_init (GInitableIface *iface); |
255 | +G_DEFINE_TYPE (GsdIdleMonitor, gsd_idle_monitor, G_TYPE_OBJECT) |
256 | |
257 | -G_DEFINE_TYPE_WITH_CODE (GsdIdleMonitor, gsd_idle_monitor, G_TYPE_OBJECT, |
258 | - G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, |
259 | - gsd_idle_monitor_initable_iface_init)) |
260 | +static GsdIdleMonitor *device_monitors[256]; |
261 | +static int device_id_max; |
262 | |
263 | static gint64 |
264 | _xsyncvalue_to_int64 (XSyncValue value) |
265 | { |
266 | - return ((guint64) XSyncValueHigh32 (value)) << 32 |
267 | - | (guint64) XSyncValueLow32 (value); |
268 | -} |
269 | - |
270 | -#define GINT64_TO_XSYNCVALUE(value, ret) XSyncIntsToValue (ret, value, ((guint64)value) >> 32) |
271 | + return ((guint64) XSyncValueHigh32 (value)) << 32 |
272 | + | (guint64) XSyncValueLow32 (value); |
273 | +} |
274 | + |
275 | +#define GUINT64_TO_XSYNCVALUE(value, ret) XSyncIntsToValue (ret, (value) & 0xFFFFFFFF, ((guint64)(value)) >> 32) |
276 | + |
277 | +static void |
278 | +fire_watch (GsdIdleMonitorWatch *watch) |
279 | +{ |
280 | + GsdIdleMonitor *monitor; |
281 | + guint id; |
282 | + gboolean is_user_active_watch; |
283 | + |
284 | + monitor = watch->monitor; |
285 | + g_object_ref (monitor); |
286 | + |
287 | + if (watch->idle_source_id) |
288 | + { |
289 | + g_source_remove (watch->idle_source_id); |
290 | + watch->idle_source_id = 0; |
291 | + } |
292 | + |
293 | + id = watch->id; |
294 | + is_user_active_watch = (watch->timeout_msec == 0); |
295 | + |
296 | + if (watch->callback) |
297 | + watch->callback (monitor, id, watch->user_data); |
298 | + |
299 | + if (is_user_active_watch) |
300 | + gsd_idle_monitor_remove_watch (monitor, id); |
301 | + |
302 | + g_object_unref (monitor); |
303 | +} |
304 | |
305 | static XSyncAlarm |
306 | _xsync_alarm_set (GsdIdleMonitor *monitor, |
307 | @@ -91,34 +146,34 @@ |
308 | guint64 interval, |
309 | gboolean want_events) |
310 | { |
311 | - XSyncAlarmAttributes attr; |
312 | - XSyncValue delta; |
313 | - guint flags; |
314 | - |
315 | - flags = XSyncCACounter | XSyncCAValueType | XSyncCATestType | |
316 | - XSyncCAValue | XSyncCADelta | XSyncCAEvents; |
317 | - |
318 | - XSyncIntToValue (&delta, 0); |
319 | - attr.trigger.counter = monitor->priv->counter; |
320 | - attr.trigger.value_type = XSyncAbsolute; |
321 | - attr.delta = delta; |
322 | - attr.events = want_events; |
323 | - |
324 | - GINT64_TO_XSYNCVALUE (interval, &attr.trigger.wait_value); |
325 | - attr.trigger.test_type = test_type; |
326 | - return XSyncCreateAlarm (monitor->priv->display, flags, &attr); |
327 | + XSyncAlarmAttributes attr; |
328 | + XSyncValue delta; |
329 | + guint flags; |
330 | + |
331 | + flags = XSyncCACounter | XSyncCAValueType | XSyncCATestType | |
332 | + XSyncCAValue | XSyncCADelta | XSyncCAEvents; |
333 | + |
334 | + XSyncIntToValue (&delta, 0); |
335 | + attr.trigger.counter = monitor->counter; |
336 | + attr.trigger.value_type = XSyncAbsolute; |
337 | + attr.delta = delta; |
338 | + attr.events = want_events; |
339 | + |
340 | + GUINT64_TO_XSYNCVALUE (interval, &attr.trigger.wait_value); |
341 | + attr.trigger.test_type = test_type; |
342 | + return XSyncCreateAlarm (monitor->display, flags, &attr); |
343 | } |
344 | |
345 | static void |
346 | ensure_alarm_rescheduled (Display *dpy, |
347 | XSyncAlarm alarm) |
348 | { |
349 | - XSyncAlarmAttributes attr; |
350 | + XSyncAlarmAttributes attr; |
351 | |
352 | - /* Some versions of Xorg have an issue where alarms aren't |
353 | - * always rescheduled. Calling XSyncChangeAlarm, even |
354 | - * without any attributes, will reschedule the alarm. */ |
355 | - XSyncChangeAlarm (dpy, alarm, 0, &attr); |
356 | + /* Some versions of Xorg have an issue where alarms aren't |
357 | + * always rescheduled. Calling XSyncChangeAlarm, even |
358 | + * without any attributes, will reschedule the alarm. */ |
359 | + XSyncChangeAlarm (dpy, alarm, 0, &attr); |
360 | } |
361 | |
362 | static void |
363 | @@ -126,373 +181,366 @@ |
364 | XSyncAlarm alarm, |
365 | gboolean enabled) |
366 | { |
367 | - XSyncAlarmAttributes attr; |
368 | - attr.events = enabled; |
369 | - XSyncChangeAlarm (dpy, alarm, XSyncCAEvents, &attr); |
370 | -} |
371 | - |
372 | -static void |
373 | -fire_watch (gpointer data, |
374 | - gpointer user_data) |
375 | -{ |
376 | - GsdIdleMonitorWatch *watch = data; |
377 | - XSyncAlarm alarm = (XSyncAlarm) user_data; |
378 | - GsdIdleMonitor *monitor; |
379 | - |
380 | - if (watch->xalarm != alarm) { |
381 | - return; |
382 | - } |
383 | - |
384 | - monitor = watch->monitor; |
385 | - g_object_ref (monitor); |
386 | - |
387 | - if (watch->callback) { |
388 | - watch->callback (watch->monitor, |
389 | - watch->id, |
390 | - watch->user_data); |
391 | - } |
392 | - |
393 | - if (watch->xalarm == monitor->priv->user_active_alarm) { |
394 | - gsd_idle_monitor_remove_watch (monitor, watch->id); |
395 | - } |
396 | - |
397 | - g_object_unref (monitor); |
398 | -} |
399 | - |
400 | -static void |
401 | -handle_alarm_notify_event (GsdIdleMonitor *monitor, |
402 | - XSyncAlarmNotifyEvent *alarm_event) |
403 | -{ |
404 | - XSyncAlarm alarm; |
405 | - GList *watches; |
406 | - gboolean has_alarm; |
407 | - |
408 | - if (alarm_event->state != XSyncAlarmActive) { |
409 | - return; |
410 | - } |
411 | - |
412 | - alarm = alarm_event->alarm; |
413 | - |
414 | - has_alarm = FALSE; |
415 | - |
416 | - if (alarm == monitor->priv->user_active_alarm) { |
417 | - set_alarm_enabled (monitor->priv->display, |
418 | - alarm, |
419 | - FALSE); |
420 | - has_alarm = TRUE; |
421 | - } else if (g_hash_table_contains (monitor->priv->alarms, (gpointer) alarm)) { |
422 | - ensure_alarm_rescheduled (monitor->priv->display, |
423 | - alarm); |
424 | - has_alarm = TRUE; |
425 | - } |
426 | - |
427 | - if (has_alarm) { |
428 | - watches = g_hash_table_get_values (monitor->priv->watches); |
429 | - |
430 | - g_list_foreach (watches, |
431 | - fire_watch, |
432 | - (gpointer) alarm); |
433 | - |
434 | - g_list_free (watches); |
435 | - } |
436 | -} |
437 | - |
438 | -static GdkFilterReturn |
439 | -xevent_filter (GdkXEvent *xevent, |
440 | - GdkEvent *event, |
441 | - GsdIdleMonitor *monitor) |
442 | -{ |
443 | - XEvent *ev; |
444 | - XSyncAlarmNotifyEvent *alarm_event; |
445 | - |
446 | - ev = xevent; |
447 | - if (ev->xany.type != monitor->priv->sync_event_base + XSyncAlarmNotify) { |
448 | - return GDK_FILTER_CONTINUE; |
449 | - } |
450 | - |
451 | - alarm_event = xevent; |
452 | - handle_alarm_notify_event (monitor, alarm_event); |
453 | - |
454 | - return GDK_FILTER_CONTINUE; |
455 | + XSyncAlarmAttributes attr; |
456 | + attr.events = enabled; |
457 | + XSyncChangeAlarm (dpy, alarm, XSyncCAEvents, &attr); |
458 | +} |
459 | + |
460 | +static void |
461 | +check_x11_watch (gpointer data, |
462 | + gpointer user_data) |
463 | +{ |
464 | + GsdIdleMonitorWatch *watch = data; |
465 | + XSyncAlarm alarm = (XSyncAlarm) user_data; |
466 | + |
467 | + if (watch->xalarm != alarm) |
468 | + return; |
469 | + |
470 | + fire_watch (watch); |
471 | +} |
472 | + |
473 | +static void |
474 | +gsd_idle_monitor_handle_xevent (GsdIdleMonitor *monitor, |
475 | + XSyncAlarmNotifyEvent *alarm_event) |
476 | +{ |
477 | + XSyncAlarm alarm; |
478 | + GList *watches; |
479 | + gboolean has_alarm; |
480 | + |
481 | + |
482 | + if (alarm_event->state != XSyncAlarmActive) |
483 | + return; |
484 | + |
485 | + alarm = alarm_event->alarm; |
486 | + |
487 | + has_alarm = FALSE; |
488 | + |
489 | + if (alarm == monitor->user_active_alarm) |
490 | + { |
491 | + set_alarm_enabled (monitor->display, |
492 | + alarm, |
493 | + FALSE); |
494 | + has_alarm = TRUE; |
495 | + } |
496 | + else if (g_hash_table_contains (monitor->alarms, (gpointer) alarm)) |
497 | + { |
498 | + ensure_alarm_rescheduled (monitor->display, |
499 | + alarm); |
500 | + has_alarm = TRUE; |
501 | + } |
502 | + |
503 | + if (has_alarm) |
504 | + { |
505 | + watches = g_hash_table_get_values (monitor->watches); |
506 | + |
507 | + g_list_foreach (watches, check_x11_watch, (gpointer) alarm); |
508 | + g_list_free (watches); |
509 | + } |
510 | +} |
511 | + |
512 | +void |
513 | +gsd_idle_monitor_handle_xevent_all (XEvent *xevent) |
514 | +{ |
515 | + int i; |
516 | + |
517 | + for (i = 0; i <= device_id_max; i++) |
518 | + if (device_monitors[i]) |
519 | + gsd_idle_monitor_handle_xevent (device_monitors[i], (XSyncAlarmNotifyEvent*)xevent); |
520 | } |
521 | |
522 | static char * |
523 | -counter_name_for_device (GdkDevice *device) |
524 | +counter_name_for_device (int device_id) |
525 | { |
526 | - if (device) { |
527 | - gint device_id = gdk_x11_device_get_id (device); |
528 | - if (device_id > 0) |
529 | - return g_strdup_printf ("DEVICEIDLETIME %d", device_id); |
530 | - } |
531 | + if (device_id > 0) |
532 | + return g_strdup_printf ("DEVICEIDLETIME %d", device_id); |
533 | |
534 | - return g_strdup ("IDLETIME"); |
535 | + return g_strdup ("IDLETIME"); |
536 | } |
537 | |
538 | static XSyncCounter |
539 | find_idletime_counter (GsdIdleMonitor *monitor) |
540 | { |
541 | - int i; |
542 | - int ncounters; |
543 | - XSyncSystemCounter *counters; |
544 | - XSyncCounter counter = None; |
545 | - char *counter_name; |
546 | - |
547 | - counter_name = counter_name_for_device (monitor->priv->device); |
548 | - counters = XSyncListSystemCounters (monitor->priv->display, &ncounters); |
549 | - for (i = 0; i < ncounters; i++) { |
550 | - if (counters[i].name != NULL && strcmp (counters[i].name, counter_name) == 0) { |
551 | - counter = counters[i].counter; |
552 | - break; |
553 | - } |
554 | - } |
555 | - XSyncFreeSystemCounterList (counters); |
556 | - g_free (counter_name); |
557 | - |
558 | - return counter; |
559 | + int i; |
560 | + int ncounters; |
561 | + XSyncSystemCounter *counters; |
562 | + XSyncCounter counter = None; |
563 | + char *counter_name; |
564 | + |
565 | + counter_name = counter_name_for_device (monitor->device_id); |
566 | + counters = XSyncListSystemCounters (monitor->display, &ncounters); |
567 | + for (i = 0; i < ncounters; i++) |
568 | + { |
569 | + if (counters[i].name != NULL && strcmp (counters[i].name, counter_name) == 0) |
570 | + { |
571 | + counter = counters[i].counter; |
572 | + break; |
573 | + } |
574 | + } |
575 | + XSyncFreeSystemCounterList (counters); |
576 | + g_free (counter_name); |
577 | + |
578 | + return counter; |
579 | } |
580 | |
581 | static guint32 |
582 | get_next_watch_serial (void) |
583 | { |
584 | - static guint32 serial = 0; |
585 | - g_atomic_int_inc (&serial); |
586 | - return serial; |
587 | + static guint32 serial = 0; |
588 | + g_atomic_int_inc (&serial); |
589 | + return serial; |
590 | } |
591 | |
592 | static void |
593 | idle_monitor_watch_free (GsdIdleMonitorWatch *watch) |
594 | { |
595 | - GsdIdleMonitor *monitor; |
596 | - |
597 | - if (watch == NULL) { |
598 | - return; |
599 | - } |
600 | - |
601 | - monitor = watch->monitor; |
602 | - |
603 | - if (watch->notify != NULL) { |
604 | - watch->notify (watch->user_data); |
605 | - } |
606 | - |
607 | - if (watch->xalarm != monitor->priv->user_active_alarm) { |
608 | - XSyncDestroyAlarm (monitor->priv->display, watch->xalarm); |
609 | - g_hash_table_remove (monitor->priv->alarms, (gpointer) watch->xalarm); |
610 | - } |
611 | - |
612 | - g_slice_free (GsdIdleMonitorWatch, watch); |
613 | + GsdIdleMonitor *monitor; |
614 | + |
615 | + if (watch == NULL) |
616 | + return; |
617 | + |
618 | + monitor = watch->monitor; |
619 | + g_object_ref (monitor); |
620 | + |
621 | + if (watch->idle_source_id) |
622 | + { |
623 | + g_source_remove (watch->idle_source_id); |
624 | + watch->idle_source_id = 0; |
625 | + } |
626 | + |
627 | + if (watch->notify != NULL) |
628 | + watch->notify (watch->user_data); |
629 | + |
630 | + if (watch->xalarm != monitor->user_active_alarm && |
631 | + watch->xalarm != None) |
632 | + { |
633 | + XSyncDestroyAlarm (monitor->display, watch->xalarm); |
634 | + g_hash_table_remove (monitor->alarms, (gpointer) watch->xalarm); |
635 | + } |
636 | + |
637 | + g_object_unref (monitor); |
638 | + g_slice_free (GsdIdleMonitorWatch, watch); |
639 | +} |
640 | + |
641 | +GdkFilterReturn |
642 | +xevent_filter (GdkXEvent *xevent, |
643 | + GdkEvent *event, |
644 | + GsdIdleMonitor *monitor) |
645 | +{ |
646 | + XEvent *ev; |
647 | + |
648 | + ev = xevent; |
649 | + if (ev->xany.type == xsync->sync_event_base + XSyncAlarmNotify) { |
650 | + gsd_idle_monitor_handle_xevent_all (ev); |
651 | + } |
652 | + return GDK_FILTER_CONTINUE; |
653 | } |
654 | |
655 | static void |
656 | init_xsync (GsdIdleMonitor *monitor) |
657 | { |
658 | - int sync_error_base; |
659 | - int res; |
660 | - int major; |
661 | - int minor; |
662 | - |
663 | - res = XSyncQueryExtension (monitor->priv->display, |
664 | - &monitor->priv->sync_event_base, |
665 | - &sync_error_base); |
666 | - if (! res) { |
667 | - g_warning ("GsdIdleMonitor: Sync extension not present"); |
668 | - return; |
669 | - } |
670 | - |
671 | - res = XSyncInitialize (monitor->priv->display, &major, &minor); |
672 | - if (! res) { |
673 | - g_warning ("GsdIdleMonitor: Unable to initialize Sync extension"); |
674 | - return; |
675 | - } |
676 | - |
677 | - monitor->priv->counter = find_idletime_counter (monitor); |
678 | - /* IDLETIME counter not found? */ |
679 | - if (monitor->priv->counter == None) |
680 | - return; |
681 | - |
682 | - monitor->priv->user_active_alarm = _xsync_alarm_set (monitor, XSyncNegativeTransition, 1, FALSE); |
683 | - |
684 | - gdk_window_add_filter (NULL, (GdkFilterFunc)xevent_filter, monitor); |
685 | + |
686 | + monitor->counter = find_idletime_counter (monitor); |
687 | + /* IDLETIME counter not found? */ |
688 | + if (monitor->counter == None) |
689 | + { |
690 | + g_warning ("IDLETIME counter not found\n"); |
691 | + return; |
692 | + } |
693 | + |
694 | + monitor->user_active_alarm = _xsync_alarm_set (monitor, XSyncNegativeTransition, 1, FALSE); |
695 | } |
696 | |
697 | static void |
698 | gsd_idle_monitor_dispose (GObject *object) |
699 | { |
700 | - GsdIdleMonitor *monitor; |
701 | - |
702 | - monitor = GSD_IDLE_MONITOR (object); |
703 | - |
704 | - g_clear_pointer (&monitor->priv->watches, g_hash_table_destroy); |
705 | - g_clear_pointer (&monitor->priv->alarms, g_hash_table_destroy); |
706 | - g_clear_object (&monitor->priv->device); |
707 | - |
708 | - if (monitor->priv->user_active_alarm != None) { |
709 | - XSyncDestroyAlarm (monitor->priv->display, monitor->priv->user_active_alarm); |
710 | - monitor->priv->user_active_alarm = None; |
711 | - } |
712 | - |
713 | - gdk_window_remove_filter (NULL, (GdkFilterFunc)xevent_filter, monitor); |
714 | - |
715 | - G_OBJECT_CLASS (gsd_idle_monitor_parent_class)->dispose (object); |
716 | + GsdIdleMonitor *monitor; |
717 | + |
718 | + monitor = gsd_idle_monitor (object); |
719 | + |
720 | + g_clear_pointer (&monitor->watches, g_hash_table_destroy); |
721 | + g_clear_pointer (&monitor->alarms, g_hash_table_destroy); |
722 | + |
723 | + if (monitor->user_active_alarm != None) |
724 | + { |
725 | + XSyncDestroyAlarm (monitor->display, monitor->user_active_alarm); |
726 | + monitor->user_active_alarm = None; |
727 | + } |
728 | + |
729 | + device_monitors[monitor->device_id] = NULL; |
730 | + |
731 | + G_OBJECT_CLASS (gsd_idle_monitor_parent_class)->dispose (object); |
732 | } |
733 | |
734 | static void |
735 | gsd_idle_monitor_get_property (GObject *object, |
736 | - guint prop_id, |
737 | - GValue *value, |
738 | - GParamSpec *pspec) |
739 | + guint prop_id, |
740 | + GValue *value, |
741 | + GParamSpec *pspec) |
742 | { |
743 | - GsdIdleMonitor *monitor = GSD_IDLE_MONITOR (object); |
744 | - switch (prop_id) |
745 | - { |
746 | - case PROP_DEVICE: |
747 | - g_value_set_object (value, monitor->priv->device); |
748 | - break; |
749 | - default: |
750 | - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
751 | - break; |
752 | - } |
753 | + GsdIdleMonitor *monitor = gsd_idle_monitor (object); |
754 | + |
755 | + switch (prop_id) |
756 | + { |
757 | + case PROP_DEVICE_ID: |
758 | + g_value_set_int (value, monitor->device_id); |
759 | + break; |
760 | + default: |
761 | + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
762 | + break; |
763 | + } |
764 | } |
765 | |
766 | static void |
767 | gsd_idle_monitor_set_property (GObject *object, |
768 | - guint prop_id, |
769 | - const GValue *value, |
770 | - GParamSpec *pspec) |
771 | + guint prop_id, |
772 | + const GValue *value, |
773 | + GParamSpec *pspec) |
774 | { |
775 | - GsdIdleMonitor *monitor = GSD_IDLE_MONITOR (object); |
776 | - switch (prop_id) |
777 | - { |
778 | - case PROP_DEVICE: |
779 | - monitor->priv->device = g_value_dup_object (value); |
780 | - break; |
781 | - default: |
782 | - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
783 | - break; |
784 | - } |
785 | + GsdIdleMonitor *monitor = gsd_idle_monitor (object); |
786 | + switch (prop_id) |
787 | + { |
788 | + case PROP_DEVICE_ID: |
789 | + monitor->device_id = g_value_get_int (value); |
790 | + break; |
791 | + default: |
792 | + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
793 | + break; |
794 | + } |
795 | } |
796 | |
797 | static void |
798 | gsd_idle_monitor_constructed (GObject *object) |
799 | { |
800 | - GsdIdleMonitor *monitor = GSD_IDLE_MONITOR (object); |
801 | - |
802 | - monitor->priv->display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); |
803 | - init_xsync (monitor); |
804 | -} |
805 | - |
806 | -static gboolean |
807 | -gsd_idle_monitor_initable_init (GInitable *initable, |
808 | - GCancellable *cancellable, |
809 | - GError **error) |
810 | -{ |
811 | - GsdIdleMonitor *monitor; |
812 | - |
813 | - monitor = GSD_IDLE_MONITOR (initable); |
814 | - |
815 | - if (monitor->priv->counter == None) { |
816 | - g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, |
817 | - "Per-device idletime is not supported"); |
818 | - return FALSE; |
819 | - } |
820 | - |
821 | - return TRUE; |
822 | -} |
823 | - |
824 | -static void |
825 | -gsd_idle_monitor_initable_iface_init (GInitableIface *iface) |
826 | -{ |
827 | - iface->init = gsd_idle_monitor_initable_init; |
828 | + GsdIdleMonitor *monitor = gsd_idle_monitor (object); |
829 | + |
830 | + monitor->display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); |
831 | + init_xsync (monitor); |
832 | } |
833 | |
834 | static void |
835 | gsd_idle_monitor_class_init (GsdIdleMonitorClass *klass) |
836 | { |
837 | - GObjectClass *object_class = G_OBJECT_CLASS (klass); |
838 | - |
839 | - object_class->dispose = gsd_idle_monitor_dispose; |
840 | - object_class->constructed = gsd_idle_monitor_constructed; |
841 | - object_class->get_property = gsd_idle_monitor_get_property; |
842 | - object_class->set_property = gsd_idle_monitor_set_property; |
843 | - |
844 | - /** |
845 | - * GsdIdleMonitor:device: |
846 | - * |
847 | - * The device to listen to idletime on. |
848 | - */ |
849 | - obj_props[PROP_DEVICE] = |
850 | - g_param_spec_object ("device", |
851 | - "Device", |
852 | - "The device to listen to idletime on", |
853 | - GDK_TYPE_DEVICE, |
854 | - G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); |
855 | - g_object_class_install_property (object_class, PROP_DEVICE, obj_props[PROP_DEVICE]); |
856 | - |
857 | - g_type_class_add_private (klass, sizeof (GsdIdleMonitorPrivate)); |
858 | + GObjectClass *object_class = G_OBJECT_CLASS (klass); |
859 | + |
860 | + object_class->dispose = gsd_idle_monitor_dispose; |
861 | + object_class->constructed = gsd_idle_monitor_constructed; |
862 | + object_class->get_property = gsd_idle_monitor_get_property; |
863 | + object_class->set_property = gsd_idle_monitor_set_property; |
864 | + |
865 | + /** |
866 | + * GsdIdleMonitor:device_id: |
867 | + * |
868 | + * The device to listen to idletime on. |
869 | + */ |
870 | + obj_props[PROP_DEVICE_ID] = |
871 | + g_param_spec_int ("device-id", |
872 | + "Device ID", |
873 | + "The device to listen to idletime on", |
874 | + 0, 255, 0, |
875 | + G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); |
876 | + g_object_class_install_property (object_class, PROP_DEVICE_ID, obj_props[PROP_DEVICE_ID]); |
877 | } |
878 | |
879 | static void |
880 | gsd_idle_monitor_init (GsdIdleMonitor *monitor) |
881 | { |
882 | - monitor->priv = GSD_IDLE_MONITOR_GET_PRIVATE (monitor); |
883 | - |
884 | - monitor->priv->watches = g_hash_table_new_full (NULL, |
885 | - NULL, |
886 | - NULL, |
887 | - (GDestroyNotify)idle_monitor_watch_free); |
888 | - |
889 | - monitor->priv->alarms = g_hash_table_new (NULL, NULL); |
890 | + monitor->watches = g_hash_table_new_full (NULL, |
891 | + NULL, |
892 | + NULL, |
893 | + (GDestroyNotify)idle_monitor_watch_free); |
894 | + |
895 | + monitor->alarms = g_hash_table_new (NULL, NULL); |
896 | +} |
897 | + |
898 | +static void |
899 | +ensure_device_monitor (int device_id) |
900 | +{ |
901 | + if (device_monitors[device_id]) |
902 | + return; |
903 | + |
904 | + device_monitors[device_id] = g_object_new (GSD_TYPE_IDLE_MONITOR, "device-id", device_id, NULL); |
905 | + device_id_max = MAX (device_id_max, device_id); |
906 | } |
907 | |
908 | /** |
909 | - * gsd_idle_monitor_new: |
910 | + * gsd_idle_monitor_get_core: |
911 | * |
912 | - * Returns: a new #GsdIdleMonitor that tracks the server-global |
913 | + * Returns: (transfer none): the #GsdIdleMonitor that tracks the server-global |
914 | * idletime for all devices. To track device-specific idletime, |
915 | - * use gsd_idle_monitor_new_for_device(). |
916 | + * use gsd_idle_monitor_get_for_device(). |
917 | */ |
918 | GsdIdleMonitor * |
919 | -gsd_idle_monitor_new (void) |
920 | +gsd_idle_monitor_get_core (void) |
921 | { |
922 | - return GSD_IDLE_MONITOR (g_initable_new (GSD_TYPE_IDLE_MONITOR, NULL, NULL, NULL)); |
923 | + ensure_device_monitor (0); |
924 | + return device_monitors[0]; |
925 | } |
926 | |
927 | /** |
928 | - * gsd_idle_monitor_new_for_device: |
929 | - * @device: A #GdkDevice to get the idle time for. |
930 | + * gsd_idle_monitor_get_for_device: |
931 | + * @device_id: the device to get the idle time for. |
932 | * |
933 | - * Returns: a new #GsdIdleMonitor that tracks the device-specific |
934 | - * idletime for @device. If device-specific idletime is not available, |
935 | - * %NULL is returned, and @error is set. To track server-global |
936 | - * idletime for all devices, use gsd_idle_monitor_new(). |
937 | + * Returns: (transfer none): a new #GsdIdleMonitor that tracks the |
938 | + * device-specific idletime for @device. To track server-global idletime |
939 | + * for all devices, use gsd_idle_monitor_get_core(). |
940 | */ |
941 | GsdIdleMonitor * |
942 | -gsd_idle_monitor_new_for_device (GdkDevice *device) |
943 | -{ |
944 | - return GSD_IDLE_MONITOR (g_initable_new (GSD_TYPE_IDLE_MONITOR, NULL, NULL, |
945 | - "device", device, NULL)); |
946 | +gsd_idle_monitor_get_for_device (int device_id) |
947 | +{ |
948 | + g_return_val_if_fail (device_id > 0 && device_id < 256, NULL); |
949 | + |
950 | + ensure_device_monitor (device_id); |
951 | + return device_monitors[device_id]; |
952 | +} |
953 | + |
954 | +static gboolean |
955 | +fire_watch_idle (gpointer data) |
956 | +{ |
957 | + GsdIdleMonitorWatch *watch = data; |
958 | + |
959 | + watch->idle_source_id = 0; |
960 | + fire_watch (watch); |
961 | + |
962 | + return FALSE; |
963 | } |
964 | |
965 | static GsdIdleMonitorWatch * |
966 | -make_watch (GsdIdleMonitor *monitor, |
967 | - XSyncAlarm xalarm, |
968 | - GsdIdleMonitorWatchFunc callback, |
969 | +make_watch (GsdIdleMonitor *monitor, |
970 | + guint64 timeout_msec, |
971 | + GsdIdleMonitorWatchFunc callback, |
972 | gpointer user_data, |
973 | GDestroyNotify notify) |
974 | { |
975 | - GsdIdleMonitorWatch *watch; |
976 | - |
977 | - watch = g_slice_new0 (GsdIdleMonitorWatch); |
978 | - watch->monitor = monitor; |
979 | - watch->id = get_next_watch_serial (); |
980 | - watch->callback = callback; |
981 | - watch->user_data = user_data; |
982 | - watch->notify = notify; |
983 | - watch->xalarm = xalarm; |
984 | - |
985 | - g_hash_table_insert (monitor->priv->watches, |
986 | - GUINT_TO_POINTER (watch->id), |
987 | - watch); |
988 | - return watch; |
989 | + GsdIdleMonitorWatch *watch; |
990 | + |
991 | + watch = g_slice_new0 (GsdIdleMonitorWatch); |
992 | + watch->monitor = monitor; |
993 | + watch->id = get_next_watch_serial (); |
994 | + watch->callback = callback; |
995 | + watch->user_data = user_data; |
996 | + watch->notify = notify; |
997 | + watch->timeout_msec = timeout_msec; |
998 | + |
999 | + if (timeout_msec != 0) |
1000 | + { |
1001 | + watch->xalarm = _xsync_alarm_set (monitor, XSyncPositiveTransition, timeout_msec, TRUE); |
1002 | + |
1003 | + g_hash_table_add (monitor->alarms, (gpointer) watch->xalarm); |
1004 | + |
1005 | + if (gsd_idle_monitor_get_idletime (monitor) > (gint64)timeout_msec) |
1006 | + watch->idle_source_id = g_idle_add (fire_watch_idle, watch); |
1007 | + } |
1008 | + else if (monitor->user_active_alarm != None) |
1009 | + { |
1010 | + watch->xalarm = monitor->user_active_alarm; |
1011 | + |
1012 | + set_alarm_enabled (monitor->display, monitor->user_active_alarm, TRUE); |
1013 | + } |
1014 | + |
1015 | + g_hash_table_insert (monitor->watches, |
1016 | + GUINT_TO_POINTER (watch->id), |
1017 | + watch); |
1018 | + return watch; |
1019 | } |
1020 | |
1021 | /** |
1022 | @@ -519,25 +567,23 @@ |
1023 | */ |
1024 | guint |
1025 | gsd_idle_monitor_add_idle_watch (GsdIdleMonitor *monitor, |
1026 | - guint64 interval_msec, |
1027 | - GsdIdleMonitorWatchFunc callback, |
1028 | - gpointer user_data, |
1029 | - GDestroyNotify notify) |
1030 | + guint64 interval_msec, |
1031 | + GsdIdleMonitorWatchFunc callback, |
1032 | + gpointer user_data, |
1033 | + GDestroyNotify notify) |
1034 | { |
1035 | - GsdIdleMonitorWatch *watch; |
1036 | - |
1037 | - g_return_val_if_fail (GSD_IS_IDLE_MONITOR (monitor), 0); |
1038 | - |
1039 | - watch = make_watch (monitor, |
1040 | - _xsync_alarm_set (monitor, XSyncPositiveTransition, interval_msec, TRUE), |
1041 | - callback, |
1042 | - user_data, |
1043 | - notify); |
1044 | - |
1045 | - g_hash_table_add (monitor->priv->alarms, |
1046 | - (gpointer) watch->xalarm); |
1047 | - |
1048 | - return watch->id; |
1049 | + GsdIdleMonitorWatch *watch; |
1050 | + |
1051 | + g_return_val_if_fail (GSD_IS_IDLE_MONITOR (monitor), 0); |
1052 | + g_return_val_if_fail (interval_msec > 0, 0); |
1053 | + |
1054 | + watch = make_watch (monitor, |
1055 | + interval_msec, |
1056 | + callback, |
1057 | + user_data, |
1058 | + notify); |
1059 | + |
1060 | + return watch->id; |
1061 | } |
1062 | |
1063 | /** |
1064 | @@ -558,25 +604,21 @@ |
1065 | */ |
1066 | guint |
1067 | gsd_idle_monitor_add_user_active_watch (GsdIdleMonitor *monitor, |
1068 | - GsdIdleMonitorWatchFunc callback, |
1069 | - gpointer user_data, |
1070 | - GDestroyNotify notify) |
1071 | + GsdIdleMonitorWatchFunc callback, |
1072 | + gpointer user_data, |
1073 | + GDestroyNotify notify) |
1074 | { |
1075 | - GsdIdleMonitorWatch *watch; |
1076 | - |
1077 | - g_return_val_if_fail (GSD_IS_IDLE_MONITOR (monitor), 0); |
1078 | - |
1079 | - set_alarm_enabled (monitor->priv->display, |
1080 | - monitor->priv->user_active_alarm, |
1081 | - TRUE); |
1082 | - |
1083 | - watch = make_watch (monitor, |
1084 | - monitor->priv->user_active_alarm, |
1085 | - callback, |
1086 | - user_data, |
1087 | - notify); |
1088 | - |
1089 | - return watch->id; |
1090 | + GsdIdleMonitorWatch *watch; |
1091 | + |
1092 | + g_return_val_if_fail (GSD_IS_IDLE_MONITOR (monitor), 0); |
1093 | + |
1094 | + watch = make_watch (monitor, |
1095 | + 0, |
1096 | + callback, |
1097 | + user_data, |
1098 | + notify); |
1099 | + |
1100 | + return watch->id; |
1101 | } |
1102 | |
1103 | /** |
1104 | @@ -590,12 +632,15 @@ |
1105 | */ |
1106 | void |
1107 | gsd_idle_monitor_remove_watch (GsdIdleMonitor *monitor, |
1108 | - guint id) |
1109 | + guint id) |
1110 | { |
1111 | - g_return_if_fail (GSD_IS_IDLE_MONITOR (monitor)); |
1112 | + g_return_if_fail (GSD_IS_IDLE_MONITOR (monitor)); |
1113 | |
1114 | - g_hash_table_remove (monitor->priv->watches, |
1115 | - GUINT_TO_POINTER (id)); |
1116 | + g_object_ref (monitor); |
1117 | + g_hash_table_remove (monitor->watches, |
1118 | + GUINT_TO_POINTER (id)); |
1119 | + |
1120 | + g_object_unref (monitor); |
1121 | } |
1122 | |
1123 | /** |
1124 | @@ -607,10 +652,326 @@ |
1125 | gint64 |
1126 | gsd_idle_monitor_get_idletime (GsdIdleMonitor *monitor) |
1127 | { |
1128 | - XSyncValue value; |
1129 | - |
1130 | - if (!XSyncQueryCounter (monitor->priv->display, monitor->priv->counter, &value)) |
1131 | - return -1; |
1132 | - |
1133 | - return _xsyncvalue_to_int64 (value); |
1134 | -} |
1135 | + XSyncValue value; |
1136 | + |
1137 | + if (!XSyncQueryCounter (monitor->display, monitor->counter, &value)) |
1138 | + return -1; |
1139 | + |
1140 | + return _xsyncvalue_to_int64 (value); |
1141 | +} |
1142 | + |
1143 | +static gboolean |
1144 | +handle_get_idletime (MetaDBusIdleMonitor *skeleton, |
1145 | + GDBusMethodInvocation *invocation, |
1146 | + GsdIdleMonitor *monitor) |
1147 | +{ |
1148 | + guint64 idletime; |
1149 | + |
1150 | + idletime = gsd_idle_monitor_get_idletime (monitor); |
1151 | + meta_dbus_idle_monitor_complete_get_idletime (skeleton, invocation, idletime); |
1152 | + |
1153 | + return TRUE; |
1154 | +} |
1155 | + |
1156 | +typedef struct { |
1157 | + MetaDBusIdleMonitor *dbus_monitor; |
1158 | + GsdIdleMonitor *monitor; |
1159 | + char *dbus_name; |
1160 | + guint watch_id; |
1161 | + guint name_watcher_id; |
1162 | +} DBusWatch; |
1163 | + |
1164 | +static void |
1165 | +destroy_dbus_watch (gpointer data) |
1166 | +{ |
1167 | + DBusWatch *watch = data; |
1168 | + |
1169 | + g_object_unref (watch->dbus_monitor); |
1170 | + g_object_unref (watch->monitor); |
1171 | + g_free (watch->dbus_name); |
1172 | + g_bus_unwatch_name (watch->name_watcher_id); |
1173 | + |
1174 | + g_slice_free (DBusWatch, watch); |
1175 | +} |
1176 | + |
1177 | +static void |
1178 | +dbus_idle_callback (GsdIdleMonitor *monitor, |
1179 | + guint watch_id, |
1180 | + gpointer user_data) |
1181 | +{ |
1182 | + DBusWatch *watch = user_data; |
1183 | + GDBusInterfaceSkeleton *skeleton = G_DBUS_INTERFACE_SKELETON (watch->dbus_monitor); |
1184 | + |
1185 | + g_dbus_connection_emit_signal (g_dbus_interface_skeleton_get_connection (skeleton), |
1186 | + watch->dbus_name, |
1187 | + g_dbus_interface_skeleton_get_object_path (skeleton), |
1188 | + "org.gnome.Mutter.IdleMonitor", |
1189 | + "WatchFired", |
1190 | + g_variant_new ("(u)", watch_id), |
1191 | + NULL); |
1192 | +} |
1193 | + |
1194 | +static void |
1195 | +name_vanished_callback (GDBusConnection *connection, |
1196 | + const char *name, |
1197 | + gpointer user_data) |
1198 | +{ |
1199 | + DBusWatch *watch = user_data; |
1200 | + |
1201 | + gsd_idle_monitor_remove_watch (watch->monitor, watch->watch_id); |
1202 | + |
1203 | + if (xsync) |
1204 | + g_slice_free(GsdXSync, xsync); |
1205 | +} |
1206 | + |
1207 | +static DBusWatch * |
1208 | +make_dbus_watch (MetaDBusIdleMonitor *skeleton, |
1209 | + GDBusMethodInvocation *invocation, |
1210 | + GsdIdleMonitor *monitor) |
1211 | +{ |
1212 | + DBusWatch *watch; |
1213 | + |
1214 | + watch = g_slice_new (DBusWatch); |
1215 | + watch->dbus_monitor = g_object_ref (skeleton); |
1216 | + watch->monitor = g_object_ref (monitor); |
1217 | + watch->dbus_name = g_strdup (g_dbus_method_invocation_get_sender (invocation)); |
1218 | + watch->name_watcher_id = g_bus_watch_name_on_connection (g_dbus_method_invocation_get_connection (invocation), |
1219 | + watch->dbus_name, |
1220 | + G_BUS_NAME_WATCHER_FLAGS_NONE, |
1221 | + NULL, /* appeared */ |
1222 | + name_vanished_callback, |
1223 | + watch, NULL); |
1224 | + |
1225 | + return watch; |
1226 | +} |
1227 | + |
1228 | +static gboolean |
1229 | +handle_add_idle_watch (MetaDBusIdleMonitor *skeleton, |
1230 | + GDBusMethodInvocation *invocation, |
1231 | + guint64 interval, |
1232 | + GsdIdleMonitor *monitor) |
1233 | +{ |
1234 | + DBusWatch *watch; |
1235 | + |
1236 | + watch = make_dbus_watch (skeleton, invocation, monitor); |
1237 | + watch->watch_id = gsd_idle_monitor_add_idle_watch (monitor, interval, |
1238 | + dbus_idle_callback, watch, destroy_dbus_watch); |
1239 | + |
1240 | + meta_dbus_idle_monitor_complete_add_idle_watch (skeleton, invocation, watch->watch_id); |
1241 | + |
1242 | + return TRUE; |
1243 | +} |
1244 | + |
1245 | +static gboolean |
1246 | +handle_add_user_active_watch (MetaDBusIdleMonitor *skeleton, |
1247 | + GDBusMethodInvocation *invocation, |
1248 | + GsdIdleMonitor *monitor) |
1249 | +{ |
1250 | + DBusWatch *watch; |
1251 | + |
1252 | + watch = make_dbus_watch (skeleton, invocation, monitor); |
1253 | + watch->watch_id = gsd_idle_monitor_add_user_active_watch (monitor, |
1254 | + dbus_idle_callback, watch, |
1255 | + destroy_dbus_watch); |
1256 | + |
1257 | + meta_dbus_idle_monitor_complete_add_user_active_watch (skeleton, invocation, watch->watch_id); |
1258 | + |
1259 | + return TRUE; |
1260 | +} |
1261 | + |
1262 | +static gboolean |
1263 | +handle_remove_watch (MetaDBusIdleMonitor *skeleton, |
1264 | + GDBusMethodInvocation *invocation, |
1265 | + guint id, |
1266 | + GsdIdleMonitor *monitor) |
1267 | +{ |
1268 | + gsd_idle_monitor_remove_watch (monitor, id); |
1269 | + meta_dbus_idle_monitor_complete_remove_watch (skeleton, invocation); |
1270 | + |
1271 | + return TRUE; |
1272 | +} |
1273 | + |
1274 | +static void |
1275 | +create_monitor_skeleton (GDBusObjectManagerServer *manager, |
1276 | + GsdIdleMonitor *monitor, |
1277 | + const char *path) |
1278 | +{ |
1279 | + MetaDBusIdleMonitor *skeleton; |
1280 | + MetaDBusObjectSkeleton *object; |
1281 | + |
1282 | + skeleton = meta_dbus_idle_monitor_skeleton_new (); |
1283 | + g_signal_connect_object (skeleton, "handle-add-idle-watch", |
1284 | + G_CALLBACK (handle_add_idle_watch), monitor, 0); |
1285 | + g_signal_connect_object (skeleton, "handle-add-user-active-watch", |
1286 | + G_CALLBACK (handle_add_user_active_watch), monitor, 0); |
1287 | + g_signal_connect_object (skeleton, "handle-remove-watch", |
1288 | + G_CALLBACK (handle_remove_watch), monitor, 0); |
1289 | + g_signal_connect_object (skeleton, "handle-get-idletime", |
1290 | + G_CALLBACK (handle_get_idletime), monitor, 0); |
1291 | + |
1292 | + object = meta_dbus_object_skeleton_new (path); |
1293 | + meta_dbus_object_skeleton_set_idle_monitor (object, skeleton); |
1294 | + |
1295 | + g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object)); |
1296 | + |
1297 | + g_object_unref (skeleton); |
1298 | + g_object_unref (object); |
1299 | +} |
1300 | + |
1301 | +static void |
1302 | +on_device_added (GdkDeviceManager *device_manager, |
1303 | + GdkDevice *device, |
1304 | + GDBusObjectManagerServer *manager) |
1305 | +{ |
1306 | + |
1307 | + GsdIdleMonitor *monitor; |
1308 | + int device_id; |
1309 | + char *path; |
1310 | + |
1311 | + g_object_ref (device); |
1312 | + device_id = gdk_x11_device_get_id (device); |
1313 | + monitor = gsd_idle_monitor_get_for_device (device_id); |
1314 | + g_object_ref (monitor); |
1315 | + path = g_strdup_printf ("/org/gnome/Mutter/IdleMonitor/Device%d", device_id); |
1316 | + |
1317 | + create_monitor_skeleton (manager, monitor, path); |
1318 | + g_free (path); |
1319 | +} |
1320 | + |
1321 | +static void |
1322 | +on_device_removed (GdkDeviceManager *device_manager, |
1323 | + GdkDevice *device, |
1324 | + GDBusObjectManagerServer *manager) |
1325 | +{ |
1326 | + int device_id; |
1327 | + char *path; |
1328 | + |
1329 | + device_id = gdk_x11_device_get_id (device); |
1330 | + path = g_strdup_printf ("/org/gnome/Mutter/IdleMonitor/Device%d", device_id); |
1331 | + g_dbus_object_manager_server_unexport (manager, path); |
1332 | + g_free (path); |
1333 | + |
1334 | + g_object_unref (device_monitors[device_id]); |
1335 | + g_clear_object (&device_monitors[device_id]); |
1336 | + if (device_id == device_id_max) |
1337 | + device_id_max--; |
1338 | +} |
1339 | + |
1340 | +static void |
1341 | +on_bus_acquired (GDBusConnection *connection, |
1342 | + const char *name, |
1343 | + gpointer user_data) |
1344 | +{ |
1345 | + GDBusObjectManagerServer *manager; |
1346 | + GdkDeviceManager *device_manager; |
1347 | + GsdIdleMonitor *monitor; |
1348 | + GList *devices, *iter; |
1349 | + char *path; |
1350 | + |
1351 | + manager = g_dbus_object_manager_server_new ("/org/gnome/Mutter/IdleMonitor"); |
1352 | + |
1353 | + /* We never clear the core monitor, as that's supposed to cumulate idle times from |
1354 | + all devices */ |
1355 | + monitor = gsd_idle_monitor_get_core (); |
1356 | + path = g_strdup ("/org/gnome/Mutter/IdleMonitor/Core"); |
1357 | + create_monitor_skeleton (manager, monitor, path); |
1358 | + g_free (path); |
1359 | + |
1360 | + device_manager = gdk_display_get_device_manager (gdk_display_get_default ()); |
1361 | + g_object_ref (device_manager); |
1362 | + |
1363 | + devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER); |
1364 | + devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_SLAVE)); |
1365 | + devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING)); |
1366 | + |
1367 | + for (iter = devices; iter; iter = iter->next) |
1368 | + on_device_added (device_manager, iter->data, manager); |
1369 | + |
1370 | + g_list_free (devices); |
1371 | + |
1372 | + g_signal_connect_object (device_manager, "device-added", |
1373 | + G_CALLBACK (on_device_added), manager, 0); |
1374 | + g_signal_connect_object (device_manager, "device-removed", |
1375 | + G_CALLBACK (on_device_removed), manager, 0); |
1376 | + |
1377 | + g_dbus_object_manager_server_set_connection (manager, connection); |
1378 | + |
1379 | + gdk_window_add_filter (NULL, (GdkFilterFunc)xevent_filter, monitor); |
1380 | +} |
1381 | + |
1382 | +static void |
1383 | +on_name_acquired (GDBusConnection *connection, |
1384 | + const char *name, |
1385 | + gpointer user_data) |
1386 | +{ |
1387 | + g_debug ("Acquired name %s\n", name); |
1388 | +} |
1389 | + |
1390 | +static void |
1391 | +on_name_lost (GDBusConnection *connection, |
1392 | + const char *name, |
1393 | + gpointer user_data) |
1394 | +{ |
1395 | + g_debug ("Lost or failed to acquire name %s\n", name); |
1396 | + |
1397 | + gdk_window_remove_filter (NULL, (GdkFilterFunc)xevent_filter, NULL); |
1398 | + //mainloop_quit(); |
1399 | +} |
1400 | + |
1401 | +static void |
1402 | +init_xsync_global (void) |
1403 | +{ |
1404 | + int major, minor; |
1405 | + xsync->display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); |
1406 | + xsync->have_xsync = FALSE; |
1407 | + |
1408 | + xsync->sync_error_base = 0; |
1409 | + xsync->sync_event_base = 0; |
1410 | + |
1411 | + /* I don't think we really have to fill these in */ |
1412 | + major = SYNC_MAJOR_VERSION; |
1413 | + minor = SYNC_MINOR_VERSION; |
1414 | + |
1415 | + if (!XSyncQueryExtension (xsync->display, |
1416 | + &xsync->sync_event_base, |
1417 | + &xsync->sync_error_base) || |
1418 | + !XSyncInitialize (xsync->display, |
1419 | + &major, &minor)) |
1420 | + { |
1421 | + xsync->sync_error_base = 0; |
1422 | + xsync->sync_event_base = 0; |
1423 | + } |
1424 | + else |
1425 | + { |
1426 | + xsync->have_xsync = TRUE; |
1427 | + XSyncSetPriority (xsync->display, None, 10); |
1428 | + } |
1429 | + |
1430 | + g_warning ("Attempted to init Xsync, found version %d.%d error base %d event base %d\n", |
1431 | + major, minor, |
1432 | + xsync->sync_error_base, |
1433 | + xsync->sync_event_base); |
1434 | +} |
1435 | + |
1436 | +void |
1437 | +gsd_idle_monitor_init_dbus (gboolean replace) |
1438 | +{ |
1439 | + static int dbus_name_id; |
1440 | + |
1441 | + if (dbus_name_id > 0) |
1442 | + return; |
1443 | + |
1444 | + xsync = g_slice_new0 (GsdXSync); |
1445 | + init_xsync_global(); |
1446 | + |
1447 | + dbus_name_id = g_bus_own_name (G_BUS_TYPE_SESSION, |
1448 | + "org.gnome.Mutter.IdleMonitor", |
1449 | + G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT | |
1450 | + (replace ? |
1451 | + G_BUS_NAME_OWNER_FLAGS_REPLACE : 0), |
1452 | + on_bus_acquired, |
1453 | + on_name_acquired, |
1454 | + on_name_lost, |
1455 | + NULL, NULL); |
1456 | +} |
1457 | + |
1458 | |
1459 | === modified file 'gnome-settings-daemon/gsd-idle-monitor.h' |
1460 | --- gnome-settings-daemon/gsd-idle-monitor.h 2014-08-29 04:27:34 +0000 |
1461 | +++ gnome-settings-daemon/gsd-idle-monitor.h 2014-10-10 08:23:44 +0000 |
1462 | @@ -1,81 +1,61 @@ |
1463 | -/* -*- mode: C; c-file-style: "linux"; indent-tabs-mode: t -*- |
1464 | - * |
1465 | - * Adapted from gnome-session/gnome-session/gs-idle-monitor.h |
1466 | - * |
1467 | - * Copyright (C) 2012 Red Hat, Inc. |
1468 | - * |
1469 | - * This program is free software; you can redistribute it and/or modify |
1470 | - * it under the terms of the GNU General Public License as published by |
1471 | - * the Free Software Foundation; either version 2 of the License, or |
1472 | - * (at your option) any later version. |
1473 | - * |
1474 | - * This program is distributed in the hope that it will be useful, |
1475 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1476 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1477 | - * GNU General Public License for more details. |
1478 | +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ |
1479 | + |
1480 | +/* |
1481 | + * Copyright 2013 Red Hat, Inc. |
1482 | + * |
1483 | + * This program is free software; you can redistribute it and/or |
1484 | + * modify it under the terms of the GNU General Public License as |
1485 | + * published by the Free Software Foundation; either version 2 of the |
1486 | + * License, or (at your option) any later version. |
1487 | + * |
1488 | + * This program is distributed in the hope that it will be useful, but |
1489 | + * WITHOUT ANY WARRANTY; without even the implied warranty of |
1490 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1491 | + * General Public License for more details. |
1492 | * |
1493 | * You should have received a copy of the GNU General Public License |
1494 | * along with this program; if not, write to the Free Software |
1495 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1496 | - * |
1497 | - * Authors: William Jon McCann <mccann@jhu.edu> |
1498 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
1499 | + * 02111-1307, USA. |
1500 | */ |
1501 | |
1502 | -#ifndef __GSD_IDLE_MONITOR_H__ |
1503 | -#define __GSD_IDLE_MONITOR_H__ |
1504 | +#ifndef gsd_idle_monitor_H |
1505 | +#define gsd_idle_monitor_H |
1506 | |
1507 | #include <glib-object.h> |
1508 | -#include <gdk/gdk.h> |
1509 | - |
1510 | -G_BEGIN_DECLS |
1511 | - |
1512 | -#define GSD_TYPE_IDLE_MONITOR (gsd_idle_monitor_get_type ()) |
1513 | -#define GSD_IDLE_MONITOR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_IDLE_MONITOR, GsdIdleMonitor)) |
1514 | -#define GSD_IDLE_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_IDLE_MONITOR, GsdIdleMonitorClass)) |
1515 | -#define GSD_IS_IDLE_MONITOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_IDLE_MONITOR)) |
1516 | -#define GSD_IS_IDLE_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_IDLE_MONITOR)) |
1517 | -#define GSD_IDLE_MONITOR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_IDLE_MONITOR, GsdIdleMonitorClass)) |
1518 | - |
1519 | -typedef struct _GsdIdleMonitor GsdIdleMonitor; |
1520 | -typedef struct _GsdIdleMonitorClass GsdIdleMonitorClass; |
1521 | -typedef struct _GsdIdleMonitorPrivate GsdIdleMonitorPrivate; |
1522 | - |
1523 | -struct _GsdIdleMonitor |
1524 | -{ |
1525 | - GObject parent; |
1526 | - GsdIdleMonitorPrivate *priv; |
1527 | -}; |
1528 | - |
1529 | -struct _GsdIdleMonitorClass |
1530 | -{ |
1531 | - GObjectClass parent_class; |
1532 | -}; |
1533 | - |
1534 | -typedef void (*GsdIdleMonitorWatchFunc) (GsdIdleMonitor *monitor, |
1535 | - guint id, |
1536 | - gpointer user_data); |
1537 | - |
1538 | -GType gsd_idle_monitor_get_type (void); |
1539 | - |
1540 | -GsdIdleMonitor * gsd_idle_monitor_new (void); |
1541 | -GsdIdleMonitor * gsd_idle_monitor_new_for_device (GdkDevice *device); |
1542 | - |
1543 | -guint gsd_idle_monitor_add_idle_watch (GsdIdleMonitor *monitor, |
1544 | - guint64 interval_msec, |
1545 | - GsdIdleMonitorWatchFunc callback, |
1546 | - gpointer user_data, |
1547 | - GDestroyNotify notify); |
1548 | - |
1549 | -guint gsd_idle_monitor_add_user_active_watch (GsdIdleMonitor *monitor, |
1550 | - GsdIdleMonitorWatchFunc callback, |
1551 | - gpointer user_data, |
1552 | - GDestroyNotify notify); |
1553 | - |
1554 | -void gsd_idle_monitor_remove_watch (GsdIdleMonitor *monitor, |
1555 | - guint id); |
1556 | - |
1557 | -gint64 gsd_idle_monitor_get_idletime (GsdIdleMonitor *monitor); |
1558 | - |
1559 | -G_END_DECLS |
1560 | - |
1561 | -#endif /* __GSD_IDLE_MONITOR_H__ */ |
1562 | + |
1563 | +#define GSD_TYPE_IDLE_MONITOR (gsd_idle_monitor_get_type ()) |
1564 | +#define gsd_idle_monitor(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSD_TYPE_IDLE_MONITOR, GsdIdleMonitor)) |
1565 | +#define gsd_idle_monitor_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GSD_TYPE_IDLE_MONITOR, GsdIdleMonitorClass)) |
1566 | +#define GSD_IS_IDLE_MONITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSD_TYPE_IDLE_MONITOR)) |
1567 | +#define GSD_IS_IDLE_MONITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GSD_TYPE_IDLE_MONITOR)) |
1568 | +#define gsd_idle_monitor_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GSD_TYPE_IDLE_MONITOR, GsdIdleMonitorClass)) |
1569 | + |
1570 | +typedef struct _GsdIdleMonitor GsdIdleMonitor; |
1571 | +typedef struct _GsdIdleMonitorClass GsdIdleMonitorClass; |
1572 | + |
1573 | +GType gsd_idle_monitor_get_type (void); |
1574 | + |
1575 | +typedef void (*GsdIdleMonitorWatchFunc) (GsdIdleMonitor *monitor, |
1576 | + guint watch_id, |
1577 | + gpointer user_data); |
1578 | + |
1579 | +GsdIdleMonitor *gsd_idle_monitor_get_core (void); |
1580 | +GsdIdleMonitor *gsd_idle_monitor_get_for_device (int device_id); |
1581 | + |
1582 | +guint gsd_idle_monitor_add_idle_watch (GsdIdleMonitor *monitor, |
1583 | + guint64 interval_msec, |
1584 | + GsdIdleMonitorWatchFunc callback, |
1585 | + gpointer user_data, |
1586 | + GDestroyNotify notify); |
1587 | + |
1588 | +guint gsd_idle_monitor_add_user_active_watch (GsdIdleMonitor *monitor, |
1589 | + GsdIdleMonitorWatchFunc callback, |
1590 | + gpointer user_data, |
1591 | + GDestroyNotify notify); |
1592 | + |
1593 | +void gsd_idle_monitor_remove_watch (GsdIdleMonitor *monitor, |
1594 | + guint id); |
1595 | +gint64 gsd_idle_monitor_get_idletime (GsdIdleMonitor *monitor); |
1596 | + |
1597 | +#endif |
1598 | |
1599 | === added file 'gnome-settings-daemon/idle-monitor.xml' |
1600 | --- gnome-settings-daemon/idle-monitor.xml 1970-01-01 00:00:00 +0000 |
1601 | +++ gnome-settings-daemon/idle-monitor.xml 2014-10-10 08:23:44 +0000 |
1602 | @@ -0,0 +1,35 @@ |
1603 | +<!DOCTYPE node PUBLIC |
1604 | +'-//freedesktop//DTD D-BUS Object Introspection 1.0//EN' |
1605 | +'http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd'> |
1606 | +<node> |
1607 | + <!-- |
1608 | + org.gnome.Mutter.IdleMonitor: |
1609 | + @short_description: idle monitor interface |
1610 | + |
1611 | + This interface is used by gnome-desktop to implement |
1612 | + user activity monitoring. |
1613 | + --> |
1614 | + |
1615 | + <interface name="org.gnome.Mutter.IdleMonitor"> |
1616 | + <method name="GetIdletime"> |
1617 | + <arg name="idletime" direction="out" type="t"/> |
1618 | + </method> |
1619 | + |
1620 | + <method name="AddIdleWatch"> |
1621 | + <arg name="interval" direction="in" type="t" /> |
1622 | + <arg name="id" direction="out" type="u" /> |
1623 | + </method> |
1624 | + |
1625 | + <method name="AddUserActiveWatch"> |
1626 | + <arg name="id" direction="out" type="u" /> |
1627 | + </method> |
1628 | + |
1629 | + <method name="RemoveWatch"> |
1630 | + <arg name="id" direction="in" type="u" /> |
1631 | + </method> |
1632 | + |
1633 | + <signal name="WatchFired"> |
1634 | + <arg name="id" direction="out" type="u" /> |
1635 | + </signal> |
1636 | + </interface> |
1637 | +</node> |
1638 | |
1639 | === modified file 'gnome-settings-daemon/main.c' |
1640 | --- gnome-settings-daemon/main.c 2013-11-13 01:37:21 +0000 |
1641 | +++ gnome-settings-daemon/main.c 2014-10-10 08:23:44 +0000 |
1642 | @@ -37,6 +37,7 @@ |
1643 | #include "gnome-settings-plugin.h" |
1644 | #include "gnome-settings-profile.h" |
1645 | #include "gnome-settings-session.h" |
1646 | +#include "gsd-idle-monitor-private.h" |
1647 | |
1648 | #define GNOME_SESSION_DBUS_NAME "org.gnome.SessionManager" |
1649 | #define GNOME_SESSION_CLIENT_PRIVATE_DBUS_INTERFACE "org.gnome.SessionManager.ClientPrivate" |
1650 | @@ -55,6 +56,8 @@ |
1651 | {NULL} |
1652 | }; |
1653 | |
1654 | + |
1655 | + |
1656 | static gboolean |
1657 | timed_exit_cb (void) |
1658 | { |
1659 | @@ -444,6 +447,7 @@ |
1660 | g_setenv ("G_MESSAGES_DEBUG", "all", FALSE); |
1661 | } |
1662 | |
1663 | + |
1664 | int |
1665 | main (int argc, char *argv[]) |
1666 | { |
1667 | @@ -454,6 +458,7 @@ |
1668 | textdomain (GETTEXT_PACKAGE); |
1669 | setlocale (LC_ALL, ""); |
1670 | |
1671 | + |
1672 | parse_args (&argc, &argv); |
1673 | |
1674 | gnome_settings_profile_start ("opening gtk display"); |
1675 | @@ -472,6 +477,8 @@ |
1676 | if (do_timed_exit) { |
1677 | g_timeout_add_seconds (30, (GSourceFunc) timed_exit_cb, NULL); |
1678 | } |
1679 | + |
1680 | + gsd_idle_monitor_init_dbus (replace); |
1681 | |
1682 | gtk_main (); |
1683 | |
1684 | |
1685 | === modified file 'plugins/cursor/gsd-cursor-manager.c' |
1686 | --- plugins/cursor/gsd-cursor-manager.c 2014-08-29 04:27:34 +0000 |
1687 | +++ plugins/cursor/gsd-cursor-manager.c 2014-10-10 08:23:44 +0000 |
1688 | @@ -129,10 +129,14 @@ |
1689 | gpointer user_data) |
1690 | { |
1691 | GdkDevice *device; |
1692 | + int device_id; |
1693 | GsdCursorManager *manager = GSD_CURSOR_MANAGER (user_data); |
1694 | + GdkDeviceManager *device_manager; |
1695 | |
1696 | /* Oh, so you're active? */ |
1697 | - g_object_get (G_OBJECT (monitor), "device", &device, NULL); |
1698 | + g_object_get (G_OBJECT (monitor), "device_id", &device_id, NULL); |
1699 | + device_manager = gdk_display_get_device_manager (gdk_display_get_default ()); |
1700 | + device = gdk_x11_device_manager_lookup (device_manager, device_id); |
1701 | g_debug ("Device %d '%s' became active", gdk_x11_device_get_id (device), gdk_device_get_name (device)); |
1702 | set_cursor_visibility (manager, |
1703 | gdk_device_get_source (device) != GDK_SOURCE_TOUCHSCREEN); |
1704 | @@ -154,6 +158,7 @@ |
1705 | GError **error) |
1706 | { |
1707 | GsdIdleMonitor *monitor; |
1708 | + int device_id; |
1709 | |
1710 | if (g_hash_table_lookup (manager->priv->monitors, device) != NULL) |
1711 | return TRUE; |
1712 | @@ -165,7 +170,8 @@ |
1713 | return TRUE; |
1714 | |
1715 | /* Create IdleMonitors for each pointer device */ |
1716 | - monitor = gsd_idle_monitor_new_for_device (device); |
1717 | + device_id = gdk_x11_device_get_id (device); |
1718 | + monitor = gsd_idle_monitor_get_for_device (device_id); |
1719 | if (!monitor) { |
1720 | g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, |
1721 | "Per-device idletime monitor not available"); |
1722 | |
1723 | === modified file 'plugins/power/gsd-power-manager.c' |
1724 | --- plugins/power/gsd-power-manager.c 2014-08-29 04:27:34 +0000 |
1725 | +++ plugins/power/gsd-power-manager.c 2014-10-10 08:23:44 +0000 |
1726 | @@ -3548,7 +3548,7 @@ |
1727 | "use-time-for-policy"); |
1728 | |
1729 | /* create IDLETIME watcher */ |
1730 | - manager->priv->idle_monitor = gsd_idle_monitor_new (); |
1731 | + manager->priv->idle_monitor = gsd_idle_monitor_get_core (); |
1732 | |
1733 | /* set up the screens */ |
1734 | g_signal_connect (manager->priv->rr_screen, "changed", G_CALLBACK (on_randr_event), manager); |
Thanks, small nitpick in the inline comments.
Are you sure nothing is using the removed symbols? I know they've only been there for a short time.