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, see <http://www.gnu.org/licenses/>.
24 #include "gdkdisplay.h"
25 #include "gdkdisplayprivate.h"
27 #include "gdkdeviceprivate.h"
28 #include "gdkevents.h"
29 #include "gdkwindowimpl.h"
30 #include "gdkinternals.h"
31 #include "gdkmarshalers.h"
32 #include "gdkscreen.h"
39 * @Short_description: Controls a set of GdkScreens and their associated input devices
42 * #GdkDisplay objects purpose are two fold:
45 * To manage and provide information about input devices (pointers
49 * To manage and provide information about the available #GdkScreens
53 * GdkDisplay objects are the GDK representation of an X Display,
54 * which can be described as <emphasis>a workstation consisting of
55 * a keyboard, a pointing device (such as a mouse) and one or more
57 * It is used to open and keep track of various GdkScreen objects
58 * currently instantiated by the application. It is also used to
59 * access the keyboard(s) and mouse pointer(s) of the display.
61 * Most of the input device handling has been factored out into
62 * the separate #GdkDeviceManager object. Every display has a
63 * device manager, which you can obtain using
64 * gdk_display_get_device_manager().
74 static void gdk_display_dispose (GObject *object);
75 static void gdk_display_finalize (GObject *object);
78 static GdkAppLaunchContext *gdk_display_real_get_app_launch_context (GdkDisplay *display);
80 static guint signals[LAST_SIGNAL] = { 0 };
82 G_DEFINE_TYPE (GdkDisplay, gdk_display, G_TYPE_OBJECT)
85 gdk_display_class_init (GdkDisplayClass *class)
87 GObjectClass *object_class = G_OBJECT_CLASS (class);
89 object_class->finalize = gdk_display_finalize;
90 object_class->dispose = gdk_display_dispose;
92 class->get_app_launch_context = gdk_display_real_get_app_launch_context;
93 class->window_type = GDK_TYPE_WINDOW;
97 * @display: the object on which the signal is emitted
99 * The ::opened signal is emitted when the connection to the windowing
100 * system for @display is opened.
103 g_signal_new (g_intern_static_string ("opened"),
104 G_OBJECT_CLASS_TYPE (object_class),
107 g_cclosure_marshal_VOID__VOID,
111 * GdkDisplay::closed:
112 * @display: the object on which the signal is emitted
113 * @is_error: %TRUE if the display was closed due to an error
115 * The ::closed signal is emitted when the connection to the windowing
116 * system for @display is closed.
121 g_signal_new (g_intern_static_string ("closed"),
122 G_OBJECT_CLASS_TYPE (object_class),
124 G_STRUCT_OFFSET (GdkDisplayClass, closed),
126 _gdk_marshal_VOID__BOOLEAN,
133 free_pointer_info (GdkPointerWindowInfo *info)
135 if (info->toplevel_under_pointer)
136 g_object_unref (info->toplevel_under_pointer);
137 g_slice_free (GdkPointerWindowInfo, info);
141 free_device_grab (GdkDeviceGrabInfo *info)
143 g_object_unref (info->window);
144 g_object_unref (info->native_window);
149 free_device_grabs_foreach (gpointer key,
155 g_list_free_full (list, (GDestroyNotify) free_device_grab);
161 device_removed_cb (GdkDeviceManager *device_manager,
165 g_hash_table_remove (display->multiple_click_info, device);
166 g_hash_table_remove (display->device_grabs, device);
167 g_hash_table_remove (display->pointers_info, device);
169 /* FIXME: change core pointer and remove from device list */
173 gdk_display_opened (GdkDisplay *display)
175 GdkDeviceManager *device_manager;
177 device_manager = gdk_display_get_device_manager (display);
179 g_signal_connect (device_manager, "device-removed",
180 G_CALLBACK (device_removed_cb), display);
184 gdk_display_init (GdkDisplay *display)
186 display->double_click_time = 250;
187 display->double_click_distance = 5;
189 display->touch_implicit_grabs = g_array_new (FALSE, FALSE, sizeof (GdkTouchGrabInfo));
190 display->device_grabs = g_hash_table_new (NULL, NULL);
191 display->motion_hint_info = g_hash_table_new_full (NULL, NULL, NULL,
192 (GDestroyNotify) g_free);
194 display->pointers_info = g_hash_table_new_full (NULL, NULL, NULL,
195 (GDestroyNotify) free_pointer_info);
197 display->multiple_click_info = g_hash_table_new_full (NULL, NULL, NULL,
198 (GDestroyNotify) g_free);
200 g_signal_connect (display, "opened",
201 G_CALLBACK (gdk_display_opened), NULL);
205 gdk_display_dispose (GObject *object)
207 GdkDisplay *display = GDK_DISPLAY (object);
208 GdkDeviceManager *device_manager;
210 device_manager = gdk_display_get_device_manager (GDK_DISPLAY (object));
212 g_list_free_full (display->queued_events, (GDestroyNotify) gdk_event_free);
213 display->queued_events = NULL;
214 display->queued_tail = NULL;
218 /* this is to make it drop devices which may require using the X
219 * display and therefore can't be cleaned up in finalize.
220 * It will also disconnect device_removed_cb
222 g_object_run_dispose (G_OBJECT (display->device_manager));
225 G_OBJECT_CLASS (gdk_display_parent_class)->dispose (object);
229 gdk_display_finalize (GObject *object)
231 GdkDisplay *display = GDK_DISPLAY (object);
233 g_hash_table_foreach_remove (display->device_grabs,
234 free_device_grabs_foreach,
236 g_hash_table_destroy (display->device_grabs);
238 g_array_free (display->touch_implicit_grabs, TRUE);
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_display_keyboard_ungrab:
408 * @display: a #GdkDisplay.
409 * @time_: a timestap (e.g #GDK_CURRENT_TIME).
411 * Release any keyboard grab
415 * Deprecated: 3.0: Use gdk_device_ungrab(), together with gdk_device_grab()
419 gdk_display_keyboard_ungrab (GdkDisplay *display,
422 GdkDeviceManager *device_manager;
423 GList *devices, *dev;
426 g_return_if_fail (GDK_IS_DISPLAY (display));
428 device_manager = gdk_display_get_device_manager (display);
429 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
431 /* FIXME: Should this be generic to all backends? */
432 /* FIXME: What happens with extended devices? */
433 for (dev = devices; dev; dev = dev->next)
437 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
440 gdk_device_ungrab (device, time);
443 g_list_free (devices);
449 * Emits a short beep on the default display.
454 gdk_display_beep (gdk_display_get_default ());
460 * Flushes the output buffers of all display connections and waits
461 * until all requests have been processed.
462 * This is rarely needed by applications.
469 list = gdk_display_manager_list_displays (gdk_display_manager_get ());
470 for (l = list; l; l = l->next)
472 GdkDisplay *display = l->data;
474 GDK_DISPLAY_GET_CLASS (display)->sync (display);
481 _gdk_display_enable_motion_hints (GdkDisplay *display,
484 gulong *device_serial, serial;
486 device_serial = g_hash_table_lookup (display->motion_hint_info, device);
490 device_serial = g_new0 (gulong, 1);
491 *device_serial = G_MAXULONG;
492 g_hash_table_insert (display->motion_hint_info, device, device_serial);
495 if (*device_serial != 0)
497 serial = _gdk_display_get_next_serial (display);
498 /* We might not actually generate the next request, so
499 make sure this triggers always, this may cause it to
500 trigger slightly too early, but this is just a hint
504 if (serial < *device_serial)
505 *device_serial = serial;
510 * gdk_display_get_pointer:
511 * @display: a #GdkDisplay
512 * @screen: (out) (allow-none) (transfer none): location to store the screen that the
513 * cursor is on, or %NULL.
514 * @x: (out) (allow-none): location to store root window X coordinate of pointer, or %NULL.
515 * @y: (out) (allow-none): location to store root window Y coordinate of pointer, or %NULL.
516 * @mask: (out) (allow-none): location to store current modifier mask, or %NULL
518 * Gets the current location of the pointer and the current modifier
519 * mask for a given display.
523 * Deprecated: 3.0: Use gdk_device_get_position() instead.
526 gdk_display_get_pointer (GdkDisplay *display,
530 GdkModifierType *mask)
532 GdkScreen *default_screen;
535 GdkModifierType tmp_mask;
537 g_return_if_fail (GDK_IS_DISPLAY (display));
539 if (gdk_display_is_closed (display))
542 default_screen = gdk_display_get_default_screen (display);
544 /* We call _gdk_device_query_state() here manually instead of
545 * gdk_device_get_position() because we care about the modifier mask */
547 _gdk_device_query_state (display->core_pointer,
548 gdk_screen_get_root_window (default_screen),
555 *screen = gdk_window_get_screen (root);
565 * gdk_display_get_window_at_pointer:
566 * @display: a #GdkDisplay
567 * @win_x: (out) (allow-none): return location for x coordinate of the pointer location relative
568 * to the window origin, or %NULL
569 * @win_y: (out) (allow-none): return location for y coordinate of the pointer location relative
570 & to the window origin, or %NULL
572 * Obtains the window underneath the mouse pointer, returning the location
573 * of the pointer in that window in @win_x, @win_y for @screen. Returns %NULL
574 * if the window under the mouse pointer is not known to GDK (for example,
575 * belongs to another application).
577 * Returns: (transfer none): the window under the mouse pointer, or %NULL
581 * Deprecated: 3.0: Use gdk_device_get_window_at_position() instead.
584 gdk_display_get_window_at_pointer (GdkDisplay *display,
588 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
590 return gdk_device_get_window_at_position (display->core_pointer, win_x, win_y);
594 generate_grab_broken_event (GdkWindow *window,
597 GdkWindow *grab_window)
599 g_return_if_fail (window != NULL);
601 if (!GDK_WINDOW_DESTROYED (window))
605 event = gdk_event_new (GDK_GRAB_BROKEN);
606 event->grab_broken.window = g_object_ref (window);
607 event->grab_broken.send_event = FALSE;
608 event->grab_broken.implicit = implicit;
609 event->grab_broken.grab_window = grab_window;
610 gdk_event_set_device (event, device);
611 event->grab_broken.keyboard = (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD) ? TRUE : FALSE;
613 gdk_event_put (event);
614 gdk_event_free (event);
619 _gdk_display_get_last_device_grab (GdkDisplay *display,
624 l = g_hash_table_lookup (display->device_grabs, device);
636 _gdk_display_add_device_grab (GdkDisplay *display,
639 GdkWindow *native_window,
640 GdkGrabOwnership grab_ownership,
641 gboolean owner_events,
642 GdkEventMask event_mask,
643 unsigned long serial_start,
647 GdkDeviceGrabInfo *info, *other_info;
650 info = g_new0 (GdkDeviceGrabInfo, 1);
652 info->window = g_object_ref (window);
653 info->native_window = g_object_ref (native_window);
654 info->serial_start = serial_start;
655 info->serial_end = G_MAXULONG;
656 info->owner_events = owner_events;
657 info->event_mask = event_mask;
659 info->implicit = implicit;
660 info->ownership = grab_ownership;
662 grabs = g_hash_table_lookup (display->device_grabs, device);
664 /* Find the first grab that has a larger start time (if any) and insert
665 * before that. I.E we insert after already existing grabs with same
667 for (l = grabs; l != NULL; l = l->next)
669 other_info = l->data;
671 if (info->serial_start < other_info->serial_start)
675 grabs = g_list_insert_before (grabs, l, info);
677 /* Make sure the new grab end before next grab */
680 other_info = l->data;
681 info->serial_end = other_info->serial_start;
684 /* Find any previous grab and update its end time */
685 l = g_list_find (grabs, info);
689 other_info = l->data;
690 other_info->serial_end = serial_start;
693 g_hash_table_insert (display->device_grabs, device, grabs);
699 _gdk_display_break_touch_grabs (GdkDisplay *display,
701 GdkWindow *new_grab_window)
705 for (i = 0; i < display->touch_implicit_grabs->len; i++)
707 GdkTouchGrabInfo *info;
709 info = &g_array_index (display->touch_implicit_grabs,
710 GdkTouchGrabInfo, i);
712 if (info->device == device && info->window != new_grab_window)
713 generate_grab_broken_event (GDK_WINDOW (info->window),
714 device, TRUE, new_grab_window);
719 _gdk_display_add_touch_grab (GdkDisplay *display,
721 GdkEventSequence *sequence,
723 GdkWindow *native_window,
724 GdkEventMask event_mask,
725 unsigned long serial,
728 GdkTouchGrabInfo info;
730 info.device = device;
731 info.sequence = sequence;
732 info.window = g_object_ref (window);
733 info.native_window = g_object_ref (native_window);
734 info.serial = serial;
735 info.event_mask = event_mask;
738 g_array_append_val (display->touch_implicit_grabs, info);
742 _gdk_display_end_touch_grab (GdkDisplay *display,
744 GdkEventSequence *sequence)
748 for (i = 0; i < display->touch_implicit_grabs->len; i++)
750 GdkTouchGrabInfo *info;
752 info = &g_array_index (display->touch_implicit_grabs,
753 GdkTouchGrabInfo, i);
755 if (info->device == device && info->sequence == sequence)
757 g_array_remove_index_fast (display->touch_implicit_grabs, i);
765 /* _gdk_synthesize_crossing_events only works inside one toplevel.
766 This function splits things into two calls if needed, converting the
767 coordinates to the right toplevel */
769 synthesize_crossing_events (GdkDisplay *display,
771 GdkDevice *source_device,
772 GdkWindow *src_window,
773 GdkWindow *dest_window,
774 GdkCrossingMode crossing_mode,
778 GdkWindow *src_toplevel, *dest_toplevel;
779 GdkModifierType state;
783 src_toplevel = gdk_window_get_toplevel (src_window);
787 dest_toplevel = gdk_window_get_toplevel (dest_window);
789 dest_toplevel = NULL;
791 if (src_toplevel == NULL && dest_toplevel == NULL)
794 if (src_toplevel == NULL ||
795 src_toplevel == dest_toplevel)
798 gdk_window_get_device_position (dest_toplevel,
801 _gdk_synthesize_crossing_events (display,
804 device, source_device,
811 else if (dest_toplevel == NULL)
813 gdk_window_get_device_position (src_toplevel,
816 _gdk_synthesize_crossing_events (display,
819 device, source_device,
828 /* Different toplevels */
829 gdk_window_get_device_position (src_toplevel,
832 _gdk_synthesize_crossing_events (display,
835 device, source_device,
841 gdk_window_get_device_position (dest_toplevel,
844 _gdk_synthesize_crossing_events (display,
847 device, source_device,
857 get_current_toplevel (GdkDisplay *display,
861 GdkModifierType *state_out)
863 GdkWindow *pointer_window;
865 GdkModifierType state;
867 pointer_window = _gdk_device_window_at_position (device, &x, &y, &state, TRUE);
869 if (pointer_window != NULL &&
870 (GDK_WINDOW_DESTROYED (pointer_window) ||
871 GDK_WINDOW_TYPE (pointer_window) == GDK_WINDOW_ROOT ||
872 GDK_WINDOW_TYPE (pointer_window) == GDK_WINDOW_FOREIGN))
873 pointer_window = NULL;
879 return pointer_window;
883 switch_to_pointer_grab (GdkDisplay *display,
885 GdkDevice *source_device,
886 GdkDeviceGrabInfo *grab,
887 GdkDeviceGrabInfo *last_grab,
891 GdkWindow *src_window, *pointer_window, *new_toplevel;
892 GdkPointerWindowInfo *info;
894 GdkModifierType state;
897 /* Temporarily unset pointer to make sure we send the crossing events below */
898 old_grabs = g_hash_table_lookup (display->device_grabs, device);
899 g_hash_table_steal (display->device_grabs, device);
900 info = _gdk_display_get_pointer_info (display, device);
904 /* New grab is in effect */
906 /* We need to generate crossing events for the grab.
907 * However, there are never any crossing events for implicit grabs
908 * TODO: ... Actually, this could happen if the pointer window
909 * doesn't have button mask so a parent gets the event...
913 /* We send GRAB crossing events from the window under the pointer to the
914 grab window. Except if there is an old grab then we start from that */
916 src_window = last_grab->window;
918 src_window = info->window_under_pointer;
920 if (src_window != grab->window)
921 synthesize_crossing_events (display, device, source_device,
922 src_window, grab->window,
923 GDK_CROSSING_GRAB, time, serial);
925 /* !owner_event Grabbing a window that we're not inside, current status is
926 now NULL (i.e. outside grabbed window) */
927 if (!grab->owner_events && info->window_under_pointer != grab->window)
928 _gdk_display_set_window_under_pointer (display, device, NULL);
931 grab->activated = TRUE;
938 if (grab == NULL /* ungrab */ ||
939 (!last_grab->owner_events && grab->owner_events) /* switched to owner_events */ )
941 /* We force check what window we're in, and update the toplevel_under_pointer info,
942 * as that won't get told of this change with toplevel enter events.
944 if (info->toplevel_under_pointer)
945 g_object_unref (info->toplevel_under_pointer);
946 info->toplevel_under_pointer = NULL;
948 /* Ungrabbed slave devices don't have a position by
949 * itself, rather depend on its master pointer, so
950 * it doesn't make sense to track any position for
951 * these after the grab
953 if (grab || gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_SLAVE)
954 new_toplevel = get_current_toplevel (display, device, &x, &y, &state);
958 /* w is now toplevel and x,y in toplevel coords */
959 info->toplevel_under_pointer = g_object_ref (new_toplevel);
960 info->toplevel_x = x;
961 info->toplevel_y = y;
966 if (grab == NULL) /* Ungrabbed, send events */
968 /* If the source device is a touch device, do not
969 * propagate any enter event yet, until one is
970 * synthesized when needed.
973 (gdk_device_get_source (source_device) == GDK_SOURCE_TOUCHSCREEN))
974 info->need_touch_press_enter = TRUE;
976 pointer_window = NULL;
979 !info->need_touch_press_enter)
981 /* Find (possibly virtual) child window */
983 _gdk_window_find_descendant_at (new_toplevel,
988 if (pointer_window != last_grab->window)
989 synthesize_crossing_events (display, device, source_device,
990 last_grab->window, pointer_window,
991 GDK_CROSSING_UNGRAB, time, serial);
993 /* We're now ungrabbed, update the window_under_pointer */
994 _gdk_display_set_window_under_pointer (display, device, pointer_window);
998 g_hash_table_insert (display->device_grabs, device, old_grabs);
1002 _gdk_display_device_grab_update (GdkDisplay *display,
1004 GdkDevice *source_device,
1005 gulong current_serial)
1007 GdkDeviceGrabInfo *current_grab, *next_grab;
1011 time = display->last_event_time;
1012 grabs = g_hash_table_lookup (display->device_grabs, device);
1014 while (grabs != NULL)
1016 current_grab = grabs->data;
1018 if (current_grab->serial_start > current_serial)
1019 return; /* Hasn't started yet */
1021 if (current_grab->serial_end > current_serial)
1023 /* This one hasn't ended yet.
1024 its the currently active one or scheduled to be active */
1026 if (!current_grab->activated)
1028 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
1029 switch_to_pointer_grab (display, device, source_device, current_grab, NULL, time, current_serial);
1038 /* This is the next active grab */
1039 next_grab = grabs->next->data;
1041 if (next_grab->serial_start > current_serial)
1042 next_grab = NULL; /* Actually its not yet active */
1046 _gdk_display_break_touch_grabs (display, device, next_grab->window);
1048 if ((next_grab == NULL && current_grab->implicit_ungrab) ||
1049 (next_grab != NULL && current_grab->window != next_grab->window))
1050 generate_grab_broken_event (GDK_WINDOW (current_grab->window),
1052 current_grab->implicit,
1053 next_grab? next_grab->window : NULL);
1055 /* Remove old grab */
1056 grabs = g_list_delete_link (grabs, grabs);
1057 g_hash_table_insert (display->device_grabs, device, grabs);
1059 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
1060 switch_to_pointer_grab (display, device, source_device,
1061 next_grab, current_grab,
1062 time, current_serial);
1064 free_device_grab (current_grab);
1069 grab_list_find (GList *grabs,
1072 GdkDeviceGrabInfo *grab;
1078 if (serial >= grab->serial_start && serial < grab->serial_end)
1081 grabs = grabs->next;
1088 find_device_grab (GdkDisplay *display,
1094 l = g_hash_table_lookup (display->device_grabs, device);
1095 return grab_list_find (l, serial);
1099 _gdk_display_has_device_grab (GdkDisplay *display,
1105 l = find_device_grab (display, device, serial);
1113 _gdk_display_has_touch_grab (GdkDisplay *display,
1115 GdkEventSequence *sequence,
1120 for (i = 0; i < display->touch_implicit_grabs->len; i++)
1122 GdkTouchGrabInfo *info;
1124 info = &g_array_index (display->touch_implicit_grabs,
1125 GdkTouchGrabInfo, i);
1127 if (info->device == device && info->sequence == sequence)
1129 if (serial >= info->serial)
1139 /* Returns true if last grab was ended
1140 * If if_child is non-NULL, end the grab only if the grabbed
1141 * window is the same as if_child or a descendant of it */
1143 _gdk_display_end_device_grab (GdkDisplay *display,
1146 GdkWindow *if_child,
1149 GdkDeviceGrabInfo *grab;
1152 l = find_device_grab (display, device, serial);
1159 (if_child == NULL ||
1160 _gdk_window_event_parent_of (if_child, grab->window)))
1162 grab->serial_end = serial;
1163 grab->implicit_ungrab = implicit;
1164 return l->next == NULL;
1170 /* Returns TRUE if device events are not blocked by any grab */
1172 _gdk_display_check_grab_ownership (GdkDisplay *display,
1176 GHashTableIter iter;
1177 gpointer key, value;
1178 GdkGrabOwnership higher_ownership, device_ownership;
1179 gboolean device_is_keyboard;
1181 g_hash_table_iter_init (&iter, display->device_grabs);
1182 higher_ownership = device_ownership = GDK_OWNERSHIP_NONE;
1183 device_is_keyboard = (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD);
1185 while (g_hash_table_iter_next (&iter, &key, &value))
1187 GdkDeviceGrabInfo *grab;
1193 grabs = grab_list_find (grabs, serial);
1198 /* Discard device if it's not of the same type */
1199 if ((device_is_keyboard && gdk_device_get_source (dev) != GDK_SOURCE_KEYBOARD) ||
1200 (!device_is_keyboard && gdk_device_get_source (dev) == GDK_SOURCE_KEYBOARD))
1206 device_ownership = grab->ownership;
1209 if (grab->ownership > higher_ownership)
1210 higher_ownership = grab->ownership;
1214 if (higher_ownership > device_ownership)
1216 /* There's a higher priority ownership
1217 * going on for other device(s)
1225 GdkPointerWindowInfo *
1226 _gdk_display_get_pointer_info (GdkDisplay *display,
1229 GdkPointerWindowInfo *info;
1231 if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
1232 device = gdk_device_get_associated_device (device);
1234 if (G_UNLIKELY (!device))
1237 info = g_hash_table_lookup (display->pointers_info, device);
1239 if (G_UNLIKELY (!info))
1241 info = g_slice_new0 (GdkPointerWindowInfo);
1242 g_hash_table_insert (display->pointers_info, device, info);
1249 _gdk_display_pointer_info_foreach (GdkDisplay *display,
1250 GdkDisplayPointerInfoForeach func,
1253 GHashTableIter iter;
1254 gpointer key, value;
1256 g_hash_table_iter_init (&iter, display->pointers_info);
1258 while (g_hash_table_iter_next (&iter, &key, &value))
1260 GdkPointerWindowInfo *info = value;
1261 GdkDevice *device = key;
1263 (func) (display, device, info, user_data);
1268 * gdk_device_grab_info_libgtk_only:
1269 * @display: the display for which to get the grab information
1270 * @device: device to get the grab information from
1271 * @grab_window: (out) (transfer none): location to store current grab window
1272 * @owner_events: (out): location to store boolean indicating whether
1273 * the @owner_events flag to gdk_keyboard_grab() or
1274 * gdk_pointer_grab() was %TRUE.
1276 * Determines information about the current keyboard grab.
1277 * This is not public API and must not be used by applications.
1279 * Return value: %TRUE if this application currently has the
1283 gdk_device_grab_info_libgtk_only (GdkDisplay *display,
1285 GdkWindow **grab_window,
1286 gboolean *owner_events)
1288 GdkDeviceGrabInfo *info;
1290 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1291 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
1293 info = _gdk_display_get_last_device_grab (display, device);
1298 *grab_window = info->window;
1300 *owner_events = info->owner_events;
1309 * gdk_display_pointer_is_grabbed:
1310 * @display: a #GdkDisplay
1312 * Test if the pointer is grabbed.
1314 * Returns: %TRUE if an active X pointer grab is in effect
1318 * Deprecated: 3.0: Use gdk_display_device_is_grabbed() instead.
1321 gdk_display_pointer_is_grabbed (GdkDisplay *display)
1323 GdkDeviceManager *device_manager;
1324 GList *devices, *dev;
1327 g_return_val_if_fail (GDK_IS_DISPLAY (display), TRUE);
1329 device_manager = gdk_display_get_device_manager (display);
1330 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
1332 for (dev = devices; dev; dev = dev->next)
1336 if (gdk_device_get_source (device) == GDK_SOURCE_MOUSE &&
1337 gdk_display_device_is_grabbed (display, device))
1339 g_list_free (devices);
1344 g_list_free (devices);
1350 * gdk_display_device_is_grabbed:
1351 * @display: a #GdkDisplay
1352 * @device: a #GdkDevice
1354 * Returns %TRUE if there is an ongoing grab on @device for @display.
1356 * Returns: %TRUE if there is a grab in effect for @device.
1359 gdk_display_device_is_grabbed (GdkDisplay *display,
1362 GdkDeviceGrabInfo *info;
1364 g_return_val_if_fail (GDK_IS_DISPLAY (display), TRUE);
1365 g_return_val_if_fail (GDK_IS_DEVICE (device), TRUE);
1367 /* What we're interested in is the steady state (ie last grab),
1368 because we're interested e.g. if we grabbed so that we
1369 can ungrab, even if our grab is not active just yet. */
1370 info = _gdk_display_get_last_device_grab (display, device);
1372 return (info && !info->implicit);
1376 * gdk_display_get_device_manager:
1377 * @display: a #GdkDisplay.
1379 * Returns the #GdkDeviceManager associated to @display.
1381 * Returns: (transfer none): A #GdkDeviceManager, or %NULL. This memory is
1382 * owned by GDK and must not be freed or unreferenced.
1387 gdk_display_get_device_manager (GdkDisplay *display)
1389 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1391 return display->device_manager;
1395 * gdk_display_get_name:
1396 * @display: a #GdkDisplay
1398 * Gets the name of the display.
1400 * Returns: a string representing the display name. This string is owned
1401 * by GDK and should not be modified or freed.
1406 gdk_display_get_name (GdkDisplay *display)
1408 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1410 return GDK_DISPLAY_GET_CLASS (display)->get_name (display);
1414 gdk_get_display (void)
1416 return g_strdup (gdk_display_get_name (gdk_display_get_default ()));
1420 * gdk_display_get_n_screens:
1421 * @display: a #GdkDisplay
1423 * Gets the number of screen managed by the @display.
1425 * Returns: number of screens.
1430 gdk_display_get_n_screens (GdkDisplay *display)
1432 g_return_val_if_fail (GDK_IS_DISPLAY (display), 0);
1434 return GDK_DISPLAY_GET_CLASS (display)->get_n_screens (display);
1438 * gdk_display_get_screen:
1439 * @display: a #GdkDisplay
1440 * @screen_num: the screen number
1442 * Returns a screen object for one of the screens of the display.
1444 * Returns: (transfer none): the #GdkScreen object
1449 gdk_display_get_screen (GdkDisplay *display,
1452 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1454 return GDK_DISPLAY_GET_CLASS (display)->get_screen (display, screen_num);
1458 * gdk_display_get_default_screen:
1459 * @display: a #GdkDisplay
1461 * Get the default #GdkScreen for @display.
1463 * Returns: (transfer none): the default #GdkScreen object for @display
1468 gdk_display_get_default_screen (GdkDisplay *display)
1470 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1472 return GDK_DISPLAY_GET_CLASS (display)->get_default_screen (display);
1477 * @display: a #GdkDisplay
1479 * Emits a short beep on @display
1484 gdk_display_beep (GdkDisplay *display)
1486 g_return_if_fail (GDK_IS_DISPLAY (display));
1488 GDK_DISPLAY_GET_CLASS (display)->beep (display);
1493 * @display: a #GdkDisplay
1495 * Flushes any requests queued for the windowing system and waits until all
1496 * requests have been handled. This is often used for making sure that the
1497 * display is synchronized with the current state of the program. Calling
1498 * gdk_display_sync() before gdk_error_trap_pop() makes sure that any errors
1499 * generated from earlier requests are handled before the error trap is
1502 * This is most useful for X11. On windowing systems where requests are
1503 * handled synchronously, this function will do nothing.
1508 gdk_display_sync (GdkDisplay *display)
1510 g_return_if_fail (GDK_IS_DISPLAY (display));
1512 GDK_DISPLAY_GET_CLASS (display)->sync (display);
1516 * gdk_display_flush:
1517 * @display: a #GdkDisplay
1519 * Flushes any requests queued for the windowing system; this happens automatically
1520 * when the main loop blocks waiting for new events, but if your application
1521 * is drawing without returning control to the main loop, you may need
1522 * to call this function explicitely. A common case where this function
1523 * needs to be called is when an application is executing drawing commands
1524 * from a thread other than the thread where the main loop is running.
1526 * This is most useful for X11. On windowing systems where requests are
1527 * handled synchronously, this function will do nothing.
1532 gdk_display_flush (GdkDisplay *display)
1534 g_return_if_fail (GDK_IS_DISPLAY (display));
1536 GDK_DISPLAY_GET_CLASS (display)->flush (display);
1540 * gdk_display_get_default_group:
1541 * @display: a #GdkDisplay
1543 * Returns the default group leader window for all toplevel windows
1544 * on @display. This window is implicitly created by GDK.
1545 * See gdk_window_set_group().
1547 * Return value: (transfer none): The default group leader window
1553 gdk_display_get_default_group (GdkDisplay *display)
1555 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1557 return GDK_DISPLAY_GET_CLASS (display)->get_default_group (display);
1561 * gdk_display_supports_selection_notification:
1562 * @display: a #GdkDisplay
1564 * Returns whether #GdkEventOwnerChange events will be
1565 * sent when the owner of a selection changes.
1567 * Return value: whether #GdkEventOwnerChange events will
1573 gdk_display_supports_selection_notification (GdkDisplay *display)
1575 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1577 return GDK_DISPLAY_GET_CLASS (display)->supports_selection_notification (display);
1581 * gdk_display_request_selection_notification:
1582 * @display: a #GdkDisplay
1583 * @selection: the #GdkAtom naming the selection for which
1584 * ownership change notification is requested
1586 * Request #GdkEventOwnerChange events for ownership changes
1587 * of the selection named by the given atom.
1589 * Return value: whether #GdkEventOwnerChange events will
1595 gdk_display_request_selection_notification (GdkDisplay *display,
1599 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1601 return GDK_DISPLAY_GET_CLASS (display)->request_selection_notification (display, selection);
1605 * gdk_display_supports_clipboard_persistence:
1606 * @display: a #GdkDisplay
1608 * Returns whether the speicifed display supports clipboard
1609 * persistance; i.e. if it's possible to store the clipboard data after an
1610 * application has quit. On X11 this checks if a clipboard daemon is
1613 * Returns: %TRUE if the display supports clipboard persistance.
1618 gdk_display_supports_clipboard_persistence (GdkDisplay *display)
1620 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1622 return GDK_DISPLAY_GET_CLASS (display)->supports_clipboard_persistence (display);
1626 * gdk_display_store_clipboard:
1627 * @display: a #GdkDisplay
1628 * @clipboard_window: a #GdkWindow belonging to the clipboard owner
1629 * @time_: a timestamp
1630 * @targets: (array length=n_targets): an array of targets
1631 * that should be saved, or %NULL
1632 * if all available targets should be saved.
1633 * @n_targets: length of the @targets array
1635 * Issues a request to the clipboard manager to store the
1636 * clipboard data. On X11, this is a special program that works
1637 * according to the freedesktop clipboard specification, available at
1638 * <ulink url="http://www.freedesktop.org/Standards/clipboard-manager-spec">
1639 * http://www.freedesktop.org/Standards/clipboard-manager-spec</ulink>.
1644 gdk_display_store_clipboard (GdkDisplay *display,
1645 GdkWindow *clipboard_window,
1647 const GdkAtom *targets,
1650 g_return_if_fail (GDK_IS_DISPLAY (display));
1652 GDK_DISPLAY_GET_CLASS (display)->store_clipboard (display, clipboard_window, time_, targets, n_targets);
1656 * gdk_display_supports_shapes:
1657 * @display: a #GdkDisplay
1659 * Returns %TRUE if gdk_window_shape_combine_mask() can
1660 * be used to create shaped windows on @display.
1662 * Returns: %TRUE if shaped windows are supported
1667 gdk_display_supports_shapes (GdkDisplay *display)
1669 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1671 return GDK_DISPLAY_GET_CLASS (display)->supports_shapes (display);
1675 * gdk_display_supports_input_shapes:
1676 * @display: a #GdkDisplay
1678 * Returns %TRUE if gdk_window_input_shape_combine_mask() can
1679 * be used to modify the input shape of windows on @display.
1681 * Returns: %TRUE if windows with modified input shape are supported
1686 gdk_display_supports_input_shapes (GdkDisplay *display)
1688 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1690 return GDK_DISPLAY_GET_CLASS (display)->supports_input_shapes (display);
1694 * gdk_display_supports_composite:
1695 * @display: a #GdkDisplay
1697 * Returns %TRUE if gdk_window_set_composited() can be used
1698 * to redirect drawing on the window using compositing.
1700 * Currently this only works on X11 with XComposite and
1701 * XDamage extensions available.
1703 * Returns: %TRUE if windows may be composited.
1708 gdk_display_supports_composite (GdkDisplay *display)
1710 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1712 return GDK_DISPLAY_GET_CLASS (display)->supports_composite (display);
1716 * gdk_display_list_devices:
1717 * @display: a #GdkDisplay
1719 * Returns the list of available input devices attached to @display.
1720 * The list is statically allocated and should not be freed.
1722 * Return value: (transfer none) (element-type GdkDevice):
1723 * a list of #GdkDevice
1727 * Deprecated: 3.0: Use gdk_device_manager_list_devices() instead.
1730 gdk_display_list_devices (GdkDisplay *display)
1732 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1734 return GDK_DISPLAY_GET_CLASS (display)->list_devices (display);
1737 static GdkAppLaunchContext *
1738 gdk_display_real_get_app_launch_context (GdkDisplay *display)
1740 GdkAppLaunchContext *ctx;
1742 ctx = g_object_new (GDK_TYPE_APP_LAUNCH_CONTEXT,
1750 * gdk_display_get_app_launch_context:
1751 * @display: a #GdkDisplay
1753 * Returns a #GdkAppLaunchContext suitable for launching
1754 * applications on the given display.
1756 * Returns: (transfer full): a new #GdkAppLaunchContext for @display.
1757 * Free with g_object_unref() when done
1761 GdkAppLaunchContext *
1762 gdk_display_get_app_launch_context (GdkDisplay *display)
1764 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1766 return GDK_DISPLAY_GET_CLASS (display)->get_app_launch_context (display);
1771 * @display_name: the name of the display to open
1775 * Return value: (transfer none): a #GdkDisplay, or %NULL
1776 * if the display could not be opened
1781 gdk_display_open (const gchar *display_name)
1783 return gdk_display_manager_open_display (gdk_display_manager_get (),
1788 * gdk_display_has_pending:
1789 * @display: a #GdkDisplay
1791 * Returns whether the display has events that are waiting
1794 * Returns: %TRUE if there are events ready to be processed.
1799 gdk_display_has_pending (GdkDisplay *display)
1801 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1803 return GDK_DISPLAY_GET_CLASS (display)->has_pending (display);
1807 * gdk_display_supports_cursor_alpha:
1808 * @display: a #GdkDisplay
1810 * Returns %TRUE if cursors can use an 8bit alpha channel
1811 * on @display. Otherwise, cursors are restricted to bilevel
1812 * alpha (i.e. a mask).
1814 * Returns: whether cursors can have alpha channels.
1819 gdk_display_supports_cursor_alpha (GdkDisplay *display)
1821 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1823 return GDK_DISPLAY_GET_CLASS (display)->supports_cursor_alpha (display);
1827 * gdk_display_supports_cursor_color:
1828 * @display: a #GdkDisplay
1830 * Returns %TRUE if multicolored cursors are supported
1831 * on @display. Otherwise, cursors have only a forground
1832 * and a background color.
1834 * Returns: whether cursors can have multiple colors.
1839 gdk_display_supports_cursor_color (GdkDisplay *display)
1841 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1843 return GDK_DISPLAY_GET_CLASS (display)->supports_cursor_color (display);
1847 * gdk_display_get_default_cursor_size:
1848 * @display: a #GdkDisplay
1850 * Returns the default size to use for cursors on @display.
1852 * Returns: the default cursor size.
1857 gdk_display_get_default_cursor_size (GdkDisplay *display)
1859 guint width, height;
1861 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1863 GDK_DISPLAY_GET_CLASS (display)->get_default_cursor_size (display,
1867 return MIN (width, height);
1871 * gdk_display_get_maximal_cursor_size:
1872 * @display: a #GdkDisplay
1873 * @width: (out): the return location for the maximal cursor width
1874 * @height: (out): the return location for the maximal cursor height
1876 * Gets the maximal size to use for cursors on @display.
1881 gdk_display_get_maximal_cursor_size (GdkDisplay *display,
1885 g_return_if_fail (GDK_IS_DISPLAY (display));
1887 GDK_DISPLAY_GET_CLASS (display)->get_maximal_cursor_size (display,
1893 * gdk_display_warp_pointer:
1894 * @display: a #GdkDisplay
1895 * @screen: the screen of @display to warp the pointer to
1896 * @x: the x coordinate of the destination
1897 * @y: the y coordinate of the destination
1899 * Warps the pointer of @display to the point @x,@y on
1900 * the screen @screen, unless the pointer is confined
1901 * to a window by a grab, in which case it will be moved
1902 * as far as allowed by the grab. Warping the pointer
1903 * creates events as if the user had moved the mouse
1904 * instantaneously to the destination.
1906 * Note that the pointer should normally be under the
1907 * control of the user. This function was added to cover
1908 * some rare use cases like keyboard navigation support
1909 * for the color picker in the #GtkColorSelectionDialog.
1913 * Deprecated: 3.0: Use gdk_device_warp() instead.
1916 gdk_display_warp_pointer (GdkDisplay *display,
1921 g_return_if_fail (GDK_IS_DISPLAY (display));
1923 gdk_device_warp (display->core_pointer,
1929 _gdk_display_get_next_serial (GdkDisplay *display)
1931 return GDK_DISPLAY_GET_CLASS (display)->get_next_serial (display);
1936 * gdk_notify_startup_complete:
1938 * Indicates to the GUI environment that the application has finished
1939 * loading. If the applications opens windows, this function is
1940 * normally called after opening the application's initial set of
1943 * GTK+ will call this function automatically after opening the first
1944 * #GtkWindow unless gtk_window_set_auto_startup_notification() is called
1945 * to disable that feature.
1950 gdk_notify_startup_complete (void)
1952 gdk_notify_startup_complete_with_id (NULL);
1956 * gdk_notify_startup_complete_with_id:
1957 * @startup_id: a startup-notification identifier, for which
1958 * notification process should be completed
1960 * Indicates to the GUI environment that the application has
1961 * finished loading, using a given identifier.
1963 * GTK+ will call this function automatically for #GtkWindow
1964 * with custom startup-notification identifier unless
1965 * gtk_window_set_auto_startup_notification() is called to
1966 * disable that feature.
1971 gdk_notify_startup_complete_with_id (const gchar* startup_id)
1973 GdkDisplay *display;
1975 display = gdk_display_get_default ();
1977 gdk_display_notify_startup_complete (display, startup_id);
1981 * gdk_display_notify_startup_complete:
1982 * @display: a #GdkDisplay
1983 * @startup_id: a startup-notification identifier, for which
1984 * notification process should be completed
1986 * Indicates to the GUI environment that the application has
1987 * finished loading, using a given identifier.
1989 * GTK+ will call this function automatically for #GtkWindow
1990 * with custom startup-notification identifier unless
1991 * gtk_window_set_auto_startup_notification() is called to
1992 * disable that feature.
1997 gdk_display_notify_startup_complete (GdkDisplay *display,
1998 const gchar *startup_id)
2000 g_return_if_fail (GDK_IS_DISPLAY (display));
2002 GDK_DISPLAY_GET_CLASS (display)->notify_startup_complete (display, startup_id);
2006 _gdk_display_event_data_copy (GdkDisplay *display,
2007 const GdkEvent *event,
2008 GdkEvent *new_event)
2010 GDK_DISPLAY_GET_CLASS (display)->event_data_copy (display, event, new_event);
2014 _gdk_display_event_data_free (GdkDisplay *display,
2017 GDK_DISPLAY_GET_CLASS (display)->event_data_free (display, event);
2021 _gdk_display_create_window_impl (GdkDisplay *display,
2023 GdkWindow *real_parent,
2025 GdkEventMask event_mask,
2026 GdkWindowAttr *attributes,
2027 gint attributes_mask)
2029 GDK_DISPLAY_GET_CLASS (display)->create_window_impl (display,
2039 _gdk_display_create_window (GdkDisplay *display)
2041 return g_object_new (GDK_DISPLAY_GET_CLASS (display)->window_type, NULL);
2045 * gdk_keymap_get_for_display:
2046 * @display: the #GdkDisplay.
2048 * Returns the #GdkKeymap attached to @display.
2050 * Return value: (transfer none): the #GdkKeymap attached to @display.
2055 gdk_keymap_get_for_display (GdkDisplay *display)
2057 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
2059 return GDK_DISPLAY_GET_CLASS (display)->get_keymap (display);
2062 typedef struct _GdkGlobalErrorTrap GdkGlobalErrorTrap;
2064 struct _GdkGlobalErrorTrap
2069 static GQueue gdk_error_traps = G_QUEUE_INIT;
2072 * gdk_error_trap_push:
2074 * This function allows X errors to be trapped instead of the normal
2075 * behavior of exiting the application. It should only be used if it
2076 * is not possible to avoid the X error in any other way. Errors are
2077 * ignored on all #GdkDisplay currently known to the
2078 * #GdkDisplayManager. If you don't care which error happens and just
2079 * want to ignore everything, pop with gdk_error_trap_pop_ignored().
2080 * If you need the error code, use gdk_error_trap_pop() which may have
2081 * to block and wait for the error to arrive from the X server.
2083 * This API exists on all platforms but only does anything on X.
2085 * You can use gdk_x11_display_error_trap_push() to ignore errors
2086 * on only a single display.
2089 * <title>Trapping an X error</title>
2091 * gdk_error_trap_push (<!-- -->);
2093 * // ... Call the X function which may cause an error here ...
2096 * if (gdk_error_trap_pop (<!-- -->))
2098 * // ... Handle the error here ...
2104 gdk_error_trap_push (void)
2106 GdkDisplayManager *manager;
2107 GdkDisplayClass *class;
2108 GdkGlobalErrorTrap *trap;
2111 manager = gdk_display_manager_get ();
2112 class = GDK_DISPLAY_GET_CLASS (gdk_display_manager_get_default_display (manager));
2114 if (class->push_error_trap == NULL)
2117 trap = g_slice_new (GdkGlobalErrorTrap);
2118 trap->displays = gdk_display_manager_list_displays (manager);
2120 g_slist_foreach (trap->displays, (GFunc) g_object_ref, NULL);
2121 for (l = trap->displays; l != NULL; l = l->next)
2123 class->push_error_trap (l->data);
2126 g_queue_push_head (&gdk_error_traps, trap);
2130 gdk_error_trap_pop_internal (gboolean need_code)
2132 GdkDisplayManager *manager;
2133 GdkDisplayClass *class;
2134 GdkGlobalErrorTrap *trap;
2138 manager = gdk_display_manager_get ();
2139 class = GDK_DISPLAY_GET_CLASS (gdk_display_manager_get_default_display (manager));
2141 if (class->pop_error_trap == NULL)
2144 trap = g_queue_pop_head (&gdk_error_traps);
2146 g_return_val_if_fail (trap != NULL, 0);
2149 for (l = trap->displays; l != NULL; l = l->next)
2153 code = class->pop_error_trap (l->data, !need_code);
2155 /* we use the error on the last display listed, why not. */
2160 g_slist_free_full (trap->displays, g_object_unref);
2161 g_slice_free (GdkGlobalErrorTrap, trap);
2167 * gdk_error_trap_pop_ignored:
2169 * Removes an error trap pushed with gdk_error_trap_push(), but
2170 * without bothering to wait and see whether an error occurred. If an
2171 * error arrives later asynchronously that was triggered while the
2172 * trap was pushed, that error will be ignored.
2177 gdk_error_trap_pop_ignored (void)
2179 gdk_error_trap_pop_internal (FALSE);
2183 * gdk_error_trap_pop:
2185 * Removes an error trap pushed with gdk_error_trap_push().
2186 * May block until an error has been definitively received
2187 * or not received from the X server. gdk_error_trap_pop_ignored()
2188 * is preferred if you don't need to know whether an error
2189 * occurred, because it never has to block. If you don't
2190 * need the return value of gdk_error_trap_pop(), use
2191 * gdk_error_trap_pop_ignored().
2193 * Prior to GDK 3.0, this function would not automatically
2194 * sync for you, so you had to gdk_flush() if your last
2195 * call to Xlib was not a blocking round trip.
2197 * Return value: X error code or 0 on success
2200 gdk_error_trap_pop (void)
2202 return gdk_error_trap_pop_internal (TRUE);