1 /* GDK - The GIMP Drawing Kit
4 * Copyright 2001 Sun Microsystems Inc.
6 * Erwann Chenede <erwann.chenede@sun.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
26 #include "gdkdisplay.h"
27 #include "gdkdisplayprivate.h"
29 #include "gdkdeviceprivate.h"
30 #include "gdkevents.h"
31 #include "gdkwindowimpl.h"
32 #include "gdkinternals.h"
33 #include "gdkmarshalers.h"
34 #include "gdkscreen.h"
41 * @Short_description: Controls a set of GdkScreens and their associated input devices
44 * #GdkDisplay objects purpose are two fold:
47 * To manage and provide information about input devices (pointers
51 * To manage and provide information about the available #GdkScreens
55 * GdkDisplay objects are the GDK representation of an X Display,
56 * which can be described as <emphasis>a workstation consisting of
57 * a keyboard, a pointing device (such as a mouse) and one or more
59 * It is used to open and keep track of various GdkScreen objects
60 * currently instantiated by the application. It is also used to
61 * access the keyboard(s) and mouse pointer(s) of the display.
63 * Most of the input device handling has been factored out into
64 * the separate #GdkDeviceManager object. Every display has a
65 * device manager, which you can obtain using
66 * gdk_display_get_device_manager().
76 static void gdk_display_dispose (GObject *object);
77 static void gdk_display_finalize (GObject *object);
80 static GdkAppLaunchContext *gdk_display_real_get_app_launch_context (GdkDisplay *display);
82 static guint signals[LAST_SIGNAL] = { 0 };
84 G_DEFINE_TYPE (GdkDisplay, gdk_display, G_TYPE_OBJECT)
87 gdk_display_class_init (GdkDisplayClass *class)
89 GObjectClass *object_class = G_OBJECT_CLASS (class);
91 object_class->finalize = gdk_display_finalize;
92 object_class->dispose = gdk_display_dispose;
94 class->get_app_launch_context = gdk_display_real_get_app_launch_context;
95 class->window_type = GDK_TYPE_WINDOW;
99 * @display: the object on which the signal is emitted
101 * The ::opened signal is emitted when the connection to the windowing
102 * system for @display is opened.
105 g_signal_new (g_intern_static_string ("opened"),
106 G_OBJECT_CLASS_TYPE (object_class),
109 g_cclosure_marshal_VOID__VOID,
113 * GdkDisplay::closed:
114 * @display: the object on which the signal is emitted
115 * @is_error: %TRUE if the display was closed due to an error
117 * The ::closed signal is emitted when the connection to the windowing
118 * system for @display is closed.
123 g_signal_new (g_intern_static_string ("closed"),
124 G_OBJECT_CLASS_TYPE (object_class),
126 G_STRUCT_OFFSET (GdkDisplayClass, closed),
128 _gdk_marshal_VOID__BOOLEAN,
135 free_pointer_info (GdkPointerWindowInfo *info)
137 g_object_unref (info->toplevel_under_pointer);
138 g_slice_free (GdkPointerWindowInfo, info);
142 free_device_grab (GdkDeviceGrabInfo *info)
144 g_object_unref (info->window);
145 g_object_unref (info->native_window);
150 free_device_grabs_foreach (gpointer key,
156 g_list_foreach (list, (GFunc) free_device_grab, NULL);
163 device_removed_cb (GdkDeviceManager *device_manager,
167 g_hash_table_remove (display->multiple_click_info, device);
168 g_hash_table_remove (display->device_grabs, device);
169 g_hash_table_remove (display->pointers_info, device);
171 /* FIXME: change core pointer and remove from device list */
175 gdk_display_opened (GdkDisplay *display)
177 GdkDeviceManager *device_manager;
179 device_manager = gdk_display_get_device_manager (display);
181 g_signal_connect (device_manager, "device-removed",
182 G_CALLBACK (device_removed_cb), display);
186 gdk_display_init (GdkDisplay *display)
188 display->double_click_time = 250;
189 display->double_click_distance = 5;
191 display->device_grabs = g_hash_table_new (NULL, NULL);
192 display->motion_hint_info = g_hash_table_new_full (NULL, NULL, NULL,
193 (GDestroyNotify) g_free);
195 display->pointers_info = g_hash_table_new_full (NULL, NULL, NULL,
196 (GDestroyNotify) free_pointer_info);
198 display->multiple_click_info = g_hash_table_new_full (NULL, NULL, NULL,
199 (GDestroyNotify) g_free);
201 g_signal_connect (display, "opened",
202 G_CALLBACK (gdk_display_opened), NULL);
206 gdk_display_dispose (GObject *object)
208 GdkDisplay *display = GDK_DISPLAY (object);
209 GdkDeviceManager *device_manager;
211 device_manager = gdk_display_get_device_manager (GDK_DISPLAY (object));
213 g_list_foreach (display->queued_events, (GFunc)gdk_event_free, NULL);
214 g_list_free (display->queued_events);
215 display->queued_events = NULL;
216 display->queued_tail = NULL;
220 /* this is to make it drop devices which may require using the X
221 * display and therefore can't be cleaned up in finalize.
222 * It will also disconnect device_removed_cb
224 g_object_run_dispose (G_OBJECT (display->device_manager));
227 G_OBJECT_CLASS (gdk_display_parent_class)->dispose (object);
231 gdk_display_finalize (GObject *object)
233 GdkDisplay *display = GDK_DISPLAY (object);
235 g_hash_table_foreach_remove (display->device_grabs,
236 free_device_grabs_foreach,
238 g_hash_table_destroy (display->device_grabs);
240 g_hash_table_destroy (display->motion_hint_info);
241 g_hash_table_destroy (display->pointers_info);
242 g_hash_table_destroy (display->multiple_click_info);
244 if (display->device_manager)
245 g_object_unref (display->device_manager);
247 G_OBJECT_CLASS (gdk_display_parent_class)->finalize (object);
252 * @display: a #GdkDisplay
254 * Closes the connection to the windowing system for the given display,
255 * and cleans up associated resources.
260 gdk_display_close (GdkDisplay *display)
262 g_return_if_fail (GDK_IS_DISPLAY (display));
264 if (!display->closed)
266 display->closed = TRUE;
268 g_signal_emit (display, signals[CLOSED], 0, FALSE);
269 g_object_run_dispose (G_OBJECT (display));
271 g_object_unref (display);
276 * gdk_display_is_closed:
277 * @display: a #GdkDisplay
279 * Finds out if the display has been closed.
281 * Returns: %TRUE if the display is closed.
286 gdk_display_is_closed (GdkDisplay *display)
288 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
290 return display->closed;
294 * gdk_display_get_event:
295 * @display: a #GdkDisplay
297 * Gets the next #GdkEvent to be processed for @display, fetching events from the
298 * windowing system if necessary.
300 * Return value: the next #GdkEvent to be processed, or %NULL if no events
301 * are pending. The returned #GdkEvent should be freed with gdk_event_free().
306 gdk_display_get_event (GdkDisplay *display)
308 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
310 GDK_DISPLAY_GET_CLASS (display)->queue_events (display);
311 return _gdk_event_unqueue (display);
315 * gdk_display_peek_event:
316 * @display: a #GdkDisplay
318 * Gets a copy of the first #GdkEvent in the @display's event queue, without
319 * removing the event from the queue. (Note that this function will
320 * not get more events from the windowing system. It only checks the events
321 * that have already been moved to the GDK event queue.)
323 * Return value: a copy of the first #GdkEvent on the event queue, or %NULL
324 * if no events are in the queue. The returned #GdkEvent should be freed with
330 gdk_display_peek_event (GdkDisplay *display)
334 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
336 tmp_list = _gdk_event_queue_find_first (display);
339 return gdk_event_copy (tmp_list->data);
345 * gdk_display_put_event:
346 * @display: a #GdkDisplay
347 * @event: a #GdkEvent.
349 * Appends a copy of the given event onto the front of the event
350 * queue for @display.
355 gdk_display_put_event (GdkDisplay *display,
356 const GdkEvent *event)
358 g_return_if_fail (GDK_IS_DISPLAY (display));
359 g_return_if_fail (event != NULL);
361 _gdk_event_queue_append (display, gdk_event_copy (event));
362 /* If the main loop is blocking in a different thread, wake it up */
363 g_main_context_wakeup (NULL);
367 * gdk_display_pointer_ungrab:
368 * @display: a #GdkDisplay.
369 * @time_: a timestap (e.g. %GDK_CURRENT_TIME).
371 * Release any pointer grab.
375 * Deprecated: 3.0: Use gdk_device_ungrab(), together with gdk_device_grab()
379 gdk_display_pointer_ungrab (GdkDisplay *display,
382 GdkDeviceManager *device_manager;
383 GList *devices, *dev;
386 g_return_if_fail (GDK_IS_DISPLAY (display));
388 device_manager = gdk_display_get_device_manager (display);
389 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
391 /* FIXME: Should this be generic to all backends? */
392 /* FIXME: What happens with extended devices? */
393 for (dev = devices; dev; dev = dev->next)
397 if (gdk_device_get_source (device) != GDK_SOURCE_MOUSE)
400 gdk_device_ungrab (device, time_);
403 g_list_free (devices);
407 * gdk_pointer_ungrab:
408 * @time_: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no
409 * timestamp is available.
411 * Ungrabs the pointer on the default display, if it is grabbed by this
414 * Deprecated: 3.0: Use gdk_device_ungrab(), together with gdk_device_grab()
418 gdk_pointer_ungrab (guint32 time)
420 gdk_display_pointer_ungrab (gdk_display_get_default (), time);
424 * gdk_pointer_is_grabbed:
426 * Returns %TRUE if the pointer on the default display is currently
427 * grabbed by this application.
429 * Note that this does not take the inmplicit pointer grab on button
430 * presses into account.
432 * Return value: %TRUE if the pointer is currently grabbed by this application.
434 * Deprecated: 3.0: Use gdk_display_device_is_grabbed() instead.
437 gdk_pointer_is_grabbed (void)
439 return gdk_display_pointer_is_grabbed (gdk_display_get_default ());
443 * gdk_display_keyboard_ungrab:
444 * @display: a #GdkDisplay.
445 * @time_: a timestap (e.g #GDK_CURRENT_TIME).
447 * Release any keyboard grab
451 * Deprecated: 3.0: Use gdk_device_ungrab(), together with gdk_device_grab()
455 gdk_display_keyboard_ungrab (GdkDisplay *display,
458 GdkDeviceManager *device_manager;
459 GList *devices, *dev;
462 g_return_if_fail (GDK_IS_DISPLAY (display));
464 device_manager = gdk_display_get_device_manager (display);
465 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
467 /* FIXME: Should this be generic to all backends? */
468 /* FIXME: What happens with extended devices? */
469 for (dev = devices; dev; dev = dev->next)
473 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
476 gdk_device_ungrab (device, time);
479 g_list_free (devices);
483 * gdk_keyboard_ungrab:
484 * @time_: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no
485 * timestamp is available.
487 * Ungrabs the keyboard on the default display, if it is grabbed by this
490 * Deprecated: 3.0: Use gdk_device_ungrab(), together with gdk_device_grab()
494 gdk_keyboard_ungrab (guint32 time)
496 gdk_display_keyboard_ungrab (gdk_display_get_default (), time);
502 * Emits a short beep on the default display.
507 gdk_display_beep (gdk_display_get_default ());
513 * Flushes the output buffers of all display connections and waits
514 * until all requests have been processed.
515 * This is rarely needed by applications.
522 list = gdk_display_manager_list_displays (gdk_display_manager_get ());
523 for (l = list; l; l = l->next)
525 GdkDisplay *display = l->data;
527 GDK_DISPLAY_GET_CLASS (display)->sync (display);
534 _gdk_display_enable_motion_hints (GdkDisplay *display,
537 gulong *device_serial, serial;
539 device_serial = g_hash_table_lookup (display->motion_hint_info, device);
543 device_serial = g_new0 (gulong, 1);
544 *device_serial = G_MAXULONG;
545 g_hash_table_insert (display->motion_hint_info, device, device_serial);
548 if (*device_serial != 0)
550 serial = _gdk_display_get_next_serial (display);
551 /* We might not actually generate the next request, so
552 make sure this triggers always, this may cause it to
553 trigger slightly too early, but this is just a hint
557 if (serial < *device_serial)
558 *device_serial = serial;
563 * gdk_display_get_pointer:
564 * @display: a #GdkDisplay
565 * @screen: (out) (allow-none): location to store the screen that the
566 * cursor is on, or %NULL.
567 * @x: (out) (allow-none): location to store root window X coordinate of pointer, or %NULL.
568 * @y: (out) (allow-none): location to store root window Y coordinate of pointer, or %NULL.
569 * @mask: (out) (allow-none): location to store current modifier mask, or %NULL
571 * Gets the current location of the pointer and the current modifier
572 * mask for a given display.
576 * Deprecated: 3.0: Use gdk_device_get_position() instead.
579 gdk_display_get_pointer (GdkDisplay *display,
583 GdkModifierType *mask)
585 GdkScreen *default_screen;
588 GdkModifierType tmp_mask;
590 g_return_if_fail (GDK_IS_DISPLAY (display));
592 if (gdk_display_is_closed (display))
595 default_screen = gdk_display_get_default_screen (display);
597 /* We call _gdk_device_query_state() here manually instead of
598 * gdk_device_get_position() because we care about the modifier mask */
600 _gdk_device_query_state (display->core_pointer,
601 gdk_screen_get_root_window (default_screen),
608 *screen = gdk_window_get_screen (root);
618 * gdk_display_get_window_at_pointer:
619 * @display: a #GdkDisplay
620 * @win_x: (out) (allow-none): return location for x coordinate of the pointer location relative
621 * to the window origin, or %NULL
622 * @win_y: (out) (allow-none): return location for y coordinate of the pointer location relative
623 & to the window origin, or %NULL
625 * Obtains the window underneath the mouse pointer, returning the location
626 * of the pointer in that window in @win_x, @win_y for @screen. Returns %NULL
627 * if the window under the mouse pointer is not known to GDK (for example,
628 * belongs to another application).
630 * Returns: (transfer none): the window under the mouse pointer, or %NULL
634 * Deprecated: 3.0: Use gdk_device_get_window_at_position() instead.
637 gdk_display_get_window_at_pointer (GdkDisplay *display,
641 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
643 return gdk_device_get_window_at_position (display->core_pointer, win_x, win_y);
647 generate_grab_broken_event (GdkWindow *window,
650 GdkWindow *grab_window)
652 g_return_if_fail (window != NULL);
654 if (!GDK_WINDOW_DESTROYED (window))
658 event = gdk_event_new (GDK_GRAB_BROKEN);
659 event->grab_broken.window = g_object_ref (window);
660 event->grab_broken.send_event = FALSE;
661 event->grab_broken.implicit = implicit;
662 event->grab_broken.grab_window = grab_window;
663 gdk_event_set_device (event, device);
664 event->grab_broken.keyboard = (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD) ? TRUE : FALSE;
666 gdk_event_put (event);
667 gdk_event_free (event);
672 _gdk_display_get_last_device_grab (GdkDisplay *display,
677 l = g_hash_table_lookup (display->device_grabs, device);
689 _gdk_display_add_device_grab (GdkDisplay *display,
692 GdkWindow *native_window,
693 GdkGrabOwnership grab_ownership,
694 gboolean owner_events,
695 GdkEventMask event_mask,
696 unsigned long serial_start,
700 GdkDeviceGrabInfo *info, *other_info;
703 info = g_new0 (GdkDeviceGrabInfo, 1);
705 info->window = g_object_ref (window);
706 info->native_window = g_object_ref (native_window);
707 info->serial_start = serial_start;
708 info->serial_end = G_MAXULONG;
709 info->owner_events = owner_events;
710 info->event_mask = event_mask;
712 info->implicit = implicit;
713 info->ownership = grab_ownership;
715 grabs = g_hash_table_lookup (display->device_grabs, device);
717 /* Find the first grab that has a larger start time (if any) and insert
718 * before that. I.E we insert after already existing grabs with same
720 for (l = grabs; l != NULL; l = l->next)
722 other_info = l->data;
724 if (info->serial_start < other_info->serial_start)
728 grabs = g_list_insert_before (grabs, l, info);
730 /* Make sure the new grab end before next grab */
733 other_info = l->data;
734 info->serial_end = other_info->serial_start;
737 /* Find any previous grab and update its end time */
738 l = g_list_find (grabs, info);
742 other_info = l->data;
743 other_info->serial_end = serial_start;
746 g_hash_table_insert (display->device_grabs, device, grabs);
751 /* _gdk_synthesize_crossing_events only works inside one toplevel.
752 This function splits things into two calls if needed, converting the
753 coordinates to the right toplevel */
755 synthesize_crossing_events (GdkDisplay *display,
757 GdkDevice *source_device,
758 GdkWindow *src_window,
759 GdkWindow *dest_window,
760 GdkCrossingMode crossing_mode,
764 GdkWindow *src_toplevel, *dest_toplevel;
765 GdkModifierType state;
769 src_toplevel = gdk_window_get_toplevel (src_window);
773 dest_toplevel = gdk_window_get_toplevel (dest_window);
775 dest_toplevel = NULL;
777 if (src_toplevel == NULL && dest_toplevel == NULL)
780 if (src_toplevel == NULL ||
781 src_toplevel == dest_toplevel)
784 gdk_window_get_pointer (dest_toplevel,
786 _gdk_synthesize_crossing_events (display,
789 device, source_device,
796 else if (dest_toplevel == NULL)
798 gdk_window_get_pointer (src_toplevel,
800 _gdk_synthesize_crossing_events (display,
803 device, source_device,
812 /* Different toplevels */
813 gdk_window_get_pointer (src_toplevel,
815 _gdk_synthesize_crossing_events (display,
818 device, source_device,
824 gdk_window_get_pointer (dest_toplevel,
826 _gdk_synthesize_crossing_events (display,
829 device, source_device,
839 get_current_toplevel (GdkDisplay *display,
843 GdkModifierType *state_out)
845 GdkWindow *pointer_window;
847 GdkModifierType state;
849 pointer_window = _gdk_device_window_at_position (device, &x, &y, &state, TRUE);
851 if (pointer_window != NULL &&
852 (GDK_WINDOW_DESTROYED (pointer_window) ||
853 GDK_WINDOW_TYPE (pointer_window) == GDK_WINDOW_ROOT ||
854 GDK_WINDOW_TYPE (pointer_window) == GDK_WINDOW_FOREIGN))
855 pointer_window = NULL;
861 return pointer_window;
865 switch_to_pointer_grab (GdkDisplay *display,
867 GdkDevice *source_device,
868 GdkDeviceGrabInfo *grab,
869 GdkDeviceGrabInfo *last_grab,
873 GdkWindow *src_window, *pointer_window, *new_toplevel;
874 GdkPointerWindowInfo *info;
876 GdkModifierType state;
879 /* Temporarily unset pointer to make sure we send the crossing events below */
880 old_grabs = g_hash_table_lookup (display->device_grabs, device);
881 g_hash_table_steal (display->device_grabs, device);
882 info = _gdk_display_get_pointer_info (display, device);
886 /* New grab is in effect */
888 /* We need to generate crossing events for the grab.
889 * However, there are never any crossing events for implicit grabs
890 * TODO: ... Actually, this could happen if the pointer window
891 * doesn't have button mask so a parent gets the event...
895 /* We send GRAB crossing events from the window under the pointer to the
896 grab window. Except if there is an old grab then we start from that */
898 src_window = last_grab->window;
900 src_window = info->window_under_pointer;
902 if (src_window != grab->window)
903 synthesize_crossing_events (display, device, source_device,
904 src_window, grab->window,
905 GDK_CROSSING_GRAB, time, serial);
907 /* !owner_event Grabbing a window that we're not inside, current status is
908 now NULL (i.e. outside grabbed window) */
909 if (!grab->owner_events && info->window_under_pointer != grab->window)
910 _gdk_display_set_window_under_pointer (display, device, NULL);
913 grab->activated = TRUE;
920 if (grab == NULL /* ungrab */ ||
921 (!last_grab->owner_events && grab->owner_events) /* switched to owner_events */ )
923 /* We force check what window we're in, and update the toplevel_under_pointer info,
924 * as that won't get told of this change with toplevel enter events.
926 if (info->toplevel_under_pointer)
927 g_object_unref (info->toplevel_under_pointer);
928 info->toplevel_under_pointer = NULL;
930 /* Ungrabbed slave devices don't have a position by
931 * itself, rather depend on its master pointer, so
932 * it doesn't make sense to track any position for
933 * these after the grab
935 if (grab || gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_SLAVE)
936 new_toplevel = get_current_toplevel (display, device, &x, &y, &state);
940 /* w is now toplevel and x,y in toplevel coords */
941 info->toplevel_under_pointer = g_object_ref (new_toplevel);
942 info->toplevel_x = x;
943 info->toplevel_y = y;
948 if (grab == NULL) /* Ungrabbed, send events */
950 pointer_window = NULL;
953 /* Find (possibly virtual) child window */
955 _gdk_window_find_descendant_at (new_toplevel,
960 if (pointer_window != last_grab->window)
961 synthesize_crossing_events (display, device, source_device,
962 last_grab->window, pointer_window,
963 GDK_CROSSING_UNGRAB, time, serial);
965 /* We're now ungrabbed, update the window_under_pointer */
966 _gdk_display_set_window_under_pointer (display, device, pointer_window);
970 g_hash_table_insert (display->device_grabs, device, old_grabs);
974 _gdk_display_device_grab_update (GdkDisplay *display,
976 GdkDevice *source_device,
977 gulong current_serial)
979 GdkDeviceGrabInfo *current_grab, *next_grab;
983 time = display->last_event_time;
984 grabs = g_hash_table_lookup (display->device_grabs, device);
986 while (grabs != NULL)
988 current_grab = grabs->data;
990 if (current_grab->serial_start > current_serial)
991 return; /* Hasn't started yet */
993 if (current_grab->serial_end > current_serial)
995 /* This one hasn't ended yet.
996 its the currently active one or scheduled to be active */
998 if (!current_grab->activated)
1000 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
1001 switch_to_pointer_grab (display, device, source_device, current_grab, NULL, time, current_serial);
1010 /* This is the next active grab */
1011 next_grab = grabs->next->data;
1013 if (next_grab->serial_start > current_serial)
1014 next_grab = NULL; /* Actually its not yet active */
1017 if ((next_grab == NULL && current_grab->implicit_ungrab) ||
1018 (next_grab != NULL && current_grab->window != next_grab->window))
1019 generate_grab_broken_event (GDK_WINDOW (current_grab->window),
1021 current_grab->implicit,
1022 next_grab? next_grab->window : NULL);
1024 /* Remove old grab */
1025 grabs = g_list_delete_link (grabs, grabs);
1026 g_hash_table_insert (display->device_grabs, device, grabs);
1028 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
1029 switch_to_pointer_grab (display, device, source_device,
1030 next_grab, current_grab,
1031 time, current_serial);
1033 free_device_grab (current_grab);
1038 grab_list_find (GList *grabs,
1041 GdkDeviceGrabInfo *grab;
1047 if (serial >= grab->serial_start && serial < grab->serial_end)
1050 grabs = grabs->next;
1057 find_device_grab (GdkDisplay *display,
1063 l = g_hash_table_lookup (display->device_grabs, device);
1064 return grab_list_find (l, serial);
1068 _gdk_display_has_device_grab (GdkDisplay *display,
1074 l = find_device_grab (display, device, serial);
1081 /* Returns true if last grab was ended
1082 * If if_child is non-NULL, end the grab only if the grabbed
1083 * window is the same as if_child or a descendant of it */
1085 _gdk_display_end_device_grab (GdkDisplay *display,
1088 GdkWindow *if_child,
1091 GdkDeviceGrabInfo *grab;
1094 l = find_device_grab (display, device, serial);
1101 (if_child == NULL ||
1102 _gdk_window_event_parent_of (if_child, grab->window)))
1104 grab->serial_end = serial;
1105 grab->implicit_ungrab = implicit;
1106 return l->next == NULL;
1112 /* Returns TRUE if device events are not blocked by any grab */
1114 _gdk_display_check_grab_ownership (GdkDisplay *display,
1118 GHashTableIter iter;
1119 gpointer key, value;
1120 GdkGrabOwnership higher_ownership, device_ownership;
1121 gboolean device_is_keyboard;
1123 g_hash_table_iter_init (&iter, display->device_grabs);
1124 higher_ownership = device_ownership = GDK_OWNERSHIP_NONE;
1125 device_is_keyboard = (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD);
1127 while (g_hash_table_iter_next (&iter, &key, &value))
1129 GdkDeviceGrabInfo *grab;
1135 grabs = grab_list_find (grabs, serial);
1140 /* Discard device if it's not of the same type */
1141 if ((device_is_keyboard && gdk_device_get_source (dev) != GDK_SOURCE_KEYBOARD) ||
1142 (!device_is_keyboard && gdk_device_get_source (dev) == GDK_SOURCE_KEYBOARD))
1148 device_ownership = grab->ownership;
1151 if (grab->ownership > higher_ownership)
1152 higher_ownership = grab->ownership;
1156 if (higher_ownership > device_ownership)
1158 /* There's a higher priority ownership
1159 * going on for other device(s)
1167 GdkPointerWindowInfo *
1168 _gdk_display_get_pointer_info (GdkDisplay *display,
1171 GdkPointerWindowInfo *info;
1173 if (G_UNLIKELY (!device))
1176 info = g_hash_table_lookup (display->pointers_info, device);
1178 if (G_UNLIKELY (!info))
1180 info = g_slice_new0 (GdkPointerWindowInfo);
1181 g_hash_table_insert (display->pointers_info, device, info);
1188 _gdk_display_pointer_info_foreach (GdkDisplay *display,
1189 GdkDisplayPointerInfoForeach func,
1192 GHashTableIter iter;
1193 gpointer key, value;
1195 g_hash_table_iter_init (&iter, display->pointers_info);
1197 while (g_hash_table_iter_next (&iter, &key, &value))
1199 GdkPointerWindowInfo *info = value;
1200 GdkDevice *device = key;
1202 (func) (display, device, info, user_data);
1207 * gdk_device_grab_info_libgtk_only:
1208 * @display: the display for which to get the grab information
1209 * @device: device to get the grab information from
1210 * @grab_window: (out) (transfer none): location to store current grab window
1211 * @owner_events: (out): location to store boolean indicating whether
1212 * the @owner_events flag to gdk_keyboard_grab() or
1213 * gdk_pointer_grab() was %TRUE.
1215 * Determines information about the current keyboard grab.
1216 * This is not public API and must not be used by applications.
1218 * Return value: %TRUE if this application currently has the
1222 gdk_device_grab_info_libgtk_only (GdkDisplay *display,
1224 GdkWindow **grab_window,
1225 gboolean *owner_events)
1227 GdkDeviceGrabInfo *info;
1229 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1230 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
1232 info = _gdk_display_get_last_device_grab (display, device);
1237 *grab_window = info->window;
1239 *owner_events = info->owner_events;
1248 * gdk_display_pointer_is_grabbed:
1249 * @display: a #GdkDisplay
1251 * Test if the pointer is grabbed.
1253 * Returns: %TRUE if an active X pointer grab is in effect
1257 * Deprecated: 3.0: Use gdk_display_device_is_grabbed() instead.
1260 gdk_display_pointer_is_grabbed (GdkDisplay *display)
1262 GdkDeviceManager *device_manager;
1263 GList *devices, *dev;
1266 g_return_val_if_fail (GDK_IS_DISPLAY (display), TRUE);
1268 device_manager = gdk_display_get_device_manager (display);
1269 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
1271 for (dev = devices; dev; dev = dev->next)
1275 if (gdk_device_get_source (device) == GDK_SOURCE_MOUSE &&
1276 gdk_display_device_is_grabbed (display, device))
1284 * gdk_display_device_is_grabbed:
1285 * @display: a #GdkDisplay
1286 * @device: a #GdkDevice
1288 * Returns %TRUE if there is an ongoing grab on @device for @display.
1290 * Returns: %TRUE if there is a grab in effect for @device.
1293 gdk_display_device_is_grabbed (GdkDisplay *display,
1296 GdkDeviceGrabInfo *info;
1298 g_return_val_if_fail (GDK_IS_DISPLAY (display), TRUE);
1299 g_return_val_if_fail (GDK_IS_DEVICE (device), TRUE);
1301 /* What we're interested in is the steady state (ie last grab),
1302 because we're interested e.g. if we grabbed so that we
1303 can ungrab, even if our grab is not active just yet. */
1304 info = _gdk_display_get_last_device_grab (display, device);
1306 return (info && !info->implicit);
1310 * gdk_display_get_device_manager:
1311 * @display: a #GdkDisplay.
1313 * Returns the #GdkDeviceManager associated to @display.
1315 * Returns: (transfer none): A #GdkDeviceManager, or %NULL. This memory is
1316 * owned by GDK and must not be freed or unreferenced.
1321 gdk_display_get_device_manager (GdkDisplay *display)
1323 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1325 return display->device_manager;
1329 * gdk_display_get_name:
1330 * @display: a #GdkDisplay
1332 * Gets the name of the display.
1334 * Returns: a string representing the display name. This string is owned
1335 * by GDK and should not be modified or freed.
1339 G_CONST_RETURN gchar *
1340 gdk_display_get_name (GdkDisplay *display)
1342 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1344 return GDK_DISPLAY_GET_CLASS (display)->get_name (display);
1348 gdk_get_display (void)
1350 return g_strdup (gdk_display_get_name (gdk_display_get_default ()));
1354 * gdk_display_get_n_screens:
1355 * @display: a #GdkDisplay
1357 * Gets the number of screen managed by the @display.
1359 * Returns: number of screens.
1364 gdk_display_get_n_screens (GdkDisplay *display)
1366 g_return_val_if_fail (GDK_IS_DISPLAY (display), 0);
1368 return GDK_DISPLAY_GET_CLASS (display)->get_n_screens (display);
1372 * gdk_display_get_screen:
1373 * @display: a #GdkDisplay
1374 * @screen_num: the screen number
1376 * Returns a screen object for one of the screens of the display.
1378 * Returns: (transfer none): the #GdkScreen object
1383 gdk_display_get_screen (GdkDisplay *display,
1386 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1388 return GDK_DISPLAY_GET_CLASS (display)->get_screen (display, screen_num);
1392 * gdk_display_get_default_screen:
1393 * @display: a #GdkDisplay
1395 * Get the default #GdkScreen for @display.
1397 * Returns: (transfer none): the default #GdkScreen object for @display
1402 gdk_display_get_default_screen (GdkDisplay *display)
1404 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1406 return GDK_DISPLAY_GET_CLASS (display)->get_default_screen (display);
1411 * @display: a #GdkDisplay
1413 * Emits a short beep on @display
1418 gdk_display_beep (GdkDisplay *display)
1420 g_return_if_fail (GDK_IS_DISPLAY (display));
1422 GDK_DISPLAY_GET_CLASS (display)->beep (display);
1427 * @display: a #GdkDisplay
1429 * Flushes any requests queued for the windowing system and waits until all
1430 * requests have been handled. This is often used for making sure that the
1431 * display is synchronized with the current state of the program. Calling
1432 * gdk_display_sync() before gdk_error_trap_pop() makes sure that any errors
1433 * generated from earlier requests are handled before the error trap is
1436 * This is most useful for X11. On windowing systems where requests are
1437 * handled synchronously, this function will do nothing.
1442 gdk_display_sync (GdkDisplay *display)
1444 g_return_if_fail (GDK_IS_DISPLAY (display));
1446 GDK_DISPLAY_GET_CLASS (display)->sync (display);
1450 * gdk_display_flush:
1451 * @display: a #GdkDisplay
1453 * Flushes any requests queued for the windowing system; this happens automatically
1454 * when the main loop blocks waiting for new events, but if your application
1455 * is drawing without returning control to the main loop, you may need
1456 * to call this function explicitely. A common case where this function
1457 * needs to be called is when an application is executing drawing commands
1458 * from a thread other than the thread where the main loop is running.
1460 * This is most useful for X11. On windowing systems where requests are
1461 * handled synchronously, this function will do nothing.
1466 gdk_display_flush (GdkDisplay *display)
1468 g_return_if_fail (GDK_IS_DISPLAY (display));
1470 GDK_DISPLAY_GET_CLASS (display)->flush (display);
1474 * gdk_display_get_default_group:
1475 * @display: a #GdkDisplay
1477 * Returns the default group leader window for all toplevel windows
1478 * on @display. This window is implicitly created by GDK.
1479 * See gdk_window_set_group().
1481 * Return value: (transfer none): The default group leader window
1487 gdk_display_get_default_group (GdkDisplay *display)
1489 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1491 return GDK_DISPLAY_GET_CLASS (display)->get_default_group (display);
1495 * gdk_display_supports_selection_notification:
1496 * @display: a #GdkDisplay
1498 * Returns whether #GdkEventOwnerChange events will be
1499 * sent when the owner of a selection changes.
1501 * Return value: whether #GdkEventOwnerChange events will
1507 gdk_display_supports_selection_notification (GdkDisplay *display)
1509 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1511 return GDK_DISPLAY_GET_CLASS (display)->supports_selection_notification (display);
1515 * gdk_display_request_selection_notification:
1516 * @display: a #GdkDisplay
1517 * @selection: the #GdkAtom naming the selection for which
1518 * ownership change notification is requested
1520 * Request #GdkEventOwnerChange events for ownership changes
1521 * of the selection named by the given atom.
1523 * Return value: whether #GdkEventOwnerChange events will
1529 gdk_display_request_selection_notification (GdkDisplay *display,
1533 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1535 return GDK_DISPLAY_GET_CLASS (display)->request_selection_notification (display, selection);
1539 * gdk_display_supports_clipboard_persistence
1540 * @display: a #GdkDisplay
1542 * Returns whether the speicifed display supports clipboard
1543 * persistance; i.e. if it's possible to store the clipboard data after an
1544 * application has quit. On X11 this checks if a clipboard daemon is
1547 * Returns: %TRUE if the display supports clipboard persistance.
1552 gdk_display_supports_clipboard_persistence (GdkDisplay *display)
1554 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1556 return GDK_DISPLAY_GET_CLASS (display)->supports_clipboard_persistence (display);
1560 * gdk_display_store_clipboard
1561 * @display: a #GdkDisplay
1562 * @clipboard_window: a #GdkWindow belonging to the clipboard owner
1563 * @time_: a timestamp
1564 * @targets: (array length=n_targets): an array of targets
1565 * that should be saved, or %NULL
1566 * if all available targets should be saved.
1567 * @n_targets: length of the @targets array
1569 * Issues a request to the clipboard manager to store the
1570 * clipboard data. On X11, this is a special program that works
1571 * according to the freedesktop clipboard specification, available at
1572 * <ulink url="http://www.freedesktop.org/Standards/clipboard-manager-spec">
1573 * http://www.freedesktop.org/Standards/clipboard-manager-spec</ulink>.
1578 gdk_display_store_clipboard (GdkDisplay *display,
1579 GdkWindow *clipboard_window,
1581 const GdkAtom *targets,
1584 g_return_if_fail (GDK_IS_DISPLAY (display));
1586 GDK_DISPLAY_GET_CLASS (display)->store_clipboard (display, clipboard_window, time_, targets, n_targets);
1590 * gdk_display_supports_shapes:
1591 * @display: a #GdkDisplay
1593 * Returns %TRUE if gdk_window_shape_combine_mask() can
1594 * be used to create shaped windows on @display.
1596 * Returns: %TRUE if shaped windows are supported
1601 gdk_display_supports_shapes (GdkDisplay *display)
1603 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1605 return GDK_DISPLAY_GET_CLASS (display)->supports_shapes (display);
1609 * gdk_display_supports_input_shapes:
1610 * @display: a #GdkDisplay
1612 * Returns %TRUE if gdk_window_input_shape_combine_mask() can
1613 * be used to modify the input shape of windows on @display.
1615 * Returns: %TRUE if windows with modified input shape are supported
1620 gdk_display_supports_input_shapes (GdkDisplay *display)
1622 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1624 return GDK_DISPLAY_GET_CLASS (display)->supports_input_shapes (display);
1628 * gdk_display_supports_composite:
1629 * @display: a #GdkDisplay
1631 * Returns %TRUE if gdk_window_set_composited() can be used
1632 * to redirect drawing on the window using compositing.
1634 * Currently this only works on X11 with XComposite and
1635 * XDamage extensions available.
1637 * Returns: %TRUE if windows may be composited.
1642 gdk_display_supports_composite (GdkDisplay *display)
1644 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1646 return GDK_DISPLAY_GET_CLASS (display)->supports_composite (display);
1650 * gdk_display_list_devices:
1651 * @display: a #GdkDisplay
1653 * Returns the list of available input devices attached to @display.
1654 * The list is statically allocated and should not be freed.
1656 * Return value: (transfer none) (element-type GdkDevice):
1657 * a list of #GdkDevice
1661 * Deprecated: 3.0: Use gdk_device_manager_list_devices() instead.
1664 gdk_display_list_devices (GdkDisplay *display)
1666 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1668 return GDK_DISPLAY_GET_CLASS (display)->list_devices (display);
1671 static GdkAppLaunchContext *
1672 gdk_display_real_get_app_launch_context (GdkDisplay *display)
1674 GdkAppLaunchContext *ctx;
1676 ctx = g_object_new (GDK_TYPE_APP_LAUNCH_CONTEXT,
1684 * gdk_display_get_app_launch_context:
1685 * @display: a #GdkDisplay
1687 * Returns a #GdkAppLaunchContext suitable for launching
1688 * applications on the given display.
1690 * Returns: (transfer full): a new #GdkAppLaunchContext for @display.
1691 * Free with g_object_unref() when done
1695 GdkAppLaunchContext *
1696 gdk_display_get_app_launch_context (GdkDisplay *display)
1698 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1700 return GDK_DISPLAY_GET_CLASS (display)->get_app_launch_context (display);
1705 * @display_name: the name of the display to open
1709 * Return value: (transfer none): a #GdkDisplay, or %NULL
1710 * if the display could not be opened
1715 gdk_display_open (const gchar *display_name)
1717 return gdk_display_manager_open_display (gdk_display_manager_get (),
1722 * gdk_display_has_pending:
1723 * @display: a #GdkDisplay
1725 * Returns whether the display has events that are waiting
1728 * Returns: %TRUE if there are events ready to be processed.
1733 gdk_display_has_pending (GdkDisplay *display)
1735 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1737 return GDK_DISPLAY_GET_CLASS (display)->has_pending (display);
1741 * gdk_display_supports_cursor_alpha:
1742 * @display: a #GdkDisplay
1744 * Returns %TRUE if cursors can use an 8bit alpha channel
1745 * on @display. Otherwise, cursors are restricted to bilevel
1746 * alpha (i.e. a mask).
1748 * Returns: whether cursors can have alpha channels.
1753 gdk_display_supports_cursor_alpha (GdkDisplay *display)
1755 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1757 return GDK_DISPLAY_GET_CLASS (display)->supports_cursor_alpha (display);
1761 * gdk_display_supports_cursor_color:
1762 * @display: a #GdkDisplay
1764 * Returns %TRUE if multicolored cursors are supported
1765 * on @display. Otherwise, cursors have only a forground
1766 * and a background color.
1768 * Returns: whether cursors can have multiple colors.
1773 gdk_display_supports_cursor_color (GdkDisplay *display)
1775 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1777 return GDK_DISPLAY_GET_CLASS (display)->supports_cursor_color (display);
1781 * gdk_display_get_default_cursor_size:
1782 * @display: a #GdkDisplay
1784 * Returns the default size to use for cursors on @display.
1786 * Returns: the default cursor size.
1791 gdk_display_get_default_cursor_size (GdkDisplay *display)
1793 guint width, height;
1795 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1797 GDK_DISPLAY_GET_CLASS (display)->get_default_cursor_size (display,
1801 return MIN (width, height);
1805 * gdk_display_get_maximal_cursor_size:
1806 * @display: a #GdkDisplay
1807 * @width: (out): the return location for the maximal cursor width
1808 * @height: (out): the return location for the maximal cursor height
1810 * Gets the maximal size to use for cursors on @display.
1815 gdk_display_get_maximal_cursor_size (GdkDisplay *display,
1819 g_return_if_fail (GDK_IS_DISPLAY (display));
1821 GDK_DISPLAY_GET_CLASS (display)->get_maximal_cursor_size (display,
1827 * gdk_display_warp_pointer:
1828 * @display: a #GdkDisplay
1829 * @screen: the screen of @display to warp the pointer to
1830 * @x: the x coordinate of the destination
1831 * @y: the y coordinate of the destination
1833 * Warps the pointer of @display to the point @x,@y on
1834 * the screen @screen, unless the pointer is confined
1835 * to a window by a grab, in which case it will be moved
1836 * as far as allowed by the grab. Warping the pointer
1837 * creates events as if the user had moved the mouse
1838 * instantaneously to the destination.
1840 * Note that the pointer should normally be under the
1841 * control of the user. This function was added to cover
1842 * some rare use cases like keyboard navigation support
1843 * for the color picker in the #GtkColorSelectionDialog.
1847 * Deprecated: 3.0: Use gdk_device_warp() instead.
1850 gdk_display_warp_pointer (GdkDisplay *display,
1855 g_return_if_fail (GDK_IS_DISPLAY (display));
1857 gdk_device_warp (display->core_pointer,
1863 _gdk_display_get_next_serial (GdkDisplay *display)
1865 return GDK_DISPLAY_GET_CLASS (display)->get_next_serial (display);
1870 * gdk_notify_startup_complete:
1872 * Indicates to the GUI environment that the application has finished
1873 * loading. If the applications opens windows, this function is
1874 * normally called after opening the application's initial set of
1877 * GTK+ will call this function automatically after opening the first
1878 * #GtkWindow unless gtk_window_set_auto_startup_notification() is called
1879 * to disable that feature.
1884 gdk_notify_startup_complete (void)
1886 gdk_notify_startup_complete_with_id (NULL);
1890 * gdk_notify_startup_complete_with_id:
1891 * @startup_id: a startup-notification identifier, for which
1892 * notification process should be completed
1894 * Indicates to the GUI environment that the application has
1895 * finished loading, using a given identifier.
1897 * GTK+ will call this function automatically for #GtkWindow
1898 * with custom startup-notification identifier unless
1899 * gtk_window_set_auto_startup_notification() is called to
1900 * disable that feature.
1905 gdk_notify_startup_complete_with_id (const gchar* startup_id)
1907 GdkDisplay *display;
1909 display = gdk_display_get_default ();
1911 gdk_display_notify_startup_complete (display, startup_id);
1915 * gdk_display_notify_startup_complete:
1916 * @display: a #GdkDisplay
1917 * @startup_id: a startup-notification identifier, for which
1918 * notification process should be completed
1920 * Indicates to the GUI environment that the application has
1921 * finished loading, using a given identifier.
1923 * GTK+ will call this function automatically for #GtkWindow
1924 * with custom startup-notification identifier unless
1925 * gtk_window_set_auto_startup_notification() is called to
1926 * disable that feature.
1931 gdk_display_notify_startup_complete (GdkDisplay *display,
1932 const gchar *startup_id)
1934 g_return_if_fail (GDK_IS_DISPLAY (display));
1936 GDK_DISPLAY_GET_CLASS (display)->notify_startup_complete (display, startup_id);
1940 _gdk_display_event_data_copy (GdkDisplay *display,
1941 const GdkEvent *event,
1942 GdkEvent *new_event)
1944 GDK_DISPLAY_GET_CLASS (display)->event_data_copy (display, event, new_event);
1948 _gdk_display_event_data_free (GdkDisplay *display,
1951 GDK_DISPLAY_GET_CLASS (display)->event_data_free (display, event);
1955 _gdk_display_create_window_impl (GdkDisplay *display,
1957 GdkWindow *real_parent,
1959 GdkEventMask event_mask,
1960 GdkWindowAttr *attributes,
1961 gint attributes_mask)
1963 GDK_DISPLAY_GET_CLASS (display)->create_window_impl (display,
1973 _gdk_display_create_window (GdkDisplay *display)
1975 return g_object_new (GDK_DISPLAY_GET_CLASS (display)->window_type, NULL);
1979 * gdk_keymap_get_for_display:
1980 * @display: the #GdkDisplay.
1982 * Returns the #GdkKeymap attached to @display.
1984 * Return value: (transfer none): the #GdkKeymap attached to @display.
1989 gdk_keymap_get_for_display (GdkDisplay *display)
1991 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1993 return GDK_DISPLAY_GET_CLASS (display)->get_keymap (display);
1996 typedef struct _GdkGlobalErrorTrap GdkGlobalErrorTrap;
1998 struct _GdkGlobalErrorTrap
2003 static GQueue gdk_error_traps = G_QUEUE_INIT;
2006 * gdk_error_trap_push:
2008 * This function allows X errors to be trapped instead of the normal
2009 * behavior of exiting the application. It should only be used if it
2010 * is not possible to avoid the X error in any other way. Errors are
2011 * ignored on all #GdkDisplay currently known to the
2012 * #GdkDisplayManager. If you don't care which error happens and just
2013 * want to ignore everything, pop with gdk_error_trap_pop_ignored().
2014 * If you need the error code, use gdk_error_trap_pop() which may have
2015 * to block and wait for the error to arrive from the X server.
2017 * This API exists on all platforms but only does anything on X.
2019 * You can use gdk_x11_display_error_trap_push() to ignore errors
2020 * on only a single display.
2023 * <title>Trapping an X error</title>
2025 * gdk_error_trap_push (<!-- -->);
2027 * // ... Call the X function which may cause an error here ...
2030 * if (gdk_error_trap_pop (<!-- -->))
2032 * // ... Handle the error here ...
2038 gdk_error_trap_push (void)
2040 GdkDisplayManager *manager;
2041 GdkDisplayClass *class;
2042 GdkGlobalErrorTrap *trap;
2045 manager = gdk_display_manager_get ();
2046 class = GDK_DISPLAY_GET_CLASS (gdk_display_manager_get_default_display (manager));
2048 if (class->push_error_trap == NULL)
2051 trap = g_slice_new (GdkGlobalErrorTrap);
2052 trap->displays = gdk_display_manager_list_displays (manager);
2054 g_slist_foreach (trap->displays, (GFunc) g_object_ref, NULL);
2055 for (l = trap->displays; l != NULL; l = l->next)
2057 class->push_error_trap (l->data);
2060 g_queue_push_head (&gdk_error_traps, trap);
2064 gdk_error_trap_pop_internal (gboolean need_code)
2066 GdkDisplayManager *manager;
2067 GdkDisplayClass *class;
2068 GdkGlobalErrorTrap *trap;
2072 manager = gdk_display_manager_get ();
2073 class = GDK_DISPLAY_GET_CLASS (gdk_display_manager_get_default_display (manager));
2075 if (class->pop_error_trap == NULL)
2078 trap = g_queue_pop_head (&gdk_error_traps);
2080 g_return_val_if_fail (trap != NULL, 0);
2083 for (l = trap->displays; l != NULL; l = l->next)
2087 code = class->pop_error_trap (l->data, !need_code);
2089 /* we use the error on the last display listed, why not. */
2094 g_slist_free_full (trap->displays, g_object_unref);
2095 g_slice_free (GdkGlobalErrorTrap, trap);
2101 * gdk_error_trap_pop_ignored:
2103 * Removes an error trap pushed with gdk_error_trap_push(), but
2104 * without bothering to wait and see whether an error occurred. If an
2105 * error arrives later asynchronously that was triggered while the
2106 * trap was pushed, that error will be ignored.
2111 gdk_error_trap_pop_ignored (void)
2113 gdk_error_trap_pop_internal (FALSE);
2117 * gdk_error_trap_pop:
2119 * Removes an error trap pushed with gdk_error_trap_push().
2120 * May block until an error has been definitively received
2121 * or not received from the X server. gdk_error_trap_pop_ignored()
2122 * is preferred if you don't need to know whether an error
2123 * occurred, because it never has to block. If you don't
2124 * need the return value of gdk_error_trap_pop(), use
2125 * gdk_error_trap_pop_ignored().
2127 * Prior to GDK 3.0, this function would not automatically
2128 * sync for you, so you had to gdk_flush() if your last
2129 * call to Xlib was not a blocking round trip.
2131 * Return value: X error code or 0 on success
2134 gdk_error_trap_pop (void)
2136 return gdk_error_trap_pop_internal (TRUE);