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