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.
105 gdk_screen_get_monitor_at_point (GdkScreen *screen,
109 gint num_monitors, i;
111 g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
113 num_monitors = gdk_screen_get_n_monitors (screen);
115 for (i=0;i<num_monitors;i++)
117 GdkRectangle monitor;
119 gdk_screen_get_monitor_geometry (screen, i, &monitor);
121 if (x >= monitor.x &&
122 x < monitor.x + monitor.width &&
124 y < (monitor.y + monitor.height))
132 * gdk_screen_get_monitor_at_window:
133 * @screen: a #GdkScreen.
134 * @window: a #GdkWindow
135 * @returns: the monitor number in which most of @window is located.
137 * Returns the number of the monitor in which the largest area of the bounding rectangle
138 * of @window resides.
141 gdk_screen_get_monitor_at_window (GdkScreen *screen,
144 gint num_monitors, i, sum = 0, screen_num = 0;
145 GdkRectangle win_rect;
146 g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
148 gdk_window_get_geometry (window, &win_rect.x, &win_rect.y, &win_rect.width,
149 &win_rect.height, NULL);
150 gdk_window_get_origin (window, &win_rect.x, &win_rect.y);
151 num_monitors = gdk_screen_get_n_monitors (screen);
153 for (i=0;i<num_monitors;i++)
155 GdkRectangle tmp_monitor, intersect;
157 gdk_screen_get_monitor_geometry (screen, i, &tmp_monitor);
158 gdk_rectangle_intersect (&win_rect, &tmp_monitor, &intersect);
160 if (intersect.width * intersect.height > sum)
162 sum = intersect.width * intersect.height;
172 * Returns the width of the default screen in pixels.
174 * Return value: the width of the default screen in pixels.
177 gdk_screen_width (void)
179 return gdk_screen_get_width (gdk_screen_get_default());
185 * Returns the height of the default screen in pixels.
187 * Return value: the height of the default screen in pixels.
190 gdk_screen_height (void)
192 return gdk_screen_get_height (gdk_screen_get_default());
196 * gdk_screen_width_mm:
198 * Returns the width of the default screen in millimeters.
199 * Note that on many X servers this value will not be correct.
201 * Return value: the width of the default screen in millimeters,
202 * though it is not always correct.
205 gdk_screen_width_mm (void)
207 return gdk_screen_get_width_mm (gdk_screen_get_default());
211 * gdk_screen_height_mm:
213 * Returns the height of the default screen in millimeters.
214 * Note that on many X servers this value will not be correct.
216 * Return value: the height of the default screen in millimeters,
217 * though it is not always correct.
220 gdk_screen_height_mm (void)
222 return gdk_screen_get_height_mm (gdk_screen_get_default ());