]> Pileus Git - ~andy/gtk/blob - gdk/gdkscreen.c
Changes multihead reorganizing code for win32 support, mostly from a patch
[~andy/gtk] / gdk / gdkscreen.c
1 /*
2  * gdkscreen.c
3  * 
4  * Copyright 2001 Sun Microsystems Inc. 
5  *
6  * Erwann Chenede <erwann.chenede@sun.com>
7  *
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.
12  *
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.
17  *
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.
22  */
23
24 #include "gdk.h"                /* For gdk_rectangle_intersect() */
25 #include "gdkcolor.h"
26 #include "gdkinternals.h"
27 #include "gdkwindow.h"
28 #include "gdkscreen.h"
29
30 GType
31 gdk_screen_get_type (void)
32 {
33   static GType object_type = 0;
34
35   if (!object_type)
36     {
37       static const GTypeInfo object_info =
38         {
39           sizeof (GdkScreenClass),
40           (GBaseInitFunc) NULL,
41           (GBaseFinalizeFunc) NULL,
42           NULL,                 /* class_init */
43           NULL,                 /* class_finalize */
44           NULL,                 /* class_data */
45           sizeof (GdkScreen),
46           0,                    /* n_preallocs */
47           (GInstanceInitFunc) NULL,
48         };
49       
50       object_type = g_type_register_static (G_TYPE_OBJECT,
51                                             "GdkScreen", &object_info, 0);
52     }
53
54   return object_type;
55 }
56
57
58 /**
59  * gdk_screen_close:
60  * @screen: a #GdkScreen
61  *
62  * Closes the @screen connection and cleanup its resources.
63  * Note that this function is called automatically by gdk_display_close().
64  **/
65 void 
66 gdk_screen_close (GdkScreen *screen)
67 {
68   g_return_if_fail (GDK_IS_SCREEN (screen));
69   
70   g_object_run_dispose (G_OBJECT (screen));
71 }
72
73 /**
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.
78  *
79  * Returns the monitor number in which the point (@x,@y) is located.
80  *
81  * Returns: the monitor number in which the point (@x,@y) belong, or
82  *   -1 if the point is not in any monitor.
83  **/
84 gint 
85 gdk_screen_get_monitor_at_point (GdkScreen *screen,
86                                  gint       x,
87                                  gint       y)
88 {
89   gint num_monitors, i;
90   
91   g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
92
93   num_monitors = gdk_screen_get_n_monitors (screen);
94   
95   for (i=0;i<num_monitors;i++)
96     {
97       GdkRectangle monitor;
98       
99       gdk_screen_get_monitor_geometry (screen, i, &monitor);
100
101       if (x >= monitor.x &&
102           x < monitor.x + monitor.width &&
103           y >= monitor.y &&
104           y < (monitor.y + monitor.height))
105         return i;
106     }
107
108   return -1;
109 }
110
111 /**
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.
116  *
117  * Returns the number of the monitor in which the largest area of the bounding rectangle
118  * of @window resides. 
119  **/
120 gint 
121 gdk_screen_get_monitor_at_window (GdkScreen      *screen,
122                                   GdkWindow      *window)
123 {
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);
127   
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);
132   
133   for (i=0;i<num_monitors;i++)
134     {
135       GdkRectangle tmp_monitor, intersect;
136       
137       gdk_screen_get_monitor_geometry (screen, i, &tmp_monitor);
138       gdk_rectangle_intersect (&win_rect, &tmp_monitor, &intersect);
139       
140       if (intersect.width * intersect.height > sum)
141         { 
142           sum = intersect.width * intersect.height;
143           screen_num = i;
144         }
145     }
146   return screen_num;
147 }
148
149 /**
150  * gdk_screen_width:
151  * 
152  * Returns the width of the default screen in pixels.
153  * 
154  * Return value:  the width of the default screen in pixels.
155  **/
156 gint
157 gdk_screen_width (void)
158 {
159   return gdk_screen_get_width (gdk_get_default_screen());
160 }
161
162 /**
163  * gdk_screen_height:
164  * 
165  * Returns the height of the default screen in pixels.
166  * 
167  * Return value: the height of the default screen in pixels.
168  **/
169 gint
170 gdk_screen_height (void)
171 {
172   return gdk_screen_get_height (gdk_get_default_screen());
173 }
174
175 /**
176  * gdk_screen_width_mm:
177  * 
178  * Returns the width of the default screen in millimeters.
179  * Note that on many X servers this value will not be correct.
180  * 
181  * Return value: the width of the default screen in millimeters,
182  * though it is not always correct.
183  **/
184 gint
185 gdk_screen_width_mm (void)
186 {
187   return gdk_screen_get_width_mm (gdk_get_default_screen());
188 }
189
190 /**
191  * gdk_screen_height_mm:
192  * 
193  * Returns the height of the default screen in millimeters.
194  * Note that on many X servers this value will not be correct.
195  * 
196  * Return value: the height of the default screen in millimeters,
197  * though it is not always correct.
198  **/
199 gint
200 gdk_screen_height_mm (void)
201 {
202   return gdk_screen_get_height_mm (gdk_get_default_screen ());
203 }
204
205 /**
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
210  * 
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).
215  * 
216  * Returns: the window under the mouse pointer, or %NULL
217  **/
218 GdkWindow *
219 gdk_screen_get_window_at_pointer (GdkScreen *screen,
220                                   gint      *win_x,
221                                   gint      *win_y)
222 {
223   return _gdk_current_pointer_hooks->window_at_pointer (screen, win_x, win_y);
224 }