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;
46 gdk_display_get_type (void)
49 static GType object_type = 0;
53 static const GTypeInfo object_info = {
54 sizeof (GdkDisplayClass),
56 (GBaseFinalizeFunc) NULL,
57 (GClassInitFunc) gdk_display_class_init,
58 NULL, /* class_finalize */
59 NULL, /* class_data */
62 (GInstanceInitFunc) gdk_display_init
64 object_type = g_type_register_static (G_TYPE_OBJECT,
65 "GdkDisplay", &object_info, 0);
72 gdk_display_class_init (GdkDisplayClass *class)
74 GObjectClass *object_class = G_OBJECT_CLASS (class);
76 parent_class = g_type_class_peek_parent (class);
78 object_class->finalize = gdk_display_finalize;
79 object_class->dispose = gdk_display_dispose;
82 g_signal_new ("closed",
83 G_OBJECT_CLASS_TYPE (object_class),
85 G_STRUCT_OFFSET (GdkDisplayClass, closed),
87 gdk_marshal_VOID__BOOLEAN,
94 gdk_display_init (GdkDisplay *display)
96 _gdk_displays = g_slist_prepend (_gdk_displays, display);
98 display->button_click_time[0] = display->button_click_time[1] = 0;
99 display->button_window[0] = display->button_window[1] = NULL;
100 display->button_number[0] = display->button_number[1] = -1;
102 display->double_click_time = 250;
106 gdk_display_dispose (GObject *object)
108 GdkDisplay *display = GDK_DISPLAY_OBJECT (object);
110 g_list_foreach (display->queued_events, (GFunc)gdk_event_free, NULL);
111 g_list_free (display->queued_events);
112 display->queued_events = NULL;
113 display->queued_tail = NULL;
115 _gdk_displays = g_slist_remove (_gdk_displays, object);
117 if (gdk_display_get_default() == display)
118 gdk_display_manager_set_default_display (gdk_display_manager_get(), NULL);
122 gdk_display_finalize (GObject *object)
124 GdkDisplay *display = GDK_DISPLAY_OBJECT (object);
126 parent_class->finalize (object);
131 * @display: a #GdkDisplay
133 * Closes the connection windowing system for the given display,
134 * and cleans up associated resources.
137 gdk_display_close (GdkDisplay *display)
139 g_return_if_fail (GDK_IS_DISPLAY (display));
141 if (!display->closed)
143 display->closed = TRUE;
145 g_signal_emit (display, signals[CLOSED], 0, FALSE);
146 g_object_run_dispose (G_OBJECT (display));
148 g_object_unref (G_OBJECT (display));
153 * gdk_display_get_event:
154 * @display: a #GdkDisplay
156 * Gets the next #GdkEvent to be processed for @display, fetching events from the
157 * windowing system if necessary.
159 * Return value: the next #GdkEvent to be processed, or %NULL if no events
160 * are pending. The returned #GdkEvent should be freed with gdk_event_free().
163 gdk_display_get_event (GdkDisplay *display)
165 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
167 _gdk_events_queue (display);
168 return _gdk_event_unqueue (display);
172 * gdk_display_peek_event:
173 * @display: a #GdkDisplay
175 * Gets a copy of the first #GdkEvent in the @display's event queue, without
176 * removing the event from the queue. (Note that this function will
177 * not get more events from the windowing system. It only checks the events
178 * that have already been moved to the GDK event queue.)
180 * Return value: a copy of the first #GdkEvent on the event queue, or %NULL if no
181 * events are in the queue. The returned #GdkEvent should be freed with
185 gdk_display_peek_event (GdkDisplay *display)
189 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
191 tmp_list = _gdk_event_queue_find_first (display);
194 return gdk_event_copy (tmp_list->data);
200 * gdk_display_put_event:
201 * @display: a #GdkDisplay
202 * @event: a #GdkEvent.
204 * Appends a copy of the given event onto the front of the event
205 * queue for @display.
208 gdk_display_put_event (GdkDisplay *display,
211 g_return_if_fail (GDK_IS_DISPLAY (display));
212 g_return_if_fail (event != NULL);
214 _gdk_event_queue_append (display, gdk_event_copy (event));
218 * gdk_pointer_ungrab:
219 * @time: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no timestamp is
222 * Ungrabs the pointer, if it is grabbed by this application.
225 gdk_pointer_ungrab (guint32 time)
227 gdk_display_pointer_ungrab (gdk_display_get_default (), time);
231 * gdk_pointer_is_grabbed:
233 * Returns %TRUE if the pointer is currently grabbed by this application.
235 * Note that this does not take the inmplicit pointer grab on button
236 * presses into account.
238 * Return value: %TRUE if the pointer is currently grabbed by this application.*
241 gdk_pointer_is_grabbed (void)
243 return gdk_display_pointer_is_grabbed (gdk_display_get_default ());
247 * gdk_keyboard_ungrab:
248 * @time: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no
249 * timestamp is available.
251 * Ungrabs the keyboard, if it is grabbed by this application.
254 gdk_keyboard_ungrab (guint32 time)
256 gdk_display_keyboard_ungrab (gdk_display_get_default (), time);
262 * Emits a short beep.
267 gdk_display_beep (gdk_display_get_default ());
271 * gdk_event_send_client_message:
272 * @event: the #GdkEvent to send, which should be a #GdkEventClient.
273 * @xid: the window to send the X ClientMessage event to.
275 * Sends an X ClientMessage event to a given window (which must be
276 * on the default #GdkDisplay.)
277 * This could be used for communicating between different applications,
278 * though the amount of data is limited to 20 bytes.
280 * Return value: non-zero on success.
283 gdk_event_send_client_message (GdkEvent *event, guint32 xid)
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 gdk_display_set_sm_client_id (gdk_display_get_default (), sm_client_id);