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 "gdk.h" /* gdk_event_send_client_message() */
27 #include "gdkdisplay.h"
28 #include "gdkinternals.h"
29 #include "gdkmarshalers.h"
30 #include "gdkscreen.h"
38 static void gdk_display_class_init (GdkDisplayClass *class);
39 static void gdk_display_init (GdkDisplay *display);
40 static void gdk_display_dispose (GObject *object);
41 static void gdk_display_finalize (GObject *object);
44 static void singlehead_get_pointer (GdkDisplay *display,
48 GdkModifierType *mask);
49 static GdkWindow* singlehead_window_get_pointer (GdkDisplay *display,
53 GdkModifierType *mask);
54 static GdkWindow* singlehead_window_at_pointer (GdkDisplay *display,
58 static GdkWindow* singlehead_default_window_get_pointer (GdkWindow *window,
61 GdkModifierType *mask);
62 static GdkWindow* singlehead_default_window_at_pointer (GdkScreen *screen,
66 static guint signals[LAST_SIGNAL] = { 0 };
68 static GObjectClass *parent_class;
69 static char *gdk_sm_client_id;
71 static const GdkDisplayPointerHooks default_pointer_hooks = {
72 _gdk_windowing_get_pointer,
73 _gdk_windowing_window_get_pointer,
74 _gdk_windowing_window_at_pointer
77 static const GdkDisplayPointerHooks singlehead_pointer_hooks = {
78 singlehead_get_pointer,
79 singlehead_window_get_pointer,
80 singlehead_window_at_pointer
83 static const GdkPointerHooks singlehead_default_pointer_hooks = {
84 singlehead_default_window_get_pointer,
85 singlehead_default_window_at_pointer
88 static const GdkPointerHooks *singlehead_current_pointer_hooks = &singlehead_default_pointer_hooks;
91 gdk_display_get_type (void)
94 static GType object_type = 0;
98 static const GTypeInfo object_info = {
99 sizeof (GdkDisplayClass),
100 (GBaseInitFunc) NULL,
101 (GBaseFinalizeFunc) NULL,
102 (GClassInitFunc) gdk_display_class_init,
103 NULL, /* class_finalize */
104 NULL, /* class_data */
107 (GInstanceInitFunc) gdk_display_init
109 object_type = g_type_register_static (G_TYPE_OBJECT,
110 g_intern_static_string ("GdkDisplay"), &object_info, 0);
117 gdk_display_class_init (GdkDisplayClass *class)
119 GObjectClass *object_class = G_OBJECT_CLASS (class);
121 parent_class = g_type_class_peek_parent (class);
123 object_class->finalize = gdk_display_finalize;
124 object_class->dispose = gdk_display_dispose;
127 * GdkDisplay::closed:
128 * @display: the object on which the signal is emitted
129 * @is_error: %TRUE if the display was closed due to an error
131 * The ::closed signal is emitted when the connection to the windowing
132 * system for @display is closed.
137 g_signal_new (g_intern_static_string ("closed"),
138 G_OBJECT_CLASS_TYPE (object_class),
140 G_STRUCT_OFFSET (GdkDisplayClass, closed),
142 gdk_marshal_VOID__BOOLEAN,
149 gdk_display_init (GdkDisplay *display)
151 _gdk_displays = g_slist_prepend (_gdk_displays, display);
153 display->button_click_time[0] = display->button_click_time[1] = 0;
154 display->button_window[0] = display->button_window[1] = NULL;
155 display->button_number[0] = display->button_number[1] = -1;
156 display->button_x[0] = display->button_x[1] = 0;
157 display->button_y[0] = display->button_y[1] = 0;
159 display->double_click_time = 250;
160 display->double_click_distance = 5;
162 display->pointer_hooks = &default_pointer_hooks;
166 gdk_display_dispose (GObject *object)
168 GdkDisplay *display = GDK_DISPLAY_OBJECT (object);
170 g_list_foreach (display->queued_events, (GFunc)gdk_event_free, NULL);
171 g_list_free (display->queued_events);
172 display->queued_events = NULL;
173 display->queued_tail = NULL;
175 _gdk_displays = g_slist_remove (_gdk_displays, object);
177 if (gdk_display_get_default() == display)
180 gdk_display_manager_set_default_display (gdk_display_manager_get(),
181 _gdk_displays->data);
183 gdk_display_manager_set_default_display (gdk_display_manager_get(),
187 G_OBJECT_CLASS (parent_class)->dispose (object);
191 gdk_display_finalize (GObject *object)
193 G_OBJECT_CLASS (parent_class)->finalize (object);
198 * @display: a #GdkDisplay
200 * Closes the connection to the windowing system for the given display,
201 * and cleans up associated resources.
206 gdk_display_close (GdkDisplay *display)
208 g_return_if_fail (GDK_IS_DISPLAY (display));
210 if (!display->closed)
212 display->closed = TRUE;
214 g_signal_emit (display, signals[CLOSED], 0, FALSE);
215 g_object_run_dispose (G_OBJECT (display));
217 g_object_unref (display);
222 * gdk_display_get_event:
223 * @display: a #GdkDisplay
225 * Gets the next #GdkEvent to be processed for @display, fetching events from the
226 * windowing system if necessary.
228 * Return value: the next #GdkEvent to be processed, or %NULL if no events
229 * are pending. The returned #GdkEvent should be freed with gdk_event_free().
234 gdk_display_get_event (GdkDisplay *display)
236 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
238 _gdk_events_queue (display);
239 return _gdk_event_unqueue (display);
243 * gdk_display_peek_event:
244 * @display: a #GdkDisplay
246 * Gets a copy of the first #GdkEvent in the @display's event queue, without
247 * removing the event from the queue. (Note that this function will
248 * not get more events from the windowing system. It only checks the events
249 * that have already been moved to the GDK event queue.)
251 * Return value: a copy of the first #GdkEvent on the event queue, or %NULL
252 * if no events are in the queue. The returned #GdkEvent should be freed with
258 gdk_display_peek_event (GdkDisplay *display)
262 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
264 tmp_list = _gdk_event_queue_find_first (display);
267 return gdk_event_copy (tmp_list->data);
273 * gdk_display_put_event:
274 * @display: a #GdkDisplay
275 * @event: a #GdkEvent.
277 * Appends a copy of the given event onto the front of the event
278 * queue for @display.
283 gdk_display_put_event (GdkDisplay *display,
286 g_return_if_fail (GDK_IS_DISPLAY (display));
287 g_return_if_fail (event != NULL);
289 _gdk_event_queue_append (display, gdk_event_copy (event));
293 * gdk_pointer_ungrab:
294 * @time_: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no
295 * timestamp is available.
297 * Ungrabs the pointer, if it is grabbed by this application.
300 gdk_pointer_ungrab (guint32 time)
302 gdk_display_pointer_ungrab (gdk_display_get_default (), time);
306 * gdk_pointer_is_grabbed:
308 * Returns %TRUE if the pointer is currently grabbed by this application.
310 * Note that this does not take the inmplicit pointer grab on button
311 * presses into account.
313 * Return value: %TRUE if the pointer is currently grabbed by this application.*
316 gdk_pointer_is_grabbed (void)
318 return gdk_display_pointer_is_grabbed (gdk_display_get_default ());
322 * gdk_keyboard_ungrab:
323 * @time_: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no
324 * timestamp is available.
326 * Ungrabs the keyboard, if it is grabbed by this application.
329 gdk_keyboard_ungrab (guint32 time)
331 gdk_display_keyboard_ungrab (gdk_display_get_default (), time);
337 * Emits a short beep.
342 gdk_display_beep (gdk_display_get_default ());
346 * gdk_event_send_client_message:
347 * @event: the #GdkEvent to send, which should be a #GdkEventClient.
348 * @winid: the window to send the X ClientMessage event to.
350 * Sends an X ClientMessage event to a given window (which must be
351 * on the default #GdkDisplay.)
352 * This could be used for communicating between different applications,
353 * though the amount of data is limited to 20 bytes.
355 * Return value: non-zero on success.
358 gdk_event_send_client_message (GdkEvent *event,
359 GdkNativeWindow winid)
361 g_return_val_if_fail (event != NULL, FALSE);
363 return gdk_event_send_client_message_for_display (gdk_display_get_default (),
368 * gdk_event_send_clientmessage_toall:
369 * @event: the #GdkEvent to send, which should be a #GdkEventClient.
371 * Sends an X ClientMessage event to all toplevel windows on the default
374 * Toplevel windows are determined by checking for the WM_STATE property, as
375 * described in the Inter-Client Communication Conventions Manual (ICCCM).
376 * If no windows are found with the WM_STATE property set, the message is sent
377 * to all children of the root window.
380 gdk_event_send_clientmessage_toall (GdkEvent *event)
382 g_return_if_fail (event != NULL);
384 gdk_screen_broadcast_client_message (gdk_screen_get_default (), event);
388 * gdk_device_get_core_pointer:
390 * Returns the core pointer device for the default display.
392 * Return value: the core pointer device; this is owned by the
393 * display and should not be freed.
396 gdk_device_get_core_pointer (void)
398 return gdk_display_get_core_pointer (gdk_display_get_default ());
402 * gdk_display_get_core_pointer:
403 * @display: a #GdkDisplay
405 * Returns the core pointer device for the given display
407 * Return value: the core pointer device; this is owned by the
408 * display and should not be freed.
413 gdk_display_get_core_pointer (GdkDisplay *display)
415 return display->core_pointer;
419 * gdk_set_sm_client_id:
420 * @sm_client_id: the client id assigned by the session manager when the
421 * connection was opened, or %NULL to remove the property.
423 * Sets the <literal>SM_CLIENT_ID</literal> property on the application's leader window so that
424 * the window manager can save the application's state using the X11R6 ICCCM
425 * session management protocol.
427 * See the X Session Management Library documentation for more information on
428 * session management and the Inter-Client Communication Conventions Manual
429 * (ICCCM) for information on the <literal>WM_CLIENT_LEADER</literal> property.
430 * (Both documents are part of the X Window System distribution.)
433 gdk_set_sm_client_id (const gchar* sm_client_id)
435 GSList *displays, *tmp_list;
437 g_free (gdk_sm_client_id);
438 gdk_sm_client_id = g_strdup (sm_client_id);
440 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
441 for (tmp_list = displays; tmp_list; tmp_list = tmp_list->next)
442 _gdk_windowing_display_set_sm_client_id (tmp_list->data, sm_client_id);
444 g_slist_free (displays);
448 * _gdk_get_sm_client_id:
450 * Gets the client ID set with gdk_set_sm_client_id(), if any.
452 * Return value: Session ID, or %NULL if gdk_set_sm_client_id()
453 * has never been called.
456 _gdk_get_sm_client_id (void)
458 return gdk_sm_client_id;
462 * gdk_display_get_pointer:
463 * @display: a #GdkDisplay
464 * @screen: location to store the screen that the
465 * cursor is on, or %NULL.
466 * @x: location to store root window X coordinate of pointer, or %NULL.
467 * @y: location to store root window Y coordinate of pointer, or %NULL.
468 * @mask: location to store current modifier mask, or %NULL
470 * Gets the current location of the pointer and the current modifier
471 * mask for a given display.
476 gdk_display_get_pointer (GdkDisplay *display,
480 GdkModifierType *mask)
482 GdkScreen *tmp_screen;
484 GdkModifierType tmp_mask;
486 g_return_if_fail (GDK_IS_DISPLAY (display));
488 display->pointer_hooks->get_pointer (display, &tmp_screen, &tmp_x, &tmp_y, &tmp_mask);
491 *screen = tmp_screen;
501 * gdk_display_get_window_at_pointer:
502 * @display: a #GdkDisplay
503 * @win_x: return location for origin of the window under the pointer
504 * @win_y: return location for origin of the window under the pointer
506 * Obtains the window underneath the mouse pointer, returning the location
507 * of that window in @win_x, @win_y for @screen. Returns %NULL if the window
508 * under the mouse pointer is not known to GDK (for example, belongs to
509 * another application).
511 * Returns: the window under the mouse pointer, or %NULL
516 gdk_display_get_window_at_pointer (GdkDisplay *display,
523 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
525 window = display->pointer_hooks->window_at_pointer (display, &tmp_x, &tmp_y);
536 * gdk_display_set_pointer_hooks:
537 * @display: a #GdkDisplay
538 * @new_hooks: a table of pointers to functions for getting
539 * quantities related to the current pointer position,
540 * or %NULL to restore the default table.
542 * This function allows for hooking into the operation
543 * of getting the current location of the pointer on a particular
544 * display. This is only useful for such low-level tools as an
545 * event recorder. Applications should never have any
546 * reason to use this facility.
548 * Return value: the previous pointer hook table
552 GdkDisplayPointerHooks *
553 gdk_display_set_pointer_hooks (GdkDisplay *display,
554 const GdkDisplayPointerHooks *new_hooks)
556 const GdkDisplayPointerHooks *result;
558 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
559 result = display->pointer_hooks;
562 display->pointer_hooks = new_hooks;
564 display->pointer_hooks = &default_pointer_hooks;
566 return (GdkDisplayPointerHooks *)result;
570 singlehead_get_pointer (GdkDisplay *display,
574 GdkModifierType *mask)
576 GdkScreen *default_screen = gdk_display_get_default_screen (display);
577 GdkWindow *root_window = gdk_screen_get_root_window (default_screen);
579 *screen = default_screen;
581 singlehead_current_pointer_hooks->get_pointer (root_window, x, y, mask);
585 singlehead_window_get_pointer (GdkDisplay *display,
589 GdkModifierType *mask)
591 return singlehead_current_pointer_hooks->get_pointer (window, x, y, mask);
595 singlehead_window_at_pointer (GdkDisplay *display,
599 GdkScreen *default_screen = gdk_display_get_default_screen (display);
601 return singlehead_current_pointer_hooks->window_at_pointer (default_screen,
606 singlehead_default_window_get_pointer (GdkWindow *window,
609 GdkModifierType *mask)
611 return _gdk_windowing_window_get_pointer (gdk_drawable_get_display (window),
616 singlehead_default_window_at_pointer (GdkScreen *screen,
620 return _gdk_windowing_window_at_pointer (gdk_screen_get_display (screen),
625 * gdk_set_pointer_hooks:
626 * @new_hooks: a table of pointers to functions for getting
627 * quantities related to the current pointer position,
628 * or %NULL to restore the default table.
630 * This function allows for hooking into the operation
631 * of getting the current location of the pointer. This
632 * is only useful for such low-level tools as an
633 * event recorder. Applications should never have any
634 * reason to use this facility.
636 * This function is not multihead safe. For multihead operation,
637 * see gdk_display_set_pointer_hooks().
639 * Return value: the previous pointer hook table
642 gdk_set_pointer_hooks (const GdkPointerHooks *new_hooks)
644 const GdkPointerHooks *result = singlehead_current_pointer_hooks;
647 singlehead_current_pointer_hooks = new_hooks;
649 singlehead_current_pointer_hooks = &singlehead_default_pointer_hooks;
651 gdk_display_set_pointer_hooks (gdk_display_get_default (),
652 &singlehead_pointer_hooks);
654 return (GdkPointerHooks *)result;
657 #define __GDK_DISPLAY_C__
658 #include "gdkaliasdef.c"