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.
25 #include "gdk.h" /* gdk_event_send_client_message() */
26 #include "gdkdisplay.h"
27 #include "gdkinternals.h"
28 #include "gdkmarshalers.h"
29 #include "gdkscreen.h"
36 static void gdk_display_class_init (GdkDisplayClass *class);
37 static void gdk_display_init (GdkDisplay *display);
38 static void gdk_display_dispose (GObject *object);
39 static void gdk_display_finalize (GObject *object);
42 void singlehead_get_pointer (GdkDisplay *display,
46 GdkModifierType *mask);
47 GdkWindow* singlehead_window_get_pointer (GdkDisplay *display,
51 GdkModifierType *mask);
52 GdkWindow* singlehead_window_at_pointer (GdkDisplay *display,
56 GdkWindow* singlehead_default_window_get_pointer (GdkWindow *window,
59 GdkModifierType *mask);
60 GdkWindow* singlehead_default_window_at_pointer (GdkScreen *screen,
64 static guint signals[LAST_SIGNAL] = { 0 };
66 static GObjectClass *parent_class;
67 static char *gdk_sm_client_id;
69 static const GdkDisplayPointerHooks default_pointer_hooks = {
70 _gdk_windowing_get_pointer,
71 _gdk_windowing_window_get_pointer,
72 _gdk_windowing_window_at_pointer
75 static const GdkDisplayPointerHooks singlehead_pointer_hooks = {
76 singlehead_get_pointer,
77 singlehead_window_get_pointer,
78 singlehead_window_at_pointer
81 static const GdkPointerHooks singlehead_default_pointer_hooks = {
82 singlehead_default_window_get_pointer,
83 singlehead_default_window_at_pointer
86 static const GdkPointerHooks *singlehead_current_pointer_hooks = &singlehead_default_pointer_hooks;
89 gdk_display_get_type (void)
92 static GType object_type = 0;
96 static const GTypeInfo object_info = {
97 sizeof (GdkDisplayClass),
99 (GBaseFinalizeFunc) NULL,
100 (GClassInitFunc) gdk_display_class_init,
101 NULL, /* class_finalize */
102 NULL, /* class_data */
105 (GInstanceInitFunc) gdk_display_init
107 object_type = g_type_register_static (G_TYPE_OBJECT,
108 "GdkDisplay", &object_info, 0);
115 gdk_display_class_init (GdkDisplayClass *class)
117 GObjectClass *object_class = G_OBJECT_CLASS (class);
119 parent_class = g_type_class_peek_parent (class);
121 object_class->finalize = gdk_display_finalize;
122 object_class->dispose = gdk_display_dispose;
125 * GdkDisplay::closed:
126 * @display: the object on which the signal is emitted
127 * @is_error: %TRUE if the display was closed due to an error
129 * The ::closed signal is emitted when the connection to the windowing
130 * system for @display is closed.
135 g_signal_new ("closed",
136 G_OBJECT_CLASS_TYPE (object_class),
138 G_STRUCT_OFFSET (GdkDisplayClass, closed),
140 gdk_marshal_VOID__BOOLEAN,
147 gdk_display_init (GdkDisplay *display)
149 _gdk_displays = g_slist_prepend (_gdk_displays, display);
151 display->button_click_time[0] = display->button_click_time[1] = 0;
152 display->button_window[0] = display->button_window[1] = NULL;
153 display->button_number[0] = display->button_number[1] = -1;
155 display->double_click_time = 250;
157 display->pointer_hooks = &default_pointer_hooks;
161 gdk_display_dispose (GObject *object)
163 GdkDisplay *display = GDK_DISPLAY_OBJECT (object);
165 g_list_foreach (display->queued_events, (GFunc)gdk_event_free, NULL);
166 g_list_free (display->queued_events);
167 display->queued_events = NULL;
168 display->queued_tail = NULL;
170 _gdk_displays = g_slist_remove (_gdk_displays, object);
172 if (gdk_display_get_default() == display)
173 gdk_display_manager_set_default_display (gdk_display_manager_get(), NULL);
177 gdk_display_finalize (GObject *object)
179 parent_class->finalize (object);
184 * @display: a #GdkDisplay
186 * Closes the connection to the windowing system for the given display,
187 * and cleans up associated resources.
192 gdk_display_close (GdkDisplay *display)
194 g_return_if_fail (GDK_IS_DISPLAY (display));
196 if (!display->closed)
198 display->closed = TRUE;
200 g_signal_emit (display, signals[CLOSED], 0, FALSE);
201 g_object_run_dispose (G_OBJECT (display));
203 g_object_unref (display);
208 * gdk_display_get_event:
209 * @display: a #GdkDisplay
211 * Gets the next #GdkEvent to be processed for @display, fetching events from the
212 * windowing system if necessary.
214 * Return value: the next #GdkEvent to be processed, or %NULL if no events
215 * are pending. The returned #GdkEvent should be freed with gdk_event_free().
220 gdk_display_get_event (GdkDisplay *display)
222 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
224 _gdk_events_queue (display);
225 return _gdk_event_unqueue (display);
229 * gdk_display_peek_event:
230 * @display: a #GdkDisplay
232 * Gets a copy of the first #GdkEvent in the @display's event queue, without
233 * removing the event from the queue. (Note that this function will
234 * not get more events from the windowing system. It only checks the events
235 * that have already been moved to the GDK event queue.)
237 * Return value: a copy of the first #GdkEvent on the event queue, or %NULL
238 * if no events are in the queue. The returned #GdkEvent should be freed with
244 gdk_display_peek_event (GdkDisplay *display)
248 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
250 tmp_list = _gdk_event_queue_find_first (display);
253 return gdk_event_copy (tmp_list->data);
259 * gdk_display_put_event:
260 * @display: a #GdkDisplay
261 * @event: a #GdkEvent.
263 * Appends a copy of the given event onto the front of the event
264 * queue for @display.
269 gdk_display_put_event (GdkDisplay *display,
272 g_return_if_fail (GDK_IS_DISPLAY (display));
273 g_return_if_fail (event != NULL);
275 _gdk_event_queue_append (display, gdk_event_copy (event));
279 * gdk_pointer_ungrab:
280 * @time_: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no
281 * timestamp is available.
283 * Ungrabs the pointer, if it is grabbed by this application.
286 gdk_pointer_ungrab (guint32 time)
288 gdk_display_pointer_ungrab (gdk_display_get_default (), time);
292 * gdk_pointer_is_grabbed:
294 * Returns %TRUE if the pointer is currently grabbed by this application.
296 * Note that this does not take the inmplicit pointer grab on button
297 * presses into account.
299 * Return value: %TRUE if the pointer is currently grabbed by this application.*
302 gdk_pointer_is_grabbed (void)
304 return gdk_display_pointer_is_grabbed (gdk_display_get_default ());
308 * gdk_keyboard_ungrab:
309 * @time_: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no
310 * timestamp is available.
312 * Ungrabs the keyboard, if it is grabbed by this application.
315 gdk_keyboard_ungrab (guint32 time)
317 gdk_display_keyboard_ungrab (gdk_display_get_default (), time);
323 * Emits a short beep.
328 gdk_display_beep (gdk_display_get_default ());
332 * gdk_event_send_client_message:
333 * @event: the #GdkEvent to send, which should be a #GdkEventClient.
334 * @winid: the window to send the X ClientMessage event to.
336 * Sends an X ClientMessage event to a given window (which must be
337 * on the default #GdkDisplay.)
338 * This could be used for communicating between different applications,
339 * though the amount of data is limited to 20 bytes.
341 * Return value: non-zero on success.
344 gdk_event_send_client_message (GdkEvent *event,
345 GdkNativeWindow winid)
347 g_return_val_if_fail (event != NULL, FALSE);
349 return gdk_event_send_client_message_for_display (gdk_display_get_default (),
354 * gdk_event_send_clientmessage_toall:
355 * @event: the #GdkEvent to send, which should be a #GdkEventClient.
357 * Sends an X ClientMessage event to all toplevel windows on the default
360 * Toplevel windows are determined by checking for the WM_STATE property, as
361 * described in the Inter-Client Communication Conventions Manual (ICCCM).
362 * If no windows are found with the WM_STATE property set, the message is sent
363 * to all children of the root window.
366 gdk_event_send_clientmessage_toall (GdkEvent *event)
368 g_return_if_fail (event != NULL);
370 gdk_screen_broadcast_client_message (gdk_screen_get_default (), event);
374 * gdk_device_get_core_pointer:
376 * Returns the core pointer device for the default display.
378 * Return value: the core pointer device; this is owned by the
379 * display and should not be freed.
382 gdk_device_get_core_pointer (void)
384 return gdk_display_get_core_pointer (gdk_display_get_default ());
388 * gdk_display_get_core_pointer:
389 * @display: a #GdkDisplay
391 * Returns the core pointer device for the given display
393 * Return value: the core pointer device; this is owned by the
394 * display and should not be freed.
399 gdk_display_get_core_pointer (GdkDisplay *display)
401 return display->core_pointer;
405 * gdk_set_sm_client_id:
406 * @sm_client_id: the client id assigned by the session manager when the
407 * connection was opened, or %NULL to remove the property.
409 * Sets the <literal>SM_CLIENT_ID</literal> property on the application's leader window so that
410 * the window manager can save the application's state using the X11R6 ICCCM
411 * session management protocol.
413 * See the X Session Management Library documentation for more information on
414 * session management and the Inter-Client Communication Conventions Manual
415 * (ICCCM) for information on the <literal>WM_CLIENT_LEADER</literal> property.
416 * (Both documents are part of the X Window System distribution.)
419 gdk_set_sm_client_id (const gchar* sm_client_id)
421 GSList *displays, *tmp_list;
423 g_free (gdk_sm_client_id);
424 gdk_sm_client_id = g_strdup (sm_client_id);
426 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
427 for (tmp_list = displays; tmp_list; tmp_list = tmp_list->next)
428 _gdk_windowing_display_set_sm_client_id (tmp_list->data, sm_client_id);
430 g_slist_free (displays);
434 * _gdk_get_sm_client_id:
436 * Gets the client ID set with gdk_set_sm_client_id(), if any.
438 * Return value: Session ID, or %NULL if gdk_set_sm_client_id()
439 * has never been called.
442 _gdk_get_sm_client_id (void)
444 return gdk_sm_client_id;
448 * gdk_display_get_pointer:
449 * @display: a #GdkDisplay
450 * @screen: location to store the screen that the
451 * cursor is on, or %NULL.
452 * @x: location to store root window X coordinate of pointer, or %NULL.
453 * @y: location to store root window Y coordinate of pointer, or %NULL.
454 * @mask: location to store current modifier mask, or %NULL
456 * Gets the current location of the pointer and the current modifier
457 * mask for a given display.
462 gdk_display_get_pointer (GdkDisplay *display,
466 GdkModifierType *mask)
468 GdkScreen *tmp_screen;
470 GdkModifierType tmp_mask;
472 g_return_if_fail (GDK_IS_DISPLAY (display));
474 display->pointer_hooks->get_pointer (display, &tmp_screen, &tmp_x, &tmp_y, &tmp_mask);
477 *screen = tmp_screen;
487 * gdk_display_get_window_at_pointer:
488 * @display: a #GdkDisplay
489 * @win_x: return location for origin of the window under the pointer
490 * @win_y: return location for origin of the window under the pointer
492 * Obtains the window underneath the mouse pointer, returning the location
493 * of that window in @win_x, @win_y for @screen. Returns %NULL if the window
494 * under the mouse pointer is not known to GDK (for example, belongs to
495 * another application).
497 * Returns: the window under the mouse pointer, or %NULL
502 gdk_display_get_window_at_pointer (GdkDisplay *display,
509 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
511 window = display->pointer_hooks->window_at_pointer (display, &tmp_x, &tmp_y);
522 * gdk_display_set_pointer_hooks:
523 * @display: a #GdkDisplay
524 * @new_hooks: a table of pointers to functions for getting
525 * quantities related to the current pointer position,
526 * or %NULL to restore the default table.
528 * This function allows for hooking into the operation
529 * of getting the current location of the pointer on a particular
530 * display. This is only useful for such low-level tools as an
531 * event recorder. Applications should never have any
532 * reason to use this facility.
534 * Return value: the previous pointer hook table
538 GdkDisplayPointerHooks *
539 gdk_display_set_pointer_hooks (GdkDisplay *display,
540 const GdkDisplayPointerHooks *new_hooks)
542 const GdkDisplayPointerHooks *result;
544 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
545 result = display->pointer_hooks;
548 display->pointer_hooks = new_hooks;
550 display->pointer_hooks = &default_pointer_hooks;
552 return (GdkDisplayPointerHooks *)result;
556 singlehead_get_pointer (GdkDisplay *display,
560 GdkModifierType *mask)
562 GdkScreen *default_screen = gdk_display_get_default_screen (display);
563 GdkWindow *root_window = gdk_screen_get_root_window (default_screen);
565 *screen = default_screen;
567 singlehead_current_pointer_hooks->get_pointer (root_window, x, y, mask);
571 singlehead_window_get_pointer (GdkDisplay *display,
575 GdkModifierType *mask)
577 return singlehead_current_pointer_hooks->get_pointer (window, x, y, mask);
581 singlehead_window_at_pointer (GdkDisplay *display,
585 GdkScreen *default_screen = gdk_display_get_default_screen (display);
587 return singlehead_current_pointer_hooks->window_at_pointer (default_screen,
592 singlehead_default_window_get_pointer (GdkWindow *window,
595 GdkModifierType *mask)
597 return _gdk_windowing_window_get_pointer (gdk_drawable_get_display (window),
602 singlehead_default_window_at_pointer (GdkScreen *screen,
606 return _gdk_windowing_window_at_pointer (gdk_screen_get_display (screen),
611 * gdk_set_pointer_hooks:
612 * @new_hooks: a table of pointers to functions for getting
613 * quantities related to the current pointer position,
614 * or %NULL to restore the default table.
616 * This function allows for hooking into the operation
617 * of getting the current location of the pointer. This
618 * is only useful for such low-level tools as an
619 * event recorder. Applications should never have any
620 * reason to use this facility.
622 * This function is not multihead safe. For multihead operation,
623 * see gdk_display_set_pointer_hooks().
625 * Return value: the previous pointer hook table
628 gdk_set_pointer_hooks (const GdkPointerHooks *new_hooks)
630 const GdkPointerHooks *result = singlehead_current_pointer_hooks;
633 singlehead_current_pointer_hooks = new_hooks;
635 singlehead_current_pointer_hooks = &singlehead_default_pointer_hooks;
637 gdk_display_set_pointer_hooks (gdk_display_get_default (),
638 &singlehead_pointer_hooks);
640 return (GdkPointerHooks *)result;