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_device_state:
701 * @display: a #GdkDisplay.
702 * @device: pointer device to query status about.
703 * @screen: (out) (transfer none) (allow-none): location to store the #GdkScreen
704 * the @device is on, or %NULL.
705 * @x: (out) (allow-none): location to store root window X coordinate of @device, or %NULL.
706 * @y: (out) (allow-none): location to store root window Y coordinate of @device, or %NULL.
707 * @mask: (out) (allow-none): location to store current modifier mask for @device, or %NULL.
709 * Gets the current location and state of @device for a given display.
714 gdk_display_get_device_state (GdkDisplay *display,
719 GdkModifierType *mask)
721 GdkScreen *tmp_screen;
723 GdkModifierType tmp_mask;
725 g_return_if_fail (GDK_IS_DISPLAY (display));
726 g_return_if_fail (GDK_IS_DEVICE (device));
727 g_return_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD);
729 display->device_hooks->get_device_state (display, device, &tmp_screen, &tmp_x, &tmp_y, &tmp_mask);
732 *screen = tmp_screen;
742 * gdk_display_get_window_at_device_position:
743 * @display: a #GdkDisplay.
744 * @device: pointer #GdkDevice to query info to.
745 * @win_x: (out) (allow-none): return location for the X coordinate of the device location,
746 * relative to the window origin, or %NULL.
747 * @win_y: (out) (allow-none): return location for the Y coordinate of the device location,
748 * relative to the window origin, or %NULL.
750 * Obtains the window underneath @device, returning the location of the device in @win_x and @win_y. Returns
751 * %NULL if the window tree under @device is not known to GDK (for example, belongs to another application).
753 * Returns: (transfer none): the #GdkWindow under the device position, or %NULL.
758 gdk_display_get_window_at_device_position (GdkDisplay *display,
766 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
767 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
768 g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, NULL);
770 window = display->device_hooks->window_at_device_position (display, device, &tmp_x, &tmp_y);
781 * gdk_display_set_device_hooks:
782 * @display: a #GdkDisplay.
783 * @new_hooks: (allow-none): a table of pointers to functions for getting quantities related
784 * to all devices position, or %NULL to restore the default table.
786 * This function allows for hooking into the operation of getting the current location of any
787 * #GdkDevice on a particular #GdkDisplay. This is only useful for such low-level tools as
788 * an event recorder. Applications should never have any reason to use this facility.
790 * Returns: (transfer none): The previous device hook table.
794 GdkDisplayDeviceHooks *
795 gdk_display_set_device_hooks (GdkDisplay *display,
796 const GdkDisplayDeviceHooks *new_hooks)
798 const GdkDisplayDeviceHooks *result;
800 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
801 result = display->device_hooks;
804 display->device_hooks = new_hooks;
806 display->device_hooks = &default_device_hooks;
808 return (GdkDisplayDeviceHooks *) result;
812 * gdk_display_get_pointer:
813 * @display: a #GdkDisplay
814 * @screen: (allow-none): location to store the screen that the
815 * cursor is on, or %NULL.
816 * @x: (out) (allow-none): location to store root window X coordinate of pointer, or %NULL.
817 * @y: (out) (allow-none): location to store root window Y coordinate of pointer, or %NULL.
818 * @mask: (out) (allow-none): location to store current modifier mask, or %NULL
820 * Gets the current location of the pointer and the current modifier
821 * mask for a given display.
825 * Deprecated: 3.0: Use gdk_display_get_device_state() instead.
828 gdk_display_get_pointer (GdkDisplay *display,
832 GdkModifierType *mask)
834 g_return_if_fail (GDK_IS_DISPLAY (display));
836 gdk_display_get_device_state (display, display->core_pointer, screen, x, y, mask);
840 gdk_display_real_get_window_at_device_position (GdkDisplay *display,
848 window = _gdk_device_window_at_position (device, &x, &y, NULL, FALSE);
850 /* This might need corrections, as the native window returned
851 may contain client side children */
856 window = _gdk_window_find_descendant_at (window,
859 x = floor (xx + 0.5);
860 y = floor (yy + 0.5);
870 gdk_window_real_window_get_device_position (GdkDisplay *display,
875 GdkModifierType *mask)
878 GdkModifierType tmp_mask;
879 gboolean normal_child;
881 normal_child = GDK_WINDOW_IMPL_GET_CLASS (window->impl)->get_device_state (window,
885 /* We got the coords on the impl, convert to the window */
886 tmpx -= window->abs_x;
887 tmpy -= window->abs_y;
897 return _gdk_window_find_child_at (window, tmpx, tmpy);
902 * gdk_display_get_window_at_pointer:
903 * @display: a #GdkDisplay
904 * @win_x: (out) (allow-none): return location for x coordinate of the pointer location relative
905 * to the window origin, or %NULL
906 * @win_y: (out) (allow-none): return location for y coordinate of the pointer location relative
907 & to the window origin, or %NULL
909 * Obtains the window underneath the mouse pointer, returning the location
910 * of the pointer in that window in @win_x, @win_y for @screen. Returns %NULL
911 * if the window under the mouse pointer is not known to GDK (for example,
912 * belongs to another application).
914 * Returns: (transfer none): the window under the mouse pointer, or %NULL
918 * Deprecated: 3.0: Use gdk_display_get_window_at_device_position() instead.
921 gdk_display_get_window_at_pointer (GdkDisplay *display,
925 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
927 return gdk_display_get_window_at_device_position (display, display->core_pointer, win_x, win_y);
931 multihead_get_device_state (GdkDisplay *display,
936 GdkModifierType *mask)
938 multihead_current_pointer_hooks->get_pointer (display, screen, x, y, mask);
942 multihead_window_get_device_position (GdkDisplay *display,
947 GdkModifierType *mask)
949 return multihead_current_pointer_hooks->window_get_pointer (display, window, x, y, mask);
953 multihead_window_at_device_position (GdkDisplay *display,
958 return multihead_current_pointer_hooks->window_at_pointer (display, win_x, win_y);
962 gdk_display_real_get_device_state (GdkDisplay *display,
967 GdkModifierType *mask)
969 GdkScreen *default_screen;
972 if (gdk_display_is_closed (display))
975 default_screen = gdk_display_get_default_screen (display);
977 _gdk_device_query_state (device,
978 gdk_screen_get_root_window (default_screen),
984 *screen = gdk_window_get_screen (root);
988 multihead_default_get_pointer (GdkDisplay *display,
992 GdkModifierType *mask)
994 gdk_display_real_get_device_state (display, display->core_pointer,
999 multihead_default_window_get_pointer (GdkDisplay *display,
1003 GdkModifierType *mask)
1005 return gdk_window_real_window_get_device_position (display,
1006 display->core_pointer,
1007 window, x, y, mask);
1011 multihead_default_window_at_pointer (GdkDisplay *display,
1015 return gdk_display_real_get_window_at_device_position (display,
1016 display->core_pointer,
1021 * gdk_display_set_pointer_hooks:
1022 * @display: a #GdkDisplay
1023 * @new_hooks: (allow-none): a table of pointers to functions for getting
1024 * quantities related to the current pointer position,
1025 * or %NULL to restore the default table.
1027 * This function allows for hooking into the operation
1028 * of getting the current location of the pointer on a particular
1029 * display. This is only useful for such low-level tools as an
1030 * event recorder. Applications should never have any
1031 * reason to use this facility.
1033 * Return value: (transfer none): the previous pointer hook table
1037 * Deprecated: 3.0: Use gdk_display_set_device_hooks() instead.
1039 GdkDisplayPointerHooks *
1040 gdk_display_set_pointer_hooks (GdkDisplay *display,
1041 const GdkDisplayPointerHooks *new_hooks)
1043 const GdkDisplayPointerHooks *result = multihead_current_pointer_hooks;
1045 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1048 multihead_current_pointer_hooks = new_hooks;
1050 multihead_current_pointer_hooks = &multihead_default_pointer_hooks;
1052 gdk_display_set_device_hooks (display, &multihead_pointer_hooks);
1054 return (GdkDisplayPointerHooks *)result;
1058 singlehead_get_pointer (GdkDisplay *display,
1062 GdkModifierType *mask)
1064 GdkScreen *default_screen = gdk_display_get_default_screen (display);
1065 GdkWindow *root_window = gdk_screen_get_root_window (default_screen);
1067 *screen = default_screen;
1069 singlehead_current_pointer_hooks->get_pointer (root_window, x, y, mask);
1073 singlehead_window_get_pointer (GdkDisplay *display,
1077 GdkModifierType *mask)
1079 return singlehead_current_pointer_hooks->get_pointer (window, x, y, mask);
1083 singlehead_window_at_pointer (GdkDisplay *display,
1087 GdkScreen *default_screen = gdk_display_get_default_screen (display);
1089 return singlehead_current_pointer_hooks->window_at_pointer (default_screen,
1094 singlehead_default_window_get_pointer (GdkWindow *window,
1097 GdkModifierType *mask)
1099 GdkDisplay *display;
1101 display = gdk_window_get_display (window);
1103 return gdk_window_real_window_get_device_position (display,
1104 display->core_pointer,
1105 window, x, y, mask);
1109 singlehead_default_window_at_pointer (GdkScreen *screen,
1113 GdkDisplay *display;
1115 display = gdk_screen_get_display (screen);
1117 return gdk_display_real_get_window_at_device_position (display,
1118 display->core_pointer,
1123 * gdk_set_pointer_hooks:
1124 * @new_hooks: (allow-none): a table of pointers to functions for getting
1125 * quantities related to the current pointer position,
1126 * or %NULL to restore the default table.
1128 * This function allows for hooking into the operation
1129 * of getting the current location of the pointer. This
1130 * is only useful for such low-level tools as an
1131 * event recorder. Applications should never have any
1132 * reason to use this facility.
1134 * This function is not multihead safe. For multihead operation,
1135 * see gdk_display_set_pointer_hooks().
1137 * Return value: the previous pointer hook table
1139 * Deprecated: 3.0: Use gdk_display_set_device_hooks() instead.
1142 gdk_set_pointer_hooks (const GdkPointerHooks *new_hooks)
1144 const GdkPointerHooks *result = singlehead_current_pointer_hooks;
1147 singlehead_current_pointer_hooks = new_hooks;
1149 singlehead_current_pointer_hooks = &singlehead_default_pointer_hooks;
1151 gdk_display_set_pointer_hooks (gdk_display_get_default (),
1152 &singlehead_pointer_hooks);
1154 return (GdkPointerHooks *)result;
1158 generate_grab_broken_event (GdkWindow *window,
1161 GdkWindow *grab_window)
1163 g_return_if_fail (window != NULL);
1165 if (!GDK_WINDOW_DESTROYED (window))
1169 event = gdk_event_new (GDK_GRAB_BROKEN);
1170 event->grab_broken.window = g_object_ref (window);
1171 event->grab_broken.send_event = FALSE;
1172 event->grab_broken.implicit = implicit;
1173 event->grab_broken.grab_window = grab_window;
1174 gdk_event_set_device (event, device);
1175 event->grab_broken.keyboard = (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD) ? TRUE : FALSE;
1177 gdk_event_put (event);
1178 gdk_event_free (event);
1183 _gdk_display_get_last_device_grab (GdkDisplay *display,
1188 l = g_hash_table_lookup (display->device_grabs, device);
1192 l = g_list_last (l);
1200 _gdk_display_add_device_grab (GdkDisplay *display,
1203 GdkWindow *native_window,
1204 GdkGrabOwnership grab_ownership,
1205 gboolean owner_events,
1206 GdkEventMask event_mask,
1207 unsigned long serial_start,
1211 GdkDeviceGrabInfo *info, *other_info;
1214 info = g_new0 (GdkDeviceGrabInfo, 1);
1216 info->window = g_object_ref (window);
1217 info->native_window = g_object_ref (native_window);
1218 info->serial_start = serial_start;
1219 info->serial_end = G_MAXULONG;
1220 info->owner_events = owner_events;
1221 info->event_mask = event_mask;
1223 info->implicit = implicit;
1224 info->ownership = grab_ownership;
1226 grabs = g_hash_table_lookup (display->device_grabs, device);
1228 /* Find the first grab that has a larger start time (if any) and insert
1229 * before that. I.E we insert after already existing grabs with same
1231 for (l = grabs; l != NULL; l = l->next)
1233 other_info = l->data;
1235 if (info->serial_start < other_info->serial_start)
1239 grabs = g_list_insert_before (grabs, l, info);
1241 /* Make sure the new grab end before next grab */
1244 other_info = l->data;
1245 info->serial_end = other_info->serial_start;
1248 /* Find any previous grab and update its end time */
1249 l = g_list_find (grabs, info);
1253 other_info = l->data;
1254 other_info->serial_end = serial_start;
1257 g_hash_table_insert (display->device_grabs, device, grabs);
1262 /* _gdk_synthesize_crossing_events only works inside one toplevel.
1263 This function splits things into two calls if needed, converting the
1264 coordinates to the right toplevel */
1266 synthesize_crossing_events (GdkDisplay *display,
1268 GdkDevice *source_device,
1269 GdkWindow *src_window,
1270 GdkWindow *dest_window,
1271 GdkCrossingMode crossing_mode,
1275 GdkWindow *src_toplevel, *dest_toplevel;
1276 GdkModifierType state;
1279 /* We use the native crossing events if all native */
1280 if (_gdk_native_windows)
1284 src_toplevel = gdk_window_get_toplevel (src_window);
1286 src_toplevel = NULL;
1288 dest_toplevel = gdk_window_get_toplevel (dest_window);
1290 dest_toplevel = NULL;
1292 if (src_toplevel == NULL && dest_toplevel == NULL)
1295 if (src_toplevel == NULL ||
1296 src_toplevel == dest_toplevel)
1298 /* Same toplevels */
1299 gdk_window_get_pointer (dest_toplevel,
1301 _gdk_synthesize_crossing_events (display,
1304 device, source_device,
1311 else if (dest_toplevel == NULL)
1313 gdk_window_get_pointer (src_toplevel,
1315 _gdk_synthesize_crossing_events (display,
1318 device, source_device,
1327 /* Different toplevels */
1328 gdk_window_get_pointer (src_toplevel,
1330 _gdk_synthesize_crossing_events (display,
1333 device, source_device,
1339 gdk_window_get_pointer (dest_toplevel,
1341 _gdk_synthesize_crossing_events (display,
1344 device, source_device,
1354 get_current_toplevel (GdkDisplay *display,
1358 GdkModifierType *state_out)
1360 GdkWindow *pointer_window;
1362 GdkModifierType state;
1364 pointer_window = _gdk_device_window_at_position (device, &x, &y, &state, TRUE);
1366 if (pointer_window != NULL &&
1367 (GDK_WINDOW_DESTROYED (pointer_window) ||
1368 GDK_WINDOW_TYPE (pointer_window) == GDK_WINDOW_ROOT ||
1369 GDK_WINDOW_TYPE (pointer_window) == GDK_WINDOW_FOREIGN))
1370 pointer_window = NULL;
1376 return pointer_window;
1380 switch_to_pointer_grab (GdkDisplay *display,
1382 GdkDevice *source_device,
1383 GdkDeviceGrabInfo *grab,
1384 GdkDeviceGrabInfo *last_grab,
1388 GdkWindow *src_window, *pointer_window, *new_toplevel;
1389 GdkPointerWindowInfo *info;
1391 GdkModifierType state;
1394 /* Temporarily unset pointer to make sure we send the crossing events below */
1395 old_grabs = g_hash_table_lookup (display->device_grabs, device);
1396 g_hash_table_steal (display->device_grabs, device);
1397 info = _gdk_display_get_pointer_info (display, device);
1401 /* New grab is in effect */
1403 /* We need to generate crossing events for the grab.
1404 * However, there are never any crossing events for implicit grabs
1405 * TODO: ... Actually, this could happen if the pointer window
1406 * doesn't have button mask so a parent gets the event...
1408 if (!grab->implicit)
1410 /* We send GRAB crossing events from the window under the pointer to the
1411 grab window. Except if there is an old grab then we start from that */
1413 src_window = last_grab->window;
1415 src_window = info->window_under_pointer;
1417 if (src_window != grab->window)
1418 synthesize_crossing_events (display, device, source_device,
1419 src_window, grab->window,
1420 GDK_CROSSING_GRAB, time, serial);
1422 /* !owner_event Grabbing a window that we're not inside, current status is
1423 now NULL (i.e. outside grabbed window) */
1424 if (!grab->owner_events && info->window_under_pointer != grab->window)
1425 _gdk_display_set_window_under_pointer (display, device, NULL);
1428 grab->activated = TRUE;
1433 new_toplevel = NULL;
1435 if (grab == NULL /* ungrab */ ||
1436 (!last_grab->owner_events && grab->owner_events) /* switched to owner_events */ )
1438 /* We force check what window we're in, and update the toplevel_under_pointer info,
1439 * as that won't get told of this change with toplevel enter events.
1441 if (info->toplevel_under_pointer)
1442 g_object_unref (info->toplevel_under_pointer);
1443 info->toplevel_under_pointer = NULL;
1445 new_toplevel = get_current_toplevel (display, device, &x, &y, &state);
1448 /* w is now toplevel and x,y in toplevel coords */
1449 info->toplevel_under_pointer = g_object_ref (new_toplevel);
1450 info->toplevel_x = x;
1451 info->toplevel_y = y;
1452 info->state = state;
1456 if (grab == NULL) /* Ungrabbed, send events */
1458 pointer_window = NULL;
1461 /* Find (possibly virtual) child window */
1463 _gdk_window_find_descendant_at (new_toplevel,
1468 if (pointer_window != last_grab->window)
1469 synthesize_crossing_events (display, device, source_device,
1470 last_grab->window, pointer_window,
1471 GDK_CROSSING_UNGRAB, time, serial);
1473 /* We're now ungrabbed, update the window_under_pointer */
1474 _gdk_display_set_window_under_pointer (display, device, pointer_window);
1478 g_hash_table_insert (display->device_grabs, device, old_grabs);
1482 _gdk_display_device_grab_update (GdkDisplay *display,
1484 GdkDevice *source_device,
1485 gulong current_serial)
1487 GdkDeviceGrabInfo *current_grab, *next_grab;
1491 time = display->last_event_time;
1492 grabs = g_hash_table_lookup (display->device_grabs, device);
1494 while (grabs != NULL)
1496 current_grab = grabs->data;
1498 if (current_grab->serial_start > current_serial)
1499 return; /* Hasn't started yet */
1501 if (current_grab->serial_end > current_serial)
1503 /* This one hasn't ended yet.
1504 its the currently active one or scheduled to be active */
1506 if (!current_grab->activated)
1508 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
1509 switch_to_pointer_grab (display, device, source_device, current_grab, NULL, time, current_serial);
1518 /* This is the next active grab */
1519 next_grab = grabs->next->data;
1521 if (next_grab->serial_start > current_serial)
1522 next_grab = NULL; /* Actually its not yet active */
1525 if ((next_grab == NULL && current_grab->implicit_ungrab) ||
1526 (next_grab != NULL && current_grab->window != next_grab->window))
1527 generate_grab_broken_event (GDK_WINDOW (current_grab->window),
1529 current_grab->implicit,
1530 next_grab? next_grab->window : NULL);
1532 /* Remove old grab */
1533 grabs = g_list_delete_link (grabs, grabs);
1534 g_hash_table_insert (display->device_grabs, device, grabs);
1536 if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
1537 switch_to_pointer_grab (display, device, source_device,
1538 next_grab, current_grab,
1539 time, current_serial);
1541 free_device_grab (current_grab);
1546 grab_list_find (GList *grabs,
1549 GdkDeviceGrabInfo *grab;
1555 if (serial >= grab->serial_start && serial < grab->serial_end)
1558 grabs = grabs->next;
1565 find_device_grab (GdkDisplay *display,
1571 l = g_hash_table_lookup (display->device_grabs, device);
1572 return grab_list_find (l, serial);
1576 _gdk_display_has_device_grab (GdkDisplay *display,
1582 l = find_device_grab (display, device, serial);
1589 /* Returns true if last grab was ended
1590 * If if_child is non-NULL, end the grab only if the grabbed
1591 * window is the same as if_child or a descendant of it */
1593 _gdk_display_end_device_grab (GdkDisplay *display,
1596 GdkWindow *if_child,
1599 GdkDeviceGrabInfo *grab;
1602 l = find_device_grab (display, device, serial);
1609 (if_child == NULL ||
1610 _gdk_window_event_parent_of (if_child, grab->window)))
1612 grab->serial_end = serial;
1613 grab->implicit_ungrab = implicit;
1614 return l->next == NULL;
1620 /* Returns TRUE if device events are not blocked by any grab */
1622 _gdk_display_check_grab_ownership (GdkDisplay *display,
1626 GHashTableIter iter;
1627 gpointer key, value;
1628 GdkGrabOwnership higher_ownership, device_ownership;
1629 gboolean device_is_keyboard;
1631 g_hash_table_iter_init (&iter, display->device_grabs);
1632 higher_ownership = device_ownership = GDK_OWNERSHIP_NONE;
1633 device_is_keyboard = (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD);
1635 while (g_hash_table_iter_next (&iter, &key, &value))
1637 GdkDeviceGrabInfo *grab;
1643 grabs = grab_list_find (grabs, serial);
1648 /* Discard device if it's not of the same type */
1649 if ((device_is_keyboard && gdk_device_get_source (dev) != GDK_SOURCE_KEYBOARD) ||
1650 (!device_is_keyboard && gdk_device_get_source (dev) == GDK_SOURCE_KEYBOARD))
1656 device_ownership = grab->ownership;
1659 if (grab->ownership > higher_ownership)
1660 higher_ownership = grab->ownership;
1664 if (higher_ownership > device_ownership)
1666 /* There's a higher priority ownership
1667 * going on for other device(s)
1675 GdkPointerWindowInfo *
1676 _gdk_display_get_pointer_info (GdkDisplay *display,
1679 GdkPointerWindowInfo *info;
1681 if (G_UNLIKELY (!device))
1684 info = g_hash_table_lookup (display->pointers_info, device);
1686 if (G_UNLIKELY (!info))
1688 info = g_slice_new0 (GdkPointerWindowInfo);
1689 g_hash_table_insert (display->pointers_info, device, info);
1696 _gdk_display_pointer_info_foreach (GdkDisplay *display,
1697 GdkDisplayPointerInfoForeach func,
1700 GHashTableIter iter;
1701 gpointer key, value;
1703 g_hash_table_iter_init (&iter, display->pointers_info);
1705 while (g_hash_table_iter_next (&iter, &key, &value))
1707 GdkPointerWindowInfo *info = value;
1708 GdkDevice *device = key;
1710 (func) (display, device, info, user_data);
1715 * gdk_device_grab_info_libgtk_only:
1716 * @display: the display for which to get the grab information
1717 * @device: device to get the grab information from
1718 * @grab_window: (out) (transfer none): location to store current grab window
1719 * @owner_events: (out): location to store boolean indicating whether
1720 * the @owner_events flag to gdk_keyboard_grab() or
1721 * gdk_pointer_grab() was %TRUE.
1723 * Determines information about the current keyboard grab.
1724 * This is not public API and must not be used by applications.
1726 * Return value: %TRUE if this application currently has the
1730 gdk_device_grab_info_libgtk_only (GdkDisplay *display,
1732 GdkWindow **grab_window,
1733 gboolean *owner_events)
1735 GdkDeviceGrabInfo *info;
1737 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1738 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
1740 info = _gdk_display_get_last_device_grab (display, device);
1745 *grab_window = info->window;
1747 *owner_events = info->owner_events;
1756 * gdk_display_pointer_is_grabbed:
1757 * @display: a #GdkDisplay
1759 * Test if the pointer is grabbed.
1761 * Returns: %TRUE if an active X pointer grab is in effect
1765 * Deprecated: 3.0: Use gdk_display_device_is_grabbed() instead.
1768 gdk_display_pointer_is_grabbed (GdkDisplay *display)
1770 GdkDeviceManager *device_manager;
1771 GList *devices, *dev;
1774 g_return_val_if_fail (GDK_IS_DISPLAY (display), TRUE);
1776 device_manager = gdk_display_get_device_manager (display);
1777 devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
1779 for (dev = devices; dev; dev = dev->next)
1783 if (gdk_device_get_source (device) == GDK_SOURCE_MOUSE &&
1784 gdk_display_device_is_grabbed (display, device))
1792 * gdk_display_device_is_grabbed:
1793 * @display: a #GdkDisplay
1794 * @device: a #GdkDevice
1796 * Returns %TRUE if there is an ongoing grab on @device for @display.
1798 * Returns: %TRUE if there is a grab in effect for @device.
1801 gdk_display_device_is_grabbed (GdkDisplay *display,
1804 GdkDeviceGrabInfo *info;
1806 g_return_val_if_fail (GDK_IS_DISPLAY (display), TRUE);
1807 g_return_val_if_fail (GDK_IS_DEVICE (device), TRUE);
1809 /* What we're interested in is the steady state (ie last grab),
1810 because we're interested e.g. if we grabbed so that we
1811 can ungrab, even if our grab is not active just yet. */
1812 info = _gdk_display_get_last_device_grab (display, device);
1814 return (info && !info->implicit);
1818 * gdk_display_get_device_manager:
1819 * @display: a #GdkDisplay.
1821 * Returns the #GdkDeviceManager associated to @display.
1823 * Returns: (transfer none): A #GdkDeviceManager, or %NULL. This memory is
1824 * owned by GDK and must not be freed or unreferenced.
1829 gdk_display_get_device_manager (GdkDisplay *display)
1831 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1833 return display->device_manager;
1837 * gdk_display_get_name:
1838 * @display: a #GdkDisplay
1840 * Gets the name of the display.
1842 * Returns: a string representing the display name. This string is owned
1843 * by GDK and should not be modified or freed.
1847 G_CONST_RETURN gchar *
1848 gdk_display_get_name (GdkDisplay *display)
1850 return GDK_DISPLAY_GET_CLASS(display)->get_name (display);
1854 gdk_get_display (void)
1856 return g_strdup (gdk_display_get_name (gdk_display_get_default ()));
1860 * gdk_display_get_n_screens:
1861 * @display: a #GdkDisplay
1863 * Gets the number of screen managed by the @display.
1865 * Returns: number of screens.
1870 gdk_display_get_n_screens (GdkDisplay *display)
1872 return GDK_DISPLAY_GET_CLASS(display)->get_n_screens (display);
1876 * gdk_display_get_screen:
1877 * @display: a #GdkDisplay
1878 * @screen_num: the screen number
1880 * Returns a screen object for one of the screens of the display.
1882 * Returns: (transfer none): the #GdkScreen object
1887 gdk_display_get_screen (GdkDisplay *display,
1890 return GDK_DISPLAY_GET_CLASS(display)->get_screen (display, screen_num);
1894 * gdk_display_get_default_screen:
1895 * @display: a #GdkDisplay
1897 * Get the default #GdkScreen for @display.
1899 * Returns: (transfer none): the default #GdkScreen object for @display
1904 gdk_display_get_default_screen (GdkDisplay *display)
1906 return GDK_DISPLAY_GET_CLASS(display)->get_default_screen (display);
1911 * @display: a #GdkDisplay
1913 * Emits a short beep on @display
1918 gdk_display_beep (GdkDisplay *display)
1920 GDK_DISPLAY_GET_CLASS(display)->beep (display);
1925 * @display: a #GdkDisplay
1927 * Flushes any requests queued for the windowing system and waits until all
1928 * requests have been handled. This is often used for making sure that the
1929 * display is synchronized with the current state of the program. Calling
1930 * gdk_display_sync() before gdk_error_trap_pop() makes sure that any errors
1931 * generated from earlier requests are handled before the error trap is
1934 * This is most useful for X11. On windowing systems where requests are
1935 * handled synchronously, this function will do nothing.
1940 gdk_display_sync (GdkDisplay *display)
1942 GDK_DISPLAY_GET_CLASS(display)->sync (display);
1946 * gdk_display_flush:
1947 * @display: a #GdkDisplay
1949 * Flushes any requests queued for the windowing system; this happens automatically
1950 * when the main loop blocks waiting for new events, but if your application
1951 * is drawing without returning control to the main loop, you may need
1952 * to call this function explicitely. A common case where this function
1953 * needs to be called is when an application is executing drawing commands
1954 * from a thread other than the thread where the main loop is running.
1956 * This is most useful for X11. On windowing systems where requests are
1957 * handled synchronously, this function will do nothing.
1962 gdk_display_flush (GdkDisplay *display)
1964 GDK_DISPLAY_GET_CLASS(display)->flush (display);
1968 * gdk_display_get_default_group:
1969 * @display: a #GdkDisplay
1971 * Returns the default group leader window for all toplevel windows
1972 * on @display. This window is implicitly created by GDK.
1973 * See gdk_window_set_group().
1975 * Return value: (transfer none): The default group leader window
1981 gdk_display_get_default_group (GdkDisplay *display)
1983 return GDK_DISPLAY_GET_CLASS(display)->get_default_group (display);
1987 * gdk_display_supports_selection_notification:
1988 * @display: a #GdkDisplay
1990 * Returns whether #GdkEventOwnerChange events will be
1991 * sent when the owner of a selection changes.
1993 * Return value: whether #GdkEventOwnerChange events will
1999 gdk_display_supports_selection_notification (GdkDisplay *display)
2001 return GDK_DISPLAY_GET_CLASS(display)->supports_selection_notification (display);
2005 * gdk_display_request_selection_notification:
2006 * @display: a #GdkDisplay
2007 * @selection: the #GdkAtom naming the selection for which
2008 * ownership change notification is requested
2010 * Request #GdkEventOwnerChange events for ownership changes
2011 * of the selection named by the given atom.
2013 * Return value: whether #GdkEventOwnerChange events will
2019 gdk_display_request_selection_notification (GdkDisplay *display,
2023 return GDK_DISPLAY_GET_CLASS(display)->request_selection_notification (display, selection);
2027 * gdk_display_supports_clipboard_persistence
2028 * @display: a #GdkDisplay
2030 * Returns whether the speicifed display supports clipboard
2031 * persistance; i.e. if it's possible to store the clipboard data after an
2032 * application has quit. On X11 this checks if a clipboard daemon is
2035 * Returns: %TRUE if the display supports clipboard persistance.
2040 gdk_display_supports_clipboard_persistence (GdkDisplay *display)
2042 return GDK_DISPLAY_GET_CLASS(display)->supports_clipboard_persistence (display);
2046 * gdk_display_store_clipboard
2047 * @display: a #GdkDisplay
2048 * @clipboard_window: a #GdkWindow belonging to the clipboard owner
2049 * @time_: a timestamp
2050 * @targets: an array of targets that should be saved, or %NULL
2051 * if all available targets should be saved.
2052 * @n_targets: length of the @targets array
2054 * Issues a request to the clipboard manager to store the
2055 * clipboard data. On X11, this is a special program that works
2056 * according to the freedesktop clipboard specification, available at
2057 * <ulink url="http://www.freedesktop.org/Standards/clipboard-manager-spec">
2058 * http://www.freedesktop.org/Standards/clipboard-manager-spec</ulink>.
2063 gdk_display_store_clipboard (GdkDisplay *display,
2064 GdkWindow *clipboard_window,
2066 const GdkAtom *targets,
2069 GDK_DISPLAY_GET_CLASS(display)->store_clipboard (display, clipboard_window, time_, targets, n_targets);
2073 * gdk_display_supports_shapes:
2074 * @display: a #GdkDisplay
2076 * Returns %TRUE if gdk_window_shape_combine_mask() can
2077 * be used to create shaped windows on @display.
2079 * Returns: %TRUE if shaped windows are supported
2084 gdk_display_supports_shapes (GdkDisplay *display)
2086 return GDK_DISPLAY_GET_CLASS(display)->supports_shapes (display);
2090 * gdk_display_supports_input_shapes:
2091 * @display: a #GdkDisplay
2093 * Returns %TRUE if gdk_window_input_shape_combine_mask() can
2094 * be used to modify the input shape of windows on @display.
2096 * Returns: %TRUE if windows with modified input shape are supported
2101 gdk_display_supports_input_shapes (GdkDisplay *display)
2103 return GDK_DISPLAY_GET_CLASS(display)->supports_input_shapes (display);
2107 * gdk_display_supports_composite:
2108 * @display: a #GdkDisplay
2110 * Returns %TRUE if gdk_window_set_composited() can be used
2111 * to redirect drawing on the window using compositing.
2113 * Currently this only works on X11 with XComposite and
2114 * XDamage extensions available.
2116 * Returns: %TRUE if windows may be composited.
2121 gdk_display_supports_composite (GdkDisplay *display)
2123 return GDK_DISPLAY_GET_CLASS(display)->supports_composite (display);
2127 * gdk_display_list_devices:
2128 * @display: a #GdkDisplay
2130 * Returns the list of available input devices attached to @display.
2131 * The list is statically allocated and should not be freed.
2133 * Return value: (transfer none) (element-type GdkDevice):
2134 * a list of #GdkDevice
2138 * Deprecated: 3.0: Use gdk_device_manager_list_devices() instead.
2141 gdk_display_list_devices (GdkDisplay *display)
2143 return GDK_DISPLAY_GET_CLASS(display)->list_devices (display);
2147 * gdk_event_send_client_message_for_display:
2148 * @display: the #GdkDisplay for the window where the message is to be sent.
2149 * @event: the #GdkEvent to send, which should be a #GdkEventClient.
2150 * @winid: the window to send the client message to.
2152 * On X11, sends an X ClientMessage event to a given window. On
2153 * Windows, sends a message registered with the name
2154 * GDK_WIN32_CLIENT_MESSAGE.
2156 * This could be used for communicating between different
2157 * applications, though the amount of data is limited to 20 bytes on
2158 * X11, and to just four bytes on Windows.
2160 * Returns: non-zero on success.
2165 gdk_event_send_client_message_for_display (GdkDisplay *display,
2167 GdkNativeWindow winid)
2169 return GDK_DISPLAY_GET_CLASS(display)->send_client_message (display, event, winid);
2173 * gdk_display_add_client_message_filter:
2174 * @display: a #GdkDisplay for which this message filter applies
2175 * @message_type: the type of ClientMessage events to receive.
2176 * This will be checked against the @message_type field
2177 * of the XClientMessage event struct.
2178 * @func: the function to call to process the event.
2179 * @data: user data to pass to @func.
2181 * Adds a filter to be called when X ClientMessage events are received.
2182 * See gdk_window_add_filter() if you are interested in filtering other
2188 gdk_display_add_client_message_filter (GdkDisplay *display,
2189 GdkAtom message_type,
2193 GDK_DISPLAY_GET_CLASS(display)->add_client_message_filter (display, message_type, func, data);
2197 * gdk_add_client_message_filter:
2198 * @message_type: the type of ClientMessage events to receive. This will be
2199 * checked against the <structfield>message_type</structfield> field of the
2200 * XClientMessage event struct.
2201 * @func: the function to call to process the event.
2202 * @data: user data to pass to @func.
2204 * Adds a filter to the default display to be called when X ClientMessage events
2205 * are received. See gdk_display_add_client_message_filter().
2208 gdk_add_client_message_filter (GdkAtom message_type,
2212 gdk_display_add_client_message_filter (gdk_display_get_default (),
2213 message_type, func, data);
2216 static GdkAppLaunchContext *
2217 gdk_display_real_get_app_launch_context (GdkDisplay *display)
2219 GdkAppLaunchContext *ctx;
2221 ctx = gdk_app_launch_context_new ();
2222 gdk_app_launch_context_set_display (ctx, display);
2228 * gdk_display_get_app_launch_context:
2229 * @display: a #GdkDisplay
2231 * Returns a #GdkAppLaunchContext suitable for launching
2232 * applications on the given display.
2234 * Returns: a new #GdkAppLaunchContext for @display.
2235 * Free with g_object_unref() when done
2239 GdkAppLaunchContext *
2240 gdk_display_get_app_launch_context (GdkDisplay *display)
2242 return GDK_DISPLAY_GET_CLASS(display)->get_app_launch_context (display);
2246 * gdk_drag_get_protocol_for_display:
2247 * @display: the #GdkDisplay where the destination window resides
2248 * @xid: the windowing system id of the destination window.
2249 * @protocol: location where the supported DND protocol is returned.
2251 * Finds out the DND protocol supported by a window.
2253 * Return value: the windowing system id of the window where the drop
2254 * should happen. This may be @xid or the id of a proxy window,
2255 * or zero if @xid does not support Drag and Drop.
2260 gdk_drag_get_protocol_for_display (GdkDisplay *display,
2261 GdkNativeWindow xid,
2262 GdkDragProtocol *protocol)
2264 return GDK_DISPLAY_GET_CLASS (display)->get_drag_protocol (display, xid, protocol, NULL);
2269 * @display_name: the name of the display to open
2273 * Return value: (transfer none): a #GdkDisplay, or %NULL if the display
2274 * could not be opened.
2279 gdk_display_open (const gchar *display_name)
2281 return gdk_display_manager_open_display (gdk_display_manager_get (), display_name);
2285 gdk_display_has_pending (GdkDisplay *display)
2287 return GDK_DISPLAY_GET_CLASS (display)->has_pending (display);
2291 * gdk_display_supports_cursor_alpha:
2292 * @display: a #GdkDisplay
2294 * Returns %TRUE if cursors can use an 8bit alpha channel
2295 * on @display. Otherwise, cursors are restricted to bilevel
2296 * alpha (i.e. a mask).
2298 * Returns: whether cursors can have alpha channels.
2303 gdk_display_supports_cursor_alpha (GdkDisplay *display)
2305 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
2307 return GDK_DISPLAY_GET_CLASS (display)->supports_cursor_alpha (display);
2311 * gdk_display_supports_cursor_color:
2312 * @display: a #GdkDisplay
2314 * Returns %TRUE if multicolored cursors are supported
2315 * on @display. Otherwise, cursors have only a forground
2316 * and a background color.
2318 * Returns: whether cursors can have multiple colors.
2323 gdk_display_supports_cursor_color (GdkDisplay *display)
2325 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
2327 return GDK_DISPLAY_GET_CLASS (display)->supports_cursor_color (display);
2331 * gdk_display_get_default_cursor_size:
2332 * @display: a #GdkDisplay
2334 * Returns the default size to use for cursors on @display.
2336 * Returns: the default cursor size.
2341 gdk_display_get_default_cursor_size (GdkDisplay *display)
2343 guint width, height;
2345 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
2347 GDK_DISPLAY_GET_CLASS (display)->get_default_cursor_size (display,
2351 return MIN (width, height);
2355 * gdk_display_get_maximal_cursor_size:
2356 * @display: a #GdkDisplay
2357 * @width: (out): the return location for the maximal cursor width
2358 * @height: (out): the return location for the maximal cursor height
2360 * Gets the maximal size to use for cursors on @display.
2365 gdk_display_get_maximal_cursor_size (GdkDisplay *display,
2369 g_return_if_fail (GDK_IS_DISPLAY (display));
2371 GDK_DISPLAY_GET_CLASS (display)->get_maximal_cursor_size (display,
2377 * gdk_display_warp_pointer:
2378 * @display: a #GdkDisplay
2379 * @screen: the screen of @display to warp the pointer to
2380 * @x: the x coordinate of the destination
2381 * @y: the y coordinate of the destination
2383 * Warps the pointer of @display to the point @x,@y on
2384 * the screen @screen, unless the pointer is confined
2385 * to a window by a grab, in which case it will be moved
2386 * as far as allowed by the grab. Warping the pointer
2387 * creates events as if the user had moved the mouse
2388 * instantaneously to the destination.
2390 * Note that the pointer should normally be under the
2391 * control of the user. This function was added to cover
2392 * some rare use cases like keyboard navigation support
2393 * for the color picker in the #GtkColorSelectionDialog.
2397 * Deprecated: 3.0: Use gdk_device_warp() instead.
2400 gdk_display_warp_pointer (GdkDisplay *display,
2405 gdk_device_warp (display->core_pointer,
2411 _gdk_display_get_next_serial (GdkDisplay *display)
2413 return GDK_DISPLAY_GET_CLASS (display)->get_next_serial (display);
2418 * gdk_notify_startup_complete:
2420 * Indicates to the GUI environment that the application has finished
2421 * loading. If the applications opens windows, this function is
2422 * normally called after opening the application's initial set of
2425 * GTK+ will call this function automatically after opening the first
2426 * #GtkWindow unless gtk_window_set_auto_startup_notification() is called
2427 * to disable that feature.
2432 gdk_notify_startup_complete (void)
2434 gdk_notify_startup_complete_with_id (NULL);
2438 * gdk_notify_startup_complete_with_id:
2439 * @startup_id: a startup-notification identifier, for which notification
2440 * process should be completed
2442 * Indicates to the GUI environment that the application has finished
2443 * loading, using a given identifier.
2445 * GTK+ will call this function automatically for #GtkWindow with custom
2446 * startup-notification identifier unless
2447 * gtk_window_set_auto_startup_notification() is called to disable
2453 gdk_notify_startup_complete_with_id (const gchar* startup_id)
2455 GdkDisplay *display;
2457 display = gdk_display_get_default ();
2459 gdk_display_notify_startup_complete (display, startup_id);
2463 gdk_display_notify_startup_complete (GdkDisplay *display,
2464 const gchar *startup_id)
2466 GDK_DISPLAY_GET_CLASS (display)->notify_startup_complete (display, startup_id);
2470 _gdk_display_event_data_copy (GdkDisplay *display,
2471 const GdkEvent *event,
2472 GdkEvent *new_event)
2474 GDK_DISPLAY_GET_CLASS (display)->event_data_copy (display, event, new_event);
2478 _gdk_display_event_data_free (GdkDisplay *display,
2481 GDK_DISPLAY_GET_CLASS (display)->event_data_free (display, event);
2485 _gdk_display_create_window_impl (GdkDisplay *display,
2487 GdkWindow *real_parent,
2489 GdkEventMask event_mask,
2490 GdkWindowAttr *attributes,
2491 gint attributes_mask)
2493 GDK_DISPLAY_GET_CLASS (display)->create_window_impl (display,
2503 _gdk_display_create_window (GdkDisplay *display)
2505 return g_object_new (GDK_DISPLAY_GET_CLASS (display)->window_type, NULL);
2509 * gdk_keymap_get_for_display:
2510 * @display: the #GdkDisplay.
2512 * Returns the #GdkKeymap attached to @display.
2514 * Return value: (transfer none): the #GdkKeymap attached to @display.
2519 gdk_keymap_get_for_display (GdkDisplay *display)
2521 return GDK_DISPLAY_GET_CLASS (display)->get_keymap (display);
2524 typedef struct _GdkGlobalErrorTrap GdkGlobalErrorTrap;
2526 struct _GdkGlobalErrorTrap
2531 static GQueue gdk_error_traps = G_QUEUE_INIT;
2534 * gdk_error_trap_push:
2536 * This function allows X errors to be trapped instead of the normal
2537 * behavior of exiting the application. It should only be used if it
2538 * is not possible to avoid the X error in any other way. Errors are
2539 * ignored on all #GdkDisplay currently known to the
2540 * #GdkDisplayManager. If you don't care which error happens and just
2541 * want to ignore everything, pop with gdk_error_trap_pop_ignored().
2542 * If you need the error code, use gdk_error_trap_pop() which may have
2543 * to block and wait for the error to arrive from the X server.
2545 * This API exists on all platforms but only does anything on X.
2547 * You can use gdk_x11_display_error_trap_push() to ignore errors
2548 * on only a single display.
2551 * <title>Trapping an X error</title>
2553 * gdk_error_trap_push (<!-- -->);
2555 * // ... Call the X function which may cause an error here ...
2558 * if (gdk_error_trap_pop (<!-- -->))
2560 * // ... Handle the error here ...
2566 gdk_error_trap_push (void)
2568 GdkDisplayManager *manager;
2569 GdkDisplayClass *class;
2570 GdkGlobalErrorTrap *trap;
2573 manager = gdk_display_manager_get ();
2574 class = GDK_DISPLAY_GET_CLASS (gdk_display_manager_get_default_display (manager));
2576 if (class->push_error_trap == NULL)
2579 trap = g_slice_new (GdkGlobalErrorTrap);
2580 trap->displays = gdk_display_manager_list_displays (manager);
2582 g_slist_foreach (trap->displays, (GFunc) g_object_ref, NULL);
2583 for (l = trap->displays; l != NULL; l = l->next)
2585 class->push_error_trap (l->data);
2588 g_queue_push_head (&gdk_error_traps, trap);
2592 gdk_error_trap_pop_internal (gboolean need_code)
2594 GdkDisplayManager *manager;
2595 GdkDisplayClass *class;
2596 GdkGlobalErrorTrap *trap;
2600 manager = gdk_display_manager_get ();
2601 class = GDK_DISPLAY_GET_CLASS (gdk_display_manager_get_default_display (manager));
2603 if (class->pop_error_trap == NULL)
2606 trap = g_queue_pop_head (&gdk_error_traps);
2608 g_return_val_if_fail (trap != NULL, 0);
2611 for (l = trap->displays; l != NULL; l = l->next)
2615 code = class->pop_error_trap (l->data, !need_code);
2617 /* we use the error on the last display listed, why not. */
2622 g_slist_free_full (trap->displays, g_object_unref);
2623 g_slice_free (GdkGlobalErrorTrap, trap);
2629 * gdk_error_trap_pop_ignored:
2631 * Removes an error trap pushed with gdk_error_trap_push(), but
2632 * without bothering to wait and see whether an error occurred. If an
2633 * error arrives later asynchronously that was triggered while the
2634 * trap was pushed, that error will be ignored.
2639 gdk_error_trap_pop_ignored (void)
2641 gdk_error_trap_pop_internal (FALSE);
2645 * gdk_error_trap_pop:
2647 * Removes an error trap pushed with gdk_error_trap_push().
2648 * May block until an error has been definitively received
2649 * or not received from the X server. gdk_error_trap_pop_ignored()
2650 * is preferred if you don't need to know whether an error
2651 * occurred, because it never has to block. If you don't
2652 * need the return value of gdk_error_trap_pop(), use
2653 * gdk_error_trap_pop_ignored().
2655 * Prior to GDK 3.0, this function would not automatically
2656 * sync for you, so you had to gdk_flush() if your last
2657 * call to Xlib was not a blocking round trip.
2659 * Return value: X error code or 0 on success
2662 gdk_error_trap_pop (void)
2664 return gdk_error_trap_pop_internal (TRUE);