]> Pileus Git - ~andy/gtk/blob - gdk/gdkdisplay.c
9a746d497867401453ec969057d45b76bf8f0471
[~andy/gtk] / gdk / gdkdisplay.c
1 /* GDK - The GIMP Drawing Kit
2  * gdkdisplay.c
3  * 
4  * Copyright 2001 Sun Microsystems Inc. 
5  *
6  * Erwann Chenede <erwann.chenede@sun.com>
7  *
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.
12  *
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.
17  *
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.
22  */
23
24 #include <glib.h>
25 #include "gdk.h"                /* gdk_event_send_client_message() */
26 #include "gdkdisplay.h"
27 #include "gdkinternals.h"
28 #include "gdkscreen.h"
29
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);
33
34 static GdkDisplay *default_display = NULL;
35
36 static GObjectClass *parent_class;
37
38 GType
39 gdk_display_get_type (void)
40 {
41
42   static GType object_type = 0;
43
44   if (!object_type)
45     {
46       static const GTypeInfo object_info = {
47         sizeof (GdkDisplayClass),
48         (GBaseInitFunc) NULL,
49         (GBaseFinalizeFunc) NULL,
50         (GClassInitFunc) gdk_display_class_init,
51         NULL,                   /* class_finalize */
52         NULL,                   /* class_data */
53         sizeof (GdkDisplay),
54         0,                      /* n_preallocs */
55         (GInstanceInitFunc) gdk_display_init
56       };
57       object_type = g_type_register_static (G_TYPE_OBJECT,
58                                             "GdkDisplay", &object_info, 0);
59     }
60
61   return object_type;
62 }
63
64 static void
65 gdk_display_class_init (GdkDisplayClass *class)
66 {
67   GObjectClass *object_class = G_OBJECT_CLASS (class);
68   
69   parent_class = g_type_class_peek_parent (class);
70
71   object_class->finalize = gdk_display_finalize;
72 }
73
74 static void
75 gdk_display_init (GdkDisplay *display)
76 {
77   _gdk_displays = g_slist_prepend (_gdk_displays, display);
78
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;
82
83   display->double_click_time = 250;
84 }
85
86 static void
87 gdk_display_finalize (GObject *object)
88 {
89   GdkDisplay *display = GDK_DISPLAY_OBJECT (object);
90   
91   _gdk_displays = g_slist_remove (_gdk_displays, display);
92
93   if (default_display == display)
94     default_display = NULL;
95   
96   parent_class->finalize (object);
97 }
98
99 /**
100  * gdk_display_close:
101  * @display: a #GdkDisplay
102  *
103  * Closes and cleanup the resources used by the @display
104  */
105 void
106 gdk_display_close (GdkDisplay *display)
107 {
108   g_return_if_fail (GDK_IS_DISPLAY (display));
109   g_object_unref (G_OBJECT (display));
110 }
111
112 /**
113  * gdk_set_default_display:
114  * @display: a #GdkDisplay
115  * 
116  * Sets @display as the default display.
117  **/
118 void
119 gdk_set_default_display (GdkDisplay *display)
120 {
121   default_display = display;
122
123   _gdk_windowing_set_default_display (display);
124 }
125
126 /**
127  * gdk_get_default_display:
128  *
129  * Gets the default #GdkDisplay. 
130  * 
131  * Returns: a #GdkDisplay, or %NULL if there is no default
132  *   display.
133  */
134 GdkDisplay *
135 gdk_get_default_display (void)
136 {
137   return default_display;
138 }
139
140 /**
141  * gdk_get_default_screen:
142  *
143  * Gets the default screen for the default display. (See
144  * gdk_get_default_display ()).
145  * 
146  * Returns: a #GdkScreen.
147  */
148 GdkScreen *
149 gdk_get_default_screen (void)
150 {
151   return gdk_display_get_default_screen (gdk_get_default_display ());
152 }
153
154 /**
155  * gdk_list_displays:
156  *
157  * List all currently open displays.
158  * 
159  * Return value: a newly allocated #GSList of #GdkDisplay objects.
160  *  Free this list with g_slist_free() when you are done with it.
161  **/
162 GSList *
163 gdk_list_displays (void)
164 {
165   return g_slist_copy (_gdk_displays);
166 }
167
168 /**
169  * gdk_display_get_event:
170  * @display: a #GdkDisplay
171  * 
172  * Gets the next #GdkEvent to be processed for @display, fetching events from the
173  * windowing system if necessary.
174  * 
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().
177  **/
178 GdkEvent*
179 gdk_display_get_event (GdkDisplay *display)
180 {
181   g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
182   
183   _gdk_events_queue (display);
184   return _gdk_event_unqueue (display);
185 }
186
187 /**
188  * gdk_display_peek_event:
189  * @display: a #GdkDisplay 
190  * 
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.)
195  * 
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
198  * gdk_event_free().
199  **/
200 GdkEvent*
201 gdk_display_peek_event (GdkDisplay *display)
202 {
203   GList *tmp_list;
204
205   g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
206
207   tmp_list = _gdk_event_queue_find_first (display);
208   
209   if (tmp_list)
210     return gdk_event_copy (tmp_list->data);
211   else
212     return NULL;
213 }
214
215 /**
216  * gdk_display_put_event:
217  * @display: a #GdkDisplay
218  * @event: a #GdkEvent.
219  *
220  * Appends a copy of the given event onto the front of the event
221  * queue for @display.
222  **/
223 void
224 gdk_display_put_event (GdkDisplay *display,
225                        GdkEvent   *event)
226 {
227   g_return_if_fail (GDK_IS_DISPLAY (display));
228   g_return_if_fail (event != NULL);
229
230   _gdk_event_queue_append (display, gdk_event_copy (event));
231 }
232
233 /**
234  * gdk_pointer_ungrab:
235  * @time: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no timestamp is
236  *        available.
237  * Ungrabs the pointer, if it is grabbed by this application.
238  **/
239 void
240 gdk_pointer_ungrab (guint32 time)
241 {
242   gdk_display_pointer_ungrab (gdk_get_default_display (), time);
243 }
244
245 /**
246  * gdk_pointer_is_grabbed:
247  * 
248  * Returns %TRUE if the pointer is currently grabbed by this application.
249  *
250  * Note that this does not take the inmplicit pointer grab on button
251  * presses into account.
252
253  * Return value: %TRUE if the pointer is currently grabbed by this application.* 
254  **/
255 gboolean
256 gdk_pointer_is_grabbed (void)
257 {
258   return gdk_display_pointer_is_grabbed (gdk_get_default_display ());
259 }
260
261 /**
262  * gdk_keyboard_ungrab:
263  * @time: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no
264  *        timestamp is available.
265  * 
266  * Ungrabs the keyboard, if it is grabbed by this application.
267  **/
268 void
269 gdk_keyboard_ungrab (guint32 time)
270 {
271   gdk_display_keyboard_ungrab (gdk_get_default_display (), time);
272 }
273
274 /**
275  * gdk_beep:
276  * 
277  * Emits a short beep.
278  **/
279 void
280 gdk_beep (void)
281 {
282   gdk_display_beep (gdk_get_default_display ());
283 }
284
285 /**
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.
289  * 
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.
294  * 
295  * Return value: non-zero on success.
296  **/
297 gboolean
298 gdk_event_send_client_message (GdkEvent *event, guint32 xid)
299 {
300   g_return_val_if_fail (event != NULL, FALSE);
301
302   return gdk_event_send_client_message_for_display (gdk_get_default_display (),
303                                                     event, xid);
304 }
305
306 /**
307  * gdk_event_send_clientmessage_toall:
308  * @event: the #GdkEvent to send, which should be a #GdkEventClient.
309  *
310  * Sends an X ClientMessage event to all toplevel windows on the default
311  * #GdkScreen.
312  *
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.
317  **/
318 void
319 gdk_event_send_clientmessage_toall (GdkEvent *event)
320 {
321   g_return_if_fail (event != NULL);
322
323   gdk_screen_broadcast_client_message (gdk_get_default_screen (), event);
324 }
325
326 /**
327  * gdk_device_get_core_pointer:
328  * 
329  * Returns the core pointer device for the default display.
330  * 
331  * Return value: the core pointer device; this is owned by the
332  *   display and should not be freed.
333  **/
334 GdkDevice *
335 gdk_device_get_core_pointer (void)
336 {
337   return gdk_display_get_core_pointer (gdk_get_default_display ());
338 }
339
340 /**
341  * gdk_display_get_core_pointer:
342  * @display: a #GdkDisplay
343  * 
344  * Returns the core pointer device for the given display
345  * 
346  * Return value: the core pointer device; this is owned by the
347  *   display and should not be freed.
348  **/
349 GdkDevice *
350 gdk_display_get_core_pointer (GdkDisplay *display)
351 {
352   return display->core_pointer;
353 }