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 "gdkscreen.h"
30 static void gdk_display_class_init (GdkDisplayClass *class);
31 static void gdk_display_init (GdkDisplay *display);
32 static void gdk_display_finalize (GObject *object);
34 static GdkDisplay *default_display = NULL;
36 static GObjectClass *parent_class;
39 gdk_display_get_type (void)
42 static GType object_type = 0;
46 static const GTypeInfo object_info = {
47 sizeof (GdkDisplayClass),
49 (GBaseFinalizeFunc) NULL,
50 (GClassInitFunc) gdk_display_class_init,
51 NULL, /* class_finalize */
52 NULL, /* class_data */
55 (GInstanceInitFunc) gdk_display_init
57 object_type = g_type_register_static (G_TYPE_OBJECT,
58 "GdkDisplay", &object_info, 0);
65 gdk_display_class_init (GdkDisplayClass *class)
67 GObjectClass *object_class = G_OBJECT_CLASS (class);
69 parent_class = g_type_class_peek_parent (class);
71 object_class->finalize = gdk_display_finalize;
75 gdk_display_init (GdkDisplay *display)
77 _gdk_displays = g_slist_prepend (_gdk_displays, display);
79 display->button_click_time[0] = display->button_click_time[1] = 0;
80 display->button_window[0] = display->button_window[1] = NULL;
81 display->button_number[0] = display->button_number[1] = -1;
83 display->double_click_time = 250;
87 gdk_display_finalize (GObject *object)
89 GdkDisplay *display = GDK_DISPLAY_OBJECT (object);
91 _gdk_displays = g_slist_remove (_gdk_displays, display);
93 if (default_display == display)
94 default_display = NULL;
96 parent_class->finalize (object);
101 * @display: a #GdkDisplay
103 * Closes and cleanup the resources used by the @display
106 gdk_display_close (GdkDisplay *display)
108 g_return_if_fail (GDK_IS_DISPLAY (display));
109 g_object_unref (G_OBJECT (display));
113 * gdk_set_default_display:
114 * @display: a #GdkDisplay
116 * Sets @display as the default display.
119 gdk_set_default_display (GdkDisplay *display)
121 default_display = display;
123 _gdk_windowing_set_default_display (display);
127 * gdk_get_default_display:
129 * Gets the default #GdkDisplay.
131 * Returns: a #GdkDisplay, or %NULL if there is no default
135 gdk_get_default_display (void)
137 return default_display;
141 * gdk_get_default_screen:
143 * Gets the default screen for the default display. (See
144 * gdk_get_default_display ()).
146 * Returns: a #GdkScreen.
149 gdk_get_default_screen (void)
151 return gdk_display_get_default_screen (gdk_get_default_display ());
157 * List all currently open displays.
159 * Return value: a newly allocated #GSList of #GdkDisplay objects.
160 * Free this list with g_slist_free() when you are done with it.
163 gdk_list_displays (void)
165 return g_slist_copy (_gdk_displays);
169 * gdk_display_get_event:
170 * @display: a #GdkDisplay
172 * Gets the next #GdkEvent to be processed for @display, fetching events from the
173 * windowing system if necessary.
175 * Return value: the next #GdkEvent to be processed, or %NULL if no events
176 * are pending. The returned #GdkEvent should be freed with gdk_event_free().
179 gdk_display_get_event (GdkDisplay *display)
181 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
183 _gdk_events_queue (display);
184 return _gdk_event_unqueue (display);
188 * gdk_display_peek_event:
189 * @display: a #GdkDisplay
191 * Gets a copy of the first #GdkEvent in the @display's event queue, without
192 * removing the event from the queue. (Note that this function will
193 * not get more events from the windowing system. It only checks the events
194 * that have already been moved to the GDK event queue.)
196 * Return value: a copy of the first #GdkEvent on the event queue, or %NULL if no
197 * events are in the queue. The returned #GdkEvent should be freed with
201 gdk_display_peek_event (GdkDisplay *display)
205 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
207 tmp_list = _gdk_event_queue_find_first (display);
210 return gdk_event_copy (tmp_list->data);
216 * gdk_display_put_event:
217 * @display: a #GdkDisplay
218 * @event: a #GdkEvent.
220 * Appends a copy of the given event onto the front of the event
221 * queue for @display.
224 gdk_display_put_event (GdkDisplay *display,
227 g_return_if_fail (GDK_IS_DISPLAY (display));
228 g_return_if_fail (event != NULL);
230 _gdk_event_queue_append (display, gdk_event_copy (event));
234 * gdk_pointer_ungrab:
235 * @time: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no timestamp is
237 * Ungrabs the pointer, if it is grabbed by this application.
240 gdk_pointer_ungrab (guint32 time)
242 gdk_display_pointer_ungrab (gdk_get_default_display (), time);
246 * gdk_pointer_is_grabbed:
248 * Returns %TRUE if the pointer is currently grabbed by this application.
250 * Note that this does not take the inmplicit pointer grab on button
251 * presses into account.
253 * Return value: %TRUE if the pointer is currently grabbed by this application.*
256 gdk_pointer_is_grabbed (void)
258 return gdk_display_pointer_is_grabbed (gdk_get_default_display ());
262 * gdk_keyboard_ungrab:
263 * @time: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no
264 * timestamp is available.
266 * Ungrabs the keyboard, if it is grabbed by this application.
269 gdk_keyboard_ungrab (guint32 time)
271 gdk_display_keyboard_ungrab (gdk_get_default_display (), time);
277 * Emits a short beep.
282 gdk_display_beep (gdk_get_default_display ());
286 * gdk_event_send_client_message:
287 * @event: the #GdkEvent to send, which should be a #GdkEventClient.
288 * @xid: the window to send the X ClientMessage event to.
290 * Sends an X ClientMessage event to a given window (which must be
291 * on the default #GdkDisplay.)
292 * This could be used for communicating between different applications,
293 * though the amount of data is limited to 20 bytes.
295 * Return value: non-zero on success.
298 gdk_event_send_client_message (GdkEvent *event, guint32 xid)
300 g_return_val_if_fail (event != NULL, FALSE);
302 return gdk_event_send_client_message_for_display (gdk_get_default_display (),
307 * gdk_event_send_clientmessage_toall:
308 * @event: the #GdkEvent to send, which should be a #GdkEventClient.
310 * Sends an X ClientMessage event to all toplevel windows on the default
313 * Toplevel windows are determined by checking for the WM_STATE property, as
314 * described in the Inter-Client Communication Conventions Manual (ICCCM).
315 * If no windows are found with the WM_STATE property set, the message is sent
316 * to all children of the root window.
319 gdk_event_send_clientmessage_toall (GdkEvent *event)
321 g_return_if_fail (event != NULL);
323 gdk_screen_broadcast_client_message (gdk_get_default_screen (), event);
327 * gdk_device_get_core_pointer:
329 * Returns the core pointer device for the default display.
331 * Return value: the core pointer device; this is owned by the
332 * display and should not be freed.
335 gdk_device_get_core_pointer (void)
337 return gdk_display_get_core_pointer (gdk_get_default_display ());
341 * gdk_display_get_core_pointer:
342 * @display: a #GdkDisplay
344 * Returns the core pointer device for the given display
346 * Return value: the core pointer device; this is owned by the
347 * display and should not be freed.
350 gdk_display_get_core_pointer (GdkDisplay *display)
352 return display->core_pointer;