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 if (info->toplevel_under_pointer)
138 g_object_unref (info->toplevel_under_pointer);
139 g_slice_free (GdkPointerWindowInfo, info);
143 free_device_grab (GdkDeviceGrabInfo *info)
145 g_object_unref (info->window);
146 g_object_unref (info->native_window);
151 free_device_grabs_foreach (gpointer key,
157 g_list_foreach (list, (GFunc) free_device_grab, NULL);
164 device_removed_cb (GdkDeviceManager *device_manager,
168 g_hash_table_remove (display->multiple_click_info, device);
169 g_hash_table_remove (display->device_grabs, device);
170 g_hash_table_remove (display->pointers_info, device);
172 /* FIXME: change core pointer and remove from device list */
176 gdk_display_opened (GdkDisplay *display)
178 GdkDeviceManager *device_manager;
180 device_manager = gdk_display_get_device_manager (display);
182 g_signal_connect (device_manager, "device-removed",
183 G_CALLBACK (device_removed_cb), display);
187 gdk_display_init (GdkDisplay *display)
189 display->double_click_time = 250;
190 display->double_click_distance = 5;
192 display->device_grabs = g_hash_table_new (NULL, NULL);
193 display->motion_hint_info = g_hash_table_new_full (NULL, NULL, NULL,
194 (GDestroyNotify) g_free);
196 display->pointers_info = g_hash_table_new_full (NULL, NULL, NULL,
197 (GDestroyNotify) free_pointer_info);
199 display->multiple_click_info = g_hash_table_new_full (NULL, NULL, NULL,
200 (GDestroyNotify) g_free);
202 g_signal_connect (display, "opened",
203 G_CALLBACK (gdk_display_opened), NULL);
207 gdk_display_dispose (GObject *object)
209 GdkDisplay *display = GDK_DISPLAY (object);
210 GdkDeviceManager *device_manager;
212 device_manager = gdk_display_get_device_manager (GDK_DISPLAY (object));
214 g_list_foreach (display->queued_events, (GFunc)gdk_event_free, NULL);
215 g_list_free (display->queued_events);
216 display->queued_events = NULL;
217 display->queued_tail = NULL;
221 /* this is to make it drop devices which may require using the X
222 * display and therefore can't be cleaned up in finalize.
223 * It will also disconnect device_removed_cb
225 g_object_run_dispose (G_OBJECT (display->device_manager));
228 G_OBJECT_CLASS (gdk_display_parent_class)->dispose (object);
232 gdk_display_finalize (GObject *object)
234 GdkDisplay *display = GDK_DISPLAY (object);
236 g_hash_table_foreach_remove (display->device_grabs,
237 free_device_grabs_foreach,
239 g_hash_table_destroy (display->device_grabs);
241 g_hash_table_destroy (display->motion_hint_info);
242 g_hash_table_destroy (display->pointers_info);
243 g_hash_table_destroy (display->multiple_click_info);
245 if (display->device_manager)
246 g_object_unref (display->device_manager);
248 G_OBJECT_CLASS (gdk_display_parent_class)->finalize (object);
253 * @display: a #GdkDisplay
255 * Closes the connection to the windowing system for the given display,
256 * and cleans up associated resources.
261 gdk_display_close (GdkDisplay *display)
263 g_return_if_fail (GDK_IS_DISPLAY (display));
265 if (!display->closed)
267 display->closed = TRUE;
269 g_signal_emit (display, signals[CLOSED], 0, FALSE);
270 g_object_run_dispose (G_OBJECT (display));
272 g_object_unref (display);
277 * gdk_display_is_closed:
278 * @display: a #GdkDisplay
280 * Finds out if the display has been closed.
282 * Returns: %TRUE if the display is closed.
287 gdk_display_is_closed (GdkDisplay *display)
289 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
291 return display->closed;
295 * gdk_display_get_event:
296 * @display: a #GdkDisplay
298 * Gets the next #GdkEvent to be processed for @display, fetching events from the
299 * windowing system if necessary.
301 * Return value: the next #GdkEvent to be processed, or %NULL if no events
302 * are pending. The returned #GdkEvent should be freed with gdk_event_free().
307 gdk_display_get_event (GdkDisplay *display)
309 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
311 GDK_DISPLAY_GET_CLASS (display)->queue_events (display);
312 return _gdk_event_unqueue (display);
316 * gdk_display_peek_event:
317 * @display: a #GdkDisplay
319 * Gets a copy of the first #GdkEvent in the @display's event queue, without
320 * removing the event from the queue. (Note that this function will
321 * not get more events from the windowing system. It only checks the events
322 * that have already been moved to the GDK event queue.)
324 * Return value: a copy of the first #GdkEvent on the event queue, or %NULL
325 * if no events are in the queue. The returned #GdkEvent should be freed with
331 gdk_display_peek_event (GdkDisplay *display)
335 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
337 tmp_list = _gdk_event_queue_find_first (display);
340 return gdk_event_copy (tmp_list->data);
346 * gdk_display_put_event:
347 * @display: a #GdkDisplay
348 * @event: a #GdkEvent.
350 * Appends a copy of the given event onto the front of the event
351 * queue for @display.
356 gdk_display_put_event (GdkDisplay *display,
357 const GdkEvent *event)
359 g_return_if_fail (GDK_IS_DISPLAY (display));
360 g_return_if_fail (event != NULL);
362 _gdk_event_queue_append (display, gdk_event_copy (event));
363 /* If the main loop is blocking in a different thread, wake it up */
364 g_main_context_wakeup (NULL);
368 * gdk_display_pointer_ungrab:
369 * @display: a #GdkDisplay.
370 * @time_: a timestap (e.g. %GDK_CURRENT_TIME).
372 * Release any pointer grab.
376 * Deprecated: 3.0: Use gdk_device_ungrab(), together with gdk_device_grab()
380 gdk_display_pointer_ungrab (GdkDisplay *display,
383 GdkDeviceManager *device_manager;
384 GList *devices, *dev;
387 g_return_if_fail (GDK_IS_DISPLAY (display));
389 device_manager = gdk_display_get_device_manager (display);
390 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
392 /* FIXME: Should this be generic to all backends? */
393 /* FIXME: What happens with extended devices? */
394 for (dev = devices; dev; dev = dev->next)
398 if (gdk_device_get_source (device) != GDK_SOURCE_MOUSE)
401 gdk_device_ungrab (device, time_);
404 g_list_free (devices);
408 * gdk_pointer_ungrab:
409 * @time_: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no
410 * timestamp is available.
412 * Ungrabs the pointer on the default display, if it is grabbed by this
415 * Deprecated: 3.0: Use gdk_device_ungrab(), together with gdk_device_grab()
419 gdk_pointer_ungrab (guint32 time)
421 gdk_display_pointer_ungrab (gdk_display_get_default (), time);
425 * gdk_pointer_is_grabbed:
427 * Returns %TRUE if the pointer on the default display is currently
428 * grabbed by this application.
430 * Note that this does not take the inmplicit pointer grab on button
431 * presses into account.
433 * Return value: %TRUE if the pointer is currently grabbed by this application.
435 * Deprecated: 3.0: Use gdk_display_device_is_grabbed() instead.
438 gdk_pointer_is_grabbed (void)
440 return gdk_display_pointer_is_grabbed (gdk_display_get_default ());
444 * gdk_display_keyboard_ungrab:
445 * @display: a #GdkDisplay.
446 * @time_: a timestap (e.g #GDK_CURRENT_TIME).
448 * Release any keyboard grab
452 * Deprecated: 3.0: Use gdk_device_ungrab(), together with gdk_device_grab()
456 gdk_display_keyboard_ungrab (GdkDisplay *display,
459 GdkDeviceManager *device_manager;
460 GList *devices, *dev;
463 g_return_if_fail (GDK_IS_DISPLAY (display));
465 device_manager = gdk_display_get_device_manager (display);
466 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
468 /* FIXME: Should this be generic to all backends? */
469 /* FIXME: What happens with extended devices? */
470 for (dev = devices; dev; dev = dev->next)
474 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
477 gdk_device_ungrab (device, time);
480 g_list_free (devices);
484 * gdk_keyboard_ungrab:
485 * @time_: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no
486 * timestamp is available.
488 * Ungrabs the keyboard on the default display, if it is grabbed by this
491 * Deprecated: 3.0: Use gdk_device_ungrab(), together with gdk_device_grab()
495 gdk_keyboard_ungrab (guint32 time)
497 gdk_display_keyboard_ungrab (gdk_display_get_default (), time);
503 * Emits a short beep on the default display.
508 gdk_display_beep (gdk_display_get_default ());
514 * Flushes the output buffers of all display connections and waits
515 * until all requests have been processed.
516 * This is rarely needed by applications.
523 list = gdk_display_manager_list_displays (gdk_display_manager_get ());
524 for (l = list; l; l = l->next)
526 GdkDisplay *display = l->data;
528 GDK_DISPLAY_GET_CLASS (display)->sync (display);
535 _gdk_display_enable_motion_hints (GdkDisplay *display,
538 gulong *device_serial, serial;
540 device_serial = g_hash_table_lookup (display->motion_hint_info, device);
544 device_serial = g_new0 (gulong, 1);
545 *device_serial = G_MAXULONG;
546 g_hash_table_insert (display->motion_hint_info, device, device_serial);
549 if (*device_serial != 0)
551 serial = _gdk_display_get_next_serial (display);
552 /* We might not actually generate the next request, so
553 make sure this triggers always, this may cause it to
554 trigger slightly too early, but this is just a hint
558 if (serial < *device_serial)
559 *device_serial = serial;
564 * gdk_display_get_pointer:
565 * @display: a #GdkDisplay
566 * @screen: (out) (allow-none): location to store the screen that the
567 * cursor is on, or %NULL.
568 * @x: (out) (allow-none): location to store root window X coordinate of pointer, or %NULL.
569 * @y: (out) (allow-none): location to store root window Y coordinate of pointer, or %NULL.
570 * @mask: (out) (allow-none): location to store current modifier mask, or %NULL
572 * Gets the current location of the pointer and the current modifier
573 * mask for a given display.
577 * Deprecated: 3.0: Use gdk_device_get_position() instead.
580 gdk_display_get_pointer (GdkDisplay *display,
584 GdkModifierType *mask)
586 GdkScreen *default_screen;
589 GdkModifierType tmp_mask;
591 g_return_if_fail (GDK_IS_DISPLAY (display));
593 if (gdk_display_is_closed (display))
596 default_screen = gdk_display_get_default_screen (display);
598 /* We call _gdk_device_query_state() here manually instead of
599 * gdk_device_get_position() because we care about the modifier mask */
601 _gdk_device_query_state (display->core_pointer,
602 gdk_screen_get_root_window (default_screen),
609 *screen = gdk_window_get_screen (root);
619 * gdk_display_get_window_at_pointer:
620 * @display: a #GdkDisplay
621 * @win_x: (out) (allow-none): return location for x coordinate of the pointer location relative
622 * to the window origin, or %NULL
623 * @win_y: (out) (allow-none): return location for y coordinate of the pointer location relative
624 & to the window origin, or %NULL
626 * Obtains the window underneath the mouse pointer, returning the location
627 * of the pointer in that window in @win_x, @win_y for @screen. Returns %NULL
628 * if the window under the mouse pointer is not known to GDK (for example,
629 * belongs to another application).
631 * Returns: (transfer none): the window under the mouse pointer, or %NULL
635 * Deprecated: 3.0: Use gdk_device_get_window_at_position() instead.
638 gdk_display_get_window_at_pointer (GdkDisplay *display,
642 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
644 return gdk_device_get_window_at_position (display->core_pointer, win_x, win_y);
648 generate_grab_broken_event (GdkWindow *window,
651 GdkWindow *grab_window)
653 g_return_if_fail (window != NULL);
655 if (!GDK_WINDOW_DESTROYED (window))
659 event = gdk_event_new (GDK_GRAB_BROKEN);
660 event->grab_broken.window = g_object_ref (window);
661 event->grab_broken.send_event = FALSE;
662 event->grab_broken.implicit = implicit;
663 event->grab_broken.grab_window = grab_window;
664 gdk_event_set_device (event, device);
665 event->grab_broken.keyboard = (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD) ? TRUE : FALSE;
667 gdk_event_put (event);
668 gdk_event_free (event);
673 _gdk_display_get_last_device_grab (GdkDisplay *display,
678 l = g_hash_table_lookup (display->device_grabs, device);
690 _gdk_display_add_device_grab (GdkDisplay *display,
693 GdkWindow *native_window,
694 GdkGrabOwnership grab_ownership,
695 gboolean owner_events,
696 GdkEventMask event_mask,
697 unsigned long serial_start,
701 GdkDeviceGrabInfo *info, *other_info;
704 info = g_new0 (GdkDeviceGrabInfo, 1);
706 info->window = g_object_ref (window);
707 info->native_window = g_object_ref (native_window);
708 info->serial_start = serial_start;
709 info->serial_end = G_MAXULONG;
710 info->owner_events = owner_events;
711 info->event_mask = event_mask;
713 info->implicit = implicit;
714 info->ownership = grab_ownership;
716 grabs = g_hash_table_lookup (display->device_grabs, device);
718 /* Find the first grab that has a larger start time (if any) and insert
719 * before that. I.E we insert after already existing grabs with same
721 for (l = grabs; l != NULL; l = l->next)
723 other_info = l->data;
725 if (info->serial_start < other_info->serial_start)
729 grabs = g_list_insert_before (grabs, l, info);
731 /* Make sure the new grab end before next grab */
734 other_info = l->data;
735 info->serial_end = other_info->serial_start;
738 /* Find any previous grab and update its end time */
739 l = g_list_find (grabs, info);
743 other_info = l->data;
744 other_info->serial_end = serial_start;
747 g_hash_table_insert (display->device_grabs, device, grabs);
752 /* _gdk_synthesize_crossing_events only works inside one toplevel.
753 This function splits things into two calls if needed, converting the
754 coordinates to the right toplevel */
756 synthesize_crossing_events (GdkDisplay *display,
758 GdkDevice *source_device,
759 GdkWindow *src_window,
760 GdkWindow *dest_window,
761 GdkCrossingMode crossing_mode,
765 GdkWindow *src_toplevel, *dest_toplevel;
766 GdkModifierType state;
770 src_toplevel = gdk_window_get_toplevel (src_window);
774 dest_toplevel = gdk_window_get_toplevel (dest_window);
776 dest_toplevel = NULL;
778 if (src_toplevel == NULL && dest_toplevel == NULL)
781 if (src_toplevel == NULL ||
782 src_toplevel == dest_toplevel)
785 gdk_window_get_pointer (dest_toplevel,
787 _gdk_synthesize_crossing_events (display,
790 device, source_device,
797 else if (dest_toplevel == NULL)
799 gdk_window_get_pointer (src_toplevel,
801 _gdk_synthesize_crossing_events (display,
804 device, source_device,
813 /* Different toplevels */
814 gdk_window_get_pointer (src_toplevel,
816 _gdk_synthesize_crossing_events (display,
819 device, source_device,
825 gdk_window_get_pointer (dest_toplevel,
827 _gdk_synthesize_crossing_events (display,
830 device, source_device,
840 get_current_toplevel (GdkDisplay *display,
844 GdkModifierType *state_out)
846 GdkWindow *pointer_window;
848 GdkModifierType state;
850 pointer_window = _gdk_device_window_at_position (device, &x, &y, &state, TRUE);
852 if (pointer_window != NULL &&
853 (GDK_WINDOW_DESTROYED (pointer_window) ||
854 GDK_WINDOW_TYPE (pointer_window) == GDK_WINDOW_ROOT ||
855 GDK_WINDOW_TYPE (pointer_window) == GDK_WINDOW_FOREIGN))
856 pointer_window = NULL;
862 return pointer_window;
866 switch_to_pointer_grab (GdkDisplay *display,
868 GdkDevice *source_device,
869 GdkDeviceGrabInfo *grab,
870 GdkDeviceGrabInfo *last_grab,
874 GdkWindow *src_window, *pointer_window, *new_toplevel;
875 GdkPointerWindowInfo *info;
877 GdkModifierType state;
880 /* Temporarily unset pointer to make sure we send the crossing events below */
881 old_grabs = g_hash_table_lookup (display->device_grabs, device);
882 g_hash_table_steal (display->device_grabs, device);
883 info = _gdk_display_get_pointer_info (display, device);
887 /* New grab is in effect */
889 /* We need to generate crossing events for the grab.
890 * However, there are never any crossing events for implicit grabs
891 * TODO: ... Actually, this could happen if the pointer window
892 * doesn't have button mask so a parent gets the event...
896 /* We send GRAB crossing events from the window under the pointer to the
897 grab window. Except if there is an old grab then we start from that */
899 src_window = last_grab->window;
901 src_window = info->window_under_pointer;
903 if (src_window != grab->window)
904 synthesize_crossing_events (display, device, source_device,
905 src_window, grab->window,
906 GDK_CROSSING_GRAB, time, serial);
908 /* !owner_event Grabbing a window that we're not inside, current status is
909 now NULL (i.e. outside grabbed window) */
910 if (!grab->owner_events && info->window_under_pointer != grab->window)
911 _gdk_display_set_window_under_pointer (display, device, NULL);
914 grab->activated = TRUE;
921 if (grab == NULL /* ungrab */ ||
922 (!last_grab->owner_events && grab->owner_events) /* switched to owner_events */ )
924 /* We force check what window we're in, and update the toplevel_under_pointer info,
925 * as that won't get told of this change with toplevel enter events.
927 if (info->toplevel_under_pointer)
928 g_object_unref (info->toplevel_under_pointer);
929 info->toplevel_under_pointer = NULL;
931 /* Ungrabbed slave devices don't have a position by
932 * itself, rather depend on its master pointer, so
933 * it doesn't make sense to track any position for
934 * these after the grab
936 if (grab || gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_SLAVE)
937 new_toplevel = get_current_toplevel (display, device, &x, &y, &state);
941 /* w is now toplevel and x,y in toplevel coords */
942 info->toplevel_under_pointer = g_object_ref (new_toplevel);
943 info->toplevel_x = x;
944 info->toplevel_y = y;
949 if (grab == NULL) /* Ungrabbed, send events */
951 pointer_window = NULL;
954 /* Find (possibly virtual) child window */
956 _gdk_window_find_descendant_at (new_toplevel,
961 if (pointer_window != last_grab->window)
962 synthesize_crossing_events (display, device, source_device,
963 last_grab->window, pointer_window,
964 GDK_CROSSING_UNGRAB, time, serial);
966 /* We're now ungrabbed, update the window_under_pointer */
967 _gdk_display_set_window_under_pointer (display, device, pointer_window);
971 g_hash_table_insert (display->device_grabs, device, old_grabs);
975 _gdk_display_device_grab_update (GdkDisplay *display,
977 GdkDevice *source_device,
978 gulong current_serial)
980 GdkDeviceGrabInfo *current_grab, *next_grab;
984 time = display->last_event_time;
985 grabs = g_hash_table_lookup (display->device_grabs, device);
987 while (grabs != NULL)
989 current_grab = grabs->data;
991 if (current_grab->serial_start > current_serial)
992 return; /* Hasn't started yet */
994 if (current_grab->serial_end > current_serial)
996 /* This one hasn't ended yet.
997 its the currently active one or scheduled to be active */
999 if (!current_grab->activated)
1001 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
1002 switch_to_pointer_grab (display, device, source_device, current_grab, NULL, time, current_serial);
1011 /* This is the next active grab */
1012 next_grab = grabs->next->data;
1014 if (next_grab->serial_start > current_serial)
1015 next_grab = NULL; /* Actually its not yet active */
1018 if ((next_grab == NULL && current_grab->implicit_ungrab) ||
1019 (next_grab != NULL && current_grab->window != next_grab->window))
1020 generate_grab_broken_event (GDK_WINDOW (current_grab->window),
1022 current_grab->implicit,
1023 next_grab? next_grab->window : NULL);
1025 /* Remove old grab */
1026 grabs = g_list_delete_link (grabs, grabs);
1027 g_hash_table_insert (display->device_grabs, device, grabs);
1029 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
1030 switch_to_pointer_grab (display, device, source_device,
1031 next_grab, current_grab,
1032 time, current_serial);
1034 free_device_grab (current_grab);
1039 grab_list_find (GList *grabs,
1042 GdkDeviceGrabInfo *grab;
1048 if (serial >= grab->serial_start && serial < grab->serial_end)
1051 grabs = grabs->next;
1058 find_device_grab (GdkDisplay *display,
1064 l = g_hash_table_lookup (display->device_grabs, device);
1065 return grab_list_find (l, serial);
1069 _gdk_display_has_device_grab (GdkDisplay *display,
1075 l = find_device_grab (display, device, serial);
1082 /* Returns true if last grab was ended
1083 * If if_child is non-NULL, end the grab only if the grabbed
1084 * window is the same as if_child or a descendant of it */
1086 _gdk_display_end_device_grab (GdkDisplay *display,
1089 GdkWindow *if_child,
1092 GdkDeviceGrabInfo *grab;
1095 l = find_device_grab (display, device, serial);
1102 (if_child == NULL ||
1103 _gdk_window_event_parent_of (if_child, grab->window)))
1105 grab->serial_end = serial;
1106 grab->implicit_ungrab = implicit;
1107 return l->next == NULL;
1113 /* Returns TRUE if device events are not blocked by any grab */
1115 _gdk_display_check_grab_ownership (GdkDisplay *display,
1119 GHashTableIter iter;
1120 gpointer key, value;
1121 GdkGrabOwnership higher_ownership, device_ownership;
1122 gboolean device_is_keyboard;
1124 g_hash_table_iter_init (&iter, display->device_grabs);
1125 higher_ownership = device_ownership = GDK_OWNERSHIP_NONE;
1126 device_is_keyboard = (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD);
1128 while (g_hash_table_iter_next (&iter, &key, &value))
1130 GdkDeviceGrabInfo *grab;
1136 grabs = grab_list_find (grabs, serial);
1141 /* Discard device if it's not of the same type */
1142 if ((device_is_keyboard && gdk_device_get_source (dev) != GDK_SOURCE_KEYBOARD) ||
1143 (!device_is_keyboard && gdk_device_get_source (dev) == GDK_SOURCE_KEYBOARD))
1149 device_ownership = grab->ownership;
1152 if (grab->ownership > higher_ownership)
1153 higher_ownership = grab->ownership;
1157 if (higher_ownership > device_ownership)
1159 /* There's a higher priority ownership
1160 * going on for other device(s)
1168 GdkPointerWindowInfo *
1169 _gdk_display_get_pointer_info (GdkDisplay *display,
1172 GdkPointerWindowInfo *info;
1174 if (G_UNLIKELY (!device))
1177 info = g_hash_table_lookup (display->pointers_info, device);
1179 if (G_UNLIKELY (!info))
1181 info = g_slice_new0 (GdkPointerWindowInfo);
1182 g_hash_table_insert (display->pointers_info, device, info);
1189 _gdk_display_pointer_info_foreach (GdkDisplay *display,
1190 GdkDisplayPointerInfoForeach func,
1193 GHashTableIter iter;
1194 gpointer key, value;
1196 g_hash_table_iter_init (&iter, display->pointers_info);
1198 while (g_hash_table_iter_next (&iter, &key, &value))
1200 GdkPointerWindowInfo *info = value;
1201 GdkDevice *device = key;
1203 (func) (display, device, info, user_data);
1208 * gdk_device_grab_info_libgtk_only:
1209 * @display: the display for which to get the grab information
1210 * @device: device to get the grab information from
1211 * @grab_window: (out) (transfer none): location to store current grab window
1212 * @owner_events: (out): location to store boolean indicating whether
1213 * the @owner_events flag to gdk_keyboard_grab() or
1214 * gdk_pointer_grab() was %TRUE.
1216 * Determines information about the current keyboard grab.
1217 * This is not public API and must not be used by applications.
1219 * Return value: %TRUE if this application currently has the
1223 gdk_device_grab_info_libgtk_only (GdkDisplay *display,
1225 GdkWindow **grab_window,
1226 gboolean *owner_events)
1228 GdkDeviceGrabInfo *info;
1230 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1231 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
1233 info = _gdk_display_get_last_device_grab (display, device);
1238 *grab_window = info->window;
1240 *owner_events = info->owner_events;
1249 * gdk_display_pointer_is_grabbed:
1250 * @display: a #GdkDisplay
1252 * Test if the pointer is grabbed.
1254 * Returns: %TRUE if an active X pointer grab is in effect
1258 * Deprecated: 3.0: Use gdk_display_device_is_grabbed() instead.
1261 gdk_display_pointer_is_grabbed (GdkDisplay *display)
1263 GdkDeviceManager *device_manager;
1264 GList *devices, *dev;
1267 g_return_val_if_fail (GDK_IS_DISPLAY (display), TRUE);
1269 device_manager = gdk_display_get_device_manager (display);
1270 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
1272 for (dev = devices; dev; dev = dev->next)
1276 if (gdk_device_get_source (device) == GDK_SOURCE_MOUSE &&
1277 gdk_display_device_is_grabbed (display, device))
1285 * gdk_display_device_is_grabbed:
1286 * @display: a #GdkDisplay
1287 * @device: a #GdkDevice
1289 * Returns %TRUE if there is an ongoing grab on @device for @display.
1291 * Returns: %TRUE if there is a grab in effect for @device.
1294 gdk_display_device_is_grabbed (GdkDisplay *display,
1297 GdkDeviceGrabInfo *info;
1299 g_return_val_if_fail (GDK_IS_DISPLAY (display), TRUE);
1300 g_return_val_if_fail (GDK_IS_DEVICE (device), TRUE);
1302 /* What we're interested in is the steady state (ie last grab),
1303 because we're interested e.g. if we grabbed so that we
1304 can ungrab, even if our grab is not active just yet. */
1305 info = _gdk_display_get_last_device_grab (display, device);
1307 return (info && !info->implicit);
1311 * gdk_display_get_device_manager:
1312 * @display: a #GdkDisplay.
1314 * Returns the #GdkDeviceManager associated to @display.
1316 * Returns: (transfer none): A #GdkDeviceManager, or %NULL. This memory is
1317 * owned by GDK and must not be freed or unreferenced.
1322 gdk_display_get_device_manager (GdkDisplay *display)
1324 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1326 return display->device_manager;
1330 * gdk_display_get_name:
1331 * @display: a #GdkDisplay
1333 * Gets the name of the display.
1335 * Returns: a string representing the display name. This string is owned
1336 * by GDK and should not be modified or freed.
1340 G_CONST_RETURN gchar *
1341 gdk_display_get_name (GdkDisplay *display)
1343 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1345 return GDK_DISPLAY_GET_CLASS (display)->get_name (display);
1349 gdk_get_display (void)
1351 return g_strdup (gdk_display_get_name (gdk_display_get_default ()));
1355 * gdk_display_get_n_screens:
1356 * @display: a #GdkDisplay
1358 * Gets the number of screen managed by the @display.
1360 * Returns: number of screens.
1365 gdk_display_get_n_screens (GdkDisplay *display)
1367 g_return_val_if_fail (GDK_IS_DISPLAY (display), 0);
1369 return GDK_DISPLAY_GET_CLASS (display)->get_n_screens (display);
1373 * gdk_display_get_screen:
1374 * @display: a #GdkDisplay
1375 * @screen_num: the screen number
1377 * Returns a screen object for one of the screens of the display.
1379 * Returns: (transfer none): the #GdkScreen object
1384 gdk_display_get_screen (GdkDisplay *display,
1387 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1389 return GDK_DISPLAY_GET_CLASS (display)->get_screen (display, screen_num);
1393 * gdk_display_get_default_screen:
1394 * @display: a #GdkDisplay
1396 * Get the default #GdkScreen for @display.
1398 * Returns: (transfer none): the default #GdkScreen object for @display
1403 gdk_display_get_default_screen (GdkDisplay *display)
1405 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1407 return GDK_DISPLAY_GET_CLASS (display)->get_default_screen (display);
1412 * @display: a #GdkDisplay
1414 * Emits a short beep on @display
1419 gdk_display_beep (GdkDisplay *display)
1421 g_return_if_fail (GDK_IS_DISPLAY (display));
1423 GDK_DISPLAY_GET_CLASS (display)->beep (display);
1428 * @display: a #GdkDisplay
1430 * Flushes any requests queued for the windowing system and waits until all
1431 * requests have been handled. This is often used for making sure that the
1432 * display is synchronized with the current state of the program. Calling
1433 * gdk_display_sync() before gdk_error_trap_pop() makes sure that any errors
1434 * generated from earlier requests are handled before the error trap is
1437 * This is most useful for X11. On windowing systems where requests are
1438 * handled synchronously, this function will do nothing.
1443 gdk_display_sync (GdkDisplay *display)
1445 g_return_if_fail (GDK_IS_DISPLAY (display));
1447 GDK_DISPLAY_GET_CLASS (display)->sync (display);
1451 * gdk_display_flush:
1452 * @display: a #GdkDisplay
1454 * Flushes any requests queued for the windowing system; this happens automatically
1455 * when the main loop blocks waiting for new events, but if your application
1456 * is drawing without returning control to the main loop, you may need
1457 * to call this function explicitely. A common case where this function
1458 * needs to be called is when an application is executing drawing commands
1459 * from a thread other than the thread where the main loop is running.
1461 * This is most useful for X11. On windowing systems where requests are
1462 * handled synchronously, this function will do nothing.
1467 gdk_display_flush (GdkDisplay *display)
1469 g_return_if_fail (GDK_IS_DISPLAY (display));
1471 GDK_DISPLAY_GET_CLASS (display)->flush (display);
1475 * gdk_display_get_default_group:
1476 * @display: a #GdkDisplay
1478 * Returns the default group leader window for all toplevel windows
1479 * on @display. This window is implicitly created by GDK.
1480 * See gdk_window_set_group().
1482 * Return value: (transfer none): The default group leader window
1488 gdk_display_get_default_group (GdkDisplay *display)
1490 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1492 return GDK_DISPLAY_GET_CLASS (display)->get_default_group (display);
1496 * gdk_display_supports_selection_notification:
1497 * @display: a #GdkDisplay
1499 * Returns whether #GdkEventOwnerChange events will be
1500 * sent when the owner of a selection changes.
1502 * Return value: whether #GdkEventOwnerChange events will
1508 gdk_display_supports_selection_notification (GdkDisplay *display)
1510 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1512 return GDK_DISPLAY_GET_CLASS (display)->supports_selection_notification (display);
1516 * gdk_display_request_selection_notification:
1517 * @display: a #GdkDisplay
1518 * @selection: the #GdkAtom naming the selection for which
1519 * ownership change notification is requested
1521 * Request #GdkEventOwnerChange events for ownership changes
1522 * of the selection named by the given atom.
1524 * Return value: whether #GdkEventOwnerChange events will
1530 gdk_display_request_selection_notification (GdkDisplay *display,
1534 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1536 return GDK_DISPLAY_GET_CLASS (display)->request_selection_notification (display, selection);
1540 * gdk_display_supports_clipboard_persistence
1541 * @display: a #GdkDisplay
1543 * Returns whether the speicifed display supports clipboard
1544 * persistance; i.e. if it's possible to store the clipboard data after an
1545 * application has quit. On X11 this checks if a clipboard daemon is
1548 * Returns: %TRUE if the display supports clipboard persistance.
1553 gdk_display_supports_clipboard_persistence (GdkDisplay *display)
1555 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1557 return GDK_DISPLAY_GET_CLASS (display)->supports_clipboard_persistence (display);
1561 * gdk_display_store_clipboard
1562 * @display: a #GdkDisplay
1563 * @clipboard_window: a #GdkWindow belonging to the clipboard owner
1564 * @time_: a timestamp
1565 * @targets: (array length=n_targets): an array of targets
1566 * that should be saved, or %NULL
1567 * if all available targets should be saved.
1568 * @n_targets: length of the @targets array
1570 * Issues a request to the clipboard manager to store the
1571 * clipboard data. On X11, this is a special program that works
1572 * according to the freedesktop clipboard specification, available at
1573 * <ulink url="http://www.freedesktop.org/Standards/clipboard-manager-spec">
1574 * http://www.freedesktop.org/Standards/clipboard-manager-spec</ulink>.
1579 gdk_display_store_clipboard (GdkDisplay *display,
1580 GdkWindow *clipboard_window,
1582 const GdkAtom *targets,
1585 g_return_if_fail (GDK_IS_DISPLAY (display));
1587 GDK_DISPLAY_GET_CLASS (display)->store_clipboard (display, clipboard_window, time_, targets, n_targets);
1591 * gdk_display_supports_shapes:
1592 * @display: a #GdkDisplay
1594 * Returns %TRUE if gdk_window_shape_combine_mask() can
1595 * be used to create shaped windows on @display.
1597 * Returns: %TRUE if shaped windows are supported
1602 gdk_display_supports_shapes (GdkDisplay *display)
1604 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1606 return GDK_DISPLAY_GET_CLASS (display)->supports_shapes (display);
1610 * gdk_display_supports_input_shapes:
1611 * @display: a #GdkDisplay
1613 * Returns %TRUE if gdk_window_input_shape_combine_mask() can
1614 * be used to modify the input shape of windows on @display.
1616 * Returns: %TRUE if windows with modified input shape are supported
1621 gdk_display_supports_input_shapes (GdkDisplay *display)
1623 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1625 return GDK_DISPLAY_GET_CLASS (display)->supports_input_shapes (display);
1629 * gdk_display_supports_composite:
1630 * @display: a #GdkDisplay
1632 * Returns %TRUE if gdk_window_set_composited() can be used
1633 * to redirect drawing on the window using compositing.
1635 * Currently this only works on X11 with XComposite and
1636 * XDamage extensions available.
1638 * Returns: %TRUE if windows may be composited.
1643 gdk_display_supports_composite (GdkDisplay *display)
1645 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1647 return GDK_DISPLAY_GET_CLASS (display)->supports_composite (display);
1651 * gdk_display_list_devices:
1652 * @display: a #GdkDisplay
1654 * Returns the list of available input devices attached to @display.
1655 * The list is statically allocated and should not be freed.
1657 * Return value: (transfer none) (element-type GdkDevice):
1658 * a list of #GdkDevice
1662 * Deprecated: 3.0: Use gdk_device_manager_list_devices() instead.
1665 gdk_display_list_devices (GdkDisplay *display)
1667 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1669 return GDK_DISPLAY_GET_CLASS (display)->list_devices (display);
1672 static GdkAppLaunchContext *
1673 gdk_display_real_get_app_launch_context (GdkDisplay *display)
1675 GdkAppLaunchContext *ctx;
1677 ctx = g_object_new (GDK_TYPE_APP_LAUNCH_CONTEXT,
1685 * gdk_display_get_app_launch_context:
1686 * @display: a #GdkDisplay
1688 * Returns a #GdkAppLaunchContext suitable for launching
1689 * applications on the given display.
1691 * Returns: (transfer full): a new #GdkAppLaunchContext for @display.
1692 * Free with g_object_unref() when done
1696 GdkAppLaunchContext *
1697 gdk_display_get_app_launch_context (GdkDisplay *display)
1699 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1701 return GDK_DISPLAY_GET_CLASS (display)->get_app_launch_context (display);
1706 * @display_name: the name of the display to open
1710 * Return value: (transfer none): a #GdkDisplay, or %NULL
1711 * if the display could not be opened
1716 gdk_display_open (const gchar *display_name)
1718 return gdk_display_manager_open_display (gdk_display_manager_get (),
1723 * gdk_display_has_pending:
1724 * @display: a #GdkDisplay
1726 * Returns whether the display has events that are waiting
1729 * Returns: %TRUE if there are events ready to be processed.
1734 gdk_display_has_pending (GdkDisplay *display)
1736 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1738 return GDK_DISPLAY_GET_CLASS (display)->has_pending (display);
1742 * gdk_display_supports_cursor_alpha:
1743 * @display: a #GdkDisplay
1745 * Returns %TRUE if cursors can use an 8bit alpha channel
1746 * on @display. Otherwise, cursors are restricted to bilevel
1747 * alpha (i.e. a mask).
1749 * Returns: whether cursors can have alpha channels.
1754 gdk_display_supports_cursor_alpha (GdkDisplay *display)
1756 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1758 return GDK_DISPLAY_GET_CLASS (display)->supports_cursor_alpha (display);
1762 * gdk_display_supports_cursor_color:
1763 * @display: a #GdkDisplay
1765 * Returns %TRUE if multicolored cursors are supported
1766 * on @display. Otherwise, cursors have only a forground
1767 * and a background color.
1769 * Returns: whether cursors can have multiple colors.
1774 gdk_display_supports_cursor_color (GdkDisplay *display)
1776 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1778 return GDK_DISPLAY_GET_CLASS (display)->supports_cursor_color (display);
1782 * gdk_display_get_default_cursor_size:
1783 * @display: a #GdkDisplay
1785 * Returns the default size to use for cursors on @display.
1787 * Returns: the default cursor size.
1792 gdk_display_get_default_cursor_size (GdkDisplay *display)
1794 guint width, height;
1796 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1798 GDK_DISPLAY_GET_CLASS (display)->get_default_cursor_size (display,
1802 return MIN (width, height);
1806 * gdk_display_get_maximal_cursor_size:
1807 * @display: a #GdkDisplay
1808 * @width: (out): the return location for the maximal cursor width
1809 * @height: (out): the return location for the maximal cursor height
1811 * Gets the maximal size to use for cursors on @display.
1816 gdk_display_get_maximal_cursor_size (GdkDisplay *display,
1820 g_return_if_fail (GDK_IS_DISPLAY (display));
1822 GDK_DISPLAY_GET_CLASS (display)->get_maximal_cursor_size (display,
1828 * gdk_display_warp_pointer:
1829 * @display: a #GdkDisplay
1830 * @screen: the screen of @display to warp the pointer to
1831 * @x: the x coordinate of the destination
1832 * @y: the y coordinate of the destination
1834 * Warps the pointer of @display to the point @x,@y on
1835 * the screen @screen, unless the pointer is confined
1836 * to a window by a grab, in which case it will be moved
1837 * as far as allowed by the grab. Warping the pointer
1838 * creates events as if the user had moved the mouse
1839 * instantaneously to the destination.
1841 * Note that the pointer should normally be under the
1842 * control of the user. This function was added to cover
1843 * some rare use cases like keyboard navigation support
1844 * for the color picker in the #GtkColorSelectionDialog.
1848 * Deprecated: 3.0: Use gdk_device_warp() instead.
1851 gdk_display_warp_pointer (GdkDisplay *display,
1856 g_return_if_fail (GDK_IS_DISPLAY (display));
1858 gdk_device_warp (display->core_pointer,
1864 _gdk_display_get_next_serial (GdkDisplay *display)
1866 return GDK_DISPLAY_GET_CLASS (display)->get_next_serial (display);
1871 * gdk_notify_startup_complete:
1873 * Indicates to the GUI environment that the application has finished
1874 * loading. If the applications opens windows, this function is
1875 * normally called after opening the application's initial set of
1878 * GTK+ will call this function automatically after opening the first
1879 * #GtkWindow unless gtk_window_set_auto_startup_notification() is called
1880 * to disable that feature.
1885 gdk_notify_startup_complete (void)
1887 gdk_notify_startup_complete_with_id (NULL);
1891 * gdk_notify_startup_complete_with_id:
1892 * @startup_id: a startup-notification identifier, for which
1893 * notification process should be completed
1895 * Indicates to the GUI environment that the application has
1896 * finished loading, using a given identifier.
1898 * GTK+ will call this function automatically for #GtkWindow
1899 * with custom startup-notification identifier unless
1900 * gtk_window_set_auto_startup_notification() is called to
1901 * disable that feature.
1906 gdk_notify_startup_complete_with_id (const gchar* startup_id)
1908 GdkDisplay *display;
1910 display = gdk_display_get_default ();
1912 gdk_display_notify_startup_complete (display, startup_id);
1916 * gdk_display_notify_startup_complete:
1917 * @display: a #GdkDisplay
1918 * @startup_id: a startup-notification identifier, for which
1919 * notification process should be completed
1921 * Indicates to the GUI environment that the application has
1922 * finished loading, using a given identifier.
1924 * GTK+ will call this function automatically for #GtkWindow
1925 * with custom startup-notification identifier unless
1926 * gtk_window_set_auto_startup_notification() is called to
1927 * disable that feature.
1932 gdk_display_notify_startup_complete (GdkDisplay *display,
1933 const gchar *startup_id)
1935 g_return_if_fail (GDK_IS_DISPLAY (display));
1937 GDK_DISPLAY_GET_CLASS (display)->notify_startup_complete (display, startup_id);
1941 _gdk_display_event_data_copy (GdkDisplay *display,
1942 const GdkEvent *event,
1943 GdkEvent *new_event)
1945 GDK_DISPLAY_GET_CLASS (display)->event_data_copy (display, event, new_event);
1949 _gdk_display_event_data_free (GdkDisplay *display,
1952 GDK_DISPLAY_GET_CLASS (display)->event_data_free (display, event);
1956 _gdk_display_create_window_impl (GdkDisplay *display,
1958 GdkWindow *real_parent,
1960 GdkEventMask event_mask,
1961 GdkWindowAttr *attributes,
1962 gint attributes_mask)
1964 GDK_DISPLAY_GET_CLASS (display)->create_window_impl (display,
1974 _gdk_display_create_window (GdkDisplay *display)
1976 return g_object_new (GDK_DISPLAY_GET_CLASS (display)->window_type, NULL);
1980 * gdk_keymap_get_for_display:
1981 * @display: the #GdkDisplay.
1983 * Returns the #GdkKeymap attached to @display.
1985 * Return value: (transfer none): the #GdkKeymap attached to @display.
1990 gdk_keymap_get_for_display (GdkDisplay *display)
1992 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1994 return GDK_DISPLAY_GET_CLASS (display)->get_keymap (display);
1997 typedef struct _GdkGlobalErrorTrap GdkGlobalErrorTrap;
1999 struct _GdkGlobalErrorTrap
2004 static GQueue gdk_error_traps = G_QUEUE_INIT;
2007 * gdk_error_trap_push:
2009 * This function allows X errors to be trapped instead of the normal
2010 * behavior of exiting the application. It should only be used if it
2011 * is not possible to avoid the X error in any other way. Errors are
2012 * ignored on all #GdkDisplay currently known to the
2013 * #GdkDisplayManager. If you don't care which error happens and just
2014 * want to ignore everything, pop with gdk_error_trap_pop_ignored().
2015 * If you need the error code, use gdk_error_trap_pop() which may have
2016 * to block and wait for the error to arrive from the X server.
2018 * This API exists on all platforms but only does anything on X.
2020 * You can use gdk_x11_display_error_trap_push() to ignore errors
2021 * on only a single display.
2024 * <title>Trapping an X error</title>
2026 * gdk_error_trap_push (<!-- -->);
2028 * // ... Call the X function which may cause an error here ...
2031 * if (gdk_error_trap_pop (<!-- -->))
2033 * // ... Handle the error here ...
2039 gdk_error_trap_push (void)
2041 GdkDisplayManager *manager;
2042 GdkDisplayClass *class;
2043 GdkGlobalErrorTrap *trap;
2046 manager = gdk_display_manager_get ();
2047 class = GDK_DISPLAY_GET_CLASS (gdk_display_manager_get_default_display (manager));
2049 if (class->push_error_trap == NULL)
2052 trap = g_slice_new (GdkGlobalErrorTrap);
2053 trap->displays = gdk_display_manager_list_displays (manager);
2055 g_slist_foreach (trap->displays, (GFunc) g_object_ref, NULL);
2056 for (l = trap->displays; l != NULL; l = l->next)
2058 class->push_error_trap (l->data);
2061 g_queue_push_head (&gdk_error_traps, trap);
2065 gdk_error_trap_pop_internal (gboolean need_code)
2067 GdkDisplayManager *manager;
2068 GdkDisplayClass *class;
2069 GdkGlobalErrorTrap *trap;
2073 manager = gdk_display_manager_get ();
2074 class = GDK_DISPLAY_GET_CLASS (gdk_display_manager_get_default_display (manager));
2076 if (class->pop_error_trap == NULL)
2079 trap = g_queue_pop_head (&gdk_error_traps);
2081 g_return_val_if_fail (trap != NULL, 0);
2084 for (l = trap->displays; l != NULL; l = l->next)
2088 code = class->pop_error_trap (l->data, !need_code);
2090 /* we use the error on the last display listed, why not. */
2095 g_slist_free_full (trap->displays, g_object_unref);
2096 g_slice_free (GdkGlobalErrorTrap, trap);
2102 * gdk_error_trap_pop_ignored:
2104 * Removes an error trap pushed with gdk_error_trap_push(), but
2105 * without bothering to wait and see whether an error occurred. If an
2106 * error arrives later asynchronously that was triggered while the
2107 * trap was pushed, that error will be ignored.
2112 gdk_error_trap_pop_ignored (void)
2114 gdk_error_trap_pop_internal (FALSE);
2118 * gdk_error_trap_pop:
2120 * Removes an error trap pushed with gdk_error_trap_push().
2121 * May block until an error has been definitively received
2122 * or not received from the X server. gdk_error_trap_pop_ignored()
2123 * is preferred if you don't need to know whether an error
2124 * occurred, because it never has to block. If you don't
2125 * need the return value of gdk_error_trap_pop(), use
2126 * gdk_error_trap_pop_ignored().
2128 * Prior to GDK 3.0, this function would not automatically
2129 * sync for you, so you had to gdk_flush() if your last
2130 * call to Xlib was not a blocking round trip.
2132 * Return value: X error code or 0 on success
2135 gdk_error_trap_pop (void)
2137 return gdk_error_trap_pop_internal (TRUE);