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);
41 static guint signals[LAST_SIGNAL] = { 0 };
43 static GObjectClass *parent_class;
44 static char *gdk_sm_client_id;
47 gdk_display_get_type (void)
50 static GType object_type = 0;
54 static const GTypeInfo object_info = {
55 sizeof (GdkDisplayClass),
57 (GBaseFinalizeFunc) NULL,
58 (GClassInitFunc) gdk_display_class_init,
59 NULL, /* class_finalize */
60 NULL, /* class_data */
63 (GInstanceInitFunc) gdk_display_init
65 object_type = g_type_register_static (G_TYPE_OBJECT,
66 "GdkDisplay", &object_info, 0);
73 gdk_display_class_init (GdkDisplayClass *class)
75 GObjectClass *object_class = G_OBJECT_CLASS (class);
77 parent_class = g_type_class_peek_parent (class);
79 object_class->finalize = gdk_display_finalize;
80 object_class->dispose = gdk_display_dispose;
83 g_signal_new ("closed",
84 G_OBJECT_CLASS_TYPE (object_class),
86 G_STRUCT_OFFSET (GdkDisplayClass, closed),
88 gdk_marshal_VOID__BOOLEAN,
95 gdk_display_init (GdkDisplay *display)
97 _gdk_displays = g_slist_prepend (_gdk_displays, display);
99 display->button_click_time[0] = display->button_click_time[1] = 0;
100 display->button_window[0] = display->button_window[1] = NULL;
101 display->button_number[0] = display->button_number[1] = -1;
103 display->double_click_time = 250;
107 gdk_display_dispose (GObject *object)
109 GdkDisplay *display = GDK_DISPLAY_OBJECT (object);
111 g_list_foreach (display->queued_events, (GFunc)gdk_event_free, NULL);
112 g_list_free (display->queued_events);
113 display->queued_events = NULL;
114 display->queued_tail = NULL;
116 _gdk_displays = g_slist_remove (_gdk_displays, object);
118 if (gdk_display_get_default() == display)
119 gdk_display_manager_set_default_display (gdk_display_manager_get(), NULL);
123 gdk_display_finalize (GObject *object)
125 parent_class->finalize (object);
130 * @display: a #GdkDisplay
132 * Closes the connection windowing system for the given display,
133 * and cleans up associated resources.
136 gdk_display_close (GdkDisplay *display)
138 g_return_if_fail (GDK_IS_DISPLAY (display));
140 if (!display->closed)
142 display->closed = TRUE;
144 g_signal_emit (display, signals[CLOSED], 0, FALSE);
145 g_object_run_dispose (G_OBJECT (display));
147 g_object_unref (display);
152 * gdk_display_get_event:
153 * @display: a #GdkDisplay
155 * Gets the next #GdkEvent to be processed for @display, fetching events from the
156 * windowing system if necessary.
158 * Return value: the next #GdkEvent to be processed, or %NULL if no events
159 * are pending. The returned #GdkEvent should be freed with gdk_event_free().
162 gdk_display_get_event (GdkDisplay *display)
164 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
166 _gdk_events_queue (display);
167 return _gdk_event_unqueue (display);
171 * gdk_display_peek_event:
172 * @display: a #GdkDisplay
174 * Gets a copy of the first #GdkEvent in the @display's event queue, without
175 * removing the event from the queue. (Note that this function will
176 * not get more events from the windowing system. It only checks the events
177 * that have already been moved to the GDK event queue.)
179 * Return value: a copy of the first #GdkEvent on the event queue, or %NULL if no
180 * events are in the queue. The returned #GdkEvent should be freed with
184 gdk_display_peek_event (GdkDisplay *display)
188 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
190 tmp_list = _gdk_event_queue_find_first (display);
193 return gdk_event_copy (tmp_list->data);
199 * gdk_display_put_event:
200 * @display: a #GdkDisplay
201 * @event: a #GdkEvent.
203 * Appends a copy of the given event onto the front of the event
204 * queue for @display.
207 gdk_display_put_event (GdkDisplay *display,
210 g_return_if_fail (GDK_IS_DISPLAY (display));
211 g_return_if_fail (event != NULL);
213 _gdk_event_queue_append (display, gdk_event_copy (event));
217 * gdk_pointer_ungrab:
218 * @time: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no timestamp is
221 * Ungrabs the pointer, if it is grabbed by this application.
224 gdk_pointer_ungrab (guint32 time)
226 gdk_display_pointer_ungrab (gdk_display_get_default (), time);
230 * gdk_pointer_is_grabbed:
232 * Returns %TRUE if the pointer is currently grabbed by this application.
234 * Note that this does not take the inmplicit pointer grab on button
235 * presses into account.
237 * Return value: %TRUE if the pointer is currently grabbed by this application.*
240 gdk_pointer_is_grabbed (void)
242 return gdk_display_pointer_is_grabbed (gdk_display_get_default ());
246 * gdk_keyboard_ungrab:
247 * @time: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no
248 * timestamp is available.
250 * Ungrabs the keyboard, if it is grabbed by this application.
253 gdk_keyboard_ungrab (guint32 time)
255 gdk_display_keyboard_ungrab (gdk_display_get_default (), time);
261 * Emits a short beep.
266 gdk_display_beep (gdk_display_get_default ());
270 * gdk_event_send_client_message:
271 * @event: the #GdkEvent to send, which should be a #GdkEventClient.
272 * @winid: the window to send the X ClientMessage event to.
274 * Sends an X ClientMessage event to a given window (which must be
275 * on the default #GdkDisplay.)
276 * This could be used for communicating between different applications,
277 * though the amount of data is limited to 20 bytes.
279 * Return value: non-zero on success.
282 gdk_event_send_client_message (GdkEvent *event,
283 GdkNativeWindow winid)
285 g_return_val_if_fail (event != NULL, FALSE);
287 return gdk_event_send_client_message_for_display (gdk_display_get_default (),
292 * gdk_event_send_clientmessage_toall:
293 * @event: the #GdkEvent to send, which should be a #GdkEventClient.
295 * Sends an X ClientMessage event to all toplevel windows on the default
298 * Toplevel windows are determined by checking for the WM_STATE property, as
299 * described in the Inter-Client Communication Conventions Manual (ICCCM).
300 * If no windows are found with the WM_STATE property set, the message is sent
301 * to all children of the root window.
304 gdk_event_send_clientmessage_toall (GdkEvent *event)
306 g_return_if_fail (event != NULL);
308 gdk_screen_broadcast_client_message (gdk_screen_get_default (), event);
312 * gdk_device_get_core_pointer:
314 * Returns the core pointer device for the default display.
316 * Return value: the core pointer device; this is owned by the
317 * display and should not be freed.
320 gdk_device_get_core_pointer (void)
322 return gdk_display_get_core_pointer (gdk_display_get_default ());
326 * gdk_display_get_core_pointer:
327 * @display: a #GdkDisplay
329 * Returns the core pointer device for the given display
331 * Return value: the core pointer device; this is owned by the
332 * display and should not be freed.
335 gdk_display_get_core_pointer (GdkDisplay *display)
337 return display->core_pointer;
341 * gdk_set_sm_client_id:
342 * @sm_client_id: the client id assigned by the session manager when the
343 * connection was opened, or %NULL to remove the property.
345 * Sets the <literal>SM_CLIENT_ID</literal> property on the application's leader window so that
346 * the window manager can save the application's state using the X11R6 ICCCM
347 * session management protocol.
349 * See the X Session Management Library documentation for more information on
350 * session management and the Inter-Client Communication Conventions Manual
351 * (ICCCM) for information on the <literal>WM_CLIENT_LEADER</literal> property.
352 * (Both documents are part of the X Window System distribution.)
355 gdk_set_sm_client_id (const gchar* sm_client_id)
357 GSList *displays, *tmp_list;
359 g_free (gdk_sm_client_id);
360 gdk_sm_client_id = g_strdup (sm_client_id);
362 displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
363 for (tmp_list = displays; tmp_list; tmp_list = tmp_list->next)
364 _gdk_windowing_display_set_sm_client_id (tmp_list->data, sm_client_id);
366 g_slist_free (displays);
370 * _gdk_get_sm_client_id:
372 * Gets the client ID set with gdk_set_sm_client_id(), if any.
374 * Return value: Session ID, or %NULL if gdk_set_sm_client_id()
375 * has never been called.
378 _gdk_get_sm_client_id (void)
380 return gdk_sm_client_id;