]> Pileus Git - ~andy/gtk/blob - gdk/gdkscreen.c
Start implementing display/screen closing scheme; keep a flag for whether
[~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 void 
58 _gdk_screen_close (GdkScreen *screen)
59 {
60   g_return_if_fail (GDK_IS_SCREEN (screen));
61
62   if (!screen->closed)
63     {
64       screen->closed = TRUE;
65       g_object_run_dispose (G_OBJECT (screen));
66     }
67 }
68
69 /**
70  * gdk_screen_get_monitor_at_point:
71  * @screen : a #GdkScreen.
72  * @x : the x coordinate in the virtual screen.
73  * @y : the y coordinate in the virtual screen.
74  *
75  * Returns the monitor number in which the point (@x,@y) is located.
76  *
77  * Returns: the monitor number in which the point (@x,@y) belong, or
78  *   -1 if the point is not in any monitor.
79  **/
80 gint 
81 gdk_screen_get_monitor_at_point (GdkScreen *screen,
82                                  gint       x,
83                                  gint       y)
84 {
85   gint num_monitors, i;
86   
87   g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
88
89   num_monitors = gdk_screen_get_n_monitors (screen);
90   
91   for (i=0;i<num_monitors;i++)
92     {
93       GdkRectangle monitor;
94       
95       gdk_screen_get_monitor_geometry (screen, i, &monitor);
96
97       if (x >= monitor.x &&
98           x < monitor.x + monitor.width &&
99           y >= monitor.y &&
100           y < (monitor.y + monitor.height))
101         return i;
102     }
103
104   return -1;
105 }
106
107 /**
108  * gdk_screen_get_monitor_at_window:
109  * @screen: a #GdkScreen.
110  * @window: a #GdkWindow
111  * @returns: the monitor number in which most of @window is located.
112  *
113  * Returns the number of the monitor in which the largest area of the bounding rectangle
114  * of @window resides. 
115  **/
116 gint 
117 gdk_screen_get_monitor_at_window (GdkScreen      *screen,
118                                   GdkWindow      *window)
119 {
120   gint num_monitors, i, sum = 0, screen_num = 0;
121   GdkRectangle win_rect;
122   g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
123   
124   gdk_window_get_geometry (window, &win_rect.x, &win_rect.y, &win_rect.width,
125                            &win_rect.height, NULL);
126   gdk_window_get_origin (window, &win_rect.x, &win_rect.y);
127   num_monitors = gdk_screen_get_n_monitors (screen);
128   
129   for (i=0;i<num_monitors;i++)
130     {
131       GdkRectangle tmp_monitor, intersect;
132       
133       gdk_screen_get_monitor_geometry (screen, i, &tmp_monitor);
134       gdk_rectangle_intersect (&win_rect, &tmp_monitor, &intersect);
135       
136       if (intersect.width * intersect.height > sum)
137         { 
138           sum = intersect.width * intersect.height;
139           screen_num = i;
140         }
141     }
142   return screen_num;
143 }
144
145 /**
146  * gdk_screen_width:
147  * 
148  * Returns the width of the default screen in pixels.
149  * 
150  * Return value:  the width of the default screen in pixels.
151  **/
152 gint
153 gdk_screen_width (void)
154 {
155   return gdk_screen_get_width (gdk_screen_get_default());
156 }
157
158 /**
159  * gdk_screen_height:
160  * 
161  * Returns the height of the default screen in pixels.
162  * 
163  * Return value: the height of the default screen in pixels.
164  **/
165 gint
166 gdk_screen_height (void)
167 {
168   return gdk_screen_get_height (gdk_screen_get_default());
169 }
170
171 /**
172  * gdk_screen_width_mm:
173  * 
174  * Returns the width of the default screen in millimeters.
175  * Note that on many X servers this value will not be correct.
176  * 
177  * Return value: the width of the default screen in millimeters,
178  * though it is not always correct.
179  **/
180 gint
181 gdk_screen_width_mm (void)
182 {
183   return gdk_screen_get_width_mm (gdk_screen_get_default());
184 }
185
186 /**
187  * gdk_screen_height_mm:
188  * 
189  * Returns the height of the default screen in millimeters.
190  * Note that on many X servers this value will not be correct.
191  * 
192  * Return value: the height of the default screen in millimeters,
193  * though it is not always correct.
194  **/
195 gint
196 gdk_screen_height_mm (void)
197 {
198   return gdk_screen_get_height_mm (gdk_screen_get_default ());
199 }
200
201 /**
202  * gdk_screen_get_window_at_pointer:
203  * @screen: a #GdkScreen
204  * @win_x: return location for origin of the window under the pointer
205  * @win_y: return location for origin of the window under the pointer
206  * 
207  * Obtains the window underneath the mouse pointer, returning the location
208  * of that window in @win_x, @win_y for @screen. Returns %NULL if the window 
209  * under the mouse pointer is not known to GDK (for example, belongs to
210  * another application).
211  * 
212  * Returns: the window under the mouse pointer, or %NULL
213  **/
214 GdkWindow *
215 gdk_screen_get_window_at_pointer (GdkScreen *screen,
216                                   gint      *win_x,
217                                   gint      *win_y)
218 {
219   return _gdk_current_pointer_hooks->window_at_pointer (screen, win_x, win_y);
220 }