]> Pileus Git - ~andy/gtk/blob - gdk/gdkdisplay.c
Set the client ID on all displays. (#85713)
[~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 static char *gdk_sm_client_id;
45
46 GType
47 gdk_display_get_type (void)
48 {
49
50   static GType object_type = 0;
51
52   if (!object_type)
53     {
54       static const GTypeInfo object_info = {
55         sizeof (GdkDisplayClass),
56         (GBaseInitFunc) NULL,
57         (GBaseFinalizeFunc) NULL,
58         (GClassInitFunc) gdk_display_class_init,
59         NULL,                   /* class_finalize */
60         NULL,                   /* class_data */
61         sizeof (GdkDisplay),
62         0,                      /* n_preallocs */
63         (GInstanceInitFunc) gdk_display_init
64       };
65       object_type = g_type_register_static (G_TYPE_OBJECT,
66                                             "GdkDisplay", &object_info, 0);
67     }
68
69   return object_type;
70 }
71
72 static void
73 gdk_display_class_init (GdkDisplayClass *class)
74 {
75   GObjectClass *object_class = G_OBJECT_CLASS (class);
76   
77   parent_class = g_type_class_peek_parent (class);
78
79   object_class->finalize = gdk_display_finalize;
80   object_class->dispose = gdk_display_dispose;
81
82   signals[CLOSED] =
83     g_signal_new ("closed",
84                   G_OBJECT_CLASS_TYPE (object_class),
85                   G_SIGNAL_RUN_LAST,
86                   G_STRUCT_OFFSET (GdkDisplayClass, closed),
87                   NULL, NULL,
88                   gdk_marshal_VOID__BOOLEAN,
89                   G_TYPE_NONE,
90                   1,
91                   G_TYPE_BOOLEAN);
92 }
93
94 static void
95 gdk_display_init (GdkDisplay *display)
96 {
97   _gdk_displays = g_slist_prepend (_gdk_displays, display);
98
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;
102
103   display->double_click_time = 250;
104 }
105
106 static void
107 gdk_display_dispose (GObject *object)
108 {
109   GdkDisplay *display = GDK_DISPLAY_OBJECT (object);
110
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;
115
116   _gdk_displays = g_slist_remove (_gdk_displays, object);
117
118   if (gdk_display_get_default() == display)
119     gdk_display_manager_set_default_display (gdk_display_manager_get(), NULL);
120 }
121
122 static void
123 gdk_display_finalize (GObject *object)
124 {
125   parent_class->finalize (object);
126 }
127
128 /**
129  * gdk_display_close:
130  * @display: a #GdkDisplay
131  *
132  * Closes the connection windowing system for the given display,
133  * and cleans up associated resources.
134  */
135 void
136 gdk_display_close (GdkDisplay *display)
137 {
138   g_return_if_fail (GDK_IS_DISPLAY (display));
139
140   if (!display->closed)
141     {
142       display->closed = TRUE;
143       
144       g_signal_emit (display, signals[CLOSED], 0, FALSE);
145       g_object_run_dispose (G_OBJECT (display));
146       
147       g_object_unref (display);
148     }
149 }
150
151 /**
152  * gdk_display_get_event:
153  * @display: a #GdkDisplay
154  * 
155  * Gets the next #GdkEvent to be processed for @display, fetching events from the
156  * windowing system if necessary.
157  * 
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().
160  **/
161 GdkEvent*
162 gdk_display_get_event (GdkDisplay *display)
163 {
164   g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
165   
166   _gdk_events_queue (display);
167   return _gdk_event_unqueue (display);
168 }
169
170 /**
171  * gdk_display_peek_event:
172  * @display: a #GdkDisplay 
173  * 
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.)
178  * 
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
181  * gdk_event_free().
182  **/
183 GdkEvent*
184 gdk_display_peek_event (GdkDisplay *display)
185 {
186   GList *tmp_list;
187
188   g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
189
190   tmp_list = _gdk_event_queue_find_first (display);
191   
192   if (tmp_list)
193     return gdk_event_copy (tmp_list->data);
194   else
195     return NULL;
196 }
197
198 /**
199  * gdk_display_put_event:
200  * @display: a #GdkDisplay
201  * @event: a #GdkEvent.
202  *
203  * Appends a copy of the given event onto the front of the event
204  * queue for @display.
205  **/
206 void
207 gdk_display_put_event (GdkDisplay *display,
208                        GdkEvent   *event)
209 {
210   g_return_if_fail (GDK_IS_DISPLAY (display));
211   g_return_if_fail (event != NULL);
212
213   _gdk_event_queue_append (display, gdk_event_copy (event));
214 }
215
216 /**
217  * gdk_pointer_ungrab:
218  * @time: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no timestamp is
219  *        available.
220  *
221  * Ungrabs the pointer, if it is grabbed by this application.
222  **/
223 void
224 gdk_pointer_ungrab (guint32 time)
225 {
226   gdk_display_pointer_ungrab (gdk_display_get_default (), time);
227 }
228
229 /**
230  * gdk_pointer_is_grabbed:
231  * 
232  * Returns %TRUE if the pointer is currently grabbed by this application.
233  *
234  * Note that this does not take the inmplicit pointer grab on button
235  * presses into account.
236
237  * Return value: %TRUE if the pointer is currently grabbed by this application.* 
238  **/
239 gboolean
240 gdk_pointer_is_grabbed (void)
241 {
242   return gdk_display_pointer_is_grabbed (gdk_display_get_default ());
243 }
244
245 /**
246  * gdk_keyboard_ungrab:
247  * @time: a timestamp from a #GdkEvent, or %GDK_CURRENT_TIME if no
248  *        timestamp is available.
249  * 
250  * Ungrabs the keyboard, if it is grabbed by this application.
251  **/
252 void
253 gdk_keyboard_ungrab (guint32 time)
254 {
255   gdk_display_keyboard_ungrab (gdk_display_get_default (), time);
256 }
257
258 /**
259  * gdk_beep:
260  * 
261  * Emits a short beep.
262  **/
263 void
264 gdk_beep (void)
265 {
266   gdk_display_beep (gdk_display_get_default ());
267 }
268
269 /**
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.
273  * 
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.
278  * 
279  * Return value: non-zero on success.
280  **/
281 gboolean
282 gdk_event_send_client_message (GdkEvent        *event,
283                                GdkNativeWindow  winid)
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, winid);
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   GSList *displays, *tmp_list;
358   
359   g_free (gdk_sm_client_id);
360   gdk_sm_client_id = g_strdup (sm_client_id);
361
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);
365
366   g_slist_free (displays);
367 }
368
369 /**
370  * _gdk_get_sm_client_id:
371  * 
372  * Gets the client ID set with gdk_set_sm_client_id(), if any.
373  * 
374  * Return value: Session ID, or %NULL if gdk_set_sm_client_id()
375  *               has never been called.
376  **/
377 const char *
378 _gdk_get_sm_client_id (void)
379 {
380   return gdk_sm_client_id;
381 }