1 /* GDK - The GIMP Drawing Kit
4 * Copyright 2001 Sun Microsystems Inc.
5 * Copyright (C) 2004 Nokia Corporation
7 * Erwann Chenede <erwann.chenede@sun.com>
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.
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.
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/>.
26 #include "gdkdisplay.h"
27 #include "gdkeventsource.h"
28 #include "gdkeventtranslator.h"
29 #include "gdkframeclockprivate.h"
30 #include "gdkinternals.h"
31 #include "gdkscreen.h"
32 #include "gdkinternals.h"
33 #include "gdkdeviceprivate.h"
34 #include "gdkkeysprivate.h"
35 #include "gdkdevicemanager.h"
36 #include "xsettings-client.h"
37 #include "gdkdisplay-x11.h"
38 #include "gdkprivate-x11.h"
39 #include "gdkscreen-x11.h"
42 #include <glib/gprintf.h>
48 #include <X11/Xatom.h>
51 #include <X11/XKBlib.h>
55 #include <X11/extensions/Xfixes.h>
58 #include <X11/extensions/shape.h>
60 #ifdef HAVE_XCOMPOSITE
61 #include <X11/extensions/Xcomposite.h>
65 #include <X11/extensions/Xdamage.h>
69 #include <X11/extensions/Xrandr.h>
72 typedef struct _GdkErrorTrap GdkErrorTrap;
76 /* Next sequence when trap was pushed, i.e. first sequence to
79 gulong start_sequence;
81 /* Next sequence when trap was popped, i.e. first sequence
82 * to not ignore. 0 if trap is still active.
86 /* Most recent error code within the sequence */
90 static void gdk_x11_display_dispose (GObject *object);
91 static void gdk_x11_display_finalize (GObject *object);
93 static void gdk_x11_display_event_translator_init (GdkEventTranslatorIface *iface);
95 static gboolean gdk_x11_display_translate_event (GdkEventTranslator *translator,
100 static void gdk_internal_connection_watch (Display *display,
104 XPointer *watch_data);
106 typedef struct _GdkEventTypeX11 GdkEventTypeX11;
108 struct _GdkEventTypeX11
114 /* Note that we never *directly* use WM_LOCALE_NAME, WM_PROTOCOLS,
115 * but including them here has the side-effect of getting them
116 * into the internal Xlib cache
118 static const char *const precache_atoms[] = {
128 "_NET_ACTIVE_WINDOW",
129 "_NET_CURRENT_DESKTOP",
130 "_NET_FRAME_EXTENTS",
140 "_NET_WM_STATE_ABOVE",
141 "_NET_WM_STATE_BELOW",
142 "_NET_WM_STATE_FULLSCREEN",
143 "_NET_WM_STATE_MODAL",
144 "_NET_WM_STATE_MAXIMIZED_VERT",
145 "_NET_WM_STATE_MAXIMIZED_HORZ",
146 "_NET_WM_STATE_SKIP_TASKBAR",
147 "_NET_WM_STATE_SKIP_PAGER",
148 "_NET_WM_STATE_STICKY",
149 "_NET_WM_SYNC_REQUEST",
150 "_NET_WM_SYNC_REQUEST_COUNTER",
151 "_NET_WM_WINDOW_TYPE",
152 "_NET_WM_WINDOW_TYPE_NORMAL",
154 "_NET_VIRTUAL_ROOTS",
156 "_NET_WM_STATE_FOCUSED"
159 static char *gdk_sm_client_id;
161 G_DEFINE_TYPE_WITH_CODE (GdkX11Display, gdk_x11_display, GDK_TYPE_DISPLAY,
162 G_IMPLEMENT_INTERFACE (GDK_TYPE_EVENT_TRANSLATOR,
163 gdk_x11_display_event_translator_init))
167 gdk_x11_display_init (GdkX11Display *display)
169 _gdk_x11_display_manager_add_display (gdk_display_manager_get (),
170 GDK_DISPLAY (display));
174 gdk_x11_display_event_translator_init (GdkEventTranslatorIface *iface)
176 iface->translate_event = gdk_x11_display_translate_event;
180 do_net_wm_state_changes (GdkWindow *window)
182 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
183 GdkWindowState old_state;
185 if (GDK_WINDOW_DESTROYED (window) ||
186 gdk_window_get_window_type (window) != GDK_WINDOW_TOPLEVEL)
189 old_state = gdk_window_get_state (window);
191 /* For found_sticky to remain TRUE, we have to also be on desktop
194 if (old_state & GDK_WINDOW_STATE_STICKY)
196 if (!(toplevel->have_sticky && toplevel->on_all_desktops))
197 gdk_synthesize_window_state (window,
198 GDK_WINDOW_STATE_STICKY,
203 if (toplevel->have_sticky && toplevel->on_all_desktops)
204 gdk_synthesize_window_state (window,
206 GDK_WINDOW_STATE_STICKY);
209 if (old_state & GDK_WINDOW_STATE_FULLSCREEN)
211 if (!toplevel->have_fullscreen)
212 gdk_synthesize_window_state (window,
213 GDK_WINDOW_STATE_FULLSCREEN,
218 if (toplevel->have_fullscreen)
219 gdk_synthesize_window_state (window,
221 GDK_WINDOW_STATE_FULLSCREEN);
224 /* Our "maximized" means both vertical and horizontal; if only one,
225 * we don't expose that via GDK
227 if (old_state & GDK_WINDOW_STATE_MAXIMIZED)
229 if (!(toplevel->have_maxvert && toplevel->have_maxhorz))
230 gdk_synthesize_window_state (window,
231 GDK_WINDOW_STATE_MAXIMIZED,
236 if (toplevel->have_maxvert && toplevel->have_maxhorz)
237 gdk_synthesize_window_state (window,
239 GDK_WINDOW_STATE_MAXIMIZED);
242 if (old_state & GDK_WINDOW_STATE_FOCUSED)
244 if (!toplevel->have_focused)
245 gdk_synthesize_window_state (window,
246 GDK_WINDOW_STATE_FOCUSED,
251 if (toplevel->have_focused)
252 gdk_synthesize_window_state (window,
254 GDK_WINDOW_STATE_FOCUSED);
257 if (old_state & GDK_WINDOW_STATE_ICONIFIED)
259 if (!toplevel->have_hidden)
260 gdk_synthesize_window_state (window,
261 GDK_WINDOW_STATE_ICONIFIED,
266 if (toplevel->have_hidden)
267 gdk_synthesize_window_state (window,
269 GDK_WINDOW_STATE_ICONIFIED);
274 gdk_check_wm_desktop_changed (GdkWindow *window)
276 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
277 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
287 gdk_x11_display_error_trap_push (display);
288 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
289 GDK_WINDOW_XID (window),
290 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
291 0, G_MAXLONG, False, XA_CARDINAL, &type,
293 &bytes_after, &data);
294 gdk_x11_display_error_trap_pop_ignored (display);
298 desktop = (gulong *)data;
299 toplevel->on_all_desktops = ((*desktop & 0xFFFFFFFF) == 0xFFFFFFFF);
303 toplevel->on_all_desktops = FALSE;
305 do_net_wm_state_changes (window);
309 gdk_check_wm_state_changed (GdkWindow *window)
311 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
312 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
313 GdkScreen *screen = GDK_WINDOW_SCREEN (window);
323 gboolean had_sticky = toplevel->have_sticky;
325 toplevel->have_sticky = FALSE;
326 toplevel->have_maxvert = FALSE;
327 toplevel->have_maxhorz = FALSE;
328 toplevel->have_fullscreen = FALSE;
329 toplevel->have_focused = FALSE;
330 toplevel->have_hidden = FALSE;
333 gdk_x11_display_error_trap_push (display);
334 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
335 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
336 0, G_MAXLONG, False, XA_ATOM, &type, &format, &nitems,
337 &bytes_after, &data);
338 gdk_x11_display_error_trap_pop_ignored (display);
342 Atom sticky_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_STICKY");
343 Atom maxvert_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_VERT");
344 Atom maxhorz_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_HORZ");
345 Atom fullscreen_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_FULLSCREEN");
346 Atom focused_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_FOCUSED");
347 Atom hidden_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_HIDDEN");
349 atoms = (Atom *)data;
354 if (atoms[i] == sticky_atom)
355 toplevel->have_sticky = TRUE;
356 else if (atoms[i] == maxvert_atom)
357 toplevel->have_maxvert = TRUE;
358 else if (atoms[i] == maxhorz_atom)
359 toplevel->have_maxhorz = TRUE;
360 else if (atoms[i] == fullscreen_atom)
361 toplevel->have_fullscreen = TRUE;
362 else if (atoms[i] == focused_atom)
363 toplevel->have_focused = TRUE;
364 else if (atoms[i] == hidden_atom)
365 toplevel->have_hidden = TRUE;
373 if (!gdk_x11_screen_supports_net_wm_hint (screen,
374 gdk_atom_intern_static_string ("_NET_WM_STATE_FOCUSED")))
375 toplevel->have_focused = TRUE;
377 /* When have_sticky is turned on, we have to check the DESKTOP property
380 if (toplevel->have_sticky && !had_sticky)
381 gdk_check_wm_desktop_changed (window);
383 do_net_wm_state_changes (window);
387 get_event_xwindow (XEvent *xevent)
391 switch (xevent->type)
394 xwindow = xevent->xdestroywindow.window;
397 xwindow = xevent->xunmap.window;
400 xwindow = xevent->xmap.window;
402 case ConfigureNotify:
403 xwindow = xevent->xconfigure.window;
406 xwindow = xevent->xreparent.window;
409 xwindow = xevent->xgravity.window;
411 case CirculateNotify:
412 xwindow = xevent->xcirculate.window;
415 xwindow = xevent->xany.window;
422 gdk_x11_display_translate_event (GdkEventTranslator *translator,
429 gboolean is_substructure;
430 GdkWindowImplX11 *window_impl = NULL;
431 GdkScreen *screen = NULL;
432 GdkX11Screen *x11_screen = NULL;
433 GdkToplevelX11 *toplevel = NULL;
434 GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
437 /* Find the GdkWindow that this event relates to. If that's
438 * not the same as the window that the event was sent to,
439 * we are getting an event from SubstructureNotifyMask.
440 * We ignore such events for internal operation, but we
441 * need to report them to the application because of
442 * GDK_SUBSTRUCTURE_MASK (which should be removed at next
443 * opportunity.) The most likely reason for getting these
444 * events is when we are used in the Metacity or Mutter
447 xwindow = get_event_xwindow (xevent);
448 is_substructure = xwindow != xevent->xany.window;
450 window = gdk_x11_window_lookup_for_display (display, xwindow);
453 /* We may receive events such as NoExpose/GraphicsExpose
454 * and ShmCompletion for pixmaps
456 if (!GDK_IS_WINDOW (window))
459 screen = GDK_WINDOW_SCREEN (window);
460 x11_screen = GDK_X11_SCREEN (screen);
461 toplevel = _gdk_x11_window_get_toplevel (window);
462 window_impl = GDK_WINDOW_IMPL_X11 (window->impl);
464 g_object_ref (window);
467 event->any.window = window;
468 event->any.send_event = xevent->xany.send_event ? TRUE : FALSE;
470 if (window && GDK_WINDOW_DESTROYED (window))
472 if (xevent->type != DestroyNotify)
479 if (xevent->type == DestroyNotify && !is_substructure)
483 n = gdk_display_get_n_screens (display);
484 for (i = 0; i < n; i++)
486 screen = gdk_display_get_screen (display, i);
487 x11_screen = GDK_X11_SCREEN (screen);
489 if (x11_screen->wmspec_check_window == xevent->xdestroywindow.window)
491 x11_screen->wmspec_check_window = None;
492 x11_screen->last_wmspec_check_time = 0;
493 g_free (x11_screen->window_manager_name);
494 x11_screen->window_manager_name = g_strdup ("unknown");
496 /* careful, reentrancy */
497 _gdk_x11_screen_window_manager_changed (screen);
505 /* We do a "manual" conversion of the XEvent to a
506 * GdkEvent. The structures are mostly the same so
507 * the conversion is fairly straightforward. We also
508 * optionally print debugging info regarding events
514 switch (xevent->type)
518 g_message ("keymap notify"));
520 /* Not currently handled */
526 g_message ("expose:\t\twindow: %ld %d x,y: %d %d w,h: %d %d%s",
527 xevent->xexpose.window, xevent->xexpose.count,
528 xevent->xexpose.x, xevent->xexpose.y,
529 xevent->xexpose.width, xevent->xexpose.height,
530 event->any.send_event ? " (send)" : ""));
539 GdkRectangle expose_rect;
541 expose_rect.x = xevent->xexpose.x;
542 expose_rect.y = xevent->xexpose.y;
543 expose_rect.width = xevent->xexpose.width;
544 expose_rect.height = xevent->xexpose.height;
546 _gdk_x11_window_process_expose (window, xevent->xexpose.serial, &expose_rect);
554 GdkRectangle expose_rect;
557 g_message ("graphics expose:\tdrawable: %ld",
558 xevent->xgraphicsexpose.drawable));
566 expose_rect.x = xevent->xgraphicsexpose.x;
567 expose_rect.y = xevent->xgraphicsexpose.y;
568 expose_rect.width = xevent->xgraphicsexpose.width;
569 expose_rect.height = xevent->xgraphicsexpose.height;
571 _gdk_x11_window_process_expose (window, xevent->xgraphicsexpose.serial, &expose_rect);
576 case VisibilityNotify:
577 #ifdef G_ENABLE_DEBUG
578 if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
579 switch (xevent->xvisibility.state)
581 case VisibilityFullyObscured:
582 g_message ("visibility notify:\twindow: %ld none",
583 xevent->xvisibility.window);
585 case VisibilityPartiallyObscured:
586 g_message ("visibility notify:\twindow: %ld partial",
587 xevent->xvisibility.window);
589 case VisibilityUnobscured:
590 g_message ("visibility notify:\twindow: %ld full",
591 xevent->xvisibility.window);
594 #endif /* G_ENABLE_DEBUG */
602 event->visibility.type = GDK_VISIBILITY_NOTIFY;
603 event->visibility.window = window;
605 switch (xevent->xvisibility.state)
607 case VisibilityFullyObscured:
608 event->visibility.state = GDK_VISIBILITY_FULLY_OBSCURED;
611 case VisibilityPartiallyObscured:
612 event->visibility.state = GDK_VISIBILITY_PARTIAL;
615 case VisibilityUnobscured:
616 event->visibility.state = GDK_VISIBILITY_UNOBSCURED;
624 g_message ("create notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d parent: %ld ovr: %d",
625 xevent->xcreatewindow.window,
626 xevent->xcreatewindow.x,
627 xevent->xcreatewindow.y,
628 xevent->xcreatewindow.width,
629 xevent->xcreatewindow.height,
630 xevent->xcreatewindow.border_width,
631 xevent->xcreatewindow.parent,
632 xevent->xcreatewindow.override_redirect));
633 /* not really handled */
638 g_message ("destroy notify:\twindow: %ld",
639 xevent->xdestroywindow.window));
641 if (!is_substructure)
643 event->any.type = GDK_DESTROY;
644 event->any.window = window;
646 return_val = window && !GDK_WINDOW_DESTROYED (window);
648 if (window && GDK_WINDOW_XID (window) != x11_screen->xroot_window)
649 gdk_window_destroy_notify (window);
658 g_message ("unmap notify:\t\twindow: %ld",
659 xevent->xmap.window));
661 event->any.type = GDK_UNMAP;
662 event->any.window = window;
664 if (window && !is_substructure)
666 /* If the WM supports the _NET_WM_STATE_HIDDEN hint, we do not want to
667 * interpret UnmapNotify events as implying iconic state.
668 * http://bugzilla.gnome.org/show_bug.cgi?id=590726.
671 !gdk_x11_screen_supports_net_wm_hint (screen,
672 gdk_atom_intern_static_string ("_NET_WM_STATE_HIDDEN")))
674 /* If we are shown (not withdrawn) and get an unmap, it means we were
675 * iconified in the X sense. If we are withdrawn, and get an unmap, it
676 * means we hid the window ourselves, so we will have already flipped
677 * the iconified bit off.
679 if (GDK_WINDOW_IS_MAPPED (window))
680 gdk_synthesize_window_state (window,
682 GDK_WINDOW_STATE_ICONIFIED);
685 if (window_impl->toplevel &&
686 window_impl->toplevel->frame_pending)
688 window_impl->toplevel->frame_pending = FALSE;
689 _gdk_frame_clock_thaw (gdk_window_get_frame_clock (event->any.window));
693 gdk_window_freeze_toplevel_updates_libgtk_only (window);
695 _gdk_x11_window_grab_check_unmap (window, xevent->xany.serial);
702 g_message ("map notify:\t\twindow: %ld",
703 xevent->xmap.window));
705 event->any.type = GDK_MAP;
706 event->any.window = window;
708 if (window && !is_substructure)
710 /* Unset iconified if it was set */
711 if (window->state & GDK_WINDOW_STATE_ICONIFIED)
712 gdk_synthesize_window_state (window,
713 GDK_WINDOW_STATE_ICONIFIED,
717 gdk_window_thaw_toplevel_updates_libgtk_only (window);
724 g_message ("reparent notify:\twindow: %ld x,y: %d %d parent: %ld ovr: %d",
725 xevent->xreparent.window,
728 xevent->xreparent.parent,
729 xevent->xreparent.override_redirect));
731 /* Not currently handled */
735 case ConfigureNotify:
737 g_message ("configure notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d above: %ld ovr: %d%s",
738 xevent->xconfigure.window,
739 xevent->xconfigure.x,
740 xevent->xconfigure.y,
741 xevent->xconfigure.width,
742 xevent->xconfigure.height,
743 xevent->xconfigure.border_width,
744 xevent->xconfigure.above,
745 xevent->xconfigure.override_redirect,
748 : window->window_type == GDK_WINDOW_CHILD
749 ? " (discarding child)"
750 : xevent->xconfigure.event != xevent->xconfigure.window
751 ? " (discarding substructure)"
753 if (window && GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
755 window->width = xevent->xconfigure.width;
756 window->height = xevent->xconfigure.height;
758 _gdk_window_update_size (window);
759 _gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
760 _gdk_x11_screen_size_changed (screen, xevent);
764 if (!is_substructure && toplevel && display_x11->use_sync && toplevel->pending_counter_value != 0)
766 toplevel->configure_counter_value = toplevel->pending_counter_value;
767 toplevel->configure_counter_value_is_extended = toplevel->pending_counter_value_is_extended;
768 toplevel->pending_counter_value = 0;
773 xevent->xconfigure.event != xevent->xconfigure.window ||
774 GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD ||
775 GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
779 event->configure.type = GDK_CONFIGURE;
780 event->configure.window = window;
781 event->configure.width = xevent->xconfigure.width;
782 event->configure.height = xevent->xconfigure.height;
784 if (!xevent->xconfigure.send_event &&
785 !xevent->xconfigure.override_redirect &&
786 !GDK_WINDOW_DESTROYED (window))
790 Window child_window = 0;
792 gdk_x11_display_error_trap_push (display);
793 if (XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
794 GDK_WINDOW_XID (window),
795 x11_screen->xroot_window,
800 event->configure.x = tx;
801 event->configure.y = ty;
803 gdk_x11_display_error_trap_pop_ignored (display);
807 event->configure.x = xevent->xconfigure.x;
808 event->configure.y = xevent->xconfigure.y;
810 if (!is_substructure)
812 window->x = event->configure.x;
813 window->y = event->configure.y;
814 window->width = xevent->xconfigure.width;
815 window->height = xevent->xconfigure.height;
817 _gdk_window_update_size (window);
818 _gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
820 if (window->resize_count >= 1)
822 window->resize_count -= 1;
824 if (window->resize_count == 0)
825 _gdk_x11_moveresize_configure_done (display, window);
833 g_message ("property notify:\twindow: %ld, atom(%ld): %s%s%s",
834 xevent->xproperty.window,
835 xevent->xproperty.atom,
837 gdk_x11_get_xatom_name_for_display (display, xevent->xproperty.atom),
846 /* We compare with the serial of the last time we mapped the
847 * window to avoid refetching properties that we set ourselves
850 xevent->xproperty.serial >= toplevel->map_serial)
852 if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"))
853 gdk_check_wm_state_changed (window);
855 if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"))
856 gdk_check_wm_desktop_changed (window);
859 if (window->event_mask & GDK_PROPERTY_CHANGE_MASK)
861 event->property.type = GDK_PROPERTY_NOTIFY;
862 event->property.window = window;
863 event->property.atom = gdk_x11_xatom_to_atom_for_display (display, xevent->xproperty.atom);
864 event->property.time = xevent->xproperty.time;
865 event->property.state = xevent->xproperty.state;
874 g_message ("selection clear:\twindow: %ld",
875 xevent->xproperty.window));
877 if (_gdk_x11_selection_filter_clear_event (&xevent->xselectionclear))
879 event->selection.type = GDK_SELECTION_CLEAR;
880 event->selection.window = window;
881 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionclear.selection);
882 event->selection.time = xevent->xselectionclear.time;
889 case SelectionRequest:
891 g_message ("selection request:\twindow: %ld",
892 xevent->xproperty.window));
894 event->selection.type = GDK_SELECTION_REQUEST;
895 event->selection.window = window;
896 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.selection);
897 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.target);
898 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.property);
899 if (xevent->xselectionrequest.requestor != None)
900 event->selection.requestor = gdk_x11_window_foreign_new_for_display (display,
901 xevent->xselectionrequest.requestor);
903 event->selection.requestor = NULL;
904 event->selection.time = xevent->xselectionrequest.time;
908 case SelectionNotify:
910 g_message ("selection notify:\twindow: %ld",
911 xevent->xproperty.window));
913 event->selection.type = GDK_SELECTION_NOTIFY;
914 event->selection.window = window;
915 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.selection);
916 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.target);
917 if (xevent->xselection.property == None)
918 event->selection.property = GDK_NONE;
920 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.property);
921 event->selection.time = xevent->xselection.time;
927 g_message ("colormap notify:\twindow: %ld",
928 xevent->xcolormap.window));
930 /* Not currently handled */
936 g_message ("client message:\twindow: %ld",
937 xevent->xclient.window));
939 /* Not currently handled */
945 g_message ("mapping notify"));
947 /* Let XLib know that there is a new keyboard mapping.
949 XRefreshKeyboardMapping (&xevent->xmapping);
950 _gdk_x11_keymap_keys_changed (display);
956 if (xevent->type - display_x11->xfixes_event_base == XFixesSelectionNotify)
958 XFixesSelectionNotifyEvent *selection_notify = (XFixesSelectionNotifyEvent *)xevent;
960 _gdk_x11_screen_process_owner_change (screen, xevent);
962 event->owner_change.type = GDK_OWNER_CHANGE;
963 event->owner_change.window = window;
964 if (selection_notify->owner != None)
965 event->owner_change.owner = gdk_x11_window_foreign_new_for_display (display,
966 selection_notify->owner);
968 event->owner_change.owner = NULL;
969 event->owner_change.reason = selection_notify->subtype;
970 event->owner_change.selection =
971 gdk_x11_xatom_to_atom_for_display (display,
972 selection_notify->selection);
973 event->owner_change.time = selection_notify->timestamp;
974 event->owner_change.selection_time = selection_notify->selection_timestamp;
981 if (xevent->type - display_x11->xrandr_event_base == RRScreenChangeNotify ||
982 xevent->type - display_x11->xrandr_event_base == RRNotify)
985 _gdk_x11_screen_size_changed (screen, xevent);
989 #if defined(HAVE_XCOMPOSITE) && defined (HAVE_XDAMAGE) && defined (HAVE_XFIXES)
990 if (display_x11->have_xdamage && window && window->composited &&
991 xevent->type == display_x11->xdamage_event_base + XDamageNotify &&
992 ((XDamageNotifyEvent *) xevent)->damage == window_impl->damage)
994 XDamageNotifyEvent *damage_event = (XDamageNotifyEvent *) xevent;
995 XserverRegion repair;
998 rect.x = window->x + damage_event->area.x;
999 rect.y = window->y + damage_event->area.y;
1000 rect.width = damage_event->area.width;
1001 rect.height = damage_event->area.height;
1003 repair = XFixesCreateRegion (display_x11->xdisplay,
1004 &damage_event->area, 1);
1005 XDamageSubtract (display_x11->xdisplay,
1006 window_impl->damage,
1008 XFixesDestroyRegion (display_x11->xdisplay, repair);
1010 if (window->parent != NULL)
1011 _gdk_x11_window_process_expose (window->parent,
1012 damage_event->serial, &rect);
1019 if (xevent->type == display_x11->xkb_event_type)
1021 XkbEvent *xkb_event = (XkbEvent *) xevent;
1023 switch (xkb_event->any.xkb_type)
1025 case XkbNewKeyboardNotify:
1027 _gdk_x11_keymap_keys_changed (display);
1032 case XkbStateNotify:
1033 _gdk_x11_keymap_state_changed (display, xevent);
1045 if (event->any.window)
1046 g_object_ref (event->any.window);
1050 /* Mark this event as having no resources to be freed */
1051 event->any.window = NULL;
1052 event->any.type = GDK_NOTHING;
1056 g_object_unref (window);
1061 static GdkFrameTimings *
1062 find_frame_timings (GdkFrameClock *clock,
1065 gint64 start_frame, end_frame, i;
1067 start_frame = gdk_frame_clock_get_history_start (clock);
1068 end_frame = gdk_frame_clock_get_frame_counter (clock);
1069 for (i = end_frame; i >= start_frame; i--)
1071 GdkFrameTimings *timings = gdk_frame_clock_get_timings (clock, i);
1073 if (timings->cookie == serial)
1081 _gdk_wm_protocols_filter (GdkXEvent *xev,
1085 XEvent *xevent = (XEvent *)xev;
1086 GdkWindow *win = event->any.window;
1087 GdkDisplay *display;
1090 if (!GDK_IS_X11_WINDOW (win) || GDK_WINDOW_DESTROYED (win))
1091 return GDK_FILTER_CONTINUE;
1093 if (xevent->type != ClientMessage)
1094 return GDK_FILTER_CONTINUE;
1096 display = GDK_WINDOW_DISPLAY (win);
1098 /* This isn't actually WM_PROTOCOLS because that wouldn't leave enough space
1099 * in the message for everything that gets stuffed in */
1100 if (xevent->xclient.message_type == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_FRAME_DRAWN"))
1102 GdkWindowImplX11 *window_impl;
1103 window_impl = GDK_WINDOW_IMPL_X11 (win->impl);
1104 if (window_impl->toplevel)
1106 guint32 d0 = xevent->xclient.data.l[0];
1107 guint32 d1 = xevent->xclient.data.l[1];
1108 guint32 d2 = xevent->xclient.data.l[2];
1109 guint32 d3 = xevent->xclient.data.l[3];
1111 guint64 serial = ((guint64)d1 << 32) | d0;
1112 gint64 frame_drawn_time = ((guint64)d3 << 32) | d2;
1113 gint64 refresh_interval, presentation_time;
1115 GdkFrameClock *clock = gdk_window_get_frame_clock (win);
1116 GdkFrameTimings *timings = find_frame_timings (clock, serial);
1119 timings->drawn_time = frame_drawn_time;
1121 if (window_impl->toplevel->frame_pending)
1123 window_impl->toplevel->frame_pending = FALSE;
1124 _gdk_frame_clock_thaw (clock);
1127 gdk_frame_clock_get_refresh_info (clock,
1130 &presentation_time);
1131 if (presentation_time != 0)
1132 window_impl->toplevel->throttled_presentation_time = presentation_time + refresh_interval;
1135 return GDK_FILTER_REMOVE;
1138 if (xevent->xclient.message_type == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_FRAME_TIMINGS"))
1140 GdkWindowImplX11 *window_impl;
1141 window_impl = GDK_WINDOW_IMPL_X11 (win->impl);
1142 if (window_impl->toplevel)
1144 guint32 d0 = xevent->xclient.data.l[0];
1145 guint32 d1 = xevent->xclient.data.l[1];
1146 guint32 d2 = xevent->xclient.data.l[2];
1147 guint32 d3 = xevent->xclient.data.l[3];
1149 guint64 serial = ((guint64)d1 << 32) | d0;
1151 GdkFrameClock *clock = gdk_window_get_frame_clock (win);
1152 GdkFrameTimings *timings = find_frame_timings (clock, serial);
1156 gint32 presentation_time_offset = (gint32)d2;
1157 gint32 refresh_interval = d3;
1159 if (timings->drawn_time && presentation_time_offset)
1160 timings->presentation_time = timings->drawn_time + presentation_time_offset;
1162 if (refresh_interval)
1163 timings->refresh_interval = refresh_interval;
1165 timings->complete = TRUE;
1166 #ifdef G_ENABLE_DEBUG
1167 if ((_gdk_debug_flags & GDK_DEBUG_FRAMES) != 0)
1168 _gdk_frame_clock_debug_print_timings (clock, timings);
1169 #endif /* G_ENABLE_DEBUG */
1174 if (xevent->xclient.message_type != gdk_x11_get_xatom_by_name_for_display (display, "WM_PROTOCOLS"))
1175 return GDK_FILTER_CONTINUE;
1177 atom = (Atom) xevent->xclient.data.l[0];
1179 if (atom == gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW"))
1181 /* The delete window request specifies a window
1182 * to delete. We don't actually destroy the
1183 * window because "it is only a request". (The
1184 * window might contain vital data that the
1185 * program does not want destroyed). Instead
1186 * the event is passed along to the program,
1187 * which should then destroy the window.
1190 g_message ("delete window:\t\twindow: %ld",
1191 xevent->xclient.window));
1193 event->any.type = GDK_DELETE;
1195 gdk_x11_window_set_user_time (win, xevent->xclient.data.l[1]);
1197 return GDK_FILTER_TRANSLATE;
1199 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS"))
1201 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (win);
1203 /* There is no way of knowing reliably whether we are viewable;
1204 * so trap errors asynchronously around the XSetInputFocus call
1206 if (toplevel && win->accept_focus)
1208 gdk_x11_display_error_trap_push (display);
1209 XSetInputFocus (GDK_DISPLAY_XDISPLAY (display),
1210 toplevel->focus_window,
1212 xevent->xclient.data.l[1]);
1213 gdk_x11_display_error_trap_pop_ignored (display);
1216 return GDK_FILTER_REMOVE;
1218 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING") &&
1219 !_gdk_x11_display_is_root_window (display,
1220 xevent->xclient.window))
1222 XClientMessageEvent xclient = xevent->xclient;
1224 xclient.window = GDK_WINDOW_XROOTWIN (win);
1225 XSendEvent (GDK_WINDOW_XDISPLAY (win),
1228 SubstructureRedirectMask | SubstructureNotifyMask, (XEvent *)&xclient);
1230 return GDK_FILTER_REMOVE;
1232 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_SYNC_REQUEST") &&
1233 GDK_X11_DISPLAY (display)->use_sync)
1235 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (win);
1239 toplevel->pending_counter_value = xevent->xclient.data.l[2] + ((gint64)xevent->xclient.data.l[3] << 32);
1240 toplevel->pending_counter_value_is_extended = xevent->xclient.data.l[4] != 0;
1243 return GDK_FILTER_REMOVE;
1246 return GDK_FILTER_CONTINUE;
1250 gdk_event_init (GdkDisplay *display)
1252 GdkX11Display *display_x11;
1253 GdkDeviceManager *device_manager;
1255 display_x11 = GDK_X11_DISPLAY (display);
1256 display_x11->event_source = gdk_x11_event_source_new (display);
1258 gdk_x11_event_source_add_translator ((GdkEventSource *) display_x11->event_source,
1259 GDK_EVENT_TRANSLATOR (display));
1261 device_manager = gdk_display_get_device_manager (display);
1262 gdk_x11_event_source_add_translator ((GdkEventSource *) display_x11->event_source,
1263 GDK_EVENT_TRANSLATOR (device_manager));
1267 gdk_x11_display_init_input (GdkDisplay *display)
1269 GdkX11Display *display_x11;
1270 GdkDeviceManager *device_manager;
1274 display_x11 = GDK_X11_DISPLAY (display);
1275 device_manager = gdk_display_get_device_manager (display);
1277 /* For backwards compatibility, just add
1278 * floating devices that are not keyboards.
1280 list = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING);
1282 for (l = list; l; l = l->next)
1286 if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
1289 display_x11->input_devices = g_list_prepend (display_x11->input_devices,
1290 g_object_ref (l->data));
1295 /* Now set "core" pointer to the first
1296 * master device that is a pointer.
1298 list = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
1300 for (l = list; l; l = l->next)
1304 if (gdk_device_get_source (device) != GDK_SOURCE_MOUSE)
1307 display->core_pointer = device;
1311 /* Add the core pointer to the devices list */
1312 display_x11->input_devices = g_list_prepend (display_x11->input_devices,
1313 g_object_ref (display->core_pointer));
1319 set_sm_client_id (GdkDisplay *display,
1320 const gchar *sm_client_id)
1322 GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
1324 if (gdk_display_is_closed (display))
1327 if (sm_client_id && strcmp (sm_client_id, ""))
1328 XChangeProperty (display_x11->xdisplay, display_x11->leader_window,
1329 gdk_x11_get_xatom_by_name_for_display (display, "SM_CLIENT_ID"),
1330 XA_STRING, 8, PropModeReplace, (guchar *)sm_client_id,
1331 strlen (sm_client_id));
1333 XDeleteProperty (display_x11->xdisplay, display_x11->leader_window,
1334 gdk_x11_get_xatom_by_name_for_display (display, "SM_CLIENT_ID"));
1338 _gdk_x11_display_open (const gchar *display_name)
1341 GdkDisplay *display;
1342 GdkX11Display *display_x11;
1347 XClassHint *class_hint;
1353 xdisplay = XOpenDisplay (display_name);
1357 display = g_object_new (GDK_TYPE_X11_DISPLAY, NULL);
1358 display_x11 = GDK_X11_DISPLAY (display);
1360 display_x11->xdisplay = xdisplay;
1362 /* Set up handlers for Xlib internal connections */
1363 XAddConnectionWatch (xdisplay, gdk_internal_connection_watch, NULL);
1365 _gdk_x11_precache_atoms (display, precache_atoms, G_N_ELEMENTS (precache_atoms));
1367 /* RandR must be initialized before we initialize the screens */
1368 display_x11->have_randr12 = FALSE;
1369 display_x11->have_randr13 = FALSE;
1371 if (XRRQueryExtension (display_x11->xdisplay,
1372 &display_x11->xrandr_event_base, &ignore))
1376 XRRQueryVersion (display_x11->xdisplay, &major, &minor);
1378 if ((major == 1 && minor >= 2) || major > 1) {
1379 display_x11->have_randr12 = TRUE;
1380 if (minor >= 3 || major > 1)
1381 display_x11->have_randr13 = TRUE;
1384 gdk_x11_register_standard_event_type (display, display_x11->xrandr_event_base, RRNumberEvents);
1388 /* initialize the display's screens */
1389 display_x11->screens = g_new (GdkScreen *, ScreenCount (display_x11->xdisplay));
1390 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1391 display_x11->screens[i] = _gdk_x11_screen_new (display, i);
1393 /* We need to initialize events after we have the screen
1394 * structures in places
1396 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1397 _gdk_x11_xsettings_init (GDK_X11_SCREEN (display_x11->screens[i]));
1399 /*set the default screen */
1400 display_x11->default_screen = display_x11->screens[DefaultScreen (display_x11->xdisplay)];
1402 display->device_manager = _gdk_x11_device_manager_new (display);
1404 gdk_event_init (display);
1406 attr.window_type = GDK_WINDOW_TOPLEVEL;
1407 attr.wclass = GDK_INPUT_OUTPUT;
1412 attr.event_mask = 0;
1414 display_x11->leader_gdk_window = gdk_window_new (GDK_X11_SCREEN (display_x11->default_screen)->root_window,
1415 &attr, GDK_WA_X | GDK_WA_Y);
1416 (_gdk_x11_window_get_toplevel (display_x11->leader_gdk_window))->is_leader = TRUE;
1418 display_x11->leader_window = GDK_WINDOW_XID (display_x11->leader_gdk_window);
1420 display_x11->leader_window_title_set = FALSE;
1423 if (XFixesQueryExtension (display_x11->xdisplay,
1424 &display_x11->xfixes_event_base,
1427 display_x11->have_xfixes = TRUE;
1429 gdk_x11_register_standard_event_type (display,
1430 display_x11->xfixes_event_base,
1431 XFixesNumberEvents);
1435 display_x11->have_xfixes = FALSE;
1437 #ifdef HAVE_XCOMPOSITE
1438 if (XCompositeQueryExtension (display_x11->xdisplay,
1443 XCompositeQueryVersion (display_x11->xdisplay, &major, &minor);
1445 /* Prior to Composite version 0.4, composited windows clipped their
1446 * parents, so you had to use IncludeInferiors to draw to the parent
1447 * This isn't useful for our purposes, so require 0.4
1449 display_x11->have_xcomposite = major > 0 || (major == 0 && minor >= 4);
1453 display_x11->have_xcomposite = FALSE;
1456 if (XDamageQueryExtension (display_x11->xdisplay,
1457 &display_x11->xdamage_event_base,
1460 display_x11->have_xdamage = TRUE;
1462 gdk_x11_register_standard_event_type (display,
1463 display_x11->xdamage_event_base,
1464 XDamageNumberEvents);
1468 display_x11->have_xdamage = FALSE;
1470 display_x11->have_shapes = FALSE;
1471 display_x11->have_input_shapes = FALSE;
1473 if (XShapeQueryExtension (GDK_DISPLAY_XDISPLAY (display), &display_x11->shape_event_base, &ignore))
1475 display_x11->have_shapes = TRUE;
1477 if (XShapeQueryVersion (GDK_DISPLAY_XDISPLAY (display), &maj, &min))
1478 display_x11->have_input_shapes = (maj == 1 && min >= 1);
1482 display_x11->trusted_client = TRUE;
1485 int rootx, rooty, winx, winy;
1488 gdk_x11_display_error_trap_push (display);
1489 XQueryPointer (display_x11->xdisplay,
1490 GDK_X11_SCREEN (display_x11->default_screen)->xroot_window,
1491 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
1492 if (G_UNLIKELY (gdk_x11_display_error_trap_pop (display) == BadWindow))
1494 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));
1495 display_x11->trusted_client = FALSE;
1499 if (g_getenv ("GDK_SYNCHRONIZE"))
1500 XSynchronize (display_x11->xdisplay, True);
1502 class_hint = XAllocClassHint();
1503 class_hint->res_name = (char *) g_get_prgname ();
1504 class_hint->res_class = (char *)gdk_get_program_class ();
1506 /* XmbSetWMProperties sets the RESOURCE_NAME environment variable
1507 * from argv[0], so we just synthesize an argument array here.
1510 argv[0] = (char *) g_get_prgname ();
1512 XmbSetWMProperties (display_x11->xdisplay,
1513 display_x11->leader_window,
1514 NULL, NULL, argv, argc, NULL, NULL,
1518 if (gdk_sm_client_id)
1519 set_sm_client_id (display, gdk_sm_client_id);
1522 XChangeProperty (display_x11->xdisplay,
1523 display_x11->leader_window,
1524 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PID"),
1525 XA_CARDINAL, 32, PropModeReplace, (guchar *) & pid, 1);
1527 /* We don't yet know a valid time. */
1528 display_x11->user_time = 0;
1532 gint xkb_major = XkbMajorVersion;
1533 gint xkb_minor = XkbMinorVersion;
1534 if (XkbLibraryVersion (&xkb_major, &xkb_minor))
1536 xkb_major = XkbMajorVersion;
1537 xkb_minor = XkbMinorVersion;
1539 if (XkbQueryExtension (display_x11->xdisplay,
1540 NULL, &display_x11->xkb_event_type, NULL,
1541 &xkb_major, &xkb_minor))
1543 Bool detectable_autorepeat_supported;
1545 display_x11->use_xkb = TRUE;
1547 XkbSelectEvents (display_x11->xdisplay,
1549 XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask,
1550 XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask);
1552 /* keep this in sync with _gdk_x11_keymap_state_changed() */
1553 XkbSelectEventDetails (display_x11->xdisplay,
1554 XkbUseCoreKbd, XkbStateNotify,
1555 XkbAllStateComponentsMask,
1556 XkbModifierStateMask|XkbGroupStateMask);
1558 XkbSetDetectableAutoRepeat (display_x11->xdisplay,
1560 &detectable_autorepeat_supported);
1562 GDK_NOTE (MISC, g_message ("Detectable autorepeat %s.",
1563 detectable_autorepeat_supported ?
1564 "supported" : "not supported"));
1566 display_x11->have_xkb_autorepeat = detectable_autorepeat_supported;
1572 display_x11->use_sync = FALSE;
1576 int error_base, event_base;
1578 if (XSyncQueryExtension (display_x11->xdisplay,
1579 &event_base, &error_base) &&
1580 XSyncInitialize (display_x11->xdisplay,
1582 display_x11->use_sync = TRUE;
1586 gdk_x11_display_init_input (display);
1588 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1589 _gdk_x11_screen_setup (display_x11->screens[i]);
1591 g_signal_emit_by_name (display, "opened");
1597 * XLib internal connection handling
1599 typedef struct _GdkInternalConnection GdkInternalConnection;
1601 struct _GdkInternalConnection
1609 process_internal_connection (GIOChannel *gioc,
1613 GdkInternalConnection *connection = (GdkInternalConnection *)data;
1615 gdk_threads_enter ();
1617 XProcessInternalConnection ((Display*)connection->display, connection->fd);
1619 gdk_threads_leave ();
1625 gdk_x11_display_get_next_serial (GdkDisplay *display)
1627 return NextRequest (GDK_DISPLAY_XDISPLAY (display));
1631 static GdkInternalConnection *
1632 gdk_add_connection_handler (Display *display,
1635 GIOChannel *io_channel;
1636 GdkInternalConnection *connection;
1638 connection = g_new (GdkInternalConnection, 1);
1640 connection->fd = fd;
1641 connection->display = display;
1643 io_channel = g_io_channel_unix_new (fd);
1645 connection->source = g_io_create_watch (io_channel, G_IO_IN);
1646 g_source_set_callback (connection->source,
1647 (GSourceFunc)process_internal_connection, connection, NULL);
1648 g_source_attach (connection->source, NULL);
1650 g_io_channel_unref (io_channel);
1656 gdk_remove_connection_handler (GdkInternalConnection *connection)
1658 g_source_destroy (connection->source);
1659 g_free (connection);
1663 gdk_internal_connection_watch (Display *display,
1667 XPointer *watch_data)
1670 *watch_data = (XPointer)gdk_add_connection_handler (display, fd);
1672 gdk_remove_connection_handler ((GdkInternalConnection *)*watch_data);
1675 static const gchar *
1676 gdk_x11_display_get_name (GdkDisplay *display)
1678 return (gchar *) DisplayString (GDK_X11_DISPLAY (display)->xdisplay);
1682 gdk_x11_display_get_n_screens (GdkDisplay *display)
1684 return ScreenCount (GDK_X11_DISPLAY (display)->xdisplay);
1688 gdk_x11_display_get_screen (GdkDisplay *display,
1691 g_return_val_if_fail (ScreenCount (GDK_X11_DISPLAY (display)->xdisplay) > screen_num, NULL);
1693 return GDK_X11_DISPLAY (display)->screens[screen_num];
1697 gdk_x11_display_get_default_screen (GdkDisplay *display)
1699 return GDK_X11_DISPLAY (display)->default_screen;
1703 _gdk_x11_display_is_root_window (GdkDisplay *display,
1704 Window xroot_window)
1706 GdkX11Display *display_x11;
1709 display_x11 = GDK_X11_DISPLAY (display);
1711 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1713 if (GDK_SCREEN_XROOTWIN (display_x11->screens[i]) == xroot_window)
1719 struct XPointerUngrabInfo {
1720 GdkDisplay *display;
1725 device_grab_update_callback (GdkDisplay *display,
1729 GdkPointerWindowInfo *pointer_info;
1730 GdkDevice *device = data;
1732 pointer_info = _gdk_display_get_pointer_info (display, device);
1733 _gdk_display_device_grab_update (display, device,
1734 pointer_info->last_slave, serial);
1737 #define XSERVER_TIME_IS_LATER(time1, time2) \
1738 ( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) || \
1739 (( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 )) \
1743 _gdk_x11_display_update_grab_info (GdkDisplay *display,
1747 if (status == GrabSuccess)
1748 _gdk_x11_roundtrip_async (display, device_grab_update_callback, device);
1752 _gdk_x11_display_update_grab_info_ungrab (GdkDisplay *display,
1757 GdkDeviceGrabInfo *grab;
1759 XFlush (GDK_DISPLAY_XDISPLAY (display));
1761 grab = _gdk_display_get_last_device_grab (display, device);
1763 (time == GDK_CURRENT_TIME ||
1764 grab->time == GDK_CURRENT_TIME ||
1765 !XSERVER_TIME_IS_LATER (grab->time, time)))
1767 grab->serial_end = serial;
1768 _gdk_x11_roundtrip_async (display, device_grab_update_callback, device);
1773 gdk_x11_display_beep (GdkDisplay *display)
1776 XkbBell (GDK_DISPLAY_XDISPLAY (display), None, 0, None);
1778 XBell (GDK_DISPLAY_XDISPLAY (display), 0);
1783 gdk_x11_display_sync (GdkDisplay *display)
1785 XSync (GDK_DISPLAY_XDISPLAY (display), False);
1789 gdk_x11_display_flush (GdkDisplay *display)
1791 if (!display->closed)
1792 XFlush (GDK_DISPLAY_XDISPLAY (display));
1796 gdk_x11_display_has_pending (GdkDisplay *display)
1798 return XPending (GDK_DISPLAY_XDISPLAY (display));
1802 gdk_x11_display_get_default_group (GdkDisplay *display)
1804 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1806 return GDK_X11_DISPLAY (display)->leader_gdk_window;
1810 * gdk_x11_display_grab:
1811 * @display: (type GdkX11Display): a #GdkDisplay
1813 * Call XGrabServer() on @display.
1814 * To ungrab the display again, use gdk_x11_display_ungrab().
1816 * gdk_x11_display_grab()/gdk_x11_display_ungrab() calls can be nested.
1821 gdk_x11_display_grab (GdkDisplay *display)
1823 GdkX11Display *display_x11;
1825 g_return_if_fail (GDK_IS_DISPLAY (display));
1827 display_x11 = GDK_X11_DISPLAY (display);
1829 if (display_x11->grab_count == 0)
1830 XGrabServer (display_x11->xdisplay);
1831 display_x11->grab_count++;
1835 * gdk_x11_display_ungrab:
1836 * @display: (type GdkX11Display): a #GdkDisplay
1838 * Ungrab @display after it has been grabbed with
1839 * gdk_x11_display_grab().
1844 gdk_x11_display_ungrab (GdkDisplay *display)
1846 GdkX11Display *display_x11;
1848 g_return_if_fail (GDK_IS_DISPLAY (display));
1850 display_x11 = GDK_X11_DISPLAY (display);;
1851 g_return_if_fail (display_x11->grab_count > 0);
1853 display_x11->grab_count--;
1854 if (display_x11->grab_count == 0)
1856 XUngrabServer (display_x11->xdisplay);
1857 XFlush (display_x11->xdisplay);
1862 gdk_x11_display_dispose (GObject *object)
1864 GdkDisplay *display = GDK_DISPLAY (object);
1865 GdkX11Display *display_x11 = GDK_X11_DISPLAY (object);
1868 _gdk_x11_display_manager_remove_display (gdk_display_manager_get (), display);
1870 g_list_foreach (display_x11->input_devices, (GFunc) g_object_run_dispose, NULL);
1872 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1873 _gdk_screen_close (display_x11->screens[i]);
1875 if (display_x11->event_source)
1877 g_source_destroy (display_x11->event_source);
1878 g_source_unref (display_x11->event_source);
1879 display_x11->event_source = NULL;
1882 G_OBJECT_CLASS (gdk_x11_display_parent_class)->dispose (object);
1886 gdk_x11_display_finalize (GObject *object)
1888 GdkX11Display *display_x11 = GDK_X11_DISPLAY (object);
1892 if (display_x11->keymap)
1893 g_object_unref (display_x11->keymap);
1895 /* Free motif Dnd */
1896 if (display_x11->motif_target_lists)
1898 for (i = 0; i < display_x11->motif_n_target_lists; i++)
1899 g_list_free (display_x11->motif_target_lists[i]);
1900 g_free (display_x11->motif_target_lists);
1903 _gdk_x11_cursor_display_finalize (GDK_DISPLAY (display_x11));
1905 /* Empty the event queue */
1906 _gdk_x11_display_free_translate_queue (GDK_DISPLAY (display_x11));
1908 /* Atom Hashtable */
1909 g_hash_table_destroy (display_x11->atom_from_virtual);
1910 g_hash_table_destroy (display_x11->atom_to_virtual);
1913 XDestroyWindow (display_x11->xdisplay, display_x11->leader_window);
1915 /* List of event window extraction functions */
1916 g_slist_foreach (display_x11->event_types, (GFunc)g_free, NULL);
1917 g_slist_free (display_x11->event_types);
1919 /* input GdkDevice list */
1920 g_list_free_full (display_x11->input_devices, g_object_unref);
1922 /* input GdkWindow list */
1923 g_list_free_full (display_x11->input_windows, g_free);
1925 /* Free all GdkScreens */
1926 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1927 g_object_unref (display_x11->screens[i]);
1928 g_free (display_x11->screens);
1930 g_free (display_x11->startup_notification_id);
1932 /* X ID hashtable */
1933 g_hash_table_destroy (display_x11->xid_ht);
1935 XCloseDisplay (display_x11->xdisplay);
1938 while (display_x11->error_traps != NULL)
1940 GdkErrorTrap *trap = display_x11->error_traps->data;
1942 display_x11->error_traps =
1943 g_slist_delete_link (display_x11->error_traps,
1944 display_x11->error_traps);
1946 if (trap->end_sequence == 0)
1947 g_warning ("Display finalized with an unpopped error trap");
1949 g_slice_free (GdkErrorTrap, trap);
1952 G_OBJECT_CLASS (gdk_x11_display_parent_class)->finalize (object);
1956 * gdk_x11_lookup_xdisplay:
1957 * @xdisplay: a pointer to an X Display
1959 * Find the #GdkDisplay corresponding to @display, if any exists.
1961 * Return value: (transfer none): the #GdkDisplay, if found, otherwise %NULL.
1966 gdk_x11_lookup_xdisplay (Display *xdisplay)
1969 GdkDisplay *display;
1973 list = gdk_display_manager_list_displays (gdk_display_manager_get ());
1975 for (l = list; l; l = l->next)
1977 if (GDK_DISPLAY_XDISPLAY (l->data) == xdisplay)
1984 g_slist_free (list);
1990 * _gdk_x11_display_screen_for_xrootwin:
1991 * @display: a #GdkDisplay
1992 * @xrootwin: window ID for one of of the screen's of the display.
1994 * Given the root window ID of one of the screen's of a #GdkDisplay,
1997 * Return value: (transfer none): the #GdkScreen corresponding to
1998 * @xrootwin, or %NULL.
2001 _gdk_x11_display_screen_for_xrootwin (GdkDisplay *display,
2006 for (i = 0; i < ScreenCount (GDK_X11_DISPLAY (display)->xdisplay); i++)
2008 GdkScreen *screen = gdk_display_get_screen (display, i);
2009 if (GDK_SCREEN_XROOTWIN (screen) == xrootwin)
2017 * gdk_x11_display_get_xdisplay:
2018 * @display: (type GdkX11Display): a #GdkDisplay
2020 * Returns the X display of a #GdkDisplay.
2022 * Returns: (transfer none): an X display
2027 gdk_x11_display_get_xdisplay (GdkDisplay *display)
2029 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
2030 return GDK_X11_DISPLAY (display)->xdisplay;
2034 _gdk_x11_display_make_default (GdkDisplay *display)
2036 GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
2037 const gchar *startup_id;
2039 g_free (display_x11->startup_notification_id);
2040 display_x11->startup_notification_id = NULL;
2042 startup_id = g_getenv ("DESKTOP_STARTUP_ID");
2043 if (startup_id && *startup_id != '\0')
2045 if (!g_utf8_validate (startup_id, -1, NULL))
2046 g_warning ("DESKTOP_STARTUP_ID contains invalid UTF-8");
2048 gdk_x11_display_set_startup_notification_id (display, startup_id);
2050 /* Clear the environment variable so it won't be inherited by
2051 * child processes and confuse things.
2053 g_unsetenv ("DESKTOP_STARTUP_ID");
2058 broadcast_xmessage (GdkDisplay *display,
2059 const char *message_type,
2060 const char *message_type_begin,
2061 const char *message)
2063 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
2064 GdkScreen *screen = gdk_display_get_default_screen (display);
2065 GdkWindow *root_window = gdk_screen_get_root_window (screen);
2066 Window xroot_window = GDK_WINDOW_XID (root_window);
2069 Atom type_atom_begin;
2072 if (!G_LIKELY (GDK_X11_DISPLAY (display)->trusted_client))
2076 XSetWindowAttributes attrs;
2078 attrs.override_redirect = True;
2079 attrs.event_mask = PropertyChangeMask | StructureNotifyMask;
2082 XCreateWindow (xdisplay,
2088 (Visual *)CopyFromParent,
2089 CWOverrideRedirect | CWEventMask,
2093 type_atom = gdk_x11_get_xatom_by_name_for_display (display,
2095 type_atom_begin = gdk_x11_get_xatom_by_name_for_display (display,
2096 message_type_begin);
2099 XClientMessageEvent xclient;
2101 const char *src_end;
2105 memset(&xclient, 0, sizeof (xclient));
2106 xclient.type = ClientMessage;
2107 xclient.message_type = type_atom_begin;
2108 xclient.display =xdisplay;
2109 xclient.window = xwindow;
2113 src_end = message + strlen (message) + 1; /* +1 to include nul byte */
2115 while (src != src_end)
2117 dest = &xclient.data.b[0];
2118 dest_end = dest + 20;
2120 while (dest != dest_end &&
2128 while (dest != dest_end)
2134 XSendEvent (xdisplay,
2138 (XEvent *)&xclient);
2140 xclient.message_type = type_atom;
2144 XDestroyWindow (xdisplay, xwindow);
2149 * gdk_x11_display_broadcast_startup_message:
2150 * @display: (type GdkX11Display): a #GdkDisplay
2151 * @message_type: startup notification message type ("new", "change",
2153 * @...: a list of key/value pairs (as strings), terminated by a
2154 * %NULL key. (A %NULL value for a key will cause that key to be
2155 * skipped in the output.)
2157 * Sends a startup notification message of type @message_type to
2160 * This is a convenience function for use by code that implements the
2161 * freedesktop startup notification specification. Applications should
2162 * not normally need to call it directly. See the <ulink
2163 * url="http://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt">Startup
2164 * Notification Protocol specification</ulink> for
2165 * definitions of the message types and keys that can be used.
2170 gdk_x11_display_broadcast_startup_message (GdkDisplay *display,
2171 const char *message_type,
2176 const char *key, *value, *p;
2178 message = g_string_new (message_type);
2179 g_string_append_c (message, ':');
2181 va_start (ap, message_type);
2182 while ((key = va_arg (ap, const char *)))
2184 value = va_arg (ap, const char *);
2188 g_string_append_printf (message, " %s=\"", key);
2189 for (p = value; *p; p++)
2196 g_string_append_c (message, '\\');
2200 g_string_append_c (message, *p);
2202 g_string_append_c (message, '\"');
2206 broadcast_xmessage (display,
2207 "_NET_STARTUP_INFO",
2208 "_NET_STARTUP_INFO_BEGIN",
2211 g_string_free (message, TRUE);
2215 gdk_x11_display_notify_startup_complete (GdkDisplay *display,
2216 const gchar *startup_id)
2218 if (startup_id == NULL)
2220 startup_id = GDK_X11_DISPLAY (display)->startup_notification_id;
2221 if (startup_id == NULL)
2225 gdk_x11_display_broadcast_startup_message (display, "remove",
2231 gdk_x11_display_supports_selection_notification (GdkDisplay *display)
2233 GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
2235 return display_x11->have_xfixes;
2239 gdk_x11_display_request_selection_notification (GdkDisplay *display,
2244 GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
2247 if (display_x11->have_xfixes)
2249 atom = gdk_x11_atom_to_xatom_for_display (display,
2251 XFixesSelectSelectionInput (display_x11->xdisplay,
2252 display_x11->leader_window,
2254 XFixesSetSelectionOwnerNotifyMask |
2255 XFixesSelectionWindowDestroyNotifyMask |
2256 XFixesSelectionClientCloseNotifyMask);
2265 gdk_x11_display_supports_clipboard_persistence (GdkDisplay *display)
2267 Atom clipboard_manager;
2269 /* It might make sense to cache this */
2270 clipboard_manager = gdk_x11_get_xatom_by_name_for_display (display, "CLIPBOARD_MANAGER");
2271 return XGetSelectionOwner (GDK_X11_DISPLAY (display)->xdisplay, clipboard_manager) != None;
2275 gdk_x11_display_store_clipboard (GdkDisplay *display,
2276 GdkWindow *clipboard_window,
2278 const GdkAtom *targets,
2281 GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
2282 Atom clipboard_manager, save_targets;
2284 g_return_if_fail (GDK_WINDOW_IS_X11 (clipboard_window));
2286 clipboard_manager = gdk_x11_get_xatom_by_name_for_display (display, "CLIPBOARD_MANAGER");
2287 save_targets = gdk_x11_get_xatom_by_name_for_display (display, "SAVE_TARGETS");
2289 gdk_x11_display_error_trap_push (display);
2291 if (XGetSelectionOwner (display_x11->xdisplay, clipboard_manager) != None)
2293 Atom property_name = None;
2299 property_name = gdk_x11_get_xatom_by_name_for_display (display, "GDK_SELECTION");
2301 xatoms = g_new (Atom, n_targets);
2302 for (i = 0; i < n_targets; i++)
2303 xatoms[i] = gdk_x11_atom_to_xatom_for_display (display, targets[i]);
2305 XChangeProperty (display_x11->xdisplay, GDK_WINDOW_XID (clipboard_window),
2306 property_name, XA_ATOM,
2307 32, PropModeReplace, (guchar *)xatoms, n_targets);
2312 XConvertSelection (display_x11->xdisplay,
2313 clipboard_manager, save_targets, property_name,
2314 GDK_WINDOW_XID (clipboard_window), time_);
2317 gdk_x11_display_error_trap_pop_ignored (display);
2322 * gdk_x11_display_get_user_time:
2323 * @display: (type GdkX11Display): a #GdkDisplay
2325 * Returns the timestamp of the last user interaction on
2326 * @display. The timestamp is taken from events caused
2327 * by user interaction such as key presses or pointer
2328 * movements. See gdk_x11_window_set_user_time().
2330 * Returns: the timestamp of the last user interaction
2335 gdk_x11_display_get_user_time (GdkDisplay *display)
2337 return GDK_X11_DISPLAY (display)->user_time;
2341 gdk_x11_display_supports_shapes (GdkDisplay *display)
2343 return GDK_X11_DISPLAY (display)->have_shapes;
2347 gdk_x11_display_supports_input_shapes (GdkDisplay *display)
2349 return GDK_X11_DISPLAY (display)->have_input_shapes;
2354 * gdk_x11_display_get_startup_notification_id:
2355 * @display: (type GdkX11Display): a #GdkDisplay
2357 * Gets the startup notification ID for a display.
2359 * Returns: the startup notification ID for @display
2364 gdk_x11_display_get_startup_notification_id (GdkDisplay *display)
2366 return GDK_X11_DISPLAY (display)->startup_notification_id;
2370 * gdk_x11_display_set_startup_notification_id:
2371 * @display: (type GdkX11Display): a #GdkDisplay
2372 * @startup_id: the startup notification ID (must be valid utf8)
2374 * Sets the startup notification ID for a display.
2376 * This is usually taken from the value of the DESKTOP_STARTUP_ID
2377 * environment variable, but in some cases (such as the application not
2378 * being launched using exec()) it can come from other sources.
2380 * If the ID contains the string "_TIME" then the portion following that
2381 * string is taken to be the X11 timestamp of the event that triggered
2382 * the application to be launched and the GDK current event time is set
2385 * The startup ID is also what is used to signal that the startup is
2386 * complete (for example, when opening a window or when calling
2387 * gdk_notify_startup_complete()).
2392 gdk_x11_display_set_startup_notification_id (GdkDisplay *display,
2393 const gchar *startup_id)
2395 GdkX11Display *display_x11;
2398 display_x11 = GDK_X11_DISPLAY (display);
2400 g_free (display_x11->startup_notification_id);
2401 display_x11->startup_notification_id = g_strdup (startup_id);
2403 /* Find the launch time from the startup_id, if it's there. Newer spec
2404 * states that the startup_id is of the form <unique>_TIME<timestamp>
2406 time_str = g_strrstr (startup_id, "_TIME");
2407 if (time_str != NULL)
2413 /* Skip past the "_TIME" part */
2416 retval = strtoul (time_str, &end, 0);
2417 if (end != time_str && errno == 0)
2418 display_x11->user_time = retval;
2421 /* Set the startup id on the leader window so it
2422 * applies to all windows we create on this display
2424 XChangeProperty (display_x11->xdisplay,
2425 display_x11->leader_window,
2426 gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"),
2427 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2429 (guchar *)startup_id, strlen (startup_id));
2433 gdk_x11_display_supports_composite (GdkDisplay *display)
2435 GdkX11Display *x11_display = GDK_X11_DISPLAY (display);
2437 return x11_display->have_xcomposite &&
2438 x11_display->have_xdamage &&
2439 x11_display->have_xfixes;
2443 gdk_x11_display_list_devices (GdkDisplay *display)
2445 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
2447 return GDK_X11_DISPLAY (display)->input_devices;
2451 * gdk_x11_register_standard_event_type:
2452 * @display: a #GdkDisplay
2453 * @event_base: first event type code to register
2454 * @n_events: number of event type codes to register
2456 * Registers interest in receiving extension events with type codes
2457 * between @event_base and <literal>event_base + n_events - 1</literal>.
2458 * The registered events must have the window field in the same place
2459 * as core X events (this is not the case for e.g. XKB extension events).
2461 * If an event type is registered, events of this type will go through
2462 * global and window-specific filters (see gdk_window_add_filter()).
2463 * Unregistered events will only go through global filters.
2464 * GDK may register the events of some X extensions on its own.
2466 * This function should only be needed in unusual circumstances, e.g.
2467 * when filtering XInput extension events on the root window.
2472 gdk_x11_register_standard_event_type (GdkDisplay *display,
2476 GdkEventTypeX11 *event_type;
2477 GdkX11Display *display_x11;
2479 display_x11 = GDK_X11_DISPLAY (display);
2480 event_type = g_new (GdkEventTypeX11, 1);
2482 event_type->base = event_base;
2483 event_type->n_events = n_events;
2485 display_x11->event_types = g_slist_prepend (display_x11->event_types, event_type);
2488 /* compare X sequence numbers handling wraparound */
2489 #define SEQUENCE_COMPARE(a,op,b) (((long) (a) - (long) (b)) op 0)
2491 /* delivers an error event from the error handler in gdkmain-x11.c */
2493 _gdk_x11_display_error_event (GdkDisplay *display,
2496 GdkX11Display *display_x11;
2500 display_x11 = GDK_X11_DISPLAY (display);
2503 for (tmp_list = display_x11->error_traps;
2505 tmp_list = tmp_list->next)
2509 trap = tmp_list->data;
2511 if (SEQUENCE_COMPARE (trap->start_sequence, <=, error->serial) &&
2512 (trap->end_sequence == 0 ||
2513 SEQUENCE_COMPARE (trap->end_sequence, >, error->serial)))
2516 trap->error_code = error->error_code;
2517 break; /* only innermost trap gets the error code */
2526 XGetErrorText (display_x11->xdisplay, error->error_code, buf, 63);
2529 g_strdup_printf ("The program '%s' received an X Window System error.\n"
2530 "This probably reflects a bug in the program.\n"
2531 "The error was '%s'.\n"
2532 " (Details: serial %ld error_code %d request_code %d minor_code %d)\n"
2533 " (Note to programmers: normally, X errors are reported asynchronously;\n"
2534 " that is, you will receive the error a while after causing it.\n"
2535 " To debug your program, run it with the GDK_SYNCHRONIZE environment\n"
2536 " variable to change this behavior. You can then get a meaningful\n"
2537 " backtrace from your debugger if you break on the gdk_x_error() function.)",
2542 error->request_code,
2545 #ifdef G_ENABLE_DEBUG
2546 g_error ("%s", msg);
2547 #else /* !G_ENABLE_DEBUG */
2548 g_warning ("%s\n", msg);
2551 #endif /* G_ENABLE_DEBUG */
2556 delete_outdated_error_traps (GdkX11Display *display_x11)
2559 gulong processed_sequence;
2561 processed_sequence = XLastKnownRequestProcessed (display_x11->xdisplay);
2563 tmp_list = display_x11->error_traps;
2564 while (tmp_list != NULL)
2566 GdkErrorTrap *trap = tmp_list->data;
2568 if (trap->end_sequence != 0 &&
2569 SEQUENCE_COMPARE (trap->end_sequence, <=, processed_sequence))
2571 GSList *free_me = tmp_list;
2573 tmp_list = tmp_list->next;
2574 display_x11->error_traps =
2575 g_slist_delete_link (display_x11->error_traps, free_me);
2576 g_slice_free (GdkErrorTrap, trap);
2580 tmp_list = tmp_list->next;
2586 * gdk_x11_display_error_trap_push:
2587 * @display: (type GdkX11Display): a #GdkDisplay
2589 * Begins a range of X requests on @display for which X error events
2590 * will be ignored. Unignored errors (when no trap is pushed) will abort
2591 * the application. Use gdk_x11_display_error_trap_pop() or
2592 * gdk_x11_display_error_trap_pop_ignored()to lift a trap pushed
2593 * with this function.
2595 * See also gdk_error_trap_push() to push a trap on all displays.
2600 gdk_x11_display_error_trap_push (GdkDisplay *display)
2602 GdkX11Display *display_x11;
2605 display_x11 = GDK_X11_DISPLAY (display);
2607 delete_outdated_error_traps (display_x11);
2609 /* set up the Xlib callback to tell us about errors */
2610 _gdk_x11_error_handler_push ();
2612 trap = g_slice_new0 (GdkErrorTrap);
2614 trap->start_sequence = XNextRequest (display_x11->xdisplay);
2615 trap->error_code = Success;
2617 display_x11->error_traps =
2618 g_slist_prepend (display_x11->error_traps, trap);
2622 gdk_x11_display_error_trap_pop_internal (GdkDisplay *display,
2625 GdkX11Display *display_x11;
2630 display_x11 = GDK_X11_DISPLAY (display);
2632 g_return_val_if_fail (display_x11->error_traps != NULL, Success);
2634 /* Find the first trap that hasn't been popped already */
2635 trap = NULL; /* quiet gcc */
2636 for (tmp_list = display_x11->error_traps;
2638 tmp_list = tmp_list->next)
2640 trap = tmp_list->data;
2642 if (trap->end_sequence == 0)
2646 g_return_val_if_fail (trap != NULL, Success);
2647 g_assert (trap->end_sequence == 0);
2649 /* May need to sync to fill in trap->error_code if we care about
2650 * getting an error code.
2654 gulong processed_sequence;
2655 gulong next_sequence;
2657 next_sequence = XNextRequest (display_x11->xdisplay);
2658 processed_sequence = XLastKnownRequestProcessed (display_x11->xdisplay);
2660 /* If our last request was already processed, there is no point
2661 * in syncing. i.e. if last request was a round trip (or even if
2662 * we got an event with the serial of a non-round-trip)
2664 if ((next_sequence - 1) != processed_sequence)
2666 XSync (display_x11->xdisplay, False);
2669 result = trap->error_code;
2676 /* record end of trap, giving us a range of
2677 * error sequences we'll ignore.
2679 trap->end_sequence = XNextRequest (display_x11->xdisplay);
2681 /* remove the Xlib callback */
2682 _gdk_x11_error_handler_pop ();
2684 /* we may already be outdated */
2685 delete_outdated_error_traps (display_x11);
2691 * gdk_x11_display_error_trap_pop:
2692 * @display: (type GdkX11Display): the display
2694 * Pops the error trap pushed by gdk_x11_display_error_trap_push().
2695 * Will XSync() if necessary and will always block until
2696 * the error is known to have occurred or not occurred,
2697 * so the error code can be returned.
2699 * If you don't need to use the return value,
2700 * gdk_x11_display_error_trap_pop_ignored() would be more efficient.
2702 * See gdk_error_trap_pop() for the all-displays-at-once
2707 * Return value: X error code or 0 on success
2710 gdk_x11_display_error_trap_pop (GdkDisplay *display)
2712 g_return_val_if_fail (GDK_IS_X11_DISPLAY (display), Success);
2714 return gdk_x11_display_error_trap_pop_internal (display, TRUE);
2718 * gdk_x11_display_error_trap_pop_ignored:
2719 * @display: (type GdkX11Display): the display
2721 * Pops the error trap pushed by gdk_x11_display_error_trap_push().
2722 * Does not block to see if an error occurred; merely records the
2723 * range of requests to ignore errors for, and ignores those errors
2724 * if they arrive asynchronously.
2726 * See gdk_error_trap_pop_ignored() for the all-displays-at-once
2732 gdk_x11_display_error_trap_pop_ignored (GdkDisplay *display)
2734 g_return_if_fail (GDK_IS_X11_DISPLAY (display));
2736 gdk_x11_display_error_trap_pop_internal (display, FALSE);
2740 * gdk_x11_set_sm_client_id:
2741 * @sm_client_id: the client id assigned by the session manager when the
2742 * connection was opened, or %NULL to remove the property.
2744 * Sets the <literal>SM_CLIENT_ID</literal> property on the application's leader window so that
2745 * the window manager can save the application's state using the X11R6 ICCCM
2746 * session management protocol.
2748 * See the X Session Management Library documentation for more information on
2749 * session management and the Inter-Client Communication Conventions Manual
2754 gdk_x11_set_sm_client_id (const gchar *sm_client_id)
2756 GSList *displays, *l;
2758 g_free (gdk_sm_client_id);
2759 gdk_sm_client_id = g_strdup (sm_client_id);
2761 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
2762 for (l = displays; l; l = l->next)
2763 set_sm_client_id (l->data, sm_client_id);
2765 g_slist_free (displays);
2769 gdk_x11_display_event_data_copy (GdkDisplay *display,
2770 const GdkEvent *src,
2776 gdk_x11_display_event_data_free (GdkDisplay *display,
2782 pop_error_trap (GdkDisplay *display,
2787 gdk_x11_display_error_trap_pop_ignored (display);
2792 return gdk_x11_display_error_trap_pop (display);
2797 gdk_x11_display_get_keymap (GdkDisplay *display)
2799 GdkX11Display *display_x11;
2800 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
2801 display_x11 = GDK_X11_DISPLAY (display);
2803 if (!display_x11->keymap)
2804 display_x11->keymap = g_object_new (GDK_TYPE_X11_KEYMAP, NULL);
2806 display_x11->keymap->display = display;
2808 return display_x11->keymap;
2812 gdk_x11_display_class_init (GdkX11DisplayClass * class)
2814 GObjectClass *object_class = G_OBJECT_CLASS (class);
2815 GdkDisplayClass *display_class = GDK_DISPLAY_CLASS (class);
2817 object_class->dispose = gdk_x11_display_dispose;
2818 object_class->finalize = gdk_x11_display_finalize;
2820 display_class->window_type = GDK_TYPE_X11_WINDOW;
2822 display_class->get_name = gdk_x11_display_get_name;
2823 display_class->get_n_screens = gdk_x11_display_get_n_screens;
2824 display_class->get_screen = gdk_x11_display_get_screen;
2825 display_class->get_default_screen = gdk_x11_display_get_default_screen;
2826 display_class->beep = gdk_x11_display_beep;
2827 display_class->sync = gdk_x11_display_sync;
2828 display_class->flush = gdk_x11_display_flush;
2829 display_class->has_pending = gdk_x11_display_has_pending;
2830 display_class->queue_events = _gdk_x11_display_queue_events;
2831 display_class->get_default_group = gdk_x11_display_get_default_group;
2832 display_class->supports_selection_notification = gdk_x11_display_supports_selection_notification;
2833 display_class->request_selection_notification = gdk_x11_display_request_selection_notification;
2834 display_class->supports_clipboard_persistence = gdk_x11_display_supports_clipboard_persistence;
2835 display_class->store_clipboard = gdk_x11_display_store_clipboard;
2836 display_class->supports_shapes = gdk_x11_display_supports_shapes;
2837 display_class->supports_input_shapes = gdk_x11_display_supports_input_shapes;
2838 display_class->supports_composite = gdk_x11_display_supports_composite;
2839 display_class->list_devices = gdk_x11_display_list_devices;
2840 display_class->get_app_launch_context = _gdk_x11_display_get_app_launch_context;
2841 display_class->get_cursor_for_type = _gdk_x11_display_get_cursor_for_type;
2842 display_class->get_cursor_for_name = _gdk_x11_display_get_cursor_for_name;
2843 display_class->get_cursor_for_pixbuf = _gdk_x11_display_get_cursor_for_pixbuf;
2844 display_class->get_default_cursor_size = _gdk_x11_display_get_default_cursor_size;
2845 display_class->get_maximal_cursor_size = _gdk_x11_display_get_maximal_cursor_size;
2846 display_class->supports_cursor_alpha = _gdk_x11_display_supports_cursor_alpha;
2847 display_class->supports_cursor_color = _gdk_x11_display_supports_cursor_color;
2849 display_class->before_process_all_updates = _gdk_x11_display_before_process_all_updates;
2850 display_class->after_process_all_updates = _gdk_x11_display_after_process_all_updates;
2851 display_class->get_next_serial = gdk_x11_display_get_next_serial;
2852 display_class->notify_startup_complete = gdk_x11_display_notify_startup_complete;
2853 display_class->event_data_copy = gdk_x11_display_event_data_copy;
2854 display_class->event_data_free = gdk_x11_display_event_data_free;
2855 display_class->create_window_impl = _gdk_x11_display_create_window_impl;
2856 display_class->get_keymap = gdk_x11_display_get_keymap;
2857 display_class->push_error_trap = gdk_x11_display_error_trap_push;
2858 display_class->pop_error_trap = pop_error_trap;
2859 display_class->get_selection_owner = _gdk_x11_display_get_selection_owner;
2860 display_class->set_selection_owner = _gdk_x11_display_set_selection_owner;
2861 display_class->send_selection_notify = _gdk_x11_display_send_selection_notify;
2862 display_class->get_selection_property = _gdk_x11_display_get_selection_property;
2863 display_class->convert_selection = _gdk_x11_display_convert_selection;
2864 display_class->text_property_to_utf8_list = _gdk_x11_display_text_property_to_utf8_list;
2865 display_class->utf8_to_string_target = _gdk_x11_display_utf8_to_string_target;