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"
30 static void gdk_screen_class_init (GdkScreenClass *klass);
38 static guint signals[LAST_SIGNAL] = { 0 };
41 gdk_screen_get_type (void)
43 static GType object_type = 0;
47 static const GTypeInfo object_info =
49 sizeof (GdkScreenClass),
51 (GBaseFinalizeFunc) NULL,
52 (GClassInitFunc) gdk_screen_class_init,
53 NULL, /* class_finalize */
54 NULL, /* class_data */
57 (GInstanceInitFunc) NULL,
60 object_type = g_type_register_static (G_TYPE_OBJECT,
61 "GdkScreen", &object_info, 0);
68 gdk_screen_class_init (GdkScreenClass *klass)
70 signals[SIZE_CHANGED] =
71 g_signal_new ("size_changed",
72 G_OBJECT_CLASS_TYPE (klass),
74 G_STRUCT_OFFSET (GdkScreenClass, size_changed),
76 g_cclosure_marshal_VOID__VOID,
82 _gdk_screen_close (GdkScreen *screen)
84 g_return_if_fail (GDK_IS_SCREEN (screen));
88 screen->closed = TRUE;
89 g_object_run_dispose (G_OBJECT (screen));
94 * gdk_screen_get_monitor_at_point:
95 * @screen: a #GdkScreen.
96 * @x: the x coordinate in the virtual screen.
97 * @y: the y coordinate in the virtual screen.
99 * Returns the monitor number in which the point (@x,@y) is located.
101 * Returns: the monitor number in which the point (@x,@y) belong, or
102 * -1 if the point is not in any monitor.
107 gdk_screen_get_monitor_at_point (GdkScreen *screen,
111 gint num_monitors, i;
113 g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
115 num_monitors = gdk_screen_get_n_monitors (screen);
117 for (i=0;i<num_monitors;i++)
119 GdkRectangle monitor;
121 gdk_screen_get_monitor_geometry (screen, i, &monitor);
123 if (x >= monitor.x &&
124 x < monitor.x + monitor.width &&
126 y < (monitor.y + monitor.height))
134 * gdk_screen_get_monitor_at_window:
135 * @screen: a #GdkScreen.
136 * @window: a #GdkWindow
137 * @returns: the monitor number in which most of @window is located.
139 * Returns the number of the monitor in which the largest area of the
140 * bounding rectangle of @window resides.
145 gdk_screen_get_monitor_at_window (GdkScreen *screen,
148 gint num_monitors, i, sum = 0, screen_num = 0;
149 GdkRectangle win_rect;
150 g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
152 gdk_window_get_geometry (window, &win_rect.x, &win_rect.y, &win_rect.width,
153 &win_rect.height, NULL);
154 gdk_window_get_origin (window, &win_rect.x, &win_rect.y);
155 num_monitors = gdk_screen_get_n_monitors (screen);
157 for (i=0;i<num_monitors;i++)
159 GdkRectangle tmp_monitor, intersect;
161 gdk_screen_get_monitor_geometry (screen, i, &tmp_monitor);
162 gdk_rectangle_intersect (&win_rect, &tmp_monitor, &intersect);
164 if (intersect.width * intersect.height > sum)
166 sum = intersect.width * intersect.height;
176 * Returns the width of the default screen in pixels.
178 * Return value: the width of the default screen in pixels.
181 gdk_screen_width (void)
183 return gdk_screen_get_width (gdk_screen_get_default());
189 * Returns the height of the default screen in pixels.
191 * Return value: the height of the default screen in pixels.
194 gdk_screen_height (void)
196 return gdk_screen_get_height (gdk_screen_get_default());
200 * gdk_screen_width_mm:
202 * Returns the width of the default screen in millimeters.
203 * Note that on many X servers this value will not be correct.
205 * Return value: the width of the default screen in millimeters,
206 * though it is not always correct.
209 gdk_screen_width_mm (void)
211 return gdk_screen_get_width_mm (gdk_screen_get_default());
215 * gdk_screen_height_mm:
217 * Returns the height of the default screen in millimeters.
218 * Note that on many X servers this value will not be correct.
220 * Return value: the height of the default screen in millimeters,
221 * though it is not always correct.
224 gdk_screen_height_mm (void)
226 return gdk_screen_get_height_mm (gdk_screen_get_default ());