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"
42 * @Short_description: Controls the keyboard/mouse pointer grabs and a set of <type>GdkScreen</type>s
45 * #GdkDisplay objects purpose are two fold:
48 * To grab/ungrab keyboard focus and mouse pointer
51 * To manage and provide information about the #GdkScreen(s)
52 * available for this #GdkDisplay
56 * #GdkDisplay objects are the GDK representation of the X Display which can be
57 * described as <emphasis>a workstation consisting of a keyboard a pointing
58 * device (such as a mouse) and one or more screens</emphasis>.
59 * It is used to open and keep track of various #GdkScreen objects currently
60 * instanciated by the application. It is also used to grab and release the keyboard
61 * and the mouse pointer.
71 static void gdk_display_dispose (GObject *object);
72 static void gdk_display_finalize (GObject *object);
74 static void multihead_get_device_state (GdkDisplay *display,
79 GdkModifierType *mask);
80 static GdkWindow * multihead_window_get_device_position (GdkDisplay *display,
85 GdkModifierType *mask);
86 static GdkWindow * multihead_window_at_device_position (GdkDisplay *display,
91 static void multihead_default_get_pointer (GdkDisplay *display,
95 GdkModifierType *mask);
96 static GdkWindow * multihead_default_window_get_pointer (GdkDisplay *display,
100 GdkModifierType *mask);
101 static GdkWindow * multihead_default_window_at_pointer (GdkDisplay *display,
106 static void singlehead_get_pointer (GdkDisplay *display,
110 GdkModifierType *mask);
111 static GdkWindow* singlehead_window_get_pointer (GdkDisplay *display,
115 GdkModifierType *mask);
116 static GdkWindow* singlehead_window_at_pointer (GdkDisplay *display,
120 static GdkWindow* singlehead_default_window_get_pointer (GdkWindow *window,
123 GdkModifierType *mask);
124 static GdkWindow* singlehead_default_window_at_pointer (GdkScreen *screen,
126 gint *win_y);static GdkWindow *gdk_window_real_window_get_device_position (GdkDisplay *display,
131 GdkModifierType *mask);
132 static GdkWindow *gdk_display_real_get_window_at_device_position (GdkDisplay *display,
136 static void gdk_display_real_get_device_state (GdkDisplay *display,
141 GdkModifierType *mask);
142 static GdkAppLaunchContext *gdk_display_real_get_app_launch_context (GdkDisplay *display);
144 static guint signals[LAST_SIGNAL] = { 0 };
146 static const GdkDisplayDeviceHooks default_device_hooks = {
147 gdk_display_real_get_device_state,
148 gdk_window_real_window_get_device_position,
149 gdk_display_real_get_window_at_device_position
152 static const GdkDisplayDeviceHooks multihead_pointer_hooks = {
153 multihead_get_device_state,
154 multihead_window_get_device_position,
155 multihead_window_at_device_position
158 static const GdkDisplayPointerHooks multihead_default_pointer_hooks = {
159 multihead_default_get_pointer,
160 multihead_default_window_get_pointer,
161 multihead_default_window_at_pointer
164 static const GdkDisplayPointerHooks singlehead_pointer_hooks = {
165 singlehead_get_pointer,
166 singlehead_window_get_pointer,
167 singlehead_window_at_pointer
170 static const GdkPointerHooks singlehead_default_pointer_hooks = {
171 singlehead_default_window_get_pointer,
172 singlehead_default_window_at_pointer
175 static const GdkPointerHooks *singlehead_current_pointer_hooks = &singlehead_default_pointer_hooks;
176 static const GdkDisplayPointerHooks *multihead_current_pointer_hooks = &multihead_default_pointer_hooks;
178 G_DEFINE_TYPE (GdkDisplay, gdk_display, G_TYPE_OBJECT)
181 gdk_display_class_init (GdkDisplayClass *class)
183 GObjectClass *object_class = G_OBJECT_CLASS (class);
185 object_class->finalize = gdk_display_finalize;
186 object_class->dispose = gdk_display_dispose;
188 class->get_app_launch_context = gdk_display_real_get_app_launch_context;
189 class->window_type = GDK_TYPE_WINDOW;
192 * GdkDisplay::opened:
193 * @display: the object on which the signal is emitted
195 * The ::opened signal is emitted when the connection to the windowing
196 * system for @display is opened.
199 g_signal_new (g_intern_static_string ("opened"),
200 G_OBJECT_CLASS_TYPE (object_class),
203 g_cclosure_marshal_VOID__VOID,
207 * GdkDisplay::closed:
208 * @display: the object on which the signal is emitted
209 * @is_error: %TRUE if the display was closed due to an error
211 * The ::closed signal is emitted when the connection to the windowing
212 * system for @display is closed.
217 g_signal_new (g_intern_static_string ("closed"),
218 G_OBJECT_CLASS_TYPE (object_class),
220 G_STRUCT_OFFSET (GdkDisplayClass, closed),
222 _gdk_marshal_VOID__BOOLEAN,
229 free_pointer_info (GdkPointerWindowInfo *info)
231 g_object_unref (info->toplevel_under_pointer);
232 g_slice_free (GdkPointerWindowInfo, info);
236 free_device_grab (GdkDeviceGrabInfo *info)
238 g_object_unref (info->window);
239 g_object_unref (info->native_window);
244 free_device_grabs_foreach (gpointer key,
250 g_list_foreach (list, (GFunc) free_device_grab, NULL);
257 device_removed_cb (GdkDeviceManager *device_manager,
261 g_hash_table_remove (display->multiple_click_info, device);
262 g_hash_table_remove (display->device_grabs, device);
263 g_hash_table_remove (display->pointers_info, device);
265 /* FIXME: change core pointer and remove from device list */
269 gdk_display_opened (GdkDisplay *display)
271 GdkDeviceManager *device_manager;
273 device_manager = gdk_display_get_device_manager (display);
275 g_signal_connect (device_manager, "device-removed",
276 G_CALLBACK (device_removed_cb), display);
280 gdk_display_init (GdkDisplay *display)
282 display->double_click_time = 250;
283 display->double_click_distance = 5;
285 display->device_hooks = &default_device_hooks;
287 display->device_grabs = g_hash_table_new (NULL, NULL);
288 display->motion_hint_info = g_hash_table_new_full (NULL, NULL, NULL,
289 (GDestroyNotify) g_free);
291 display->pointers_info = g_hash_table_new_full (NULL, NULL, NULL,
292 (GDestroyNotify) free_pointer_info);
294 display->multiple_click_info = g_hash_table_new_full (NULL, NULL, NULL,
295 (GDestroyNotify) g_free);
297 g_signal_connect (display, "opened",
298 G_CALLBACK (gdk_display_opened), NULL);
302 gdk_display_dispose (GObject *object)
304 GdkDisplay *display = GDK_DISPLAY (object);
305 GdkDeviceManager *device_manager;
307 device_manager = gdk_display_get_device_manager (GDK_DISPLAY (object));
309 g_list_foreach (display->queued_events, (GFunc)gdk_event_free, NULL);
310 g_list_free (display->queued_events);
311 display->queued_events = NULL;
312 display->queued_tail = NULL;
316 /* this is to make it drop devices which may require using the X
317 * display and therefore can't be cleaned up in finalize.
318 * It will also disconnect device_removed_cb
320 g_object_run_dispose (G_OBJECT (display->device_manager));
323 G_OBJECT_CLASS (gdk_display_parent_class)->dispose (object);
327 gdk_display_finalize (GObject *object)
329 GdkDisplay *display = GDK_DISPLAY (object);
331 g_hash_table_foreach_remove (display->device_grabs,
332 free_device_grabs_foreach,
334 g_hash_table_destroy (display->device_grabs);
336 g_hash_table_destroy (display->pointers_info);
337 g_hash_table_destroy (display->multiple_click_info);
339 if (display->device_manager)
340 g_object_unref (display->device_manager);
342 G_OBJECT_CLASS (gdk_display_parent_class)->finalize (object);
347 * @display: a #GdkDisplay
349 * Closes the connection to the windowing system for the given display,
350 * and cleans up associated resources.
355 gdk_display_close (GdkDisplay *display)
357 g_return_if_fail (GDK_IS_DISPLAY (display));
359 if (!display->closed)
361 display->closed = TRUE;
363 g_signal_emit (display, signals[CLOSED], 0, FALSE);
364 g_object_run_dispose (G_OBJECT (display));
366 g_object_unref (display);
371 * gdk_display_is_closed:
372 * @display: a #GdkDisplay
374 * Finds out if the display has been closed.
376 * Returns: %TRUE if the display is closed.
381 gdk_display_is_closed (GdkDisplay *display)
383 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
385 return display->closed;
389 * gdk_display_get_event:
390 * @display: a #GdkDisplay
392 * Gets the next #GdkEvent to be processed for @display, fetching events from the
393 * windowing system if necessary.
395 * Return value: the next #GdkEvent to be processed, or %NULL if no events
396 * are pending. The returned #GdkEvent should be freed with gdk_event_free().
401 gdk_display_get_event (GdkDisplay *display)
403 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
405 GDK_DISPLAY_GET_CLASS (display)->queue_events (display);
406 return _gdk_event_unqueue (display);
410 * gdk_display_peek_event:
411 * @display: a #GdkDisplay
413 * Gets a copy of the first #GdkEvent in the @display's event queue, without
414 * removing the event from the queue. (Note that this function will
415 * not get more events from the windowing system. It only checks the events
416 * that have already been moved to the GDK event queue.)
418 * Return value: a copy of the first #GdkEvent on the event queue, or %NULL
419 * if no events are in the queue. The returned #GdkEvent should be freed with
425 gdk_display_peek_event (GdkDisplay *display)
429 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
431 tmp_list = _gdk_event_queue_find_first (display);
434 return gdk_event_copy (tmp_list->data);
440 * gdk_display_put_event:
441 * @display: a #GdkDisplay
442 * @event: a #GdkEvent.
444 * Appends a copy of the given event onto the front of the event
445 * queue for @display.
450 gdk_display_put_event (GdkDisplay *display,
451 const GdkEvent *event)
453 g_return_if_fail (GDK_IS_DISPLAY (display));
454 g_return_if_fail (event != NULL);
456 _gdk_event_queue_append (display, gdk_event_copy (event));
457 /* If the main loop is blocking in a different thread, wake it up */
458 g_main_context_wakeup (NULL);
462 * gdk_display_pointer_ungrab:
463 * @display: a #GdkDisplay.
464 * @time_: a timestap (e.g. %GDK_CURRENT_TIME).
466 * Release any pointer grab.
470 * Deprecated: 3.0: Use gdk_device_ungrab(), together with gdk_device_grab()
474 gdk_display_pointer_ungrab (GdkDisplay *display,
477 GdkDeviceManager *device_manager;
478 GList *devices, *dev;
481 g_return_if_fail (GDK_IS_DISPLAY (display));
483 device_manager = gdk_display_get_device_manager (display);
484 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
486 /* FIXME: Should this be generic to all backends? */
487 /* FIXME: What happens with extended devices? */
488 for (dev = devices; dev; dev = dev->next)
492 if (gdk_device_get_source (device) != GDK_SOURCE_MOUSE)
495 gdk_device_ungrab (device, time_);
498 g_list_free (devices);
502 * gdk_pointer_ungrab:
503 * @time_: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no
504 * timestamp is available.
506 * Ungrabs the pointer on the default display, if it is grabbed by this
509 * Deprecated: 3.0: Use gdk_device_ungrab(), together with gdk_device_grab()
513 gdk_pointer_ungrab (guint32 time)
515 gdk_display_pointer_ungrab (gdk_display_get_default (), time);
519 * gdk_pointer_is_grabbed:
521 * Returns %TRUE if the pointer on the default display is currently
522 * grabbed by this application.
524 * Note that this does not take the inmplicit pointer grab on button
525 * presses into account.
527 * Return value: %TRUE if the pointer is currently grabbed by this application.
529 * Deprecated: 3.0: Use gdk_display_device_is_grabbed() instead.
532 gdk_pointer_is_grabbed (void)
534 return gdk_display_pointer_is_grabbed (gdk_display_get_default ());
538 * gdk_display_keyboard_ungrab:
539 * @display: a #GdkDisplay.
540 * @time_: a timestap (e.g #GDK_CURRENT_TIME).
542 * Release any keyboard grab
546 * Deprecated: 3.0: Use gdk_device_ungrab(), together with gdk_device_grab()
550 gdk_display_keyboard_ungrab (GdkDisplay *display,
553 GdkDeviceManager *device_manager;
554 GList *devices, *dev;
557 g_return_if_fail (GDK_IS_DISPLAY (display));
559 device_manager = gdk_display_get_device_manager (display);
560 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
562 /* FIXME: Should this be generic to all backends? */
563 /* FIXME: What happens with extended devices? */
564 for (dev = devices; dev; dev = dev->next)
568 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
571 gdk_device_ungrab (device, time);
574 g_list_free (devices);
578 * gdk_keyboard_ungrab:
579 * @time_: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no
580 * timestamp is available.
582 * Ungrabs the keyboard on the default display, if it is grabbed by this
585 * Deprecated: 3.0: Use gdk_device_ungrab(), together with gdk_device_grab()
589 gdk_keyboard_ungrab (guint32 time)
591 gdk_display_keyboard_ungrab (gdk_display_get_default (), time);
597 * Emits a short beep on the default display.
602 gdk_display_beep (gdk_display_get_default ());
608 * Flushes the output buffers of all display connections and waits
609 * until all requests have been processed.
610 * This is rarely needed by applications.
617 list = gdk_display_manager_list_displays (gdk_display_manager_get ());
618 for (l = list; l; l = l->next)
620 GdkDisplay *display = l->data;
622 GDK_DISPLAY_GET_CLASS (display)->sync (display);
629 * gdk_event_send_client_message:
630 * @event: the #GdkEvent to send, which should be a #GdkEventClient.
631 * @winid: the window to send the X ClientMessage event to.
633 * Sends an X ClientMessage event to a given window (which must be
634 * on the default #GdkDisplay.)
635 * This could be used for communicating between different applications,
636 * though the amount of data is limited to 20 bytes.
638 * Return value: non-zero on success.
641 gdk_event_send_client_message (GdkEvent *event,
642 GdkNativeWindow winid)
644 g_return_val_if_fail (event != NULL, FALSE);
646 return gdk_event_send_client_message_for_display (gdk_display_get_default (),
651 * gdk_event_send_clientmessage_toall:
652 * @event: the #GdkEvent to send, which should be a #GdkEventClient.
654 * Sends an X ClientMessage event to all toplevel windows on the default
657 * Toplevel windows are determined by checking for the WM_STATE property, as
658 * described in the Inter-Client Communication Conventions Manual (ICCCM).
659 * If no windows are found with the WM_STATE property set, the message is sent
660 * to all children of the root window.
663 gdk_event_send_clientmessage_toall (GdkEvent *event)
665 g_return_if_fail (event != NULL);
667 gdk_screen_broadcast_client_message (gdk_screen_get_default (), event);
671 _gdk_display_enable_motion_hints (GdkDisplay *display,
674 gulong *device_serial, serial;
676 device_serial = g_hash_table_lookup (display->motion_hint_info, device);
680 device_serial = g_new0 (gulong, 1);
681 *device_serial = G_MAXULONG;
682 g_hash_table_insert (display->motion_hint_info, device, device_serial);
685 if (*device_serial != 0)
687 serial = _gdk_display_get_next_serial (display);
688 /* We might not actually generate the next request, so
689 make sure this triggers always, this may cause it to
690 trigger slightly too early, but this is just a hint
694 if (serial < *device_serial)
695 *device_serial = serial;
700 * gdk_display_get_window_at_device_position:
701 * @display: a #GdkDisplay.
702 * @device: pointer #GdkDevice to query info to.
703 * @win_x: (out) (allow-none): return location for the X coordinate of the device location,
704 * relative to the window origin, or %NULL.
705 * @win_y: (out) (allow-none): return location for the Y coordinate of the device location,
706 * relative to the window origin, or %NULL.
708 * Obtains the window underneath @device, returning the location of the device in @win_x and @win_y. Returns
709 * %NULL if the window tree under @device is not known to GDK (for example, belongs to another application).
711 * Returns: (transfer none): the #GdkWindow under the device position, or %NULL.
716 gdk_display_get_window_at_device_position (GdkDisplay *display,
724 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
725 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
726 g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, NULL);
728 window = display->device_hooks->window_at_device_position (display, device, &tmp_x, &tmp_y);
739 * gdk_display_set_device_hooks:
740 * @display: a #GdkDisplay.
741 * @new_hooks: (allow-none): a table of pointers to functions for getting quantities related
742 * to all devices position, or %NULL to restore the default table.
744 * This function allows for hooking into the operation of getting the current location of any
745 * #GdkDevice on a particular #GdkDisplay. This is only useful for such low-level tools as
746 * an event recorder. Applications should never have any reason to use this facility.
748 * Returns: (transfer none): The previous device hook table.
752 GdkDisplayDeviceHooks *
753 gdk_display_set_device_hooks (GdkDisplay *display,
754 const GdkDisplayDeviceHooks *new_hooks)
756 const GdkDisplayDeviceHooks *result;
758 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
759 result = display->device_hooks;
762 display->device_hooks = new_hooks;
764 display->device_hooks = &default_device_hooks;
766 return (GdkDisplayDeviceHooks *) result;
770 * gdk_display_get_pointer:
771 * @display: a #GdkDisplay
772 * @screen: (allow-none): location to store the screen that the
773 * cursor is on, or %NULL.
774 * @x: (out) (allow-none): location to store root window X coordinate of pointer, or %NULL.
775 * @y: (out) (allow-none): location to store root window Y coordinate of pointer, or %NULL.
776 * @mask: (out) (allow-none): location to store current modifier mask, or %NULL
778 * Gets the current location of the pointer and the current modifier
779 * mask for a given display.
783 * Deprecated: 3.0: Use gdk_device_get_position() instead.
786 gdk_display_get_pointer (GdkDisplay *display,
790 GdkModifierType *mask)
792 GdkScreen *tmp_screen;
794 GdkModifierType tmp_mask;
796 g_return_if_fail (GDK_IS_DISPLAY (display));
798 /* We call get_device_state here manually instead of gdk_device_get_position()
799 * because we also care about the modifier mask */
801 display->device_hooks->get_device_state (display,
802 display->core_pointer,
803 &tmp_screen, &tmp_x, &tmp_y, &tmp_mask);
805 *screen = tmp_screen;
815 gdk_display_real_get_window_at_device_position (GdkDisplay *display,
823 window = _gdk_device_window_at_position (device, &x, &y, NULL, FALSE);
825 /* This might need corrections, as the native window returned
826 may contain client side children */
831 window = _gdk_window_find_descendant_at (window,
834 x = floor (xx + 0.5);
835 y = floor (yy + 0.5);
845 gdk_window_real_window_get_device_position (GdkDisplay *display,
850 GdkModifierType *mask)
853 GdkModifierType tmp_mask;
854 gboolean normal_child;
856 normal_child = GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_device_state (window,
860 /* We got the coords on the impl, convert to the window */
861 tmpx -= window->abs_x;
862 tmpy -= window->abs_y;
872 return _gdk_window_find_child_at (window, tmpx, tmpy);
877 * gdk_display_get_window_at_pointer:
878 * @display: a #GdkDisplay
879 * @win_x: (out) (allow-none): return location for x coordinate of the pointer location relative
880 * to the window origin, or %NULL
881 * @win_y: (out) (allow-none): return location for y coordinate of the pointer location relative
882 & to the window origin, or %NULL
884 * Obtains the window underneath the mouse pointer, returning the location
885 * of the pointer in that window in @win_x, @win_y for @screen. Returns %NULL
886 * if the window under the mouse pointer is not known to GDK (for example,
887 * belongs to another application).
889 * Returns: (transfer none): the window under the mouse pointer, or %NULL
893 * Deprecated: 3.0: Use gdk_display_get_window_at_device_position() instead.
896 gdk_display_get_window_at_pointer (GdkDisplay *display,
900 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
902 return gdk_display_get_window_at_device_position (display, display->core_pointer, win_x, win_y);
906 multihead_get_device_state (GdkDisplay *display,
911 GdkModifierType *mask)
913 multihead_current_pointer_hooks->get_pointer (display, screen, x, y, mask);
917 multihead_window_get_device_position (GdkDisplay *display,
922 GdkModifierType *mask)
924 return multihead_current_pointer_hooks->window_get_pointer (display, window, x, y, mask);
928 multihead_window_at_device_position (GdkDisplay *display,
933 return multihead_current_pointer_hooks->window_at_pointer (display, win_x, win_y);
937 gdk_display_real_get_device_state (GdkDisplay *display,
942 GdkModifierType *mask)
944 GdkScreen *default_screen;
947 if (gdk_display_is_closed (display))
950 default_screen = gdk_display_get_default_screen (display);
952 _gdk_device_query_state (device,
953 gdk_screen_get_root_window (default_screen),
959 *screen = gdk_window_get_screen (root);
963 multihead_default_get_pointer (GdkDisplay *display,
967 GdkModifierType *mask)
969 gdk_display_real_get_device_state (display, display->core_pointer,
974 multihead_default_window_get_pointer (GdkDisplay *display,
978 GdkModifierType *mask)
980 return gdk_window_real_window_get_device_position (display,
981 display->core_pointer,
986 multihead_default_window_at_pointer (GdkDisplay *display,
990 return gdk_display_real_get_window_at_device_position (display,
991 display->core_pointer,
996 * gdk_display_set_pointer_hooks:
997 * @display: a #GdkDisplay
998 * @new_hooks: (allow-none): a table of pointers to functions for getting
999 * quantities related to the current pointer position,
1000 * or %NULL to restore the default table.
1002 * This function allows for hooking into the operation
1003 * of getting the current location of the pointer on a particular
1004 * display. This is only useful for such low-level tools as an
1005 * event recorder. Applications should never have any
1006 * reason to use this facility.
1008 * Return value: (transfer none): the previous pointer hook table
1012 * Deprecated: 3.0: Use gdk_display_set_device_hooks() instead.
1014 GdkDisplayPointerHooks *
1015 gdk_display_set_pointer_hooks (GdkDisplay *display,
1016 const GdkDisplayPointerHooks *new_hooks)
1018 const GdkDisplayPointerHooks *result = multihead_current_pointer_hooks;
1020 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1023 multihead_current_pointer_hooks = new_hooks;
1025 multihead_current_pointer_hooks = &multihead_default_pointer_hooks;
1027 gdk_display_set_device_hooks (display, &multihead_pointer_hooks);
1029 return (GdkDisplayPointerHooks *)result;
1033 singlehead_get_pointer (GdkDisplay *display,
1037 GdkModifierType *mask)
1039 GdkScreen *default_screen = gdk_display_get_default_screen (display);
1040 GdkWindow *root_window = gdk_screen_get_root_window (default_screen);
1042 *screen = default_screen;
1044 singlehead_current_pointer_hooks->get_pointer (root_window, x, y, mask);
1048 singlehead_window_get_pointer (GdkDisplay *display,
1052 GdkModifierType *mask)
1054 return singlehead_current_pointer_hooks->get_pointer (window, x, y, mask);
1058 singlehead_window_at_pointer (GdkDisplay *display,
1062 GdkScreen *default_screen = gdk_display_get_default_screen (display);
1064 return singlehead_current_pointer_hooks->window_at_pointer (default_screen,
1069 singlehead_default_window_get_pointer (GdkWindow *window,
1072 GdkModifierType *mask)
1074 GdkDisplay *display;
1076 display = gdk_window_get_display (window);
1078 return gdk_window_real_window_get_device_position (display,
1079 display->core_pointer,
1080 window, x, y, mask);
1084 singlehead_default_window_at_pointer (GdkScreen *screen,
1088 GdkDisplay *display;
1090 display = gdk_screen_get_display (screen);
1092 return gdk_display_real_get_window_at_device_position (display,
1093 display->core_pointer,
1098 * gdk_set_pointer_hooks:
1099 * @new_hooks: (allow-none): a table of pointers to functions for getting
1100 * quantities related to the current pointer position,
1101 * or %NULL to restore the default table.
1103 * This function allows for hooking into the operation
1104 * of getting the current location of the pointer. This
1105 * is only useful for such low-level tools as an
1106 * event recorder. Applications should never have any
1107 * reason to use this facility.
1109 * This function is not multihead safe. For multihead operation,
1110 * see gdk_display_set_pointer_hooks().
1112 * Return value: the previous pointer hook table
1114 * Deprecated: 3.0: Use gdk_display_set_device_hooks() instead.
1117 gdk_set_pointer_hooks (const GdkPointerHooks *new_hooks)
1119 const GdkPointerHooks *result = singlehead_current_pointer_hooks;
1122 singlehead_current_pointer_hooks = new_hooks;
1124 singlehead_current_pointer_hooks = &singlehead_default_pointer_hooks;
1126 gdk_display_set_pointer_hooks (gdk_display_get_default (),
1127 &singlehead_pointer_hooks);
1129 return (GdkPointerHooks *)result;
1133 generate_grab_broken_event (GdkWindow *window,
1136 GdkWindow *grab_window)
1138 g_return_if_fail (window != NULL);
1140 if (!GDK_WINDOW_DESTROYED (window))
1144 event = gdk_event_new (GDK_GRAB_BROKEN);
1145 event->grab_broken.window = g_object_ref (window);
1146 event->grab_broken.send_event = FALSE;
1147 event->grab_broken.implicit = implicit;
1148 event->grab_broken.grab_window = grab_window;
1149 gdk_event_set_device (event, device);
1150 event->grab_broken.keyboard = (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD) ? TRUE : FALSE;
1152 gdk_event_put (event);
1153 gdk_event_free (event);
1158 _gdk_display_get_last_device_grab (GdkDisplay *display,
1163 l = g_hash_table_lookup (display->device_grabs, device);
1167 l = g_list_last (l);
1175 _gdk_display_add_device_grab (GdkDisplay *display,
1178 GdkWindow *native_window,
1179 GdkGrabOwnership grab_ownership,
1180 gboolean owner_events,
1181 GdkEventMask event_mask,
1182 unsigned long serial_start,
1186 GdkDeviceGrabInfo *info, *other_info;
1189 info = g_new0 (GdkDeviceGrabInfo, 1);
1191 info->window = g_object_ref (window);
1192 info->native_window = g_object_ref (native_window);
1193 info->serial_start = serial_start;
1194 info->serial_end = G_MAXULONG;
1195 info->owner_events = owner_events;
1196 info->event_mask = event_mask;
1198 info->implicit = implicit;
1199 info->ownership = grab_ownership;
1201 grabs = g_hash_table_lookup (display->device_grabs, device);
1203 /* Find the first grab that has a larger start time (if any) and insert
1204 * before that. I.E we insert after already existing grabs with same
1206 for (l = grabs; l != NULL; l = l->next)
1208 other_info = l->data;
1210 if (info->serial_start < other_info->serial_start)
1214 grabs = g_list_insert_before (grabs, l, info);
1216 /* Make sure the new grab end before next grab */
1219 other_info = l->data;
1220 info->serial_end = other_info->serial_start;
1223 /* Find any previous grab and update its end time */
1224 l = g_list_find (grabs, info);
1228 other_info = l->data;
1229 other_info->serial_end = serial_start;
1232 g_hash_table_insert (display->device_grabs, device, grabs);
1237 /* _gdk_synthesize_crossing_events only works inside one toplevel.
1238 This function splits things into two calls if needed, converting the
1239 coordinates to the right toplevel */
1241 synthesize_crossing_events (GdkDisplay *display,
1243 GdkDevice *source_device,
1244 GdkWindow *src_window,
1245 GdkWindow *dest_window,
1246 GdkCrossingMode crossing_mode,
1250 GdkWindow *src_toplevel, *dest_toplevel;
1251 GdkModifierType state;
1254 /* We use the native crossing events if all native */
1255 if (_gdk_native_windows)
1259 src_toplevel = gdk_window_get_toplevel (src_window);
1261 src_toplevel = NULL;
1263 dest_toplevel = gdk_window_get_toplevel (dest_window);
1265 dest_toplevel = NULL;
1267 if (src_toplevel == NULL && dest_toplevel == NULL)
1270 if (src_toplevel == NULL ||
1271 src_toplevel == dest_toplevel)
1273 /* Same toplevels */
1274 gdk_window_get_pointer (dest_toplevel,
1276 _gdk_synthesize_crossing_events (display,
1279 device, source_device,
1286 else if (dest_toplevel == NULL)
1288 gdk_window_get_pointer (src_toplevel,
1290 _gdk_synthesize_crossing_events (display,
1293 device, source_device,
1302 /* Different toplevels */
1303 gdk_window_get_pointer (src_toplevel,
1305 _gdk_synthesize_crossing_events (display,
1308 device, source_device,
1314 gdk_window_get_pointer (dest_toplevel,
1316 _gdk_synthesize_crossing_events (display,
1319 device, source_device,
1329 get_current_toplevel (GdkDisplay *display,
1333 GdkModifierType *state_out)
1335 GdkWindow *pointer_window;
1337 GdkModifierType state;
1339 pointer_window = _gdk_device_window_at_position (device, &x, &y, &state, TRUE);
1341 if (pointer_window != NULL &&
1342 (GDK_WINDOW_DESTROYED (pointer_window) ||
1343 GDK_WINDOW_TYPE (pointer_window) == GDK_WINDOW_ROOT ||
1344 GDK_WINDOW_TYPE (pointer_window) == GDK_WINDOW_FOREIGN))
1345 pointer_window = NULL;
1351 return pointer_window;
1355 switch_to_pointer_grab (GdkDisplay *display,
1357 GdkDevice *source_device,
1358 GdkDeviceGrabInfo *grab,
1359 GdkDeviceGrabInfo *last_grab,
1363 GdkWindow *src_window, *pointer_window, *new_toplevel;
1364 GdkPointerWindowInfo *info;
1366 GdkModifierType state;
1369 /* Temporarily unset pointer to make sure we send the crossing events below */
1370 old_grabs = g_hash_table_lookup (display->device_grabs, device);
1371 g_hash_table_steal (display->device_grabs, device);
1372 info = _gdk_display_get_pointer_info (display, device);
1376 /* New grab is in effect */
1378 /* We need to generate crossing events for the grab.
1379 * However, there are never any crossing events for implicit grabs
1380 * TODO: ... Actually, this could happen if the pointer window
1381 * doesn't have button mask so a parent gets the event...
1383 if (!grab->implicit)
1385 /* We send GRAB crossing events from the window under the pointer to the
1386 grab window. Except if there is an old grab then we start from that */
1388 src_window = last_grab->window;
1390 src_window = info->window_under_pointer;
1392 if (src_window != grab->window)
1393 synthesize_crossing_events (display, device, source_device,
1394 src_window, grab->window,
1395 GDK_CROSSING_GRAB, time, serial);
1397 /* !owner_event Grabbing a window that we're not inside, current status is
1398 now NULL (i.e. outside grabbed window) */
1399 if (!grab->owner_events && info->window_under_pointer != grab->window)
1400 _gdk_display_set_window_under_pointer (display, device, NULL);
1403 grab->activated = TRUE;
1408 new_toplevel = NULL;
1410 if (grab == NULL /* ungrab */ ||
1411 (!last_grab->owner_events && grab->owner_events) /* switched to owner_events */ )
1413 /* We force check what window we're in, and update the toplevel_under_pointer info,
1414 * as that won't get told of this change with toplevel enter events.
1416 if (info->toplevel_under_pointer)
1417 g_object_unref (info->toplevel_under_pointer);
1418 info->toplevel_under_pointer = NULL;
1420 new_toplevel = get_current_toplevel (display, device, &x, &y, &state);
1423 /* w is now toplevel and x,y in toplevel coords */
1424 info->toplevel_under_pointer = g_object_ref (new_toplevel);
1425 info->toplevel_x = x;
1426 info->toplevel_y = y;
1427 info->state = state;
1431 if (grab == NULL) /* Ungrabbed, send events */
1433 pointer_window = NULL;
1436 /* Find (possibly virtual) child window */
1438 _gdk_window_find_descendant_at (new_toplevel,
1443 if (pointer_window != last_grab->window)
1444 synthesize_crossing_events (display, device, source_device,
1445 last_grab->window, pointer_window,
1446 GDK_CROSSING_UNGRAB, time, serial);
1448 /* We're now ungrabbed, update the window_under_pointer */
1449 _gdk_display_set_window_under_pointer (display, device, pointer_window);
1453 g_hash_table_insert (display->device_grabs, device, old_grabs);
1457 _gdk_display_device_grab_update (GdkDisplay *display,
1459 GdkDevice *source_device,
1460 gulong current_serial)
1462 GdkDeviceGrabInfo *current_grab, *next_grab;
1466 time = display->last_event_time;
1467 grabs = g_hash_table_lookup (display->device_grabs, device);
1469 while (grabs != NULL)
1471 current_grab = grabs->data;
1473 if (current_grab->serial_start > current_serial)
1474 return; /* Hasn't started yet */
1476 if (current_grab->serial_end > current_serial)
1478 /* This one hasn't ended yet.
1479 its the currently active one or scheduled to be active */
1481 if (!current_grab->activated)
1483 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
1484 switch_to_pointer_grab (display, device, source_device, current_grab, NULL, time, current_serial);
1493 /* This is the next active grab */
1494 next_grab = grabs->next->data;
1496 if (next_grab->serial_start > current_serial)
1497 next_grab = NULL; /* Actually its not yet active */
1500 if ((next_grab == NULL && current_grab->implicit_ungrab) ||
1501 (next_grab != NULL && current_grab->window != next_grab->window))
1502 generate_grab_broken_event (GDK_WINDOW (current_grab->window),
1504 current_grab->implicit,
1505 next_grab? next_grab->window : NULL);
1507 /* Remove old grab */
1508 grabs = g_list_delete_link (grabs, grabs);
1509 g_hash_table_insert (display->device_grabs, device, grabs);
1511 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
1512 switch_to_pointer_grab (display, device, source_device,
1513 next_grab, current_grab,
1514 time, current_serial);
1516 free_device_grab (current_grab);
1521 grab_list_find (GList *grabs,
1524 GdkDeviceGrabInfo *grab;
1530 if (serial >= grab->serial_start && serial < grab->serial_end)
1533 grabs = grabs->next;
1540 find_device_grab (GdkDisplay *display,
1546 l = g_hash_table_lookup (display->device_grabs, device);
1547 return grab_list_find (l, serial);
1551 _gdk_display_has_device_grab (GdkDisplay *display,
1557 l = find_device_grab (display, device, serial);
1564 /* Returns true if last grab was ended
1565 * If if_child is non-NULL, end the grab only if the grabbed
1566 * window is the same as if_child or a descendant of it */
1568 _gdk_display_end_device_grab (GdkDisplay *display,
1571 GdkWindow *if_child,
1574 GdkDeviceGrabInfo *grab;
1577 l = find_device_grab (display, device, serial);
1584 (if_child == NULL ||
1585 _gdk_window_event_parent_of (if_child, grab->window)))
1587 grab->serial_end = serial;
1588 grab->implicit_ungrab = implicit;
1589 return l->next == NULL;
1595 /* Returns TRUE if device events are not blocked by any grab */
1597 _gdk_display_check_grab_ownership (GdkDisplay *display,
1601 GHashTableIter iter;
1602 gpointer key, value;
1603 GdkGrabOwnership higher_ownership, device_ownership;
1604 gboolean device_is_keyboard;
1606 g_hash_table_iter_init (&iter, display->device_grabs);
1607 higher_ownership = device_ownership = GDK_OWNERSHIP_NONE;
1608 device_is_keyboard = (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD);
1610 while (g_hash_table_iter_next (&iter, &key, &value))
1612 GdkDeviceGrabInfo *grab;
1618 grabs = grab_list_find (grabs, serial);
1623 /* Discard device if it's not of the same type */
1624 if ((device_is_keyboard && gdk_device_get_source (dev) != GDK_SOURCE_KEYBOARD) ||
1625 (!device_is_keyboard && gdk_device_get_source (dev) == GDK_SOURCE_KEYBOARD))
1631 device_ownership = grab->ownership;
1634 if (grab->ownership > higher_ownership)
1635 higher_ownership = grab->ownership;
1639 if (higher_ownership > device_ownership)
1641 /* There's a higher priority ownership
1642 * going on for other device(s)
1650 GdkPointerWindowInfo *
1651 _gdk_display_get_pointer_info (GdkDisplay *display,
1654 GdkPointerWindowInfo *info;
1656 if (G_UNLIKELY (!device))
1659 info = g_hash_table_lookup (display->pointers_info, device);
1661 if (G_UNLIKELY (!info))
1663 info = g_slice_new0 (GdkPointerWindowInfo);
1664 g_hash_table_insert (display->pointers_info, device, info);
1671 _gdk_display_pointer_info_foreach (GdkDisplay *display,
1672 GdkDisplayPointerInfoForeach func,
1675 GHashTableIter iter;
1676 gpointer key, value;
1678 g_hash_table_iter_init (&iter, display->pointers_info);
1680 while (g_hash_table_iter_next (&iter, &key, &value))
1682 GdkPointerWindowInfo *info = value;
1683 GdkDevice *device = key;
1685 (func) (display, device, info, user_data);
1690 * gdk_device_grab_info_libgtk_only:
1691 * @display: the display for which to get the grab information
1692 * @device: device to get the grab information from
1693 * @grab_window: (out) (transfer none): location to store current grab window
1694 * @owner_events: (out): location to store boolean indicating whether
1695 * the @owner_events flag to gdk_keyboard_grab() or
1696 * gdk_pointer_grab() was %TRUE.
1698 * Determines information about the current keyboard grab.
1699 * This is not public API and must not be used by applications.
1701 * Return value: %TRUE if this application currently has the
1705 gdk_device_grab_info_libgtk_only (GdkDisplay *display,
1707 GdkWindow **grab_window,
1708 gboolean *owner_events)
1710 GdkDeviceGrabInfo *info;
1712 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1713 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
1715 info = _gdk_display_get_last_device_grab (display, device);
1720 *grab_window = info->window;
1722 *owner_events = info->owner_events;
1731 * gdk_display_pointer_is_grabbed:
1732 * @display: a #GdkDisplay
1734 * Test if the pointer is grabbed.
1736 * Returns: %TRUE if an active X pointer grab is in effect
1740 * Deprecated: 3.0: Use gdk_display_device_is_grabbed() instead.
1743 gdk_display_pointer_is_grabbed (GdkDisplay *display)
1745 GdkDeviceManager *device_manager;
1746 GList *devices, *dev;
1749 g_return_val_if_fail (GDK_IS_DISPLAY (display), TRUE);
1751 device_manager = gdk_display_get_device_manager (display);
1752 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
1754 for (dev = devices; dev; dev = dev->next)
1758 if (gdk_device_get_source (device) == GDK_SOURCE_MOUSE &&
1759 gdk_display_device_is_grabbed (display, device))
1767 * gdk_display_device_is_grabbed:
1768 * @display: a #GdkDisplay
1769 * @device: a #GdkDevice
1771 * Returns %TRUE if there is an ongoing grab on @device for @display.
1773 * Returns: %TRUE if there is a grab in effect for @device.
1776 gdk_display_device_is_grabbed (GdkDisplay *display,
1779 GdkDeviceGrabInfo *info;
1781 g_return_val_if_fail (GDK_IS_DISPLAY (display), TRUE);
1782 g_return_val_if_fail (GDK_IS_DEVICE (device), TRUE);
1784 /* What we're interested in is the steady state (ie last grab),
1785 because we're interested e.g. if we grabbed so that we
1786 can ungrab, even if our grab is not active just yet. */
1787 info = _gdk_display_get_last_device_grab (display, device);
1789 return (info && !info->implicit);
1793 * gdk_display_get_device_manager:
1794 * @display: a #GdkDisplay.
1796 * Returns the #GdkDeviceManager associated to @display.
1798 * Returns: (transfer none): A #GdkDeviceManager, or %NULL. This memory is
1799 * owned by GDK and must not be freed or unreferenced.
1804 gdk_display_get_device_manager (GdkDisplay *display)
1806 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1808 return display->device_manager;
1812 * gdk_display_get_name:
1813 * @display: a #GdkDisplay
1815 * Gets the name of the display.
1817 * Returns: a string representing the display name. This string is owned
1818 * by GDK and should not be modified or freed.
1822 G_CONST_RETURN gchar *
1823 gdk_display_get_name (GdkDisplay *display)
1825 return GDK_DISPLAY_GET_CLASS(display)->get_name (display);
1829 gdk_get_display (void)
1831 return g_strdup (gdk_display_get_name (gdk_display_get_default ()));
1835 * gdk_display_get_n_screens:
1836 * @display: a #GdkDisplay
1838 * Gets the number of screen managed by the @display.
1840 * Returns: number of screens.
1845 gdk_display_get_n_screens (GdkDisplay *display)
1847 return GDK_DISPLAY_GET_CLASS(display)->get_n_screens (display);
1851 * gdk_display_get_screen:
1852 * @display: a #GdkDisplay
1853 * @screen_num: the screen number
1855 * Returns a screen object for one of the screens of the display.
1857 * Returns: (transfer none): the #GdkScreen object
1862 gdk_display_get_screen (GdkDisplay *display,
1865 return GDK_DISPLAY_GET_CLASS(display)->get_screen (display, screen_num);
1869 * gdk_display_get_default_screen:
1870 * @display: a #GdkDisplay
1872 * Get the default #GdkScreen for @display.
1874 * Returns: (transfer none): the default #GdkScreen object for @display
1879 gdk_display_get_default_screen (GdkDisplay *display)
1881 return GDK_DISPLAY_GET_CLASS(display)->get_default_screen (display);
1886 * @display: a #GdkDisplay
1888 * Emits a short beep on @display
1893 gdk_display_beep (GdkDisplay *display)
1895 GDK_DISPLAY_GET_CLASS(display)->beep (display);
1900 * @display: a #GdkDisplay
1902 * Flushes any requests queued for the windowing system and waits until all
1903 * requests have been handled. This is often used for making sure that the
1904 * display is synchronized with the current state of the program. Calling
1905 * gdk_display_sync() before gdk_error_trap_pop() makes sure that any errors
1906 * generated from earlier requests are handled before the error trap is
1909 * This is most useful for X11. On windowing systems where requests are
1910 * handled synchronously, this function will do nothing.
1915 gdk_display_sync (GdkDisplay *display)
1917 GDK_DISPLAY_GET_CLASS(display)->sync (display);
1921 * gdk_display_flush:
1922 * @display: a #GdkDisplay
1924 * Flushes any requests queued for the windowing system; this happens automatically
1925 * when the main loop blocks waiting for new events, but if your application
1926 * is drawing without returning control to the main loop, you may need
1927 * to call this function explicitely. A common case where this function
1928 * needs to be called is when an application is executing drawing commands
1929 * from a thread other than the thread where the main loop is running.
1931 * This is most useful for X11. On windowing systems where requests are
1932 * handled synchronously, this function will do nothing.
1937 gdk_display_flush (GdkDisplay *display)
1939 GDK_DISPLAY_GET_CLASS(display)->flush (display);
1943 * gdk_display_get_default_group:
1944 * @display: a #GdkDisplay
1946 * Returns the default group leader window for all toplevel windows
1947 * on @display. This window is implicitly created by GDK.
1948 * See gdk_window_set_group().
1950 * Return value: (transfer none): The default group leader window
1956 gdk_display_get_default_group (GdkDisplay *display)
1958 return GDK_DISPLAY_GET_CLASS(display)->get_default_group (display);
1962 * gdk_display_supports_selection_notification:
1963 * @display: a #GdkDisplay
1965 * Returns whether #GdkEventOwnerChange events will be
1966 * sent when the owner of a selection changes.
1968 * Return value: whether #GdkEventOwnerChange events will
1974 gdk_display_supports_selection_notification (GdkDisplay *display)
1976 return GDK_DISPLAY_GET_CLASS(display)->supports_selection_notification (display);
1980 * gdk_display_request_selection_notification:
1981 * @display: a #GdkDisplay
1982 * @selection: the #GdkAtom naming the selection for which
1983 * ownership change notification is requested
1985 * Request #GdkEventOwnerChange events for ownership changes
1986 * of the selection named by the given atom.
1988 * Return value: whether #GdkEventOwnerChange events will
1994 gdk_display_request_selection_notification (GdkDisplay *display,
1998 return GDK_DISPLAY_GET_CLASS(display)->request_selection_notification (display, selection);
2002 * gdk_display_supports_clipboard_persistence
2003 * @display: a #GdkDisplay
2005 * Returns whether the speicifed display supports clipboard
2006 * persistance; i.e. if it's possible to store the clipboard data after an
2007 * application has quit. On X11 this checks if a clipboard daemon is
2010 * Returns: %TRUE if the display supports clipboard persistance.
2015 gdk_display_supports_clipboard_persistence (GdkDisplay *display)
2017 return GDK_DISPLAY_GET_CLASS(display)->supports_clipboard_persistence (display);
2021 * gdk_display_store_clipboard
2022 * @display: a #GdkDisplay
2023 * @clipboard_window: a #GdkWindow belonging to the clipboard owner
2024 * @time_: a timestamp
2025 * @targets: an array of targets that should be saved, or %NULL
2026 * if all available targets should be saved.
2027 * @n_targets: length of the @targets array
2029 * Issues a request to the clipboard manager to store the
2030 * clipboard data. On X11, this is a special program that works
2031 * according to the freedesktop clipboard specification, available at
2032 * <ulink url="http://www.freedesktop.org/Standards/clipboard-manager-spec">
2033 * http://www.freedesktop.org/Standards/clipboard-manager-spec</ulink>.
2038 gdk_display_store_clipboard (GdkDisplay *display,
2039 GdkWindow *clipboard_window,
2041 const GdkAtom *targets,
2044 GDK_DISPLAY_GET_CLASS(display)->store_clipboard (display, clipboard_window, time_, targets, n_targets);
2048 * gdk_display_supports_shapes:
2049 * @display: a #GdkDisplay
2051 * Returns %TRUE if gdk_window_shape_combine_mask() can
2052 * be used to create shaped windows on @display.
2054 * Returns: %TRUE if shaped windows are supported
2059 gdk_display_supports_shapes (GdkDisplay *display)
2061 return GDK_DISPLAY_GET_CLASS(display)->supports_shapes (display);
2065 * gdk_display_supports_input_shapes:
2066 * @display: a #GdkDisplay
2068 * Returns %TRUE if gdk_window_input_shape_combine_mask() can
2069 * be used to modify the input shape of windows on @display.
2071 * Returns: %TRUE if windows with modified input shape are supported
2076 gdk_display_supports_input_shapes (GdkDisplay *display)
2078 return GDK_DISPLAY_GET_CLASS(display)->supports_input_shapes (display);
2082 * gdk_display_supports_composite:
2083 * @display: a #GdkDisplay
2085 * Returns %TRUE if gdk_window_set_composited() can be used
2086 * to redirect drawing on the window using compositing.
2088 * Currently this only works on X11 with XComposite and
2089 * XDamage extensions available.
2091 * Returns: %TRUE if windows may be composited.
2096 gdk_display_supports_composite (GdkDisplay *display)
2098 return GDK_DISPLAY_GET_CLASS(display)->supports_composite (display);
2102 * gdk_display_list_devices:
2103 * @display: a #GdkDisplay
2105 * Returns the list of available input devices attached to @display.
2106 * The list is statically allocated and should not be freed.
2108 * Return value: (transfer none) (element-type GdkDevice):
2109 * a list of #GdkDevice
2113 * Deprecated: 3.0: Use gdk_device_manager_list_devices() instead.
2116 gdk_display_list_devices (GdkDisplay *display)
2118 return GDK_DISPLAY_GET_CLASS(display)->list_devices (display);
2122 * gdk_event_send_client_message_for_display:
2123 * @display: the #GdkDisplay for the window where the message is to be sent.
2124 * @event: the #GdkEvent to send, which should be a #GdkEventClient.
2125 * @winid: the window to send the client message to.
2127 * On X11, sends an X ClientMessage event to a given window. On
2128 * Windows, sends a message registered with the name
2129 * GDK_WIN32_CLIENT_MESSAGE.
2131 * This could be used for communicating between different
2132 * applications, though the amount of data is limited to 20 bytes on
2133 * X11, and to just four bytes on Windows.
2135 * Returns: non-zero on success.
2140 gdk_event_send_client_message_for_display (GdkDisplay *display,
2142 GdkNativeWindow winid)
2144 return GDK_DISPLAY_GET_CLASS(display)->send_client_message (display, event, winid);
2148 * gdk_display_add_client_message_filter:
2149 * @display: a #GdkDisplay for which this message filter applies
2150 * @message_type: the type of ClientMessage events to receive.
2151 * This will be checked against the @message_type field
2152 * of the XClientMessage event struct.
2153 * @func: the function to call to process the event.
2154 * @data: user data to pass to @func.
2156 * Adds a filter to be called when X ClientMessage events are received.
2157 * See gdk_window_add_filter() if you are interested in filtering other
2163 gdk_display_add_client_message_filter (GdkDisplay *display,
2164 GdkAtom message_type,
2168 GDK_DISPLAY_GET_CLASS(display)->add_client_message_filter (display, message_type, func, data);
2172 * gdk_add_client_message_filter:
2173 * @message_type: the type of ClientMessage events to receive. This will be
2174 * checked against the <structfield>message_type</structfield> field of the
2175 * XClientMessage event struct.
2176 * @func: the function to call to process the event.
2177 * @data: user data to pass to @func.
2179 * Adds a filter to the default display to be called when X ClientMessage events
2180 * are received. See gdk_display_add_client_message_filter().
2183 gdk_add_client_message_filter (GdkAtom message_type,
2187 gdk_display_add_client_message_filter (gdk_display_get_default (),
2188 message_type, func, data);
2191 static GdkAppLaunchContext *
2192 gdk_display_real_get_app_launch_context (GdkDisplay *display)
2194 GdkAppLaunchContext *ctx;
2196 ctx = g_object_new (GDK_TYPE_APP_LAUNCH_CONTEXT,
2204 * gdk_display_get_app_launch_context:
2205 * @display: a #GdkDisplay
2207 * Returns a #GdkAppLaunchContext suitable for launching
2208 * applications on the given display.
2210 * Returns: a new #GdkAppLaunchContext for @display.
2211 * Free with g_object_unref() when done
2215 GdkAppLaunchContext *
2216 gdk_display_get_app_launch_context (GdkDisplay *display)
2218 return GDK_DISPLAY_GET_CLASS(display)->get_app_launch_context (display);
2222 * gdk_drag_get_protocol_for_display:
2223 * @display: the #GdkDisplay where the destination window resides
2224 * @xid: the windowing system id of the destination window.
2225 * @protocol: location where the supported DND protocol is returned.
2227 * Finds out the DND protocol supported by a window.
2229 * Return value: the windowing system id of the window where the drop
2230 * should happen. This may be @xid or the id of a proxy window,
2231 * or zero if @xid does not support Drag and Drop.
2236 gdk_drag_get_protocol_for_display (GdkDisplay *display,
2237 GdkNativeWindow xid,
2238 GdkDragProtocol *protocol)
2240 return GDK_DISPLAY_GET_CLASS (display)->get_drag_protocol (display, xid, protocol, NULL);
2245 * @display_name: the name of the display to open
2249 * Return value: (transfer none): a #GdkDisplay, or %NULL
2250 * if the display could not be opened
2255 gdk_display_open (const gchar *display_name)
2257 return gdk_display_manager_open_display (gdk_display_manager_get (), display_name);
2261 * gdk_display_has_pending:
2262 * @display: a #GdkDisplay
2264 * Returns whether the display has events that are waiting
2267 * Returns: %TRUE if there are events ready to be processed.
2272 gdk_display_has_pending (GdkDisplay *display)
2274 return GDK_DISPLAY_GET_CLASS (display)->has_pending (display);
2278 * gdk_display_supports_cursor_alpha:
2279 * @display: a #GdkDisplay
2281 * Returns %TRUE if cursors can use an 8bit alpha channel
2282 * on @display. Otherwise, cursors are restricted to bilevel
2283 * alpha (i.e. a mask).
2285 * Returns: whether cursors can have alpha channels.
2290 gdk_display_supports_cursor_alpha (GdkDisplay *display)
2292 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
2294 return GDK_DISPLAY_GET_CLASS (display)->supports_cursor_alpha (display);
2298 * gdk_display_supports_cursor_color:
2299 * @display: a #GdkDisplay
2301 * Returns %TRUE if multicolored cursors are supported
2302 * on @display. Otherwise, cursors have only a forground
2303 * and a background color.
2305 * Returns: whether cursors can have multiple colors.
2310 gdk_display_supports_cursor_color (GdkDisplay *display)
2312 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
2314 return GDK_DISPLAY_GET_CLASS (display)->supports_cursor_color (display);
2318 * gdk_display_get_default_cursor_size:
2319 * @display: a #GdkDisplay
2321 * Returns the default size to use for cursors on @display.
2323 * Returns: the default cursor size.
2328 gdk_display_get_default_cursor_size (GdkDisplay *display)
2330 guint width, height;
2332 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
2334 GDK_DISPLAY_GET_CLASS (display)->get_default_cursor_size (display,
2338 return MIN (width, height);
2342 * gdk_display_get_maximal_cursor_size:
2343 * @display: a #GdkDisplay
2344 * @width: (out): the return location for the maximal cursor width
2345 * @height: (out): the return location for the maximal cursor height
2347 * Gets the maximal size to use for cursors on @display.
2352 gdk_display_get_maximal_cursor_size (GdkDisplay *display,
2356 g_return_if_fail (GDK_IS_DISPLAY (display));
2358 GDK_DISPLAY_GET_CLASS (display)->get_maximal_cursor_size (display,
2364 * gdk_display_warp_pointer:
2365 * @display: a #GdkDisplay
2366 * @screen: the screen of @display to warp the pointer to
2367 * @x: the x coordinate of the destination
2368 * @y: the y coordinate of the destination
2370 * Warps the pointer of @display to the point @x,@y on
2371 * the screen @screen, unless the pointer is confined
2372 * to a window by a grab, in which case it will be moved
2373 * as far as allowed by the grab. Warping the pointer
2374 * creates events as if the user had moved the mouse
2375 * instantaneously to the destination.
2377 * Note that the pointer should normally be under the
2378 * control of the user. This function was added to cover
2379 * some rare use cases like keyboard navigation support
2380 * for the color picker in the #GtkColorSelectionDialog.
2384 * Deprecated: 3.0: Use gdk_device_warp() instead.
2387 gdk_display_warp_pointer (GdkDisplay *display,
2392 gdk_device_warp (display->core_pointer,
2398 _gdk_display_get_next_serial (GdkDisplay *display)
2400 return GDK_DISPLAY_GET_CLASS (display)->get_next_serial (display);
2405 * gdk_notify_startup_complete:
2407 * Indicates to the GUI environment that the application has finished
2408 * loading. If the applications opens windows, this function is
2409 * normally called after opening the application's initial set of
2412 * GTK+ will call this function automatically after opening the first
2413 * #GtkWindow unless gtk_window_set_auto_startup_notification() is called
2414 * to disable that feature.
2419 gdk_notify_startup_complete (void)
2421 gdk_notify_startup_complete_with_id (NULL);
2425 * gdk_notify_startup_complete_with_id:
2426 * @startup_id: a startup-notification identifier, for which
2427 * notification process should be completed
2429 * Indicates to the GUI environment that the application has
2430 * finished loading, using a given identifier.
2432 * GTK+ will call this function automatically for #GtkWindow
2433 * with custom startup-notification identifier unless
2434 * gtk_window_set_auto_startup_notification() is called to
2435 * disable that feature.
2440 gdk_notify_startup_complete_with_id (const gchar* startup_id)
2442 GdkDisplay *display;
2444 display = gdk_display_get_default ();
2446 gdk_display_notify_startup_complete (display, startup_id);
2450 * gdk_display_notify_startup_complete:
2451 * @display: a #GdkDisplay
2452 * @startup_id: a startup-notification identifier, for which
2453 * notification process should be completed
2455 * Indicates to the GUI environment that the application has
2456 * finished loading, using a given identifier.
2458 * GTK+ will call this function automatically for #GtkWindow
2459 * with custom startup-notification identifier unless
2460 * gtk_window_set_auto_startup_notification() is called to
2461 * disable that feature.
2466 gdk_display_notify_startup_complete (GdkDisplay *display,
2467 const gchar *startup_id)
2469 GDK_DISPLAY_GET_CLASS (display)->notify_startup_complete (display, startup_id);
2473 _gdk_display_event_data_copy (GdkDisplay *display,
2474 const GdkEvent *event,
2475 GdkEvent *new_event)
2477 GDK_DISPLAY_GET_CLASS (display)->event_data_copy (display, event, new_event);
2481 _gdk_display_event_data_free (GdkDisplay *display,
2484 GDK_DISPLAY_GET_CLASS (display)->event_data_free (display, event);
2488 _gdk_display_create_window_impl (GdkDisplay *display,
2490 GdkWindow *real_parent,
2492 GdkEventMask event_mask,
2493 GdkWindowAttr *attributes,
2494 gint attributes_mask)
2496 GDK_DISPLAY_GET_CLASS (display)->create_window_impl (display,
2506 _gdk_display_create_window (GdkDisplay *display)
2508 return g_object_new (GDK_DISPLAY_GET_CLASS (display)->window_type, NULL);
2512 * gdk_keymap_get_for_display:
2513 * @display: the #GdkDisplay.
2515 * Returns the #GdkKeymap attached to @display.
2517 * Return value: (transfer none): the #GdkKeymap attached to @display.
2522 gdk_keymap_get_for_display (GdkDisplay *display)
2524 return GDK_DISPLAY_GET_CLASS (display)->get_keymap (display);
2527 typedef struct _GdkGlobalErrorTrap GdkGlobalErrorTrap;
2529 struct _GdkGlobalErrorTrap
2534 static GQueue gdk_error_traps = G_QUEUE_INIT;
2537 * gdk_error_trap_push:
2539 * This function allows X errors to be trapped instead of the normal
2540 * behavior of exiting the application. It should only be used if it
2541 * is not possible to avoid the X error in any other way. Errors are
2542 * ignored on all #GdkDisplay currently known to the
2543 * #GdkDisplayManager. If you don't care which error happens and just
2544 * want to ignore everything, pop with gdk_error_trap_pop_ignored().
2545 * If you need the error code, use gdk_error_trap_pop() which may have
2546 * to block and wait for the error to arrive from the X server.
2548 * This API exists on all platforms but only does anything on X.
2550 * You can use gdk_x11_display_error_trap_push() to ignore errors
2551 * on only a single display.
2554 * <title>Trapping an X error</title>
2556 * gdk_error_trap_push (<!-- -->);
2558 * // ... Call the X function which may cause an error here ...
2561 * if (gdk_error_trap_pop (<!-- -->))
2563 * // ... Handle the error here ...
2569 gdk_error_trap_push (void)
2571 GdkDisplayManager *manager;
2572 GdkDisplayClass *class;
2573 GdkGlobalErrorTrap *trap;
2576 manager = gdk_display_manager_get ();
2577 class = GDK_DISPLAY_GET_CLASS (gdk_display_manager_get_default_display (manager));
2579 if (class->push_error_trap == NULL)
2582 trap = g_slice_new (GdkGlobalErrorTrap);
2583 trap->displays = gdk_display_manager_list_displays (manager);
2585 g_slist_foreach (trap->displays, (GFunc) g_object_ref, NULL);
2586 for (l = trap->displays; l != NULL; l = l->next)
2588 class->push_error_trap (l->data);
2591 g_queue_push_head (&gdk_error_traps, trap);
2595 gdk_error_trap_pop_internal (gboolean need_code)
2597 GdkDisplayManager *manager;
2598 GdkDisplayClass *class;
2599 GdkGlobalErrorTrap *trap;
2603 manager = gdk_display_manager_get ();
2604 class = GDK_DISPLAY_GET_CLASS (gdk_display_manager_get_default_display (manager));
2606 if (class->pop_error_trap == NULL)
2609 trap = g_queue_pop_head (&gdk_error_traps);
2611 g_return_val_if_fail (trap != NULL, 0);
2614 for (l = trap->displays; l != NULL; l = l->next)
2618 code = class->pop_error_trap (l->data, !need_code);
2620 /* we use the error on the last display listed, why not. */
2625 g_slist_free_full (trap->displays, g_object_unref);
2626 g_slice_free (GdkGlobalErrorTrap, trap);
2632 * gdk_error_trap_pop_ignored:
2634 * Removes an error trap pushed with gdk_error_trap_push(), but
2635 * without bothering to wait and see whether an error occurred. If an
2636 * error arrives later asynchronously that was triggered while the
2637 * trap was pushed, that error will be ignored.
2642 gdk_error_trap_pop_ignored (void)
2644 gdk_error_trap_pop_internal (FALSE);
2648 * gdk_error_trap_pop:
2650 * Removes an error trap pushed with gdk_error_trap_push().
2651 * May block until an error has been definitively received
2652 * or not received from the X server. gdk_error_trap_pop_ignored()
2653 * is preferred if you don't need to know whether an error
2654 * occurred, because it never has to block. If you don't
2655 * need the return value of gdk_error_trap_pop(), use
2656 * gdk_error_trap_pop_ignored().
2658 * Prior to GDK 3.0, this function would not automatically
2659 * sync for you, so you had to gdk_flush() if your last
2660 * call to Xlib was not a blocking round trip.
2662 * Return value: X error code or 0 on success
2665 gdk_error_trap_pop (void)
2667 return gdk_error_trap_pop_internal (TRUE);