]> Pileus Git - ~andy/gtk/blob - gdk/gdkdisplaymanager.c
quartz: Clean up header files, use same arrangement as X11 backend
[~andy/gtk] / gdk / gdkdisplaymanager.c
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 2000 Red Hat, Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GTK+ Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
25  */
26
27 #include "config.h"
28
29 #include "gdkconfig.h"
30 #include "gdkdisplaymanagerprivate.h"
31 #include "gdkinternals.h"
32 #include "gdkmarshalers.h"
33 #include "gdkintl.h"
34
35 #ifdef GDK_WINDOWING_X11
36 #include "x11/gdkx.h"
37 #endif
38
39 #ifdef GDK_WINDOWING_QUARTZ
40 /* We immediately include gdkquartzdisplaymanager.h here instead of
41  * gdkquartz.h so that we do not have to enable -xobjective-c for the
42  * "generic" GDK source code.
43  */
44 #include "quartz/gdkquartzdisplaymanager.h"
45 #endif
46
47
48 /**
49  * SECTION:gdkdisplaymanager
50  * @Short_description: Maintains a list of all open GdkDisplays
51  * @Title: GdkDisplayManager
52  *
53  * The purpose of the #GdkDisplayManager singleton object is to offer
54  * notification when displays appear or disappear or the default display
55  * changes.
56  */
57
58
59 enum {
60   PROP_0,
61   PROP_DEFAULT_DISPLAY
62 };
63
64 enum {
65   DISPLAY_OPENED,
66   LAST_SIGNAL
67 };
68
69 static void gdk_display_manager_class_init   (GdkDisplayManagerClass *klass);
70 static void gdk_display_manager_set_property (GObject                *object,
71                                               guint                   prop_id,
72                                               const GValue           *value,
73                                               GParamSpec             *pspec);
74 static void gdk_display_manager_get_property (GObject                *object,
75                                               guint                   prop_id,
76                                               GValue                 *value,
77                                               GParamSpec             *pspec);
78
79 static guint signals[LAST_SIGNAL] = { 0 };
80
81 G_DEFINE_TYPE (GdkDisplayManager, gdk_display_manager, G_TYPE_OBJECT)
82
83 static void
84 gdk_display_manager_class_init (GdkDisplayManagerClass *klass)
85 {
86   GObjectClass *object_class = G_OBJECT_CLASS (klass);
87
88   object_class->set_property = gdk_display_manager_set_property;
89   object_class->get_property = gdk_display_manager_get_property;
90
91   /**
92    * GdkDisplayManager::display-opened:
93    * @manager: the object on which the signal is emitted
94    * @display: the opened display
95    *
96    * The ::display-opened signal is emitted when a display is opened.
97    *
98    * Since: 2.2
99    */
100   signals[DISPLAY_OPENED] =
101     g_signal_new (g_intern_static_string ("display-opened"),
102                   G_OBJECT_CLASS_TYPE (object_class),
103                   G_SIGNAL_RUN_LAST,
104                   G_STRUCT_OFFSET (GdkDisplayManagerClass, display_opened),
105                   NULL, NULL,
106                   _gdk_marshal_VOID__OBJECT,
107                   G_TYPE_NONE,
108                   1,
109                   GDK_TYPE_DISPLAY);
110
111   g_object_class_install_property (object_class,
112                                    PROP_DEFAULT_DISPLAY,
113                                    g_param_spec_object ("default-display",
114                                                         P_("Default Display"),
115                                                         P_("The default display for GDK"),
116                                                         GDK_TYPE_DISPLAY,
117                                                         G_PARAM_READWRITE|G_PARAM_STATIC_NAME|
118                                                         G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
119 }
120
121 static void
122 gdk_display_manager_init (GdkDisplayManager *manager)
123 {
124 }
125
126 static void
127 gdk_display_manager_set_property (GObject      *object,
128                                   guint         prop_id,
129                                   const GValue *value,
130                                   GParamSpec   *pspec)
131 {
132   switch (prop_id)
133     {
134     case PROP_DEFAULT_DISPLAY:
135       gdk_display_manager_set_default_display (GDK_DISPLAY_MANAGER (object),
136                                                g_value_get_object (value));
137       break;
138     default:
139       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
140       break;
141     }
142 }
143
144 static void
145 gdk_display_manager_get_property (GObject      *object,
146                                   guint         prop_id,
147                                   GValue       *value,
148                                   GParamSpec   *pspec)
149 {
150   switch (prop_id)
151     {
152     case PROP_DEFAULT_DISPLAY:
153       g_value_set_object (value,
154                           gdk_display_manager_get_default_display (GDK_DISPLAY_MANAGER (object)));
155       break;
156     default:
157       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
158       break;
159     }
160 }
161
162 /**
163  * gdk_display_manager_get:
164  *
165  * Gets the singleton #GdkDisplayManager object.
166  *
167  * When called for the first time, this function consults the
168  * <envar>GDK_BACKEND</envar> to find out which of the supported
169  * GDK backends to use (in case GDK has been compiled with multiple
170  * backends).
171  *
172  * Returns: (transfer none): The global #GdkDisplayManager singleton;
173  *     gdk_parse_pargs(), gdk_init(), or gdk_init_check() must have
174  *     been called first.
175  *
176  * Since: 2.2
177  **/
178 GdkDisplayManager*
179 gdk_display_manager_get (void)
180 {
181   static GdkDisplayManager *manager = NULL;
182
183   if (!manager)
184     {
185       const gchar *backend;
186
187       backend = g_getenv ("GDK_BACKEND");
188 #ifdef GDK_WINDOWING_X11
189       if (backend == NULL || strcmp (backend, "x11") == 0)
190         manager = g_object_new (gdk_x11_display_manager_get_type (), NULL);
191       else
192 #endif
193 #ifdef GDK_WINDOWING_QUARTZ
194       if (backend == NULL || strcmp (backend, "quartz") == 0)
195         manager = g_object_new (gdk_quartz_display_manager_get_type (), NULL);
196       else
197 #endif
198       if (backend != NULL)
199         g_error ("Unsupported GDK backend: %s", backend);
200       else
201         g_error ("No GDK backend found");
202     }
203
204   return manager;
205 }
206
207 /**
208  * gdk_display_manager_get_default_display:
209  * @manager: a #GdkDisplayManager
210  *
211  * Gets the default #GdkDisplay.
212  *
213  * Returns: (transfer none): a #GdkDisplay, or %NULL
214  *     if there is no default display.
215  *
216  * Since: 2.2
217  */
218 GdkDisplay *
219 gdk_display_manager_get_default_display (GdkDisplayManager *manager)
220 {
221   return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->get_default_display (manager);
222 }
223
224 /**
225  * gdk_display_get_default:
226  *
227  * Gets the default #GdkDisplay. This is a convenience
228  * function for
229  * <literal>gdk_display_manager_get_default_display (gdk_display_manager_get ())</literal>.
230  *
231  * Returns: (transfer none): a #GdkDisplay, or %NULL if there is no default
232  *   display.
233  *
234  * Since: 2.2
235  */
236 GdkDisplay *
237 gdk_display_get_default (void)
238 {
239   return gdk_display_manager_get_default_display (gdk_display_manager_get ());
240 }
241
242 /**
243  * gdk_screen_get_default:
244  *
245  * Gets the default screen for the default display. (See
246  * gdk_display_get_default ()).
247  *
248  * Returns: (transfer none): a #GdkScreen, or %NULL if there is no default display.
249  *
250  * Since: 2.2
251  */
252 GdkScreen *
253 gdk_screen_get_default (void)
254 {
255   GdkDisplay *default_display;
256
257   default_display = gdk_display_get_default ();
258
259   if (default_display)
260     return gdk_display_get_default_screen (default_display);
261   else
262     return NULL;
263 }
264
265 /**
266  * gdk_display_manager_set_default_display:
267  * @manager: a #GdkDisplayManager
268  * @display: a #GdkDisplay
269  * 
270  * Sets @display as the default display.
271  *
272  * Since: 2.2
273  **/
274 void
275 gdk_display_manager_set_default_display (GdkDisplayManager *manager,
276                                          GdkDisplay        *display)
277 {
278   GDK_DISPLAY_MANAGER_GET_CLASS (manager)->set_default_display (manager, display);
279
280   g_object_notify (G_OBJECT (manager), "default-display");
281 }
282
283 /**
284  * gdk_display_manager_list_displays:
285  * @manager: a #GdkDisplayManager
286  *
287  * List all currently open displays.
288  *
289  * Return value: (transfer container) (element-type GdkDisplay): a newly
290  *     allocated #GSList of #GdkDisplay objects. Free with g_slist_free()
291  *     when you are done with it.
292  *
293  * Since: 2.2
294  **/
295 GSList *
296 gdk_display_manager_list_displays (GdkDisplayManager *manager)
297 {
298   return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->list_displays (manager);
299 }
300
301 GdkDisplay *
302 gdk_display_manager_open_display (GdkDisplayManager *manager,
303                                   const gchar       *name)
304 {
305   return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->open_display (manager, name);
306 }
307
308 /**
309  * gdk_atom_intern:
310  * @atom_name: a string.
311  * @only_if_exists: if %TRUE, GDK is allowed to not create a new atom, but
312  *   just return %GDK_NONE if the requested atom doesn't already
313  *   exists. Currently, the flag is ignored, since checking the
314  *   existance of an atom is as expensive as creating it.
315  *
316  * Finds or creates an atom corresponding to a given string.
317  *
318  * Returns: the atom corresponding to @atom_name.
319  */
320 GdkAtom
321 gdk_atom_intern (const gchar *atom_name,
322                  gboolean     only_if_exists)
323 {
324   GdkDisplayManager *manager = gdk_display_manager_get ();
325
326   return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->atom_intern (manager, atom_name, TRUE);
327 }
328
329 /**
330  * gdk_atom_intern_static_string:
331  * @atom_name: a static string
332  *
333  * Finds or creates an atom corresponding to a given string.
334  *
335  * Note that this function is identical to gdk_atom_intern() except
336  * that if a new #GdkAtom is created the string itself is used rather
337  * than a copy. This saves memory, but can only be used if the string
338  * will <emphasis>always</emphasis> exist. It can be used with statically
339  * allocated strings in the main program, but not with statically
340  * allocated memory in dynamically loaded modules, if you expect to
341  * ever unload the module again (e.g. do not use this function in
342  * GTK+ theme engines).
343  *
344  * Returns: the atom corresponding to @atom_name
345  *
346  * Since: 2.10
347  */
348 GdkAtom
349 gdk_atom_intern_static_string (const gchar *atom_name)
350 {
351   GdkDisplayManager *manager = gdk_display_manager_get ();
352
353   return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->atom_intern (manager, atom_name, FALSE);
354 }
355
356 /**
357  * gdk_atom_name:
358  * @atom: a #GdkAtom.
359  *
360  * Determines the string corresponding to an atom.
361  *
362  * Returns: a newly-allocated string containing the string
363  *   corresponding to @atom. When you are done with the
364  *   return value, you should free it using g_free().
365  */
366 gchar *
367 gdk_atom_name (GdkAtom atom)
368 {
369   GdkDisplayManager *manager = gdk_display_manager_get ();
370
371   return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->get_atom_name (manager, atom);
372 }