4 * Copyright 2001 Sun Microsystems Inc.
6 * Erwann Chenede <erwann.chenede@sun.com>
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.
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.
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.
30 #include "gdkscreen.h"
31 #include "gdkscreen-x11.h"
32 #include "gdkdisplay.h"
33 #include "gdkdisplay-x11.h"
37 #include <X11/Xatom.h>
39 #ifdef HAVE_SOLARIS_XINERAMA
40 #include <X11/extensions/xinerama.h>
42 #ifdef HAVE_XFREE_XINERAMA
43 #include <X11/extensions/Xinerama.h>
47 #include <X11/extensions/Xrandr.h>
51 #include <X11/extensions/Xfixes.h>
54 static void gdk_screen_x11_dispose (GObject *object);
55 static void gdk_screen_x11_finalize (GObject *object);
56 static void init_randr_support (GdkScreen *screen);
57 static void deinit_multihead (GdkScreen *screen);
61 WINDOW_MANAGER_CHANGED,
65 static guint signals[LAST_SIGNAL] = { 0 };
67 G_DEFINE_TYPE (GdkScreenX11, _gdk_screen_x11, GDK_TYPE_SCREEN)
71 GdkRectangle geometry;
80 _gdk_screen_x11_class_init (GdkScreenX11Class *klass)
82 GObjectClass *object_class = G_OBJECT_CLASS (klass);
84 object_class->dispose = gdk_screen_x11_dispose;
85 object_class->finalize = gdk_screen_x11_finalize;
87 signals[WINDOW_MANAGER_CHANGED] =
88 g_signal_new (g_intern_static_string ("window_manager_changed"),
89 G_OBJECT_CLASS_TYPE (object_class),
91 G_STRUCT_OFFSET (GdkScreenX11Class, window_manager_changed),
93 g_cclosure_marshal_VOID__VOID,
99 _gdk_screen_x11_init (GdkScreenX11 *screen)
104 * gdk_screen_get_display:
105 * @screen: a #GdkScreen
107 * Gets the display to which the @screen belongs.
109 * Returns: the display to which @screen belongs
114 gdk_screen_get_display (GdkScreen *screen)
116 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
118 return GDK_SCREEN_X11 (screen)->display;
121 * gdk_screen_get_width:
122 * @screen: a #GdkScreen
124 * Gets the width of @screen in pixels
126 * Returns: the width of @screen in pixels.
131 gdk_screen_get_width (GdkScreen *screen)
133 g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
135 return WidthOfScreen (GDK_SCREEN_X11 (screen)->xscreen);
139 * gdk_screen_get_height:
140 * @screen: a #GdkScreen
142 * Gets the height of @screen in pixels
144 * Returns: the height of @screen in pixels.
149 gdk_screen_get_height (GdkScreen *screen)
151 g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
153 return HeightOfScreen (GDK_SCREEN_X11 (screen)->xscreen);
157 * gdk_screen_get_width_mm:
158 * @screen: a #GdkScreen
160 * Gets the width of @screen in millimeters.
161 * Note that on some X servers this value will not be correct.
163 * Returns: the width of @screen in millimeters.
168 gdk_screen_get_width_mm (GdkScreen *screen)
170 g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
172 return WidthMMOfScreen (GDK_SCREEN_X11 (screen)->xscreen);
176 * gdk_screen_get_height_mm:
177 * @screen: a #GdkScreen
179 * Returns the height of @screen in millimeters.
180 * Note that on some X servers this value will not be correct.
182 * Returns: the heigth of @screen in millimeters.
187 gdk_screen_get_height_mm (GdkScreen *screen)
189 g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
191 return HeightMMOfScreen (GDK_SCREEN_X11 (screen)->xscreen);
195 * gdk_screen_get_number:
196 * @screen: a #GdkScreen
198 * Gets the index of @screen among the screens in the display
199 * to which it belongs. (See gdk_screen_get_display())
206 gdk_screen_get_number (GdkScreen *screen)
208 g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
210 return GDK_SCREEN_X11 (screen)->screen_num;
214 * gdk_screen_get_root_window:
215 * @screen: a #GdkScreen
217 * Gets the root window of @screen.
219 * Returns: the root window
224 gdk_screen_get_root_window (GdkScreen *screen)
226 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
228 return GDK_SCREEN_X11 (screen)->root_window;
232 * gdk_screen_get_default_colormap:
233 * @screen: a #GdkScreen
235 * Gets the default colormap for @screen.
237 * Returns: the default #GdkColormap.
242 gdk_screen_get_default_colormap (GdkScreen *screen)
244 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
246 return GDK_SCREEN_X11 (screen)->default_colormap;
250 * gdk_screen_set_default_colormap:
251 * @screen: a #GdkScreen
252 * @colormap: a #GdkColormap
254 * Sets the default @colormap for @screen.
259 gdk_screen_set_default_colormap (GdkScreen *screen,
260 GdkColormap *colormap)
262 GdkColormap *old_colormap;
264 g_return_if_fail (GDK_IS_SCREEN (screen));
265 g_return_if_fail (GDK_IS_COLORMAP (colormap));
267 old_colormap = GDK_SCREEN_X11 (screen)->default_colormap;
269 GDK_SCREEN_X11 (screen)->default_colormap = g_object_ref (colormap);
272 g_object_unref (old_colormap);
276 gdk_screen_x11_dispose (GObject *object)
278 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (object);
280 _gdk_x11_events_uninit_screen (GDK_SCREEN (object));
282 if (screen_x11->default_colormap)
284 g_object_unref (screen_x11->default_colormap);
285 screen_x11->default_colormap = NULL;
288 if (screen_x11->system_colormap)
290 g_object_unref (screen_x11->system_colormap);
291 screen_x11->system_colormap = NULL;
294 if (screen_x11->rgba_colormap)
296 g_object_unref (screen_x11->rgba_colormap);
297 screen_x11->rgba_colormap = NULL;
300 if (screen_x11->root_window)
301 _gdk_window_destroy (screen_x11->root_window, TRUE);
303 G_OBJECT_CLASS (_gdk_screen_x11_parent_class)->dispose (object);
305 screen_x11->xdisplay = NULL;
306 screen_x11->xscreen = NULL;
307 screen_x11->screen_num = -1;
308 screen_x11->xroot_window = None;
309 screen_x11->wmspec_check_window = None;
313 gdk_screen_x11_finalize (GObject *object)
315 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (object);
318 if (screen_x11->root_window)
319 g_object_unref (screen_x11->root_window);
321 if (screen_x11->renderer)
322 g_object_unref (screen_x11->renderer);
325 for (i = 0; i < screen_x11->nvisuals; i++)
326 g_object_unref (screen_x11->visuals[i]);
327 g_free (screen_x11->visuals);
328 g_hash_table_destroy (screen_x11->visual_hash);
330 g_free (screen_x11->window_manager_name);
332 g_hash_table_destroy (screen_x11->colormap_hash);
334 deinit_multihead (GDK_SCREEN (object));
336 G_OBJECT_CLASS (_gdk_screen_x11_parent_class)->finalize (object);
340 * gdk_screen_get_n_monitors:
341 * @screen: a #GdkScreen.
343 * Returns the number of monitors which @screen consists of.
345 * Returns: number of monitors which @screen consists of.
350 gdk_screen_get_n_monitors (GdkScreen *screen)
352 g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
354 return GDK_SCREEN_X11 (screen)->n_monitors;
357 static GdkX11Monitor *
358 get_monitor (GdkScreen *screen,
361 GdkScreenX11 *screen_x11;
363 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
365 screen_x11 = GDK_SCREEN_X11 (screen);
367 g_return_val_if_fail (monitor_num < screen_x11->n_monitors, NULL);
368 g_return_val_if_fail (monitor_num >= 0, NULL);
370 return &(screen_x11->monitors[monitor_num]);
374 * gdk_screen_get_monitor_width_mm:
375 * @screen: a #GdkScreen
376 * @monitor_num: number of the monitor
378 * Gets the width in millimeters of the specified monitor, if available.
380 * Returns the width of the monitor, or -1 if not available
385 gdk_screen_get_monitor_width_mm (GdkScreen *screen,
388 return get_monitor (screen, monitor_num)->width_mm;
392 * gdk_screen_get_monitor_height_mm:
393 * @screen: a #GdkScreen
394 * @monitor_num: number of the monitor
396 * Gets the height in millimeters of the specified monitor.
398 * Returns: the height of the monitor, or -1 if not available
403 gdk_screen_get_monitor_height_mm (GdkScreen *screen,
406 return get_monitor (screen, monitor_num)->height_mm;
410 * gdk_screen_get_monitor_plug_name:
411 * @screen: a #GdkScreen
412 * @monitor_num: number of the monitor
414 * Returns the output name of the specified monitor.
415 * Usually something like VGA, DVI, or TV, not the actual
416 * product name of the display device.
418 * Returns: a newly-allocated string containing the name of the monitor,
419 * or %NULL if the name cannot be determined
424 gdk_screen_get_monitor_plug_name (GdkScreen *screen,
427 return g_strdup (get_monitor (screen, monitor_num)->output_name);
431 * gdk_x11_screen_get_monitor_output:
432 * @screen: a #GdkScreen
433 * @monitor_num: number of the monitor
435 * Gets the XID of the specified output/monitor.
436 * If the X server does not support version 1.2 of the RANDR
437 * extension, 0 is returned.
439 * Returns: the XID of the monitor
444 gdk_x11_screen_get_monitor_output (GdkScreen *screen,
447 return get_monitor (screen, monitor_num)->output;
451 * gdk_screen_get_monitor_geometry:
452 * @screen : a #GdkScreen.
453 * @monitor_num: the monitor number.
454 * @dest : a #GdkRectangle to be filled with the monitor geometry
456 * Retrieves the #GdkRectangle representing the size and position of
457 * the individual monitor within the entire screen area.
459 * Note that the size of the entire screen area can be retrieved via
460 * gdk_screen_get_width() and gdk_screen_get_height().
465 gdk_screen_get_monitor_geometry (GdkScreen *screen,
471 GdkX11Monitor *monitor = get_monitor (screen, monitor_num);
473 *dest = monitor->geometry;
478 * gdk_screen_get_rgba_colormap:
479 * @screen: a #GdkScreen.
481 * Gets a colormap to use for creating windows or pixmaps with an
482 * alpha channel. The windowing system on which GTK+ is running
483 * may not support this capability, in which case %NULL will
484 * be returned. Even if a non-%NULL value is returned, its
485 * possible that the window's alpha channel won't be honored
486 * when displaying the window on the screen: in particular, for
487 * X an appropriate windowing manager and compositing manager
488 * must be running to provide appropriate display.
490 * This functionality is not implemented in the Windows backend.
492 * For setting an overall opacity for a top-level window, see
493 * gdk_window_set_opacity().
495 * Return value: a colormap to use for windows with an alpha channel
496 * or %NULL if the capability is not available.
501 gdk_screen_get_rgba_colormap (GdkScreen *screen)
503 GdkScreenX11 *screen_x11;
505 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
507 screen_x11 = GDK_SCREEN_X11 (screen);
509 if (!screen_x11->rgba_visual)
512 if (!screen_x11->rgba_colormap)
513 screen_x11->rgba_colormap = gdk_colormap_new (screen_x11->rgba_visual,
516 return screen_x11->rgba_colormap;
520 * gdk_screen_get_rgba_visual:
521 * @screen: a #GdkScreen
523 * Gets a visual to use for creating windows or pixmaps with an
524 * alpha channel. See the docs for gdk_screen_get_rgba_colormap()
527 * Return value: a visual to use for windows with an alpha channel
528 * or %NULL if the capability is not available.
533 gdk_screen_get_rgba_visual (GdkScreen *screen)
535 GdkScreenX11 *screen_x11;
537 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
539 screen_x11 = GDK_SCREEN_X11 (screen);
541 return screen_x11->rgba_visual;
545 * gdk_x11_screen_get_xscreen:
546 * @screen: a #GdkScreen.
547 * @returns: an Xlib <type>Screen*</type>
549 * Returns the screen of a #GdkScreen.
554 gdk_x11_screen_get_xscreen (GdkScreen *screen)
556 return GDK_SCREEN_X11 (screen)->xscreen;
560 * gdk_x11_screen_get_screen_number:
561 * @screen: a #GdkScreen.
562 * @returns: the position of @screen among the screens of
565 * Returns the index of a #GdkScreen.
570 gdk_x11_screen_get_screen_number (GdkScreen *screen)
572 return GDK_SCREEN_X11 (screen)->screen_num;
576 check_is_composited (GdkDisplay *display,
577 GdkScreenX11 *screen_x11)
579 Atom xselection = gdk_x11_atom_to_xatom_for_display (display, screen_x11->cm_selection_atom);
582 xwindow = XGetSelectionOwner (GDK_DISPLAY_XDISPLAY (display), xselection);
584 return xwindow != None;
588 make_cm_atom (int screen_number)
590 gchar *name = g_strdup_printf ("_NET_WM_CM_S%d", screen_number);
591 GdkAtom atom = gdk_atom_intern (name, FALSE);
597 init_monitor_geometry (GdkX11Monitor *monitor,
598 int x, int y, int width, int height)
600 monitor->geometry.x = x;
601 monitor->geometry.y = y;
602 monitor->geometry.width = width;
603 monitor->geometry.height = height;
605 monitor->output = None;
606 monitor->width_mm = -1;
607 monitor->height_mm = -1;
608 monitor->output_name = NULL;
609 monitor->manufacturer = NULL;
613 init_fake_xinerama (GdkScreen *screen)
615 #ifdef G_ENABLE_DEBUG
616 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
617 XSetWindowAttributes atts;
621 if (!(_gdk_debug_flags & GDK_DEBUG_XINERAMA))
624 /* Fake Xinerama mode by splitting the screen into 4 monitors.
625 * Also draw a little cross to make the monitor boundaries visible.
627 w = WidthOfScreen (screen_x11->xscreen);
628 h = HeightOfScreen (screen_x11->xscreen);
630 screen_x11->n_monitors = 4;
631 screen_x11->monitors = g_new0 (GdkX11Monitor, 4);
632 init_monitor_geometry (&screen_x11->monitors[0], 0, 0, w / 2, h / 2);
633 init_monitor_geometry (&screen_x11->monitors[1], w / 2, 0, w / 2, h / 2);
634 init_monitor_geometry (&screen_x11->monitors[2], 0, h / 2, w / 2, h / 2);
635 init_monitor_geometry (&screen_x11->monitors[3], w / 2, h / 2, w / 2, h / 2);
637 atts.override_redirect = 1;
638 atts.background_pixel = WhitePixel(GDK_SCREEN_XDISPLAY (screen),
639 screen_x11->screen_num);
640 win = XCreateWindow(GDK_SCREEN_XDISPLAY (screen),
641 screen_x11->xroot_window, 0, h / 2, w, 1, 0,
642 DefaultDepth(GDK_SCREEN_XDISPLAY (screen),
643 screen_x11->screen_num),
645 DefaultVisual(GDK_SCREEN_XDISPLAY (screen),
646 screen_x11->screen_num),
647 CWOverrideRedirect|CWBackPixel,
649 XMapRaised(GDK_SCREEN_XDISPLAY (screen), win);
650 win = XCreateWindow(GDK_SCREEN_XDISPLAY (screen),
651 screen_x11->xroot_window, w/2 , 0, 1, h, 0,
652 DefaultDepth(GDK_SCREEN_XDISPLAY (screen),
653 screen_x11->screen_num),
655 DefaultVisual(GDK_SCREEN_XDISPLAY (screen),
656 screen_x11->screen_num),
657 CWOverrideRedirect|CWBackPixel,
659 XMapRaised(GDK_SCREEN_XDISPLAY (screen), win);
667 monitor_compare_function (GdkX11Monitor *monitor1,
668 GdkX11Monitor *monitor2)
670 /* Sort the leftmost/topmost monitors first.
671 * For "cloned" monitors, sort the bigger ones first
672 * (giving preference to taller monitors over wider
676 if (monitor1->geometry.x != monitor2->geometry.x)
677 return monitor1->geometry.x - monitor2->geometry.x;
679 if (monitor1->geometry.y != monitor2->geometry.y)
680 return monitor1->geometry.y - monitor2->geometry.y;
682 if (monitor1->geometry.height != monitor2->geometry.height)
683 return - (monitor1->geometry.height - monitor2->geometry.height);
685 if (monitor1->geometry.width != monitor2->geometry.width)
686 return - (monitor1->geometry.width - monitor2->geometry.width);
692 init_randr13 (GdkScreen *screen)
695 GdkDisplay *display = gdk_screen_get_display (screen);
696 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
697 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
698 Display *dpy = GDK_SCREEN_XDISPLAY (screen);
699 XRRScreenResources *resources;
702 gboolean randr12_compat = FALSE;
704 if (!display_x11->have_randr13)
707 resources = XRRGetScreenResourcesCurrent (screen_x11->xdisplay,
708 screen_x11->xroot_window);
712 monitors = g_array_sized_new (FALSE, TRUE, sizeof (GdkX11Monitor),
715 for (i = 0; i < resources->noutput; ++i)
717 XRROutputInfo *output =
718 XRRGetOutputInfo (dpy, resources, resources->outputs[i]);
720 /* Non RandR1.2 X driver have output name "default" */
721 randr12_compat |= !g_strcmp0(output->name, "default");
723 if (output->connection == RR_Disconnected)
728 GdkX11Monitor monitor;
729 XRRCrtcInfo *crtc = XRRGetCrtcInfo (dpy, resources, output->crtc);
731 monitor.geometry.x = crtc->x;
732 monitor.geometry.y = crtc->y;
733 monitor.geometry.width = crtc->width;
734 monitor.geometry.height = crtc->height;
736 monitor.output = resources->outputs[i];
737 monitor.width_mm = output->mm_width;
738 monitor.height_mm = output->mm_height;
739 monitor.output_name = g_strdup (output->name);
740 /* FIXME: need EDID parser */
741 monitor.manufacturer = NULL;
743 g_array_append_val (monitors, monitor);
745 XRRFreeCrtcInfo (crtc);
748 XRRFreeOutputInfo (output);
751 XRRFreeScreenResources (resources);
753 /* non RandR 1.2 X driver doesn't return any usable multihead data */
756 g_array_free (monitors, TRUE);
760 g_array_sort (monitors,
761 (GCompareFunc) monitor_compare_function);
762 screen_x11->n_monitors = monitors->len;
763 screen_x11->monitors = (GdkX11Monitor *)g_array_free (monitors, FALSE);
765 return screen_x11->n_monitors > 0;
772 init_solaris_xinerama (GdkScreen *screen)
774 #ifdef HAVE_SOLARIS_XINERAMA
775 Display *dpy = GDK_SCREEN_XDISPLAY (screen);
776 int screen_no = gdk_screen_get_number (screen);
777 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
778 XRectangle monitors[MAXFRAMEBUFFERS];
779 unsigned char hints[16];
784 if (!XineramaGetState (dpy, screen_no))
787 result = XineramaGetInfo (dpy, screen_no, monitors, hints, &n_monitors);
789 /* Yes I know it should be Success but the current implementation
790 * returns the num of monitor
797 screen_x11->monitors = g_new0 (GdkX11Monitor, n_monitors);
798 screen_x11->n_monitors = n_monitors;
800 for (i = 0; i < n_monitors; i++)
802 init_monitor_geometry (&screen_x11->monitors[i],
803 monitors[i].x, monitors[i].y,
804 monitors[i].width, monitors[i].height);
808 #endif /* HAVE_SOLARIS_XINERAMA */
814 init_xfree_xinerama (GdkScreen *screen)
816 #ifdef HAVE_XFREE_XINERAMA
817 Display *dpy = GDK_SCREEN_XDISPLAY (screen);
818 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
819 XineramaScreenInfo *monitors;
822 if (!XineramaIsActive (dpy))
825 monitors = XineramaQueryScreens (dpy, &n_monitors);
827 if (n_monitors <= 0 || monitors == NULL)
829 /* If Xinerama doesn't think we have any monitors, try acting as
830 * though we had no Xinerama. If the "no monitors" condition
831 * is because XRandR 1.2 is currently switching between CRTCs,
832 * we'll be notified again when we have our monitor back,
833 * and can go back into Xinerama-ish mode at that point.
841 screen_x11->n_monitors = n_monitors;
842 screen_x11->monitors = g_new0 (GdkX11Monitor, n_monitors);
844 for (i = 0; i < n_monitors; ++i)
846 init_monitor_geometry (&screen_x11->monitors[i],
847 monitors[i].x_org, monitors[i].y_org,
848 monitors[i].width, monitors[i].height);
854 #endif /* HAVE_XFREE_XINERAMA */
860 free_monitors (GdkX11Monitor *monitors,
865 for (i = 0; i < n_monitors; ++i)
867 g_free (monitors[i].output_name);
868 g_free (monitors[i].manufacturer);
875 deinit_multihead (GdkScreen *screen)
877 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
879 free_monitors (screen_x11->monitors, screen_x11->n_monitors);
881 screen_x11->n_monitors = 0;
882 screen_x11->monitors = NULL;
886 compare_monitor (GdkX11Monitor *m1,
889 if (m1->geometry.x != m2->geometry.x ||
890 m1->geometry.y != m2->geometry.y ||
891 m1->geometry.width != m2->geometry.width ||
892 m1->geometry.height != m2->geometry.height)
895 if (m1->width_mm != m2->width_mm ||
896 m1->height_mm != m2->height_mm)
899 if (g_strcmp0 (m1->output_name, m2->output_name) != 0)
902 if (g_strcmp0 (m1->manufacturer, m2->manufacturer) != 0)
909 compare_monitors (GdkX11Monitor *monitors1, gint n_monitors1,
910 GdkX11Monitor *monitors2, gint n_monitors2)
914 if (n_monitors1 != n_monitors2)
917 for (i = 0; i < n_monitors1; i++)
919 if (!compare_monitor (monitors1 + i, monitors2 + i))
927 init_multihead (GdkScreen *screen)
929 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
930 int opcode, firstevent, firsterror;
932 /* There are four different implementations of multihead support:
934 * 1. Fake Xinerama for debugging purposes
936 * 3. Solaris Xinerama
937 * 4. XFree86/Xorg Xinerama
939 * We use them in that order.
941 if (init_fake_xinerama (screen))
944 if (init_randr13 (screen))
947 if (XQueryExtension (GDK_SCREEN_XDISPLAY (screen), "XINERAMA",
948 &opcode, &firstevent, &firsterror))
950 if (init_solaris_xinerama (screen))
953 if (init_xfree_xinerama (screen))
957 /* No multihead support of any kind for this screen */
958 screen_x11->n_monitors = 1;
959 screen_x11->monitors = g_new0 (GdkX11Monitor, 1);
961 init_monitor_geometry (screen_x11->monitors, 0, 0,
962 WidthOfScreen (screen_x11->xscreen),
963 HeightOfScreen (screen_x11->xscreen));
967 _gdk_x11_screen_new (GdkDisplay *display,
971 GdkScreenX11 *screen_x11;
972 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
974 screen = g_object_new (GDK_TYPE_SCREEN_X11, NULL);
976 screen_x11 = GDK_SCREEN_X11 (screen);
977 screen_x11->display = display;
978 screen_x11->xdisplay = display_x11->xdisplay;
979 screen_x11->xscreen = ScreenOfDisplay (display_x11->xdisplay, screen_number);
980 screen_x11->screen_num = screen_number;
981 screen_x11->xroot_window = RootWindow (display_x11->xdisplay,screen_number);
982 screen_x11->wmspec_check_window = None;
983 /* we want this to be always non-null */
984 screen_x11->window_manager_name = g_strdup ("unknown");
985 screen_x11->cm_selection_atom = make_cm_atom (screen_number);
986 screen_x11->is_composited = check_is_composited (display, screen_x11);
988 init_multihead (screen);
989 init_randr_support (screen);
991 _gdk_visual_init (screen);
992 _gdk_windowing_window_init (screen);
998 * gdk_screen_is_composited:
999 * @screen: a #GdkScreen
1001 * Returns whether windows with an RGBA visual can reasonably
1002 * be expected to have their alpha channel drawn correctly on
1005 * On X11 this function returns whether a compositing manager is
1006 * compositing @screen.
1008 * Return value: Whether windows with RGBA visuals can reasonably be
1009 * expected to have their alpha channels drawn correctly on the screen.
1014 gdk_screen_is_composited (GdkScreen *screen)
1016 GdkScreenX11 *screen_x11;
1018 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
1020 screen_x11 = GDK_SCREEN_X11 (screen);
1022 return screen_x11->is_composited;
1026 init_randr_support (GdkScreen * screen)
1028 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
1030 XSelectInput (GDK_SCREEN_XDISPLAY (screen),
1031 screen_x11->xroot_window,
1032 StructureNotifyMask);
1035 XRRSelectInput (GDK_SCREEN_XDISPLAY (screen),
1036 screen_x11->xroot_window,
1037 RRScreenChangeNotifyMask |
1038 RRCrtcChangeNotifyMask |
1039 RROutputPropertyNotifyMask);
1044 process_monitors_change (GdkScreen *screen)
1046 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
1048 GdkX11Monitor *monitors;
1051 n_monitors = screen_x11->n_monitors;
1052 monitors = screen_x11->monitors;
1054 screen_x11->n_monitors = 0;
1055 screen_x11->monitors = NULL;
1057 init_multihead (screen);
1059 changed = !compare_monitors (monitors, n_monitors,
1060 screen_x11->monitors, screen_x11->n_monitors);
1062 free_monitors (monitors, n_monitors);
1065 g_signal_emit_by_name (screen, "monitors-changed");
1069 _gdk_x11_screen_size_changed (GdkScreen *screen,
1073 GdkDisplayX11 *display_x11;
1074 gboolean monitors_changed;
1076 width = gdk_screen_get_width (screen);
1077 height = gdk_screen_get_height (screen);
1080 display_x11 = GDK_DISPLAY_X11 (gdk_screen_get_display (screen));
1082 if (display_x11->have_randr13 && event->type == ConfigureNotify)
1085 XRRUpdateConfiguration (event);
1087 if (event->type == ConfigureNotify)
1089 XConfigureEvent *rcevent = (XConfigureEvent *) event;
1090 Screen *xscreen = gdk_x11_screen_get_xscreen (screen);
1092 xscreen->width = rcevent->width;
1093 xscreen->height = rcevent->height;
1099 process_monitors_change (screen);
1101 if (width != gdk_screen_get_width (screen) ||
1102 height != gdk_screen_get_height (screen))
1103 g_signal_emit_by_name (screen, "size-changed");
1107 _gdk_x11_screen_window_manager_changed (GdkScreen *screen)
1109 g_signal_emit (screen, signals[WINDOW_MANAGER_CHANGED], 0);
1113 _gdk_x11_screen_process_owner_change (GdkScreen *screen,
1117 XFixesSelectionNotifyEvent *selection_event = (XFixesSelectionNotifyEvent *)event;
1118 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
1119 Atom xcm_selection_atom = gdk_x11_atom_to_xatom_for_display (screen_x11->display,
1120 screen_x11->cm_selection_atom);
1122 if (selection_event->selection == xcm_selection_atom)
1124 gboolean composited = selection_event->owner != None;
1126 if (composited != screen_x11->is_composited)
1128 screen_x11->is_composited = composited;
1130 g_signal_emit_by_name (screen, "composited-changed");
1137 * _gdk_windowing_substitute_screen_number:
1138 * @display_name : The name of a display, in the form used by
1139 * gdk_display_open (). If %NULL a default value
1140 * will be used. On X11, this is derived from the DISPLAY
1141 * environment variable.
1142 * @screen_number : The number of a screen within the display
1143 * referred to by @display_name.
1145 * Modifies a @display_name to make @screen_number the default
1146 * screen when the display is opened.
1148 * Return value: a newly allocated string holding the resulting
1149 * display name. Free with g_free().
1152 _gdk_windowing_substitute_screen_number (const gchar *display_name,
1159 display_name = getenv ("DISPLAY");
1164 str = g_string_new (display_name);
1166 p = strrchr (str->str, '.');
1167 if (p && p > strchr (str->str, ':'))
1168 g_string_truncate (str, p - str->str);
1170 g_string_append_printf (str, ".%d", screen_number);
1172 return g_string_free (str, FALSE);
1176 * gdk_screen_make_display_name:
1177 * @screen: a #GdkScreen
1179 * Determines the name to pass to gdk_display_open() to get
1180 * a #GdkDisplay with this screen as the default screen.
1182 * Return value: a newly allocated string, free with g_free()
1187 gdk_screen_make_display_name (GdkScreen *screen)
1189 const gchar *old_display;
1191 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
1193 old_display = gdk_display_get_name (gdk_screen_get_display (screen));
1195 return _gdk_windowing_substitute_screen_number (old_display,
1196 gdk_screen_get_number (screen));
1200 * gdk_screen_get_active_window
1201 * @screen: a #GdkScreen
1203 * Returns the screen's currently active window.
1205 * On X11, this is done by inspecting the _NET_ACTIVE_WINDOW property
1206 * on the root window, as described in the <ulink
1207 * url="http://www.freedesktop.org/Standards/wm-spec">Extended Window
1208 * Manager Hints</ulink>. If there is no currently currently active
1209 * window, or the window manager does not support the
1210 * _NET_ACTIVE_WINDOW hint, this function returns %NULL.
1212 * On other platforms, this function may return %NULL, depending on whether
1213 * it is implementable on that platform.
1215 * The returned window should be unrefed using g_object_unref() when
1218 * Return value: the currently active window, or %NULL.
1223 gdk_screen_get_active_window (GdkScreen *screen)
1225 GdkScreenX11 *screen_x11;
1226 GdkWindow *ret = NULL;
1229 gulong nitems_return;
1230 gulong bytes_after_return;
1231 guchar *data = NULL;
1233 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
1235 if (!gdk_x11_screen_supports_net_wm_hint (screen,
1236 gdk_atom_intern_static_string ("_NET_ACTIVE_WINDOW")))
1239 screen_x11 = GDK_SCREEN_X11 (screen);
1241 if (XGetWindowProperty (screen_x11->xdisplay, screen_x11->xroot_window,
1242 gdk_x11_get_xatom_by_name_for_display (screen_x11->display,
1243 "_NET_ACTIVE_WINDOW"),
1244 0, 1, False, XA_WINDOW, &type_return,
1245 &format_return, &nitems_return,
1246 &bytes_after_return, &data)
1249 if ((type_return == XA_WINDOW) && (format_return == 32) && (data))
1251 GdkNativeWindow window = *(GdkNativeWindow *) data;
1255 ret = gdk_window_foreign_new_for_display (screen_x11->display,
1256 *(GdkNativeWindow *) data);
1268 * gdk_screen_get_window_stack
1269 * @screen: a #GdkScreen
1271 * Returns a #GList of #GdkWindow<!-- -->s representing the current
1274 * On X11, this is done by inspecting the _NET_CLIENT_LIST_STACKING
1275 * property on the root window, as described in the <ulink
1276 * url="http://www.freedesktop.org/Standards/wm-spec">Extended Window
1277 * Manager Hints</ulink>. If the window manager does not support the
1278 * _NET_CLIENT_LIST_STACKING hint, this function returns %NULL.
1280 * On other platforms, this function may return %NULL, depending on whether
1281 * it is implementable on that platform.
1283 * The returned list is newly allocated and owns references to the
1284 * windows it contains, so it should be freed using g_list_free() and
1285 * its windows unrefed using g_object_unref() when no longer needed.
1287 * Return value: a list of #GdkWindow<!-- -->s for the current window stack,
1293 gdk_screen_get_window_stack (GdkScreen *screen)
1295 GdkScreenX11 *screen_x11;
1299 gulong nitems_return;
1300 gulong bytes_after_return;
1301 guchar *data = NULL;
1303 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
1305 if (!gdk_x11_screen_supports_net_wm_hint (screen,
1306 gdk_atom_intern_static_string ("_NET_CLIENT_LIST_STACKING")))
1309 screen_x11 = GDK_SCREEN_X11 (screen);
1311 if (XGetWindowProperty (screen_x11->xdisplay, screen_x11->xroot_window,
1312 gdk_x11_get_xatom_by_name_for_display (screen_x11->display,
1313 "_NET_CLIENT_LIST_STACKING"),
1314 0, G_MAXLONG, False, XA_WINDOW, &type_return,
1315 &format_return, &nitems_return,
1316 &bytes_after_return, &data)
1319 if ((type_return == XA_WINDOW) && (format_return == 32) &&
1320 (data) && (nitems_return > 0))
1322 gulong *stack = (gulong *) data;
1326 for (i = 0; i < nitems_return; i++)
1328 win = gdk_window_foreign_new_for_display (screen_x11->display,
1329 (GdkNativeWindow)stack[i]);
1332 ret = g_list_append (ret, win);
1343 #define __GDK_SCREEN_X11_C__
1344 #include "gdkaliasdef.c"