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, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
27 #include <glib/gprintf.h>
36 #include "gdkdisplay.h"
37 #include "gdkdisplay-x11.h"
38 #include "gdkeventsource.h"
39 #include "gdkeventtranslator.h"
40 #include "gdkscreen.h"
41 #include "gdkscreen-x11.h"
42 #include "gdkinternals.h"
43 #include "gdkdeviceprivate.h"
44 #include "gdkdevicemanager.h"
45 #include "xsettings-client.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_display_x11_dispose (GObject *object);
90 static void gdk_display_x11_finalize (GObject *object);
92 static void gdk_display_x11_event_translator_init (GdkEventTranslatorIface *iface);
94 static gboolean gdk_display_x11_translate_event (GdkEventTranslator *translator,
100 static void gdk_internal_connection_watch (Display *display,
104 XPointer *watch_data);
105 #endif /* HAVE_X11R6 */
107 typedef struct _GdkEventTypeX11 GdkEventTypeX11;
109 struct _GdkEventTypeX11
115 /* Note that we never *directly* use WM_LOCALE_NAME, WM_PROTOCOLS,
116 * but including them here has the side-effect of getting them
117 * into the internal Xlib cache
119 static const char *const precache_atoms[] = {
129 "_NET_ACTIVE_WINDOW",
130 "_NET_CURRENT_DESKTOP",
131 "_NET_FRAME_EXTENTS",
141 "_NET_WM_STATE_ABOVE",
142 "_NET_WM_STATE_BELOW",
143 "_NET_WM_STATE_FULLSCREEN",
144 "_NET_WM_STATE_MODAL",
145 "_NET_WM_STATE_MAXIMIZED_VERT",
146 "_NET_WM_STATE_MAXIMIZED_HORZ",
147 "_NET_WM_STATE_SKIP_TASKBAR",
148 "_NET_WM_STATE_SKIP_PAGER",
149 "_NET_WM_STATE_STICKY",
150 "_NET_WM_SYNC_REQUEST",
151 "_NET_WM_SYNC_REQUEST_COUNTER",
152 "_NET_WM_WINDOW_TYPE",
153 "_NET_WM_WINDOW_TYPE_NORMAL",
158 G_DEFINE_TYPE_WITH_CODE (GdkDisplayX11, _gdk_display_x11, GDK_TYPE_DISPLAY,
159 G_IMPLEMENT_INTERFACE (GDK_TYPE_EVENT_TRANSLATOR,
160 gdk_display_x11_event_translator_init))
164 _gdk_display_x11_class_init (GdkDisplayX11Class * class)
166 GObjectClass *object_class = G_OBJECT_CLASS (class);
168 object_class->dispose = gdk_display_x11_dispose;
169 object_class->finalize = gdk_display_x11_finalize;
173 _gdk_display_x11_init (GdkDisplayX11 *display)
178 gdk_display_x11_event_translator_init (GdkEventTranslatorIface *iface)
180 iface->translate_event = gdk_display_x11_translate_event;
184 do_net_wm_state_changes (GdkWindow *window)
186 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
187 GdkWindowState old_state;
189 if (GDK_WINDOW_DESTROYED (window) ||
190 gdk_window_get_window_type (window) != GDK_WINDOW_TOPLEVEL)
193 old_state = gdk_window_get_state (window);
195 /* For found_sticky to remain TRUE, we have to also be on desktop
198 if (old_state & GDK_WINDOW_STATE_STICKY)
200 if (!(toplevel->have_sticky && toplevel->on_all_desktops))
201 gdk_synthesize_window_state (window,
202 GDK_WINDOW_STATE_STICKY,
207 if (toplevel->have_sticky || toplevel->on_all_desktops)
208 gdk_synthesize_window_state (window,
210 GDK_WINDOW_STATE_STICKY);
213 if (old_state & GDK_WINDOW_STATE_FULLSCREEN)
215 if (!toplevel->have_fullscreen)
216 gdk_synthesize_window_state (window,
217 GDK_WINDOW_STATE_FULLSCREEN,
222 if (toplevel->have_fullscreen)
223 gdk_synthesize_window_state (window,
225 GDK_WINDOW_STATE_FULLSCREEN);
228 /* Our "maximized" means both vertical and horizontal; if only one,
229 * we don't expose that via GDK
231 if (old_state & GDK_WINDOW_STATE_MAXIMIZED)
233 if (!(toplevel->have_maxvert && toplevel->have_maxhorz))
234 gdk_synthesize_window_state (window,
235 GDK_WINDOW_STATE_MAXIMIZED,
240 if (toplevel->have_maxvert && toplevel->have_maxhorz)
241 gdk_synthesize_window_state (window,
243 GDK_WINDOW_STATE_MAXIMIZED);
248 gdk_check_wm_desktop_changed (GdkWindow *window)
250 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
251 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
261 gdk_error_trap_push ();
262 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
263 GDK_WINDOW_XID (window),
264 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
265 0, G_MAXLONG, False, XA_CARDINAL, &type,
267 &bytes_after, &data);
268 gdk_error_trap_pop ();
272 desktop = (gulong *)data;
273 toplevel->on_all_desktops = (*desktop == 0xFFFFFFFF);
277 toplevel->on_all_desktops = FALSE;
279 do_net_wm_state_changes (window);
283 gdk_check_wm_state_changed (GdkWindow *window)
285 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
286 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
296 gboolean had_sticky = toplevel->have_sticky;
298 toplevel->have_sticky = FALSE;
299 toplevel->have_maxvert = FALSE;
300 toplevel->have_maxhorz = FALSE;
301 toplevel->have_fullscreen = FALSE;
304 gdk_error_trap_push ();
305 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
306 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
307 0, G_MAXLONG, False, XA_ATOM, &type, &format, &nitems,
308 &bytes_after, &data);
309 gdk_error_trap_pop ();
313 Atom sticky_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_STICKY");
314 Atom maxvert_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_VERT");
315 Atom maxhorz_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_HORZ");
316 Atom fullscreen_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_FULLSCREEN");
318 atoms = (Atom *)data;
323 if (atoms[i] == sticky_atom)
324 toplevel->have_sticky = TRUE;
325 else if (atoms[i] == maxvert_atom)
326 toplevel->have_maxvert = TRUE;
327 else if (atoms[i] == maxhorz_atom)
328 toplevel->have_maxhorz = TRUE;
329 else if (atoms[i] == fullscreen_atom)
330 toplevel->have_fullscreen = TRUE;
338 /* When have_sticky is turned on, we have to check the DESKTOP property
341 if (toplevel->have_sticky && !had_sticky)
342 gdk_check_wm_desktop_changed (window);
344 do_net_wm_state_changes (window);
348 get_event_window (GdkEventTranslator *translator,
354 display = (GdkDisplay *) translator;
356 switch (xevent->type)
359 xwindow = xevent->xdestroywindow.window;
362 xwindow = xevent->xunmap.window;
365 xwindow = xevent->xmap.window;
367 case ConfigureNotify:
368 xwindow = xevent->xconfigure.window;
371 xwindow = xevent->xany.window;
374 return gdk_window_lookup_for_display (display, xwindow);
378 gdk_display_x11_translate_event (GdkEventTranslator *translator,
384 GdkWindowObject *window_private;
385 GdkWindowImplX11 *window_impl = NULL;
386 GdkScreen *screen = NULL;
387 GdkScreenX11 *screen_x11 = NULL;
388 GdkToplevelX11 *toplevel = NULL;
389 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
391 Window xwindow = None;
393 /* Find the GdkWindow that this event relates to.
394 * Basically this means substructure events
395 * are reported same as structure events
397 window = get_event_window (translator, xevent);
398 window_private = (GdkWindowObject *) window;
402 /* We may receive events such as NoExpose/GraphicsExpose
403 * and ShmCompletion for pixmaps
405 if (!GDK_IS_WINDOW (window))
408 screen = GDK_WINDOW_SCREEN (window);
409 screen_x11 = GDK_SCREEN_X11 (screen);
410 toplevel = _gdk_x11_window_get_toplevel (window);
411 window_impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
412 xwindow = GDK_WINDOW_XID (window);
414 g_object_ref (window);
417 event->any.window = window;
418 event->any.send_event = xevent->xany.send_event ? TRUE : FALSE;
420 if (window_private && GDK_WINDOW_DESTROYED (window))
422 if (xevent->type != DestroyNotify)
429 if (xevent->type == DestroyNotify)
433 n = gdk_display_get_n_screens (display);
434 for (i = 0; i < n; i++)
436 screen = gdk_display_get_screen (display, i);
437 screen_x11 = GDK_SCREEN_X11 (screen);
439 if (screen_x11->wmspec_check_window == xwindow)
441 screen_x11->wmspec_check_window = None;
442 screen_x11->last_wmspec_check_time = 0;
443 g_free (screen_x11->window_manager_name);
444 screen_x11->window_manager_name = g_strdup ("unknown");
446 /* careful, reentrancy */
447 _gdk_x11_screen_window_manager_changed (screen);
455 /* We do a "manual" conversion of the XEvent to a
456 * GdkEvent. The structures are mostly the same so
457 * the conversion is fairly straightforward. We also
458 * optionally print debugging info regarding events
464 switch (xevent->type)
468 g_message ("keymap notify"));
470 /* Not currently handled */
476 g_message ("expose:\t\twindow: %ld %d x,y: %d %d w,h: %d %d%s",
477 xevent->xexpose.window, xevent->xexpose.count,
478 xevent->xexpose.x, xevent->xexpose.y,
479 xevent->xexpose.width, xevent->xexpose.height,
480 event->any.send_event ? " (send)" : ""));
482 if (window_private == NULL)
489 GdkRectangle expose_rect;
491 expose_rect.x = xevent->xexpose.x;
492 expose_rect.y = xevent->xexpose.y;
493 expose_rect.width = xevent->xexpose.width;
494 expose_rect.height = xevent->xexpose.height;
496 _gdk_window_process_expose (window, xevent->xexpose.serial, &expose_rect);
504 GdkRectangle expose_rect;
507 g_message ("graphics expose:\tdrawable: %ld",
508 xevent->xgraphicsexpose.drawable));
510 if (window_private == NULL)
516 expose_rect.x = xevent->xgraphicsexpose.x;
517 expose_rect.y = xevent->xgraphicsexpose.y;
518 expose_rect.width = xevent->xgraphicsexpose.width;
519 expose_rect.height = xevent->xgraphicsexpose.height;
521 _gdk_window_process_expose (window, xevent->xgraphicsexpose.serial, &expose_rect);
528 g_message ("no expose:\t\tdrawable: %ld",
529 xevent->xnoexpose.drawable));
531 event->no_expose.type = GDK_NO_EXPOSE;
532 event->no_expose.window = window;
536 case VisibilityNotify:
537 #ifdef G_ENABLE_DEBUG
538 if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
539 switch (xevent->xvisibility.state)
541 case VisibilityFullyObscured:
542 g_message ("visibility notify:\twindow: %ld none",
543 xevent->xvisibility.window);
545 case VisibilityPartiallyObscured:
546 g_message ("visibility notify:\twindow: %ld partial",
547 xevent->xvisibility.window);
549 case VisibilityUnobscured:
550 g_message ("visibility notify:\twindow: %ld full",
551 xevent->xvisibility.window);
554 #endif /* G_ENABLE_DEBUG */
556 if (window_private == NULL)
562 event->visibility.type = GDK_VISIBILITY_NOTIFY;
563 event->visibility.window = window;
565 switch (xevent->xvisibility.state)
567 case VisibilityFullyObscured:
568 event->visibility.state = GDK_VISIBILITY_FULLY_OBSCURED;
571 case VisibilityPartiallyObscured:
572 event->visibility.state = GDK_VISIBILITY_PARTIAL;
575 case VisibilityUnobscured:
576 event->visibility.state = GDK_VISIBILITY_UNOBSCURED;
584 g_message ("create notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d parent: %ld ovr: %d",
585 xevent->xcreatewindow.window,
586 xevent->xcreatewindow.x,
587 xevent->xcreatewindow.y,
588 xevent->xcreatewindow.width,
589 xevent->xcreatewindow.height,
590 xevent->xcreatewindow.border_width,
591 xevent->xcreatewindow.parent,
592 xevent->xcreatewindow.override_redirect));
593 /* not really handled */
598 g_message ("destroy notify:\twindow: %ld",
599 xevent->xdestroywindow.window));
601 /* Ignore DestroyNotify from SubstructureNotifyMask */
602 if (xevent->xdestroywindow.window == xevent->xdestroywindow.event)
604 event->any.type = GDK_DESTROY;
605 event->any.window = window;
607 return_val = window_private && !GDK_WINDOW_DESTROYED (window);
609 if (window && GDK_WINDOW_XID (window) != screen_x11->xroot_window)
610 gdk_window_destroy_notify (window);
619 g_message ("unmap notify:\t\twindow: %ld",
620 xevent->xmap.window));
622 event->any.type = GDK_UNMAP;
623 event->any.window = window;
625 /* If we are shown (not withdrawn) and get an unmap, it means we
626 * were iconified in the X sense. If we are withdrawn, and get
627 * an unmap, it means we hid the window ourselves, so we
628 * will have already flipped the iconified bit off.
632 if (GDK_WINDOW_IS_MAPPED (window))
633 gdk_synthesize_window_state (window,
635 GDK_WINDOW_STATE_ICONIFIED);
637 _gdk_xgrab_check_unmap (window, xevent->xany.serial);
644 g_message ("map notify:\t\twindow: %ld",
645 xevent->xmap.window));
647 event->any.type = GDK_MAP;
648 event->any.window = window;
650 /* Unset iconified if it was set */
651 if (window && (((GdkWindowObject*)window)->state & GDK_WINDOW_STATE_ICONIFIED))
652 gdk_synthesize_window_state (window,
653 GDK_WINDOW_STATE_ICONIFIED,
660 g_message ("reparent notify:\twindow: %ld x,y: %d %d parent: %ld ovr: %d",
661 xevent->xreparent.window,
664 xevent->xreparent.parent,
665 xevent->xreparent.override_redirect));
667 /* Not currently handled */
671 case ConfigureNotify:
673 g_message ("configure notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d above: %ld ovr: %d%s",
674 xevent->xconfigure.window,
675 xevent->xconfigure.x,
676 xevent->xconfigure.y,
677 xevent->xconfigure.width,
678 xevent->xconfigure.height,
679 xevent->xconfigure.border_width,
680 xevent->xconfigure.above,
681 xevent->xconfigure.override_redirect,
684 : GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD
685 ? " (discarding child)"
686 : xevent->xconfigure.event != xevent->xconfigure.window
687 ? " (discarding substructure)"
689 if (window && GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
691 window_private->width = xevent->xconfigure.width;
692 window_private->height = xevent->xconfigure.height;
694 _gdk_window_update_size (window);
695 _gdk_x11_drawable_update_size (window_private->impl);
696 _gdk_x11_screen_size_changed (screen, xevent);
700 if (toplevel && display_x11->use_sync && !XSyncValueIsZero (toplevel->pending_counter_value))
702 toplevel->current_counter_value = toplevel->pending_counter_value;
703 XSyncIntToValue (&toplevel->pending_counter_value, 0);
708 xevent->xconfigure.event != xevent->xconfigure.window ||
709 GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD ||
710 GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
714 event->configure.type = GDK_CONFIGURE;
715 event->configure.window = window;
716 event->configure.width = xevent->xconfigure.width;
717 event->configure.height = xevent->xconfigure.height;
719 if (!xevent->xconfigure.send_event &&
720 !xevent->xconfigure.override_redirect &&
721 !GDK_WINDOW_DESTROYED (window))
725 Window child_window = 0;
727 gdk_error_trap_push ();
728 if (XTranslateCoordinates (GDK_DRAWABLE_XDISPLAY (window),
729 GDK_DRAWABLE_XID (window),
730 screen_x11->xroot_window,
735 event->configure.x = tx;
736 event->configure.y = ty;
738 gdk_error_trap_pop ();
742 event->configure.x = xevent->xconfigure.x;
743 event->configure.y = xevent->xconfigure.y;
745 window_private->x = event->configure.x;
746 window_private->y = event->configure.y;
747 window_private->width = xevent->xconfigure.width;
748 window_private->height = xevent->xconfigure.height;
750 _gdk_window_update_size (window);
751 _gdk_x11_drawable_update_size (window_private->impl);
753 if (window_private->resize_count >= 1)
755 window_private->resize_count -= 1;
757 if (window_private->resize_count == 0)
758 _gdk_moveresize_configure_done (display, window);
765 g_message ("property notify:\twindow: %ld, atom(%ld): %s%s%s",
766 xevent->xproperty.window,
767 xevent->xproperty.atom,
769 gdk_x11_get_xatom_name_for_display (display, xevent->xproperty.atom),
772 if (window_private == NULL)
778 /* We compare with the serial of the last time we mapped the
779 * window to avoid refetching properties that we set ourselves
782 xevent->xproperty.serial >= toplevel->map_serial)
784 if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"))
785 gdk_check_wm_state_changed (window);
787 if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"))
788 gdk_check_wm_desktop_changed (window);
791 if (window_private->event_mask & GDK_PROPERTY_CHANGE_MASK)
793 event->property.type = GDK_PROPERTY_NOTIFY;
794 event->property.window = window;
795 event->property.atom = gdk_x11_xatom_to_atom_for_display (display, xevent->xproperty.atom);
796 event->property.time = xevent->xproperty.time;
797 event->property.state = xevent->xproperty.state;
806 g_message ("selection clear:\twindow: %ld",
807 xevent->xproperty.window));
809 if (_gdk_selection_filter_clear_event (&xevent->xselectionclear))
811 event->selection.type = GDK_SELECTION_CLEAR;
812 event->selection.window = window;
813 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionclear.selection);
814 event->selection.time = xevent->xselectionclear.time;
821 case SelectionRequest:
823 g_message ("selection request:\twindow: %ld",
824 xevent->xproperty.window));
826 event->selection.type = GDK_SELECTION_REQUEST;
827 event->selection.window = window;
828 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.selection);
829 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.target);
830 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.property);
831 event->selection.requestor = xevent->xselectionrequest.requestor;
832 event->selection.time = xevent->xselectionrequest.time;
836 case SelectionNotify:
838 g_message ("selection notify:\twindow: %ld",
839 xevent->xproperty.window));
841 event->selection.type = GDK_SELECTION_NOTIFY;
842 event->selection.window = window;
843 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.selection);
844 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.target);
845 if (xevent->xselection.property == None)
846 event->selection.property = GDK_NONE;
848 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.property);
849 event->selection.time = xevent->xselection.time;
855 g_message ("colormap notify:\twindow: %ld",
856 xevent->xcolormap.window));
858 /* Not currently handled */
865 GdkFilterReturn result = GDK_FILTER_CONTINUE;
866 GdkAtom message_type = gdk_x11_xatom_to_atom_for_display (display, xevent->xclient.message_type);
869 g_message ("client message:\twindow: %ld",
870 xevent->xclient.window));
872 tmp_list = display_x11->client_filters;
875 GdkClientFilter *filter = tmp_list->data;
876 tmp_list = tmp_list->next;
878 if (filter->type == message_type)
880 result = (*filter->function) (xevent, event, filter->data);
881 if (result != GDK_FILTER_CONTINUE)
888 case GDK_FILTER_REMOVE:
891 case GDK_FILTER_TRANSLATE:
894 case GDK_FILTER_CONTINUE:
895 /* Send unknown ClientMessage's on to Gtk for it to use */
896 if (window_private == NULL)
902 event->client.type = GDK_CLIENT_EVENT;
903 event->client.window = window;
904 event->client.message_type = message_type;
905 event->client.data_format = xevent->xclient.format;
906 memcpy(&event->client.data, &xevent->xclient.data,
907 sizeof(event->client.data));
917 g_message ("mapping notify"));
919 /* Let XLib know that there is a new keyboard mapping.
921 XRefreshKeyboardMapping (&xevent->xmapping);
922 _gdk_keymap_keys_changed (display);
928 if (xevent->type - display_x11->xfixes_event_base == XFixesSelectionNotify)
930 XFixesSelectionNotifyEvent *selection_notify = (XFixesSelectionNotifyEvent *)xevent;
932 _gdk_x11_screen_process_owner_change (screen, xevent);
934 event->owner_change.type = GDK_OWNER_CHANGE;
935 event->owner_change.window = window;
936 event->owner_change.owner = selection_notify->owner;
937 event->owner_change.reason = selection_notify->subtype;
938 event->owner_change.selection =
939 gdk_x11_xatom_to_atom_for_display (display,
940 selection_notify->selection);
941 event->owner_change.time = selection_notify->timestamp;
942 event->owner_change.selection_time = selection_notify->selection_timestamp;
949 if (xevent->type - display_x11->xrandr_event_base == RRScreenChangeNotify ||
950 xevent->type - display_x11->xrandr_event_base == RRNotify)
953 _gdk_x11_screen_size_changed (screen, xevent);
957 #if defined(HAVE_XCOMPOSITE) && defined (HAVE_XDAMAGE) && defined (HAVE_XFIXES)
958 if (display_x11->have_xdamage && window_private && window_private->composited &&
959 xevent->type == display_x11->xdamage_event_base + XDamageNotify &&
960 ((XDamageNotifyEvent *) xevent)->damage == window_impl->damage)
962 XDamageNotifyEvent *damage_event = (XDamageNotifyEvent *) xevent;
963 XserverRegion repair;
966 rect.x = window_private->x + damage_event->area.x;
967 rect.y = window_private->y + damage_event->area.y;
968 rect.width = damage_event->area.width;
969 rect.height = damage_event->area.height;
971 repair = XFixesCreateRegion (display_x11->xdisplay,
972 &damage_event->area, 1);
973 XDamageSubtract (display_x11->xdisplay,
976 XFixesDestroyRegion (display_x11->xdisplay, repair);
978 if (window_private->parent != NULL)
979 _gdk_window_process_expose (GDK_WINDOW (window_private->parent),
980 damage_event->serial, &rect);
987 if (xevent->type == display_x11->xkb_event_type)
989 XkbEvent *xkb_event = (XkbEvent *) xevent;
991 switch (xkb_event->any.xkb_type)
993 case XkbNewKeyboardNotify:
995 _gdk_keymap_keys_changed (display);
1000 case XkbStateNotify:
1001 _gdk_keymap_state_changed (display, xevent);
1013 if (event->any.window)
1014 g_object_ref (event->any.window);
1018 /* Mark this event as having no resources to be freed */
1019 event->any.window = NULL;
1020 event->any.type = GDK_NOTHING;
1024 g_object_unref (window);
1029 static GdkFilterReturn
1030 gdk_wm_protocols_filter (GdkXEvent *xev,
1034 XEvent *xevent = (XEvent *)xev;
1035 GdkWindow *win = event->any.window;
1036 GdkDisplay *display;
1040 return GDK_FILTER_REMOVE;
1042 display = GDK_WINDOW_DISPLAY (win);
1043 atom = (Atom)xevent->xclient.data.l[0];
1045 if (atom == gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW"))
1047 /* The delete window request specifies a window
1048 * to delete. We don't actually destroy the
1049 * window because "it is only a request". (The
1050 * window might contain vital data that the
1051 * program does not want destroyed). Instead
1052 * the event is passed along to the program,
1053 * which should then destroy the window.
1056 g_message ("delete window:\t\twindow: %ld",
1057 xevent->xclient.window));
1059 event->any.type = GDK_DELETE;
1061 gdk_x11_window_set_user_time (win, xevent->xclient.data.l[1]);
1063 return GDK_FILTER_TRANSLATE;
1065 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS"))
1067 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (event->any.window);
1068 GdkWindowObject *private = (GdkWindowObject *)win;
1070 /* There is no way of knowing reliably whether we are viewable;
1071 * _gdk_x11_set_input_focus_safe() traps errors asynchronously.
1073 if (toplevel && private->accept_focus)
1074 _gdk_x11_set_input_focus_safe (display, toplevel->focus_window,
1076 xevent->xclient.data.l[1]);
1078 return GDK_FILTER_REMOVE;
1080 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING") &&
1081 !_gdk_x11_display_is_root_window (display,
1082 xevent->xclient.window))
1084 XClientMessageEvent xclient = xevent->xclient;
1086 xclient.window = GDK_WINDOW_XROOTWIN (win);
1087 XSendEvent (GDK_WINDOW_XDISPLAY (win),
1090 SubstructureRedirectMask | SubstructureNotifyMask, (XEvent *)&xclient);
1092 return GDK_FILTER_REMOVE;
1094 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_SYNC_REQUEST") &&
1095 GDK_DISPLAY_X11 (display)->use_sync)
1097 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (event->any.window);
1101 XSyncIntsToValue (&toplevel->pending_counter_value,
1102 xevent->xclient.data.l[2],
1103 xevent->xclient.data.l[3]);
1106 return GDK_FILTER_REMOVE;
1109 return GDK_FILTER_CONTINUE;
1113 _gdk_event_init (GdkDisplay *display)
1115 GdkDisplayX11 *display_x11;
1116 GdkDeviceManager *device_manager;
1118 display_x11 = GDK_DISPLAY_X11 (display);
1119 display_x11->event_source = gdk_event_source_new (display);
1121 gdk_event_source_add_translator ((GdkEventSource *) display_x11->event_source,
1122 GDK_EVENT_TRANSLATOR (display));
1124 device_manager = gdk_display_get_device_manager (display);
1125 gdk_event_source_add_translator ((GdkEventSource *) display_x11->event_source,
1126 GDK_EVENT_TRANSLATOR (device_manager));
1128 gdk_display_add_client_message_filter (display,
1129 gdk_atom_intern_static_string ("WM_PROTOCOLS"),
1130 gdk_wm_protocols_filter,
1135 _gdk_input_init (GdkDisplay *display)
1137 GdkDisplayX11 *display_x11;
1138 GdkDeviceManager *device_manager;
1142 display_x11 = GDK_DISPLAY_X11 (display);
1143 device_manager = gdk_display_get_device_manager (display);
1145 /* For backwards compatibility, just add
1146 * floating devices that are not keyboards.
1148 list = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING);
1150 for (l = list; l; l = l->next)
1154 if (device->source == GDK_SOURCE_KEYBOARD)
1157 display_x11->input_devices = g_list_prepend (display_x11->input_devices,
1158 g_object_ref (l->data));
1163 /* Now set "core" pointer to the first
1164 * master device that is a pointer.
1166 list = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
1168 for (l = list; l; l = l->next)
1170 device = list->data;
1172 if (device->source != GDK_SOURCE_MOUSE)
1175 display->core_pointer = device;
1179 /* Add the core pointer to the devices list */
1180 display_x11->input_devices = g_list_prepend (display_x11->input_devices,
1181 g_object_ref (display->core_pointer));
1188 * @display_name: the name of the display to open
1189 * @returns: a #GdkDisplay, or %NULL if the display
1190 * could not be opened.
1197 gdk_display_open (const gchar *display_name)
1200 GdkDisplay *display;
1201 GdkDisplayX11 *display_x11;
1205 const char *sm_client_id;
1207 XClassHint *class_hint;
1213 xdisplay = XOpenDisplay (display_name);
1217 display = g_object_new (GDK_TYPE_DISPLAY_X11, NULL);
1218 display_x11 = GDK_DISPLAY_X11 (display);
1220 display_x11->xdisplay = xdisplay;
1223 /* Set up handlers for Xlib internal connections */
1224 XAddConnectionWatch (xdisplay, gdk_internal_connection_watch, NULL);
1225 #endif /* HAVE_X11R6 */
1227 _gdk_x11_precache_atoms (display, precache_atoms, G_N_ELEMENTS (precache_atoms));
1229 /* RandR must be initialized before we initialize the screens */
1230 display_x11->have_randr13 = FALSE;
1232 if (XRRQueryExtension (display_x11->xdisplay,
1233 &display_x11->xrandr_event_base, &ignore))
1237 XRRQueryVersion (display_x11->xdisplay, &major, &minor);
1239 if ((major == 1 && minor >= 3) || major > 1)
1240 display_x11->have_randr13 = TRUE;
1242 gdk_x11_register_standard_event_type (display, display_x11->xrandr_event_base, RRNumberEvents);
1246 /* initialize the display's screens */
1247 display_x11->screens = g_new (GdkScreen *, ScreenCount (display_x11->xdisplay));
1248 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1249 display_x11->screens[i] = _gdk_x11_screen_new (display, i);
1251 /* We need to initialize events after we have the screen
1252 * structures in places
1254 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1255 _gdk_screen_x11_events_init (display_x11->screens[i]);
1257 /*set the default screen */
1258 display_x11->default_screen = display_x11->screens[DefaultScreen (display_x11->xdisplay)];
1260 display->device_manager = _gdk_device_manager_new (display);
1262 _gdk_event_init (display);
1264 attr.window_type = GDK_WINDOW_TOPLEVEL;
1265 attr.wclass = GDK_INPUT_OUTPUT;
1270 attr.event_mask = 0;
1272 display_x11->leader_gdk_window = gdk_window_new (GDK_SCREEN_X11 (display_x11->default_screen)->root_window,
1273 &attr, GDK_WA_X | GDK_WA_Y);
1274 (_gdk_x11_window_get_toplevel (display_x11->leader_gdk_window))->is_leader = TRUE;
1276 display_x11->leader_window = GDK_WINDOW_XID (display_x11->leader_gdk_window);
1278 display_x11->leader_window_title_set = FALSE;
1281 if (XFixesQueryExtension (display_x11->xdisplay,
1282 &display_x11->xfixes_event_base,
1285 display_x11->have_xfixes = TRUE;
1287 gdk_x11_register_standard_event_type (display,
1288 display_x11->xfixes_event_base,
1289 XFixesNumberEvents);
1293 display_x11->have_xfixes = FALSE;
1295 #ifdef HAVE_XCOMPOSITE
1296 if (XCompositeQueryExtension (display_x11->xdisplay,
1301 XCompositeQueryVersion (display_x11->xdisplay, &major, &minor);
1303 /* Prior to Composite version 0.4, composited windows clipped their
1304 * parents, so you had to use IncludeInferiors to draw to the parent
1305 * This isn't useful for our purposes, so require 0.4
1307 display_x11->have_xcomposite = major > 0 || (major == 0 && minor >= 4);
1311 display_x11->have_xcomposite = FALSE;
1314 if (XDamageQueryExtension (display_x11->xdisplay,
1315 &display_x11->xdamage_event_base,
1318 display_x11->have_xdamage = TRUE;
1320 gdk_x11_register_standard_event_type (display,
1321 display_x11->xdamage_event_base,
1322 XDamageNumberEvents);
1326 display_x11->have_xdamage = FALSE;
1328 display_x11->have_shapes = FALSE;
1329 display_x11->have_input_shapes = FALSE;
1331 if (XShapeQueryExtension (GDK_DISPLAY_XDISPLAY (display), &display_x11->shape_event_base, &ignore))
1333 display_x11->have_shapes = TRUE;
1335 if (XShapeQueryVersion (GDK_DISPLAY_XDISPLAY (display), &maj, &min))
1336 display_x11->have_input_shapes = (maj == 1 && min >= 1);
1340 display_x11->trusted_client = TRUE;
1343 int rootx, rooty, winx, winy;
1346 gdk_error_trap_push ();
1347 XQueryPointer (display_x11->xdisplay,
1348 GDK_SCREEN_X11 (display_x11->default_screen)->xroot_window,
1349 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
1351 if (G_UNLIKELY (gdk_error_trap_pop () == BadWindow))
1353 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));
1354 display_x11->trusted_client = FALSE;
1358 if (_gdk_synchronize)
1359 XSynchronize (display_x11->xdisplay, True);
1361 class_hint = XAllocClassHint();
1362 class_hint->res_name = g_get_prgname ();
1364 class_hint->res_class = (char *)gdk_get_program_class ();
1366 /* XmbSetWMProperties sets the RESOURCE_NAME environment variable
1367 * from argv[0], so we just synthesize an argument array here.
1370 argv[0] = g_get_prgname ();
1372 XmbSetWMProperties (display_x11->xdisplay,
1373 display_x11->leader_window,
1374 NULL, NULL, argv, argc, NULL, NULL,
1378 sm_client_id = _gdk_get_sm_client_id ();
1380 _gdk_windowing_display_set_sm_client_id (display, sm_client_id);
1383 XChangeProperty (display_x11->xdisplay,
1384 display_x11->leader_window,
1385 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PID"),
1386 XA_CARDINAL, 32, PropModeReplace, (guchar *) & pid, 1);
1388 /* We don't yet know a valid time. */
1389 display_x11->user_time = 0;
1393 gint xkb_major = XkbMajorVersion;
1394 gint xkb_minor = XkbMinorVersion;
1395 if (XkbLibraryVersion (&xkb_major, &xkb_minor))
1397 xkb_major = XkbMajorVersion;
1398 xkb_minor = XkbMinorVersion;
1400 if (XkbQueryExtension (display_x11->xdisplay,
1401 NULL, &display_x11->xkb_event_type, NULL,
1402 &xkb_major, &xkb_minor))
1404 Bool detectable_autorepeat_supported;
1406 display_x11->use_xkb = TRUE;
1408 XkbSelectEvents (display_x11->xdisplay,
1410 XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask,
1411 XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask);
1413 /* keep this in sync with _gdk_keymap_state_changed() */
1414 XkbSelectEventDetails (display_x11->xdisplay,
1415 XkbUseCoreKbd, XkbStateNotify,
1416 XkbAllStateComponentsMask,
1417 XkbGroupLockMask|XkbModifierLockMask);
1419 XkbSetDetectableAutoRepeat (display_x11->xdisplay,
1421 &detectable_autorepeat_supported);
1423 GDK_NOTE (MISC, g_message ("Detectable autorepeat %s.",
1424 detectable_autorepeat_supported ?
1425 "supported" : "not supported"));
1427 display_x11->have_xkb_autorepeat = detectable_autorepeat_supported;
1433 display_x11->use_sync = FALSE;
1437 int error_base, event_base;
1439 if (XSyncQueryExtension (display_x11->xdisplay,
1440 &event_base, &error_base) &&
1441 XSyncInitialize (display_x11->xdisplay,
1443 display_x11->use_sync = TRUE;
1447 _gdk_input_init (display);
1448 _gdk_dnd_init (display);
1450 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1451 _gdk_x11_screen_setup (display_x11->screens[i]);
1453 g_signal_emit_by_name (display, "opened");
1454 g_signal_emit_by_name (gdk_display_manager_get (), "display-opened", display);
1461 * XLib internal connection handling
1463 typedef struct _GdkInternalConnection GdkInternalConnection;
1465 struct _GdkInternalConnection
1473 process_internal_connection (GIOChannel *gioc,
1477 GdkInternalConnection *connection = (GdkInternalConnection *)data;
1479 GDK_THREADS_ENTER ();
1481 XProcessInternalConnection ((Display*)connection->display, connection->fd);
1483 GDK_THREADS_LEAVE ();
1489 _gdk_windowing_window_get_next_serial (GdkDisplay *display)
1491 return NextRequest (GDK_DISPLAY_XDISPLAY (display));
1495 static GdkInternalConnection *
1496 gdk_add_connection_handler (Display *display,
1499 GIOChannel *io_channel;
1500 GdkInternalConnection *connection;
1502 connection = g_new (GdkInternalConnection, 1);
1504 connection->fd = fd;
1505 connection->display = display;
1507 io_channel = g_io_channel_unix_new (fd);
1509 connection->source = g_io_create_watch (io_channel, G_IO_IN);
1510 g_source_set_callback (connection->source,
1511 (GSourceFunc)process_internal_connection, connection, NULL);
1512 g_source_attach (connection->source, NULL);
1514 g_io_channel_unref (io_channel);
1520 gdk_remove_connection_handler (GdkInternalConnection *connection)
1522 g_source_destroy (connection->source);
1523 g_free (connection);
1527 gdk_internal_connection_watch (Display *display,
1531 XPointer *watch_data)
1534 *watch_data = (XPointer)gdk_add_connection_handler (display, fd);
1536 gdk_remove_connection_handler ((GdkInternalConnection *)*watch_data);
1538 #endif /* HAVE_X11R6 */
1541 * gdk_display_get_name:
1542 * @display: a #GdkDisplay
1544 * Gets the name of the display.
1546 * Returns: a string representing the display name. This string is owned
1547 * by GDK and should not be modified or freed.
1551 G_CONST_RETURN gchar *
1552 gdk_display_get_name (GdkDisplay *display)
1554 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1556 return (gchar *) DisplayString (GDK_DISPLAY_X11 (display)->xdisplay);
1560 * gdk_display_get_n_screens:
1561 * @display: a #GdkDisplay
1563 * Gets the number of screen managed by the @display.
1565 * Returns: number of screens.
1570 gdk_display_get_n_screens (GdkDisplay *display)
1572 g_return_val_if_fail (GDK_IS_DISPLAY (display), 0);
1574 return ScreenCount (GDK_DISPLAY_X11 (display)->xdisplay);
1578 * gdk_display_get_screen:
1579 * @display: a #GdkDisplay
1580 * @screen_num: the screen number
1582 * Returns a screen object for one of the screens of the display.
1584 * Returns: the #GdkScreen object
1589 gdk_display_get_screen (GdkDisplay *display,
1592 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1593 g_return_val_if_fail (ScreenCount (GDK_DISPLAY_X11 (display)->xdisplay) > screen_num, NULL);
1595 return GDK_DISPLAY_X11 (display)->screens[screen_num];
1599 * gdk_display_get_default_screen:
1600 * @display: a #GdkDisplay
1602 * Get the default #GdkScreen for @display.
1604 * Returns: the default #GdkScreen object for @display
1609 gdk_display_get_default_screen (GdkDisplay *display)
1611 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1613 return GDK_DISPLAY_X11 (display)->default_screen;
1617 _gdk_x11_display_is_root_window (GdkDisplay *display,
1618 Window xroot_window)
1620 GdkDisplayX11 *display_x11;
1623 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1625 display_x11 = GDK_DISPLAY_X11 (display);
1627 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1629 if (GDK_SCREEN_XROOTWIN (display_x11->screens[i]) == xroot_window)
1635 struct XPointerUngrabInfo {
1636 GdkDisplay *display;
1641 device_ungrab_callback (GdkDisplay *display,
1645 GdkDevice *device = data;
1647 _gdk_display_device_grab_update (display, device, serial);
1651 #define XSERVER_TIME_IS_LATER(time1, time2) \
1652 ( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) || \
1653 (( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 )) \
1657 * gdk_device_ungrab:
1658 * @device: a #GdkDevice
1659 * @time_: a timestap (e.g. %GDK_CURRENT_TIME).
1661 * Release any grab on @device.
1666 gdk_device_ungrab (GdkDevice *device,
1669 GdkDisplay *display;
1671 GdkDeviceGrabInfo *grab;
1672 unsigned long serial;
1674 g_return_if_fail (GDK_IS_DEVICE (device));
1676 display = gdk_device_get_display (device);
1677 xdisplay = GDK_DISPLAY_XDISPLAY (display);
1679 serial = NextRequest (xdisplay);
1681 GDK_DEVICE_GET_CLASS (device)->ungrab (device, time_);
1684 grab = _gdk_display_get_last_device_grab (display, device);
1686 (time_ == GDK_CURRENT_TIME ||
1687 grab->time == GDK_CURRENT_TIME ||
1688 !XSERVER_TIME_IS_LATER (grab->time, time_)))
1690 grab->serial_end = serial;
1691 _gdk_x11_roundtrip_async (display,
1692 device_ungrab_callback,
1699 * @display: a #GdkDisplay
1701 * Emits a short beep on @display
1706 gdk_display_beep (GdkDisplay *display)
1708 g_return_if_fail (GDK_IS_DISPLAY (display));
1711 XkbBell (GDK_DISPLAY_XDISPLAY (display), None, 0, None);
1713 XBell (GDK_DISPLAY_XDISPLAY (display), 0);
1719 * @display: a #GdkDisplay
1721 * Flushes any requests queued for the windowing system and waits until all
1722 * requests have been handled. This is often used for making sure that the
1723 * display is synchronized with the current state of the program. Calling
1724 * gdk_display_sync() before gdk_error_trap_pop() makes sure that any errors
1725 * generated from earlier requests are handled before the error trap is
1728 * This is most useful for X11. On windowing systems where requests are
1729 * handled synchronously, this function will do nothing.
1734 gdk_display_sync (GdkDisplay *display)
1736 g_return_if_fail (GDK_IS_DISPLAY (display));
1738 XSync (GDK_DISPLAY_XDISPLAY (display), False);
1742 * gdk_display_flush:
1743 * @display: a #GdkDisplay
1745 * Flushes any requests queued for the windowing system; this happens automatically
1746 * when the main loop blocks waiting for new events, but if your application
1747 * is drawing without returning control to the main loop, you may need
1748 * to call this function explicitely. A common case where this function
1749 * needs to be called is when an application is executing drawing commands
1750 * from a thread other than the thread where the main loop is running.
1752 * This is most useful for X11. On windowing systems where requests are
1753 * handled synchronously, this function will do nothing.
1758 gdk_display_flush (GdkDisplay *display)
1760 g_return_if_fail (GDK_IS_DISPLAY (display));
1762 if (!display->closed)
1763 XFlush (GDK_DISPLAY_XDISPLAY (display));
1767 * gdk_display_get_default_group:
1768 * @display: a #GdkDisplay
1770 * Returns the default group leader window for all toplevel windows
1771 * on @display. This window is implicitly created by GDK.
1772 * See gdk_window_set_group().
1774 * Return value: The default group leader window for @display
1779 gdk_display_get_default_group (GdkDisplay *display)
1781 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1783 return GDK_DISPLAY_X11 (display)->leader_gdk_window;
1787 * gdk_x11_display_grab:
1788 * @display: a #GdkDisplay
1790 * Call XGrabServer() on @display.
1791 * To ungrab the display again, use gdk_x11_display_ungrab().
1793 * gdk_x11_display_grab()/gdk_x11_display_ungrab() calls can be nested.
1798 gdk_x11_display_grab (GdkDisplay *display)
1800 GdkDisplayX11 *display_x11;
1802 g_return_if_fail (GDK_IS_DISPLAY (display));
1804 display_x11 = GDK_DISPLAY_X11 (display);
1806 if (display_x11->grab_count == 0)
1807 XGrabServer (display_x11->xdisplay);
1808 display_x11->grab_count++;
1812 * gdk_x11_display_ungrab:
1813 * @display: a #GdkDisplay
1815 * Ungrab @display after it has been grabbed with
1816 * gdk_x11_display_grab().
1821 gdk_x11_display_ungrab (GdkDisplay *display)
1823 GdkDisplayX11 *display_x11;
1825 g_return_if_fail (GDK_IS_DISPLAY (display));
1827 display_x11 = GDK_DISPLAY_X11 (display);;
1828 g_return_if_fail (display_x11->grab_count > 0);
1830 display_x11->grab_count--;
1831 if (display_x11->grab_count == 0)
1833 XUngrabServer (display_x11->xdisplay);
1834 XFlush (display_x11->xdisplay);
1839 gdk_display_x11_dispose (GObject *object)
1841 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (object);
1844 g_list_foreach (display_x11->input_devices, (GFunc) g_object_run_dispose, NULL);
1846 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1847 _gdk_screen_close (display_x11->screens[i]);
1849 if (display_x11->event_source)
1851 g_source_destroy (display_x11->event_source);
1852 g_source_unref (display_x11->event_source);
1853 display_x11->event_source = NULL;
1856 G_OBJECT_CLASS (_gdk_display_x11_parent_class)->dispose (object);
1860 gdk_display_x11_finalize (GObject *object)
1862 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (object);
1866 if (display_x11->keymap)
1867 g_object_unref (display_x11->keymap);
1869 /* Free motif Dnd */
1870 if (display_x11->motif_target_lists)
1872 for (i = 0; i < display_x11->motif_n_target_lists; i++)
1873 g_list_free (display_x11->motif_target_lists[i]);
1874 g_free (display_x11->motif_target_lists);
1877 _gdk_x11_cursor_display_finalize (GDK_DISPLAY_OBJECT(display_x11));
1879 /* Atom Hashtable */
1880 g_hash_table_destroy (display_x11->atom_from_virtual);
1881 g_hash_table_destroy (display_x11->atom_to_virtual);
1884 XDestroyWindow (display_x11->xdisplay, display_x11->leader_window);
1886 /* list of filters for client messages */
1887 g_list_foreach (display_x11->client_filters, (GFunc) g_free, NULL);
1888 g_list_free (display_x11->client_filters);
1890 /* List of event window extraction functions */
1891 g_slist_foreach (display_x11->event_types, (GFunc)g_free, NULL);
1892 g_slist_free (display_x11->event_types);
1894 /* input GdkDevice list */
1895 g_list_foreach (display_x11->input_devices, (GFunc) g_object_unref, NULL);
1896 g_list_free (display_x11->input_devices);
1898 /* input GdkWindow list */
1899 g_list_foreach (display_x11->input_windows, (GFunc) g_free, NULL);
1900 g_list_free (display_x11->input_windows);
1902 /* Free all GdkScreens */
1903 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
1904 g_object_unref (display_x11->screens[i]);
1905 g_free (display_x11->screens);
1907 g_free (display_x11->startup_notification_id);
1909 /* X ID hashtable */
1910 g_hash_table_destroy (display_x11->xid_ht);
1912 XCloseDisplay (display_x11->xdisplay);
1915 while (display_x11->error_traps != NULL)
1917 GdkErrorTrap *trap = display_x11->error_traps->data;
1919 display_x11->error_traps =
1920 g_slist_delete_link (display_x11->error_traps,
1921 display_x11->error_traps);
1923 if (trap->end_sequence == 0)
1924 g_warning ("Display finalized with an unpopped error trap");
1926 g_slice_free (GdkErrorTrap, trap);
1929 G_OBJECT_CLASS (_gdk_display_x11_parent_class)->finalize (object);
1933 * gdk_x11_lookup_xdisplay:
1934 * @xdisplay: a pointer to an X Display
1936 * Find the #GdkDisplay corresponding to @display, if any exists.
1938 * Return value: the #GdkDisplay, if found, otherwise %NULL.
1943 gdk_x11_lookup_xdisplay (Display *xdisplay)
1947 for (tmp_list = _gdk_displays; tmp_list; tmp_list = tmp_list->next)
1949 if (GDK_DISPLAY_XDISPLAY (tmp_list->data) == xdisplay)
1950 return tmp_list->data;
1957 * _gdk_x11_display_screen_for_xrootwin:
1958 * @display: a #GdkDisplay
1959 * @xrootwin: window ID for one of of the screen's of the display.
1961 * Given the root window ID of one of the screen's of a #GdkDisplay,
1964 * Return value: the #GdkScreen corresponding to @xrootwin, or %NULL.
1967 _gdk_x11_display_screen_for_xrootwin (GdkDisplay *display,
1972 for (i = 0; i < ScreenCount (GDK_DISPLAY_X11 (display)->xdisplay); i++)
1974 GdkScreen *screen = gdk_display_get_screen (display, i);
1975 if (GDK_SCREEN_XROOTWIN (screen) == xrootwin)
1983 * gdk_x11_display_get_xdisplay:
1984 * @display: a #GdkDisplay
1985 * @returns: an X display.
1987 * Returns the X display of a #GdkDisplay.
1992 gdk_x11_display_get_xdisplay (GdkDisplay *display)
1994 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1995 return GDK_DISPLAY_X11 (display)->xdisplay;
1999 _gdk_windowing_set_default_display (GdkDisplay *display)
2001 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
2002 const gchar *startup_id;
2007 g_free (display_x11->startup_notification_id);
2008 display_x11->startup_notification_id = NULL;
2010 startup_id = g_getenv ("DESKTOP_STARTUP_ID");
2011 if (startup_id && *startup_id != '\0')
2015 if (!g_utf8_validate (startup_id, -1, NULL))
2016 g_warning ("DESKTOP_STARTUP_ID contains invalid UTF-8");
2018 display_x11->startup_notification_id = g_strdup (startup_id);
2020 /* Find the launch time from the startup_id, if it's there. Newer spec
2021 * states that the startup_id is of the form <unique>_TIME<timestamp>
2023 time_str = g_strrstr (startup_id, "_TIME");
2024 if (time_str != NULL)
2030 /* Skip past the "_TIME" part */
2033 retval = strtoul (time_str, &end, 0);
2034 if (end != time_str && errno == 0)
2035 display_x11->user_time = retval;
2038 /* Clear the environment variable so it won't be inherited by
2039 * child processes and confuse things.
2041 g_unsetenv ("DESKTOP_STARTUP_ID");
2043 /* Set the startup id on the leader window so it
2044 * applies to all windows we create on this display
2046 XChangeProperty (display_x11->xdisplay,
2047 display_x11->leader_window,
2048 gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"),
2049 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
2051 (guchar *)startup_id, strlen (startup_id));
2056 broadcast_xmessage (GdkDisplay *display,
2057 const char *message_type,
2058 const char *message_type_begin,
2059 const char *message)
2061 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
2062 GdkScreen *screen = gdk_display_get_default_screen (display);
2063 GdkWindow *root_window = gdk_screen_get_root_window (screen);
2064 Window xroot_window = GDK_WINDOW_XID (root_window);
2067 Atom type_atom_begin;
2070 if (!G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
2074 XSetWindowAttributes attrs;
2076 attrs.override_redirect = True;
2077 attrs.event_mask = PropertyChangeMask | StructureNotifyMask;
2080 XCreateWindow (xdisplay,
2086 (Visual *)CopyFromParent,
2087 CWOverrideRedirect | CWEventMask,
2091 type_atom = gdk_x11_get_xatom_by_name_for_display (display,
2093 type_atom_begin = gdk_x11_get_xatom_by_name_for_display (display,
2094 message_type_begin);
2097 XClientMessageEvent xclient;
2099 const char *src_end;
2103 memset(&xclient, 0, sizeof (xclient));
2104 xclient.type = ClientMessage;
2105 xclient.message_type = type_atom_begin;
2106 xclient.display =xdisplay;
2107 xclient.window = xwindow;
2111 src_end = message + strlen (message) + 1; /* +1 to include nul byte */
2113 while (src != src_end)
2115 dest = &xclient.data.b[0];
2116 dest_end = dest + 20;
2118 while (dest != dest_end &&
2126 while (dest != dest_end)
2132 XSendEvent (xdisplay,
2136 (XEvent *)&xclient);
2138 xclient.message_type = type_atom;
2142 XDestroyWindow (xdisplay, xwindow);
2147 * gdk_x11_display_broadcast_startup_message:
2148 * @display: a #GdkDisplay
2149 * @message_type: startup notification message type ("new", "change",
2151 * @...: a list of key/value pairs (as strings), terminated by a
2152 * %NULL key. (A %NULL value for a key will cause that key to be
2153 * skipped in the output.)
2155 * Sends a startup notification message of type @message_type to
2158 * This is a convenience function for use by code that implements the
2159 * freedesktop startup notification specification. Applications should
2160 * not normally need to call it directly. See the <ulink
2161 * url="http://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt">Startup
2162 * Notification Protocol specification</ulink> for
2163 * definitions of the message types and keys that can be used.
2168 gdk_x11_display_broadcast_startup_message (GdkDisplay *display,
2169 const char *message_type,
2174 const char *key, *value, *p;
2176 message = g_string_new (message_type);
2177 g_string_append_c (message, ':');
2179 va_start (ap, message_type);
2180 while ((key = va_arg (ap, const char *)))
2182 value = va_arg (ap, const char *);
2186 g_string_append_printf (message, " %s=\"", key);
2187 for (p = value; *p; p++)
2194 g_string_append_c (message, '\\');
2198 g_string_append_c (message, *p);
2200 g_string_append_c (message, '\"');
2204 broadcast_xmessage (display,
2205 "_NET_STARTUP_INFO",
2206 "_NET_STARTUP_INFO_BEGIN",
2209 g_string_free (message, TRUE);
2213 * gdk_notify_startup_complete:
2215 * Indicates to the GUI environment that the application has finished
2216 * loading. If the applications opens windows, this function is
2217 * normally called after opening the application's initial set of
2220 * GTK+ will call this function automatically after opening the first
2221 * #GtkWindow unless gtk_window_set_auto_startup_notification() is called
2222 * to disable that feature.
2227 gdk_notify_startup_complete (void)
2229 GdkDisplay *display;
2230 GdkDisplayX11 *display_x11;
2232 display = gdk_display_get_default ();
2236 display_x11 = GDK_DISPLAY_X11 (display);
2238 if (display_x11->startup_notification_id == NULL)
2241 gdk_notify_startup_complete_with_id (display_x11->startup_notification_id);
2245 * gdk_notify_startup_complete_with_id:
2246 * @startup_id: a startup-notification identifier, for which notification
2247 * process should be completed
2249 * Indicates to the GUI environment that the application has finished
2250 * loading, using a given identifier.
2252 * GTK+ will call this function automatically for #GtkWindow with custom
2253 * startup-notification identifier unless
2254 * gtk_window_set_auto_startup_notification() is called to disable
2260 gdk_notify_startup_complete_with_id (const gchar* startup_id)
2262 GdkDisplay *display;
2264 display = gdk_display_get_default ();
2268 gdk_x11_display_broadcast_startup_message (display, "remove",
2274 * gdk_display_supports_selection_notification:
2275 * @display: a #GdkDisplay
2277 * Returns whether #GdkEventOwnerChange events will be
2278 * sent when the owner of a selection changes.
2280 * Return value: whether #GdkEventOwnerChange events will
2286 gdk_display_supports_selection_notification (GdkDisplay *display)
2288 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
2290 return display_x11->have_xfixes;
2294 * gdk_display_request_selection_notification:
2295 * @display: a #GdkDisplay
2296 * @selection: the #GdkAtom naming the selection for which
2297 * ownership change notification is requested
2299 * Request #GdkEventOwnerChange events for ownership changes
2300 * of the selection named by the given atom.
2302 * Return value: whether #GdkEventOwnerChange events will
2308 gdk_display_request_selection_notification (GdkDisplay *display,
2313 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
2316 if (display_x11->have_xfixes)
2318 atom = gdk_x11_atom_to_xatom_for_display (display,
2320 XFixesSelectSelectionInput (display_x11->xdisplay,
2321 display_x11->leader_window,
2323 XFixesSetSelectionOwnerNotifyMask |
2324 XFixesSelectionWindowDestroyNotifyMask |
2325 XFixesSelectionClientCloseNotifyMask);
2334 * gdk_display_supports_clipboard_persistence
2335 * @display: a #GdkDisplay
2337 * Returns whether the speicifed display supports clipboard
2338 * persistance; i.e. if it's possible to store the clipboard data after an
2339 * application has quit. On X11 this checks if a clipboard daemon is
2342 * Returns: %TRUE if the display supports clipboard persistance.
2347 gdk_display_supports_clipboard_persistence (GdkDisplay *display)
2349 Atom clipboard_manager;
2351 /* It might make sense to cache this */
2352 clipboard_manager = gdk_x11_get_xatom_by_name_for_display (display, "CLIPBOARD_MANAGER");
2353 return XGetSelectionOwner (GDK_DISPLAY_X11 (display)->xdisplay, clipboard_manager) != None;
2357 * gdk_display_store_clipboard
2358 * @display: a #GdkDisplay
2359 * @clipboard_window: a #GdkWindow belonging to the clipboard owner
2360 * @time_: a timestamp
2361 * @targets: an array of targets that should be saved, or %NULL
2362 * if all available targets should be saved.
2363 * @n_targets: length of the @targets array
2365 * Issues a request to the clipboard manager to store the
2366 * clipboard data. On X11, this is a special program that works
2367 * according to the freedesktop clipboard specification, available at
2368 * <ulink url="http://www.freedesktop.org/Standards/clipboard-manager-spec">
2369 * http://www.freedesktop.org/Standards/clipboard-manager-spec</ulink>.
2374 gdk_display_store_clipboard (GdkDisplay *display,
2375 GdkWindow *clipboard_window,
2377 const GdkAtom *targets,
2380 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
2381 Atom clipboard_manager, save_targets;
2383 g_return_if_fail (GDK_WINDOW_IS_X11 (clipboard_window));
2385 clipboard_manager = gdk_x11_get_xatom_by_name_for_display (display, "CLIPBOARD_MANAGER");
2386 save_targets = gdk_x11_get_xatom_by_name_for_display (display, "SAVE_TARGETS");
2388 gdk_error_trap_push ();
2390 if (XGetSelectionOwner (display_x11->xdisplay, clipboard_manager) != None)
2392 Atom property_name = None;
2398 property_name = gdk_x11_atom_to_xatom_for_display (display, _gdk_selection_property);
2400 xatoms = g_new (Atom, n_targets);
2401 for (i = 0; i < n_targets; i++)
2402 xatoms[i] = gdk_x11_atom_to_xatom_for_display (display, targets[i]);
2404 XChangeProperty (display_x11->xdisplay, GDK_WINDOW_XID (clipboard_window),
2405 property_name, XA_ATOM,
2406 32, PropModeReplace, (guchar *)xatoms, n_targets);
2411 XConvertSelection (display_x11->xdisplay,
2412 clipboard_manager, save_targets, property_name,
2413 GDK_WINDOW_XID (clipboard_window), time_);
2416 gdk_error_trap_pop ();
2421 * gdk_x11_display_get_user_time:
2422 * @display: a #GdkDisplay
2424 * Returns the timestamp of the last user interaction on
2425 * @display. The timestamp is taken from events caused
2426 * by user interaction such as key presses or pointer
2427 * movements. See gdk_x11_window_set_user_time().
2429 * Returns: the timestamp of the last user interaction
2434 gdk_x11_display_get_user_time (GdkDisplay *display)
2436 return GDK_DISPLAY_X11 (display)->user_time;
2440 * gdk_display_supports_shapes:
2441 * @display: a #GdkDisplay
2443 * Returns %TRUE if gdk_window_shape_combine_mask() can
2444 * be used to create shaped windows on @display.
2446 * Returns: %TRUE if shaped windows are supported
2451 gdk_display_supports_shapes (GdkDisplay *display)
2453 return GDK_DISPLAY_X11 (display)->have_shapes;
2457 * gdk_display_supports_input_shapes:
2458 * @display: a #GdkDisplay
2460 * Returns %TRUE if gdk_window_input_shape_combine_mask() can
2461 * be used to modify the input shape of windows on @display.
2463 * Returns: %TRUE if windows with modified input shape are supported
2468 gdk_display_supports_input_shapes (GdkDisplay *display)
2470 return GDK_DISPLAY_X11 (display)->have_input_shapes;
2475 * gdk_x11_display_get_startup_notification_id:
2476 * @display: a #GdkDisplay
2478 * Gets the startup notification ID for a display.
2480 * Returns: the startup notification ID for @display
2484 G_CONST_RETURN gchar *
2485 gdk_x11_display_get_startup_notification_id (GdkDisplay *display)
2487 return GDK_DISPLAY_X11 (display)->startup_notification_id;
2491 * gdk_display_supports_composite:
2492 * @display: a #GdkDisplay
2494 * Returns %TRUE if gdk_window_set_composited() can be used
2495 * to redirect drawing on the window using compositing.
2497 * Currently this only works on X11 with XComposite and
2498 * XDamage extensions available.
2500 * Returns: %TRUE if windows may be composited.
2505 gdk_display_supports_composite (GdkDisplay *display)
2507 GdkDisplayX11 *x11_display = GDK_DISPLAY_X11 (display);
2509 return x11_display->have_xcomposite &&
2510 x11_display->have_xdamage &&
2511 x11_display->have_xfixes;
2515 * gdk_display_list_devices:
2516 * @display: a #GdkDisplay
2518 * Returns the list of available input devices attached to @display.
2519 * The list is statically allocated and should not be freed.
2521 * Return value: (transfer none) (element-type GdkDevice):
2522 * a list of #GdkDevice
2526 * Deprecated: 3.0: Use gdk_device_manager_list_devices() instead.
2529 gdk_display_list_devices (GdkDisplay *display)
2531 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
2533 return GDK_DISPLAY_X11 (display)->input_devices;
2537 * gdk_event_send_client_message_for_display:
2538 * @display: the #GdkDisplay for the window where the message is to be sent.
2539 * @event: the #GdkEvent to send, which should be a #GdkEventClient.
2540 * @winid: the window to send the client message to.
2542 * On X11, sends an X ClientMessage event to a given window. On
2543 * Windows, sends a message registered with the name
2544 * GDK_WIN32_CLIENT_MESSAGE.
2546 * This could be used for communicating between different
2547 * applications, though the amount of data is limited to 20 bytes on
2548 * X11, and to just four bytes on Windows.
2550 * Returns: non-zero on success.
2555 gdk_event_send_client_message_for_display (GdkDisplay *display,
2557 GdkNativeWindow winid)
2561 g_return_val_if_fail(event != NULL, FALSE);
2563 /* Set up our event to send, with the exception of its target window */
2564 sev.xclient.type = ClientMessage;
2565 sev.xclient.display = GDK_DISPLAY_XDISPLAY (display);
2566 sev.xclient.format = event->client.data_format;
2567 sev.xclient.window = winid;
2568 memcpy(&sev.xclient.data, &event->client.data, sizeof (sev.xclient.data));
2569 sev.xclient.message_type = gdk_x11_atom_to_xatom_for_display (display, event->client.message_type);
2571 return _gdk_send_xevent (display, winid, False, NoEventMask, &sev);
2575 * gdk_display_add_client_message_filter:
2576 * @display: a #GdkDisplay for which this message filter applies
2577 * @message_type: the type of ClientMessage events to receive.
2578 * This will be checked against the @message_type field
2579 * of the XClientMessage event struct.
2580 * @func: the function to call to process the event.
2581 * @data: user data to pass to @func.
2583 * Adds a filter to be called when X ClientMessage events are received.
2584 * See gdk_window_add_filter() if you are interested in filtering other
2590 gdk_display_add_client_message_filter (GdkDisplay *display,
2591 GdkAtom message_type,
2595 GdkClientFilter *filter;
2596 g_return_if_fail (GDK_IS_DISPLAY (display));
2597 filter = g_new (GdkClientFilter, 1);
2599 filter->type = message_type;
2600 filter->function = func;
2601 filter->data = data;
2603 GDK_DISPLAY_X11(display)->client_filters =
2604 g_list_append (GDK_DISPLAY_X11 (display)->client_filters,
2609 * gdk_add_client_message_filter:
2610 * @message_type: the type of ClientMessage events to receive. This will be
2611 * checked against the <structfield>message_type</structfield> field of the
2612 * XClientMessage event struct.
2613 * @func: the function to call to process the event.
2614 * @data: user data to pass to @func.
2616 * Adds a filter to the default display to be called when X ClientMessage events
2617 * are received. See gdk_display_add_client_message_filter().
2620 gdk_add_client_message_filter (GdkAtom message_type,
2624 gdk_display_add_client_message_filter (gdk_display_get_default (),
2625 message_type, func, data);
2629 *--------------------------------------------------------------
2632 * Flushes the Xlib output buffer and then waits
2633 * until all requests have been received and processed
2634 * by the X server. The only real use for this function
2635 * is in dealing with XShm.
2643 *--------------------------------------------------------------
2648 GSList *tmp_list = _gdk_displays;
2652 XSync (GDK_DISPLAY_XDISPLAY (tmp_list->data), False);
2653 tmp_list = tmp_list->next;
2658 * gdk_x11_register_standard_event_type:
2659 * @display: a #GdkDisplay
2660 * @event_base: first event type code to register
2661 * @n_events: number of event type codes to register
2663 * Registers interest in receiving extension events with type codes
2664 * between @event_base and <literal>event_base + n_events - 1</literal>.
2665 * The registered events must have the window field in the same place
2666 * as core X events (this is not the case for e.g. XKB extension events).
2668 * If an event type is registered, events of this type will go through
2669 * global and window-specific filters (see gdk_window_add_filter()).
2670 * Unregistered events will only go through global filters.
2671 * GDK may register the events of some X extensions on its own.
2673 * This function should only be needed in unusual circumstances, e.g.
2674 * when filtering XInput extension events on the root window.
2679 gdk_x11_register_standard_event_type (GdkDisplay *display,
2683 GdkEventTypeX11 *event_type;
2684 GdkDisplayX11 *display_x11;
2686 display_x11 = GDK_DISPLAY_X11 (display);
2687 event_type = g_new (GdkEventTypeX11, 1);
2689 event_type->base = event_base;
2690 event_type->n_events = n_events;
2692 display_x11->event_types = g_slist_prepend (display_x11->event_types, event_type);
2695 /* compare X sequence numbers handling wraparound */
2696 #define SEQUENCE_COMPARE(a,op,b) (((long) (a) - (long) (b)) op 0)
2698 /* delivers an error event from the error handler in gdkmain-x11.c */
2700 _gdk_x11_display_error_event (GdkDisplay *display,
2703 GdkDisplayX11 *display_x11;
2707 display_x11 = GDK_DISPLAY_X11 (display);
2710 for (tmp_list = display_x11->error_traps;
2712 tmp_list = tmp_list->next)
2716 trap = tmp_list->data;
2718 if (SEQUENCE_COMPARE (trap->start_sequence, <=, error->serial) &&
2719 (trap->end_sequence == 0 ||
2720 SEQUENCE_COMPARE (trap->end_sequence, >, error->serial)))
2723 trap->error_code = error->error_code;
2732 XGetErrorText (display_x11->xdisplay, error->error_code, buf, 63);
2735 g_strdup_printf ("The program '%s' received an X Window System error.\n"
2736 "This probably reflects a bug in the program.\n"
2737 "The error was '%s'.\n"
2738 " (Details: serial %ld error_code %d request_code %d minor_code %d)\n"
2739 " (Note to programmers: normally, X errors are reported asynchronously;\n"
2740 " that is, you will receive the error a while after causing it.\n"
2741 " To debug your program, run it with the --sync command line\n"
2742 " option to change this behavior. You can then get a meaningful\n"
2743 " backtrace from your debugger if you break on the gdk_x_error() function.)",
2748 error->request_code,
2751 #ifdef G_ENABLE_DEBUG
2752 g_error ("%s", msg);
2753 #else /* !G_ENABLE_DEBUG */
2754 g_fprintf (stderr, "%s\n", msg);
2757 #endif /* G_ENABLE_DEBUG */
2762 delete_outdated_error_traps (GdkDisplayX11 *display_x11)
2765 gulong processed_sequence;
2767 processed_sequence = XLastKnownRequestProcessed (display_x11->xdisplay);
2769 tmp_list = display_x11->error_traps;
2770 while (tmp_list != NULL)
2772 GdkErrorTrap *trap = tmp_list->data;
2774 if (trap->end_sequence != 0 &&
2775 SEQUENCE_COMPARE (trap->end_sequence, <, processed_sequence))
2777 GSList *free_me = tmp_list;
2779 tmp_list = tmp_list->next;
2780 display_x11->error_traps =
2781 g_slist_delete_link (display_x11->error_traps, free_me);
2782 g_slice_free (GdkErrorTrap, trap);
2786 tmp_list = tmp_list->next;
2792 * gdk_x11_display_error_trap_push:
2794 * Begins a range of X requests for which X error events will be
2795 * ignored. Unignored errors (when no trap is pushed) will abort the
2798 * See also gdk_error_trap_push() to push a trap on all displays.
2803 gdk_x11_display_error_trap_push (GdkDisplay *display)
2805 GdkDisplayX11 *display_x11;
2808 display_x11 = GDK_DISPLAY_X11 (display);
2810 delete_outdated_error_traps (display_x11);
2812 /* set up the Xlib callback to tell us about errors */
2813 _gdk_x11_error_handler_push ();
2815 trap = g_slice_new0 (GdkErrorTrap);
2817 trap->start_sequence = XNextRequest (display_x11->xdisplay);
2818 trap->error_code = Success;
2820 display_x11->error_traps =
2821 g_slist_prepend (display_x11->error_traps, trap);
2825 gdk_x11_display_error_trap_pop_internal (GdkDisplay *display,
2828 GdkDisplayX11 *display_x11;
2833 display_x11 = GDK_DISPLAY_X11 (display);
2835 g_return_val_if_fail (display_x11->error_traps != NULL, Success);
2837 /* Find the first trap that hasn't been popped already */
2838 trap = NULL; /* quiet gcc */
2839 for (tmp_list = display_x11->error_traps;
2841 tmp_list = tmp_list->next)
2843 trap = tmp_list->data;
2845 if (trap->end_sequence == 0)
2849 g_return_val_if_fail (trap != NULL, Success);
2850 g_assert (trap->end_sequence == 0);
2852 /* May need to sync to fill in trap->error_code if we care about
2853 * getting an error code.
2857 gulong processed_sequence;
2858 gulong next_sequence;
2860 next_sequence = XNextRequest (display_x11->xdisplay);
2861 processed_sequence = XLastKnownRequestProcessed (display_x11->xdisplay);
2863 /* If our last request was already processed, there is no point
2864 * in syncing. i.e. if last request was a round trip (or even if
2865 * we got an event with the serial of a non-round-trip)
2867 if ((next_sequence - 1) != processed_sequence)
2869 XSync (display_x11->xdisplay, False);
2872 result = trap->error_code;
2879 /* record end of trap, giving us a range of
2880 * error sequences we'll ignore.
2882 trap->end_sequence = XNextRequest (display_x11->xdisplay);
2884 /* remove the Xlib callback */
2885 _gdk_x11_error_handler_pop ();
2887 /* we may already be outdated */
2888 delete_outdated_error_traps (display_x11);
2894 * gdk_x11_display_error_trap_pop:
2895 * @display: the display
2897 * Pops the error trap pushed by gdk_x11_display_error_trap_push().
2898 * Will XSync() if necessary and will always block until
2899 * the error is known to have occurred or not occurred,
2900 * so the error code can be returned.
2902 * If you don't need to use the return value,
2903 * gdk_x11_display_error_trap_pop_ignored() would be more efficient.
2905 * See gdk_error_trap_pop() for the all-displays-at-once
2910 * Return value: X error code or 0 on success
2913 gdk_x11_display_error_trap_pop (GdkDisplay *display)
2915 g_return_val_if_fail (GDK_IS_DISPLAY_X11 (display), Success);
2917 return gdk_x11_display_error_trap_pop_internal (display, TRUE);
2921 * gdk_x11_display_error_trap_pop_ignored:
2922 * @display: the display
2924 * Pops the error trap pushed by gdk_x11_display_error_trap_push().
2925 * Does not block to see if an error occurred; merely records the
2926 * range of requests to ignore errors for, and ignores those errors
2927 * if they arrive asynchronously.
2929 * See gdk_error_trap_pop_ignored() for the all-displays-at-once
2935 gdk_x11_display_error_trap_pop_ignored (GdkDisplay *display)
2937 g_return_if_fail (GDK_IS_DISPLAY_X11 (display));
2939 gdk_x11_display_error_trap_pop_internal (display, FALSE);