]> Pileus Git - ~andy/gtk/blob - gdk/gdkdisplaymanager.c
b19fc36b807511706e7954d9465cbc93375063e5
[~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 "gdkdisplay.h"
30 #include "gdkdisplaymanager.h"
31
32 #include "gdkinternals.h"
33 #include "gdkmarshalers.h"
34
35 #include "gdkintl.h"
36
37 struct _GdkDisplayManager
38 {
39   GObject parent_instance;
40 };
41
42 enum {
43   PROP_0,
44
45   PROP_DEFAULT_DISPLAY
46 };
47
48 enum {
49   DISPLAY_OPENED,
50   LAST_SIGNAL
51 };
52
53 static void gdk_display_manager_class_init   (GdkDisplayManagerClass *klass);
54 static void gdk_display_manager_set_property (GObject                *object,
55                                               guint                   prop_id,
56                                               const GValue           *value,
57                                               GParamSpec             *pspec);
58 static void gdk_display_manager_get_property (GObject                *object,
59                                               guint                   prop_id,
60                                               GValue                 *value,
61                                               GParamSpec             *pspec);
62
63 static guint signals[LAST_SIGNAL] = { 0 };
64
65 static GdkDisplay *default_display = NULL;
66
67 GType
68 gdk_display_manager_get_type (void)
69 {
70   static GType object_type = 0;
71
72   if (!object_type)
73     {
74       static const GTypeInfo object_info =
75       {
76         sizeof (GdkDisplayManagerClass),
77         (GBaseInitFunc) NULL,
78         (GBaseFinalizeFunc) NULL,
79         (GClassInitFunc) gdk_display_manager_class_init,
80         NULL,           /* class_finalize */
81         NULL,           /* class_data */
82         sizeof (GdkDisplayManager),
83         0,              /* n_preallocs */
84         (GInstanceInitFunc) NULL,
85       };
86       
87       object_type = g_type_register_static (G_TYPE_OBJECT,
88                                             "GdkDisplayManager",
89                                             &object_info, 0);
90     }
91   
92   return object_type;
93 }
94
95 static void
96 gdk_display_manager_class_init (GdkDisplayManagerClass *klass)
97 {
98   GObjectClass *object_class = G_OBJECT_CLASS (klass);
99
100   object_class->set_property = gdk_display_manager_set_property;
101   object_class->get_property = gdk_display_manager_get_property;
102
103   /**
104    * GdkDisplayManager::display-opened:
105    * @display_manager: the object on which the signal is emitted
106    * @display: the opened display
107    *
108    * The ::display_opened signal is emitted when a display is opened.
109    *
110    * Since: 2.2
111    */
112   signals[DISPLAY_OPENED] =
113     g_signal_new ("display_opened",
114                   G_OBJECT_CLASS_TYPE (object_class),
115                   G_SIGNAL_RUN_LAST,
116                   G_STRUCT_OFFSET (GdkDisplayManagerClass, display_opened),
117                   NULL, NULL,
118                   gdk_marshal_VOID__OBJECT,
119                   G_TYPE_NONE,
120                   1,
121                   GDK_TYPE_DISPLAY);
122
123   g_object_class_install_property (object_class,
124                                    PROP_DEFAULT_DISPLAY,
125                                    g_param_spec_object ("default-display",
126                                                         _("Default Display"),
127                                                         _("The default display for GDK"),
128                                                         GDK_TYPE_DISPLAY,
129                                                         G_PARAM_READWRITE));
130 }
131
132 static void
133 gdk_display_manager_set_property (GObject      *object,
134                                   guint         prop_id,
135                                   const GValue *value,
136                                   GParamSpec   *pspec)
137 {
138   switch (prop_id)
139     {
140     case PROP_DEFAULT_DISPLAY:
141       default_display = g_value_get_object (value);
142       break;
143     default:
144       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
145       break;
146     }
147 }
148
149 static void
150 gdk_display_manager_get_property (GObject      *object,
151                                   guint         prop_id,
152                                   GValue       *value,
153                                   GParamSpec   *pspec)
154 {
155   switch (prop_id)
156     {
157     case PROP_DEFAULT_DISPLAY:
158       g_value_set_object (value, default_display);
159       break;
160     default:
161       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
162       break;
163     }
164 }
165
166 /** 
167  * gdk_display_manager_get:
168  * @returns: the singleton #GdkDisplayManager object.
169  *
170  * Returns the global #GdkDisplayManager singleton; gdk_parse_pargs(),
171  * gdk_init(), or gdk_init_check() must have been called first.
172  *
173  * Since: 2.2
174  **/
175 GdkDisplayManager*
176 gdk_display_manager_get (void)
177 {
178   static GdkDisplayManager *display_manager = NULL;
179
180   if (!display_manager)
181     display_manager = g_object_new (GDK_TYPE_DISPLAY_MANAGER, NULL);
182
183   return display_manager;
184 }
185
186 /**
187  * gdk_display_manager_get_default_display:
188  * @display_manager: a #GdkDisplayManager 
189  *
190  * Gets the default #GdkDisplay. 
191  * 
192  * Returns: a #GdkDisplay, or %NULL if there is no default
193  *   display.
194  *
195  * Since: 2.2
196  */
197 GdkDisplay *
198 gdk_display_manager_get_default_display (GdkDisplayManager *display_manager)
199 {
200   return default_display;
201 }
202
203 /**
204  * gdk_display_get_default:
205  *
206  * Gets the default #GdkDisplay. This is a convenience
207  * function for:
208  * <programlisting>
209  *   gdk_display_manager_get_default_display (gdk_display_manager_get ())
210  * </programlisting>
211  * 
212  * Returns: a #GdkDisplay, or %NULL if there is no default
213  *   display.
214  *
215  * Since: 2.2
216  */
217 GdkDisplay *
218 gdk_display_get_default (void)
219 {
220   return default_display;
221 }
222
223 /**
224  * gdk_screen_get_default:
225  *
226  * Gets the default screen for the default display. (See
227  * gdk_display_get_default ()).
228  * 
229  * Returns: a #GdkScreen, or %NULL if there is no default display.
230  *
231  * Since: 2.2
232  */
233 GdkScreen *
234 gdk_screen_get_default (void)
235 {
236   if (default_display)
237     return gdk_display_get_default_screen (default_display);
238   else
239     return NULL;
240 }
241
242 /**
243  * gdk_display_manager_set_default_display:
244  * @display_manager: a #GdkDisplayManager
245  * @display: a #GdkDisplay
246  * 
247  * Sets @display as the default display.
248  *
249  * Since: 2.2
250  **/
251 void
252 gdk_display_manager_set_default_display (GdkDisplayManager *display_manager,
253                                          GdkDisplay        *display)
254 {
255   default_display = display;
256
257   _gdk_windowing_set_default_display (display);
258
259   g_object_notify (G_OBJECT (display_manager), "default_display");
260 }
261
262 /**
263  * gdk_display_manager_list_displays:
264  * @display_manager: a #GdkDisplayManager 
265  *
266  * List all currently open displays.
267  * 
268  * Return value: a newly allocated #GSList of #GdkDisplay objects.
269  *  Free this list with g_slist_free() when you are done with it.
270  *
271  * Since: 2.2
272  **/
273 GSList *
274 gdk_display_manager_list_displays (GdkDisplayManager *display_manager)
275 {
276   return g_slist_copy (_gdk_displays);
277 }
278