1 /* GDK - The GIMP Drawing Kit
4 * Copyright 2001 Sun Microsystems Inc.
6 * Erwann Chenede <erwann.chenede@sun.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 #include "gdkdisplay.h"
26 #include "gdkinternals.h"
28 static void gdk_display_class_init (GdkDisplayClass *class);
29 static void gdk_display_init (GdkDisplay *display);
30 static void gdk_display_finalize (GObject *object);
32 static GdkDisplay *default_display = NULL;
34 static GObjectClass *parent_class;
37 gdk_display_get_type (void)
40 static GType object_type = 0;
44 static const GTypeInfo object_info = {
45 sizeof (GdkDisplayClass),
47 (GBaseFinalizeFunc) NULL,
48 (GClassInitFunc) gdk_display_class_init,
49 NULL, /* class_finalize */
50 NULL, /* class_data */
53 (GInstanceInitFunc) gdk_display_init
55 object_type = g_type_register_static (G_TYPE_OBJECT,
56 "GdkDisplay", &object_info, 0);
63 gdk_display_class_init (GdkDisplayClass *class)
65 GObjectClass *object_class = G_OBJECT_CLASS (class);
67 parent_class = g_type_class_peek_parent (class);
69 object_class->finalize = gdk_display_finalize;
73 gdk_display_init (GdkDisplay *display)
75 _gdk_displays = g_slist_prepend (_gdk_displays, display);
77 display->button_click_time[0] = display->button_click_time[1] = 0;
78 display->button_window[0] = display->button_window[1] = NULL;
79 display->button_number[0] = display->button_number[1] = -1;
81 display->double_click_time = 250;
85 gdk_display_finalize (GObject *object)
87 GdkDisplay *display = GDK_DISPLAY_OBJECT (object);
89 _gdk_displays = g_slist_remove (_gdk_displays, display);
91 if (default_display == display)
92 default_display = NULL;
94 parent_class->finalize (object);
98 * gdk_display_get_name:
99 * @display: a #GdkDisplay
101 * Gets the name of the display.
103 * Returns: a string representing the display name.
105 G_CONST_RETURN gchar *
106 gdk_display_get_name (GdkDisplay * display)
108 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
109 return GDK_DISPLAY_GET_CLASS (display)->get_display_name (display);
113 * gdk_display_get_n_screens:
114 * @display: a #GdkDisplay
116 * Gets the number of screen managed by the @display.
118 * Returns: number of screens.
122 gdk_display_get_n_screens (GdkDisplay * display)
124 g_return_val_if_fail (GDK_IS_DISPLAY (display), 0);
125 return GDK_DISPLAY_GET_CLASS (display)->get_n_screens (display);
129 * gdk_display_get_screen:
130 * @display: a #GdkDisplay
131 * @screen_num: the screen number
133 * Returns a screen object for one of the screens of the display.
135 * Returns: the #GdkScreen object
139 gdk_display_get_screen (GdkDisplay * display, gint screen_num)
141 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
142 return GDK_DISPLAY_GET_CLASS (display)->get_screen (display, screen_num);
146 * gdk_display_get_default_screen:
147 * @display: a #GdkDisplay
149 * Get the default #GdkScreen for @display.
151 * Returns: the default #GdkScreen object for @display
155 gdk_display_get_default_screen (GdkDisplay * display)
157 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
158 return GDK_DISPLAY_GET_CLASS (display)->get_default_screen (display);
163 * @display: a #GdkDisplay
165 * Closes and cleanup the resources used by the @display
168 gdk_display_close (GdkDisplay *display)
170 g_return_if_fail (GDK_IS_DISPLAY (display));
171 g_object_unref (G_OBJECT (display));
175 * gdk_set_default_display:
176 * @display: a #GdkDisplay
178 * Sets @display as the default display.
181 gdk_set_default_display (GdkDisplay *display)
183 default_display = display;
187 * gdk_get_default_display:
189 * Gets the default #GdkDisplay.
191 * Returns: a #GdkDisplay, or %NULL if there is no default
195 gdk_get_default_display (void)
197 return default_display;
201 * gdk_get_default_screen:
203 * Gets the default screen for the default display. (See
204 * gdk_get_default_display ()).
206 * Returns: a #GdkScreen.
209 gdk_get_default_screen (void)
211 return gdk_display_get_default_screen (gdk_get_default_display ());
217 * List all currently open displays.
219 * Return value: a newly allocated #GSList of #GdkDisplay objects.
220 * Free this list with g_slist_free() when you are done with it.
223 gdk_list_displays (void)
225 return g_slist_copy (_gdk_displays);
229 * gdk_display_get_event:
230 * @display: a #GdkDisplay
231 * @event: a #GdkEvent
233 * Gets the next #GdkEvent to be processed for @display, fetching events from the
234 * windowing system if necessary.
236 * Return value: the next #GdkEvent to be processed, or %NULL if no events
237 * are pending. The returned #GdkEvent should be freed with gdk_event_free().
240 gdk_display_get_event (GdkDisplay *display)
242 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
244 _gdk_events_queue (display);
245 return _gdk_event_unqueue (display);
249 * gdk_display_peek_event:
252 * Gets a copy of the first #GdkEvent in the @display's event queue, without
253 * removing the event from the queue. (Note that this function will
254 * not get more events from the windowing system. It only checks the events
255 * that have already been moved to the GDK event queue.)
257 * Return value: a copy of the first #GdkEvent on the event queue, or %NULL if no
258 * events are in the queue. The returned #GdkEvent should be freed with
262 gdk_display_peek_event (GdkDisplay *display)
266 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
268 tmp_list = _gdk_event_queue_find_first (display);
271 return gdk_event_copy (tmp_list->data);
277 * gdk_display_put_event:
278 * @display: a #GdkDisplay
279 * @event: a #GdkEvent.
281 * Appends a copy of the given event onto the front of the event
282 * queue for @display.
285 gdk_display_put_event (GdkDisplay *display,
288 g_return_if_fail (GDK_IS_DISPLAY (display));
289 g_return_if_fail (event != NULL);
291 _gdk_event_queue_append (display, gdk_event_copy (event));