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 "gdkinternals.h"
30 #include "gdkscreen.h"
31 #include "gdkinternals.h"
32 #include "gdkdeviceprivate.h"
33 #include "gdkkeysprivate.h"
34 #include "gdkdevicemanager.h"
35 #include "xsettings-client.h"
36 #include "gdkdisplay-x11.h"
37 #include "gdkprivate-x11.h"
38 #include "gdkscreen-x11.h"
41 #include <glib/gprintf.h>
47 #include <X11/Xatom.h>
50 #include <X11/XKBlib.h>
54 #include <X11/extensions/Xfixes.h>
57 #include <X11/extensions/shape.h>
59 #ifdef HAVE_XCOMPOSITE
60 #include <X11/extensions/Xcomposite.h>
64 #include <X11/extensions/Xdamage.h>
68 #include <X11/extensions/Xrandr.h>
71 typedef struct _GdkErrorTrap GdkErrorTrap;
75 /* Next sequence when trap was pushed, i.e. first sequence to
78 gulong start_sequence;
80 /* Next sequence when trap was popped, i.e. first sequence
81 * to not ignore. 0 if trap is still active.
85 /* Most recent error code within the sequence */
89 static void gdk_x11_display_dispose (GObject *object);
90 static void gdk_x11_display_finalize (GObject *object);
92 static void gdk_x11_display_event_translator_init (GdkEventTranslatorIface *iface);
94 static gboolean gdk_x11_display_translate_event (GdkEventTranslator *translator,
99 static void gdk_internal_connection_watch (Display *display,
103 XPointer *watch_data);
105 typedef struct _GdkEventTypeX11 GdkEventTypeX11;
107 struct _GdkEventTypeX11
113 /* Note that we never *directly* use WM_LOCALE_NAME, WM_PROTOCOLS,
114 * but including them here has the side-effect of getting them
115 * into the internal Xlib cache
117 static const char *const precache_atoms[] = {
127 "_NET_ACTIVE_WINDOW",
128 "_NET_CURRENT_DESKTOP",
129 "_NET_FRAME_EXTENTS",
139 "_NET_WM_STATE_ABOVE",
140 "_NET_WM_STATE_BELOW",
141 "_NET_WM_STATE_FULLSCREEN",
142 "_NET_WM_STATE_MODAL",
143 "_NET_WM_STATE_MAXIMIZED_VERT",
144 "_NET_WM_STATE_MAXIMIZED_HORZ",
145 "_NET_WM_STATE_SKIP_TASKBAR",
146 "_NET_WM_STATE_SKIP_PAGER",
147 "_NET_WM_STATE_STICKY",
148 "_NET_WM_SYNC_REQUEST",
149 "_NET_WM_SYNC_REQUEST_COUNTER",
150 "_NET_WM_WINDOW_TYPE",
151 "_NET_WM_WINDOW_TYPE_NORMAL",
153 "_NET_VIRTUAL_ROOTS",
155 "_NET_WM_STATE_FOCUSED"
158 static char *gdk_sm_client_id;
160 G_DEFINE_TYPE_WITH_CODE (GdkX11Display, gdk_x11_display, GDK_TYPE_DISPLAY,
161 G_IMPLEMENT_INTERFACE (GDK_TYPE_EVENT_TRANSLATOR,
162 gdk_x11_display_event_translator_init))
166 gdk_x11_display_init (GdkX11Display *display)
168 _gdk_x11_display_manager_add_display (gdk_display_manager_get (),
169 GDK_DISPLAY (display));
173 gdk_x11_display_event_translator_init (GdkEventTranslatorIface *iface)
175 iface->translate_event = gdk_x11_display_translate_event;
179 do_net_wm_state_changes (GdkWindow *window)
181 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
182 GdkWindowState old_state;
184 if (GDK_WINDOW_DESTROYED (window) ||
185 gdk_window_get_window_type (window) != GDK_WINDOW_TOPLEVEL)
188 old_state = gdk_window_get_state (window);
190 /* For found_sticky to remain TRUE, we have to also be on desktop
193 if (old_state & GDK_WINDOW_STATE_STICKY)
195 if (!(toplevel->have_sticky && toplevel->on_all_desktops))
196 gdk_synthesize_window_state (window,
197 GDK_WINDOW_STATE_STICKY,
202 if (toplevel->have_sticky && toplevel->on_all_desktops)
203 gdk_synthesize_window_state (window,
205 GDK_WINDOW_STATE_STICKY);
208 if (old_state & GDK_WINDOW_STATE_FULLSCREEN)
210 if (!toplevel->have_fullscreen)
211 gdk_synthesize_window_state (window,
212 GDK_WINDOW_STATE_FULLSCREEN,
217 if (toplevel->have_fullscreen)
218 gdk_synthesize_window_state (window,
220 GDK_WINDOW_STATE_FULLSCREEN);
223 /* Our "maximized" means both vertical and horizontal; if only one,
224 * we don't expose that via GDK
226 if (old_state & GDK_WINDOW_STATE_MAXIMIZED)
228 if (!(toplevel->have_maxvert && toplevel->have_maxhorz))
229 gdk_synthesize_window_state (window,
230 GDK_WINDOW_STATE_MAXIMIZED,
235 if (toplevel->have_maxvert && toplevel->have_maxhorz)
236 gdk_synthesize_window_state (window,
238 GDK_WINDOW_STATE_MAXIMIZED);
241 if (old_state & GDK_WINDOW_STATE_FOCUSED)
243 if (!toplevel->have_focused)
244 gdk_synthesize_window_state (window,
245 GDK_WINDOW_STATE_FOCUSED,
250 if (toplevel->have_focused)
251 gdk_synthesize_window_state (window,
253 GDK_WINDOW_STATE_FOCUSED);
256 if (old_state & GDK_WINDOW_STATE_ICONIFIED)
258 if (!toplevel->have_hidden)
259 gdk_synthesize_window_state (window,
260 GDK_WINDOW_STATE_ICONIFIED,
265 if (toplevel->have_hidden)
266 gdk_synthesize_window_state (window,
268 GDK_WINDOW_STATE_ICONIFIED);
273 gdk_check_wm_desktop_changed (GdkWindow *window)
275 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
276 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
286 gdk_x11_display_error_trap_push (display);
287 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
288 GDK_WINDOW_XID (window),
289 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
290 0, G_MAXLONG, False, XA_CARDINAL, &type,
292 &bytes_after, &data);
293 gdk_x11_display_error_trap_pop_ignored (display);
297 desktop = (gulong *)data;
298 toplevel->on_all_desktops = ((*desktop & 0xFFFFFFFF) == 0xFFFFFFFF);
302 toplevel->on_all_desktops = FALSE;
304 do_net_wm_state_changes (window);
308 gdk_check_wm_state_changed (GdkWindow *window)
310 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
311 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
312 GdkScreen *screen = GDK_WINDOW_SCREEN (window);
322 gboolean had_sticky = toplevel->have_sticky;
324 toplevel->have_sticky = FALSE;
325 toplevel->have_maxvert = FALSE;
326 toplevel->have_maxhorz = FALSE;
327 toplevel->have_fullscreen = FALSE;
328 toplevel->have_focused = FALSE;
329 toplevel->have_hidden = FALSE;
332 gdk_x11_display_error_trap_push (display);
333 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
334 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
335 0, G_MAXLONG, False, XA_ATOM, &type, &format, &nitems,
336 &bytes_after, &data);
337 gdk_x11_display_error_trap_pop_ignored (display);
341 Atom sticky_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_STICKY");
342 Atom maxvert_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_VERT");
343 Atom maxhorz_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_HORZ");
344 Atom fullscreen_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_FULLSCREEN");
345 Atom focused_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_FOCUSED");
346 Atom hidden_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_HIDDEN");
348 atoms = (Atom *)data;
353 if (atoms[i] == sticky_atom)
354 toplevel->have_sticky = TRUE;
355 else if (atoms[i] == maxvert_atom)
356 toplevel->have_maxvert = TRUE;
357 else if (atoms[i] == maxhorz_atom)
358 toplevel->have_maxhorz = TRUE;
359 else if (atoms[i] == fullscreen_atom)
360 toplevel->have_fullscreen = TRUE;
361 else if (atoms[i] == focused_atom)
362 toplevel->have_focused = TRUE;
363 else if (atoms[i] == hidden_atom)
364 toplevel->have_hidden = TRUE;
372 if (!gdk_x11_screen_supports_net_wm_hint (screen,
373 gdk_atom_intern_static_string ("_NET_WM_STATE_FOCUSED")))
374 toplevel->have_focused = TRUE;
376 /* When have_sticky is turned on, we have to check the DESKTOP property
379 if (toplevel->have_sticky && !had_sticky)
380 gdk_check_wm_desktop_changed (window);
382 do_net_wm_state_changes (window);
386 get_event_xwindow (XEvent *xevent)
390 switch (xevent->type)
393 xwindow = xevent->xdestroywindow.window;
396 xwindow = xevent->xunmap.window;
399 xwindow = xevent->xmap.window;
401 case ConfigureNotify:
402 xwindow = xevent->xconfigure.window;
405 xwindow = xevent->xreparent.window;
408 xwindow = xevent->xgravity.window;
410 case CirculateNotify:
411 xwindow = xevent->xcirculate.window;
414 xwindow = xevent->xany.window;
421 gdk_x11_display_translate_event (GdkEventTranslator *translator,
428 gboolean is_substructure;
429 GdkWindowImplX11 *window_impl = NULL;
430 GdkScreen *screen = NULL;
431 GdkX11Screen *x11_screen = NULL;
432 GdkToplevelX11 *toplevel = NULL;
433 GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
436 /* Find the GdkWindow that this event relates to. If that's
437 * not the same as the window that the event was sent to,
438 * we are getting an event from SubstructureNotifyMask.
439 * We ignore such events for internal operation, but we
440 * need to report them to the application because of
441 * GDK_SUBSTRUCTURE_MASK (which should be removed at next
442 * opportunity.) The most likely reason for getting these
443 * events is when we are used in the Metacity or Mutter
446 xwindow = get_event_xwindow (xevent);
447 is_substructure = xwindow != xevent->xany.window;
449 window = gdk_x11_window_lookup_for_display (display, xwindow);
452 /* We may receive events such as NoExpose/GraphicsExpose
453 * and ShmCompletion for pixmaps
455 if (!GDK_IS_WINDOW (window))
458 screen = GDK_WINDOW_SCREEN (window);
459 x11_screen = GDK_X11_SCREEN (screen);
460 toplevel = _gdk_x11_window_get_toplevel (window);
461 window_impl = GDK_WINDOW_IMPL_X11 (window->impl);
463 g_object_ref (window);
466 event->any.window = window;
467 event->any.send_event = xevent->xany.send_event ? TRUE : FALSE;
469 if (window && GDK_WINDOW_DESTROYED (window))
471 if (xevent->type != DestroyNotify)
478 if (xevent->type == DestroyNotify && !is_substructure)
482 n = gdk_display_get_n_screens (display);
483 for (i = 0; i < n; i++)
485 screen = gdk_display_get_screen (display, i);
486 x11_screen = GDK_X11_SCREEN (screen);
488 if (x11_screen->wmspec_check_window == xevent->xdestroywindow.window)
490 x11_screen->wmspec_check_window = None;
491 x11_screen->last_wmspec_check_time = 0;
492 g_free (x11_screen->window_manager_name);
493 x11_screen->window_manager_name = g_strdup ("unknown");
495 /* careful, reentrancy */
496 _gdk_x11_screen_window_manager_changed (screen);
504 /* We do a "manual" conversion of the XEvent to a
505 * GdkEvent. The structures are mostly the same so
506 * the conversion is fairly straightforward. We also
507 * optionally print debugging info regarding events
513 switch (xevent->type)
517 g_message ("keymap notify"));
519 /* Not currently handled */
525 g_message ("expose:\t\twindow: %ld %d x,y: %d %d w,h: %d %d%s",
526 xevent->xexpose.window, xevent->xexpose.count,
527 xevent->xexpose.x, xevent->xexpose.y,
528 xevent->xexpose.width, xevent->xexpose.height,
529 event->any.send_event ? " (send)" : ""));
538 GdkRectangle expose_rect;
540 expose_rect.x = xevent->xexpose.x;
541 expose_rect.y = xevent->xexpose.y;
542 expose_rect.width = xevent->xexpose.width;
543 expose_rect.height = xevent->xexpose.height;
545 _gdk_x11_window_process_expose (window, xevent->xexpose.serial, &expose_rect);
553 GdkRectangle expose_rect;
556 g_message ("graphics expose:\tdrawable: %ld",
557 xevent->xgraphicsexpose.drawable));
565 expose_rect.x = xevent->xgraphicsexpose.x;
566 expose_rect.y = xevent->xgraphicsexpose.y;
567 expose_rect.width = xevent->xgraphicsexpose.width;
568 expose_rect.height = xevent->xgraphicsexpose.height;
570 _gdk_x11_window_process_expose (window, xevent->xgraphicsexpose.serial, &expose_rect);
575 case VisibilityNotify:
576 #ifdef G_ENABLE_DEBUG
577 if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
578 switch (xevent->xvisibility.state)
580 case VisibilityFullyObscured:
581 g_message ("visibility notify:\twindow: %ld none",
582 xevent->xvisibility.window);
584 case VisibilityPartiallyObscured:
585 g_message ("visibility notify:\twindow: %ld partial",
586 xevent->xvisibility.window);
588 case VisibilityUnobscured:
589 g_message ("visibility notify:\twindow: %ld full",
590 xevent->xvisibility.window);
593 #endif /* G_ENABLE_DEBUG */
601 event->visibility.type = GDK_VISIBILITY_NOTIFY;
602 event->visibility.window = window;
604 switch (xevent->xvisibility.state)
606 case VisibilityFullyObscured:
607 event->visibility.state = GDK_VISIBILITY_FULLY_OBSCURED;
610 case VisibilityPartiallyObscured:
611 event->visibility.state = GDK_VISIBILITY_PARTIAL;
614 case VisibilityUnobscured:
615 event->visibility.state = GDK_VISIBILITY_UNOBSCURED;
623 g_message ("create notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d parent: %ld ovr: %d",
624 xevent->xcreatewindow.window,
625 xevent->xcreatewindow.x,
626 xevent->xcreatewindow.y,
627 xevent->xcreatewindow.width,
628 xevent->xcreatewindow.height,
629 xevent->xcreatewindow.border_width,
630 xevent->xcreatewindow.parent,
631 xevent->xcreatewindow.override_redirect));
632 /* not really handled */
637 g_message ("destroy notify:\twindow: %ld",
638 xevent->xdestroywindow.window));
640 if (!is_substructure)
642 event->any.type = GDK_DESTROY;
643 event->any.window = window;
645 return_val = window && !GDK_WINDOW_DESTROYED (window);
647 if (window && GDK_WINDOW_XID (window) != x11_screen->xroot_window)
648 gdk_window_destroy_notify (window);
657 g_message ("unmap notify:\t\twindow: %ld",
658 xevent->xmap.window));
660 event->any.type = GDK_UNMAP;
661 event->any.window = window;
663 if (window && !is_substructure)
665 /* If the WM supports the _NET_WM_STATE_HIDDEN hint, we do not want to
666 * interpret UnmapNotify events as implying iconic state.
667 * http://bugzilla.gnome.org/show_bug.cgi?id=590726.
670 !gdk_x11_screen_supports_net_wm_hint (screen,
671 gdk_atom_intern_static_string ("_NET_WM_STATE_HIDDEN")))
673 /* If we are shown (not withdrawn) and get an unmap, it means we were
674 * iconified in the X sense. If we are withdrawn, and get an unmap, it
675 * means we hid the window ourselves, so we will have already flipped
676 * the iconified bit off.
678 if (GDK_WINDOW_IS_MAPPED (window))
679 gdk_synthesize_window_state (window,
681 GDK_WINDOW_STATE_ICONIFIED);
684 if (window_impl->toplevel &&
685 window_impl->toplevel->frame_pending)
687 window_impl->toplevel->frame_pending = FALSE;
688 gdk_frame_clock_thaw (gdk_window_get_frame_clock (event->any.window));
692 gdk_window_freeze_toplevel_updates_libgtk_only (window);
694 _gdk_x11_window_grab_check_unmap (window, xevent->xany.serial);
701 g_message ("map notify:\t\twindow: %ld",
702 xevent->xmap.window));
704 event->any.type = GDK_MAP;
705 event->any.window = window;
707 if (window && !is_substructure)
709 /* Unset iconified if it was set */
710 if (window->state & GDK_WINDOW_STATE_ICONIFIED)
711 gdk_synthesize_window_state (window,
712 GDK_WINDOW_STATE_ICONIFIED,
716 gdk_window_thaw_toplevel_updates_libgtk_only (window);
723 g_message ("reparent notify:\twindow: %ld x,y: %d %d parent: %ld ovr: %d",
724 xevent->xreparent.window,
727 xevent->xreparent.parent,
728 xevent->xreparent.override_redirect));
730 /* Not currently handled */
734 case ConfigureNotify:
736 g_message ("configure notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d above: %ld ovr: %d%s",
737 xevent->xconfigure.window,
738 xevent->xconfigure.x,
739 xevent->xconfigure.y,
740 xevent->xconfigure.width,
741 xevent->xconfigure.height,
742 xevent->xconfigure.border_width,
743 xevent->xconfigure.above,
744 xevent->xconfigure.override_redirect,
747 : window->window_type == GDK_WINDOW_CHILD
748 ? " (discarding child)"
749 : xevent->xconfigure.event != xevent->xconfigure.window
750 ? " (discarding substructure)"
752 if (window && GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
754 window->width = xevent->xconfigure.width;
755 window->height = xevent->xconfigure.height;
757 _gdk_window_update_size (window);
758 _gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
759 _gdk_x11_screen_size_changed (screen, xevent);
763 if (!is_substructure && toplevel && display_x11->use_sync && toplevel->pending_counter_value != 0)
765 toplevel->configure_counter_value = toplevel->pending_counter_value;
766 toplevel->pending_counter_value = 0;
771 xevent->xconfigure.event != xevent->xconfigure.window ||
772 GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD ||
773 GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
777 event->configure.type = GDK_CONFIGURE;
778 event->configure.window = window;
779 event->configure.width = xevent->xconfigure.width;
780 event->configure.height = xevent->xconfigure.height;
782 if (!xevent->xconfigure.send_event &&
783 !xevent->xconfigure.override_redirect &&
784 !GDK_WINDOW_DESTROYED (window))
788 Window child_window = 0;
790 gdk_x11_display_error_trap_push (display);
791 if (XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
792 GDK_WINDOW_XID (window),
793 x11_screen->xroot_window,
798 event->configure.x = tx;
799 event->configure.y = ty;
801 gdk_x11_display_error_trap_pop_ignored (display);
805 event->configure.x = xevent->xconfigure.x;
806 event->configure.y = xevent->xconfigure.y;
808 if (!is_substructure)
810 window->x = event->configure.x;
811 window->y = event->configure.y;
812 window->width = xevent->xconfigure.width;
813 window->height = xevent->xconfigure.height;
815 _gdk_window_update_size (window);
816 _gdk_x11_window_update_size (GDK_WINDOW_IMPL_X11 (window->impl));
818 if (window->resize_count >= 1)
820 window->resize_count -= 1;
822 if (window->resize_count == 0)
823 _gdk_x11_moveresize_configure_done (display, window);
831 g_message ("property notify:\twindow: %ld, atom(%ld): %s%s%s",
832 xevent->xproperty.window,
833 xevent->xproperty.atom,
835 gdk_x11_get_xatom_name_for_display (display, xevent->xproperty.atom),
844 /* We compare with the serial of the last time we mapped the
845 * window to avoid refetching properties that we set ourselves
848 xevent->xproperty.serial >= toplevel->map_serial)
850 if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"))
851 gdk_check_wm_state_changed (window);
853 if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"))
854 gdk_check_wm_desktop_changed (window);
857 if (window->event_mask & GDK_PROPERTY_CHANGE_MASK)
859 event->property.type = GDK_PROPERTY_NOTIFY;
860 event->property.window = window;
861 event->property.atom = gdk_x11_xatom_to_atom_for_display (display, xevent->xproperty.atom);
862 event->property.time = xevent->xproperty.time;
863 event->property.state = xevent->xproperty.state;
872 g_message ("selection clear:\twindow: %ld",
873 xevent->xproperty.window));
875 if (_gdk_x11_selection_filter_clear_event (&xevent->xselectionclear))
877 event->selection.type = GDK_SELECTION_CLEAR;
878 event->selection.window = window;
879 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionclear.selection);
880 event->selection.time = xevent->xselectionclear.time;
887 case SelectionRequest:
889 g_message ("selection request:\twindow: %ld",
890 xevent->xproperty.window));
892 event->selection.type = GDK_SELECTION_REQUEST;
893 event->selection.window = window;
894 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.selection);
895 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.target);
896 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.property);
897 if (xevent->xselectionrequest.requestor != None)
898 event->selection.requestor = gdk_x11_window_foreign_new_for_display (display,
899 xevent->xselectionrequest.requestor);
901 event->selection.requestor = NULL;
902 event->selection.time = xevent->xselectionrequest.time;
906 case SelectionNotify:
908 g_message ("selection notify:\twindow: %ld",
909 xevent->xproperty.window));
911 event->selection.type = GDK_SELECTION_NOTIFY;
912 event->selection.window = window;
913 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.selection);
914 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.target);
915 if (xevent->xselection.property == None)
916 event->selection.property = GDK_NONE;
918 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.property);
919 event->selection.time = xevent->xselection.time;
925 g_message ("colormap notify:\twindow: %ld",
926 xevent->xcolormap.window));
928 /* Not currently handled */
934 g_message ("client message:\twindow: %ld",
935 xevent->xclient.window));
937 /* Not currently handled */
943 g_message ("mapping notify"));
945 /* Let XLib know that there is a new keyboard mapping.
947 XRefreshKeyboardMapping (&xevent->xmapping);
948 _gdk_x11_keymap_keys_changed (display);
954 if (xevent->type - display_x11->xfixes_event_base == XFixesSelectionNotify)
956 XFixesSelectionNotifyEvent *selection_notify = (XFixesSelectionNotifyEvent *)xevent;
958 _gdk_x11_screen_process_owner_change (screen, xevent);
960 event->owner_change.type = GDK_OWNER_CHANGE;
961 event->owner_change.window = window;
962 if (selection_notify->owner != None)
963 event->owner_change.owner = gdk_x11_window_foreign_new_for_display (display,
964 selection_notify->owner);
966 event->owner_change.owner = NULL;
967 event->owner_change.reason = selection_notify->subtype;
968 event->owner_change.selection =
969 gdk_x11_xatom_to_atom_for_display (display,
970 selection_notify->selection);
971 event->owner_change.time = selection_notify->timestamp;
972 event->owner_change.selection_time = selection_notify->selection_timestamp;
979 if (xevent->type - display_x11->xrandr_event_base == RRScreenChangeNotify ||
980 xevent->type - display_x11->xrandr_event_base == RRNotify)
983 _gdk_x11_screen_size_changed (screen, xevent);
987 #if defined(HAVE_XCOMPOSITE) && defined (HAVE_XDAMAGE) && defined (HAVE_XFIXES)
988 if (display_x11->have_xdamage && window && window->composited &&
989 xevent->type == display_x11->xdamage_event_base + XDamageNotify &&
990 ((XDamageNotifyEvent *) xevent)->damage == window_impl->damage)
992 XDamageNotifyEvent *damage_event = (XDamageNotifyEvent *) xevent;
993 XserverRegion repair;
996 rect.x = window->x + damage_event->area.x;
997 rect.y = window->y + damage_event->area.y;
998 rect.width = damage_event->area.width;
999 rect.height = damage_event->area.height;
1001 repair = XFixesCreateRegion (display_x11->xdisplay,
1002 &damage_event->area, 1);
1003 XDamageSubtract (display_x11->xdisplay,
1004 window_impl->damage,
1006 XFixesDestroyRegion (display_x11->xdisplay, repair);
1008 if (window->parent != NULL)
1009 _gdk_x11_window_process_expose (window->parent,
1010 damage_event->serial, &rect);
1017 if (xevent->type == display_x11->xkb_event_type)
1019 XkbEvent *xkb_event = (XkbEvent *) xevent;
1021 switch (xkb_event->any.xkb_type)
1023 case XkbNewKeyboardNotify:
1025 _gdk_x11_keymap_keys_changed (display);
1030 case XkbStateNotify:
1031 _gdk_x11_keymap_state_changed (display, xevent);
1043 if (event->any.window)
1044 g_object_ref (event->any.window);
1048 /* Mark this event as having no resources to be freed */
1049 event->any.window = NULL;
1050 event->any.type = GDK_NOTHING;
1054 g_object_unref (window);
1059 static GdkFrameTimings *
1060 find_frame_timings (GdkFrameClock *clock,
1063 GdkFrameHistory *history = gdk_frame_clock_get_history (clock);
1064 gint64 start_frame, end_frame, i;
1066 start_frame = gdk_frame_history_get_start (history);
1067 end_frame = gdk_frame_history_get_frame_counter (history);
1068 for (i = end_frame; i >= start_frame; i--)
1070 GdkFrameTimings *timings = gdk_frame_history_get_timings (history, i);
1072 if (gdk_frame_timings_get_cookie (timings) == serial)
1080 _gdk_wm_protocols_filter (GdkXEvent *xev,
1084 XEvent *xevent = (XEvent *)xev;
1085 GdkWindow *win = event->any.window;
1086 GdkDisplay *display;
1089 if (!GDK_IS_X11_WINDOW (win))
1090 return GDK_FILTER_CONTINUE;
1092 if (xevent->type != ClientMessage)
1093 return GDK_FILTER_CONTINUE;
1095 display = GDK_WINDOW_DISPLAY (win);
1097 /* This isn't actually WM_PROTOCOLS because that wouldn't leave enough space
1098 * in the message for everything that gets stuffed in */
1099 if (xevent->xclient.message_type == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_FRAME_DRAWN"))
1101 GdkWindowImplX11 *window_impl;
1102 window_impl = GDK_WINDOW_IMPL_X11 (event->any.window->impl);
1103 if (window_impl->toplevel)
1105 guint32 d0 = xevent->xclient.data.l[0];
1106 guint32 d1 = xevent->xclient.data.l[1];
1107 guint32 d2 = xevent->xclient.data.l[2];
1108 guint32 d3 = xevent->xclient.data.l[3];
1110 guint64 serial = ((guint64)d0 << 32) | d1;
1112 GdkFrameClock *clock = gdk_window_get_frame_clock (event->any.window);
1113 GdkFrameTimings *timings = find_frame_timings (clock, serial);
1116 gdk_frame_timings_set_drawn_time (timings, ((guint64)d2 << 32) | d3);
1118 if (window_impl->toplevel->frame_pending)
1120 window_impl->toplevel->frame_pending = FALSE;
1121 gdk_frame_clock_thaw (clock);
1125 return GDK_FILTER_REMOVE;
1128 if (xevent->xclient.message_type == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_FRAME_TIMINGS"))
1130 GdkWindowImplX11 *window_impl;
1131 window_impl = GDK_WINDOW_IMPL_X11 (event->any.window->impl);
1132 if (window_impl->toplevel)
1134 guint32 d0 = xevent->xclient.data.l[0];
1135 guint32 d1 = xevent->xclient.data.l[1];
1136 guint32 d2 = xevent->xclient.data.l[2];
1137 guint32 d3 = xevent->xclient.data.l[3];
1139 guint64 serial = ((guint64)d0 << 32) | d1;
1141 GdkFrameClock *clock = gdk_window_get_frame_clock (event->any.window);
1142 GdkFrameTimings *timings = find_frame_timings (clock, serial);
1146 gint64 drawn_time = gdk_frame_timings_get_drawn_time (timings);
1147 gint32 presentation_time_offset = (gint32)d2;
1148 gint32 refresh_interval = d3;
1150 if (drawn_time && presentation_time_offset)
1151 gdk_frame_timings_set_presentation_time (timings,
1152 drawn_time + presentation_time_offset);
1154 if (refresh_interval)
1155 gdk_frame_timings_set_refresh_interval (timings, refresh_interval);
1157 gdk_frame_timings_set_complete (timings, TRUE);
1158 #ifdef G_ENABLE_DEBUG
1159 if ((_gdk_debug_flags & GDK_DEBUG_FRAMES) != 0)
1160 _gdk_frame_history_debug_print (gdk_frame_clock_get_history (clock),
1162 #endif /* G_ENABLE_DEBUG */
1167 if (xevent->xclient.message_type != gdk_x11_get_xatom_by_name_for_display (display, "WM_PROTOCOLS"))
1168 return GDK_FILTER_CONTINUE;
1170 atom = (Atom) xevent->xclient.data.l[0];
1172 if (atom == gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW"))
1174 /* The delete window request specifies a window
1175 * to delete. We don't actually destroy the
1176 * window because "it is only a request". (The
1177 * window might contain vital data that the
1178 * program does not want destroyed). Instead
1179 * the event is passed along to the program,
1180 * which should then destroy the window.
1183 g_message ("delete window:\t\twindow: %ld",
1184 xevent->xclient.window));
1186 event->any.type = GDK_DELETE;
1188 gdk_x11_window_set_user_time (win, xevent->xclient.data.l[1]);
1190 return GDK_FILTER_TRANSLATE;
1192 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS"))
1194 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (event->any.window);
1196 /* There is no way of knowing reliably whether we are viewable;
1197 * so trap errors asynchronously around the XSetInputFocus call
1199 if (toplevel && win->accept_focus)
1201 gdk_x11_display_error_trap_push (display);
1202 XSetInputFocus (GDK_DISPLAY_XDISPLAY (display),
1203 toplevel->focus_window,
1205 xevent->xclient.data.l[1]);
1206 gdk_x11_display_error_trap_pop_ignored (display);
1209 return GDK_FILTER_REMOVE;
1211 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING") &&
1212 !_gdk_x11_display_is_root_window (display,
1213 xevent->xclient.window))
1215 XClientMessageEvent xclient = xevent->xclient;
1217 xclient.window = GDK_WINDOW_XROOTWIN (win);
1218 XSendEvent (GDK_WINDOW_XDISPLAY (win),
1221 SubstructureRedirectMask | SubstructureNotifyMask, (XEvent *)&xclient);
1223 return GDK_FILTER_REMOVE;
1225 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_SYNC_REQUEST") &&
1226 GDK_X11_DISPLAY (display)->use_sync)
1228 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (event->any.window);
1232 toplevel->pending_counter_value = xevent->xclient.data.l[2] + ((gint64)xevent->xclient.data.l[3] << 32);
1235 return GDK_FILTER_REMOVE;
1238 return GDK_FILTER_CONTINUE;
1242 gdk_event_init (GdkDisplay *display)
1244 GdkX11Display *display_x11;
1245 GdkDeviceManager *device_manager;
1247 display_x11 = GDK_X11_DISPLAY (display);
1248 display_x11->event_source = gdk_x11_event_source_new (display);
1250 gdk_x11_event_source_add_translator ((GdkEventSource *) display_x11->event_source,
1251 GDK_EVENT_TRANSLATOR (display));
1253 device_manager = gdk_display_get_device_manager (display);
1254 gdk_x11_event_source_add_translator ((GdkEventSource *) display_x11->event_source,
1255 GDK_EVENT_TRANSLATOR (device_manager));
1259 gdk_x11_display_init_input (GdkDisplay *display)
1261 GdkX11Display *display_x11;
1262 GdkDeviceManager *device_manager;
1266 display_x11 = GDK_X11_DISPLAY (display);
1267 device_manager = gdk_display_get_device_manager (display);
1269 /* For backwards compatibility, just add
1270 * floating devices that are not keyboards.
1272 list = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING);
1274 for (l = list; l; l = l->next)
1278 if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
1281 display_x11->input_devices = g_list_prepend (display_x11->input_devices,
1282 g_object_ref (l->data));
1287 /* Now set "core" pointer to the first
1288 * master device that is a pointer.
1290 list = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
1292 for (l = list; l; l = l->next)
1296 if (gdk_device_get_source (device) != GDK_SOURCE_MOUSE)
1299 display->core_pointer = device;
1303 /* Add the core pointer to the devices list */
1304 display_x11->input_devices = g_list_prepend (display_x11->input_devices,
1305 g_object_ref (display->core_pointer));
1311 set_sm_client_id (GdkDisplay *display,
1312 const gchar *sm_client_id)
1314 GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
1316 if (gdk_display_is_closed (display))
1319 if (sm_client_id && strcmp (sm_client_id, ""))
1320 XChangeProperty (display_x11->xdisplay, display_x11->leader_window,
1321 gdk_x11_get_xatom_by_name_for_display (display, "SM_CLIENT_ID"),
1322 XA_STRING, 8, PropModeReplace, (guchar *)sm_client_id,
1323 strlen (sm_client_id));
1325 XDeleteProperty (display_x11->xdisplay, display_x11->leader_window,
1326 gdk_x11_get_xatom_by_name_for_display (display, "SM_CLIENT_ID"));
1330 _gdk_x11_display_open (const gchar *display_name)
1333 GdkDisplay *display;
1334 GdkX11Display *display_x11;
1339 XClassHint *class_hint;
1345 xdisplay = XOpenDisplay (display_name);
1349 display = g_object_new (GDK_TYPE_X11_DISPLAY, NULL);
1350 display_x11 = GDK_X11_DISPLAY (display);
1352 display_x11->xdisplay = xdisplay;
1354 /* Set up handlers for Xlib internal connections */
1355 XAddConnectionWatch (xdisplay, gdk_internal_connection_watch, NULL);
1357 _gdk_x11_precache_atoms (display, precache_atoms, G_N_ELEMENTS (precache_atoms));
1359 /* RandR must be initialized before we initialize the screens */
1360 display_x11->have_randr12 = FALSE;
1361 display_x11->have_randr13 = FALSE;
1363 if (XRRQueryExtension (display_x11->xdisplay,
1364 &display_x11->xrandr_event_base, &ignore))
1368 XRRQueryVersion (display_x11->xdisplay, &major, &minor);
1370 if ((major == 1 && minor >= 2) || major > 1) {
1371 display_x11->have_randr12 = TRUE;
1372 if (minor >= 3 || major > 1)
1373 display_x11->have_randr13 = TRUE;
1376 gdk_x11_register_standard_event_type (display, display_x11->xrandr_event_base, RRNumberEvents);
1380 /* initialize the display's screens */
1381 display_x11->screens = g_new (GdkScreen *, ScreenCount (display_x11->xdisplay));
1382 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1383 display_x11->screens[i] = _gdk_x11_screen_new (display, i);
1385 /* We need to initialize events after we have the screen
1386 * structures in places
1388 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1389 _gdk_x11_screen_init_events (display_x11->screens[i]);
1391 /*set the default screen */
1392 display_x11->default_screen = display_x11->screens[DefaultScreen (display_x11->xdisplay)];
1394 display->device_manager = _gdk_x11_device_manager_new (display);
1396 gdk_event_init (display);
1398 attr.window_type = GDK_WINDOW_TOPLEVEL;
1399 attr.wclass = GDK_INPUT_OUTPUT;
1404 attr.event_mask = 0;
1406 display_x11->leader_gdk_window = gdk_window_new (GDK_X11_SCREEN (display_x11->default_screen)->root_window,
1407 &attr, GDK_WA_X | GDK_WA_Y);
1408 (_gdk_x11_window_get_toplevel (display_x11->leader_gdk_window))->is_leader = TRUE;
1410 display_x11->leader_window = GDK_WINDOW_XID (display_x11->leader_gdk_window);
1412 display_x11->leader_window_title_set = FALSE;
1415 if (XFixesQueryExtension (display_x11->xdisplay,
1416 &display_x11->xfixes_event_base,
1419 display_x11->have_xfixes = TRUE;
1421 gdk_x11_register_standard_event_type (display,
1422 display_x11->xfixes_event_base,
1423 XFixesNumberEvents);
1427 display_x11->have_xfixes = FALSE;
1429 #ifdef HAVE_XCOMPOSITE
1430 if (XCompositeQueryExtension (display_x11->xdisplay,
1435 XCompositeQueryVersion (display_x11->xdisplay, &major, &minor);
1437 /* Prior to Composite version 0.4, composited windows clipped their
1438 * parents, so you had to use IncludeInferiors to draw to the parent
1439 * This isn't useful for our purposes, so require 0.4
1441 display_x11->have_xcomposite = major > 0 || (major == 0 && minor >= 4);
1445 display_x11->have_xcomposite = FALSE;
1448 if (XDamageQueryExtension (display_x11->xdisplay,
1449 &display_x11->xdamage_event_base,
1452 display_x11->have_xdamage = TRUE;
1454 gdk_x11_register_standard_event_type (display,
1455 display_x11->xdamage_event_base,
1456 XDamageNumberEvents);
1460 display_x11->have_xdamage = FALSE;
1462 display_x11->have_shapes = FALSE;
1463 display_x11->have_input_shapes = FALSE;
1465 if (XShapeQueryExtension (GDK_DISPLAY_XDISPLAY (display), &display_x11->shape_event_base, &ignore))
1467 display_x11->have_shapes = TRUE;
1469 if (XShapeQueryVersion (GDK_DISPLAY_XDISPLAY (display), &maj, &min))
1470 display_x11->have_input_shapes = (maj == 1 && min >= 1);
1474 display_x11->trusted_client = TRUE;
1477 int rootx, rooty, winx, winy;
1480 gdk_x11_display_error_trap_push (display);
1481 XQueryPointer (display_x11->xdisplay,
1482 GDK_X11_SCREEN (display_x11->default_screen)->xroot_window,
1483 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
1484 if (G_UNLIKELY (gdk_x11_display_error_trap_pop (display) == BadWindow))
1486 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));
1487 display_x11->trusted_client = FALSE;
1491 if (g_getenv ("GDK_SYNCHRONIZE"))
1492 XSynchronize (display_x11->xdisplay, True);
1494 class_hint = XAllocClassHint();
1495 class_hint->res_name = (char *) g_get_prgname ();
1496 class_hint->res_class = (char *)gdk_get_program_class ();
1498 /* XmbSetWMProperties sets the RESOURCE_NAME environment variable
1499 * from argv[0], so we just synthesize an argument array here.
1502 argv[0] = (char *) g_get_prgname ();
1504 XmbSetWMProperties (display_x11->xdisplay,
1505 display_x11->leader_window,
1506 NULL, NULL, argv, argc, NULL, NULL,
1510 if (gdk_sm_client_id)
1511 set_sm_client_id (display, gdk_sm_client_id);
1514 XChangeProperty (display_x11->xdisplay,
1515 display_x11->leader_window,
1516 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PID"),
1517 XA_CARDINAL, 32, PropModeReplace, (guchar *) & pid, 1);
1519 /* We don't yet know a valid time. */
1520 display_x11->user_time = 0;
1524 gint xkb_major = XkbMajorVersion;
1525 gint xkb_minor = XkbMinorVersion;
1526 if (XkbLibraryVersion (&xkb_major, &xkb_minor))
1528 xkb_major = XkbMajorVersion;
1529 xkb_minor = XkbMinorVersion;
1531 if (XkbQueryExtension (display_x11->xdisplay,
1532 NULL, &display_x11->xkb_event_type, NULL,
1533 &xkb_major, &xkb_minor))
1535 Bool detectable_autorepeat_supported;
1537 display_x11->use_xkb = TRUE;
1539 XkbSelectEvents (display_x11->xdisplay,
1541 XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask,
1542 XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask);
1544 /* keep this in sync with _gdk_x11_keymap_state_changed() */
1545 XkbSelectEventDetails (display_x11->xdisplay,
1546 XkbUseCoreKbd, XkbStateNotify,
1547 XkbAllStateComponentsMask,
1548 XkbModifierStateMask|XkbGroupStateMask);
1550 XkbSetDetectableAutoRepeat (display_x11->xdisplay,
1552 &detectable_autorepeat_supported);
1554 GDK_NOTE (MISC, g_message ("Detectable autorepeat %s.",
1555 detectable_autorepeat_supported ?
1556 "supported" : "not supported"));
1558 display_x11->have_xkb_autorepeat = detectable_autorepeat_supported;
1564 display_x11->use_sync = FALSE;
1568 int error_base, event_base;
1570 if (XSyncQueryExtension (display_x11->xdisplay,
1571 &event_base, &error_base) &&
1572 XSyncInitialize (display_x11->xdisplay,
1574 display_x11->use_sync = TRUE;
1578 gdk_x11_display_init_input (display);
1580 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1581 _gdk_x11_screen_setup (display_x11->screens[i]);
1583 g_signal_emit_by_name (display, "opened");
1589 * XLib internal connection handling
1591 typedef struct _GdkInternalConnection GdkInternalConnection;
1593 struct _GdkInternalConnection
1601 process_internal_connection (GIOChannel *gioc,
1605 GdkInternalConnection *connection = (GdkInternalConnection *)data;
1607 gdk_threads_enter ();
1609 XProcessInternalConnection ((Display*)connection->display, connection->fd);
1611 gdk_threads_leave ();
1617 gdk_x11_display_get_next_serial (GdkDisplay *display)
1619 return NextRequest (GDK_DISPLAY_XDISPLAY (display));
1623 static GdkInternalConnection *
1624 gdk_add_connection_handler (Display *display,
1627 GIOChannel *io_channel;
1628 GdkInternalConnection *connection;
1630 connection = g_new (GdkInternalConnection, 1);
1632 connection->fd = fd;
1633 connection->display = display;
1635 io_channel = g_io_channel_unix_new (fd);
1637 connection->source = g_io_create_watch (io_channel, G_IO_IN);
1638 g_source_set_callback (connection->source,
1639 (GSourceFunc)process_internal_connection, connection, NULL);
1640 g_source_attach (connection->source, NULL);
1642 g_io_channel_unref (io_channel);
1648 gdk_remove_connection_handler (GdkInternalConnection *connection)
1650 g_source_destroy (connection->source);
1651 g_free (connection);
1655 gdk_internal_connection_watch (Display *display,
1659 XPointer *watch_data)
1662 *watch_data = (XPointer)gdk_add_connection_handler (display, fd);
1664 gdk_remove_connection_handler ((GdkInternalConnection *)*watch_data);
1667 static const gchar *
1668 gdk_x11_display_get_name (GdkDisplay *display)
1670 return (gchar *) DisplayString (GDK_X11_DISPLAY (display)->xdisplay);
1674 gdk_x11_display_get_n_screens (GdkDisplay *display)
1676 return ScreenCount (GDK_X11_DISPLAY (display)->xdisplay);
1680 gdk_x11_display_get_screen (GdkDisplay *display,
1683 g_return_val_if_fail (ScreenCount (GDK_X11_DISPLAY (display)->xdisplay) > screen_num, NULL);
1685 return GDK_X11_DISPLAY (display)->screens[screen_num];
1689 gdk_x11_display_get_default_screen (GdkDisplay *display)
1691 return GDK_X11_DISPLAY (display)->default_screen;
1695 _gdk_x11_display_is_root_window (GdkDisplay *display,
1696 Window xroot_window)
1698 GdkX11Display *display_x11;
1701 display_x11 = GDK_X11_DISPLAY (display);
1703 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1705 if (GDK_SCREEN_XROOTWIN (display_x11->screens[i]) == xroot_window)
1711 struct XPointerUngrabInfo {
1712 GdkDisplay *display;
1717 device_grab_update_callback (GdkDisplay *display,
1721 GdkPointerWindowInfo *pointer_info;
1722 GdkDevice *device = data;
1724 pointer_info = _gdk_display_get_pointer_info (display, device);
1725 _gdk_display_device_grab_update (display, device,
1726 pointer_info->last_slave, serial);
1729 #define XSERVER_TIME_IS_LATER(time1, time2) \
1730 ( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) || \
1731 (( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 )) \
1735 _gdk_x11_display_update_grab_info (GdkDisplay *display,
1739 if (status == GrabSuccess)
1740 _gdk_x11_roundtrip_async (display, device_grab_update_callback, device);
1744 _gdk_x11_display_update_grab_info_ungrab (GdkDisplay *display,
1749 GdkDeviceGrabInfo *grab;
1751 XFlush (GDK_DISPLAY_XDISPLAY (display));
1753 grab = _gdk_display_get_last_device_grab (display, device);
1755 (time == GDK_CURRENT_TIME ||
1756 grab->time == GDK_CURRENT_TIME ||
1757 !XSERVER_TIME_IS_LATER (grab->time, time)))
1759 grab->serial_end = serial;
1760 _gdk_x11_roundtrip_async (display, device_grab_update_callback, device);
1765 gdk_x11_display_beep (GdkDisplay *display)
1768 XkbBell (GDK_DISPLAY_XDISPLAY (display), None, 0, None);
1770 XBell (GDK_DISPLAY_XDISPLAY (display), 0);
1775 gdk_x11_display_sync (GdkDisplay *display)
1777 XSync (GDK_DISPLAY_XDISPLAY (display), False);
1781 gdk_x11_display_flush (GdkDisplay *display)
1783 if (!display->closed)
1784 XFlush (GDK_DISPLAY_XDISPLAY (display));
1788 gdk_x11_display_has_pending (GdkDisplay *display)
1790 return XPending (GDK_DISPLAY_XDISPLAY (display));
1794 gdk_x11_display_get_default_group (GdkDisplay *display)
1796 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1798 return GDK_X11_DISPLAY (display)->leader_gdk_window;
1802 * gdk_x11_display_grab:
1803 * @display: (type GdkX11Display): a #GdkDisplay
1805 * Call XGrabServer() on @display.
1806 * To ungrab the display again, use gdk_x11_display_ungrab().
1808 * gdk_x11_display_grab()/gdk_x11_display_ungrab() calls can be nested.
1813 gdk_x11_display_grab (GdkDisplay *display)
1815 GdkX11Display *display_x11;
1817 g_return_if_fail (GDK_IS_DISPLAY (display));
1819 display_x11 = GDK_X11_DISPLAY (display);
1821 if (display_x11->grab_count == 0)
1822 XGrabServer (display_x11->xdisplay);
1823 display_x11->grab_count++;
1827 * gdk_x11_display_ungrab:
1828 * @display: (type GdkX11Display): a #GdkDisplay
1830 * Ungrab @display after it has been grabbed with
1831 * gdk_x11_display_grab().
1836 gdk_x11_display_ungrab (GdkDisplay *display)
1838 GdkX11Display *display_x11;
1840 g_return_if_fail (GDK_IS_DISPLAY (display));
1842 display_x11 = GDK_X11_DISPLAY (display);;
1843 g_return_if_fail (display_x11->grab_count > 0);
1845 display_x11->grab_count--;
1846 if (display_x11->grab_count == 0)
1848 XUngrabServer (display_x11->xdisplay);
1849 XFlush (display_x11->xdisplay);
1854 gdk_x11_display_dispose (GObject *object)
1856 GdkDisplay *display = GDK_DISPLAY (object);
1857 GdkX11Display *display_x11 = GDK_X11_DISPLAY (object);
1860 _gdk_x11_display_manager_remove_display (gdk_display_manager_get (), display);
1862 g_list_foreach (display_x11->input_devices, (GFunc) g_object_run_dispose, NULL);
1864 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1865 _gdk_screen_close (display_x11->screens[i]);
1867 if (display_x11->event_source)
1869 g_source_destroy (display_x11->event_source);
1870 g_source_unref (display_x11->event_source);
1871 display_x11->event_source = NULL;
1874 G_OBJECT_CLASS (gdk_x11_display_parent_class)->dispose (object);
1878 gdk_x11_display_finalize (GObject *object)
1880 GdkX11Display *display_x11 = GDK_X11_DISPLAY (object);
1884 if (display_x11->keymap)
1885 g_object_unref (display_x11->keymap);
1887 /* Free motif Dnd */
1888 if (display_x11->motif_target_lists)
1890 for (i = 0; i < display_x11->motif_n_target_lists; i++)
1891 g_list_free (display_x11->motif_target_lists[i]);
1892 g_free (display_x11->motif_target_lists);
1895 _gdk_x11_cursor_display_finalize (GDK_DISPLAY (display_x11));
1897 /* Empty the event queue */
1898 _gdk_x11_display_free_translate_queue (GDK_DISPLAY (display_x11));
1900 /* Atom Hashtable */
1901 g_hash_table_destroy (display_x11->atom_from_virtual);
1902 g_hash_table_destroy (display_x11->atom_to_virtual);
1905 XDestroyWindow (display_x11->xdisplay, display_x11->leader_window);
1907 /* List of event window extraction functions */
1908 g_slist_foreach (display_x11->event_types, (GFunc)g_free, NULL);
1909 g_slist_free (display_x11->event_types);
1911 /* input GdkDevice list */
1912 g_list_free_full (display_x11->input_devices, g_object_unref);
1914 /* input GdkWindow list */
1915 g_list_free_full (display_x11->input_windows, g_free);
1917 /* Free all GdkScreens */
1918 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1919 g_object_unref (display_x11->screens[i]);
1920 g_free (display_x11->screens);
1922 g_free (display_x11->startup_notification_id);
1924 /* X ID hashtable */
1925 g_hash_table_destroy (display_x11->xid_ht);
1927 XCloseDisplay (display_x11->xdisplay);
1930 while (display_x11->error_traps != NULL)
1932 GdkErrorTrap *trap = display_x11->error_traps->data;
1934 display_x11->error_traps =
1935 g_slist_delete_link (display_x11->error_traps,
1936 display_x11->error_traps);
1938 if (trap->end_sequence == 0)
1939 g_warning ("Display finalized with an unpopped error trap");
1941 g_slice_free (GdkErrorTrap, trap);
1944 G_OBJECT_CLASS (gdk_x11_display_parent_class)->finalize (object);
1948 * gdk_x11_lookup_xdisplay:
1949 * @xdisplay: a pointer to an X Display
1951 * Find the #GdkDisplay corresponding to @display, if any exists.
1953 * Return value: (transfer none): the #GdkDisplay, if found, otherwise %NULL.
1958 gdk_x11_lookup_xdisplay (Display *xdisplay)
1961 GdkDisplay *display;
1965 list = gdk_display_manager_list_displays (gdk_display_manager_get ());
1967 for (l = list; l; l = l->next)
1969 if (GDK_DISPLAY_XDISPLAY (l->data) == xdisplay)
1976 g_slist_free (list);
1982 * _gdk_x11_display_screen_for_xrootwin:
1983 * @display: a #GdkDisplay
1984 * @xrootwin: window ID for one of of the screen's of the display.
1986 * Given the root window ID of one of the screen's of a #GdkDisplay,
1989 * Return value: (transfer none): the #GdkScreen corresponding to
1990 * @xrootwin, or %NULL.
1993 _gdk_x11_display_screen_for_xrootwin (GdkDisplay *display,
1998 for (i = 0; i < ScreenCount (GDK_X11_DISPLAY (display)->xdisplay); i++)
2000 GdkScreen *screen = gdk_display_get_screen (display, i);
2001 if (GDK_SCREEN_XROOTWIN (screen) == xrootwin)
2009 * gdk_x11_display_get_xdisplay:
2010 * @display: (type GdkX11Display): a #GdkDisplay
2012 * Returns the X display of a #GdkDisplay.
2014 * Returns: (transfer none): an X display
2019 gdk_x11_display_get_xdisplay (GdkDisplay *display)
2021 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
2022 return GDK_X11_DISPLAY (display)->xdisplay;
2026 _gdk_x11_display_make_default (GdkDisplay *display)
2028 GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
2029 const gchar *startup_id;
2031 g_free (display_x11->startup_notification_id);
2032 display_x11->startup_notification_id = NULL;
2034 startup_id = g_getenv ("DESKTOP_STARTUP_ID");
2035 if (startup_id && *startup_id != '\0')
2037 if (!g_utf8_validate (startup_id, -1, NULL))
2038 g_warning ("DESKTOP_STARTUP_ID contains invalid UTF-8");
2040 gdk_x11_display_set_startup_notification_id (display, startup_id);
2042 /* Clear the environment variable so it won't be inherited by
2043 * child processes and confuse things.
2045 g_unsetenv ("DESKTOP_STARTUP_ID");
2050 broadcast_xmessage (GdkDisplay *display,
2051 const char *message_type,
2052 const char *message_type_begin,
2053 const char *message)
2055 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
2056 GdkScreen *screen = gdk_display_get_default_screen (display);
2057 GdkWindow *root_window = gdk_screen_get_root_window (screen);
2058 Window xroot_window = GDK_WINDOW_XID (root_window);
2061 Atom type_atom_begin;
2064 if (!G_LIKELY (GDK_X11_DISPLAY (display)->trusted_client))
2068 XSetWindowAttributes attrs;
2070 attrs.override_redirect = True;
2071 attrs.event_mask = PropertyChangeMask | StructureNotifyMask;
2074 XCreateWindow (xdisplay,
2080 (Visual *)CopyFromParent,
2081 CWOverrideRedirect | CWEventMask,
2085 type_atom = gdk_x11_get_xatom_by_name_for_display (display,
2087 type_atom_begin = gdk_x11_get_xatom_by_name_for_display (display,
2088 message_type_begin);
2091 XClientMessageEvent xclient;
2093 const char *src_end;
2097 memset(&xclient, 0, sizeof (xclient));
2098 xclient.type = ClientMessage;
2099 xclient.message_type = type_atom_begin;
2100 xclient.display =xdisplay;
2101 xclient.window = xwindow;
2105 src_end = message + strlen (message) + 1; /* +1 to include nul byte */
2107 while (src != src_end)
2109 dest = &xclient.data.b[0];
2110 dest_end = dest + 20;
2112 while (dest != dest_end &&
2120 while (dest != dest_end)
2126 XSendEvent (xdisplay,
2130 (XEvent *)&xclient);
2132 xclient.message_type = type_atom;
2136 XDestroyWindow (xdisplay, xwindow);
2141 * gdk_x11_display_broadcast_startup_message:
2142 * @display: (type GdkX11Display): a #GdkDisplay
2143 * @message_type: startup notification message type ("new", "change",
2145 * @...: a list of key/value pairs (as strings), terminated by a
2146 * %NULL key. (A %NULL value for a key will cause that key to be
2147 * skipped in the output.)
2149 * Sends a startup notification message of type @message_type to
2152 * This is a convenience function for use by code that implements the
2153 * freedesktop startup notification specification. Applications should
2154 * not normally need to call it directly. See the <ulink
2155 * url="http://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt">Startup
2156 * Notification Protocol specification</ulink> for
2157 * definitions of the message types and keys that can be used.
2162 gdk_x11_display_broadcast_startup_message (GdkDisplay *display,
2163 const char *message_type,
2168 const char *key, *value, *p;
2170 message = g_string_new (message_type);
2171 g_string_append_c (message, ':');
2173 va_start (ap, message_type);
2174 while ((key = va_arg (ap, const char *)))
2176 value = va_arg (ap, const char *);
2180 g_string_append_printf (message, " %s=\"", key);
2181 for (p = value; *p; p++)
2188 g_string_append_c (message, '\\');
2192 g_string_append_c (message, *p);
2194 g_string_append_c (message, '\"');
2198 broadcast_xmessage (display,
2199 "_NET_STARTUP_INFO",
2200 "_NET_STARTUP_INFO_BEGIN",
2203 g_string_free (message, TRUE);
2207 gdk_x11_display_notify_startup_complete (GdkDisplay *display,
2208 const gchar *startup_id)
2210 if (startup_id == NULL)
2212 startup_id = GDK_X11_DISPLAY (display)->startup_notification_id;
2213 if (startup_id == NULL)
2217 gdk_x11_display_broadcast_startup_message (display, "remove",
2223 gdk_x11_display_supports_selection_notification (GdkDisplay *display)
2225 GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
2227 return display_x11->have_xfixes;
2231 gdk_x11_display_request_selection_notification (GdkDisplay *display,
2236 GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
2239 if (display_x11->have_xfixes)
2241 atom = gdk_x11_atom_to_xatom_for_display (display,
2243 XFixesSelectSelectionInput (display_x11->xdisplay,
2244 display_x11->leader_window,
2246 XFixesSetSelectionOwnerNotifyMask |
2247 XFixesSelectionWindowDestroyNotifyMask |
2248 XFixesSelectionClientCloseNotifyMask);
2257 gdk_x11_display_supports_clipboard_persistence (GdkDisplay *display)
2259 Atom clipboard_manager;
2261 /* It might make sense to cache this */
2262 clipboard_manager = gdk_x11_get_xatom_by_name_for_display (display, "CLIPBOARD_MANAGER");
2263 return XGetSelectionOwner (GDK_X11_DISPLAY (display)->xdisplay, clipboard_manager) != None;
2267 gdk_x11_display_store_clipboard (GdkDisplay *display,
2268 GdkWindow *clipboard_window,
2270 const GdkAtom *targets,
2273 GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
2274 Atom clipboard_manager, save_targets;
2276 g_return_if_fail (GDK_WINDOW_IS_X11 (clipboard_window));
2278 clipboard_manager = gdk_x11_get_xatom_by_name_for_display (display, "CLIPBOARD_MANAGER");
2279 save_targets = gdk_x11_get_xatom_by_name_for_display (display, "SAVE_TARGETS");
2281 gdk_x11_display_error_trap_push (display);
2283 if (XGetSelectionOwner (display_x11->xdisplay, clipboard_manager) != None)
2285 Atom property_name = None;
2291 property_name = gdk_x11_get_xatom_by_name_for_display (display, "GDK_SELECTION");
2293 xatoms = g_new (Atom, n_targets);
2294 for (i = 0; i < n_targets; i++)
2295 xatoms[i] = gdk_x11_atom_to_xatom_for_display (display, targets[i]);
2297 XChangeProperty (display_x11->xdisplay, GDK_WINDOW_XID (clipboard_window),
2298 property_name, XA_ATOM,
2299 32, PropModeReplace, (guchar *)xatoms, n_targets);
2304 XConvertSelection (display_x11->xdisplay,
2305 clipboard_manager, save_targets, property_name,
2306 GDK_WINDOW_XID (clipboard_window), time_);
2309 gdk_x11_display_error_trap_pop_ignored (display);
2314 * gdk_x11_display_get_user_time:
2315 * @display: (type GdkX11Display): a #GdkDisplay
2317 * Returns the timestamp of the last user interaction on
2318 * @display. The timestamp is taken from events caused
2319 * by user interaction such as key presses or pointer
2320 * movements. See gdk_x11_window_set_user_time().
2322 * Returns: the timestamp of the last user interaction
2327 gdk_x11_display_get_user_time (GdkDisplay *display)
2329 return GDK_X11_DISPLAY (display)->user_time;
2333 gdk_x11_display_supports_shapes (GdkDisplay *display)
2335 return GDK_X11_DISPLAY (display)->have_shapes;
2339 gdk_x11_display_supports_input_shapes (GdkDisplay *display)
2341 return GDK_X11_DISPLAY (display)->have_input_shapes;
2346 * gdk_x11_display_get_startup_notification_id:
2347 * @display: (type GdkX11Display): a #GdkDisplay
2349 * Gets the startup notification ID for a display.
2351 * Returns: the startup notification ID for @display
2356 gdk_x11_display_get_startup_notification_id (GdkDisplay *display)
2358 return GDK_X11_DISPLAY (display)->startup_notification_id;
2362 * gdk_x11_display_set_startup_notification_id:
2363 * @display: (type GdkX11Display): a #GdkDisplay
2364 * @startup_id: the startup notification ID (must be valid utf8)
2366 * Sets the startup notification ID for a display.
2368 * This is usually taken from the value of the DESKTOP_STARTUP_ID
2369 * environment variable, but in some cases (such as the application not
2370 * being launched using exec()) it can come from other sources.
2372 * If the ID contains the string "_TIME" then the portion following that
2373 * string is taken to be the X11 timestamp of the event that triggered
2374 * the application to be launched and the GDK current event time is set
2377 * The startup ID is also what is used to signal that the startup is
2378 * complete (for example, when opening a window or when calling
2379 * gdk_notify_startup_complete()).
2384 gdk_x11_display_set_startup_notification_id (GdkDisplay *display,
2385 const gchar *startup_id)
2387 GdkX11Display *display_x11;
2390 display_x11 = GDK_X11_DISPLAY (display);
2392 g_free (display_x11->startup_notification_id);
2393 display_x11->startup_notification_id = g_strdup (startup_id);
2395 /* Find the launch time from the startup_id, if it's there. Newer spec
2396 * states that the startup_id is of the form <unique>_TIME<timestamp>
2398 time_str = g_strrstr (startup_id, "_TIME");
2399 if (time_str != NULL)
2405 /* Skip past the "_TIME" part */
2408 retval = strtoul (time_str, &end, 0);
2409 if (end != time_str && errno == 0)
2410 display_x11->user_time = retval;
2413 /* Set the startup id on the leader window so it
2414 * applies to all windows we create on this display
2416 XChangeProperty (display_x11->xdisplay,
2417 display_x11->leader_window,
2418 gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"),
2419 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2421 (guchar *)startup_id, strlen (startup_id));
2425 gdk_x11_display_supports_composite (GdkDisplay *display)
2427 GdkX11Display *x11_display = GDK_X11_DISPLAY (display);
2429 return x11_display->have_xcomposite &&
2430 x11_display->have_xdamage &&
2431 x11_display->have_xfixes;
2435 gdk_x11_display_list_devices (GdkDisplay *display)
2437 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
2439 return GDK_X11_DISPLAY (display)->input_devices;
2443 * gdk_x11_register_standard_event_type:
2444 * @display: a #GdkDisplay
2445 * @event_base: first event type code to register
2446 * @n_events: number of event type codes to register
2448 * Registers interest in receiving extension events with type codes
2449 * between @event_base and <literal>event_base + n_events - 1</literal>.
2450 * The registered events must have the window field in the same place
2451 * as core X events (this is not the case for e.g. XKB extension events).
2453 * If an event type is registered, events of this type will go through
2454 * global and window-specific filters (see gdk_window_add_filter()).
2455 * Unregistered events will only go through global filters.
2456 * GDK may register the events of some X extensions on its own.
2458 * This function should only be needed in unusual circumstances, e.g.
2459 * when filtering XInput extension events on the root window.
2464 gdk_x11_register_standard_event_type (GdkDisplay *display,
2468 GdkEventTypeX11 *event_type;
2469 GdkX11Display *display_x11;
2471 display_x11 = GDK_X11_DISPLAY (display);
2472 event_type = g_new (GdkEventTypeX11, 1);
2474 event_type->base = event_base;
2475 event_type->n_events = n_events;
2477 display_x11->event_types = g_slist_prepend (display_x11->event_types, event_type);
2480 /* compare X sequence numbers handling wraparound */
2481 #define SEQUENCE_COMPARE(a,op,b) (((long) (a) - (long) (b)) op 0)
2483 /* delivers an error event from the error handler in gdkmain-x11.c */
2485 _gdk_x11_display_error_event (GdkDisplay *display,
2488 GdkX11Display *display_x11;
2492 display_x11 = GDK_X11_DISPLAY (display);
2495 for (tmp_list = display_x11->error_traps;
2497 tmp_list = tmp_list->next)
2501 trap = tmp_list->data;
2503 if (SEQUENCE_COMPARE (trap->start_sequence, <=, error->serial) &&
2504 (trap->end_sequence == 0 ||
2505 SEQUENCE_COMPARE (trap->end_sequence, >, error->serial)))
2508 trap->error_code = error->error_code;
2509 break; /* only innermost trap gets the error code */
2518 XGetErrorText (display_x11->xdisplay, error->error_code, buf, 63);
2521 g_strdup_printf ("The program '%s' received an X Window System error.\n"
2522 "This probably reflects a bug in the program.\n"
2523 "The error was '%s'.\n"
2524 " (Details: serial %ld error_code %d request_code %d minor_code %d)\n"
2525 " (Note to programmers: normally, X errors are reported asynchronously;\n"
2526 " that is, you will receive the error a while after causing it.\n"
2527 " To debug your program, run it with the GDK_SYNCHRONIZE environment\n"
2528 " variable to change this behavior. You can then get a meaningful\n"
2529 " backtrace from your debugger if you break on the gdk_x_error() function.)",
2534 error->request_code,
2537 #ifdef G_ENABLE_DEBUG
2538 g_error ("%s", msg);
2539 #else /* !G_ENABLE_DEBUG */
2540 g_warning ("%s\n", msg);
2543 #endif /* G_ENABLE_DEBUG */
2548 delete_outdated_error_traps (GdkX11Display *display_x11)
2551 gulong processed_sequence;
2553 processed_sequence = XLastKnownRequestProcessed (display_x11->xdisplay);
2555 tmp_list = display_x11->error_traps;
2556 while (tmp_list != NULL)
2558 GdkErrorTrap *trap = tmp_list->data;
2560 if (trap->end_sequence != 0 &&
2561 SEQUENCE_COMPARE (trap->end_sequence, <=, processed_sequence))
2563 GSList *free_me = tmp_list;
2565 tmp_list = tmp_list->next;
2566 display_x11->error_traps =
2567 g_slist_delete_link (display_x11->error_traps, free_me);
2568 g_slice_free (GdkErrorTrap, trap);
2572 tmp_list = tmp_list->next;
2578 * gdk_x11_display_error_trap_push:
2579 * @display: (type GdkX11Display): a #GdkDisplay
2581 * Begins a range of X requests on @display for which X error events
2582 * will be ignored. Unignored errors (when no trap is pushed) will abort
2583 * the application. Use gdk_x11_display_error_trap_pop() or
2584 * gdk_x11_display_error_trap_pop_ignored()to lift a trap pushed
2585 * with this function.
2587 * See also gdk_error_trap_push() to push a trap on all displays.
2592 gdk_x11_display_error_trap_push (GdkDisplay *display)
2594 GdkX11Display *display_x11;
2597 display_x11 = GDK_X11_DISPLAY (display);
2599 delete_outdated_error_traps (display_x11);
2601 /* set up the Xlib callback to tell us about errors */
2602 _gdk_x11_error_handler_push ();
2604 trap = g_slice_new0 (GdkErrorTrap);
2606 trap->start_sequence = XNextRequest (display_x11->xdisplay);
2607 trap->error_code = Success;
2609 display_x11->error_traps =
2610 g_slist_prepend (display_x11->error_traps, trap);
2614 gdk_x11_display_error_trap_pop_internal (GdkDisplay *display,
2617 GdkX11Display *display_x11;
2622 display_x11 = GDK_X11_DISPLAY (display);
2624 g_return_val_if_fail (display_x11->error_traps != NULL, Success);
2626 /* Find the first trap that hasn't been popped already */
2627 trap = NULL; /* quiet gcc */
2628 for (tmp_list = display_x11->error_traps;
2630 tmp_list = tmp_list->next)
2632 trap = tmp_list->data;
2634 if (trap->end_sequence == 0)
2638 g_return_val_if_fail (trap != NULL, Success);
2639 g_assert (trap->end_sequence == 0);
2641 /* May need to sync to fill in trap->error_code if we care about
2642 * getting an error code.
2646 gulong processed_sequence;
2647 gulong next_sequence;
2649 next_sequence = XNextRequest (display_x11->xdisplay);
2650 processed_sequence = XLastKnownRequestProcessed (display_x11->xdisplay);
2652 /* If our last request was already processed, there is no point
2653 * in syncing. i.e. if last request was a round trip (or even if
2654 * we got an event with the serial of a non-round-trip)
2656 if ((next_sequence - 1) != processed_sequence)
2658 XSync (display_x11->xdisplay, False);
2661 result = trap->error_code;
2668 /* record end of trap, giving us a range of
2669 * error sequences we'll ignore.
2671 trap->end_sequence = XNextRequest (display_x11->xdisplay);
2673 /* remove the Xlib callback */
2674 _gdk_x11_error_handler_pop ();
2676 /* we may already be outdated */
2677 delete_outdated_error_traps (display_x11);
2683 * gdk_x11_display_error_trap_pop:
2684 * @display: (type GdkX11Display): the display
2686 * Pops the error trap pushed by gdk_x11_display_error_trap_push().
2687 * Will XSync() if necessary and will always block until
2688 * the error is known to have occurred or not occurred,
2689 * so the error code can be returned.
2691 * If you don't need to use the return value,
2692 * gdk_x11_display_error_trap_pop_ignored() would be more efficient.
2694 * See gdk_error_trap_pop() for the all-displays-at-once
2699 * Return value: X error code or 0 on success
2702 gdk_x11_display_error_trap_pop (GdkDisplay *display)
2704 g_return_val_if_fail (GDK_IS_X11_DISPLAY (display), Success);
2706 return gdk_x11_display_error_trap_pop_internal (display, TRUE);
2710 * gdk_x11_display_error_trap_pop_ignored:
2711 * @display: (type GdkX11Display): the display
2713 * Pops the error trap pushed by gdk_x11_display_error_trap_push().
2714 * Does not block to see if an error occurred; merely records the
2715 * range of requests to ignore errors for, and ignores those errors
2716 * if they arrive asynchronously.
2718 * See gdk_error_trap_pop_ignored() for the all-displays-at-once
2724 gdk_x11_display_error_trap_pop_ignored (GdkDisplay *display)
2726 g_return_if_fail (GDK_IS_X11_DISPLAY (display));
2728 gdk_x11_display_error_trap_pop_internal (display, FALSE);
2732 * gdk_x11_set_sm_client_id:
2733 * @sm_client_id: the client id assigned by the session manager when the
2734 * connection was opened, or %NULL to remove the property.
2736 * Sets the <literal>SM_CLIENT_ID</literal> property on the application's leader window so that
2737 * the window manager can save the application's state using the X11R6 ICCCM
2738 * session management protocol.
2740 * See the X Session Management Library documentation for more information on
2741 * session management and the Inter-Client Communication Conventions Manual
2746 gdk_x11_set_sm_client_id (const gchar *sm_client_id)
2748 GSList *displays, *l;
2750 g_free (gdk_sm_client_id);
2751 gdk_sm_client_id = g_strdup (sm_client_id);
2753 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
2754 for (l = displays; l; l = l->next)
2755 set_sm_client_id (l->data, sm_client_id);
2757 g_slist_free (displays);
2761 gdk_x11_display_event_data_copy (GdkDisplay *display,
2762 const GdkEvent *src,
2768 gdk_x11_display_event_data_free (GdkDisplay *display,
2774 pop_error_trap (GdkDisplay *display,
2779 gdk_x11_display_error_trap_pop_ignored (display);
2784 return gdk_x11_display_error_trap_pop (display);
2789 gdk_x11_display_get_keymap (GdkDisplay *display)
2791 GdkX11Display *display_x11;
2792 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
2793 display_x11 = GDK_X11_DISPLAY (display);
2795 if (!display_x11->keymap)
2796 display_x11->keymap = g_object_new (GDK_TYPE_X11_KEYMAP, NULL);
2798 display_x11->keymap->display = display;
2800 return display_x11->keymap;
2804 gdk_x11_display_class_init (GdkX11DisplayClass * class)
2806 GObjectClass *object_class = G_OBJECT_CLASS (class);
2807 GdkDisplayClass *display_class = GDK_DISPLAY_CLASS (class);
2809 object_class->dispose = gdk_x11_display_dispose;
2810 object_class->finalize = gdk_x11_display_finalize;
2812 display_class->window_type = GDK_TYPE_X11_WINDOW;
2814 display_class->get_name = gdk_x11_display_get_name;
2815 display_class->get_n_screens = gdk_x11_display_get_n_screens;
2816 display_class->get_screen = gdk_x11_display_get_screen;
2817 display_class->get_default_screen = gdk_x11_display_get_default_screen;
2818 display_class->beep = gdk_x11_display_beep;
2819 display_class->sync = gdk_x11_display_sync;
2820 display_class->flush = gdk_x11_display_flush;
2821 display_class->has_pending = gdk_x11_display_has_pending;
2822 display_class->queue_events = _gdk_x11_display_queue_events;
2823 display_class->get_default_group = gdk_x11_display_get_default_group;
2824 display_class->supports_selection_notification = gdk_x11_display_supports_selection_notification;
2825 display_class->request_selection_notification = gdk_x11_display_request_selection_notification;
2826 display_class->supports_clipboard_persistence = gdk_x11_display_supports_clipboard_persistence;
2827 display_class->store_clipboard = gdk_x11_display_store_clipboard;
2828 display_class->supports_shapes = gdk_x11_display_supports_shapes;
2829 display_class->supports_input_shapes = gdk_x11_display_supports_input_shapes;
2830 display_class->supports_composite = gdk_x11_display_supports_composite;
2831 display_class->list_devices = gdk_x11_display_list_devices;
2832 display_class->get_app_launch_context = _gdk_x11_display_get_app_launch_context;
2833 display_class->get_cursor_for_type = _gdk_x11_display_get_cursor_for_type;
2834 display_class->get_cursor_for_name = _gdk_x11_display_get_cursor_for_name;
2835 display_class->get_cursor_for_pixbuf = _gdk_x11_display_get_cursor_for_pixbuf;
2836 display_class->get_default_cursor_size = _gdk_x11_display_get_default_cursor_size;
2837 display_class->get_maximal_cursor_size = _gdk_x11_display_get_maximal_cursor_size;
2838 display_class->supports_cursor_alpha = _gdk_x11_display_supports_cursor_alpha;
2839 display_class->supports_cursor_color = _gdk_x11_display_supports_cursor_color;
2841 display_class->before_process_all_updates = _gdk_x11_display_before_process_all_updates;
2842 display_class->after_process_all_updates = _gdk_x11_display_after_process_all_updates;
2843 display_class->get_next_serial = gdk_x11_display_get_next_serial;
2844 display_class->notify_startup_complete = gdk_x11_display_notify_startup_complete;
2845 display_class->event_data_copy = gdk_x11_display_event_data_copy;
2846 display_class->event_data_free = gdk_x11_display_event_data_free;
2847 display_class->create_window_impl = _gdk_x11_display_create_window_impl;
2848 display_class->get_keymap = gdk_x11_display_get_keymap;
2849 display_class->push_error_trap = gdk_x11_display_error_trap_push;
2850 display_class->pop_error_trap = pop_error_trap;
2851 display_class->get_selection_owner = _gdk_x11_display_get_selection_owner;
2852 display_class->set_selection_owner = _gdk_x11_display_set_selection_owner;
2853 display_class->send_selection_notify = _gdk_x11_display_send_selection_notify;
2854 display_class->get_selection_property = _gdk_x11_display_get_selection_property;
2855 display_class->convert_selection = _gdk_x11_display_convert_selection;
2856 display_class->text_property_to_utf8_list = _gdk_x11_display_text_property_to_utf8_list;
2857 display_class->utf8_to_string_target = _gdk_x11_display_utf8_to_string_target;