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 "gdk.h" /* For gdk_rectangle_intersect() */
26 #include "gdkinternals.h"
27 #include "gdkwindow.h"
28 #include "gdkscreen.h"
31 gdk_screen_get_type (void)
33 static GType object_type = 0;
37 static const GTypeInfo object_info =
39 sizeof (GdkScreenClass),
41 (GBaseFinalizeFunc) NULL,
42 NULL, /* class_init */
43 NULL, /* class_finalize */
44 NULL, /* class_data */
47 (GInstanceInitFunc) NULL,
50 object_type = g_type_register_static (G_TYPE_OBJECT,
51 "GdkScreen", &object_info, 0);
58 _gdk_screen_close (GdkScreen *screen)
60 g_return_if_fail (GDK_IS_SCREEN (screen));
64 screen->closed = TRUE;
65 g_object_run_dispose (G_OBJECT (screen));
70 * gdk_screen_get_monitor_at_point:
71 * @screen : a #GdkScreen.
72 * @x : the x coordinate in the virtual screen.
73 * @y : the y coordinate in the virtual screen.
75 * Returns the monitor number in which the point (@x,@y) is located.
77 * Returns: the monitor number in which the point (@x,@y) belong, or
78 * -1 if the point is not in any monitor.
81 gdk_screen_get_monitor_at_point (GdkScreen *screen,
87 g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
89 num_monitors = gdk_screen_get_n_monitors (screen);
91 for (i=0;i<num_monitors;i++)
95 gdk_screen_get_monitor_geometry (screen, i, &monitor);
98 x < monitor.x + monitor.width &&
100 y < (monitor.y + monitor.height))
108 * gdk_screen_get_monitor_at_window:
109 * @screen: a #GdkScreen.
110 * @window: a #GdkWindow
111 * @returns: the monitor number in which most of @window is located.
113 * Returns the number of the monitor in which the largest area of the bounding rectangle
114 * of @window resides.
117 gdk_screen_get_monitor_at_window (GdkScreen *screen,
120 gint num_monitors, i, sum = 0, screen_num = 0;
121 GdkRectangle win_rect;
122 g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
124 gdk_window_get_geometry (window, &win_rect.x, &win_rect.y, &win_rect.width,
125 &win_rect.height, NULL);
126 gdk_window_get_origin (window, &win_rect.x, &win_rect.y);
127 num_monitors = gdk_screen_get_n_monitors (screen);
129 for (i=0;i<num_monitors;i++)
131 GdkRectangle tmp_monitor, intersect;
133 gdk_screen_get_monitor_geometry (screen, i, &tmp_monitor);
134 gdk_rectangle_intersect (&win_rect, &tmp_monitor, &intersect);
136 if (intersect.width * intersect.height > sum)
138 sum = intersect.width * intersect.height;
148 * Returns the width of the default screen in pixels.
150 * Return value: the width of the default screen in pixels.
153 gdk_screen_width (void)
155 return gdk_screen_get_width (gdk_screen_get_default());
161 * Returns the height of the default screen in pixels.
163 * Return value: the height of the default screen in pixels.
166 gdk_screen_height (void)
168 return gdk_screen_get_height (gdk_screen_get_default());
172 * gdk_screen_width_mm:
174 * Returns the width of the default screen in millimeters.
175 * Note that on many X servers this value will not be correct.
177 * Return value: the width of the default screen in millimeters,
178 * though it is not always correct.
181 gdk_screen_width_mm (void)
183 return gdk_screen_get_width_mm (gdk_screen_get_default());
187 * gdk_screen_height_mm:
189 * Returns the height of the default screen in millimeters.
190 * Note that on many X servers this value will not be correct.
192 * Return value: the height of the default screen in millimeters,
193 * though it is not always correct.
196 gdk_screen_height_mm (void)
198 return gdk_screen_get_height_mm (gdk_screen_get_default ());
202 * gdk_screen_get_window_at_pointer:
203 * @screen: a #GdkScreen
204 * @win_x: return location for origin of the window under the pointer
205 * @win_y: return location for origin of the window under the pointer
207 * Obtains the window underneath the mouse pointer, returning the location
208 * of that window in @win_x, @win_y for @screen. Returns %NULL if the window
209 * under the mouse pointer is not known to GDK (for example, belongs to
210 * another application).
212 * Returns: the window under the mouse pointer, or %NULL
215 gdk_screen_get_window_at_pointer (GdkScreen *screen,
219 return _gdk_current_pointer_hooks->window_at_pointer (screen, win_x, win_y);