]> Pileus Git - ~andy/gtk/blob - gdk/gdkscreen.c
Document 2.2 API additions.
[~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  * Since: 2.2
105  **/
106 gint 
107 gdk_screen_get_monitor_at_point (GdkScreen *screen,
108                                  gint       x,
109                                  gint       y)
110 {
111   gint num_monitors, i;
112   
113   g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
114
115   num_monitors = gdk_screen_get_n_monitors (screen);
116   
117   for (i=0;i<num_monitors;i++)
118     {
119       GdkRectangle monitor;
120       
121       gdk_screen_get_monitor_geometry (screen, i, &monitor);
122
123       if (x >= monitor.x &&
124           x < monitor.x + monitor.width &&
125           y >= monitor.y &&
126           y < (monitor.y + monitor.height))
127         return i;
128     }
129
130   return -1;
131 }
132
133 /**
134  * gdk_screen_get_monitor_at_window:
135  * @screen: a #GdkScreen.
136  * @window: a #GdkWindow
137  * @returns: the monitor number in which most of @window is located.
138  *
139  * Returns the number of the monitor in which the largest area of the 
140  * bounding rectangle of @window resides. 
141  *
142  * Since: 2.2
143  **/
144 gint 
145 gdk_screen_get_monitor_at_window (GdkScreen      *screen,
146                                   GdkWindow      *window)
147 {
148   gint num_monitors, i, sum = 0, screen_num = 0;
149   GdkRectangle win_rect;
150   g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
151   
152   gdk_window_get_geometry (window, &win_rect.x, &win_rect.y, &win_rect.width,
153                            &win_rect.height, NULL);
154   gdk_window_get_origin (window, &win_rect.x, &win_rect.y);
155   num_monitors = gdk_screen_get_n_monitors (screen);
156   
157   for (i=0;i<num_monitors;i++)
158     {
159       GdkRectangle tmp_monitor, intersect;
160       
161       gdk_screen_get_monitor_geometry (screen, i, &tmp_monitor);
162       gdk_rectangle_intersect (&win_rect, &tmp_monitor, &intersect);
163       
164       if (intersect.width * intersect.height > sum)
165         { 
166           sum = intersect.width * intersect.height;
167           screen_num = i;
168         }
169     }
170   return screen_num;
171 }
172
173 /**
174  * gdk_screen_width:
175  * 
176  * Returns the width of the default screen in pixels.
177  * 
178  * Return value: the width of the default screen in pixels.
179  **/
180 gint
181 gdk_screen_width (void)
182 {
183   return gdk_screen_get_width (gdk_screen_get_default());
184 }
185
186 /**
187  * gdk_screen_height:
188  * 
189  * Returns the height of the default screen in pixels.
190  * 
191  * Return value: the height of the default screen in pixels.
192  **/
193 gint
194 gdk_screen_height (void)
195 {
196   return gdk_screen_get_height (gdk_screen_get_default());
197 }
198
199 /**
200  * gdk_screen_width_mm:
201  * 
202  * Returns the width of the default screen in millimeters.
203  * Note that on many X servers this value will not be correct.
204  * 
205  * Return value: the width of the default screen in millimeters,
206  * though it is not always correct.
207  **/
208 gint
209 gdk_screen_width_mm (void)
210 {
211   return gdk_screen_get_width_mm (gdk_screen_get_default());
212 }
213
214 /**
215  * gdk_screen_height_mm:
216  * 
217  * Returns the height of the default screen in millimeters.
218  * Note that on many X servers this value will not be correct.
219  * 
220  * Return value: the height of the default screen in millimeters,
221  * though it is not always correct.
222  **/
223 gint
224 gdk_screen_height_mm (void)
225 {
226   return gdk_screen_get_height_mm (gdk_screen_get_default ());
227 }