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"
51 #ifdef GDK_WINDOWING_WAYLAND
52 #include "wayland/gdkwayland.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
76 static void gdk_display_manager_class_init (GdkDisplayManagerClass *klass);
77 static void gdk_display_manager_set_property (GObject *object,
81 static void gdk_display_manager_get_property (GObject *object,
86 static guint signals[LAST_SIGNAL] = { 0 };
88 G_DEFINE_TYPE (GdkDisplayManager, gdk_display_manager, G_TYPE_OBJECT)
91 gdk_display_manager_class_init (GdkDisplayManagerClass *klass)
93 GObjectClass *object_class = G_OBJECT_CLASS (klass);
95 object_class->set_property = gdk_display_manager_set_property;
96 object_class->get_property = gdk_display_manager_get_property;
99 * GdkDisplayManager::display-opened:
100 * @manager: the object on which the signal is emitted
101 * @display: the opened display
103 * The ::display-opened signal is emitted when a display is opened.
107 signals[DISPLAY_OPENED] =
108 g_signal_new (g_intern_static_string ("display-opened"),
109 G_OBJECT_CLASS_TYPE (object_class),
111 G_STRUCT_OFFSET (GdkDisplayManagerClass, display_opened),
113 _gdk_marshal_VOID__OBJECT,
118 g_object_class_install_property (object_class,
119 PROP_DEFAULT_DISPLAY,
120 g_param_spec_object ("default-display",
121 P_("Default Display"),
122 P_("The default display for GDK"),
124 G_PARAM_READWRITE|G_PARAM_STATIC_NAME|
125 G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
129 gdk_display_manager_init (GdkDisplayManager *manager)
134 gdk_display_manager_set_property (GObject *object,
141 case PROP_DEFAULT_DISPLAY:
142 gdk_display_manager_set_default_display (GDK_DISPLAY_MANAGER (object),
143 g_value_get_object (value));
146 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
152 gdk_display_manager_get_property (GObject *object,
159 case PROP_DEFAULT_DISPLAY:
160 g_value_set_object (value,
161 gdk_display_manager_get_default_display (GDK_DISPLAY_MANAGER (object)));
164 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
170 * gdk_display_manager_get:
172 * Gets the singleton #GdkDisplayManager object.
174 * When called for the first time, this function consults the
175 * <envar>GDK_BACKEND</envar> to find out which of the supported
176 * GDK backends to use (in case GDK has been compiled with multiple
179 * Returns: (transfer none): The global #GdkDisplayManager singleton;
180 * gdk_parse_args(), gdk_init(), or gdk_init_check() must have
186 gdk_display_manager_get (void)
188 static GdkDisplayManager *manager = NULL;
192 const gchar *backend;
194 backend = g_getenv ("GDK_BACKEND");
195 #ifdef GDK_WINDOWING_X11
196 if (backend == NULL || strcmp (backend, "x11") == 0)
197 manager = g_object_new (gdk_x11_display_manager_get_type (), NULL);
200 #ifdef GDK_WINDOWING_QUARTZ
201 if (backend == NULL || strcmp (backend, "quartz") == 0)
202 manager = g_object_new (gdk_quartz_display_manager_get_type (), NULL);
205 #ifdef GDK_WINDOWING_WIN32
206 if (backend == NULL || strcmp (backend, "win32") == 0)
207 manager = g_object_new (gdk_win32_display_manager_get_type (), NULL);
210 #ifdef GDK_WINDOWING_WAYLAND
211 if (backend == NULL || strcmp (backend, "wayland") == 0)
212 manager = g_object_new (gdk_wayland_display_manager_get_type (), NULL);
216 g_error ("Unsupported GDK backend: %s", backend);
218 g_error ("No GDK backend found");
225 * gdk_display_manager_get_default_display:
226 * @manager: a #GdkDisplayManager
228 * Gets the default #GdkDisplay.
230 * Returns: (transfer none): a #GdkDisplay, or %NULL
231 * if there is no default display.
236 gdk_display_manager_get_default_display (GdkDisplayManager *manager)
238 return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->get_default_display (manager);
242 * gdk_display_get_default:
244 * Gets the default #GdkDisplay. This is a convenience
246 * <literal>gdk_display_manager_get_default_display (gdk_display_manager_get ())</literal>.
248 * Returns: (transfer none): a #GdkDisplay, or %NULL if there is no default
254 gdk_display_get_default (void)
256 return gdk_display_manager_get_default_display (gdk_display_manager_get ());
260 * gdk_screen_get_default:
262 * Gets the default screen for the default display. (See
263 * gdk_display_get_default ()).
265 * Returns: (transfer none): a #GdkScreen, or %NULL if there is no default display.
270 gdk_screen_get_default (void)
272 GdkDisplay *default_display;
274 default_display = gdk_display_get_default ();
277 return gdk_display_get_default_screen (default_display);
283 * gdk_display_manager_set_default_display:
284 * @manager: a #GdkDisplayManager
285 * @display: a #GdkDisplay
287 * Sets @display as the default display.
292 gdk_display_manager_set_default_display (GdkDisplayManager *manager,
295 GDK_DISPLAY_MANAGER_GET_CLASS (manager)->set_default_display (manager, display);
297 g_object_notify (G_OBJECT (manager), "default-display");
301 * gdk_display_manager_list_displays:
302 * @manager: a #GdkDisplayManager
304 * List all currently open displays.
306 * Return value: (transfer container) (element-type GdkDisplay): a newly
307 * allocated #GSList of #GdkDisplay objects. Free with g_slist_free()
308 * when you are done with it.
313 gdk_display_manager_list_displays (GdkDisplayManager *manager)
315 return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->list_displays (manager);
319 * gdk_display_manager_open_display:
320 * @manager: a #GdkDisplayManager
321 * @name: the name of the display to open
325 * Return value: (transfer none): a #GdkDisplay, or %NULL
326 * if the display could not be opened
331 gdk_display_manager_open_display (GdkDisplayManager *manager,
334 return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->open_display (manager, name);
339 * @atom_name: a string.
340 * @only_if_exists: if %TRUE, GDK is allowed to not create a new atom, but
341 * just return %GDK_NONE if the requested atom doesn't already
342 * exists. Currently, the flag is ignored, since checking the
343 * existance of an atom is as expensive as creating it.
345 * Finds or creates an atom corresponding to a given string.
347 * Returns: (transfer none): the atom corresponding to @atom_name.
350 gdk_atom_intern (const gchar *atom_name,
351 gboolean only_if_exists)
353 GdkDisplayManager *manager = gdk_display_manager_get ();
355 return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->atom_intern (manager, atom_name, TRUE);
359 * gdk_atom_intern_static_string:
360 * @atom_name: a static string
362 * Finds or creates an atom corresponding to a given string.
364 * Note that this function is identical to gdk_atom_intern() except
365 * that if a new #GdkAtom is created the string itself is used rather
366 * than a copy. This saves memory, but can only be used if the string
367 * will <emphasis>always</emphasis> exist. It can be used with statically
368 * allocated strings in the main program, but not with statically
369 * allocated memory in dynamically loaded modules, if you expect to
370 * ever unload the module again (e.g. do not use this function in
371 * GTK+ theme engines).
373 * Returns: (transfer none): the atom corresponding to @atom_name
378 gdk_atom_intern_static_string (const gchar *atom_name)
380 GdkDisplayManager *manager = gdk_display_manager_get ();
382 return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->atom_intern (manager, atom_name, FALSE);
389 * Determines the string corresponding to an atom.
391 * Returns: a newly-allocated string containing the string
392 * corresponding to @atom. When you are done with the
393 * return value, you should free it using g_free().
396 gdk_atom_name (GdkAtom atom)
398 GdkDisplayManager *manager = gdk_display_manager_get ();
400 return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->get_atom_name (manager, atom);