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.
24 #include "gdkscreen.h"
28 gdk_screen_get_type (void)
30 static GType object_type = 0;
34 static const GTypeInfo object_info =
36 sizeof (GdkScreenClass),
38 (GBaseFinalizeFunc) NULL,
39 NULL, /* class_init */
40 NULL, /* class_finalize */
41 NULL, /* class_data */
44 (GInstanceInitFunc) NULL,
47 object_type = g_type_register_static (G_TYPE_OBJECT,
48 "GdkScreen", &object_info, 0);
55 * gdk_screen_get_default_colormap:
56 * @screen: a #GdkScreen
58 * Gets the default colormap for @screen.
60 * Returns: the default #GdkColormap.
63 gdk_screen_get_default_colormap (GdkScreen *screen)
65 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
67 return GDK_SCREEN_GET_CLASS (screen)->get_default_colormap (screen);
71 * gdk_screen_set_default_colormap:
72 * @screen: a #GdkScreen
73 * @colormap: a #GdkColormap
75 * Sets the default @colormap for @screen.
78 gdk_screen_set_default_colormap (GdkScreen *screen,
79 GdkColormap *colormap)
81 g_return_if_fail (GDK_IS_SCREEN (screen));
82 g_return_if_fail (GDK_IS_COLORMAP (colormap));
84 GDK_SCREEN_GET_CLASS (screen)->set_default_colormap (screen, colormap);
88 * gdk_screen_get_root_window:
89 * @screen: a #GdkScreen
91 * Gets the root window of @screen.
93 * Returns: the root window
96 gdk_screen_get_root_window (GdkScreen *screen)
98 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
100 return GDK_SCREEN_GET_CLASS (screen)->get_root_window (screen);
104 * gdk_screen_get_display:
105 * @screen: a #GdkScreen
107 * Gets the display to which the @screen belongs.
109 * Returns: the display to which @screen belongs
112 gdk_screen_get_display (GdkScreen *screen)
114 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
116 return GDK_SCREEN_GET_CLASS (screen)->get_display (screen);
120 * gdk_screen_get_number:
121 * @screen: a #GdkScreen
123 * Gets the index of @screen among the screens in the display
124 * to which it belongs. (See gdk_screen_get_display())
129 gdk_screen_get_number (GdkScreen *screen)
131 g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
133 return GDK_SCREEN_GET_CLASS (screen)->get_screen_num (screen);
137 * gdk_screen_get_window_at_pointer:
138 * @screen: a #GdkScreen
139 * @win_x: return location for origin of the window under the pointer
140 * @win_y: return location for origin of the window under the pointer
142 * Obtains the window underneath the mouse pointer, returning the location
143 * of that window in @win_x, @win_y for @screen. Returns %NULL if the window
144 * under the mouse pointer is not known to GDK (for example, belongs to
145 * another application).
147 * Returns: the window under the mouse pointer, or %NULL
150 gdk_screen_get_window_at_pointer (GdkScreen *screen,
154 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
156 return GDK_SCREEN_GET_CLASS (screen)->get_window_at_pointer (screen, win_x, win_y);
160 * gdk_screen_get_width:
161 * @screen: a #GdkScreen
163 * Gets the width of @screen in pixels
165 * Returns: the width of @screen in pixels.
168 gdk_screen_get_width (GdkScreen *screen)
170 g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
172 return GDK_SCREEN_GET_CLASS (screen)->get_width (screen);
176 * gdk_screen_get_height:
177 * @screen: a #GdkScreen
179 * Gets the height of @screen in pixels
181 * Returns: the height of @screen in pixels.
184 gdk_screen_get_height (GdkScreen *screen)
186 g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
188 return GDK_SCREEN_GET_CLASS (screen)->get_height (screen);
192 * gdk_screen_get_width_mm:
193 * @screen: a #GdkScreen
195 * Gets the width of @screen in millimeters.
196 * Note that on some X servers this value will not be correct.
198 * Returns: the width of @screen in pixels.
201 gdk_screen_get_width_mm (GdkScreen *screen)
203 g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
205 return GDK_SCREEN_GET_CLASS (screen)->get_width_mm (screen);
209 * gdk_screen_get_height_mm:
210 * @screen: a #GdkScreen
212 * Returns the height of @screen in millimeters.
213 * Note that on some X servers this value will not be correct.
215 * Returns: the heigth of @screen in pixels.
218 gdk_screen_get_height_mm (GdkScreen *screen)
220 g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
222 return GDK_SCREEN_GET_CLASS (screen)->get_height_mm (screen);
227 * @screen: a #GdkScreen
229 * Closes the @screen connection and cleanup its resources.
230 * Note that this function is called automatically by gdk_display_close().
233 gdk_screen_close (GdkScreen *screen)
235 g_return_if_fail (GDK_IS_SCREEN (screen));
237 g_object_run_dispose (G_OBJECT (screen));
241 * gdk_screen_get_n_monitors:
242 * @screen : a #GdkScreen.
244 * Returns the number of monitors being part of the virtual screen
246 * Returns: number of monitors part of the virtual screen or
247 * 0 if @screen is not in virtual screen mode.
250 gdk_screen_get_n_monitors (GdkScreen *screen)
252 g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
254 return GDK_SCREEN_GET_CLASS (screen)->get_n_monitors (screen);
258 * gdk_screen_get_monitor_geometry:
259 * @screen : a #GdkScreen.
260 * @monitor_num: the monitor number.
261 * @dest : a #GdkRectangle to be filled with the monitor geometry
263 * Retrieves the #GdkRectangle representing the size and start
264 * coordinates of the individual monitor within the the entire virtual
267 * Note that the virtual screen coordinates can be retrieved via
268 * gdk_screen_get_width() and gdk_screen_get_height().
272 gdk_screen_get_monitor_geometry (GdkScreen *screen,
276 g_return_if_fail (GDK_IS_SCREEN (screen));
278 GDK_SCREEN_GET_CLASS (screen)->get_monitor_geometry (screen, monitor_num, dest);
282 * gdk_screen_get_monitor_at_point:
283 * @screen : a #GdkScreen.
284 * @x : the x coordinate in the virtual screen.
285 * @y : the y coordinate in the virtual screen.
287 * Returns the monitor number in which the point (@x,@y) is located.
289 * Returns: the monitor number in which the point (@x,@y) belong, or
290 * -1 if the point is not in any monitor.
293 gdk_screen_get_monitor_at_point (GdkScreen *screen,
297 gint num_monitors, i;
299 g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
301 num_monitors = gdk_screen_get_n_monitors (screen);
303 for (i=0;i<num_monitors;i++)
305 GdkRectangle monitor;
307 gdk_screen_get_monitor_geometry (screen, i, &monitor);
309 if (x >= monitor.x &&
310 x < monitor.x + monitor.width &&
312 y < (monitor.y + monitor.height))
320 * gdk_screen_get_monitor_at_window:
321 * @screen: a #GdkScreen.
322 * @window: a #GdkWindow
323 * @returns: the monitor number in which most of @window is located.
325 * Returns the number of the monitor in which the largest area of the bounding rectangle
326 * of @window resides.
329 gdk_screen_get_monitor_at_window (GdkScreen *screen,
332 gint num_monitors, i, sum = 0, screen_num = 0;
333 GdkRectangle win_rect;
334 g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
336 gdk_window_get_geometry (window, &win_rect.x, &win_rect.y, &win_rect.width,
337 &win_rect.height, NULL);
338 gdk_window_get_origin (window, &win_rect.x, &win_rect.y);
339 num_monitors = gdk_screen_get_n_monitors (screen);
341 for (i=0;i<num_monitors;i++)
343 GdkRectangle tmp_monitor, intersect;
345 gdk_screen_get_monitor_geometry (screen, i, &tmp_monitor);
346 gdk_rectangle_intersect (&win_rect, &tmp_monitor, &intersect);
348 if (intersect.width * intersect.height > sum)
350 sum = intersect.width * intersect.height;