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, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "config.h"
23 
24 #include "gdkscreenprivate.h"
25 
26 #include "gdkinternals.h"
27 #include "gdkmonitorprivate.h"
28 #include "gdkrectangle.h"
29 #include "gdkwindow.h"
30 #include "gdkintl.h"
31 
32 
33 /**
34  * SECTION:gdkscreen
35  * @Short_description: Object representing a physical screen
36  * @Title: GdkScreen
37  *
38  * #GdkScreen objects are the GDK representation of the screen on
39  * which windows can be displayed and on which the pointer moves.
40  * X originally identified screens with physical screens, but
41  * nowadays it is more common to have a single #GdkScreen which
42  * combines several physical monitors (see gdk_screen_get_n_monitors()).
43  *
44  * GdkScreen is used throughout GDK and GTK+ to specify which screen
45  * the top level windows are to be displayed on. it is also used to
46  * query the screen specification and default settings such as
47  * the default visual (gdk_screen_get_system_visual()), the dimensions
48  * of the physical monitors (gdk_screen_get_monitor_geometry()), etc.
49  */
50 
51 
52 static void gdk_screen_finalize     (GObject        *object);
53 static void gdk_screen_set_property (GObject        *object,
54 				     guint           prop_id,
55 				     const GValue   *value,
56 				     GParamSpec     *pspec);
57 static void gdk_screen_get_property (GObject        *object,
58 				     guint           prop_id,
59 				     GValue         *value,
60 				     GParamSpec     *pspec);
61 
62 enum
63 {
64   PROP_0,
65   PROP_FONT_OPTIONS,
66   PROP_RESOLUTION
67 };
68 
69 enum
70 {
71   SIZE_CHANGED,
72   COMPOSITED_CHANGED,
73   MONITORS_CHANGED,
74   LAST_SIGNAL
75 };
76 
77 static guint signals[LAST_SIGNAL] = { 0 };
78 
G_DEFINE_TYPE(GdkScreen,gdk_screen,G_TYPE_OBJECT)79 G_DEFINE_TYPE (GdkScreen, gdk_screen, G_TYPE_OBJECT)
80 
81 static void
82 gdk_screen_class_init (GdkScreenClass *klass)
83 {
84   GObjectClass *object_class = G_OBJECT_CLASS (klass);
85 
86   object_class->finalize = gdk_screen_finalize;
87   object_class->set_property = gdk_screen_set_property;
88   object_class->get_property = gdk_screen_get_property;
89 
90   g_object_class_install_property (object_class,
91 				   PROP_FONT_OPTIONS,
92 				   g_param_spec_pointer ("font-options",
93 							 P_("Font options"),
94 							 P_("The default font options for the screen"),
95 							 G_PARAM_READWRITE|G_PARAM_STATIC_NAME|
96 							G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
97 
98   g_object_class_install_property (object_class,
99 				   PROP_RESOLUTION,
100 				   g_param_spec_double ("resolution",
101 							P_("Font resolution"),
102 							P_("The resolution for fonts on the screen"),
103 							-1.0,
104 							10000.0,
105 							-1.0,
106 							G_PARAM_READWRITE|G_PARAM_STATIC_NAME|
107 							G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
108 
109   /**
110    * GdkScreen::size-changed:
111    * @screen: the object on which the signal is emitted
112    *
113    * The ::size-changed signal is emitted when the pixel width or
114    * height of a screen changes.
115    *
116    * Since: 2.2
117    */
118   signals[SIZE_CHANGED] =
119     g_signal_new (g_intern_static_string ("size-changed"),
120                   G_OBJECT_CLASS_TYPE (klass),
121                   G_SIGNAL_RUN_LAST,
122                   G_STRUCT_OFFSET (GdkScreenClass, size_changed),
123                   NULL, NULL,
124                   NULL,
125                   G_TYPE_NONE,
126                   0);
127 
128   /**
129    * GdkScreen::composited-changed:
130    * @screen: the object on which the signal is emitted
131    *
132    * The ::composited-changed signal is emitted when the composited
133    * status of the screen changes
134    *
135    * Since: 2.10
136    */
137   signals[COMPOSITED_CHANGED] =
138     g_signal_new (g_intern_static_string ("composited-changed"),
139 		  G_OBJECT_CLASS_TYPE (klass),
140 		  G_SIGNAL_RUN_LAST,
141 		  G_STRUCT_OFFSET (GdkScreenClass, composited_changed),
142 		  NULL, NULL,
143 		  NULL,
144 		  G_TYPE_NONE,
145 		  0);
146 
147   /**
148    * GdkScreen::monitors-changed:
149    * @screen: the object on which the signal is emitted
150    *
151    * The ::monitors-changed signal is emitted when the number, size
152    * or position of the monitors attached to the screen change.
153    *
154    * Only for X11 and OS X for now. A future implementation for Win32
155    * may be a possibility.
156    *
157    * Since: 2.14
158    */
159   signals[MONITORS_CHANGED] =
160     g_signal_new (g_intern_static_string ("monitors-changed"),
161 		  G_OBJECT_CLASS_TYPE (klass),
162 		  G_SIGNAL_RUN_LAST,
163 		  G_STRUCT_OFFSET (GdkScreenClass, monitors_changed),
164 		  NULL, NULL,
165 		  NULL,
166 		  G_TYPE_NONE,
167 		  0);
168 }
169 
170 static void
gdk_screen_init(GdkScreen * screen)171 gdk_screen_init (GdkScreen *screen)
172 {
173   screen->resolution = -1.;
174 }
175 
176 static void
gdk_screen_finalize(GObject * object)177 gdk_screen_finalize (GObject *object)
178 {
179   GdkScreen *screen = GDK_SCREEN (object);
180 
181   if (screen->font_options)
182       cairo_font_options_destroy (screen->font_options);
183 
184   G_OBJECT_CLASS (gdk_screen_parent_class)->finalize (object);
185 }
186 
187 void
_gdk_screen_close(GdkScreen * screen)188 _gdk_screen_close (GdkScreen *screen)
189 {
190   g_return_if_fail (GDK_IS_SCREEN (screen));
191 
192   if (!screen->closed)
193     {
194       screen->closed = TRUE;
195       g_object_run_dispose (G_OBJECT (screen));
196     }
197 }
198 
199 static int
get_monitor_num(GdkMonitor * monitor)200 get_monitor_num (GdkMonitor *monitor)
201 {
202   GdkDisplay *display;
203   int n_monitors, i;
204 
205   display = gdk_monitor_get_display (monitor);
206   n_monitors = gdk_display_get_n_monitors (display);
207   for (i = 0; i < n_monitors; i++)
208     {
209       if (gdk_display_get_monitor (display, i) == monitor)
210         return i;
211     }
212   return -1;
213 }
214 
215 /**
216  * gdk_screen_get_monitor_at_point:
217  * @screen: a #GdkScreen.
218  * @x: the x coordinate in the virtual screen.
219  * @y: the y coordinate in the virtual screen.
220  *
221  * Returns the monitor number in which the point (@x,@y) is located.
222  *
223  * Returns: the monitor number in which the point (@x,@y) lies, or
224  *   a monitor close to (@x,@y) if the point is not in any monitor.
225  *
226  * Since: 2.2
227  *
228  * Deprecated: 3.22: Use gdk_display_get_monitor_at_point() instead
229  **/
230 gint
gdk_screen_get_monitor_at_point(GdkScreen * screen,gint x,gint y)231 gdk_screen_get_monitor_at_point (GdkScreen *screen,
232 				 gint       x,
233 				 gint       y)
234 {
235   GdkDisplay *display;
236   GdkMonitor *monitor;
237 
238   g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
239 
240   display = gdk_screen_get_display (screen);
241   monitor = gdk_display_get_monitor_at_point (display, x, y);
242   return get_monitor_num (monitor);
243 }
244 
245 /**
246  * gdk_screen_get_monitor_at_window:
247  * @screen: a #GdkScreen.
248  * @window: a #GdkWindow
249  *
250  * Returns the number of the monitor in which the largest area of the
251  * bounding rectangle of @window resides.
252  *
253  * Returns: the monitor number in which most of @window is located,
254  *     or if @window does not intersect any monitors, a monitor,
255  *     close to @window.
256  *
257  * Since: 2.2
258  *
259  * Deprecated: 3.22: Use gdk_display_get_monitor_at_window() instead
260  **/
261 gint
gdk_screen_get_monitor_at_window(GdkScreen * screen,GdkWindow * window)262 gdk_screen_get_monitor_at_window (GdkScreen *screen,
263                                   GdkWindow *window)
264 {
265   GdkDisplay *display;
266   GdkMonitor *monitor;
267 
268   g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
269   g_return_val_if_fail (GDK_IS_WINDOW (window), -1);
270 
271   display = gdk_screen_get_display (screen);
272   monitor = gdk_display_get_monitor_at_window (display, window);
273   return get_monitor_num (monitor);
274 }
275 
276 /**
277  * gdk_screen_width:
278  *
279  * Gets the width of the default screen in pixels. The returned
280  * size is in ”application pixels”, not in ”device pixels” (see
281  * gdk_screen_get_monitor_scale_factor()).
282  *
283  * Returns: the width of the default screen in pixels.
284  *
285  * Deprecated: 3.22: Use per-monitor information
286  **/
287 gint
gdk_screen_width(void)288 gdk_screen_width (void)
289 {
290 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
291   return gdk_screen_get_width (gdk_screen_get_default ());
292 G_GNUC_END_IGNORE_DEPRECATIONS
293 }
294 
295 /**
296  * gdk_screen_height:
297  *
298  * Gets the height of the default screen in pixels. The returned
299  * size is in ”application pixels”, not in ”device pixels” (see
300  * gdk_screen_get_monitor_scale_factor()).
301  *
302  * Returns: the height of the default screen in pixels.
303  *
304  * Deprecated: 3.22: Use per-monitor information
305  **/
306 gint
gdk_screen_height(void)307 gdk_screen_height (void)
308 {
309 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
310   return gdk_screen_get_height (gdk_screen_get_default ());
311 G_GNUC_END_IGNORE_DEPRECATIONS
312 }
313 
314 /**
315  * gdk_screen_width_mm:
316  *
317  * Returns the width of the default screen in millimeters.
318  * Note that on many X servers this value will not be correct.
319  *
320  * Returns: the width of the default screen in millimeters,
321  * though it is not always correct.
322  *
323  * Deprecated: 3.22: Use per-monitor information
324  **/
325 gint
gdk_screen_width_mm(void)326 gdk_screen_width_mm (void)
327 {
328 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
329   return gdk_screen_get_width_mm (gdk_screen_get_default ());
330 G_GNUC_END_IGNORE_DEPRECATIONS
331 }
332 
333 /**
334  * gdk_screen_height_mm:
335  *
336  * Returns the height of the default screen in millimeters.
337  * Note that on many X servers this value will not be correct.
338  *
339  * Returns: the height of the default screen in millimeters,
340  * though it is not always correct.
341  *
342  * Deprecated: 3.22: Use per-monitor information
343  **/
344 gint
gdk_screen_height_mm(void)345 gdk_screen_height_mm (void)
346 {
347 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
348   return gdk_screen_get_height_mm (gdk_screen_get_default ());
349 G_GNUC_END_IGNORE_DEPRECATIONS
350 }
351 
352 /**
353  * gdk_screen_set_font_options:
354  * @screen: a #GdkScreen
355  * @options: (allow-none): a #cairo_font_options_t, or %NULL to unset any
356  *   previously set default font options.
357  *
358  * Sets the default font options for the screen. These
359  * options will be set on any #PangoContext’s newly created
360  * with gdk_pango_context_get_for_screen(). Changing the
361  * default set of font options does not affect contexts that
362  * have already been created.
363  *
364  * Since: 2.10
365  **/
366 void
gdk_screen_set_font_options(GdkScreen * screen,const cairo_font_options_t * options)367 gdk_screen_set_font_options (GdkScreen                  *screen,
368 			     const cairo_font_options_t *options)
369 {
370   g_return_if_fail (GDK_IS_SCREEN (screen));
371 
372   if (screen->font_options != options)
373     {
374       if (screen->font_options)
375         cairo_font_options_destroy (screen->font_options);
376 
377       if (options)
378         screen->font_options = cairo_font_options_copy (options);
379       else
380         screen->font_options = NULL;
381 
382       g_object_notify (G_OBJECT (screen), "font-options");
383     }
384 }
385 
386 /**
387  * gdk_screen_get_font_options:
388  * @screen: a #GdkScreen
389  *
390  * Gets any options previously set with gdk_screen_set_font_options().
391  *
392  * Returns: (nullable): the current font options, or %NULL if no
393  *  default font options have been set.
394  *
395  * Since: 2.10
396  **/
397 const cairo_font_options_t *
gdk_screen_get_font_options(GdkScreen * screen)398 gdk_screen_get_font_options (GdkScreen *screen)
399 {
400   g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
401 
402   return screen->font_options;
403 }
404 
405 /**
406  * gdk_screen_set_resolution:
407  * @screen: a #GdkScreen
408  * @dpi: the resolution in “dots per inch”. (Physical inches aren’t actually
409  *   involved; the terminology is conventional.)
410 
411  * Sets the resolution for font handling on the screen. This is a
412  * scale factor between points specified in a #PangoFontDescription
413  * and cairo units. The default value is 96, meaning that a 10 point
414  * font will be 13 units high. (10 * 96. / 72. = 13.3).
415  *
416  * Since: 2.10
417  **/
418 void
gdk_screen_set_resolution(GdkScreen * screen,gdouble dpi)419 gdk_screen_set_resolution (GdkScreen *screen,
420 			   gdouble    dpi)
421 {
422   g_return_if_fail (GDK_IS_SCREEN (screen));
423 
424   if (dpi < 0)
425     dpi = -1.0;
426 
427   screen->resolution_set = TRUE;
428 
429   if (screen->resolution != dpi)
430     {
431       screen->resolution = dpi;
432 
433       g_object_notify (G_OBJECT (screen), "resolution");
434     }
435 }
436 
437 /* Just like gdk_screen_set_resolution(), but doesn't change
438  * screen->resolution. This is us to allow us to distinguish
439  * resolution changes that the backend picks up from resolution
440  * changes made through the public API - perhaps using
441  * g_object_set(<GtkSetting>, "gtk-xft-dpi", ...);
442  */
443 void
_gdk_screen_set_resolution(GdkScreen * screen,gdouble dpi)444 _gdk_screen_set_resolution (GdkScreen *screen,
445                             gdouble    dpi)
446 {
447   g_return_if_fail (GDK_IS_SCREEN (screen));
448 
449   if (dpi < 0)
450     dpi = -1.0;
451 
452   if (screen->resolution != dpi)
453     {
454       screen->resolution = dpi;
455 
456       g_object_notify (G_OBJECT (screen), "resolution");
457     }
458 }
459 
460 /**
461  * gdk_screen_get_resolution:
462  * @screen: a #GdkScreen
463  *
464  * Gets the resolution for font handling on the screen; see
465  * gdk_screen_set_resolution() for full details.
466  *
467  * Returns: the current resolution, or -1 if no resolution
468  * has been set.
469  *
470  * Since: 2.10
471  **/
472 gdouble
gdk_screen_get_resolution(GdkScreen * screen)473 gdk_screen_get_resolution (GdkScreen *screen)
474 {
475   g_return_val_if_fail (GDK_IS_SCREEN (screen), -1.0);
476 
477   return screen->resolution;
478 }
479 
480 static void
gdk_screen_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)481 gdk_screen_get_property (GObject      *object,
482 			 guint         prop_id,
483 			 GValue       *value,
484 			 GParamSpec   *pspec)
485 {
486   GdkScreen *screen = GDK_SCREEN (object);
487 
488   switch (prop_id)
489     {
490     case PROP_FONT_OPTIONS:
491       g_value_set_pointer (value, (gpointer) gdk_screen_get_font_options (screen));
492       break;
493     case PROP_RESOLUTION:
494       g_value_set_double (value, gdk_screen_get_resolution (screen));
495       break;
496     default:
497       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
498       break;
499     }
500 }
501 
502 static void
gdk_screen_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)503 gdk_screen_set_property (GObject      *object,
504 			 guint         prop_id,
505 			 const GValue *value,
506 			 GParamSpec   *pspec)
507 {
508   GdkScreen *screen = GDK_SCREEN (object);
509 
510   switch (prop_id)
511     {
512     case PROP_FONT_OPTIONS:
513       gdk_screen_set_font_options (screen, g_value_get_pointer (value));
514       break;
515     case PROP_RESOLUTION:
516       gdk_screen_set_resolution (screen, g_value_get_double (value));
517       break;
518     default:
519       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
520       break;
521     }
522 }
523 
524 /**
525  * gdk_screen_get_display:
526  * @screen: a #GdkScreen
527  *
528  * Gets the display to which the @screen belongs.
529  *
530  * Returns: (transfer none): the display to which @screen belongs
531  *
532  * Since: 2.2
533  **/
534 GdkDisplay *
gdk_screen_get_display(GdkScreen * screen)535 gdk_screen_get_display (GdkScreen *screen)
536 {
537   g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
538 
539   return GDK_SCREEN_GET_CLASS (screen)->get_display (screen);
540 }
541 
542 
543 /**
544  * gdk_screen_get_width:
545  * @screen: a #GdkScreen
546  *
547  * Gets the width of @screen in pixels. The returned size is in
548  * ”application pixels”, not in ”device pixels” (see
549  * gdk_screen_get_monitor_scale_factor()).
550  *
551  * Returns: the width of @screen in pixels.
552  *
553  * Since: 2.2
554  *
555  * Deprecated: 3.22: Use per-monitor information instead
556  **/
557 gint
gdk_screen_get_width(GdkScreen * screen)558 gdk_screen_get_width (GdkScreen *screen)
559 {
560   g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
561 
562   return GDK_SCREEN_GET_CLASS (screen)->get_width (screen);
563 }
564 
565 /**
566  * gdk_screen_get_height:
567  * @screen: a #GdkScreen
568  *
569  * Gets the height of @screen in pixels. The returned size is in
570  * ”application pixels”, not in ”device pixels” (see
571  * gdk_screen_get_monitor_scale_factor()).
572  *
573  * Returns: the height of @screen in pixels.
574  *
575  * Since: 2.2
576  *
577  * Deprecated: 3.22: Use per-monitor information instead
578  **/
579 gint
gdk_screen_get_height(GdkScreen * screen)580 gdk_screen_get_height (GdkScreen *screen)
581 {
582   g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
583 
584   return GDK_SCREEN_GET_CLASS (screen)->get_height (screen);
585 }
586 
587 /**
588  * gdk_screen_get_width_mm:
589  * @screen: a #GdkScreen
590  *
591  * Gets the width of @screen in millimeters.
592  *
593  * Note that this value is somewhat ill-defined when the screen
594  * has multiple monitors of different resolution. It is recommended
595  * to use the monitor dimensions instead.
596  *
597  * Returns: the width of @screen in millimeters.
598  *
599  * Since: 2.2
600  *
601  * Deprecated: 3.22: Use per-monitor information instead
602  **/
603 gint
gdk_screen_get_width_mm(GdkScreen * screen)604 gdk_screen_get_width_mm (GdkScreen *screen)
605 {
606   g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
607 
608   return GDK_SCREEN_GET_CLASS (screen)->get_width_mm (screen);
609 }
610 
611 /**
612  * gdk_screen_get_height_mm:
613  * @screen: a #GdkScreen
614  *
615  * Returns the height of @screen in millimeters.
616  *
617  * Note that this value is somewhat ill-defined when the screen
618  * has multiple monitors of different resolution. It is recommended
619  * to use the monitor dimensions instead.
620  *
621  * Returns: the heigth of @screen in millimeters.
622  *
623  * Deprecated: 3.22: Use per-monitor information instead
624  *
625  * Since: 2.2
626  **/
627 gint
gdk_screen_get_height_mm(GdkScreen * screen)628 gdk_screen_get_height_mm (GdkScreen *screen)
629 {
630   g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
631 
632   return GDK_SCREEN_GET_CLASS (screen)->get_height_mm (screen);
633 }
634 
635 /**
636  * gdk_screen_get_number:
637  * @screen: a #GdkScreen
638  *
639  * Gets the index of @screen among the screens in the display
640  * to which it belongs. (See gdk_screen_get_display())
641  *
642  * Returns: the index
643  *
644  * Since: 2.2
645  *
646  * Deprecated: 3.22
647  **/
648 gint
gdk_screen_get_number(GdkScreen * screen)649 gdk_screen_get_number (GdkScreen *screen)
650 {
651   g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
652 
653   return GDK_SCREEN_GET_CLASS (screen)->get_number (screen);
654 }
655 
656 /**
657  * gdk_screen_get_root_window:
658  * @screen: a #GdkScreen
659  *
660  * Gets the root window of @screen.
661  *
662  * Returns: (transfer none): the root window
663  *
664  * Since: 2.2
665  **/
666 GdkWindow *
gdk_screen_get_root_window(GdkScreen * screen)667 gdk_screen_get_root_window (GdkScreen *screen)
668 {
669   g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
670 
671   return GDK_SCREEN_GET_CLASS (screen)->get_root_window (screen);
672 }
673 
674 static GdkMonitor *
get_monitor(GdkScreen * screen,gint n)675 get_monitor (GdkScreen *screen,
676              gint       n)
677 {
678   GdkDisplay *display;
679 
680   display = gdk_screen_get_display (screen);
681   return gdk_display_get_monitor (display, n);
682 }
683 
684 /**
685  * gdk_screen_get_n_monitors:
686  * @screen: a #GdkScreen
687  *
688  * Returns the number of monitors which @screen consists of.
689  *
690  * Returns: number of monitors which @screen consists of
691  *
692  * Since: 2.2
693  *
694  * Deprecated: 3.22: Use gdk_display_get_n_monitors() instead
695  */
696 gint
gdk_screen_get_n_monitors(GdkScreen * screen)697 gdk_screen_get_n_monitors (GdkScreen *screen)
698 {
699   GdkDisplay *display;
700 
701   g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
702 
703   display = gdk_screen_get_display (screen);
704   return gdk_display_get_n_monitors (display);
705 }
706 
707 /**
708  * gdk_screen_get_primary_monitor:
709  * @screen: a #GdkScreen.
710  *
711  * Gets the primary monitor for @screen.  The primary monitor
712  * is considered the monitor where the “main desktop” lives.
713  * While normal application windows typically allow the window
714  * manager to place the windows, specialized desktop applications
715  * such as panels should place themselves on the primary monitor.
716  *
717  * If no primary monitor is configured by the user, the return value
718  * will be 0, defaulting to the first monitor.
719  *
720  * Returns: An integer index for the primary monitor, or 0 if none is configured.
721  *
722  * Since: 2.20
723  *
724  * Deprecated: 3.22: Use gdk_display_get_primary_monitor() instead
725  */
726 gint
gdk_screen_get_primary_monitor(GdkScreen * screen)727 gdk_screen_get_primary_monitor (GdkScreen *screen)
728 {
729   GdkDisplay *display;
730   GdkMonitor *primary;
731 
732   g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
733 
734   display = gdk_screen_get_display (screen);
735   primary = gdk_display_get_primary_monitor (display);
736   if (primary)
737     return get_monitor_num (primary);
738 
739   return 0;
740 }
741 
742 /**
743  * gdk_screen_get_monitor_width_mm:
744  * @screen: a #GdkScreen
745  * @monitor_num: number of the monitor, between 0 and gdk_screen_get_n_monitors (screen)
746  *
747  * Gets the width in millimeters of the specified monitor, if available.
748  *
749  * Returns: the width of the monitor, or -1 if not available
750  *
751  * Since: 2.14
752  *
753  * Deprecated: 3.22: Use gdk_monitor_get_width_mm() instead
754  */
755 gint
gdk_screen_get_monitor_width_mm(GdkScreen * screen,gint monitor_num)756 gdk_screen_get_monitor_width_mm	(GdkScreen *screen,
757 				 gint       monitor_num)
758 {
759   GdkMonitor *monitor;
760 
761   g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
762 
763   monitor = get_monitor (screen, monitor_num);
764 
765   g_return_val_if_fail (monitor != NULL, -1);
766 
767   return gdk_monitor_get_width_mm (monitor);
768 }
769 
770 /**
771  * gdk_screen_get_monitor_height_mm:
772  * @screen: a #GdkScreen
773  * @monitor_num: number of the monitor, between 0 and gdk_screen_get_n_monitors (screen)
774  *
775  * Gets the height in millimeters of the specified monitor.
776  *
777  * Returns: the height of the monitor, or -1 if not available
778  *
779  * Since: 2.14
780  *
781  * Deprecated: 3.22: Use gdk_monitor_get_height_mm() instead
782  */
783 gint
gdk_screen_get_monitor_height_mm(GdkScreen * screen,gint monitor_num)784 gdk_screen_get_monitor_height_mm (GdkScreen *screen,
785                                   gint       monitor_num)
786 {
787   GdkMonitor *monitor;
788 
789   g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
790 
791   monitor = get_monitor (screen, monitor_num);
792 
793   g_return_val_if_fail (monitor != NULL, -1);
794 
795   return gdk_monitor_get_height_mm (monitor);
796 }
797 
798 /**
799  * gdk_screen_get_monitor_plug_name:
800  * @screen: a #GdkScreen
801  * @monitor_num: number of the monitor, between 0 and gdk_screen_get_n_monitors (screen)
802  *
803  * Returns the output name of the specified monitor.
804  * Usually something like VGA, DVI, or TV, not the actual
805  * product name of the display device.
806  *
807  * Returns: (nullable): a newly-allocated string containing the name
808  *   of the monitor, or %NULL if the name cannot be determined
809  *
810  * Since: 2.14
811  *
812  * Deprecated: 3.22: Use gdk_monitor_get_model() instead
813  */
814 gchar *
gdk_screen_get_monitor_plug_name(GdkScreen * screen,gint monitor_num)815 gdk_screen_get_monitor_plug_name (GdkScreen *screen,
816 				  gint       monitor_num)
817 {
818   GdkMonitor *monitor;
819 
820   g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
821 
822   monitor = get_monitor (screen, monitor_num);
823 
824   g_return_val_if_fail (monitor != NULL, NULL);
825 
826   return g_strdup (gdk_monitor_get_connector (monitor));
827 }
828 
829 /**
830  * gdk_screen_get_monitor_geometry:
831  * @screen: a #GdkScreen
832  * @monitor_num: the monitor number
833  * @dest: (out) (allow-none): a #GdkRectangle to be filled with
834  *     the monitor geometry
835  *
836  * Retrieves the #GdkRectangle representing the size and position of
837  * the individual monitor within the entire screen area. The returned
838  * geometry is in ”application pixels”, not in ”device pixels” (see
839  * gdk_screen_get_monitor_scale_factor()).
840  *
841  * Monitor numbers start at 0. To obtain the number of monitors of
842  * @screen, use gdk_screen_get_n_monitors().
843  *
844  * Note that the size of the entire screen area can be retrieved via
845  * gdk_screen_get_width() and gdk_screen_get_height().
846  *
847  * Since: 2.2
848  *
849  * Deprecated: 3.22: Use gdk_monitor_get_geometry() instead
850  */
851 void
gdk_screen_get_monitor_geometry(GdkScreen * screen,gint monitor_num,GdkRectangle * dest)852 gdk_screen_get_monitor_geometry (GdkScreen    *screen,
853 				 gint          monitor_num,
854 				 GdkRectangle *dest)
855 {
856   GdkMonitor *monitor;
857 
858   g_return_if_fail (GDK_IS_SCREEN (screen));
859 
860   monitor = get_monitor (screen, monitor_num);
861 
862   g_return_if_fail (monitor != NULL);
863 
864   gdk_monitor_get_geometry (monitor, dest);
865 }
866 
867 /**
868  * gdk_screen_get_monitor_workarea:
869  * @screen: a #GdkScreen
870  * @monitor_num: the monitor number
871  * @dest: (out) (allow-none): a #GdkRectangle to be filled with
872  *     the monitor workarea
873  *
874  * Retrieves the #GdkRectangle representing the size and position of
875  * the “work area” on a monitor within the entire screen area. The returned
876  * geometry is in ”application pixels”, not in ”device pixels” (see
877  * gdk_screen_get_monitor_scale_factor()).
878  *
879  * The work area should be considered when positioning menus and
880  * similar popups, to avoid placing them below panels, docks or other
881  * desktop components.
882  *
883  * Note that not all backends may have a concept of workarea. This
884  * function will return the monitor geometry if a workarea is not
885  * available, or does not apply.
886  *
887  * Monitor numbers start at 0. To obtain the number of monitors of
888  * @screen, use gdk_screen_get_n_monitors().
889  *
890  * Since: 3.4
891  *
892  * Deprecated: 3.22: Use gdk_monitor_get_workarea() instead
893  */
894 void
gdk_screen_get_monitor_workarea(GdkScreen * screen,gint monitor_num,GdkRectangle * dest)895 gdk_screen_get_monitor_workarea (GdkScreen    *screen,
896                                  gint          monitor_num,
897                                  GdkRectangle *dest)
898 {
899   GdkMonitor *monitor;
900 
901   g_return_if_fail (GDK_IS_SCREEN (screen));
902 
903   monitor = get_monitor (screen, monitor_num);
904 
905   g_return_if_fail (monitor != NULL);
906 
907   gdk_monitor_get_workarea (monitor, dest);
908 }
909 
910 /**
911  * gdk_screen_list_visuals:
912  * @screen: the relevant #GdkScreen.
913  *
914  * Lists the available visuals for the specified @screen.
915  * A visual describes a hardware image data format.
916  * For example, a visual might support 24-bit color, or 8-bit color,
917  * and might expect pixels to be in a certain format.
918  *
919  * Call g_list_free() on the return value when you’re finished with it.
920  *
921  * Returns: (transfer container) (element-type GdkVisual):
922  *     a list of visuals; the list must be freed, but not its contents
923  *
924  * Since: 2.2
925  **/
926 GList *
gdk_screen_list_visuals(GdkScreen * screen)927 gdk_screen_list_visuals (GdkScreen *screen)
928 {
929   g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
930 
931   return GDK_SCREEN_GET_CLASS (screen)->list_visuals (screen);
932 }
933 
934 /**
935  * gdk_screen_get_system_visual:
936  * @screen: a #GdkScreen.
937  *
938  * Get the system’s default visual for @screen.
939  * This is the visual for the root window of the display.
940  * The return value should not be freed.
941  *
942  * Returns: (transfer none): the system visual
943  *
944  * Since: 2.2
945  **/
946 GdkVisual *
gdk_screen_get_system_visual(GdkScreen * screen)947 gdk_screen_get_system_visual (GdkScreen * screen)
948 {
949   g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
950 
951   return GDK_SCREEN_GET_CLASS (screen)->get_system_visual (screen);
952 }
953 
954 /**
955  * gdk_screen_get_rgba_visual:
956  * @screen: a #GdkScreen
957  *
958  * Gets a visual to use for creating windows with an alpha channel.
959  * The windowing system on which GTK+ is running
960  * may not support this capability, in which case %NULL will
961  * be returned. Even if a non-%NULL value is returned, its
962  * possible that the window’s alpha channel won’t be honored
963  * when displaying the window on the screen: in particular, for
964  * X an appropriate windowing manager and compositing manager
965  * must be running to provide appropriate display.
966  *
967  * This functionality is not implemented in the Windows backend.
968  *
969  * For setting an overall opacity for a top-level window, see
970  * gdk_window_set_opacity().
971  *
972  * Returns: (nullable) (transfer none): a visual to use for windows
973  *     with an alpha channel or %NULL if the capability is not
974  *     available.
975  *
976  * Since: 2.8
977  **/
978 GdkVisual *
gdk_screen_get_rgba_visual(GdkScreen * screen)979 gdk_screen_get_rgba_visual (GdkScreen *screen)
980 {
981   g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
982 
983   return GDK_SCREEN_GET_CLASS (screen)->get_rgba_visual (screen);
984 }
985 
986 /**
987  * gdk_screen_is_composited:
988  * @screen: a #GdkScreen
989  *
990  * Returns whether windows with an RGBA visual can reasonably
991  * be expected to have their alpha channel drawn correctly on
992  * the screen.
993  *
994  * On X11 this function returns whether a compositing manager is
995  * compositing @screen.
996  *
997  * Returns: Whether windows with RGBA visuals can reasonably be
998  * expected to have their alpha channels drawn correctly on the screen.
999  *
1000  * Since: 2.10
1001  **/
1002 gboolean
gdk_screen_is_composited(GdkScreen * screen)1003 gdk_screen_is_composited (GdkScreen *screen)
1004 {
1005   g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
1006 
1007   return GDK_SCREEN_GET_CLASS (screen)->is_composited (screen);
1008 }
1009 
1010 /**
1011  * gdk_screen_make_display_name:
1012  * @screen: a #GdkScreen
1013  *
1014  * Determines the name to pass to gdk_display_open() to get
1015  * a #GdkDisplay with this screen as the default screen.
1016  *
1017  * Returns: a newly allocated string, free with g_free()
1018  *
1019  * Since: 2.2
1020  *
1021  * Deprecated: 3.22
1022  **/
1023 gchar *
gdk_screen_make_display_name(GdkScreen * screen)1024 gdk_screen_make_display_name (GdkScreen *screen)
1025 {
1026   g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
1027 
1028   return GDK_SCREEN_GET_CLASS (screen)->make_display_name (screen);
1029 }
1030 
1031 /**
1032  * gdk_screen_get_active_window:
1033  * @screen: a #GdkScreen
1034  *
1035  * Returns the screen’s currently active window.
1036  *
1037  * On X11, this is done by inspecting the _NET_ACTIVE_WINDOW property
1038  * on the root window, as described in the
1039  * [Extended Window Manager Hints](http://www.freedesktop.org/Standards/wm-spec).
1040  * If there is no currently currently active
1041  * window, or the window manager does not support the
1042  * _NET_ACTIVE_WINDOW hint, this function returns %NULL.
1043  *
1044  * On other platforms, this function may return %NULL, depending on whether
1045  * it is implementable on that platform.
1046  *
1047  * The returned window should be unrefed using g_object_unref() when
1048  * no longer needed.
1049  *
1050  * Returns: (nullable) (transfer full): the currently active window,
1051  *   or %NULL.
1052  *
1053  * Since: 2.10
1054  *
1055  * Deprecated: 3.22
1056  **/
1057 GdkWindow *
gdk_screen_get_active_window(GdkScreen * screen)1058 gdk_screen_get_active_window (GdkScreen *screen)
1059 {
1060   g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
1061 
1062   return GDK_SCREEN_GET_CLASS (screen)->get_active_window (screen);
1063 }
1064 
1065 /**
1066  * gdk_screen_get_window_stack:
1067  * @screen: a #GdkScreen
1068  *
1069  * Returns a #GList of #GdkWindows representing the current
1070  * window stack.
1071  *
1072  * On X11, this is done by inspecting the _NET_CLIENT_LIST_STACKING
1073  * property on the root window, as described in the
1074  * [Extended Window Manager Hints](http://www.freedesktop.org/Standards/wm-spec).
1075  * If the window manager does not support the
1076  * _NET_CLIENT_LIST_STACKING hint, this function returns %NULL.
1077  *
1078  * On other platforms, this function may return %NULL, depending on whether
1079  * it is implementable on that platform.
1080  *
1081  * The returned list is newly allocated and owns references to the
1082  * windows it contains, so it should be freed using g_list_free() and
1083  * its windows unrefed using g_object_unref() when no longer needed.
1084  *
1085  * Returns: (nullable) (transfer full) (element-type GdkWindow): a
1086  *     list of #GdkWindows for the current window stack, or %NULL.
1087  *
1088  * Since: 2.10
1089  **/
1090 GList *
gdk_screen_get_window_stack(GdkScreen * screen)1091 gdk_screen_get_window_stack (GdkScreen *screen)
1092 {
1093   g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
1094 
1095   return GDK_SCREEN_GET_CLASS (screen)->get_window_stack (screen);
1096 }
1097 
1098 /**
1099  * gdk_screen_get_setting:
1100  * @screen: the #GdkScreen where the setting is located
1101  * @name: the name of the setting
1102  * @value: location to store the value of the setting
1103  *
1104  * Retrieves a desktop-wide setting such as double-click time
1105  * for the #GdkScreen @screen.
1106  *
1107  * FIXME needs a list of valid settings here, or a link to
1108  * more information.
1109  *
1110  * Returns: %TRUE if the setting existed and a value was stored
1111  *   in @value, %FALSE otherwise.
1112  *
1113  * Since: 2.2
1114  **/
1115 gboolean
gdk_screen_get_setting(GdkScreen * screen,const gchar * name,GValue * value)1116 gdk_screen_get_setting (GdkScreen   *screen,
1117 			const gchar *name,
1118 			GValue      *value)
1119 {
1120   g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
1121   g_return_val_if_fail (name != NULL, FALSE);
1122   g_return_val_if_fail (value != NULL, FALSE);
1123 
1124   return GDK_SCREEN_GET_CLASS (screen)->get_setting (screen, name, value);
1125 }
1126 
1127 /**
1128  * gdk_screen_get_monitor_scale_factor:
1129  * @screen: screen to get scale factor for
1130  * @monitor_num: number of the monitor, between 0 and gdk_screen_get_n_monitors (screen)
1131  *
1132  * Returns the internal scale factor that maps from monitor coordinates
1133  * to the actual device pixels. On traditional systems this is 1, but
1134  * on very high density outputs this can be a higher value (often 2).
1135  *
1136  * This can be used if you want to create pixel based data for a
1137  * particular monitor, but most of the time you’re drawing to a window
1138  * where it is better to use gdk_window_get_scale_factor() instead.
1139  *
1140  * Returns: the scale factor
1141  *
1142  * Since: 3.10
1143  *
1144  * Deprecated: 3.22: Use gdk_monitor_get_scale_factor() instead
1145  */
1146 gint
gdk_screen_get_monitor_scale_factor(GdkScreen * screen,gint monitor_num)1147 gdk_screen_get_monitor_scale_factor (GdkScreen *screen,
1148                                      gint       monitor_num)
1149 {
1150   GdkMonitor *monitor;
1151 
1152   g_return_val_if_fail (GDK_IS_SCREEN (screen), 1);
1153   g_return_val_if_fail (monitor_num >= 0, 1);
1154 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
1155   g_return_val_if_fail (monitor_num < gdk_screen_get_n_monitors (screen), 1);
1156 G_GNUC_END_IGNORE_DEPRECATIONS
1157 
1158   monitor = get_monitor (screen, monitor_num);
1159 
1160   g_return_val_if_fail (monitor != NULL, 1);
1161 
1162   return gdk_monitor_get_scale_factor (monitor);
1163 }
1164