1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 2000 Red Hat, Inc.
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.
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.
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.
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/.
29 #include "gdkconfig.h"
30 #include "gdkdisplaymanagerprivate.h"
31 #include "gdkinternals.h"
32 #include "gdkmarshalers.h"
35 #ifdef GDK_WINDOWING_X11
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.
44 #include "quartz/gdkquartzdisplaymanager.h"
47 #ifdef GDK_WINDOWING_BROADWAY
48 #include "broadway/gdkbroadwaydisplaymanager.h"
51 #ifdef GDK_WINDOWING_WIN32
52 #include "win32/gdkwin32.h"
56 * SECTION:gdkdisplaymanager
57 * @Short_description: Maintains a list of all open GdkDisplays
58 * @Title: GdkDisplayManager
60 * The purpose of the #GdkDisplayManager singleton object is to offer
61 * notification when displays appear or disappear or the default display
64 * You can use gdk_display_manager_get() to obtain the GdkDisplayManager
65 * singleton, but that should be rarely necessary. Typically, initializing
66 * GTK+ opens a display that you can work with without ever accessing the
69 * The GDK library can be built with support for multiple backends.
70 * The GdkDisplayManager object determines which backend is used
73 * When writing backend-specific code that is supposed to work with
74 * multiple GDK backends, you have to consider both compile time and
75 * runtime. At compile time, use the #GDK_WINDOWING_X11, #GDK_WINDOWING_WIN32
76 * macros, etc. to find out which backends are present in the GDK library
77 * you are building your application against. At runtime, use type-check
78 * macros like GDK_IS_X11_DISPLAY() to find out which backend is in use:
80 * <example id="backend-specific">
81 * <title>Backend-specific code</title>
83 * #ifdef GDK_WINDOWING_X11
84 * if (GDK_IS_X11_DISPLAY (display))
86 * /* make X11-specific calls here */
90 * #ifdef GDK_WINDOWING_QUARTZ
91 * if (GDK_IS_QUARTZ_DISPLAY (display))
93 * /* make Quartz-specific calls here */
97 * g_error ("Unsupported GDK backend");
113 static void gdk_display_manager_class_init (GdkDisplayManagerClass *klass);
114 static void gdk_display_manager_set_property (GObject *object,
118 static void gdk_display_manager_get_property (GObject *object,
123 static guint signals[LAST_SIGNAL] = { 0 };
125 G_DEFINE_TYPE (GdkDisplayManager, gdk_display_manager, G_TYPE_OBJECT)
128 gdk_display_manager_class_init (GdkDisplayManagerClass *klass)
130 GObjectClass *object_class = G_OBJECT_CLASS (klass);
132 object_class->set_property = gdk_display_manager_set_property;
133 object_class->get_property = gdk_display_manager_get_property;
136 * GdkDisplayManager::display-opened:
137 * @manager: the object on which the signal is emitted
138 * @display: the opened display
140 * The ::display-opened signal is emitted when a display is opened.
144 signals[DISPLAY_OPENED] =
145 g_signal_new (g_intern_static_string ("display-opened"),
146 G_OBJECT_CLASS_TYPE (object_class),
148 G_STRUCT_OFFSET (GdkDisplayManagerClass, display_opened),
150 _gdk_marshal_VOID__OBJECT,
155 g_object_class_install_property (object_class,
156 PROP_DEFAULT_DISPLAY,
157 g_param_spec_object ("default-display",
158 P_("Default Display"),
159 P_("The default display for GDK"),
161 G_PARAM_READWRITE|G_PARAM_STATIC_NAME|
162 G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
166 gdk_display_manager_init (GdkDisplayManager *manager)
171 gdk_display_manager_set_property (GObject *object,
178 case PROP_DEFAULT_DISPLAY:
179 gdk_display_manager_set_default_display (GDK_DISPLAY_MANAGER (object),
180 g_value_get_object (value));
183 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
189 gdk_display_manager_get_property (GObject *object,
196 case PROP_DEFAULT_DISPLAY:
197 g_value_set_object (value,
198 gdk_display_manager_get_default_display (GDK_DISPLAY_MANAGER (object)));
201 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
207 * gdk_display_manager_get:
209 * Gets the singleton #GdkDisplayManager object.
211 * When called for the first time, this function consults the
212 * <envar>GDK_BACKEND</envar> environment variable to find out which
213 * of the supported GDK backends to use (in case GDK has been compiled
214 * with multiple backends).
216 * Returns: (transfer none): The global #GdkDisplayManager singleton;
217 * gdk_parse_args(), gdk_init(), or gdk_init_check() must have
223 gdk_display_manager_get (void)
225 static GdkDisplayManager *manager = NULL;
229 const gchar *backend;
231 backend = g_getenv ("GDK_BACKEND");
232 #ifdef GDK_WINDOWING_X11
233 if (backend == NULL || strcmp (backend, "x11") == 0)
234 manager = g_object_new (gdk_x11_display_manager_get_type (), NULL);
237 #ifdef GDK_WINDOWING_QUARTZ
238 if (backend == NULL || strcmp (backend, "quartz") == 0)
239 manager = g_object_new (gdk_quartz_display_manager_get_type (), NULL);
242 #ifdef GDK_WINDOWING_WIN32
243 if (backend == NULL || strcmp (backend, "win32") == 0)
244 manager = g_object_new (gdk_win32_display_manager_get_type (), NULL);
247 #ifdef GDK_WINDOWING_BROADWAY
248 if (backend == NULL || strcmp (backend, "broadway") == 0)
249 manager = g_object_new (gdk_broadway_display_manager_get_type (), NULL);
253 g_error ("Unsupported GDK backend: %s", backend);
255 g_error ("No GDK backend found");
262 * gdk_display_manager_get_default_display:
263 * @manager: a #GdkDisplayManager
265 * Gets the default #GdkDisplay.
267 * Returns: (transfer none): a #GdkDisplay, or %NULL
268 * if there is no default display.
273 gdk_display_manager_get_default_display (GdkDisplayManager *manager)
275 return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->get_default_display (manager);
279 * gdk_display_get_default:
281 * Gets the default #GdkDisplay. This is a convenience
283 * <literal>gdk_display_manager_get_default_display (gdk_display_manager_get ())</literal>.
285 * Returns: (transfer none): a #GdkDisplay, or %NULL if there is no default
291 gdk_display_get_default (void)
293 return gdk_display_manager_get_default_display (gdk_display_manager_get ());
297 * gdk_screen_get_default:
299 * Gets the default screen for the default display. (See
300 * gdk_display_get_default ()).
302 * Returns: (transfer none): a #GdkScreen, or %NULL if there is no default display.
307 gdk_screen_get_default (void)
309 GdkDisplay *default_display;
311 default_display = gdk_display_get_default ();
314 return gdk_display_get_default_screen (default_display);
320 * gdk_display_manager_set_default_display:
321 * @manager: a #GdkDisplayManager
322 * @display: a #GdkDisplay
324 * Sets @display as the default display.
329 gdk_display_manager_set_default_display (GdkDisplayManager *manager,
332 GDK_DISPLAY_MANAGER_GET_CLASS (manager)->set_default_display (manager, display);
334 g_object_notify (G_OBJECT (manager), "default-display");
338 * gdk_display_manager_list_displays:
339 * @manager: a #GdkDisplayManager
341 * List all currently open displays.
343 * Return value: (transfer container) (element-type GdkDisplay): a newly
344 * allocated #GSList of #GdkDisplay objects. Free with g_slist_free()
345 * when you are done with it.
350 gdk_display_manager_list_displays (GdkDisplayManager *manager)
352 return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->list_displays (manager);
356 * gdk_display_manager_open_display:
357 * @manager: a #GdkDisplayManager
358 * @name: the name of the display to open
362 * Return value: (transfer none): a #GdkDisplay, or %NULL
363 * if the display could not be opened
368 gdk_display_manager_open_display (GdkDisplayManager *manager,
371 return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->open_display (manager, name);
376 * @atom_name: a string.
377 * @only_if_exists: if %TRUE, GDK is allowed to not create a new atom, but
378 * just return %GDK_NONE if the requested atom doesn't already
379 * exists. Currently, the flag is ignored, since checking the
380 * existance of an atom is as expensive as creating it.
382 * Finds or creates an atom corresponding to a given string.
384 * Returns: (transfer none): the atom corresponding to @atom_name.
387 gdk_atom_intern (const gchar *atom_name,
388 gboolean only_if_exists)
390 GdkDisplayManager *manager = gdk_display_manager_get ();
392 return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->atom_intern (manager, atom_name, TRUE);
396 * gdk_atom_intern_static_string:
397 * @atom_name: a static string
399 * Finds or creates an atom corresponding to a given string.
401 * Note that this function is identical to gdk_atom_intern() except
402 * that if a new #GdkAtom is created the string itself is used rather
403 * than a copy. This saves memory, but can only be used if the string
404 * will <emphasis>always</emphasis> exist. It can be used with statically
405 * allocated strings in the main program, but not with statically
406 * allocated memory in dynamically loaded modules, if you expect to
407 * ever unload the module again (e.g. do not use this function in
408 * GTK+ theme engines).
410 * Returns: (transfer none): the atom corresponding to @atom_name
415 gdk_atom_intern_static_string (const gchar *atom_name)
417 GdkDisplayManager *manager = gdk_display_manager_get ();
419 return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->atom_intern (manager, atom_name, FALSE);
426 * Determines the string corresponding to an atom.
428 * Returns: a newly-allocated string containing the string
429 * corresponding to @atom. When you are done with the
430 * return value, you should free it using g_free().
433 gdk_atom_name (GdkAtom atom)
435 GdkDisplayManager *manager = gdk_display_manager_get ();
437 return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->get_atom_name (manager, atom);