]> Pileus Git - ~andy/gtk/blob - gdk/gdkscreen.c
564328ff758993385f34fa3c51ac55a19bec585c
[~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 static void         gdk_screen_class_init  (GdkScreenClass *klass);
31
32 enum
33 {
34   SIZE_CHANGED,
35   LAST_SIGNAL
36 };
37
38 static guint signals[LAST_SIGNAL] = { 0 };
39
40 GType
41 gdk_screen_get_type (void)
42 {
43   static GType object_type = 0;
44
45   if (!object_type)
46     {
47       static const GTypeInfo object_info =
48         {
49           sizeof (GdkScreenClass),
50           (GBaseInitFunc) NULL,
51           (GBaseFinalizeFunc) NULL,
52           (GClassInitFunc) gdk_screen_class_init,
53           NULL,                 /* class_finalize */
54           NULL,                 /* class_data */
55           sizeof (GdkScreen),
56           0,                    /* n_preallocs */
57           (GInstanceInitFunc) NULL,
58         };
59       
60       object_type = g_type_register_static (G_TYPE_OBJECT,
61                                             "GdkScreen", &object_info, 0);
62     }
63
64   return object_type;
65 }
66
67 static void
68 gdk_screen_class_init (GdkScreenClass *klass)
69 {
70   signals[SIZE_CHANGED] =
71     g_signal_new ("size_changed",
72                   G_OBJECT_CLASS_TYPE (klass),
73                   G_SIGNAL_RUN_LAST,
74                   G_STRUCT_OFFSET (GdkScreenClass, size_changed),
75                   NULL, NULL,
76                   g_cclosure_marshal_VOID__VOID,
77                   G_TYPE_NONE,
78                   0);
79 }
80
81 void 
82 _gdk_screen_close (GdkScreen *screen)
83 {
84   g_return_if_fail (GDK_IS_SCREEN (screen));
85
86   if (!screen->closed)
87     {
88       screen->closed = TRUE;
89       g_object_run_dispose (G_OBJECT (screen));
90     }
91 }
92
93 /**
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.
98  *
99  * Returns the monitor number in which the point (@x,@y) is located.
100  *
101  * Returns: the monitor number in which the point (@x,@y) belong, or
102  *   -1 if the point is not in any monitor.
103  **/
104 gint 
105 gdk_screen_get_monitor_at_point (GdkScreen *screen,
106                                  gint       x,
107                                  gint       y)
108 {
109   gint num_monitors, i;
110   
111   g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
112
113   num_monitors = gdk_screen_get_n_monitors (screen);
114   
115   for (i=0;i<num_monitors;i++)
116     {
117       GdkRectangle monitor;
118       
119       gdk_screen_get_monitor_geometry (screen, i, &monitor);
120
121       if (x >= monitor.x &&
122           x < monitor.x + monitor.width &&
123           y >= monitor.y &&
124           y < (monitor.y + monitor.height))
125         return i;
126     }
127
128   return -1;
129 }
130
131 /**
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.
136  *
137  * Returns the number of the monitor in which the largest area of the bounding rectangle
138  * of @window resides. 
139  **/
140 gint 
141 gdk_screen_get_monitor_at_window (GdkScreen      *screen,
142                                   GdkWindow      *window)
143 {
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);
147   
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);
152   
153   for (i=0;i<num_monitors;i++)
154     {
155       GdkRectangle tmp_monitor, intersect;
156       
157       gdk_screen_get_monitor_geometry (screen, i, &tmp_monitor);
158       gdk_rectangle_intersect (&win_rect, &tmp_monitor, &intersect);
159       
160       if (intersect.width * intersect.height > sum)
161         { 
162           sum = intersect.width * intersect.height;
163           screen_num = i;
164         }
165     }
166   return screen_num;
167 }
168
169 /**
170  * gdk_screen_width:
171  * 
172  * Returns the width of the default screen in pixels.
173  * 
174  * Return value:  the width of the default screen in pixels.
175  **/
176 gint
177 gdk_screen_width (void)
178 {
179   return gdk_screen_get_width (gdk_screen_get_default());
180 }
181
182 /**
183  * gdk_screen_height:
184  * 
185  * Returns the height of the default screen in pixels.
186  * 
187  * Return value: the height of the default screen in pixels.
188  **/
189 gint
190 gdk_screen_height (void)
191 {
192   return gdk_screen_get_height (gdk_screen_get_default());
193 }
194
195 /**
196  * gdk_screen_width_mm:
197  * 
198  * Returns the width of the default screen in millimeters.
199  * Note that on many X servers this value will not be correct.
200  * 
201  * Return value: the width of the default screen in millimeters,
202  * though it is not always correct.
203  **/
204 gint
205 gdk_screen_width_mm (void)
206 {
207   return gdk_screen_get_width_mm (gdk_screen_get_default());
208 }
209
210 /**
211  * gdk_screen_height_mm:
212  * 
213  * Returns the height of the default screen in millimeters.
214  * Note that on many X servers this value will not be correct.
215  * 
216  * Return value: the height of the default screen in millimeters,
217  * though it is not always correct.
218  **/
219 gint
220 gdk_screen_height_mm (void)
221 {
222   return gdk_screen_get_height_mm (gdk_screen_get_default ());
223 }