]> Pileus Git - ~andy/gtk/blob - gdk/x11/gdkdisplay-x11.c
x11: unconst-cast result of g_get_prgname()
[~andy/gtk] / gdk / x11 / gdkdisplay-x11.c
1 /* GDK - The GIMP Drawing Kit
2  * gdkdisplay-x11.c
3  * 
4  * Copyright 2001 Sun Microsystems Inc.
5  * Copyright (C) 2004 Nokia Corporation
6  *
7  * Erwann Chenede <erwann.chenede@sun.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public
20  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21  */
22
23 #include "config.h"
24
25 #include "gdkasync.h"
26 #include "gdkdisplay.h"
27 #include "gdkeventsource.h"
28 #include "gdkeventtranslator.h"
29 #include "gdkinternals.h"
30 #include "gdkscreen.h"
31 #include "gdkinternals.h"
32 #include "gdkdeviceprivate.h"
33 #include "gdkkeysprivate.h"
34 #include "gdkdevicemanager.h"
35 #include "xsettings-client.h"
36 #include "gdkdisplay-x11.h"
37 #include "gdkprivate-x11.h"
38 #include "gdkscreen-x11.h"
39
40 #include <glib.h>
41 #include <glib/gprintf.h>
42 #include <stdlib.h>
43 #include <string.h>
44 #include <errno.h>
45 #include <unistd.h>
46
47 #include <X11/Xatom.h>
48
49 #ifdef HAVE_XKB
50 #include <X11/XKBlib.h>
51 #endif
52
53 #ifdef HAVE_XFIXES
54 #include <X11/extensions/Xfixes.h>
55 #endif
56
57 #include <X11/extensions/shape.h>
58
59 #ifdef HAVE_XCOMPOSITE
60 #include <X11/extensions/Xcomposite.h>
61 #endif
62
63 #ifdef HAVE_XDAMAGE
64 #include <X11/extensions/Xdamage.h>
65 #endif
66
67 #ifdef HAVE_RANDR
68 #include <X11/extensions/Xrandr.h>
69 #endif
70
71 typedef struct _GdkErrorTrap  GdkErrorTrap;
72
73 struct _GdkErrorTrap
74 {
75   /* Next sequence when trap was pushed, i.e. first sequence to
76    * ignore
77    */
78   gulong start_sequence;
79
80   /* Next sequence when trap was popped, i.e. first sequence
81    * to not ignore. 0 if trap is still active.
82    */
83   gulong end_sequence;
84
85   /* Most recent error code within the sequence */
86   int error_code;
87 };
88
89 static void   gdk_x11_display_dispose            (GObject            *object);
90 static void   gdk_x11_display_finalize           (GObject            *object);
91
92 static void     gdk_x11_display_event_translator_init (GdkEventTranslatorIface *iface);
93
94 static gboolean gdk_x11_display_translate_event (GdkEventTranslator *translator,
95                                                  GdkDisplay         *display,
96                                                  GdkEvent           *event,
97                                                  XEvent             *xevent);
98
99 static void gdk_internal_connection_watch (Display  *display,
100                                            XPointer  arg,
101                                            gint      fd,
102                                            gboolean  opening,
103                                            XPointer *watch_data);
104
105 typedef struct _GdkEventTypeX11 GdkEventTypeX11;
106
107 struct _GdkEventTypeX11
108 {
109   gint base;
110   gint n_events;
111 };
112
113 /* Note that we never *directly* use WM_LOCALE_NAME, WM_PROTOCOLS,
114  * but including them here has the side-effect of getting them
115  * into the internal Xlib cache
116  */
117 static const char *const precache_atoms[] = {
118   "UTF8_STRING",
119   "WM_CLIENT_LEADER",
120   "WM_DELETE_WINDOW",
121   "WM_ICON_NAME",
122   "WM_LOCALE_NAME",
123   "WM_NAME",
124   "WM_PROTOCOLS",
125   "WM_TAKE_FOCUS",
126   "WM_WINDOW_ROLE",
127   "_NET_ACTIVE_WINDOW",
128   "_NET_CURRENT_DESKTOP",
129   "_NET_FRAME_EXTENTS",
130   "_NET_STARTUP_ID",
131   "_NET_WM_CM_S0",
132   "_NET_WM_DESKTOP",
133   "_NET_WM_ICON",
134   "_NET_WM_ICON_NAME",
135   "_NET_WM_NAME",
136   "_NET_WM_PID",
137   "_NET_WM_PING",
138   "_NET_WM_STATE",
139   "_NET_WM_STATE_ABOVE",
140   "_NET_WM_STATE_BELOW",
141   "_NET_WM_STATE_FULLSCREEN",
142   "_NET_WM_STATE_MODAL",
143   "_NET_WM_STATE_MAXIMIZED_VERT",
144   "_NET_WM_STATE_MAXIMIZED_HORZ",
145   "_NET_WM_STATE_SKIP_TASKBAR",
146   "_NET_WM_STATE_SKIP_PAGER",
147   "_NET_WM_STATE_STICKY",
148   "_NET_WM_SYNC_REQUEST",
149   "_NET_WM_SYNC_REQUEST_COUNTER",
150   "_NET_WM_WINDOW_TYPE",
151   "_NET_WM_WINDOW_TYPE_NORMAL",
152   "_NET_WM_USER_TIME",
153   "_NET_VIRTUAL_ROOTS",
154   "GDK_SELECTION",
155   "_NET_WM_STATE_FOCUSED"
156 };
157
158 static char *gdk_sm_client_id;
159
160 G_DEFINE_TYPE_WITH_CODE (GdkX11Display, gdk_x11_display, GDK_TYPE_DISPLAY,
161                          G_IMPLEMENT_INTERFACE (GDK_TYPE_EVENT_TRANSLATOR,
162                                                 gdk_x11_display_event_translator_init))
163
164
165 static void
166 gdk_x11_display_init (GdkX11Display *display)
167 {
168   _gdk_x11_display_manager_add_display (gdk_display_manager_get (),
169                                         GDK_DISPLAY (display));
170 }
171
172 static void
173 gdk_x11_display_event_translator_init (GdkEventTranslatorIface *iface)
174 {
175   iface->translate_event = gdk_x11_display_translate_event;
176 }
177
178 static void
179 do_net_wm_state_changes (GdkWindow *window)
180 {
181   GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
182   GdkWindowState old_state;
183
184   if (GDK_WINDOW_DESTROYED (window) ||
185       gdk_window_get_window_type (window) != GDK_WINDOW_TOPLEVEL)
186     return;
187
188   old_state = gdk_window_get_state (window);
189
190   /* For found_sticky to remain TRUE, we have to also be on desktop
191    * 0xFFFFFFFF
192    */
193   if (old_state & GDK_WINDOW_STATE_STICKY)
194     {
195       if (!(toplevel->have_sticky && toplevel->on_all_desktops))
196         gdk_synthesize_window_state (window,
197                                      GDK_WINDOW_STATE_STICKY,
198                                      0);
199     }
200   else
201     {
202       if (toplevel->have_sticky && toplevel->on_all_desktops)
203         gdk_synthesize_window_state (window,
204                                      0,
205                                      GDK_WINDOW_STATE_STICKY);
206     }
207
208   if (old_state & GDK_WINDOW_STATE_FULLSCREEN)
209     {
210       if (!toplevel->have_fullscreen)
211         gdk_synthesize_window_state (window,
212                                      GDK_WINDOW_STATE_FULLSCREEN,
213                                      0);
214     }
215   else
216     {
217       if (toplevel->have_fullscreen)
218         gdk_synthesize_window_state (window,
219                                      0,
220                                      GDK_WINDOW_STATE_FULLSCREEN);
221     }
222
223   /* Our "maximized" means both vertical and horizontal; if only one,
224    * we don't expose that via GDK
225    */
226   if (old_state & GDK_WINDOW_STATE_MAXIMIZED)
227     {
228       if (!(toplevel->have_maxvert && toplevel->have_maxhorz))
229         gdk_synthesize_window_state (window,
230                                      GDK_WINDOW_STATE_MAXIMIZED,
231                                      0);
232     }
233   else
234     {
235       if (toplevel->have_maxvert && toplevel->have_maxhorz)
236         gdk_synthesize_window_state (window,
237                                      0,
238                                      GDK_WINDOW_STATE_MAXIMIZED);
239     }
240
241   if (old_state & GDK_WINDOW_STATE_FOCUSED)
242     {
243       if (!toplevel->have_focused)
244         gdk_synthesize_window_state (window,
245                                      GDK_WINDOW_STATE_FOCUSED,
246                                      0);
247     }
248   else
249     {
250       if (toplevel->have_focused)
251         gdk_synthesize_window_state (window,
252                                      0,
253                                      GDK_WINDOW_STATE_FOCUSED);
254     }
255
256   if (old_state & GDK_WINDOW_STATE_ICONIFIED)
257     {
258       if (!toplevel->have_hidden)
259         gdk_synthesize_window_state (window,
260                                      GDK_WINDOW_STATE_ICONIFIED,
261                                      0);
262     }
263   else
264     {
265       if (toplevel->have_hidden)
266         gdk_synthesize_window_state (window,
267                                      0,
268                                      GDK_WINDOW_STATE_ICONIFIED);
269     }
270 }
271
272 static void
273 gdk_check_wm_desktop_changed (GdkWindow *window)
274 {
275   GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
276   GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
277
278   Atom type;
279   gint format;
280   gulong nitems;
281   gulong bytes_after;
282   guchar *data;
283   gulong *desktop;
284
285   type = None;
286   gdk_x11_display_error_trap_push (display);
287   XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
288                       GDK_WINDOW_XID (window),
289                       gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
290                       0, G_MAXLONG, False, XA_CARDINAL, &type,
291                       &format, &nitems,
292                       &bytes_after, &data);
293   gdk_x11_display_error_trap_pop_ignored (display);
294
295   if (type != None)
296     {
297       desktop = (gulong *)data;
298       toplevel->on_all_desktops = ((*desktop & 0xFFFFFFFF) == 0xFFFFFFFF);
299       XFree (desktop);
300     }
301   else
302     toplevel->on_all_desktops = FALSE;
303
304   do_net_wm_state_changes (window);
305 }
306
307 static void
308 gdk_check_wm_state_changed (GdkWindow *window)
309 {
310   GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
311   GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
312   GdkScreen *screen = GDK_WINDOW_SCREEN (window);
313
314   Atom type;
315   gint format;
316   gulong nitems;
317   gulong bytes_after;
318   guchar *data;
319   Atom *atoms = NULL;
320   gulong i;
321
322   gboolean had_sticky = toplevel->have_sticky;
323
324   toplevel->have_sticky = FALSE;
325   toplevel->have_maxvert = FALSE;
326   toplevel->have_maxhorz = FALSE;
327   toplevel->have_fullscreen = FALSE;
328   toplevel->have_focused = FALSE;
329   toplevel->have_hidden = FALSE;
330
331   type = None;
332   gdk_x11_display_error_trap_push (display);
333   XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
334                       gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
335                       0, G_MAXLONG, False, XA_ATOM, &type, &format, &nitems,
336                       &bytes_after, &data);
337   gdk_x11_display_error_trap_pop_ignored (display);
338
339   if (type != None)
340     {
341       Atom sticky_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_STICKY");
342       Atom maxvert_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_VERT");
343       Atom maxhorz_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_HORZ");
344       Atom fullscreen_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_FULLSCREEN");
345       Atom focused_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_FOCUSED");
346       Atom hidden_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_HIDDEN");
347
348       atoms = (Atom *)data;
349
350       i = 0;
351       while (i < nitems)
352         {
353           if (atoms[i] == sticky_atom)
354             toplevel->have_sticky = TRUE;
355           else if (atoms[i] == maxvert_atom)
356             toplevel->have_maxvert = TRUE;
357           else if (atoms[i] == maxhorz_atom)
358             toplevel->have_maxhorz = TRUE;
359           else if (atoms[i] == fullscreen_atom)
360             toplevel->have_fullscreen = TRUE;
361           else if (atoms[i] == focused_atom)
362             toplevel->have_focused = TRUE;
363           else if (atoms[i] == hidden_atom)
364             toplevel->have_hidden = TRUE;
365
366           ++i;
367         }
368
369       XFree (atoms);
370     }
371
372   if (!gdk_x11_screen_supports_net_wm_hint (screen,
373                                             gdk_atom_intern_static_string ("_NET_WM_STATE_FOCUSED")))
374     toplevel->have_focused = TRUE;
375
376   /* When have_sticky is turned on, we have to check the DESKTOP property
377    * as well.
378    */
379   if (toplevel->have_sticky && !had_sticky)
380     gdk_check_wm_desktop_changed (window);
381   else
382     do_net_wm_state_changes (window);
383 }
384
385 static GdkWindow *
386 get_event_window (GdkEventTranslator *translator,
387                   XEvent             *xevent)
388 {
389   GdkDisplay *display;
390   Window xwindow;
391
392   display = (GdkDisplay *) translator;
393
394   switch (xevent->type)
395     {
396     case DestroyNotify:
397       xwindow = xevent->xdestroywindow.window;
398       break;
399     case UnmapNotify:
400       xwindow = xevent->xunmap.window;
401       break;
402     case MapNotify:
403       xwindow = xevent->xmap.window;
404       break;
405     case ConfigureNotify:
406       xwindow = xevent->xconfigure.window;
407       break;
408     default:
409       xwindow = xevent->xany.window;
410     }
411
412   return gdk_x11_window_lookup_for_display (display, xwindow);
413 }
414
415 static gboolean
416 gdk_x11_display_translate_event (GdkEventTranslator *translator,
417                                  GdkDisplay         *display,
418                                  GdkEvent           *event,
419                                  XEvent             *xevent)
420 {
421   GdkWindow *window;
422   GdkWindowImplX11 *window_impl = NULL;
423   GdkScreen *screen = NULL;
424   GdkX11Screen *x11_screen = NULL;
425   GdkToplevelX11 *toplevel = NULL;
426   GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
427   gboolean return_val;
428
429   /* Find the GdkWindow that this event relates to.
430    * Basically this means substructure events
431    * are reported same as structure events
432    */
433   window = get_event_window (translator, xevent);
434
435   if (window)
436     {
437       /* We may receive events such as NoExpose/GraphicsExpose
438        * and ShmCompletion for pixmaps
439        */
440       if (!GDK_IS_WINDOW (window))
441         return FALSE;
442
443       screen = GDK_WINDOW_SCREEN (window);
444       x11_screen = GDK_X11_SCREEN (screen);
445       toplevel = _gdk_x11_window_get_toplevel (window);
446       window_impl = GDK_WINDOW_IMPL_X11 (window->impl);
447
448       g_object_ref (window);
449     }
450
451   event->any.window = window;
452   event->any.send_event = xevent->xany.send_event ? TRUE : FALSE;
453
454   if (window && GDK_WINDOW_DESTROYED (window))
455     {
456       if (xevent->type != DestroyNotify)
457         {
458           return_val = FALSE;
459           goto done;
460         }
461     }
462
463   if (xevent->type == DestroyNotify)
464     {
465       int i, n;
466
467       n = gdk_display_get_n_screens (display);
468       for (i = 0; i < n; i++)
469         {
470           screen = gdk_display_get_screen (display, i);
471           x11_screen = GDK_X11_SCREEN (screen);
472
473           if (x11_screen->wmspec_check_window == xevent->xdestroywindow.window)
474             {
475               x11_screen->wmspec_check_window = None;
476               x11_screen->last_wmspec_check_time = 0;
477               g_free (x11_screen->window_manager_name);
478               x11_screen->window_manager_name = g_strdup ("unknown");
479
480               /* careful, reentrancy */
481               _gdk_x11_screen_window_manager_changed (screen);
482
483               return_val = FALSE;
484               goto done;
485             }
486         }
487     }
488
489   /* We do a "manual" conversion of the XEvent to a
490    *  GdkEvent. The structures are mostly the same so
491    *  the conversion is fairly straightforward. We also
492    *  optionally print debugging info regarding events
493    *  received.
494    */
495
496   return_val = TRUE;
497
498   switch (xevent->type)
499     {
500     case KeymapNotify:
501       GDK_NOTE (EVENTS,
502                 g_message ("keymap notify"));
503
504       /* Not currently handled */
505       return_val = FALSE;
506       break;
507
508     case Expose:
509       GDK_NOTE (EVENTS,
510                 g_message ("expose:\t\twindow: %ld  %d  x,y: %d %d  w,h: %d %d%s",
511                            xevent->xexpose.window, xevent->xexpose.count,
512                            xevent->xexpose.x, xevent->xexpose.y,
513                            xevent->xexpose.width, xevent->xexpose.height,
514                            event->any.send_event ? " (send)" : ""));
515
516       if (window == NULL)
517         {
518           return_val = FALSE;
519           break;
520         }
521
522       {
523         GdkRectangle expose_rect;
524
525         expose_rect.x = xevent->xexpose.x;
526         expose_rect.y = xevent->xexpose.y;
527         expose_rect.width = xevent->xexpose.width;
528         expose_rect.height = xevent->xexpose.height;
529
530         _gdk_x11_window_process_expose (window, xevent->xexpose.serial, &expose_rect);
531         return_val = FALSE;
532       }
533
534       break;
535
536     case GraphicsExpose:
537       {
538         GdkRectangle expose_rect;
539
540         GDK_NOTE (EVENTS,
541                   g_message ("graphics expose:\tdrawable: %ld",
542                              xevent->xgraphicsexpose.drawable));
543
544         if (window == NULL)
545           {
546             return_val = FALSE;
547             break;
548           }
549
550         expose_rect.x = xevent->xgraphicsexpose.x;
551         expose_rect.y = xevent->xgraphicsexpose.y;
552         expose_rect.width = xevent->xgraphicsexpose.width;
553         expose_rect.height = xevent->xgraphicsexpose.height;
554
555         _gdk_x11_window_process_expose (window, xevent->xgraphicsexpose.serial, &expose_rect);
556         return_val = FALSE;
557       }
558       break;
559
560     case VisibilityNotify:
561 #ifdef G_ENABLE_DEBUG
562       if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
563         switch (xevent->xvisibility.state)
564           {
565           case VisibilityFullyObscured:
566             g_message ("visibility notify:\twindow: %ld  none",
567                        xevent->xvisibility.window);
568             break;
569           case VisibilityPartiallyObscured:
570             g_message ("visibility notify:\twindow: %ld  partial",
571                        xevent->xvisibility.window);
572             break;
573           case VisibilityUnobscured:
574             g_message ("visibility notify:\twindow: %ld  full",
575                        xevent->xvisibility.window);
576             break;
577           }
578 #endif /* G_ENABLE_DEBUG */
579
580       if (window == NULL)
581         {
582           return_val = FALSE;
583           break;
584         }
585
586       event->visibility.type = GDK_VISIBILITY_NOTIFY;
587       event->visibility.window = window;
588
589       switch (xevent->xvisibility.state)
590         {
591         case VisibilityFullyObscured:
592           event->visibility.state = GDK_VISIBILITY_FULLY_OBSCURED;
593           break;
594
595         case VisibilityPartiallyObscured:
596           event->visibility.state = GDK_VISIBILITY_PARTIAL;
597           break;
598
599         case VisibilityUnobscured:
600           event->visibility.state = GDK_VISIBILITY_UNOBSCURED;
601           break;
602         }
603
604       break;
605
606     case CreateNotify:
607       GDK_NOTE (EVENTS,
608                 g_message ("create notify:\twindow: %ld  x,y: %d %d     w,h: %d %d  b-w: %d  parent: %ld         ovr: %d",
609                            xevent->xcreatewindow.window,
610                            xevent->xcreatewindow.x,
611                            xevent->xcreatewindow.y,
612                            xevent->xcreatewindow.width,
613                            xevent->xcreatewindow.height,
614                            xevent->xcreatewindow.border_width,
615                            xevent->xcreatewindow.parent,
616                            xevent->xcreatewindow.override_redirect));
617       /* not really handled */
618       break;
619
620     case DestroyNotify:
621       GDK_NOTE (EVENTS,
622                 g_message ("destroy notify:\twindow: %ld",
623                            xevent->xdestroywindow.window));
624
625       /* Ignore DestroyNotify from SubstructureNotifyMask */
626       if (xevent->xdestroywindow.window == xevent->xdestroywindow.event)
627         {
628           event->any.type = GDK_DESTROY;
629           event->any.window = window;
630
631           return_val = window && !GDK_WINDOW_DESTROYED (window);
632
633           if (window && GDK_WINDOW_XID (window) != x11_screen->xroot_window)
634             gdk_window_destroy_notify (window);
635         }
636       else
637         return_val = FALSE;
638
639       break;
640
641     case UnmapNotify:
642       GDK_NOTE (EVENTS,
643                 g_message ("unmap notify:\t\twindow: %ld",
644                            xevent->xmap.window));
645
646       event->any.type = GDK_UNMAP;
647       event->any.window = window;
648
649       /* If the WM supports the _NET_WM_STATE_HIDDEN hint, we do not want to
650        * interpret UnmapNotify events as implying iconic state.
651        * http://bugzilla.gnome.org/show_bug.cgi?id=590726.
652        */
653       if (screen &&
654           !gdk_x11_screen_supports_net_wm_hint (screen,
655                                                 gdk_atom_intern_static_string ("_NET_WM_STATE_HIDDEN")))
656         {
657           /* If we are shown (not withdrawn) and get an unmap, it means we were
658            * iconified in the X sense. If we are withdrawn, and get an unmap, it
659            * means we hid the window ourselves, so we will have already flipped
660            * the iconified bit off.
661            */
662           if (window && GDK_WINDOW_IS_MAPPED (window))
663             gdk_synthesize_window_state (window,
664                                          0,
665                                          GDK_WINDOW_STATE_ICONIFIED);
666         }
667
668       if (window)
669         _gdk_x11_window_grab_check_unmap (window, xevent->xany.serial);
670
671       break;
672
673     case MapNotify:
674       GDK_NOTE (EVENTS,
675                 g_message ("map notify:\t\twindow: %ld",
676                            xevent->xmap.window));
677
678       event->any.type = GDK_MAP;
679       event->any.window = window;
680
681       /* Unset iconified if it was set */
682       if (window && (window->state & GDK_WINDOW_STATE_ICONIFIED))
683         gdk_synthesize_window_state (window,
684                                      GDK_WINDOW_STATE_ICONIFIED,
685                                      0);
686
687       break;
688
689     case ReparentNotify:
690       GDK_NOTE (EVENTS,
691                 g_message ("reparent notify:\twindow: %ld  x,y: %d %d  parent: %ld      ovr: %d",
692                            xevent->xreparent.window,
693                            xevent->xreparent.x,
694                            xevent->xreparent.y,
695                            xevent->xreparent.parent,
696                            xevent->xreparent.override_redirect));
697
698       /* Not currently handled */
699       return_val = FALSE;
700       break;
701
702     case ConfigureNotify:
703       GDK_NOTE (EVENTS,
704                 g_message ("configure notify:\twindow: %ld  x,y: %d %d  w,h: %d %d  b-w: %d  above: %ld  ovr: %d%s",
705                            xevent->xconfigure.window,
706                            xevent->xconfigure.x,
707                            xevent->xconfigure.y,
708                            xevent->xconfigure.width,
709                            xevent->xconfigure.height,
710                            xevent->xconfigure.border_width,
711                            xevent->xconfigure.above,
712                            xevent->xconfigure.override_redirect,
713                            !window
714                            ? " (discarding)"
715                            : window->window_type == GDK_WINDOW_CHILD
716                            ? " (discarding child)"
717                            : xevent->xconfigure.event != xevent->xconfigure.window
718                            ? " (discarding substructure)"
719                            : ""));
720       if (window && GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
721         {
722           window->width = xevent->xconfigure.width;
723           window->height = xevent->xconfigure.height;
724
725           _gdk_window_update_size (window);
726           _gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
727           _gdk_x11_screen_size_changed (screen, xevent);
728         }
729
730 #ifdef HAVE_XSYNC
731       if (toplevel && display_x11->use_sync && !XSyncValueIsZero (toplevel->pending_counter_value))
732         {
733           toplevel->current_counter_value = toplevel->pending_counter_value;
734           XSyncIntToValue (&toplevel->pending_counter_value, 0);
735         }
736 #endif
737
738     if (!window ||
739           xevent->xconfigure.event != xevent->xconfigure.window ||
740           GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD ||
741           GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
742         return_val = FALSE;
743       else
744         {
745           event->configure.type = GDK_CONFIGURE;
746           event->configure.window = window;
747           event->configure.width = xevent->xconfigure.width;
748           event->configure.height = xevent->xconfigure.height;
749
750           if (!xevent->xconfigure.send_event &&
751               !xevent->xconfigure.override_redirect &&
752               !GDK_WINDOW_DESTROYED (window))
753             {
754               gint tx = 0;
755               gint ty = 0;
756               Window child_window = 0;
757
758               gdk_x11_display_error_trap_push (display);
759               if (XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
760                                          GDK_WINDOW_XID (window),
761                                          x11_screen->xroot_window,
762                                          0, 0,
763                                          &tx, &ty,
764                                          &child_window))
765                 {
766                   event->configure.x = tx;
767                   event->configure.y = ty;
768                 }
769               gdk_x11_display_error_trap_pop_ignored (display);
770             }
771           else
772             {
773               event->configure.x = xevent->xconfigure.x;
774               event->configure.y = xevent->xconfigure.y;
775             }
776           window->x = event->configure.x;
777           window->y = event->configure.y;
778           window->width = xevent->xconfigure.width;
779           window->height = xevent->xconfigure.height;
780
781           _gdk_window_update_size (window);
782           _gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
783
784           if (window->resize_count >= 1)
785             {
786               window->resize_count -= 1;
787
788               if (window->resize_count == 0)
789                 _gdk_x11_moveresize_configure_done (display, window);
790             }
791         }
792       break;
793
794     case PropertyNotify:
795       GDK_NOTE (EVENTS,
796                 g_message ("property notify:\twindow: %ld, atom(%ld): %s%s%s",
797                            xevent->xproperty.window,
798                            xevent->xproperty.atom,
799                            "\"",
800                            gdk_x11_get_xatom_name_for_display (display, xevent->xproperty.atom),
801                            "\""));
802
803       if (window == NULL)
804         {
805           return_val = FALSE;
806           break;
807         }
808
809       /* We compare with the serial of the last time we mapped the
810        * window to avoid refetching properties that we set ourselves
811        */
812       if (toplevel &&
813           xevent->xproperty.serial >= toplevel->map_serial)
814         {
815           if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"))
816             gdk_check_wm_state_changed (window);
817
818           if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"))
819             gdk_check_wm_desktop_changed (window);
820         }
821
822       if (window->event_mask & GDK_PROPERTY_CHANGE_MASK)
823         {
824           event->property.type = GDK_PROPERTY_NOTIFY;
825           event->property.window = window;
826           event->property.atom = gdk_x11_xatom_to_atom_for_display (display, xevent->xproperty.atom);
827           event->property.time = xevent->xproperty.time;
828           event->property.state = xevent->xproperty.state;
829         }
830       else
831         return_val = FALSE;
832
833       break;
834
835     case SelectionClear:
836       GDK_NOTE (EVENTS,
837                 g_message ("selection clear:\twindow: %ld",
838                            xevent->xproperty.window));
839
840       if (_gdk_x11_selection_filter_clear_event (&xevent->xselectionclear))
841         {
842           event->selection.type = GDK_SELECTION_CLEAR;
843           event->selection.window = window;
844           event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionclear.selection);
845           event->selection.time = xevent->xselectionclear.time;
846         }
847       else
848         return_val = FALSE;
849
850       break;
851
852     case SelectionRequest:
853       GDK_NOTE (EVENTS,
854                 g_message ("selection request:\twindow: %ld",
855                            xevent->xproperty.window));
856
857       event->selection.type = GDK_SELECTION_REQUEST;
858       event->selection.window = window;
859       event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.selection);
860       event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.target);
861       event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.property);
862       if (xevent->xselectionrequest.requestor != None)
863         event->selection.requestor = gdk_x11_window_foreign_new_for_display (display,
864                                                                              xevent->xselectionrequest.requestor);
865       else
866         event->selection.requestor = NULL;
867       event->selection.time = xevent->xselectionrequest.time;
868
869       break;
870
871     case SelectionNotify:
872       GDK_NOTE (EVENTS,
873                 g_message ("selection notify:\twindow: %ld",
874                            xevent->xproperty.window));
875
876       event->selection.type = GDK_SELECTION_NOTIFY;
877       event->selection.window = window;
878       event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.selection);
879       event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.target);
880       if (xevent->xselection.property == None)
881         event->selection.property = GDK_NONE;
882       else
883         event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.property);
884       event->selection.time = xevent->xselection.time;
885
886       break;
887
888     case ColormapNotify:
889       GDK_NOTE (EVENTS,
890                 g_message ("colormap notify:\twindow: %ld",
891                            xevent->xcolormap.window));
892
893       /* Not currently handled */
894       return_val = FALSE;
895       break;
896
897     case ClientMessage:
898       GDK_NOTE (EVENTS,
899                 g_message ("client message:\twindow: %ld",
900                            xevent->xclient.window));
901
902       /* Not currently handled */
903       return_val = FALSE;
904       break;
905
906     case MappingNotify:
907       GDK_NOTE (EVENTS,
908                 g_message ("mapping notify"));
909
910       /* Let XLib know that there is a new keyboard mapping.
911        */
912       XRefreshKeyboardMapping (&xevent->xmapping);
913       _gdk_x11_keymap_keys_changed (display);
914       return_val = FALSE;
915       break;
916
917     default:
918 #ifdef HAVE_XFIXES
919       if (xevent->type - display_x11->xfixes_event_base == XFixesSelectionNotify)
920         {
921           XFixesSelectionNotifyEvent *selection_notify = (XFixesSelectionNotifyEvent *)xevent;
922
923           _gdk_x11_screen_process_owner_change (screen, xevent);
924           
925           event->owner_change.type = GDK_OWNER_CHANGE;
926           event->owner_change.window = window;
927           if (selection_notify->owner != None)
928             event->owner_change.owner = gdk_x11_window_foreign_new_for_display (display,
929                                                                                 selection_notify->owner);
930           else
931             event->owner_change.owner = NULL;
932           event->owner_change.reason = selection_notify->subtype;
933           event->owner_change.selection = 
934             gdk_x11_xatom_to_atom_for_display (display, 
935                                                selection_notify->selection);
936           event->owner_change.time = selection_notify->timestamp;
937           event->owner_change.selection_time = selection_notify->selection_timestamp;
938           
939           return_val = TRUE;
940         }
941       else
942 #endif
943 #ifdef HAVE_RANDR
944       if (xevent->type - display_x11->xrandr_event_base == RRScreenChangeNotify ||
945           xevent->type - display_x11->xrandr_event_base == RRNotify)
946         {
947           if (screen)
948             _gdk_x11_screen_size_changed (screen, xevent);
949         }
950       else
951 #endif
952 #if defined(HAVE_XCOMPOSITE) && defined (HAVE_XDAMAGE) && defined (HAVE_XFIXES)
953       if (display_x11->have_xdamage && window && window->composited &&
954           xevent->type == display_x11->xdamage_event_base + XDamageNotify &&
955           ((XDamageNotifyEvent *) xevent)->damage == window_impl->damage)
956         {
957           XDamageNotifyEvent *damage_event = (XDamageNotifyEvent *) xevent;
958           XserverRegion repair;
959           GdkRectangle rect;
960
961           rect.x = window->x + damage_event->area.x;
962           rect.y = window->y + damage_event->area.y;
963           rect.width = damage_event->area.width;
964           rect.height = damage_event->area.height;
965
966           repair = XFixesCreateRegion (display_x11->xdisplay,
967                                        &damage_event->area, 1);
968           XDamageSubtract (display_x11->xdisplay,
969                            window_impl->damage,
970                            repair, None);
971           XFixesDestroyRegion (display_x11->xdisplay, repair);
972
973           if (window->parent != NULL)
974            _gdk_x11_window_process_expose (window->parent,
975                                            damage_event->serial, &rect);
976
977           return_val = TRUE;
978         }
979       else
980 #endif
981 #ifdef HAVE_XKB
982       if (xevent->type == display_x11->xkb_event_type)
983         {
984           XkbEvent *xkb_event = (XkbEvent *) xevent;
985
986           switch (xkb_event->any.xkb_type)
987             {
988             case XkbNewKeyboardNotify:
989             case XkbMapNotify:
990               _gdk_x11_keymap_keys_changed (display);
991
992               return_val = FALSE;
993               break;
994
995             case XkbStateNotify:
996               _gdk_x11_keymap_state_changed (display, xevent);
997               break;
998             }
999         }
1000       else
1001 #endif
1002         return_val = FALSE;
1003     }
1004
1005  done:
1006   if (return_val)
1007     {
1008       if (event->any.window)
1009         g_object_ref (event->any.window);
1010     }
1011   else
1012     {
1013       /* Mark this event as having no resources to be freed */
1014       event->any.window = NULL;
1015       event->any.type = GDK_NOTHING;
1016     }
1017
1018   if (window)
1019     g_object_unref (window);
1020
1021   return return_val;
1022 }
1023
1024 GdkFilterReturn
1025 _gdk_wm_protocols_filter (GdkXEvent *xev,
1026                           GdkEvent  *event,
1027                           gpointer   data)
1028 {
1029   XEvent *xevent = (XEvent *)xev;
1030   GdkWindow *win = event->any.window;
1031   GdkDisplay *display;
1032   Atom atom;
1033
1034   if (!GDK_IS_X11_WINDOW (win))
1035     return GDK_FILTER_CONTINUE;
1036
1037   if (xevent->type != ClientMessage)
1038     return GDK_FILTER_CONTINUE;
1039
1040   display = GDK_WINDOW_DISPLAY (win);
1041
1042   if (xevent->xclient.message_type != gdk_x11_get_xatom_by_name_for_display (display, "WM_PROTOCOLS"))
1043     return GDK_FILTER_CONTINUE;
1044
1045   atom = (Atom) xevent->xclient.data.l[0];
1046
1047   if (atom == gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW"))
1048     {
1049   /* The delete window request specifies a window
1050    *  to delete. We don't actually destroy the
1051    *  window because "it is only a request". (The
1052    *  window might contain vital data that the
1053    *  program does not want destroyed). Instead
1054    *  the event is passed along to the program,
1055    *  which should then destroy the window.
1056    */
1057       GDK_NOTE (EVENTS,
1058                 g_message ("delete window:\t\twindow: %ld",
1059                            xevent->xclient.window));
1060
1061       event->any.type = GDK_DELETE;
1062
1063       gdk_x11_window_set_user_time (win, xevent->xclient.data.l[1]);
1064
1065       return GDK_FILTER_TRANSLATE;
1066     }
1067   else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS"))
1068     {
1069       GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (event->any.window);
1070
1071       /* There is no way of knowing reliably whether we are viewable;
1072        * so trap errors asynchronously around the XSetInputFocus call
1073        */
1074       if (toplevel && win->accept_focus)
1075         {
1076           gdk_x11_display_error_trap_push (display);
1077           XSetInputFocus (GDK_DISPLAY_XDISPLAY (display),
1078                           toplevel->focus_window,
1079                           RevertToParent,
1080                           xevent->xclient.data.l[1]);
1081           gdk_x11_display_error_trap_pop_ignored (display);
1082        }
1083
1084       return GDK_FILTER_REMOVE;
1085     }
1086   else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING") &&
1087            !_gdk_x11_display_is_root_window (display,
1088                                              xevent->xclient.window))
1089     {
1090       XClientMessageEvent xclient = xevent->xclient;
1091
1092       xclient.window = GDK_WINDOW_XROOTWIN (win);
1093       XSendEvent (GDK_WINDOW_XDISPLAY (win),
1094                   xclient.window,
1095                   False,
1096                   SubstructureRedirectMask | SubstructureNotifyMask, (XEvent *)&xclient);
1097
1098       return GDK_FILTER_REMOVE;
1099     }
1100   else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_SYNC_REQUEST") &&
1101            GDK_X11_DISPLAY (display)->use_sync)
1102     {
1103       GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (event->any.window);
1104       if (toplevel)
1105         {
1106 #ifdef HAVE_XSYNC
1107           XSyncIntsToValue (&toplevel->pending_counter_value,
1108                             xevent->xclient.data.l[2],
1109                             xevent->xclient.data.l[3]);
1110 #endif
1111         }
1112       return GDK_FILTER_REMOVE;
1113     }
1114
1115   return GDK_FILTER_CONTINUE;
1116 }
1117
1118 static void
1119 gdk_event_init (GdkDisplay *display)
1120 {
1121   GdkX11Display *display_x11;
1122   GdkDeviceManager *device_manager;
1123
1124   display_x11 = GDK_X11_DISPLAY (display);
1125   display_x11->event_source = gdk_x11_event_source_new (display);
1126
1127   gdk_x11_event_source_add_translator ((GdkEventSource *) display_x11->event_source,
1128                                        GDK_EVENT_TRANSLATOR (display));
1129
1130   device_manager = gdk_display_get_device_manager (display);
1131   gdk_x11_event_source_add_translator ((GdkEventSource *) display_x11->event_source,
1132                                         GDK_EVENT_TRANSLATOR (device_manager));
1133 }
1134
1135 static void
1136 gdk_x11_display_init_input (GdkDisplay *display)
1137 {
1138   GdkX11Display *display_x11;
1139   GdkDeviceManager *device_manager;
1140   GdkDevice *device;
1141   GList *list, *l;
1142
1143   display_x11 = GDK_X11_DISPLAY (display);
1144   device_manager = gdk_display_get_device_manager (display);
1145
1146   /* For backwards compatibility, just add
1147    * floating devices that are not keyboards.
1148    */
1149   list = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING);
1150
1151   for (l = list; l; l = l->next)
1152     {
1153       device = l->data;
1154
1155       if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
1156         continue;
1157
1158       display_x11->input_devices = g_list_prepend (display_x11->input_devices,
1159                                                    g_object_ref (l->data));
1160     }
1161
1162   g_list_free (list);
1163
1164   /* Now set "core" pointer to the first
1165    * master device that is a pointer.
1166    */
1167   list = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
1168
1169   for (l = list; l; l = l->next)
1170     {
1171       device = l->data;
1172
1173       if (gdk_device_get_source (device) != GDK_SOURCE_MOUSE)
1174         continue;
1175
1176       display->core_pointer = device;
1177       break;
1178     }
1179
1180   /* Add the core pointer to the devices list */
1181   display_x11->input_devices = g_list_prepend (display_x11->input_devices,
1182                                                g_object_ref (display->core_pointer));
1183
1184   g_list_free (list);
1185 }
1186
1187 static void
1188 set_sm_client_id (GdkDisplay  *display,
1189                   const gchar *sm_client_id)
1190 {
1191   GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
1192
1193   if (gdk_display_is_closed (display))
1194     return;
1195
1196   if (sm_client_id && strcmp (sm_client_id, ""))
1197     XChangeProperty (display_x11->xdisplay, display_x11->leader_window,
1198                      gdk_x11_get_xatom_by_name_for_display (display, "SM_CLIENT_ID"),
1199                      XA_STRING, 8, PropModeReplace, (guchar *)sm_client_id,
1200                      strlen (sm_client_id));
1201   else
1202     XDeleteProperty (display_x11->xdisplay, display_x11->leader_window,
1203                      gdk_x11_get_xatom_by_name_for_display (display, "SM_CLIENT_ID"));
1204 }
1205
1206 GdkDisplay *
1207 _gdk_x11_display_open (const gchar *display_name)
1208 {
1209   Display *xdisplay;
1210   GdkDisplay *display;
1211   GdkX11Display *display_x11;
1212   GdkWindowAttr attr;
1213   gint argc;
1214   gchar *argv[1];
1215
1216   XClassHint *class_hint;
1217   gulong pid;
1218   gint i;
1219   gint ignore;
1220   gint maj, min;
1221
1222   xdisplay = XOpenDisplay (display_name);
1223   if (!xdisplay)
1224     return NULL;
1225
1226   display = g_object_new (GDK_TYPE_X11_DISPLAY, NULL);
1227   display_x11 = GDK_X11_DISPLAY (display);
1228
1229   display_x11->xdisplay = xdisplay;
1230
1231   /* Set up handlers for Xlib internal connections */
1232   XAddConnectionWatch (xdisplay, gdk_internal_connection_watch, NULL);
1233
1234   _gdk_x11_precache_atoms (display, precache_atoms, G_N_ELEMENTS (precache_atoms));
1235
1236   /* RandR must be initialized before we initialize the screens */
1237   display_x11->have_randr12 = FALSE;
1238   display_x11->have_randr13 = FALSE;
1239 #ifdef HAVE_RANDR
1240   if (XRRQueryExtension (display_x11->xdisplay,
1241                          &display_x11->xrandr_event_base, &ignore))
1242   {
1243       int major, minor;
1244
1245       XRRQueryVersion (display_x11->xdisplay, &major, &minor);
1246
1247       if ((major == 1 && minor >= 2) || major > 1) {
1248           display_x11->have_randr12 = TRUE;
1249           if (minor >= 3 || major > 1)
1250               display_x11->have_randr13 = TRUE;
1251       }
1252
1253        gdk_x11_register_standard_event_type (display, display_x11->xrandr_event_base, RRNumberEvents);
1254   }
1255 #endif
1256
1257   /* initialize the display's screens */ 
1258   display_x11->screens = g_new (GdkScreen *, ScreenCount (display_x11->xdisplay));
1259   for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1260     display_x11->screens[i] = _gdk_x11_screen_new (display, i);
1261
1262   /* We need to initialize events after we have the screen
1263    * structures in places
1264    */
1265   for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1266     _gdk_x11_screen_init_events (display_x11->screens[i]);
1267
1268   /*set the default screen */
1269   display_x11->default_screen = display_x11->screens[DefaultScreen (display_x11->xdisplay)];
1270
1271   display->device_manager = _gdk_x11_device_manager_new (display);
1272
1273   gdk_event_init (display);
1274
1275   attr.window_type = GDK_WINDOW_TOPLEVEL;
1276   attr.wclass = GDK_INPUT_OUTPUT;
1277   attr.x = 10;
1278   attr.y = 10;
1279   attr.width = 10;
1280   attr.height = 10;
1281   attr.event_mask = 0;
1282
1283   display_x11->leader_gdk_window = gdk_window_new (GDK_X11_SCREEN (display_x11->default_screen)->root_window, 
1284                                                    &attr, GDK_WA_X | GDK_WA_Y);
1285   (_gdk_x11_window_get_toplevel (display_x11->leader_gdk_window))->is_leader = TRUE;
1286
1287   display_x11->leader_window = GDK_WINDOW_XID (display_x11->leader_gdk_window);
1288
1289   display_x11->leader_window_title_set = FALSE;
1290
1291 #ifdef HAVE_XFIXES
1292   if (XFixesQueryExtension (display_x11->xdisplay, 
1293                             &display_x11->xfixes_event_base, 
1294                             &ignore))
1295     {
1296       display_x11->have_xfixes = TRUE;
1297
1298       gdk_x11_register_standard_event_type (display,
1299                                             display_x11->xfixes_event_base, 
1300                                             XFixesNumberEvents);
1301     }
1302   else
1303 #endif
1304     display_x11->have_xfixes = FALSE;
1305
1306 #ifdef HAVE_XCOMPOSITE
1307   if (XCompositeQueryExtension (display_x11->xdisplay,
1308                                 &ignore, &ignore))
1309     {
1310       int major, minor;
1311
1312       XCompositeQueryVersion (display_x11->xdisplay, &major, &minor);
1313
1314       /* Prior to Composite version 0.4, composited windows clipped their
1315        * parents, so you had to use IncludeInferiors to draw to the parent
1316        * This isn't useful for our purposes, so require 0.4
1317        */
1318       display_x11->have_xcomposite = major > 0 || (major == 0 && minor >= 4);
1319     }
1320   else
1321 #endif
1322     display_x11->have_xcomposite = FALSE;
1323
1324 #ifdef HAVE_XDAMAGE
1325   if (XDamageQueryExtension (display_x11->xdisplay,
1326                              &display_x11->xdamage_event_base,
1327                              &ignore))
1328     {
1329       display_x11->have_xdamage = TRUE;
1330
1331       gdk_x11_register_standard_event_type (display,
1332                                             display_x11->xdamage_event_base,
1333                                             XDamageNumberEvents);
1334     }
1335   else
1336 #endif
1337     display_x11->have_xdamage = FALSE;
1338
1339   display_x11->have_shapes = FALSE;
1340   display_x11->have_input_shapes = FALSE;
1341
1342   if (XShapeQueryExtension (GDK_DISPLAY_XDISPLAY (display), &display_x11->shape_event_base, &ignore))
1343     {
1344       display_x11->have_shapes = TRUE;
1345 #ifdef ShapeInput
1346       if (XShapeQueryVersion (GDK_DISPLAY_XDISPLAY (display), &maj, &min))
1347         display_x11->have_input_shapes = (maj == 1 && min >= 1);
1348 #endif
1349     }
1350
1351   display_x11->trusted_client = TRUE;
1352   {
1353     Window root, child;
1354     int rootx, rooty, winx, winy;
1355     unsigned int xmask;
1356
1357     gdk_x11_display_error_trap_push (display);
1358     XQueryPointer (display_x11->xdisplay,
1359                    GDK_X11_SCREEN (display_x11->default_screen)->xroot_window,
1360                    &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
1361     if (G_UNLIKELY (gdk_x11_display_error_trap_pop (display) == BadWindow))
1362       {
1363         g_warning ("Connection to display %s appears to be untrusted. Pointer and keyboard grabs and inter-client communication may not work as expected.", gdk_display_get_name (display));
1364         display_x11->trusted_client = FALSE;
1365       }
1366   }
1367
1368   if (g_getenv ("GDK_SYNCHRONIZE"))
1369     XSynchronize (display_x11->xdisplay, True);
1370
1371   class_hint = XAllocClassHint();
1372   class_hint->res_name = (char *) g_get_prgname ();
1373   class_hint->res_class = (char *)gdk_get_program_class ();
1374
1375   /* XmbSetWMProperties sets the RESOURCE_NAME environment variable
1376    * from argv[0], so we just synthesize an argument array here.
1377    */
1378   argc = 1;
1379   argv[0] = (char *) g_get_prgname ();
1380
1381   XmbSetWMProperties (display_x11->xdisplay,
1382                       display_x11->leader_window,
1383                       NULL, NULL, argv, argc, NULL, NULL,
1384                       class_hint);
1385   XFree (class_hint);
1386
1387   if (gdk_sm_client_id)
1388     set_sm_client_id (display, gdk_sm_client_id);
1389
1390   pid = getpid ();
1391   XChangeProperty (display_x11->xdisplay,
1392                    display_x11->leader_window,
1393                    gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PID"),
1394                    XA_CARDINAL, 32, PropModeReplace, (guchar *) & pid, 1);
1395
1396   /* We don't yet know a valid time. */
1397   display_x11->user_time = 0;
1398   
1399 #ifdef HAVE_XKB
1400   {
1401     gint xkb_major = XkbMajorVersion;
1402     gint xkb_minor = XkbMinorVersion;
1403     if (XkbLibraryVersion (&xkb_major, &xkb_minor))
1404       {
1405         xkb_major = XkbMajorVersion;
1406         xkb_minor = XkbMinorVersion;
1407             
1408         if (XkbQueryExtension (display_x11->xdisplay, 
1409                                NULL, &display_x11->xkb_event_type, NULL,
1410                                &xkb_major, &xkb_minor))
1411           {
1412             Bool detectable_autorepeat_supported;
1413             
1414             display_x11->use_xkb = TRUE;
1415
1416             XkbSelectEvents (display_x11->xdisplay,
1417                              XkbUseCoreKbd,
1418                              XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask,
1419                              XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask);
1420
1421             /* keep this in sync with _gdk_x11_keymap_state_changed() */
1422             XkbSelectEventDetails (display_x11->xdisplay,
1423                                    XkbUseCoreKbd, XkbStateNotify,
1424                                    XkbAllStateComponentsMask,
1425                                    XkbModifierStateMask|XkbGroupStateMask);
1426
1427             XkbSetDetectableAutoRepeat (display_x11->xdisplay,
1428                                         True,
1429                                         &detectable_autorepeat_supported);
1430
1431             GDK_NOTE (MISC, g_message ("Detectable autorepeat %s.",
1432                                        detectable_autorepeat_supported ?
1433                                        "supported" : "not supported"));
1434             
1435             display_x11->have_xkb_autorepeat = detectable_autorepeat_supported;
1436           }
1437       }
1438   }
1439 #endif
1440
1441   display_x11->use_sync = FALSE;
1442 #ifdef HAVE_XSYNC
1443   {
1444     int major, minor;
1445     int error_base, event_base;
1446     
1447     if (XSyncQueryExtension (display_x11->xdisplay,
1448                              &event_base, &error_base) &&
1449         XSyncInitialize (display_x11->xdisplay,
1450                          &major, &minor))
1451       display_x11->use_sync = TRUE;
1452   }
1453 #endif
1454
1455   gdk_x11_display_init_input (display);
1456
1457   for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1458     _gdk_x11_screen_setup (display_x11->screens[i]);
1459
1460   g_signal_emit_by_name (display, "opened");
1461
1462   return display;
1463 }
1464
1465 /*
1466  * XLib internal connection handling
1467  */
1468 typedef struct _GdkInternalConnection GdkInternalConnection;
1469
1470 struct _GdkInternalConnection
1471 {
1472   gint           fd;
1473   GSource       *source;
1474   Display       *display;
1475 };
1476
1477 static gboolean
1478 process_internal_connection (GIOChannel  *gioc,
1479                              GIOCondition cond,
1480                              gpointer     data)
1481 {
1482   GdkInternalConnection *connection = (GdkInternalConnection *)data;
1483
1484   gdk_threads_enter ();
1485
1486   XProcessInternalConnection ((Display*)connection->display, connection->fd);
1487
1488   gdk_threads_leave ();
1489
1490   return TRUE;
1491 }
1492
1493 static gulong
1494 gdk_x11_display_get_next_serial (GdkDisplay *display)
1495 {
1496   return NextRequest (GDK_DISPLAY_XDISPLAY (display));
1497 }
1498
1499
1500 static GdkInternalConnection *
1501 gdk_add_connection_handler (Display *display,
1502                             guint    fd)
1503 {
1504   GIOChannel *io_channel;
1505   GdkInternalConnection *connection;
1506
1507   connection = g_new (GdkInternalConnection, 1);
1508
1509   connection->fd = fd;
1510   connection->display = display;
1511   
1512   io_channel = g_io_channel_unix_new (fd);
1513   
1514   connection->source = g_io_create_watch (io_channel, G_IO_IN);
1515   g_source_set_callback (connection->source,
1516                          (GSourceFunc)process_internal_connection, connection, NULL);
1517   g_source_attach (connection->source, NULL);
1518   
1519   g_io_channel_unref (io_channel);
1520   
1521   return connection;
1522 }
1523
1524 static void
1525 gdk_remove_connection_handler (GdkInternalConnection *connection)
1526 {
1527   g_source_destroy (connection->source);
1528   g_free (connection);
1529 }
1530
1531 static void
1532 gdk_internal_connection_watch (Display  *display,
1533                                XPointer  arg,
1534                                gint      fd,
1535                                gboolean  opening,
1536                                XPointer *watch_data)
1537 {
1538   if (opening)
1539     *watch_data = (XPointer)gdk_add_connection_handler (display, fd);
1540   else
1541     gdk_remove_connection_handler ((GdkInternalConnection *)*watch_data);
1542 }
1543
1544 static const gchar *
1545 gdk_x11_display_get_name (GdkDisplay *display)
1546 {
1547   return (gchar *) DisplayString (GDK_X11_DISPLAY (display)->xdisplay);
1548 }
1549
1550 static gint
1551 gdk_x11_display_get_n_screens (GdkDisplay *display)
1552 {
1553   return ScreenCount (GDK_X11_DISPLAY (display)->xdisplay);
1554 }
1555
1556 static GdkScreen *
1557 gdk_x11_display_get_screen (GdkDisplay *display,
1558                             gint        screen_num)
1559 {
1560   g_return_val_if_fail (ScreenCount (GDK_X11_DISPLAY (display)->xdisplay) > screen_num, NULL);
1561
1562   return GDK_X11_DISPLAY (display)->screens[screen_num];
1563 }
1564
1565 static GdkScreen *
1566 gdk_x11_display_get_default_screen (GdkDisplay *display)
1567 {
1568   return GDK_X11_DISPLAY (display)->default_screen;
1569 }
1570
1571 gboolean
1572 _gdk_x11_display_is_root_window (GdkDisplay *display,
1573                                  Window      xroot_window)
1574 {
1575   GdkX11Display *display_x11;
1576   gint i;
1577
1578   display_x11 = GDK_X11_DISPLAY (display);
1579
1580   for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1581     {
1582       if (GDK_SCREEN_XROOTWIN (display_x11->screens[i]) == xroot_window)
1583         return TRUE;
1584     }
1585   return FALSE;
1586 }
1587
1588 struct XPointerUngrabInfo {
1589   GdkDisplay *display;
1590   guint32 time;
1591 };
1592
1593 static void
1594 device_grab_update_callback (GdkDisplay *display,
1595                              gpointer    data,
1596                              gulong      serial)
1597 {
1598   GdkPointerWindowInfo *pointer_info;
1599   GdkDevice *device = data;
1600
1601   pointer_info = _gdk_display_get_pointer_info (display, device);
1602   _gdk_display_device_grab_update (display, device,
1603                                    pointer_info->last_slave, serial);
1604 }
1605
1606 #define XSERVER_TIME_IS_LATER(time1, time2)                        \
1607   ( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) ||  \
1608     (( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 ))     \
1609   )
1610
1611 void
1612 _gdk_x11_display_update_grab_info (GdkDisplay *display,
1613                                    GdkDevice  *device,
1614                                    gint        status)
1615 {
1616   if (status == GrabSuccess)
1617     _gdk_x11_roundtrip_async (display, device_grab_update_callback, device);
1618 }
1619
1620 void
1621 _gdk_x11_display_update_grab_info_ungrab (GdkDisplay *display,
1622                                           GdkDevice  *device,
1623                                           guint32     time,
1624                                           gulong      serial)
1625 {
1626   GdkDeviceGrabInfo *grab;
1627
1628   XFlush (GDK_DISPLAY_XDISPLAY (display));
1629
1630   grab = _gdk_display_get_last_device_grab (display, device);
1631   if (grab &&
1632       (time == GDK_CURRENT_TIME ||
1633        grab->time == GDK_CURRENT_TIME ||
1634        !XSERVER_TIME_IS_LATER (grab->time, time)))
1635     {
1636       grab->serial_end = serial;
1637       _gdk_x11_roundtrip_async (display, device_grab_update_callback, device);
1638     }
1639 }
1640
1641 static void
1642 gdk_x11_display_beep (GdkDisplay *display)
1643 {
1644 #ifdef HAVE_XKB
1645   XkbBell (GDK_DISPLAY_XDISPLAY (display), None, 0, None);
1646 #else
1647   XBell (GDK_DISPLAY_XDISPLAY (display), 0);
1648 #endif
1649 }
1650
1651 static void
1652 gdk_x11_display_sync (GdkDisplay *display)
1653 {
1654   XSync (GDK_DISPLAY_XDISPLAY (display), False);
1655 }
1656
1657 static void
1658 gdk_x11_display_flush (GdkDisplay *display)
1659 {
1660   if (!display->closed)
1661     XFlush (GDK_DISPLAY_XDISPLAY (display));
1662 }
1663
1664 static gboolean
1665 gdk_x11_display_has_pending (GdkDisplay *display)
1666 {
1667   return XPending (GDK_DISPLAY_XDISPLAY (display));
1668 }
1669
1670 static GdkWindow *
1671 gdk_x11_display_get_default_group (GdkDisplay *display)
1672 {
1673   g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1674
1675   return GDK_X11_DISPLAY (display)->leader_gdk_window;
1676 }
1677
1678 /**
1679  * gdk_x11_display_grab:
1680  * @display: (type GdkX11Display): a #GdkDisplay 
1681  * 
1682  * Call XGrabServer() on @display. 
1683  * To ungrab the display again, use gdk_x11_display_ungrab(). 
1684  *
1685  * gdk_x11_display_grab()/gdk_x11_display_ungrab() calls can be nested.
1686  *
1687  * Since: 2.2
1688  **/
1689 void
1690 gdk_x11_display_grab (GdkDisplay *display)
1691 {
1692   GdkX11Display *display_x11;
1693   
1694   g_return_if_fail (GDK_IS_DISPLAY (display));
1695   
1696   display_x11 = GDK_X11_DISPLAY (display);
1697   
1698   if (display_x11->grab_count == 0)
1699     XGrabServer (display_x11->xdisplay);
1700   display_x11->grab_count++;
1701 }
1702
1703 /**
1704  * gdk_x11_display_ungrab:
1705  * @display: (type GdkX11Display): a #GdkDisplay
1706  * 
1707  * Ungrab @display after it has been grabbed with 
1708  * gdk_x11_display_grab(). 
1709  *
1710  * Since: 2.2
1711  **/
1712 void
1713 gdk_x11_display_ungrab (GdkDisplay *display)
1714 {
1715   GdkX11Display *display_x11;
1716   
1717   g_return_if_fail (GDK_IS_DISPLAY (display));
1718   
1719   display_x11 = GDK_X11_DISPLAY (display);;
1720   g_return_if_fail (display_x11->grab_count > 0);
1721   
1722   display_x11->grab_count--;
1723   if (display_x11->grab_count == 0)
1724     {
1725       XUngrabServer (display_x11->xdisplay);
1726       XFlush (display_x11->xdisplay);
1727     }
1728 }
1729
1730 static void
1731 gdk_x11_display_dispose (GObject *object)
1732 {
1733   GdkDisplay *display = GDK_DISPLAY (object);
1734   GdkX11Display *display_x11 = GDK_X11_DISPLAY (object);
1735   gint           i;
1736
1737   _gdk_x11_display_manager_remove_display (gdk_display_manager_get (), display);
1738
1739   g_list_foreach (display_x11->input_devices, (GFunc) g_object_run_dispose, NULL);
1740
1741   for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1742     _gdk_screen_close (display_x11->screens[i]);
1743
1744   if (display_x11->event_source)
1745     {
1746       g_source_destroy (display_x11->event_source);
1747       g_source_unref (display_x11->event_source);
1748       display_x11->event_source = NULL;
1749     }
1750
1751   G_OBJECT_CLASS (gdk_x11_display_parent_class)->dispose (object);
1752 }
1753
1754 static void
1755 gdk_x11_display_finalize (GObject *object)
1756 {
1757   GdkX11Display *display_x11 = GDK_X11_DISPLAY (object);
1758   gint           i;
1759
1760   /* Keymap */
1761   if (display_x11->keymap)
1762     g_object_unref (display_x11->keymap);
1763
1764   /* Free motif Dnd */
1765   if (display_x11->motif_target_lists)
1766     {
1767       for (i = 0; i < display_x11->motif_n_target_lists; i++)
1768         g_list_free (display_x11->motif_target_lists[i]);
1769       g_free (display_x11->motif_target_lists);
1770     }
1771
1772   _gdk_x11_cursor_display_finalize (GDK_DISPLAY (display_x11));
1773
1774   /* Empty the event queue */
1775   _gdk_x11_display_free_translate_queue (GDK_DISPLAY (display_x11));
1776
1777   /* Atom Hashtable */
1778   g_hash_table_destroy (display_x11->atom_from_virtual);
1779   g_hash_table_destroy (display_x11->atom_to_virtual);
1780
1781   /* Leader Window */
1782   XDestroyWindow (display_x11->xdisplay, display_x11->leader_window);
1783
1784   /* List of event window extraction functions */
1785   g_slist_foreach (display_x11->event_types, (GFunc)g_free, NULL);
1786   g_slist_free (display_x11->event_types);
1787
1788   /* input GdkDevice list */
1789   g_list_free_full (display_x11->input_devices, g_object_unref);
1790
1791   /* input GdkWindow list */
1792   g_list_free_full (display_x11->input_windows, g_free);
1793
1794   /* Free all GdkScreens */
1795   for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1796     g_object_unref (display_x11->screens[i]);
1797   g_free (display_x11->screens);
1798
1799   g_free (display_x11->startup_notification_id);
1800
1801   /* X ID hashtable */
1802   g_hash_table_destroy (display_x11->xid_ht);
1803
1804   XCloseDisplay (display_x11->xdisplay);
1805
1806   /* error traps */
1807   while (display_x11->error_traps != NULL)
1808     {
1809       GdkErrorTrap *trap = display_x11->error_traps->data;
1810
1811       display_x11->error_traps =
1812         g_slist_delete_link (display_x11->error_traps,
1813                              display_x11->error_traps);
1814
1815       if (trap->end_sequence == 0)
1816         g_warning ("Display finalized with an unpopped error trap");
1817
1818       g_slice_free (GdkErrorTrap, trap);
1819     }
1820
1821   G_OBJECT_CLASS (gdk_x11_display_parent_class)->finalize (object);
1822 }
1823
1824 /**
1825  * gdk_x11_lookup_xdisplay:
1826  * @xdisplay: a pointer to an X Display
1827  * 
1828  * Find the #GdkDisplay corresponding to @display, if any exists.
1829  * 
1830  * Return value: (transfer none): the #GdkDisplay, if found, otherwise %NULL.
1831  *
1832  * Since: 2.2
1833  **/
1834 GdkDisplay *
1835 gdk_x11_lookup_xdisplay (Display *xdisplay)
1836 {
1837   GSList *list, *l;
1838   GdkDisplay *display;
1839
1840   display = NULL;
1841
1842   list = gdk_display_manager_list_displays (gdk_display_manager_get ());
1843
1844   for (l = list; l; l = l->next)
1845     {
1846       if (GDK_DISPLAY_XDISPLAY (l->data) == xdisplay)
1847         {
1848           display = l->data;
1849           break;
1850         }
1851     }
1852
1853   g_slist_free (list);
1854
1855   return display;
1856 }
1857
1858 /**
1859  * _gdk_x11_display_screen_for_xrootwin:
1860  * @display: a #GdkDisplay
1861  * @xrootwin: window ID for one of of the screen's of the display.
1862  * 
1863  * Given the root window ID of one of the screen's of a #GdkDisplay,
1864  * finds the screen.
1865  * 
1866  * Return value: (transfer none): the #GdkScreen corresponding to
1867  *     @xrootwin, or %NULL.
1868  **/
1869 GdkScreen *
1870 _gdk_x11_display_screen_for_xrootwin (GdkDisplay *display,
1871                                       Window      xrootwin)
1872 {
1873   gint i;
1874
1875   for (i = 0; i < ScreenCount (GDK_X11_DISPLAY (display)->xdisplay); i++)
1876     {
1877       GdkScreen *screen = gdk_display_get_screen (display, i);
1878       if (GDK_SCREEN_XROOTWIN (screen) == xrootwin)
1879         return screen;
1880     }
1881
1882   return NULL;
1883 }
1884
1885 /**
1886  * gdk_x11_display_get_xdisplay:
1887  * @display: (type GdkX11Display): a #GdkDisplay
1888  *
1889  * Returns the X display of a #GdkDisplay.
1890  *
1891  * Returns: (transfer none): an X display
1892  *
1893  * Since: 2.2
1894  */
1895 Display *
1896 gdk_x11_display_get_xdisplay (GdkDisplay *display)
1897 {
1898   g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1899   return GDK_X11_DISPLAY (display)->xdisplay;
1900 }
1901
1902 void
1903 _gdk_x11_display_make_default (GdkDisplay *display)
1904 {
1905   GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
1906   const gchar *startup_id;
1907
1908   g_free (display_x11->startup_notification_id);
1909   display_x11->startup_notification_id = NULL;
1910
1911   startup_id = g_getenv ("DESKTOP_STARTUP_ID");
1912   if (startup_id && *startup_id != '\0')
1913     {
1914       if (!g_utf8_validate (startup_id, -1, NULL))
1915         g_warning ("DESKTOP_STARTUP_ID contains invalid UTF-8");
1916       else
1917         gdk_x11_display_set_startup_notification_id (display, startup_id);
1918
1919       /* Clear the environment variable so it won't be inherited by
1920        * child processes and confuse things.
1921        */
1922       g_unsetenv ("DESKTOP_STARTUP_ID");
1923     }
1924 }
1925
1926 static void
1927 broadcast_xmessage (GdkDisplay *display,
1928                     const char *message_type,
1929                     const char *message_type_begin,
1930                     const char *message)
1931 {
1932   Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
1933   GdkScreen *screen = gdk_display_get_default_screen (display);
1934   GdkWindow *root_window = gdk_screen_get_root_window (screen);
1935   Window xroot_window = GDK_WINDOW_XID (root_window);
1936   
1937   Atom type_atom;
1938   Atom type_atom_begin;
1939   Window xwindow;
1940
1941   if (!G_LIKELY (GDK_X11_DISPLAY (display)->trusted_client))
1942     return;
1943
1944   {
1945     XSetWindowAttributes attrs;
1946
1947     attrs.override_redirect = True;
1948     attrs.event_mask = PropertyChangeMask | StructureNotifyMask;
1949
1950     xwindow =
1951       XCreateWindow (xdisplay,
1952                      xroot_window,
1953                      -100, -100, 1, 1,
1954                      0,
1955                      CopyFromParent,
1956                      CopyFromParent,
1957                      (Visual *)CopyFromParent,
1958                      CWOverrideRedirect | CWEventMask,
1959                      &attrs);
1960   }
1961
1962   type_atom = gdk_x11_get_xatom_by_name_for_display (display,
1963                                                      message_type);
1964   type_atom_begin = gdk_x11_get_xatom_by_name_for_display (display,
1965                                                            message_type_begin);
1966   
1967   {
1968     XClientMessageEvent xclient;
1969     const char *src;
1970     const char *src_end;
1971     char *dest;
1972     char *dest_end;
1973     
1974                 memset(&xclient, 0, sizeof (xclient));
1975     xclient.type = ClientMessage;
1976     xclient.message_type = type_atom_begin;
1977     xclient.display =xdisplay;
1978     xclient.window = xwindow;
1979     xclient.format = 8;
1980
1981     src = message;
1982     src_end = message + strlen (message) + 1; /* +1 to include nul byte */
1983     
1984     while (src != src_end)
1985       {
1986         dest = &xclient.data.b[0];
1987         dest_end = dest + 20;        
1988         
1989         while (dest != dest_end &&
1990                src != src_end)
1991           {
1992             *dest = *src;
1993             ++dest;
1994             ++src;
1995           }
1996
1997         while (dest != dest_end)
1998           {
1999             *dest = 0;
2000             ++dest;
2001           }
2002         
2003         XSendEvent (xdisplay,
2004                     xroot_window,
2005                     False,
2006                     PropertyChangeMask,
2007                     (XEvent *)&xclient);
2008
2009         xclient.message_type = type_atom;
2010       }
2011   }
2012
2013   XDestroyWindow (xdisplay, xwindow);
2014   XFlush (xdisplay);
2015 }
2016
2017 /**
2018  * gdk_x11_display_broadcast_startup_message:
2019  * @display: (type GdkX11Display): a #GdkDisplay
2020  * @message_type: startup notification message type ("new", "change",
2021  * or "remove")
2022  * @...: a list of key/value pairs (as strings), terminated by a
2023  * %NULL key. (A %NULL value for a key will cause that key to be
2024  * skipped in the output.)
2025  *
2026  * Sends a startup notification message of type @message_type to
2027  * @display. 
2028  *
2029  * This is a convenience function for use by code that implements the
2030  * freedesktop startup notification specification. Applications should
2031  * not normally need to call it directly. See the <ulink
2032  * url="http://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt">Startup
2033  * Notification Protocol specification</ulink> for
2034  * definitions of the message types and keys that can be used.
2035  *
2036  * Since: 2.12
2037  **/
2038 void
2039 gdk_x11_display_broadcast_startup_message (GdkDisplay *display,
2040                                            const char *message_type,
2041                                            ...)
2042 {
2043   GString *message;
2044   va_list ap;
2045   const char *key, *value, *p;
2046
2047   message = g_string_new (message_type);
2048   g_string_append_c (message, ':');
2049
2050   va_start (ap, message_type);
2051   while ((key = va_arg (ap, const char *)))
2052     {
2053       value = va_arg (ap, const char *);
2054       if (!value)
2055         continue;
2056
2057       g_string_append_printf (message, " %s=\"", key);
2058       for (p = value; *p; p++)
2059         {
2060           switch (*p)
2061             {
2062             case ' ':
2063             case '"':
2064             case '\\':
2065               g_string_append_c (message, '\\');
2066               break;
2067             }
2068
2069           g_string_append_c (message, *p);
2070         }
2071       g_string_append_c (message, '\"');
2072     }
2073   va_end (ap);
2074
2075   broadcast_xmessage (display,
2076                       "_NET_STARTUP_INFO",
2077                       "_NET_STARTUP_INFO_BEGIN",
2078                       message->str);
2079
2080   g_string_free (message, TRUE);
2081 }
2082
2083 static void
2084 gdk_x11_display_notify_startup_complete (GdkDisplay  *display,
2085                                          const gchar *startup_id)
2086 {
2087   if (startup_id == NULL)
2088     {
2089       startup_id = GDK_X11_DISPLAY (display)->startup_notification_id;
2090       if (startup_id == NULL)
2091         return;
2092     }
2093
2094   gdk_x11_display_broadcast_startup_message (display, "remove",
2095                                              "ID", startup_id,
2096                                              NULL);
2097 }
2098
2099 static gboolean
2100 gdk_x11_display_supports_selection_notification (GdkDisplay *display)
2101 {
2102   GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
2103
2104   return display_x11->have_xfixes;
2105 }
2106
2107 static gboolean
2108 gdk_x11_display_request_selection_notification (GdkDisplay *display,
2109                                                 GdkAtom     selection)
2110
2111 {
2112 #ifdef HAVE_XFIXES
2113   GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
2114   Atom atom;
2115
2116   if (display_x11->have_xfixes)
2117     {
2118       atom = gdk_x11_atom_to_xatom_for_display (display, 
2119                                                 selection);
2120       XFixesSelectSelectionInput (display_x11->xdisplay, 
2121                                   display_x11->leader_window,
2122                                   atom,
2123                                   XFixesSetSelectionOwnerNotifyMask |
2124                                   XFixesSelectionWindowDestroyNotifyMask |
2125                                   XFixesSelectionClientCloseNotifyMask);
2126       return TRUE;
2127     }
2128   else
2129 #endif
2130     return FALSE;
2131 }
2132
2133 static gboolean
2134 gdk_x11_display_supports_clipboard_persistence (GdkDisplay *display)
2135 {
2136   Atom clipboard_manager;
2137
2138   /* It might make sense to cache this */
2139   clipboard_manager = gdk_x11_get_xatom_by_name_for_display (display, "CLIPBOARD_MANAGER");
2140   return XGetSelectionOwner (GDK_X11_DISPLAY (display)->xdisplay, clipboard_manager) != None;
2141 }
2142
2143 static void
2144 gdk_x11_display_store_clipboard (GdkDisplay    *display,
2145                                  GdkWindow     *clipboard_window,
2146                                  guint32        time_,
2147                                  const GdkAtom *targets,
2148                                  gint           n_targets)
2149 {
2150   GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
2151   Atom clipboard_manager, save_targets;
2152
2153   g_return_if_fail (GDK_WINDOW_IS_X11 (clipboard_window));
2154
2155   clipboard_manager = gdk_x11_get_xatom_by_name_for_display (display, "CLIPBOARD_MANAGER");
2156   save_targets = gdk_x11_get_xatom_by_name_for_display (display, "SAVE_TARGETS");
2157
2158   gdk_x11_display_error_trap_push (display);
2159
2160   if (XGetSelectionOwner (display_x11->xdisplay, clipboard_manager) != None)
2161     {
2162       Atom property_name = None;
2163       Atom *xatoms;
2164       int i;
2165
2166       if (n_targets > 0)
2167         {
2168           property_name = gdk_x11_get_xatom_by_name_for_display (display, "GDK_SELECTION");
2169
2170           xatoms = g_new (Atom, n_targets);
2171           for (i = 0; i < n_targets; i++)
2172             xatoms[i] = gdk_x11_atom_to_xatom_for_display (display, targets[i]);
2173
2174           XChangeProperty (display_x11->xdisplay, GDK_WINDOW_XID (clipboard_window),
2175                            property_name, XA_ATOM,
2176                            32, PropModeReplace, (guchar *)xatoms, n_targets);
2177           g_free (xatoms);
2178
2179         }
2180
2181       XConvertSelection (display_x11->xdisplay,
2182                          clipboard_manager, save_targets, property_name,
2183                          GDK_WINDOW_XID (clipboard_window), time_);
2184
2185     }
2186   gdk_x11_display_error_trap_pop_ignored (display);
2187
2188 }
2189
2190 /**
2191  * gdk_x11_display_get_user_time:
2192  * @display: (type GdkX11Display): a #GdkDisplay
2193  *
2194  * Returns the timestamp of the last user interaction on 
2195  * @display. The timestamp is taken from events caused
2196  * by user interaction such as key presses or pointer 
2197  * movements. See gdk_x11_window_set_user_time().
2198  *
2199  * Returns: the timestamp of the last user interaction 
2200  *
2201  * Since: 2.8
2202  */
2203 guint32
2204 gdk_x11_display_get_user_time (GdkDisplay *display)
2205 {
2206   return GDK_X11_DISPLAY (display)->user_time;
2207 }
2208
2209 static gboolean
2210 gdk_x11_display_supports_shapes (GdkDisplay *display)
2211 {
2212   return GDK_X11_DISPLAY (display)->have_shapes;
2213 }
2214
2215 static gboolean
2216 gdk_x11_display_supports_input_shapes (GdkDisplay *display)
2217 {
2218   return GDK_X11_DISPLAY (display)->have_input_shapes;
2219 }
2220
2221
2222 /**
2223  * gdk_x11_display_get_startup_notification_id:
2224  * @display: (type GdkX11Display): a #GdkDisplay
2225  *
2226  * Gets the startup notification ID for a display.
2227  * 
2228  * Returns: the startup notification ID for @display
2229  *
2230  * Since: 2.12
2231  */
2232 const gchar *
2233 gdk_x11_display_get_startup_notification_id (GdkDisplay *display)
2234 {
2235   return GDK_X11_DISPLAY (display)->startup_notification_id;
2236 }
2237
2238 /**
2239  * gdk_x11_display_set_startup_notification_id:
2240  * @display: (type GdkX11Display): a #GdkDisplay
2241  * @startup_id: the startup notification ID (must be valid utf8)
2242  *
2243  * Sets the startup notification ID for a display.
2244  *
2245  * This is usually taken from the value of the DESKTOP_STARTUP_ID
2246  * environment variable, but in some cases (such as the application not
2247  * being launched using exec()) it can come from other sources.
2248  *
2249  * If the ID contains the string "_TIME" then the portion following that
2250  * string is taken to be the X11 timestamp of the event that triggered
2251  * the application to be launched and the GDK current event time is set
2252  * accordingly.
2253  *
2254  * The startup ID is also what is used to signal that the startup is
2255  * complete (for example, when opening a window or when calling
2256  * gdk_notify_startup_complete()).
2257  *
2258  * Since: 3.0
2259  **/
2260 void
2261 gdk_x11_display_set_startup_notification_id (GdkDisplay  *display,
2262                                              const gchar *startup_id)
2263 {
2264   GdkX11Display *display_x11;
2265   gchar *time_str;
2266
2267   display_x11 = GDK_X11_DISPLAY (display);
2268
2269   g_free (display_x11->startup_notification_id);
2270   display_x11->startup_notification_id = g_strdup (startup_id);
2271
2272   /* Find the launch time from the startup_id, if it's there.  Newer spec
2273    * states that the startup_id is of the form <unique>_TIME<timestamp>
2274    */
2275   time_str = g_strrstr (startup_id, "_TIME");
2276   if (time_str != NULL)
2277     {
2278       gulong retval;
2279       gchar *end;
2280       errno = 0;
2281
2282       /* Skip past the "_TIME" part */
2283       time_str += 5;
2284
2285       retval = strtoul (time_str, &end, 0);
2286       if (end != time_str && errno == 0)
2287         display_x11->user_time = retval;
2288     }
2289
2290   /* Set the startup id on the leader window so it
2291    * applies to all windows we create on this display
2292    */
2293   XChangeProperty (display_x11->xdisplay,
2294                    display_x11->leader_window,
2295                    gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"),
2296                    gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2297                    PropModeReplace,
2298                    (guchar *)startup_id, strlen (startup_id));
2299 }
2300
2301 static gboolean
2302 gdk_x11_display_supports_composite (GdkDisplay *display)
2303 {
2304   GdkX11Display *x11_display = GDK_X11_DISPLAY (display);
2305
2306   return x11_display->have_xcomposite &&
2307          x11_display->have_xdamage &&
2308          x11_display->have_xfixes;
2309 }
2310
2311 static GList *
2312 gdk_x11_display_list_devices (GdkDisplay *display)
2313 {
2314   g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
2315
2316   return GDK_X11_DISPLAY (display)->input_devices;
2317 }
2318
2319 /**
2320  * gdk_x11_register_standard_event_type:
2321  * @display: a #GdkDisplay
2322  * @event_base: first event type code to register
2323  * @n_events: number of event type codes to register
2324  *
2325  * Registers interest in receiving extension events with type codes
2326  * between @event_base and <literal>event_base + n_events - 1</literal>.
2327  * The registered events must have the window field in the same place
2328  * as core X events (this is not the case for e.g. XKB extension events).
2329  *
2330  * If an event type is registered, events of this type will go through
2331  * global and window-specific filters (see gdk_window_add_filter()).
2332  * Unregistered events will only go through global filters.
2333  * GDK may register the events of some X extensions on its own.
2334  *
2335  * This function should only be needed in unusual circumstances, e.g.
2336  * when filtering XInput extension events on the root window.
2337  *
2338  * Since: 2.4
2339  **/
2340 void
2341 gdk_x11_register_standard_event_type (GdkDisplay *display,
2342                                       gint        event_base,
2343                                       gint        n_events)
2344 {
2345   GdkEventTypeX11 *event_type;
2346   GdkX11Display *display_x11;
2347
2348   display_x11 = GDK_X11_DISPLAY (display);
2349   event_type = g_new (GdkEventTypeX11, 1);
2350
2351   event_type->base = event_base;
2352   event_type->n_events = n_events;
2353
2354   display_x11->event_types = g_slist_prepend (display_x11->event_types, event_type);
2355 }
2356
2357 /* compare X sequence numbers handling wraparound */
2358 #define SEQUENCE_COMPARE(a,op,b) (((long) (a) - (long) (b)) op 0)
2359
2360 /* delivers an error event from the error handler in gdkmain-x11.c */
2361 void
2362 _gdk_x11_display_error_event (GdkDisplay  *display,
2363                               XErrorEvent *error)
2364 {
2365   GdkX11Display *display_x11;
2366   GSList *tmp_list;
2367   gboolean ignore;
2368
2369   display_x11 = GDK_X11_DISPLAY (display);
2370
2371   ignore = FALSE;
2372   for (tmp_list = display_x11->error_traps;
2373        tmp_list != NULL;
2374        tmp_list = tmp_list->next)
2375     {
2376       GdkErrorTrap *trap;
2377
2378       trap = tmp_list->data;
2379
2380       if (SEQUENCE_COMPARE (trap->start_sequence, <=, error->serial) &&
2381           (trap->end_sequence == 0 ||
2382            SEQUENCE_COMPARE (trap->end_sequence, >, error->serial)))
2383         {
2384           ignore = TRUE;
2385           trap->error_code = error->error_code;
2386           break; /* only innermost trap gets the error code */
2387         }
2388     }
2389
2390   if (!ignore)
2391     {
2392       gchar buf[64];
2393       gchar *msg;
2394
2395       XGetErrorText (display_x11->xdisplay, error->error_code, buf, 63);
2396
2397       msg =
2398         g_strdup_printf ("The program '%s' received an X Window System error.\n"
2399                          "This probably reflects a bug in the program.\n"
2400                          "The error was '%s'.\n"
2401                          "  (Details: serial %ld error_code %d request_code %d minor_code %d)\n"
2402                          "  (Note to programmers: normally, X errors are reported asynchronously;\n"
2403                          "   that is, you will receive the error a while after causing it.\n"
2404                          "   To debug your program, run it with the GDK_SYNCHRONIZE environment\n"
2405                          "   variable to change this behavior. You can then get a meaningful\n"
2406                          "   backtrace from your debugger if you break on the gdk_x_error() function.)",
2407                          g_get_prgname (),
2408                          buf,
2409                          error->serial,
2410                          error->error_code,
2411                          error->request_code,
2412                          error->minor_code);
2413
2414 #ifdef G_ENABLE_DEBUG
2415       g_error ("%s", msg);
2416 #else /* !G_ENABLE_DEBUG */
2417       g_warning ("%s\n", msg);
2418
2419       _exit (1);
2420 #endif /* G_ENABLE_DEBUG */
2421     }
2422 }
2423
2424 static void
2425 delete_outdated_error_traps (GdkX11Display *display_x11)
2426 {
2427   GSList *tmp_list;
2428   gulong processed_sequence;
2429
2430   processed_sequence = XLastKnownRequestProcessed (display_x11->xdisplay);
2431
2432   tmp_list = display_x11->error_traps;
2433   while (tmp_list != NULL)
2434     {
2435       GdkErrorTrap *trap = tmp_list->data;
2436
2437       if (trap->end_sequence != 0 &&
2438           SEQUENCE_COMPARE (trap->end_sequence, <=, processed_sequence))
2439         {
2440           GSList *free_me = tmp_list;
2441
2442           tmp_list = tmp_list->next;
2443           display_x11->error_traps =
2444             g_slist_delete_link (display_x11->error_traps, free_me);
2445           g_slice_free (GdkErrorTrap, trap);
2446         }
2447       else
2448         {
2449           tmp_list = tmp_list->next;
2450         }
2451     }
2452 }
2453
2454 /**
2455  * gdk_x11_display_error_trap_push:
2456  * @display: (type GdkX11Display): a #GdkDisplay
2457  *
2458  * Begins a range of X requests on @display for which X error events
2459  * will be ignored. Unignored errors (when no trap is pushed) will abort
2460  * the application. Use gdk_x11_display_error_trap_pop() or
2461  * gdk_x11_display_error_trap_pop_ignored()to lift a trap pushed
2462  * with this function.
2463  *
2464  * See also gdk_error_trap_push() to push a trap on all displays.
2465  *
2466  * Since: 3.0
2467  */
2468 void
2469 gdk_x11_display_error_trap_push (GdkDisplay *display)
2470 {
2471   GdkX11Display *display_x11;
2472   GdkErrorTrap *trap;
2473
2474   display_x11 = GDK_X11_DISPLAY (display);
2475
2476   delete_outdated_error_traps (display_x11);
2477
2478   /* set up the Xlib callback to tell us about errors */
2479   _gdk_x11_error_handler_push ();
2480
2481   trap = g_slice_new0 (GdkErrorTrap);
2482
2483   trap->start_sequence = XNextRequest (display_x11->xdisplay);
2484   trap->error_code = Success;
2485
2486   display_x11->error_traps =
2487     g_slist_prepend (display_x11->error_traps, trap);
2488 }
2489
2490 static gint
2491 gdk_x11_display_error_trap_pop_internal (GdkDisplay *display,
2492                                          gboolean    need_code)
2493 {
2494   GdkX11Display *display_x11;
2495   GdkErrorTrap *trap;
2496   GSList *tmp_list;
2497   int result;
2498
2499   display_x11 = GDK_X11_DISPLAY (display);
2500
2501   g_return_val_if_fail (display_x11->error_traps != NULL, Success);
2502
2503   /* Find the first trap that hasn't been popped already */
2504   trap = NULL; /* quiet gcc */
2505   for (tmp_list = display_x11->error_traps;
2506        tmp_list != NULL;
2507        tmp_list = tmp_list->next)
2508     {
2509       trap = tmp_list->data;
2510
2511       if (trap->end_sequence == 0)
2512         break;
2513     }
2514
2515   g_return_val_if_fail (trap != NULL, Success);
2516   g_assert (trap->end_sequence == 0);
2517
2518   /* May need to sync to fill in trap->error_code if we care about
2519    * getting an error code.
2520    */
2521   if (need_code)
2522     {
2523       gulong processed_sequence;
2524       gulong next_sequence;
2525
2526       next_sequence = XNextRequest (display_x11->xdisplay);
2527       processed_sequence = XLastKnownRequestProcessed (display_x11->xdisplay);
2528
2529       /* If our last request was already processed, there is no point
2530        * in syncing. i.e. if last request was a round trip (or even if
2531        * we got an event with the serial of a non-round-trip)
2532        */
2533       if ((next_sequence - 1) != processed_sequence)
2534         {
2535           XSync (display_x11->xdisplay, False);
2536         }
2537
2538       result = trap->error_code;
2539     }
2540   else
2541     {
2542       result = Success;
2543     }
2544
2545   /* record end of trap, giving us a range of
2546    * error sequences we'll ignore.
2547    */
2548   trap->end_sequence = XNextRequest (display_x11->xdisplay);
2549
2550   /* remove the Xlib callback */
2551   _gdk_x11_error_handler_pop ();
2552
2553   /* we may already be outdated */
2554   delete_outdated_error_traps (display_x11);
2555
2556   return result;
2557 }
2558
2559 /**
2560  * gdk_x11_display_error_trap_pop:
2561  * @display: (type GdkX11Display): the display
2562  *
2563  * Pops the error trap pushed by gdk_x11_display_error_trap_push().
2564  * Will XSync() if necessary and will always block until
2565  * the error is known to have occurred or not occurred,
2566  * so the error code can be returned.
2567  *
2568  * If you don't need to use the return value,
2569  * gdk_x11_display_error_trap_pop_ignored() would be more efficient.
2570  *
2571  * See gdk_error_trap_pop() for the all-displays-at-once
2572  * equivalent.
2573  *
2574  * Since: 3.0
2575  *
2576  * Return value: X error code or 0 on success
2577  */
2578 gint
2579 gdk_x11_display_error_trap_pop (GdkDisplay *display)
2580 {
2581   g_return_val_if_fail (GDK_IS_X11_DISPLAY (display), Success);
2582
2583   return gdk_x11_display_error_trap_pop_internal (display, TRUE);
2584 }
2585
2586 /**
2587  * gdk_x11_display_error_trap_pop_ignored:
2588  * @display: (type GdkX11Display): the display
2589  *
2590  * Pops the error trap pushed by gdk_x11_display_error_trap_push().
2591  * Does not block to see if an error occurred; merely records the
2592  * range of requests to ignore errors for, and ignores those errors
2593  * if they arrive asynchronously.
2594  *
2595  * See gdk_error_trap_pop_ignored() for the all-displays-at-once
2596  * equivalent.
2597  *
2598  * Since: 3.0
2599  */
2600 void
2601 gdk_x11_display_error_trap_pop_ignored (GdkDisplay *display)
2602 {
2603   g_return_if_fail (GDK_IS_X11_DISPLAY (display));
2604
2605   gdk_x11_display_error_trap_pop_internal (display, FALSE);
2606 }
2607
2608 /**
2609  * gdk_x11_set_sm_client_id:
2610  * @sm_client_id: the client id assigned by the session manager when the
2611  *    connection was opened, or %NULL to remove the property.
2612  *
2613  * Sets the <literal>SM_CLIENT_ID</literal> property on the application's leader window so that
2614  * the window manager can save the application's state using the X11R6 ICCCM
2615  * session management protocol.
2616  *
2617  * See the X Session Management Library documentation for more information on
2618  * session management and the Inter-Client Communication Conventions Manual
2619  *
2620  * Since: 2.24
2621  */
2622 void
2623 gdk_x11_set_sm_client_id (const gchar *sm_client_id)
2624 {
2625  GSList *displays, *l;
2626
2627   g_free (gdk_sm_client_id);
2628   gdk_sm_client_id = g_strdup (sm_client_id);
2629
2630   displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
2631   for (l = displays; l; l = l->next)
2632     set_sm_client_id (l->data, sm_client_id);
2633
2634   g_slist_free (displays);
2635 }
2636
2637 static void
2638 gdk_x11_display_event_data_copy (GdkDisplay    *display,
2639                                 const GdkEvent *src,
2640                                 GdkEvent       *dst)
2641 {
2642 }
2643
2644 static void
2645 gdk_x11_display_event_data_free (GdkDisplay *display,
2646                                  GdkEvent *event)
2647 {
2648 }
2649
2650 static gint
2651 pop_error_trap (GdkDisplay *display,
2652                 gboolean    ignored)
2653 {
2654   if (ignored)
2655     {
2656       gdk_x11_display_error_trap_pop_ignored (display);
2657       return Success;
2658     }
2659   else
2660     {
2661       return gdk_x11_display_error_trap_pop (display);
2662     }
2663 }
2664
2665 static GdkKeymap *
2666 gdk_x11_display_get_keymap (GdkDisplay *display)
2667 {
2668   GdkX11Display *display_x11;
2669   g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
2670   display_x11 = GDK_X11_DISPLAY (display);
2671
2672   if (!display_x11->keymap)
2673     display_x11->keymap = g_object_new (GDK_TYPE_X11_KEYMAP, NULL);
2674
2675   display_x11->keymap->display = display;
2676
2677   return display_x11->keymap;
2678 }
2679
2680 static void
2681 gdk_x11_display_class_init (GdkX11DisplayClass * class)
2682 {
2683   GObjectClass *object_class = G_OBJECT_CLASS (class);
2684   GdkDisplayClass *display_class = GDK_DISPLAY_CLASS (class);
2685
2686   object_class->dispose = gdk_x11_display_dispose;
2687   object_class->finalize = gdk_x11_display_finalize;
2688
2689   display_class->window_type = GDK_TYPE_X11_WINDOW;
2690
2691   display_class->get_name = gdk_x11_display_get_name;
2692   display_class->get_n_screens = gdk_x11_display_get_n_screens;
2693   display_class->get_screen = gdk_x11_display_get_screen;
2694   display_class->get_default_screen = gdk_x11_display_get_default_screen;
2695   display_class->beep = gdk_x11_display_beep;
2696   display_class->sync = gdk_x11_display_sync;
2697   display_class->flush = gdk_x11_display_flush;
2698   display_class->has_pending = gdk_x11_display_has_pending;
2699   display_class->queue_events = _gdk_x11_display_queue_events;
2700   display_class->get_default_group = gdk_x11_display_get_default_group;
2701   display_class->supports_selection_notification = gdk_x11_display_supports_selection_notification;
2702   display_class->request_selection_notification = gdk_x11_display_request_selection_notification;
2703   display_class->supports_clipboard_persistence = gdk_x11_display_supports_clipboard_persistence;
2704   display_class->store_clipboard = gdk_x11_display_store_clipboard;
2705   display_class->supports_shapes = gdk_x11_display_supports_shapes;
2706   display_class->supports_input_shapes = gdk_x11_display_supports_input_shapes;
2707   display_class->supports_composite = gdk_x11_display_supports_composite;
2708   display_class->list_devices = gdk_x11_display_list_devices;
2709   display_class->get_app_launch_context = _gdk_x11_display_get_app_launch_context;
2710   display_class->get_cursor_for_type = _gdk_x11_display_get_cursor_for_type;
2711   display_class->get_cursor_for_name = _gdk_x11_display_get_cursor_for_name;
2712   display_class->get_cursor_for_pixbuf = _gdk_x11_display_get_cursor_for_pixbuf;
2713   display_class->get_default_cursor_size = _gdk_x11_display_get_default_cursor_size;
2714   display_class->get_maximal_cursor_size = _gdk_x11_display_get_maximal_cursor_size;
2715   display_class->supports_cursor_alpha = _gdk_x11_display_supports_cursor_alpha;
2716   display_class->supports_cursor_color = _gdk_x11_display_supports_cursor_color;
2717
2718   display_class->before_process_all_updates = _gdk_x11_display_before_process_all_updates;
2719   display_class->after_process_all_updates = _gdk_x11_display_after_process_all_updates;
2720   display_class->get_next_serial = gdk_x11_display_get_next_serial;
2721   display_class->notify_startup_complete = gdk_x11_display_notify_startup_complete;
2722   display_class->event_data_copy = gdk_x11_display_event_data_copy;
2723   display_class->event_data_free = gdk_x11_display_event_data_free;
2724   display_class->create_window_impl = _gdk_x11_display_create_window_impl;
2725   display_class->get_keymap = gdk_x11_display_get_keymap;
2726   display_class->push_error_trap = gdk_x11_display_error_trap_push;
2727   display_class->pop_error_trap = pop_error_trap;
2728   display_class->get_selection_owner = _gdk_x11_display_get_selection_owner;
2729   display_class->set_selection_owner = _gdk_x11_display_set_selection_owner;
2730   display_class->send_selection_notify = _gdk_x11_display_send_selection_notify;
2731   display_class->get_selection_property = _gdk_x11_display_get_selection_property;
2732   display_class->convert_selection = _gdk_x11_display_convert_selection;
2733   display_class->text_property_to_utf8_list = _gdk_x11_display_text_property_to_utf8_list;
2734   display_class->utf8_to_string_target = _gdk_x11_display_utf8_to_string_target;
2735 }