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_WIN32
48 #include "win32/gdkwin32.h"
52 * SECTION:gdkdisplaymanager
53 * @Short_description: Maintains a list of all open GdkDisplays
54 * @Title: GdkDisplayManager
56 * The purpose of the #GdkDisplayManager singleton object is to offer
57 * notification when displays appear or disappear or the default display
60 * You can use gdk_display_manager_get() to obtain the GdkDisplayManager
61 * singleton, but that should be rarely necessary. Typically, initializing
62 * GTK+ opens a display that you can work with without ever accessing the
65 * The GDK library can be built with support for multiple backends.
66 * The GdkDisplayManager object determines which backend is used
69 * When writing backend-specific code that is supposed to work with
70 * multiple GDK backends, you have to consider both compile time and
71 * runtime. At compile time, use the #GDK_WINDOWING_X11, #GDK_WINDOWING_WIN32
72 * macros, etc. to find out which backends are present in the GDK library
73 * you are building your application against. At runtime, use type-check
74 * macros like GDK_IS_X11_DISPLAY() to find out which backend is in use:
76 * <example id="backend-specific">
77 * <title>Backend-specific code</title>
79 * #ifdef GDK_WINDOWING_X11
80 * if (GDK_IS_X11_DISPLAY (display))
82 * /* make X11-specific calls here */
86 * #ifdef GDK_WINDOWING_QUARTZ
87 * if (GDK_IS_QUARTZ_DISPLAY (display))
89 * /* make Quartz-specific calls here */
93 * g_error ("Unsupported GDK backend");
109 static void gdk_display_manager_class_init (GdkDisplayManagerClass *klass);
110 static void gdk_display_manager_set_property (GObject *object,
114 static void gdk_display_manager_get_property (GObject *object,
119 static guint signals[LAST_SIGNAL] = { 0 };
121 G_DEFINE_TYPE (GdkDisplayManager, gdk_display_manager, G_TYPE_OBJECT)
124 gdk_display_manager_class_init (GdkDisplayManagerClass *klass)
126 GObjectClass *object_class = G_OBJECT_CLASS (klass);
128 object_class->set_property = gdk_display_manager_set_property;
129 object_class->get_property = gdk_display_manager_get_property;
132 * GdkDisplayManager::display-opened:
133 * @manager: the object on which the signal is emitted
134 * @display: the opened display
136 * The ::display-opened signal is emitted when a display is opened.
140 signals[DISPLAY_OPENED] =
141 g_signal_new (g_intern_static_string ("display-opened"),
142 G_OBJECT_CLASS_TYPE (object_class),
144 G_STRUCT_OFFSET (GdkDisplayManagerClass, display_opened),
146 _gdk_marshal_VOID__OBJECT,
151 g_object_class_install_property (object_class,
152 PROP_DEFAULT_DISPLAY,
153 g_param_spec_object ("default-display",
154 P_("Default Display"),
155 P_("The default display for GDK"),
157 G_PARAM_READWRITE|G_PARAM_STATIC_NAME|
158 G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
162 gdk_display_manager_init (GdkDisplayManager *manager)
167 gdk_display_manager_set_property (GObject *object,
174 case PROP_DEFAULT_DISPLAY:
175 gdk_display_manager_set_default_display (GDK_DISPLAY_MANAGER (object),
176 g_value_get_object (value));
179 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
185 gdk_display_manager_get_property (GObject *object,
192 case PROP_DEFAULT_DISPLAY:
193 g_value_set_object (value,
194 gdk_display_manager_get_default_display (GDK_DISPLAY_MANAGER (object)));
197 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
203 * gdk_display_manager_get:
205 * Gets the singleton #GdkDisplayManager object.
207 * When called for the first time, this function consults the
208 * <envar>GDK_BACKEND</envar> environment variable to find out which
209 * of the supported GDK backends to use (in case GDK has been compiled
210 * with multiple backends).
212 * Returns: (transfer none): The global #GdkDisplayManager singleton;
213 * gdk_parse_args(), gdk_init(), or gdk_init_check() must have
219 gdk_display_manager_get (void)
221 static GdkDisplayManager *manager = NULL;
225 const gchar *backend;
227 backend = g_getenv ("GDK_BACKEND");
228 #ifdef GDK_WINDOWING_QUARTZ
229 if (backend == NULL || strcmp (backend, "quartz") == 0)
230 manager = g_object_new (gdk_quartz_display_manager_get_type (), NULL);
233 #ifdef GDK_WINDOWING_WIN32
234 if (backend == NULL || strcmp (backend, "win32") == 0)
235 manager = g_object_new (gdk_win32_display_manager_get_type (), NULL);
238 #ifdef GDK_WINDOWING_X11
239 if (backend == NULL || strcmp (backend, "x11") == 0)
240 manager = g_object_new (gdk_x11_display_manager_get_type (), NULL);
244 g_error ("Unsupported GDK backend: %s", backend);
246 g_error ("No GDK backend found");
253 * gdk_display_manager_get_default_display:
254 * @manager: a #GdkDisplayManager
256 * Gets the default #GdkDisplay.
258 * Returns: (transfer none): a #GdkDisplay, or %NULL
259 * if there is no default display.
264 gdk_display_manager_get_default_display (GdkDisplayManager *manager)
266 return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->get_default_display (manager);
270 * gdk_display_get_default:
272 * Gets the default #GdkDisplay. This is a convenience
274 * <literal>gdk_display_manager_get_default_display (gdk_display_manager_get ())</literal>.
276 * Returns: (transfer none): a #GdkDisplay, or %NULL if there is no default
282 gdk_display_get_default (void)
284 return gdk_display_manager_get_default_display (gdk_display_manager_get ());
288 * gdk_screen_get_default:
290 * Gets the default screen for the default display. (See
291 * gdk_display_get_default ()).
293 * Returns: (transfer none): a #GdkScreen, or %NULL if there is no default display.
298 gdk_screen_get_default (void)
300 GdkDisplay *default_display;
302 default_display = gdk_display_get_default ();
305 return gdk_display_get_default_screen (default_display);
311 * gdk_display_manager_set_default_display:
312 * @manager: a #GdkDisplayManager
313 * @display: a #GdkDisplay
315 * Sets @display as the default display.
320 gdk_display_manager_set_default_display (GdkDisplayManager *manager,
323 GDK_DISPLAY_MANAGER_GET_CLASS (manager)->set_default_display (manager, display);
325 g_object_notify (G_OBJECT (manager), "default-display");
329 * gdk_display_manager_list_displays:
330 * @manager: a #GdkDisplayManager
332 * List all currently open displays.
334 * Return value: (transfer container) (element-type GdkDisplay): a newly
335 * allocated #GSList of #GdkDisplay objects. Free with g_slist_free()
336 * when you are done with it.
341 gdk_display_manager_list_displays (GdkDisplayManager *manager)
343 return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->list_displays (manager);
347 * gdk_display_manager_open_display:
348 * @manager: a #GdkDisplayManager
349 * @name: the name of the display to open
353 * Return value: (transfer none): a #GdkDisplay, or %NULL
354 * if the display could not be opened
359 gdk_display_manager_open_display (GdkDisplayManager *manager,
362 return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->open_display (manager, name);
367 * @atom_name: a string.
368 * @only_if_exists: if %TRUE, GDK is allowed to not create a new atom, but
369 * just return %GDK_NONE if the requested atom doesn't already
370 * exists. Currently, the flag is ignored, since checking the
371 * existance of an atom is as expensive as creating it.
373 * Finds or creates an atom corresponding to a given string.
375 * Returns: (transfer none): the atom corresponding to @atom_name.
378 gdk_atom_intern (const gchar *atom_name,
379 gboolean only_if_exists)
381 GdkDisplayManager *manager = gdk_display_manager_get ();
383 return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->atom_intern (manager, atom_name, TRUE);
387 * gdk_atom_intern_static_string:
388 * @atom_name: a static string
390 * Finds or creates an atom corresponding to a given string.
392 * Note that this function is identical to gdk_atom_intern() except
393 * that if a new #GdkAtom is created the string itself is used rather
394 * than a copy. This saves memory, but can only be used if the string
395 * will <emphasis>always</emphasis> exist. It can be used with statically
396 * allocated strings in the main program, but not with statically
397 * allocated memory in dynamically loaded modules, if you expect to
398 * ever unload the module again (e.g. do not use this function in
399 * GTK+ theme engines).
401 * Returns: (transfer none): the atom corresponding to @atom_name
406 gdk_atom_intern_static_string (const gchar *atom_name)
408 GdkDisplayManager *manager = gdk_display_manager_get ();
410 return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->atom_intern (manager, atom_name, FALSE);
417 * Determines the string corresponding to an atom.
419 * Returns: a newly-allocated string containing the string
420 * corresponding to @atom. When you are done with the
421 * return value, you should free it using g_free().
424 gdk_atom_name (GdkAtom atom)
426 GdkDisplayManager *manager = gdk_display_manager_get ();
428 return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->get_atom_name (manager, atom);