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);
60 * @screen: a #GdkScreen
62 * Closes the @screen connection and cleanup its resources.
63 * Note that this function is called automatically by gdk_display_close().
66 gdk_screen_close (GdkScreen *screen)
68 g_return_if_fail (GDK_IS_SCREEN (screen));
70 g_object_run_dispose (G_OBJECT (screen));
74 * gdk_screen_get_monitor_at_point:
75 * @screen : a #GdkScreen.
76 * @x : the x coordinate in the virtual screen.
77 * @y : the y coordinate in the virtual screen.
79 * Returns the monitor number in which the point (@x,@y) is located.
81 * Returns: the monitor number in which the point (@x,@y) belong, or
82 * -1 if the point is not in any monitor.
85 gdk_screen_get_monitor_at_point (GdkScreen *screen,
91 g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
93 num_monitors = gdk_screen_get_n_monitors (screen);
95 for (i=0;i<num_monitors;i++)
99 gdk_screen_get_monitor_geometry (screen, i, &monitor);
101 if (x >= monitor.x &&
102 x < monitor.x + monitor.width &&
104 y < (monitor.y + monitor.height))
112 * gdk_screen_get_monitor_at_window:
113 * @screen: a #GdkScreen.
114 * @window: a #GdkWindow
115 * @returns: the monitor number in which most of @window is located.
117 * Returns the number of the monitor in which the largest area of the bounding rectangle
118 * of @window resides.
121 gdk_screen_get_monitor_at_window (GdkScreen *screen,
124 gint num_monitors, i, sum = 0, screen_num = 0;
125 GdkRectangle win_rect;
126 g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
128 gdk_window_get_geometry (window, &win_rect.x, &win_rect.y, &win_rect.width,
129 &win_rect.height, NULL);
130 gdk_window_get_origin (window, &win_rect.x, &win_rect.y);
131 num_monitors = gdk_screen_get_n_monitors (screen);
133 for (i=0;i<num_monitors;i++)
135 GdkRectangle tmp_monitor, intersect;
137 gdk_screen_get_monitor_geometry (screen, i, &tmp_monitor);
138 gdk_rectangle_intersect (&win_rect, &tmp_monitor, &intersect);
140 if (intersect.width * intersect.height > sum)
142 sum = intersect.width * intersect.height;
152 * Returns the width of the default screen in pixels.
154 * Return value: the width of the default screen in pixels.
157 gdk_screen_width (void)
159 return gdk_screen_get_width (gdk_get_default_screen());
165 * Returns the height of the default screen in pixels.
167 * Return value: the height of the default screen in pixels.
170 gdk_screen_height (void)
172 return gdk_screen_get_height (gdk_get_default_screen());
176 * gdk_screen_width_mm:
178 * Returns the width of the default screen in millimeters.
179 * Note that on many X servers this value will not be correct.
181 * Return value: the width of the default screen in millimeters,
182 * though it is not always correct.
185 gdk_screen_width_mm (void)
187 return gdk_screen_get_width_mm (gdk_get_default_screen());
191 * gdk_screen_height_mm:
193 * Returns the height of the default screen in millimeters.
194 * Note that on many X servers this value will not be correct.
196 * Return value: the height of the default screen in millimeters,
197 * though it is not always correct.
200 gdk_screen_height_mm (void)
202 return gdk_screen_get_height_mm (gdk_get_default_screen ());
206 * gdk_screen_get_window_at_pointer:
207 * @screen: a #GdkScreen
208 * @win_x: return location for origin of the window under the pointer
209 * @win_y: return location for origin of the window under the pointer
211 * Obtains the window underneath the mouse pointer, returning the location
212 * of that window in @win_x, @win_y for @screen. Returns %NULL if the window
213 * under the mouse pointer is not known to GDK (for example, belongs to
214 * another application).
216 * Returns: the window under the mouse pointer, or %NULL
219 gdk_screen_get_window_at_pointer (GdkScreen *screen,
223 return _gdk_current_pointer_hooks->window_at_pointer (screen, win_x, win_y);