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_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 (gdk_frame_timings_get_cookie (timings) == 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))
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 (event->any.window->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 (event->any.window);
1116 GdkFrameTimings *timings = find_frame_timings (clock, serial);
1119 gdk_frame_timings_set_drawn_time (timings, 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 (event->any.window->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 (event->any.window);
1152 GdkFrameTimings *timings = find_frame_timings (clock, serial);
1156 gint64 drawn_time = gdk_frame_timings_get_drawn_time (timings);
1157 gint32 presentation_time_offset = (gint32)d2;
1158 gint32 refresh_interval = d3;
1160 if (drawn_time && presentation_time_offset)
1161 gdk_frame_timings_set_presentation_time (timings,
1162 drawn_time + presentation_time_offset);
1164 if (refresh_interval)
1165 gdk_frame_timings_set_refresh_interval (timings, refresh_interval);
1167 gdk_frame_timings_set_complete (timings, TRUE);
1168 #ifdef G_ENABLE_DEBUG
1169 if ((_gdk_debug_flags & GDK_DEBUG_FRAMES) != 0)
1170 _gdk_frame_clock_debug_print_timings (clock, timings);
1171 #endif /* G_ENABLE_DEBUG */
1176 if (xevent->xclient.message_type != gdk_x11_get_xatom_by_name_for_display (display, "WM_PROTOCOLS"))
1177 return GDK_FILTER_CONTINUE;
1179 atom = (Atom) xevent->xclient.data.l[0];
1181 if (atom == gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW"))
1183 /* The delete window request specifies a window
1184 * to delete. We don't actually destroy the
1185 * window because "it is only a request". (The
1186 * window might contain vital data that the
1187 * program does not want destroyed). Instead
1188 * the event is passed along to the program,
1189 * which should then destroy the window.
1192 g_message ("delete window:\t\twindow: %ld",
1193 xevent->xclient.window));
1195 event->any.type = GDK_DELETE;
1197 gdk_x11_window_set_user_time (win, xevent->xclient.data.l[1]);
1199 return GDK_FILTER_TRANSLATE;
1201 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS"))
1203 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (event->any.window);
1205 /* There is no way of knowing reliably whether we are viewable;
1206 * so trap errors asynchronously around the XSetInputFocus call
1208 if (toplevel && win->accept_focus)
1210 gdk_x11_display_error_trap_push (display);
1211 XSetInputFocus (GDK_DISPLAY_XDISPLAY (display),
1212 toplevel->focus_window,
1214 xevent->xclient.data.l[1]);
1215 gdk_x11_display_error_trap_pop_ignored (display);
1218 return GDK_FILTER_REMOVE;
1220 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING") &&
1221 !_gdk_x11_display_is_root_window (display,
1222 xevent->xclient.window))
1224 XClientMessageEvent xclient = xevent->xclient;
1226 xclient.window = GDK_WINDOW_XROOTWIN (win);
1227 XSendEvent (GDK_WINDOW_XDISPLAY (win),
1230 SubstructureRedirectMask | SubstructureNotifyMask, (XEvent *)&xclient);
1232 return GDK_FILTER_REMOVE;
1234 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_SYNC_REQUEST") &&
1235 GDK_X11_DISPLAY (display)->use_sync)
1237 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (event->any.window);
1241 toplevel->pending_counter_value = xevent->xclient.data.l[2] + ((gint64)xevent->xclient.data.l[3] << 32);
1242 toplevel->pending_counter_value_is_extended = xevent->xclient.data.l[4] != 0;
1245 return GDK_FILTER_REMOVE;
1248 return GDK_FILTER_CONTINUE;
1252 gdk_event_init (GdkDisplay *display)
1254 GdkX11Display *display_x11;
1255 GdkDeviceManager *device_manager;
1257 display_x11 = GDK_X11_DISPLAY (display);
1258 display_x11->event_source = gdk_x11_event_source_new (display);
1260 gdk_x11_event_source_add_translator ((GdkEventSource *) display_x11->event_source,
1261 GDK_EVENT_TRANSLATOR (display));
1263 device_manager = gdk_display_get_device_manager (display);
1264 gdk_x11_event_source_add_translator ((GdkEventSource *) display_x11->event_source,
1265 GDK_EVENT_TRANSLATOR (device_manager));
1269 gdk_x11_display_init_input (GdkDisplay *display)
1271 GdkX11Display *display_x11;
1272 GdkDeviceManager *device_manager;
1276 display_x11 = GDK_X11_DISPLAY (display);
1277 device_manager = gdk_display_get_device_manager (display);
1279 /* For backwards compatibility, just add
1280 * floating devices that are not keyboards.
1282 list = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING);
1284 for (l = list; l; l = l->next)
1288 if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
1291 display_x11->input_devices = g_list_prepend (display_x11->input_devices,
1292 g_object_ref (l->data));
1297 /* Now set "core" pointer to the first
1298 * master device that is a pointer.
1300 list = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
1302 for (l = list; l; l = l->next)
1306 if (gdk_device_get_source (device) != GDK_SOURCE_MOUSE)
1309 display->core_pointer = device;
1313 /* Add the core pointer to the devices list */
1314 display_x11->input_devices = g_list_prepend (display_x11->input_devices,
1315 g_object_ref (display->core_pointer));
1321 set_sm_client_id (GdkDisplay *display,
1322 const gchar *sm_client_id)
1324 GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
1326 if (gdk_display_is_closed (display))
1329 if (sm_client_id && strcmp (sm_client_id, ""))
1330 XChangeProperty (display_x11->xdisplay, display_x11->leader_window,
1331 gdk_x11_get_xatom_by_name_for_display (display, "SM_CLIENT_ID"),
1332 XA_STRING, 8, PropModeReplace, (guchar *)sm_client_id,
1333 strlen (sm_client_id));
1335 XDeleteProperty (display_x11->xdisplay, display_x11->leader_window,
1336 gdk_x11_get_xatom_by_name_for_display (display, "SM_CLIENT_ID"));
1340 _gdk_x11_display_open (const gchar *display_name)
1343 GdkDisplay *display;
1344 GdkX11Display *display_x11;
1349 XClassHint *class_hint;
1355 xdisplay = XOpenDisplay (display_name);
1359 display = g_object_new (GDK_TYPE_X11_DISPLAY, NULL);
1360 display_x11 = GDK_X11_DISPLAY (display);
1362 display_x11->xdisplay = xdisplay;
1364 /* Set up handlers for Xlib internal connections */
1365 XAddConnectionWatch (xdisplay, gdk_internal_connection_watch, NULL);
1367 _gdk_x11_precache_atoms (display, precache_atoms, G_N_ELEMENTS (precache_atoms));
1369 /* RandR must be initialized before we initialize the screens */
1370 display_x11->have_randr12 = FALSE;
1371 display_x11->have_randr13 = FALSE;
1373 if (XRRQueryExtension (display_x11->xdisplay,
1374 &display_x11->xrandr_event_base, &ignore))
1378 XRRQueryVersion (display_x11->xdisplay, &major, &minor);
1380 if ((major == 1 && minor >= 2) || major > 1) {
1381 display_x11->have_randr12 = TRUE;
1382 if (minor >= 3 || major > 1)
1383 display_x11->have_randr13 = TRUE;
1386 gdk_x11_register_standard_event_type (display, display_x11->xrandr_event_base, RRNumberEvents);
1390 /* initialize the display's screens */
1391 display_x11->screens = g_new (GdkScreen *, ScreenCount (display_x11->xdisplay));
1392 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1393 display_x11->screens[i] = _gdk_x11_screen_new (display, i);
1395 /* We need to initialize events after we have the screen
1396 * structures in places
1398 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1399 _gdk_x11_screen_init_events (display_x11->screens[i]);
1401 /*set the default screen */
1402 display_x11->default_screen = display_x11->screens[DefaultScreen (display_x11->xdisplay)];
1404 display->device_manager = _gdk_x11_device_manager_new (display);
1406 gdk_event_init (display);
1408 attr.window_type = GDK_WINDOW_TOPLEVEL;
1409 attr.wclass = GDK_INPUT_OUTPUT;
1414 attr.event_mask = 0;
1416 display_x11->leader_gdk_window = gdk_window_new (GDK_X11_SCREEN (display_x11->default_screen)->root_window,
1417 &attr, GDK_WA_X | GDK_WA_Y);
1418 (_gdk_x11_window_get_toplevel (display_x11->leader_gdk_window))->is_leader = TRUE;
1420 display_x11->leader_window = GDK_WINDOW_XID (display_x11->leader_gdk_window);
1422 display_x11->leader_window_title_set = FALSE;
1425 if (XFixesQueryExtension (display_x11->xdisplay,
1426 &display_x11->xfixes_event_base,
1429 display_x11->have_xfixes = TRUE;
1431 gdk_x11_register_standard_event_type (display,
1432 display_x11->xfixes_event_base,
1433 XFixesNumberEvents);
1437 display_x11->have_xfixes = FALSE;
1439 #ifdef HAVE_XCOMPOSITE
1440 if (XCompositeQueryExtension (display_x11->xdisplay,
1445 XCompositeQueryVersion (display_x11->xdisplay, &major, &minor);
1447 /* Prior to Composite version 0.4, composited windows clipped their
1448 * parents, so you had to use IncludeInferiors to draw to the parent
1449 * This isn't useful for our purposes, so require 0.4
1451 display_x11->have_xcomposite = major > 0 || (major == 0 && minor >= 4);
1455 display_x11->have_xcomposite = FALSE;
1458 if (XDamageQueryExtension (display_x11->xdisplay,
1459 &display_x11->xdamage_event_base,
1462 display_x11->have_xdamage = TRUE;
1464 gdk_x11_register_standard_event_type (display,
1465 display_x11->xdamage_event_base,
1466 XDamageNumberEvents);
1470 display_x11->have_xdamage = FALSE;
1472 display_x11->have_shapes = FALSE;
1473 display_x11->have_input_shapes = FALSE;
1475 if (XShapeQueryExtension (GDK_DISPLAY_XDISPLAY (display), &display_x11->shape_event_base, &ignore))
1477 display_x11->have_shapes = TRUE;
1479 if (XShapeQueryVersion (GDK_DISPLAY_XDISPLAY (display), &maj, &min))
1480 display_x11->have_input_shapes = (maj == 1 && min >= 1);
1484 display_x11->trusted_client = TRUE;
1487 int rootx, rooty, winx, winy;
1490 gdk_x11_display_error_trap_push (display);
1491 XQueryPointer (display_x11->xdisplay,
1492 GDK_X11_SCREEN (display_x11->default_screen)->xroot_window,
1493 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
1494 if (G_UNLIKELY (gdk_x11_display_error_trap_pop (display) == BadWindow))
1496 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));
1497 display_x11->trusted_client = FALSE;
1501 if (g_getenv ("GDK_SYNCHRONIZE"))
1502 XSynchronize (display_x11->xdisplay, True);
1504 class_hint = XAllocClassHint();
1505 class_hint->res_name = (char *) g_get_prgname ();
1506 class_hint->res_class = (char *)gdk_get_program_class ();
1508 /* XmbSetWMProperties sets the RESOURCE_NAME environment variable
1509 * from argv[0], so we just synthesize an argument array here.
1512 argv[0] = (char *) g_get_prgname ();
1514 XmbSetWMProperties (display_x11->xdisplay,
1515 display_x11->leader_window,
1516 NULL, NULL, argv, argc, NULL, NULL,
1520 if (gdk_sm_client_id)
1521 set_sm_client_id (display, gdk_sm_client_id);
1524 XChangeProperty (display_x11->xdisplay,
1525 display_x11->leader_window,
1526 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PID"),
1527 XA_CARDINAL, 32, PropModeReplace, (guchar *) & pid, 1);
1529 /* We don't yet know a valid time. */
1530 display_x11->user_time = 0;
1534 gint xkb_major = XkbMajorVersion;
1535 gint xkb_minor = XkbMinorVersion;
1536 if (XkbLibraryVersion (&xkb_major, &xkb_minor))
1538 xkb_major = XkbMajorVersion;
1539 xkb_minor = XkbMinorVersion;
1541 if (XkbQueryExtension (display_x11->xdisplay,
1542 NULL, &display_x11->xkb_event_type, NULL,
1543 &xkb_major, &xkb_minor))
1545 Bool detectable_autorepeat_supported;
1547 display_x11->use_xkb = TRUE;
1549 XkbSelectEvents (display_x11->xdisplay,
1551 XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask,
1552 XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask);
1554 /* keep this in sync with _gdk_x11_keymap_state_changed() */
1555 XkbSelectEventDetails (display_x11->xdisplay,
1556 XkbUseCoreKbd, XkbStateNotify,
1557 XkbAllStateComponentsMask,
1558 XkbModifierStateMask|XkbGroupStateMask);
1560 XkbSetDetectableAutoRepeat (display_x11->xdisplay,
1562 &detectable_autorepeat_supported);
1564 GDK_NOTE (MISC, g_message ("Detectable autorepeat %s.",
1565 detectable_autorepeat_supported ?
1566 "supported" : "not supported"));
1568 display_x11->have_xkb_autorepeat = detectable_autorepeat_supported;
1574 display_x11->use_sync = FALSE;
1578 int error_base, event_base;
1580 if (XSyncQueryExtension (display_x11->xdisplay,
1581 &event_base, &error_base) &&
1582 XSyncInitialize (display_x11->xdisplay,
1584 display_x11->use_sync = TRUE;
1588 gdk_x11_display_init_input (display);
1590 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1591 _gdk_x11_screen_setup (display_x11->screens[i]);
1593 g_signal_emit_by_name (display, "opened");
1599 * XLib internal connection handling
1601 typedef struct _GdkInternalConnection GdkInternalConnection;
1603 struct _GdkInternalConnection
1611 process_internal_connection (GIOChannel *gioc,
1615 GdkInternalConnection *connection = (GdkInternalConnection *)data;
1617 gdk_threads_enter ();
1619 XProcessInternalConnection ((Display*)connection->display, connection->fd);
1621 gdk_threads_leave ();
1627 gdk_x11_display_get_next_serial (GdkDisplay *display)
1629 return NextRequest (GDK_DISPLAY_XDISPLAY (display));
1633 static GdkInternalConnection *
1634 gdk_add_connection_handler (Display *display,
1637 GIOChannel *io_channel;
1638 GdkInternalConnection *connection;
1640 connection = g_new (GdkInternalConnection, 1);
1642 connection->fd = fd;
1643 connection->display = display;
1645 io_channel = g_io_channel_unix_new (fd);
1647 connection->source = g_io_create_watch (io_channel, G_IO_IN);
1648 g_source_set_callback (connection->source,
1649 (GSourceFunc)process_internal_connection, connection, NULL);
1650 g_source_attach (connection->source, NULL);
1652 g_io_channel_unref (io_channel);
1658 gdk_remove_connection_handler (GdkInternalConnection *connection)
1660 g_source_destroy (connection->source);
1661 g_free (connection);
1665 gdk_internal_connection_watch (Display *display,
1669 XPointer *watch_data)
1672 *watch_data = (XPointer)gdk_add_connection_handler (display, fd);
1674 gdk_remove_connection_handler ((GdkInternalConnection *)*watch_data);
1677 static const gchar *
1678 gdk_x11_display_get_name (GdkDisplay *display)
1680 return (gchar *) DisplayString (GDK_X11_DISPLAY (display)->xdisplay);
1684 gdk_x11_display_get_n_screens (GdkDisplay *display)
1686 return ScreenCount (GDK_X11_DISPLAY (display)->xdisplay);
1690 gdk_x11_display_get_screen (GdkDisplay *display,
1693 g_return_val_if_fail (ScreenCount (GDK_X11_DISPLAY (display)->xdisplay) > screen_num, NULL);
1695 return GDK_X11_DISPLAY (display)->screens[screen_num];
1699 gdk_x11_display_get_default_screen (GdkDisplay *display)
1701 return GDK_X11_DISPLAY (display)->default_screen;
1705 _gdk_x11_display_is_root_window (GdkDisplay *display,
1706 Window xroot_window)
1708 GdkX11Display *display_x11;
1711 display_x11 = GDK_X11_DISPLAY (display);
1713 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1715 if (GDK_SCREEN_XROOTWIN (display_x11->screens[i]) == xroot_window)
1721 struct XPointerUngrabInfo {
1722 GdkDisplay *display;
1727 device_grab_update_callback (GdkDisplay *display,
1731 GdkPointerWindowInfo *pointer_info;
1732 GdkDevice *device = data;
1734 pointer_info = _gdk_display_get_pointer_info (display, device);
1735 _gdk_display_device_grab_update (display, device,
1736 pointer_info->last_slave, serial);
1739 #define XSERVER_TIME_IS_LATER(time1, time2) \
1740 ( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) || \
1741 (( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 )) \
1745 _gdk_x11_display_update_grab_info (GdkDisplay *display,
1749 if (status == GrabSuccess)
1750 _gdk_x11_roundtrip_async (display, device_grab_update_callback, device);
1754 _gdk_x11_display_update_grab_info_ungrab (GdkDisplay *display,
1759 GdkDeviceGrabInfo *grab;
1761 XFlush (GDK_DISPLAY_XDISPLAY (display));
1763 grab = _gdk_display_get_last_device_grab (display, device);
1765 (time == GDK_CURRENT_TIME ||
1766 grab->time == GDK_CURRENT_TIME ||
1767 !XSERVER_TIME_IS_LATER (grab->time, time)))
1769 grab->serial_end = serial;
1770 _gdk_x11_roundtrip_async (display, device_grab_update_callback, device);
1775 gdk_x11_display_beep (GdkDisplay *display)
1778 XkbBell (GDK_DISPLAY_XDISPLAY (display), None, 0, None);
1780 XBell (GDK_DISPLAY_XDISPLAY (display), 0);
1785 gdk_x11_display_sync (GdkDisplay *display)
1787 XSync (GDK_DISPLAY_XDISPLAY (display), False);
1791 gdk_x11_display_flush (GdkDisplay *display)
1793 if (!display->closed)
1794 XFlush (GDK_DISPLAY_XDISPLAY (display));
1798 gdk_x11_display_has_pending (GdkDisplay *display)
1800 return XPending (GDK_DISPLAY_XDISPLAY (display));
1804 gdk_x11_display_get_default_group (GdkDisplay *display)
1806 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1808 return GDK_X11_DISPLAY (display)->leader_gdk_window;
1812 * gdk_x11_display_grab:
1813 * @display: (type GdkX11Display): a #GdkDisplay
1815 * Call XGrabServer() on @display.
1816 * To ungrab the display again, use gdk_x11_display_ungrab().
1818 * gdk_x11_display_grab()/gdk_x11_display_ungrab() calls can be nested.
1823 gdk_x11_display_grab (GdkDisplay *display)
1825 GdkX11Display *display_x11;
1827 g_return_if_fail (GDK_IS_DISPLAY (display));
1829 display_x11 = GDK_X11_DISPLAY (display);
1831 if (display_x11->grab_count == 0)
1832 XGrabServer (display_x11->xdisplay);
1833 display_x11->grab_count++;
1837 * gdk_x11_display_ungrab:
1838 * @display: (type GdkX11Display): a #GdkDisplay
1840 * Ungrab @display after it has been grabbed with
1841 * gdk_x11_display_grab().
1846 gdk_x11_display_ungrab (GdkDisplay *display)
1848 GdkX11Display *display_x11;
1850 g_return_if_fail (GDK_IS_DISPLAY (display));
1852 display_x11 = GDK_X11_DISPLAY (display);;
1853 g_return_if_fail (display_x11->grab_count > 0);
1855 display_x11->grab_count--;
1856 if (display_x11->grab_count == 0)
1858 XUngrabServer (display_x11->xdisplay);
1859 XFlush (display_x11->xdisplay);
1864 gdk_x11_display_dispose (GObject *object)
1866 GdkDisplay *display = GDK_DISPLAY (object);
1867 GdkX11Display *display_x11 = GDK_X11_DISPLAY (object);
1870 _gdk_x11_display_manager_remove_display (gdk_display_manager_get (), display);
1872 g_list_foreach (display_x11->input_devices, (GFunc) g_object_run_dispose, NULL);
1874 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1875 _gdk_screen_close (display_x11->screens[i]);
1877 if (display_x11->event_source)
1879 g_source_destroy (display_x11->event_source);
1880 g_source_unref (display_x11->event_source);
1881 display_x11->event_source = NULL;
1884 G_OBJECT_CLASS (gdk_x11_display_parent_class)->dispose (object);
1888 gdk_x11_display_finalize (GObject *object)
1890 GdkX11Display *display_x11 = GDK_X11_DISPLAY (object);
1894 if (display_x11->keymap)
1895 g_object_unref (display_x11->keymap);
1897 /* Free motif Dnd */
1898 if (display_x11->motif_target_lists)
1900 for (i = 0; i < display_x11->motif_n_target_lists; i++)
1901 g_list_free (display_x11->motif_target_lists[i]);
1902 g_free (display_x11->motif_target_lists);
1905 _gdk_x11_cursor_display_finalize (GDK_DISPLAY (display_x11));
1907 /* Empty the event queue */
1908 _gdk_x11_display_free_translate_queue (GDK_DISPLAY (display_x11));
1910 /* Atom Hashtable */
1911 g_hash_table_destroy (display_x11->atom_from_virtual);
1912 g_hash_table_destroy (display_x11->atom_to_virtual);
1915 XDestroyWindow (display_x11->xdisplay, display_x11->leader_window);
1917 /* List of event window extraction functions */
1918 g_slist_foreach (display_x11->event_types, (GFunc)g_free, NULL);
1919 g_slist_free (display_x11->event_types);
1921 /* input GdkDevice list */
1922 g_list_free_full (display_x11->input_devices, g_object_unref);
1924 /* input GdkWindow list */
1925 g_list_free_full (display_x11->input_windows, g_free);
1927 /* Free all GdkScreens */
1928 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1929 g_object_unref (display_x11->screens[i]);
1930 g_free (display_x11->screens);
1932 g_free (display_x11->startup_notification_id);
1934 /* X ID hashtable */
1935 g_hash_table_destroy (display_x11->xid_ht);
1937 XCloseDisplay (display_x11->xdisplay);
1940 while (display_x11->error_traps != NULL)
1942 GdkErrorTrap *trap = display_x11->error_traps->data;
1944 display_x11->error_traps =
1945 g_slist_delete_link (display_x11->error_traps,
1946 display_x11->error_traps);
1948 if (trap->end_sequence == 0)
1949 g_warning ("Display finalized with an unpopped error trap");
1951 g_slice_free (GdkErrorTrap, trap);
1954 G_OBJECT_CLASS (gdk_x11_display_parent_class)->finalize (object);
1958 * gdk_x11_lookup_xdisplay:
1959 * @xdisplay: a pointer to an X Display
1961 * Find the #GdkDisplay corresponding to @display, if any exists.
1963 * Return value: (transfer none): the #GdkDisplay, if found, otherwise %NULL.
1968 gdk_x11_lookup_xdisplay (Display *xdisplay)
1971 GdkDisplay *display;
1975 list = gdk_display_manager_list_displays (gdk_display_manager_get ());
1977 for (l = list; l; l = l->next)
1979 if (GDK_DISPLAY_XDISPLAY (l->data) == xdisplay)
1986 g_slist_free (list);
1992 * _gdk_x11_display_screen_for_xrootwin:
1993 * @display: a #GdkDisplay
1994 * @xrootwin: window ID for one of of the screen's of the display.
1996 * Given the root window ID of one of the screen's of a #GdkDisplay,
1999 * Return value: (transfer none): the #GdkScreen corresponding to
2000 * @xrootwin, or %NULL.
2003 _gdk_x11_display_screen_for_xrootwin (GdkDisplay *display,
2008 for (i = 0; i < ScreenCount (GDK_X11_DISPLAY (display)->xdisplay); i++)
2010 GdkScreen *screen = gdk_display_get_screen (display, i);
2011 if (GDK_SCREEN_XROOTWIN (screen) == xrootwin)
2019 * gdk_x11_display_get_xdisplay:
2020 * @display: (type GdkX11Display): a #GdkDisplay
2022 * Returns the X display of a #GdkDisplay.
2024 * Returns: (transfer none): an X display
2029 gdk_x11_display_get_xdisplay (GdkDisplay *display)
2031 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
2032 return GDK_X11_DISPLAY (display)->xdisplay;
2036 _gdk_x11_display_make_default (GdkDisplay *display)
2038 GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
2039 const gchar *startup_id;
2041 g_free (display_x11->startup_notification_id);
2042 display_x11->startup_notification_id = NULL;
2044 startup_id = g_getenv ("DESKTOP_STARTUP_ID");
2045 if (startup_id && *startup_id != '\0')
2047 if (!g_utf8_validate (startup_id, -1, NULL))
2048 g_warning ("DESKTOP_STARTUP_ID contains invalid UTF-8");
2050 gdk_x11_display_set_startup_notification_id (display, startup_id);
2052 /* Clear the environment variable so it won't be inherited by
2053 * child processes and confuse things.
2055 g_unsetenv ("DESKTOP_STARTUP_ID");
2060 broadcast_xmessage (GdkDisplay *display,
2061 const char *message_type,
2062 const char *message_type_begin,
2063 const char *message)
2065 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
2066 GdkScreen *screen = gdk_display_get_default_screen (display);
2067 GdkWindow *root_window = gdk_screen_get_root_window (screen);
2068 Window xroot_window = GDK_WINDOW_XID (root_window);
2071 Atom type_atom_begin;
2074 if (!G_LIKELY (GDK_X11_DISPLAY (display)->trusted_client))
2078 XSetWindowAttributes attrs;
2080 attrs.override_redirect = True;
2081 attrs.event_mask = PropertyChangeMask | StructureNotifyMask;
2084 XCreateWindow (xdisplay,
2090 (Visual *)CopyFromParent,
2091 CWOverrideRedirect | CWEventMask,
2095 type_atom = gdk_x11_get_xatom_by_name_for_display (display,
2097 type_atom_begin = gdk_x11_get_xatom_by_name_for_display (display,
2098 message_type_begin);
2101 XClientMessageEvent xclient;
2103 const char *src_end;
2107 memset(&xclient, 0, sizeof (xclient));
2108 xclient.type = ClientMessage;
2109 xclient.message_type = type_atom_begin;
2110 xclient.display =xdisplay;
2111 xclient.window = xwindow;
2115 src_end = message + strlen (message) + 1; /* +1 to include nul byte */
2117 while (src != src_end)
2119 dest = &xclient.data.b[0];
2120 dest_end = dest + 20;
2122 while (dest != dest_end &&
2130 while (dest != dest_end)
2136 XSendEvent (xdisplay,
2140 (XEvent *)&xclient);
2142 xclient.message_type = type_atom;
2146 XDestroyWindow (xdisplay, xwindow);
2151 * gdk_x11_display_broadcast_startup_message:
2152 * @display: (type GdkX11Display): a #GdkDisplay
2153 * @message_type: startup notification message type ("new", "change",
2155 * @...: a list of key/value pairs (as strings), terminated by a
2156 * %NULL key. (A %NULL value for a key will cause that key to be
2157 * skipped in the output.)
2159 * Sends a startup notification message of type @message_type to
2162 * This is a convenience function for use by code that implements the
2163 * freedesktop startup notification specification. Applications should
2164 * not normally need to call it directly. See the <ulink
2165 * url="http://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt">Startup
2166 * Notification Protocol specification</ulink> for
2167 * definitions of the message types and keys that can be used.
2172 gdk_x11_display_broadcast_startup_message (GdkDisplay *display,
2173 const char *message_type,
2178 const char *key, *value, *p;
2180 message = g_string_new (message_type);
2181 g_string_append_c (message, ':');
2183 va_start (ap, message_type);
2184 while ((key = va_arg (ap, const char *)))
2186 value = va_arg (ap, const char *);
2190 g_string_append_printf (message, " %s=\"", key);
2191 for (p = value; *p; p++)
2198 g_string_append_c (message, '\\');
2202 g_string_append_c (message, *p);
2204 g_string_append_c (message, '\"');
2208 broadcast_xmessage (display,
2209 "_NET_STARTUP_INFO",
2210 "_NET_STARTUP_INFO_BEGIN",
2213 g_string_free (message, TRUE);
2217 gdk_x11_display_notify_startup_complete (GdkDisplay *display,
2218 const gchar *startup_id)
2220 if (startup_id == NULL)
2222 startup_id = GDK_X11_DISPLAY (display)->startup_notification_id;
2223 if (startup_id == NULL)
2227 gdk_x11_display_broadcast_startup_message (display, "remove",
2233 gdk_x11_display_supports_selection_notification (GdkDisplay *display)
2235 GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
2237 return display_x11->have_xfixes;
2241 gdk_x11_display_request_selection_notification (GdkDisplay *display,
2246 GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
2249 if (display_x11->have_xfixes)
2251 atom = gdk_x11_atom_to_xatom_for_display (display,
2253 XFixesSelectSelectionInput (display_x11->xdisplay,
2254 display_x11->leader_window,
2256 XFixesSetSelectionOwnerNotifyMask |
2257 XFixesSelectionWindowDestroyNotifyMask |
2258 XFixesSelectionClientCloseNotifyMask);
2267 gdk_x11_display_supports_clipboard_persistence (GdkDisplay *display)
2269 Atom clipboard_manager;
2271 /* It might make sense to cache this */
2272 clipboard_manager = gdk_x11_get_xatom_by_name_for_display (display, "CLIPBOARD_MANAGER");
2273 return XGetSelectionOwner (GDK_X11_DISPLAY (display)->xdisplay, clipboard_manager) != None;
2277 gdk_x11_display_store_clipboard (GdkDisplay *display,
2278 GdkWindow *clipboard_window,
2280 const GdkAtom *targets,
2283 GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
2284 Atom clipboard_manager, save_targets;
2286 g_return_if_fail (GDK_WINDOW_IS_X11 (clipboard_window));
2288 clipboard_manager = gdk_x11_get_xatom_by_name_for_display (display, "CLIPBOARD_MANAGER");
2289 save_targets = gdk_x11_get_xatom_by_name_for_display (display, "SAVE_TARGETS");
2291 gdk_x11_display_error_trap_push (display);
2293 if (XGetSelectionOwner (display_x11->xdisplay, clipboard_manager) != None)
2295 Atom property_name = None;
2301 property_name = gdk_x11_get_xatom_by_name_for_display (display, "GDK_SELECTION");
2303 xatoms = g_new (Atom, n_targets);
2304 for (i = 0; i < n_targets; i++)
2305 xatoms[i] = gdk_x11_atom_to_xatom_for_display (display, targets[i]);
2307 XChangeProperty (display_x11->xdisplay, GDK_WINDOW_XID (clipboard_window),
2308 property_name, XA_ATOM,
2309 32, PropModeReplace, (guchar *)xatoms, n_targets);
2314 XConvertSelection (display_x11->xdisplay,
2315 clipboard_manager, save_targets, property_name,
2316 GDK_WINDOW_XID (clipboard_window), time_);
2319 gdk_x11_display_error_trap_pop_ignored (display);
2324 * gdk_x11_display_get_user_time:
2325 * @display: (type GdkX11Display): a #GdkDisplay
2327 * Returns the timestamp of the last user interaction on
2328 * @display. The timestamp is taken from events caused
2329 * by user interaction such as key presses or pointer
2330 * movements. See gdk_x11_window_set_user_time().
2332 * Returns: the timestamp of the last user interaction
2337 gdk_x11_display_get_user_time (GdkDisplay *display)
2339 return GDK_X11_DISPLAY (display)->user_time;
2343 gdk_x11_display_supports_shapes (GdkDisplay *display)
2345 return GDK_X11_DISPLAY (display)->have_shapes;
2349 gdk_x11_display_supports_input_shapes (GdkDisplay *display)
2351 return GDK_X11_DISPLAY (display)->have_input_shapes;
2356 * gdk_x11_display_get_startup_notification_id:
2357 * @display: (type GdkX11Display): a #GdkDisplay
2359 * Gets the startup notification ID for a display.
2361 * Returns: the startup notification ID for @display
2366 gdk_x11_display_get_startup_notification_id (GdkDisplay *display)
2368 return GDK_X11_DISPLAY (display)->startup_notification_id;
2372 * gdk_x11_display_set_startup_notification_id:
2373 * @display: (type GdkX11Display): a #GdkDisplay
2374 * @startup_id: the startup notification ID (must be valid utf8)
2376 * Sets the startup notification ID for a display.
2378 * This is usually taken from the value of the DESKTOP_STARTUP_ID
2379 * environment variable, but in some cases (such as the application not
2380 * being launched using exec()) it can come from other sources.
2382 * If the ID contains the string "_TIME" then the portion following that
2383 * string is taken to be the X11 timestamp of the event that triggered
2384 * the application to be launched and the GDK current event time is set
2387 * The startup ID is also what is used to signal that the startup is
2388 * complete (for example, when opening a window or when calling
2389 * gdk_notify_startup_complete()).
2394 gdk_x11_display_set_startup_notification_id (GdkDisplay *display,
2395 const gchar *startup_id)
2397 GdkX11Display *display_x11;
2400 display_x11 = GDK_X11_DISPLAY (display);
2402 g_free (display_x11->startup_notification_id);
2403 display_x11->startup_notification_id = g_strdup (startup_id);
2405 /* Find the launch time from the startup_id, if it's there. Newer spec
2406 * states that the startup_id is of the form <unique>_TIME<timestamp>
2408 time_str = g_strrstr (startup_id, "_TIME");
2409 if (time_str != NULL)
2415 /* Skip past the "_TIME" part */
2418 retval = strtoul (time_str, &end, 0);
2419 if (end != time_str && errno == 0)
2420 display_x11->user_time = retval;
2423 /* Set the startup id on the leader window so it
2424 * applies to all windows we create on this display
2426 XChangeProperty (display_x11->xdisplay,
2427 display_x11->leader_window,
2428 gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"),
2429 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2431 (guchar *)startup_id, strlen (startup_id));
2435 gdk_x11_display_supports_composite (GdkDisplay *display)
2437 GdkX11Display *x11_display = GDK_X11_DISPLAY (display);
2439 return x11_display->have_xcomposite &&
2440 x11_display->have_xdamage &&
2441 x11_display->have_xfixes;
2445 gdk_x11_display_list_devices (GdkDisplay *display)
2447 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
2449 return GDK_X11_DISPLAY (display)->input_devices;
2453 * gdk_x11_register_standard_event_type:
2454 * @display: a #GdkDisplay
2455 * @event_base: first event type code to register
2456 * @n_events: number of event type codes to register
2458 * Registers interest in receiving extension events with type codes
2459 * between @event_base and <literal>event_base + n_events - 1</literal>.
2460 * The registered events must have the window field in the same place
2461 * as core X events (this is not the case for e.g. XKB extension events).
2463 * If an event type is registered, events of this type will go through
2464 * global and window-specific filters (see gdk_window_add_filter()).
2465 * Unregistered events will only go through global filters.
2466 * GDK may register the events of some X extensions on its own.
2468 * This function should only be needed in unusual circumstances, e.g.
2469 * when filtering XInput extension events on the root window.
2474 gdk_x11_register_standard_event_type (GdkDisplay *display,
2478 GdkEventTypeX11 *event_type;
2479 GdkX11Display *display_x11;
2481 display_x11 = GDK_X11_DISPLAY (display);
2482 event_type = g_new (GdkEventTypeX11, 1);
2484 event_type->base = event_base;
2485 event_type->n_events = n_events;
2487 display_x11->event_types = g_slist_prepend (display_x11->event_types, event_type);
2490 /* compare X sequence numbers handling wraparound */
2491 #define SEQUENCE_COMPARE(a,op,b) (((long) (a) - (long) (b)) op 0)
2493 /* delivers an error event from the error handler in gdkmain-x11.c */
2495 _gdk_x11_display_error_event (GdkDisplay *display,
2498 GdkX11Display *display_x11;
2502 display_x11 = GDK_X11_DISPLAY (display);
2505 for (tmp_list = display_x11->error_traps;
2507 tmp_list = tmp_list->next)
2511 trap = tmp_list->data;
2513 if (SEQUENCE_COMPARE (trap->start_sequence, <=, error->serial) &&
2514 (trap->end_sequence == 0 ||
2515 SEQUENCE_COMPARE (trap->end_sequence, >, error->serial)))
2518 trap->error_code = error->error_code;
2519 break; /* only innermost trap gets the error code */
2528 XGetErrorText (display_x11->xdisplay, error->error_code, buf, 63);
2531 g_strdup_printf ("The program '%s' received an X Window System error.\n"
2532 "This probably reflects a bug in the program.\n"
2533 "The error was '%s'.\n"
2534 " (Details: serial %ld error_code %d request_code %d minor_code %d)\n"
2535 " (Note to programmers: normally, X errors are reported asynchronously;\n"
2536 " that is, you will receive the error a while after causing it.\n"
2537 " To debug your program, run it with the GDK_SYNCHRONIZE environment\n"
2538 " variable to change this behavior. You can then get a meaningful\n"
2539 " backtrace from your debugger if you break on the gdk_x_error() function.)",
2544 error->request_code,
2547 #ifdef G_ENABLE_DEBUG
2548 g_error ("%s", msg);
2549 #else /* !G_ENABLE_DEBUG */
2550 g_warning ("%s\n", msg);
2553 #endif /* G_ENABLE_DEBUG */
2558 delete_outdated_error_traps (GdkX11Display *display_x11)
2561 gulong processed_sequence;
2563 processed_sequence = XLastKnownRequestProcessed (display_x11->xdisplay);
2565 tmp_list = display_x11->error_traps;
2566 while (tmp_list != NULL)
2568 GdkErrorTrap *trap = tmp_list->data;
2570 if (trap->end_sequence != 0 &&
2571 SEQUENCE_COMPARE (trap->end_sequence, <=, processed_sequence))
2573 GSList *free_me = tmp_list;
2575 tmp_list = tmp_list->next;
2576 display_x11->error_traps =
2577 g_slist_delete_link (display_x11->error_traps, free_me);
2578 g_slice_free (GdkErrorTrap, trap);
2582 tmp_list = tmp_list->next;
2588 * gdk_x11_display_error_trap_push:
2589 * @display: (type GdkX11Display): a #GdkDisplay
2591 * Begins a range of X requests on @display for which X error events
2592 * will be ignored. Unignored errors (when no trap is pushed) will abort
2593 * the application. Use gdk_x11_display_error_trap_pop() or
2594 * gdk_x11_display_error_trap_pop_ignored()to lift a trap pushed
2595 * with this function.
2597 * See also gdk_error_trap_push() to push a trap on all displays.
2602 gdk_x11_display_error_trap_push (GdkDisplay *display)
2604 GdkX11Display *display_x11;
2607 display_x11 = GDK_X11_DISPLAY (display);
2609 delete_outdated_error_traps (display_x11);
2611 /* set up the Xlib callback to tell us about errors */
2612 _gdk_x11_error_handler_push ();
2614 trap = g_slice_new0 (GdkErrorTrap);
2616 trap->start_sequence = XNextRequest (display_x11->xdisplay);
2617 trap->error_code = Success;
2619 display_x11->error_traps =
2620 g_slist_prepend (display_x11->error_traps, trap);
2624 gdk_x11_display_error_trap_pop_internal (GdkDisplay *display,
2627 GdkX11Display *display_x11;
2632 display_x11 = GDK_X11_DISPLAY (display);
2634 g_return_val_if_fail (display_x11->error_traps != NULL, Success);
2636 /* Find the first trap that hasn't been popped already */
2637 trap = NULL; /* quiet gcc */
2638 for (tmp_list = display_x11->error_traps;
2640 tmp_list = tmp_list->next)
2642 trap = tmp_list->data;
2644 if (trap->end_sequence == 0)
2648 g_return_val_if_fail (trap != NULL, Success);
2649 g_assert (trap->end_sequence == 0);
2651 /* May need to sync to fill in trap->error_code if we care about
2652 * getting an error code.
2656 gulong processed_sequence;
2657 gulong next_sequence;
2659 next_sequence = XNextRequest (display_x11->xdisplay);
2660 processed_sequence = XLastKnownRequestProcessed (display_x11->xdisplay);
2662 /* If our last request was already processed, there is no point
2663 * in syncing. i.e. if last request was a round trip (or even if
2664 * we got an event with the serial of a non-round-trip)
2666 if ((next_sequence - 1) != processed_sequence)
2668 XSync (display_x11->xdisplay, False);
2671 result = trap->error_code;
2678 /* record end of trap, giving us a range of
2679 * error sequences we'll ignore.
2681 trap->end_sequence = XNextRequest (display_x11->xdisplay);
2683 /* remove the Xlib callback */
2684 _gdk_x11_error_handler_pop ();
2686 /* we may already be outdated */
2687 delete_outdated_error_traps (display_x11);
2693 * gdk_x11_display_error_trap_pop:
2694 * @display: (type GdkX11Display): the display
2696 * Pops the error trap pushed by gdk_x11_display_error_trap_push().
2697 * Will XSync() if necessary and will always block until
2698 * the error is known to have occurred or not occurred,
2699 * so the error code can be returned.
2701 * If you don't need to use the return value,
2702 * gdk_x11_display_error_trap_pop_ignored() would be more efficient.
2704 * See gdk_error_trap_pop() for the all-displays-at-once
2709 * Return value: X error code or 0 on success
2712 gdk_x11_display_error_trap_pop (GdkDisplay *display)
2714 g_return_val_if_fail (GDK_IS_X11_DISPLAY (display), Success);
2716 return gdk_x11_display_error_trap_pop_internal (display, TRUE);
2720 * gdk_x11_display_error_trap_pop_ignored:
2721 * @display: (type GdkX11Display): the display
2723 * Pops the error trap pushed by gdk_x11_display_error_trap_push().
2724 * Does not block to see if an error occurred; merely records the
2725 * range of requests to ignore errors for, and ignores those errors
2726 * if they arrive asynchronously.
2728 * See gdk_error_trap_pop_ignored() for the all-displays-at-once
2734 gdk_x11_display_error_trap_pop_ignored (GdkDisplay *display)
2736 g_return_if_fail (GDK_IS_X11_DISPLAY (display));
2738 gdk_x11_display_error_trap_pop_internal (display, FALSE);
2742 * gdk_x11_set_sm_client_id:
2743 * @sm_client_id: the client id assigned by the session manager when the
2744 * connection was opened, or %NULL to remove the property.
2746 * Sets the <literal>SM_CLIENT_ID</literal> property on the application's leader window so that
2747 * the window manager can save the application's state using the X11R6 ICCCM
2748 * session management protocol.
2750 * See the X Session Management Library documentation for more information on
2751 * session management and the Inter-Client Communication Conventions Manual
2756 gdk_x11_set_sm_client_id (const gchar *sm_client_id)
2758 GSList *displays, *l;
2760 g_free (gdk_sm_client_id);
2761 gdk_sm_client_id = g_strdup (sm_client_id);
2763 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
2764 for (l = displays; l; l = l->next)
2765 set_sm_client_id (l->data, sm_client_id);
2767 g_slist_free (displays);
2771 gdk_x11_display_event_data_copy (GdkDisplay *display,
2772 const GdkEvent *src,
2778 gdk_x11_display_event_data_free (GdkDisplay *display,
2784 pop_error_trap (GdkDisplay *display,
2789 gdk_x11_display_error_trap_pop_ignored (display);
2794 return gdk_x11_display_error_trap_pop (display);
2799 gdk_x11_display_get_keymap (GdkDisplay *display)
2801 GdkX11Display *display_x11;
2802 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
2803 display_x11 = GDK_X11_DISPLAY (display);
2805 if (!display_x11->keymap)
2806 display_x11->keymap = g_object_new (GDK_TYPE_X11_KEYMAP, NULL);
2808 display_x11->keymap->display = display;
2810 return display_x11->keymap;
2814 gdk_x11_display_class_init (GdkX11DisplayClass * class)
2816 GObjectClass *object_class = G_OBJECT_CLASS (class);
2817 GdkDisplayClass *display_class = GDK_DISPLAY_CLASS (class);
2819 object_class->dispose = gdk_x11_display_dispose;
2820 object_class->finalize = gdk_x11_display_finalize;
2822 display_class->window_type = GDK_TYPE_X11_WINDOW;
2824 display_class->get_name = gdk_x11_display_get_name;
2825 display_class->get_n_screens = gdk_x11_display_get_n_screens;
2826 display_class->get_screen = gdk_x11_display_get_screen;
2827 display_class->get_default_screen = gdk_x11_display_get_default_screen;
2828 display_class->beep = gdk_x11_display_beep;
2829 display_class->sync = gdk_x11_display_sync;
2830 display_class->flush = gdk_x11_display_flush;
2831 display_class->has_pending = gdk_x11_display_has_pending;
2832 display_class->queue_events = _gdk_x11_display_queue_events;
2833 display_class->get_default_group = gdk_x11_display_get_default_group;
2834 display_class->supports_selection_notification = gdk_x11_display_supports_selection_notification;
2835 display_class->request_selection_notification = gdk_x11_display_request_selection_notification;
2836 display_class->supports_clipboard_persistence = gdk_x11_display_supports_clipboard_persistence;
2837 display_class->store_clipboard = gdk_x11_display_store_clipboard;
2838 display_class->supports_shapes = gdk_x11_display_supports_shapes;
2839 display_class->supports_input_shapes = gdk_x11_display_supports_input_shapes;
2840 display_class->supports_composite = gdk_x11_display_supports_composite;
2841 display_class->list_devices = gdk_x11_display_list_devices;
2842 display_class->get_app_launch_context = _gdk_x11_display_get_app_launch_context;
2843 display_class->get_cursor_for_type = _gdk_x11_display_get_cursor_for_type;
2844 display_class->get_cursor_for_name = _gdk_x11_display_get_cursor_for_name;
2845 display_class->get_cursor_for_pixbuf = _gdk_x11_display_get_cursor_for_pixbuf;
2846 display_class->get_default_cursor_size = _gdk_x11_display_get_default_cursor_size;
2847 display_class->get_maximal_cursor_size = _gdk_x11_display_get_maximal_cursor_size;
2848 display_class->supports_cursor_alpha = _gdk_x11_display_supports_cursor_alpha;
2849 display_class->supports_cursor_color = _gdk_x11_display_supports_cursor_color;
2851 display_class->before_process_all_updates = _gdk_x11_display_before_process_all_updates;
2852 display_class->after_process_all_updates = _gdk_x11_display_after_process_all_updates;
2853 display_class->get_next_serial = gdk_x11_display_get_next_serial;
2854 display_class->notify_startup_complete = gdk_x11_display_notify_startup_complete;
2855 display_class->event_data_copy = gdk_x11_display_event_data_copy;
2856 display_class->event_data_free = gdk_x11_display_event_data_free;
2857 display_class->create_window_impl = _gdk_x11_display_create_window_impl;
2858 display_class->get_keymap = gdk_x11_display_get_keymap;
2859 display_class->push_error_trap = gdk_x11_display_error_trap_push;
2860 display_class->pop_error_trap = pop_error_trap;
2861 display_class->get_selection_owner = _gdk_x11_display_get_selection_owner;
2862 display_class->set_selection_owner = _gdk_x11_display_set_selection_owner;
2863 display_class->send_selection_notify = _gdk_x11_display_send_selection_notify;
2864 display_class->get_selection_property = _gdk_x11_display_get_selection_property;
2865 display_class->convert_selection = _gdk_x11_display_convert_selection;
2866 display_class->text_property_to_utf8_list = _gdk_x11_display_text_property_to_utf8_list;
2867 display_class->utf8_to_string_target = _gdk_x11_display_utf8_to_string_target;