]> Pileus Git - ~andy/gtk/blob - gdk/gdkscreen.c
Doc updates.
[~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 "gdkscreen.h"
25 #include "gdkcolor.h"
26
27 GType
28 gdk_screen_get_type (void)
29 {
30   static GType object_type = 0;
31
32   if (!object_type)
33     {
34       static const GTypeInfo object_info =
35         {
36           sizeof (GdkScreenClass),
37           (GBaseInitFunc) NULL,
38           (GBaseFinalizeFunc) NULL,
39           NULL,                 /* class_init */
40           NULL,                 /* class_finalize */
41           NULL,                 /* class_data */
42           sizeof (GdkScreen),
43           0,                    /* n_preallocs */
44           (GInstanceInitFunc) NULL,
45         };
46       
47       object_type = g_type_register_static (G_TYPE_OBJECT,
48                                             "GdkScreen", &object_info, 0);
49     }
50
51   return object_type;
52 }
53
54 /**
55  * gdk_screen_get_default_colormap:
56  * @screen: a #GdkScreen
57  *
58  * Gets the default colormap for @screen.
59  * 
60  * Returns: the default #GdkColormap.
61  **/
62 GdkColormap *
63 gdk_screen_get_default_colormap (GdkScreen *screen)
64 {
65   g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
66   
67   return GDK_SCREEN_GET_CLASS (screen)->get_default_colormap (screen);
68 }
69
70 /**
71  * gdk_screen_set_default_colormap:
72  * @screen: a #GdkScreen
73  * @colormap: a #GdkColormap
74  *
75  * Sets the default @colormap for @screen.
76  **/
77 void
78 gdk_screen_set_default_colormap (GdkScreen   *screen,
79                                  GdkColormap *colormap)
80 {
81   g_return_if_fail (GDK_IS_SCREEN (screen));
82   g_return_if_fail (GDK_IS_COLORMAP (colormap));
83   
84   GDK_SCREEN_GET_CLASS (screen)->set_default_colormap (screen, colormap);
85 }
86
87 /**
88  * gdk_screen_get_root_window:
89  * @screen: a #GdkScreen
90  *
91  * Gets the root window of @screen. 
92  * 
93  * Returns: the root window
94  **/
95 GdkWindow *
96 gdk_screen_get_root_window (GdkScreen *screen)
97 {
98   g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
99   
100   return GDK_SCREEN_GET_CLASS (screen)->get_root_window (screen);
101 }
102
103 /**
104  * gdk_screen_get_display:
105  * @screen: a #GdkScreen
106  *
107  * Gets the display to which the @screen belongs.
108  * 
109  * Returns: the display to which @screen belongs
110  **/
111 GdkDisplay *
112 gdk_screen_get_display (GdkScreen *screen)
113 {
114   g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
115   
116   return GDK_SCREEN_GET_CLASS (screen)->get_display (screen);
117 }
118
119 /**
120  * gdk_screen_get_number:
121  * @screen: a #GdkScreen
122  *
123  * Gets the index of @screen among the screens in the display
124  * to which it belongs. (See gdk_screen_get_display())
125  * 
126  * Returns: the index
127  **/
128 gint
129 gdk_screen_get_number (GdkScreen *screen)
130 {
131   g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
132   
133   return GDK_SCREEN_GET_CLASS (screen)->get_screen_num (screen);
134 }
135
136 /**
137  * gdk_screen_get_window_at_pointer:
138  * @screen: a #GdkScreen
139  * @win_x: return location for origin of the window under the pointer
140  * @win_y: return location for origin of the window under the pointer
141  * 
142  * Obtains the window underneath the mouse pointer, returning the location
143  * of that window in @win_x, @win_y for @screen. Returns %NULL if the window 
144  * under the mouse pointer is not known to GDK (for example, belongs to
145  * another application).
146  * 
147  * Returns: the window under the mouse pointer, or %NULL
148  **/
149 GdkWindow *
150 gdk_screen_get_window_at_pointer (GdkScreen *screen,
151                                   gint      *win_x,
152                                   gint      *win_y)
153 {
154   g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
155   
156   return GDK_SCREEN_GET_CLASS (screen)->get_window_at_pointer (screen, win_x, win_y);
157 }
158
159 /**
160  * gdk_screen_get_width:
161  * @screen: a #GdkScreen
162  *
163  * Gets the width of @screen in pixels
164  * 
165  * Returns: the width of @screen in pixels.
166  **/
167 gint
168 gdk_screen_get_width (GdkScreen *screen)
169 {
170   g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
171   
172   return GDK_SCREEN_GET_CLASS (screen)->get_width (screen);
173 }
174
175 /**
176  * gdk_screen_get_height:
177  * @screen: a #GdkScreen
178  *
179  * Gets the height of @screen in pixels
180  * 
181  * Returns: the height of @screen in pixels.
182  **/
183 gint
184 gdk_screen_get_height (GdkScreen *screen)
185 {
186   g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
187   
188   return GDK_SCREEN_GET_CLASS (screen)->get_height (screen);
189 }
190
191 /**
192  * gdk_screen_get_width_mm:
193  * @screen: a #GdkScreen
194  *
195  * Gets the width of @screen in millimeters. 
196  * Note that on some X servers this value will not be correct.
197  * 
198  * Returns: the width of @screen in pixels.
199  **/
200 gint
201 gdk_screen_get_width_mm (GdkScreen *screen)
202 {
203   g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
204   
205   return GDK_SCREEN_GET_CLASS (screen)->get_width_mm (screen);
206 }
207
208 /**
209  * gdk_screen_get_height_mm:
210  * @screen: a #GdkScreen
211  *
212  * Returns the height of @screen in millimeters. 
213  * Note that on some X servers this value will not be correct.
214  * 
215  * Returns: the heigth of @screen in pixels.
216  **/
217 gint
218 gdk_screen_get_height_mm (GdkScreen *screen)
219 {
220   g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
221   
222   return GDK_SCREEN_GET_CLASS (screen)->get_height_mm (screen);
223 }
224
225 /**
226  * gdk_screen_close:
227  * @screen: a #GdkScreen
228  *
229  * Closes the @screen connection and cleanup its resources.
230  * Note that this function is called automatically by gdk_display_close().
231  **/
232 void 
233 gdk_screen_close (GdkScreen *screen)
234 {
235   g_return_if_fail (GDK_IS_SCREEN (screen));
236   
237   g_object_run_dispose (G_OBJECT (screen));
238 }
239
240 /**
241  * gdk_screen_get_n_monitors:
242  * @screen : a #GdkScreen.
243  *
244  * Returns the number of monitors being part of the virtual screen
245  *
246  * Returns: number of monitors part of the virtual screen or
247  *          0 if @screen is not in virtual screen mode.
248  **/
249 gint 
250 gdk_screen_get_n_monitors (GdkScreen *screen)
251 {
252   g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
253   
254   return GDK_SCREEN_GET_CLASS (screen)->get_n_monitors (screen);
255 }
256
257 /**
258  * gdk_screen_get_monitor_geometry:
259  * @screen : a #GdkScreen.
260  * @monitor_num: the monitor number. 
261  * @dest : a #GdkRectangle to be filled with the monitor geometry
262  *
263  * Retrieves the #GdkRectangle representing the size and start
264  * coordinates of the individual monitor within the the entire virtual
265  * screen.
266  * 
267  * Note that the virtual screen coordinates can be retrieved via 
268  * gdk_screen_get_width() and gdk_screen_get_height().
269  *
270  **/
271 void 
272 gdk_screen_get_monitor_geometry (GdkScreen    *screen,
273                                  gint          monitor_num,
274                                  GdkRectangle *dest)
275 {
276   g_return_if_fail (GDK_IS_SCREEN (screen));
277   
278   GDK_SCREEN_GET_CLASS (screen)->get_monitor_geometry (screen, monitor_num, dest);
279 }
280
281 /**
282  * gdk_screen_get_monitor_at_point:
283  * @screen : a #GdkScreen.
284  * @x : the x coordinate in the virtual screen.
285  * @y : the y coordinate in the virtual screen.
286  *
287  * Returns the monitor number in which the point (@x,@y) is located.
288  *
289  * Returns: the monitor number in which the point (@x,@y) belong, or
290  *   -1 if the point is not in any monitor.
291  **/
292 gint 
293 gdk_screen_get_monitor_at_point (GdkScreen *screen,
294                                  gint       x,
295                                  gint       y)
296 {
297   gint num_monitors, i;
298   
299   g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
300
301   num_monitors = gdk_screen_get_n_monitors (screen);
302   
303   for (i=0;i<num_monitors;i++)
304     {
305       GdkRectangle monitor;
306       
307       gdk_screen_get_monitor_geometry (screen, i, &monitor);
308
309       if (x >= monitor.x &&
310           x < monitor.x + monitor.width &&
311           y >= monitor.y &&
312           y < (monitor.y + monitor.height))
313         return i;
314     }
315
316   return -1;
317 }
318
319 /**
320  * gdk_screen_get_monitor_at_window:
321  * @screen: a #GdkScreen.
322  * @window: a #GdkWindow
323  * @returns: the monitor number in which most of @window is located.
324  *
325  * Returns the number of the monitor in which the largest area of the bounding rectangle
326  * of @window resides. 
327  **/
328 gint 
329 gdk_screen_get_monitor_at_window (GdkScreen      *screen,
330                                   GdkWindow      *window)
331 {
332   gint num_monitors, i, sum = 0, screen_num = 0;
333   GdkRectangle win_rect;
334   g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
335   
336   gdk_window_get_geometry (window, &win_rect.x, &win_rect.y, &win_rect.width,
337                            &win_rect.height, NULL);
338   gdk_window_get_origin (window, &win_rect.x, &win_rect.y);
339   num_monitors = gdk_screen_get_n_monitors (screen);
340   
341   for (i=0;i<num_monitors;i++)
342     {
343       GdkRectangle tmp_monitor, intersect;
344       
345       gdk_screen_get_monitor_geometry (screen, i, &tmp_monitor);
346       gdk_rectangle_intersect (&win_rect, &tmp_monitor, &intersect);
347       
348       if (intersect.width * intersect.height > sum)
349         { 
350           sum = intersect.width * intersect.height;
351           screen_num = i;
352         }
353     }
354   return screen_num;
355 }