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"
37 static void gdk_display_class_init (GdkDisplayClass *class);
38 static void gdk_display_init (GdkDisplay *display);
39 static void gdk_display_dispose (GObject *object);
40 static void gdk_display_finalize (GObject *object);
43 static void singlehead_get_pointer (GdkDisplay *display,
47 GdkModifierType *mask);
48 static GdkWindow* singlehead_window_get_pointer (GdkDisplay *display,
52 GdkModifierType *mask);
53 static GdkWindow* singlehead_window_at_pointer (GdkDisplay *display,
57 static GdkWindow* singlehead_default_window_get_pointer (GdkWindow *window,
60 GdkModifierType *mask);
61 static GdkWindow* singlehead_default_window_at_pointer (GdkScreen *screen,
65 static guint signals[LAST_SIGNAL] = { 0 };
67 static GObjectClass *parent_class;
68 static char *gdk_sm_client_id;
70 static const GdkDisplayPointerHooks default_pointer_hooks = {
71 _gdk_windowing_get_pointer,
72 _gdk_windowing_window_get_pointer,
73 _gdk_windowing_window_at_pointer
76 static const GdkDisplayPointerHooks singlehead_pointer_hooks = {
77 singlehead_get_pointer,
78 singlehead_window_get_pointer,
79 singlehead_window_at_pointer
82 static const GdkPointerHooks singlehead_default_pointer_hooks = {
83 singlehead_default_window_get_pointer,
84 singlehead_default_window_at_pointer
87 static const GdkPointerHooks *singlehead_current_pointer_hooks = &singlehead_default_pointer_hooks;
90 gdk_display_get_type (void)
93 static GType object_type = 0;
97 static const GTypeInfo object_info = {
98 sizeof (GdkDisplayClass),
100 (GBaseFinalizeFunc) NULL,
101 (GClassInitFunc) gdk_display_class_init,
102 NULL, /* class_finalize */
103 NULL, /* class_data */
106 (GInstanceInitFunc) gdk_display_init
108 object_type = g_type_register_static (G_TYPE_OBJECT,
109 "GdkDisplay", &object_info, 0);
116 gdk_display_class_init (GdkDisplayClass *class)
118 GObjectClass *object_class = G_OBJECT_CLASS (class);
120 parent_class = g_type_class_peek_parent (class);
122 object_class->finalize = gdk_display_finalize;
123 object_class->dispose = gdk_display_dispose;
126 * GdkDisplay::closed:
127 * @display: the object on which the signal is emitted
128 * @is_error: %TRUE if the display was closed due to an error
130 * The ::closed signal is emitted when the connection to the windowing
131 * system for @display is closed.
136 g_signal_new ("closed",
137 G_OBJECT_CLASS_TYPE (object_class),
139 G_STRUCT_OFFSET (GdkDisplayClass, closed),
141 gdk_marshal_VOID__BOOLEAN,
148 gdk_display_init (GdkDisplay *display)
150 _gdk_displays = g_slist_prepend (_gdk_displays, display);
152 display->button_click_time[0] = display->button_click_time[1] = 0;
153 display->button_window[0] = display->button_window[1] = NULL;
154 display->button_number[0] = display->button_number[1] = -1;
155 display->button_x[0] = display->button_x[1] = 0;
156 display->button_y[0] = display->button_y[1] = 0;
158 display->double_click_time = 250;
159 display->double_click_distance = 5;
161 display->pointer_hooks = &default_pointer_hooks;
165 gdk_display_dispose (GObject *object)
167 GdkDisplay *display = GDK_DISPLAY_OBJECT (object);
169 g_list_foreach (display->queued_events, (GFunc)gdk_event_free, NULL);
170 g_list_free (display->queued_events);
171 display->queued_events = NULL;
172 display->queued_tail = NULL;
174 _gdk_displays = g_slist_remove (_gdk_displays, object);
176 if (gdk_display_get_default() == display)
177 gdk_display_manager_set_default_display (gdk_display_manager_get(), NULL);
179 G_OBJECT_CLASS (parent_class)->dispose (object);
183 gdk_display_finalize (GObject *object)
185 G_OBJECT_CLASS (parent_class)->finalize (object);
190 * @display: a #GdkDisplay
192 * Closes the connection to the windowing system for the given display,
193 * and cleans up associated resources.
198 gdk_display_close (GdkDisplay *display)
200 g_return_if_fail (GDK_IS_DISPLAY (display));
202 if (!display->closed)
204 display->closed = TRUE;
206 g_signal_emit (display, signals[CLOSED], 0, FALSE);
207 g_object_run_dispose (G_OBJECT (display));
209 g_object_unref (display);
214 * gdk_display_get_event:
215 * @display: a #GdkDisplay
217 * Gets the next #GdkEvent to be processed for @display, fetching events from the
218 * windowing system if necessary.
220 * Return value: the next #GdkEvent to be processed, or %NULL if no events
221 * are pending. The returned #GdkEvent should be freed with gdk_event_free().
226 gdk_display_get_event (GdkDisplay *display)
228 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
230 _gdk_events_queue (display);
231 return _gdk_event_unqueue (display);
235 * gdk_display_peek_event:
236 * @display: a #GdkDisplay
238 * Gets a copy of the first #GdkEvent in the @display's event queue, without
239 * removing the event from the queue. (Note that this function will
240 * not get more events from the windowing system. It only checks the events
241 * that have already been moved to the GDK event queue.)
243 * Return value: a copy of the first #GdkEvent on the event queue, or %NULL
244 * if no events are in the queue. The returned #GdkEvent should be freed with
250 gdk_display_peek_event (GdkDisplay *display)
254 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
256 tmp_list = _gdk_event_queue_find_first (display);
259 return gdk_event_copy (tmp_list->data);
265 * gdk_display_put_event:
266 * @display: a #GdkDisplay
267 * @event: a #GdkEvent.
269 * Appends a copy of the given event onto the front of the event
270 * queue for @display.
275 gdk_display_put_event (GdkDisplay *display,
278 g_return_if_fail (GDK_IS_DISPLAY (display));
279 g_return_if_fail (event != NULL);
281 _gdk_event_queue_append (display, gdk_event_copy (event));
285 * gdk_pointer_ungrab:
286 * @time_: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no
287 * timestamp is available.
289 * Ungrabs the pointer, if it is grabbed by this application.
292 gdk_pointer_ungrab (guint32 time)
294 gdk_display_pointer_ungrab (gdk_display_get_default (), time);
298 * gdk_pointer_is_grabbed:
300 * Returns %TRUE if the pointer is currently grabbed by this application.
302 * Note that this does not take the inmplicit pointer grab on button
303 * presses into account.
305 * Return value: %TRUE if the pointer is currently grabbed by this application.*
308 gdk_pointer_is_grabbed (void)
310 return gdk_display_pointer_is_grabbed (gdk_display_get_default ());
314 * gdk_keyboard_ungrab:
315 * @time_: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no
316 * timestamp is available.
318 * Ungrabs the keyboard, if it is grabbed by this application.
321 gdk_keyboard_ungrab (guint32 time)
323 gdk_display_keyboard_ungrab (gdk_display_get_default (), time);
329 * Emits a short beep.
334 gdk_display_beep (gdk_display_get_default ());
338 * gdk_event_send_client_message:
339 * @event: the #GdkEvent to send, which should be a #GdkEventClient.
340 * @winid: the window to send the X ClientMessage event to.
342 * Sends an X ClientMessage event to a given window (which must be
343 * on the default #GdkDisplay.)
344 * This could be used for communicating between different applications,
345 * though the amount of data is limited to 20 bytes.
347 * Return value: non-zero on success.
350 gdk_event_send_client_message (GdkEvent *event,
351 GdkNativeWindow winid)
353 g_return_val_if_fail (event != NULL, FALSE);
355 return gdk_event_send_client_message_for_display (gdk_display_get_default (),
360 * gdk_event_send_clientmessage_toall:
361 * @event: the #GdkEvent to send, which should be a #GdkEventClient.
363 * Sends an X ClientMessage event to all toplevel windows on the default
366 * Toplevel windows are determined by checking for the WM_STATE property, as
367 * described in the Inter-Client Communication Conventions Manual (ICCCM).
368 * If no windows are found with the WM_STATE property set, the message is sent
369 * to all children of the root window.
372 gdk_event_send_clientmessage_toall (GdkEvent *event)
374 g_return_if_fail (event != NULL);
376 gdk_screen_broadcast_client_message (gdk_screen_get_default (), event);
380 * gdk_device_get_core_pointer:
382 * Returns the core pointer device for the default display.
384 * Return value: the core pointer device; this is owned by the
385 * display and should not be freed.
388 gdk_device_get_core_pointer (void)
390 return gdk_display_get_core_pointer (gdk_display_get_default ());
394 * gdk_display_get_core_pointer:
395 * @display: a #GdkDisplay
397 * Returns the core pointer device for the given display
399 * Return value: the core pointer device; this is owned by the
400 * display and should not be freed.
405 gdk_display_get_core_pointer (GdkDisplay *display)
407 return display->core_pointer;
411 * gdk_set_sm_client_id:
412 * @sm_client_id: the client id assigned by the session manager when the
413 * connection was opened, or %NULL to remove the property.
415 * Sets the <literal>SM_CLIENT_ID</literal> property on the application's leader window so that
416 * the window manager can save the application's state using the X11R6 ICCCM
417 * session management protocol.
419 * See the X Session Management Library documentation for more information on
420 * session management and the Inter-Client Communication Conventions Manual
421 * (ICCCM) for information on the <literal>WM_CLIENT_LEADER</literal> property.
422 * (Both documents are part of the X Window System distribution.)
425 gdk_set_sm_client_id (const gchar* sm_client_id)
427 GSList *displays, *tmp_list;
429 g_free (gdk_sm_client_id);
430 gdk_sm_client_id = g_strdup (sm_client_id);
432 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
433 for (tmp_list = displays; tmp_list; tmp_list = tmp_list->next)
434 _gdk_windowing_display_set_sm_client_id (tmp_list->data, sm_client_id);
436 g_slist_free (displays);
440 * _gdk_get_sm_client_id:
442 * Gets the client ID set with gdk_set_sm_client_id(), if any.
444 * Return value: Session ID, or %NULL if gdk_set_sm_client_id()
445 * has never been called.
448 _gdk_get_sm_client_id (void)
450 return gdk_sm_client_id;
454 * gdk_display_get_pointer:
455 * @display: a #GdkDisplay
456 * @screen: location to store the screen that the
457 * cursor is on, or %NULL.
458 * @x: location to store root window X coordinate of pointer, or %NULL.
459 * @y: location to store root window Y coordinate of pointer, or %NULL.
460 * @mask: location to store current modifier mask, or %NULL
462 * Gets the current location of the pointer and the current modifier
463 * mask for a given display.
468 gdk_display_get_pointer (GdkDisplay *display,
472 GdkModifierType *mask)
474 GdkScreen *tmp_screen;
476 GdkModifierType tmp_mask;
478 g_return_if_fail (GDK_IS_DISPLAY (display));
480 display->pointer_hooks->get_pointer (display, &tmp_screen, &tmp_x, &tmp_y, &tmp_mask);
483 *screen = tmp_screen;
493 * gdk_display_get_window_at_pointer:
494 * @display: a #GdkDisplay
495 * @win_x: return location for origin of the window under the pointer
496 * @win_y: return location for origin of the window under the pointer
498 * Obtains the window underneath the mouse pointer, returning the location
499 * of that window in @win_x, @win_y for @screen. Returns %NULL if the window
500 * under the mouse pointer is not known to GDK (for example, belongs to
501 * another application).
503 * Returns: the window under the mouse pointer, or %NULL
508 gdk_display_get_window_at_pointer (GdkDisplay *display,
515 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
517 window = display->pointer_hooks->window_at_pointer (display, &tmp_x, &tmp_y);
528 * gdk_display_set_pointer_hooks:
529 * @display: a #GdkDisplay
530 * @new_hooks: a table of pointers to functions for getting
531 * quantities related to the current pointer position,
532 * or %NULL to restore the default table.
534 * This function allows for hooking into the operation
535 * of getting the current location of the pointer on a particular
536 * display. This is only useful for such low-level tools as an
537 * event recorder. Applications should never have any
538 * reason to use this facility.
540 * Return value: the previous pointer hook table
544 GdkDisplayPointerHooks *
545 gdk_display_set_pointer_hooks (GdkDisplay *display,
546 const GdkDisplayPointerHooks *new_hooks)
548 const GdkDisplayPointerHooks *result;
550 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
551 result = display->pointer_hooks;
554 display->pointer_hooks = new_hooks;
556 display->pointer_hooks = &default_pointer_hooks;
558 return (GdkDisplayPointerHooks *)result;
562 singlehead_get_pointer (GdkDisplay *display,
566 GdkModifierType *mask)
568 GdkScreen *default_screen = gdk_display_get_default_screen (display);
569 GdkWindow *root_window = gdk_screen_get_root_window (default_screen);
571 *screen = default_screen;
573 singlehead_current_pointer_hooks->get_pointer (root_window, x, y, mask);
577 singlehead_window_get_pointer (GdkDisplay *display,
581 GdkModifierType *mask)
583 return singlehead_current_pointer_hooks->get_pointer (window, x, y, mask);
587 singlehead_window_at_pointer (GdkDisplay *display,
591 GdkScreen *default_screen = gdk_display_get_default_screen (display);
593 return singlehead_current_pointer_hooks->window_at_pointer (default_screen,
598 singlehead_default_window_get_pointer (GdkWindow *window,
601 GdkModifierType *mask)
603 return _gdk_windowing_window_get_pointer (gdk_drawable_get_display (window),
608 singlehead_default_window_at_pointer (GdkScreen *screen,
612 return _gdk_windowing_window_at_pointer (gdk_screen_get_display (screen),
617 * gdk_set_pointer_hooks:
618 * @new_hooks: a table of pointers to functions for getting
619 * quantities related to the current pointer position,
620 * or %NULL to restore the default table.
622 * This function allows for hooking into the operation
623 * of getting the current location of the pointer. This
624 * is only useful for such low-level tools as an
625 * event recorder. Applications should never have any
626 * reason to use this facility.
628 * This function is not multihead safe. For multihead operation,
629 * see gdk_display_set_pointer_hooks().
631 * Return value: the previous pointer hook table
634 gdk_set_pointer_hooks (const GdkPointerHooks *new_hooks)
636 const GdkPointerHooks *result = singlehead_current_pointer_hooks;
639 singlehead_current_pointer_hooks = new_hooks;
641 singlehead_current_pointer_hooks = &singlehead_default_pointer_hooks;
643 gdk_display_set_pointer_hooks (gdk_display_get_default (),
644 &singlehead_pointer_hooks);
646 return (GdkPointerHooks *)result;