]> Pileus Git - ~andy/gtk/blob - gdk/gdkdisplay.c
Remove gdk_screen_close, add a section for GdkDisplayManager, add
[~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 "gdkmarshalers.h"
29 #include "gdkscreen.h"
30
31 enum {
32   CLOSED,
33   LAST_SIGNAL
34 };
35
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);
40
41 static guint signals[LAST_SIGNAL] = { 0 };
42
43 static GObjectClass *parent_class;
44
45 GType
46 gdk_display_get_type (void)
47 {
48
49   static GType object_type = 0;
50
51   if (!object_type)
52     {
53       static const GTypeInfo object_info = {
54         sizeof (GdkDisplayClass),
55         (GBaseInitFunc) NULL,
56         (GBaseFinalizeFunc) NULL,
57         (GClassInitFunc) gdk_display_class_init,
58         NULL,                   /* class_finalize */
59         NULL,                   /* class_data */
60         sizeof (GdkDisplay),
61         0,                      /* n_preallocs */
62         (GInstanceInitFunc) gdk_display_init
63       };
64       object_type = g_type_register_static (G_TYPE_OBJECT,
65                                             "GdkDisplay", &object_info, 0);
66     }
67
68   return object_type;
69 }
70
71 static void
72 gdk_display_class_init (GdkDisplayClass *class)
73 {
74   GObjectClass *object_class = G_OBJECT_CLASS (class);
75   
76   parent_class = g_type_class_peek_parent (class);
77
78   object_class->finalize = gdk_display_finalize;
79   object_class->dispose = gdk_display_dispose;
80
81   signals[CLOSED] =
82     g_signal_new ("closed",
83                   G_OBJECT_CLASS_TYPE (object_class),
84                   G_SIGNAL_RUN_LAST,
85                   G_STRUCT_OFFSET (GdkDisplayClass, closed),
86                   NULL, NULL,
87                   gdk_marshal_VOID__BOOLEAN,
88                   G_TYPE_NONE,
89                   1,
90                   G_TYPE_BOOLEAN);
91 }
92
93 static void
94 gdk_display_init (GdkDisplay *display)
95 {
96   _gdk_displays = g_slist_prepend (_gdk_displays, display);
97
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;
101
102   display->double_click_time = 250;
103 }
104
105 static void
106 gdk_display_dispose (GObject *object)
107 {
108   GdkDisplay *display = GDK_DISPLAY_OBJECT (object);
109
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;
114
115   _gdk_displays = g_slist_remove (_gdk_displays, object);
116
117   if (gdk_display_get_default() == display)
118     gdk_display_manager_set_default_display (gdk_display_manager_get(), NULL);
119 }
120
121 static void
122 gdk_display_finalize (GObject *object)
123 {
124   GdkDisplay *display = GDK_DISPLAY_OBJECT (object);
125   
126   parent_class->finalize (object);
127 }
128
129 /**
130  * gdk_display_close:
131  * @display: a #GdkDisplay
132  *
133  * Closes the connection windowing system for the given display,
134  * and cleans up associated resources.
135  */
136 void
137 gdk_display_close (GdkDisplay *display)
138 {
139   g_return_if_fail (GDK_IS_DISPLAY (display));
140
141   if (!display->closed)
142     {
143       display->closed = TRUE;
144       
145       g_signal_emit (display, signals[CLOSED], 0, FALSE);
146       g_object_run_dispose (G_OBJECT (display));
147       
148       g_object_unref (G_OBJECT (display));
149     }
150 }
151
152 /**
153  * gdk_display_get_event:
154  * @display: a #GdkDisplay
155  * 
156  * Gets the next #GdkEvent to be processed for @display, fetching events from the
157  * windowing system if necessary.
158  * 
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().
161  **/
162 GdkEvent*
163 gdk_display_get_event (GdkDisplay *display)
164 {
165   g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
166   
167   _gdk_events_queue (display);
168   return _gdk_event_unqueue (display);
169 }
170
171 /**
172  * gdk_display_peek_event:
173  * @display: a #GdkDisplay 
174  * 
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.)
179  * 
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
182  * gdk_event_free().
183  **/
184 GdkEvent*
185 gdk_display_peek_event (GdkDisplay *display)
186 {
187   GList *tmp_list;
188
189   g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
190
191   tmp_list = _gdk_event_queue_find_first (display);
192   
193   if (tmp_list)
194     return gdk_event_copy (tmp_list->data);
195   else
196     return NULL;
197 }
198
199 /**
200  * gdk_display_put_event:
201  * @display: a #GdkDisplay
202  * @event: a #GdkEvent.
203  *
204  * Appends a copy of the given event onto the front of the event
205  * queue for @display.
206  **/
207 void
208 gdk_display_put_event (GdkDisplay *display,
209                        GdkEvent   *event)
210 {
211   g_return_if_fail (GDK_IS_DISPLAY (display));
212   g_return_if_fail (event != NULL);
213
214   _gdk_event_queue_append (display, gdk_event_copy (event));
215 }
216
217 /**
218  * gdk_pointer_ungrab:
219  * @time: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no timestamp is
220  *        available.
221  *
222  * Ungrabs the pointer, if it is grabbed by this application.
223  **/
224 void
225 gdk_pointer_ungrab (guint32 time)
226 {
227   gdk_display_pointer_ungrab (gdk_display_get_default (), time);
228 }
229
230 /**
231  * gdk_pointer_is_grabbed:
232  * 
233  * Returns %TRUE if the pointer is currently grabbed by this application.
234  *
235  * Note that this does not take the inmplicit pointer grab on button
236  * presses into account.
237
238  * Return value: %TRUE if the pointer is currently grabbed by this application.* 
239  **/
240 gboolean
241 gdk_pointer_is_grabbed (void)
242 {
243   return gdk_display_pointer_is_grabbed (gdk_display_get_default ());
244 }
245
246 /**
247  * gdk_keyboard_ungrab:
248  * @time: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no
249  *        timestamp is available.
250  * 
251  * Ungrabs the keyboard, if it is grabbed by this application.
252  **/
253 void
254 gdk_keyboard_ungrab (guint32 time)
255 {
256   gdk_display_keyboard_ungrab (gdk_display_get_default (), time);
257 }
258
259 /**
260  * gdk_beep:
261  * 
262  * Emits a short beep.
263  **/
264 void
265 gdk_beep (void)
266 {
267   gdk_display_beep (gdk_display_get_default ());
268 }
269
270 /**
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.
274  * 
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.
279  * 
280  * Return value: non-zero on success.
281  **/
282 gboolean
283 gdk_event_send_client_message (GdkEvent *event, guint32 xid)
284 {
285   g_return_val_if_fail (event != NULL, FALSE);
286
287   return gdk_event_send_client_message_for_display (gdk_display_get_default (),
288                                                     event, xid);
289 }
290
291 /**
292  * gdk_event_send_clientmessage_toall:
293  * @event: the #GdkEvent to send, which should be a #GdkEventClient.
294  *
295  * Sends an X ClientMessage event to all toplevel windows on the default
296  * #GdkScreen.
297  *
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.
302  **/
303 void
304 gdk_event_send_clientmessage_toall (GdkEvent *event)
305 {
306   g_return_if_fail (event != NULL);
307
308   gdk_screen_broadcast_client_message (gdk_screen_get_default (), event);
309 }
310
311 /**
312  * gdk_device_get_core_pointer:
313  * 
314  * Returns the core pointer device for the default display.
315  * 
316  * Return value: the core pointer device; this is owned by the
317  *   display and should not be freed.
318  **/
319 GdkDevice *
320 gdk_device_get_core_pointer (void)
321 {
322   return gdk_display_get_core_pointer (gdk_display_get_default ());
323 }
324
325 /**
326  * gdk_display_get_core_pointer:
327  * @display: a #GdkDisplay
328  * 
329  * Returns the core pointer device for the given 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_display_get_core_pointer (GdkDisplay *display)
336 {
337   return display->core_pointer;
338 }
339
340 /**
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.
344  * 
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.
348  *
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.)
353  **/
354 void
355 gdk_set_sm_client_id (const gchar* sm_client_id)
356 {
357   gdk_display_set_sm_client_id (gdk_display_get_default (), sm_client_id);
358 }
359