1 /* screens.c --- dealing with RANDR, Xinerama, and VidMode Viewports.
2 * xscreensaver, Copyright (c) 1991-2008 Jamie Zawinski <jwz@jwz.org>
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation. No representations are made about the suitability of this
9 * software for any purpose. It is provided "as is" without express or
13 /* There are a bunch of different mechanisms for multiple monitors
14 * available in X. XScreenSaver needs to care about this for two
15 * reasons: first, to ensure that all visible areas go black; and
16 * second, so that the windows of screen savers exactly fill the
17 * glass of each monitor (instead of one saver spanning multiple
18 * monitors, or a monitor displaying only a sub-rectangle of the
23 * This is the original way. Each monitor gets its own display
24 * number. :0.0 is the first one, :0.1 is the next, etc. The
25 * value of $DISPLAY determines which screen windows open on by
26 * default. A single app can open windows on multiple screens
27 * with the same display connection, but windows cannot be moved
28 * from one screen to another. The mouse can be moved from one
29 * screen to another, though. Screens may be different depths
30 * (e.g., one can be TrueColor and one can be PseudoColor.)
31 * Screens cannot be resized or moved without restarting X.
33 * Everyone hates this way of doing things because of the
34 * inability to move a window from one screen to another without
35 * restarting the application.
39 * There is a single giant root window that spans all the
40 * monitors. All monitors are the same depth, and windows can be
41 * moved around. Applications can learn which rectangles are
42 * actually visible on monitors by querying the Xinerama server
43 * extension. (If you don't do that, you end up with dialog
44 * boxes that try to appear in the middle of the screen actually
45 * spanning the gap between two monitors.)
47 * Xinerama doesn't work with DRI, which means that if you use
48 * it, you lose hardware acceleration on OpenGL programs. Also,
49 * screens can't be resized or moved without restarting X.
51 * 3) Vidmode Viewports:
53 * With this extension, the root window can be bigger than the
54 * monitor. Moving the mouse near the edges of the screen
55 * scrolls around, like a pan-and-scan movie. There can also be
56 * a hot key for changing the monitor's resolution (zooming
59 * Trying to combine this with Xinerama crashes the server, so
60 * you can only use this if you have only a single screen, or are
61 * in old-multi-screen mode.
63 * Also, half the time it doesn't work at all: it tends to lie
64 * about the size of the rectangle in use.
68 * The first version of the "Resize and Rotate" extension let you
69 * change the resolution of a screen on the fly. The root window
70 * would actually resize. However, it was also incompatible with
71 * Xinerama (did it crash, or just do nothing? I can't remember)
72 * so you needed to be in single-screen or old multi-screen mode.
73 * I believe RANDR could co-exist with Vidmode Viewports, but I'm
78 * Finally, RANDR added the functionality of Xinerama, plus some.
79 * Each X screen (in the sense of #1, "multi-screen") can have a
80 * number of sub-rectangles that are displayed on monitors, and
81 * each of those sub-rectangles can be displayed on more than one
82 * monitor. So it's possible (I think) to have a hybrid of
83 * multi-screen and Xinerama (e.g., to have two monitors running
84 * in one depth, and three monitors running in another?)
85 * Typically though, there will be a single X screen, with
86 * Xinerama-like division of that large root window onto multiple
87 * monitors. Also everything's dynamic: monitors can be added,
88 * removed, and resized at runtime.
90 * I believe that as of RANDR 1.2, the Xinerama extension still
91 * exists but only as a compatiblity layer: it's actually
92 * returning data from the RANDR extension.
94 * Though RANDR 1.2 allows the same image to be cloned onto more
95 * than one monitor, and also allows one monitor to show a
96 * subsection of something on another monitor (e.g., the
97 * rectangles can be enclosed or overlap). Since there's no way
98 * to put seperate savers on those duplicated-or-overlapping
99 * monitors, xscreensaver just ignores them (which allows them to
100 * display duplicates or overlaps).
102 * 5a) Nvidia fucks it up:
104 * Nvidia drivers as of Aug 2008 running in "TwinView" mode
105 * apparently report correct screen geometry via Xinerama, but
106 * report one giant screen via RANDR. The response from the
107 * nvidia developers is, "we don't support RANDR, use Xinerama
108 * instead." Which is a seriously lame answer. So, xscreensaver
109 * has to query *both* extensions, and make a guess as to which
117 #include <X11/Xlib.h>
120 # include <X11/extensions/Xrandr.h>
121 #endif /* HAVE_RANDR */
124 # include <X11/extensions/Xinerama.h>
125 #endif /* HAVE_XINERAMA */
127 #ifdef HAVE_XF86VMODE
128 # include <X11/extensions/xf86vmode.h>
129 #endif /* HAVE_XF86VMODE */
131 /* This file doesn't need the Xt headers, so stub these types out... */
133 #define XtAppContext void*
134 #define XrmDatabase void*
135 #define XtIntervalId void*
136 #define XtPointer void*
139 #include "xscreensaver.h"
143 typedef enum { S_SANE, S_ENCLOSED, S_DUPLICATE, S_OVERLAP,
144 S_OFFSCREEN, S_DISABLED } monitor_sanity;
146 /* 'typedef monitor' is in types.h */
151 int x, y, width, height;
152 monitor_sanity sanity; /* I'm not crazy you're the one who's crazy */
153 int enemy; /* which monitor it overlaps or duplicates */
156 static Bool layouts_differ_p (monitor **a, monitor **b);
160 free_monitors (monitor **monitors)
162 monitor **m2 = monitors;
163 if (! monitors) return;
166 if ((*m2)->desc) free ((*m2)->desc);
177 xinerama_scan_monitors (Display *dpy)
179 Screen *screen = DefaultScreenOfDisplay (dpy);
180 int event, error, nscreens, i;
181 XineramaScreenInfo *xsi;
184 if (! XineramaQueryExtension (dpy, &event, &error))
187 if (! XineramaIsActive (dpy))
190 xsi = XineramaQueryScreens (dpy, &nscreens);
193 monitors = (monitor **) calloc (nscreens + 1, sizeof(*monitors));
194 if (!monitors) return 0;
196 for (i = 0; i < nscreens; i++)
198 monitor *m = (monitor *) calloc (1, sizeof (monitor));
204 m->width = xsi[i].width;
205 m->height = xsi[i].height;
210 #endif /* HAVE_XINERAMA */
213 #ifdef HAVE_XF86VMODE
216 vidmode_scan_monitors (Display *dpy)
218 int event, error, nscreens, i;
221 /* Note that XF86VidModeGetViewPort() tends to be full of lies on laptops
222 that have a docking station or external monitor that runs in a different
223 resolution than the laptop's screen:
225 http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=81593
226 http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=208417
227 http://bugs.xfree86.org/show_bug.cgi?id=421
229 Presumably this is fixed by using RANDR instead of VidMode.
232 # ifdef HAVE_XINERAMA
233 /* Attempts to use the VidMode extension when the Xinerama extension is
234 active can result in a server crash! Yay! */
235 if (XQueryExtension (dpy, "XINERAMA", &error, &event, &error))
237 # endif /* !HAVE_XINERAMA */
239 if (! XF86VidModeQueryExtension (dpy, &event, &error))
242 nscreens = ScreenCount (dpy);
243 monitors = (monitor **) calloc (nscreens + 1, sizeof(*monitors));
244 if (!monitors) return 0;
246 for (i = 0; i < nscreens; i++)
248 monitor *m = (monitor *) calloc (1, sizeof (monitor));
249 XF86VidModeModeLine ml;
251 Screen *screen = ScreenOfDisplay (dpy, i);
257 if (! safe_XF86VidModeGetViewPort (dpy, i, &m->x, &m->y))
260 if (XF86VidModeGetModeLine (dpy, i, &dot, &ml))
262 m->width = ml.hdisplay;
263 m->height = ml.vdisplay;
266 /* Apparently, though the server stores the X position in increments of
267 1 pixel, it will only make changes to the *display* in some other
268 increment. With XF86_SVGA on a Thinkpad, the display only updates
269 in multiples of 8 pixels when in 8-bit mode, and in multiples of 4
270 pixels in 16-bit mode. I don't know what it does in 24- and 32-bit
271 mode, because I don't have enough video memory to find out.
273 I consider it a bug that XF86VidModeGetViewPort() is telling me the
274 server's *target* scroll position rather than the server's *actual*
275 scroll position. David Dawes agrees, and says they may fix this in
276 XFree86 4.0, but it's notrivial.
278 He also confirms that this behavior is server-dependent, so the
279 actual scroll position cannot be reliably determined by the client.
280 So... that means the only solution is to provide a ``sandbox''
281 around the blackout window -- we make the window be up to N pixels
282 larger than the viewport on both the left and right sides. That
283 means some part of the outer edges of each hack might not be
284 visible, but screw it.
286 I'm going to guess that 16 pixels is enough, and that the Y dimension
287 doesn't have this problem.
289 The drawback of doing this, of course, is that some of the screenhacks
290 will still look pretty stupid -- for example, "slidescreen" will cut
291 off the left and right edges of the grid, etc.
294 if (m->x > 0 && m->x < m->width - ml.hdisplay)
296 /* Not at left edge or right edge:
297 Round X position down to next lower multiple of FUDGE.
298 Increase width by 2*FUDGE in case some server rounds up.
300 m->x = ((m->x - 1) / FUDGE) * FUDGE;
301 m->width += (FUDGE * 2);
309 #endif /* HAVE_XF86VMODE */
315 randr_scan_monitors (Display *dpy)
317 int event, error, major, minor, nscreens, i, j;
319 Bool new_randr_p = False;
321 if (! XRRQueryExtension (dpy, &event, &error))
324 if (! XRRQueryVersion (dpy, &major, &minor))
327 if (major <= 0) /* Protocol was still in flux back then -- fuck it. */
330 # ifdef HAVE_RANDR_12
331 new_randr_p = (major > 1 || (major == 1 && minor >= 2));
335 /* RANDR 1.0 -- no Xinerama-like virtual screens. */
336 nscreens = ScreenCount (dpy);
337 else /* RANDR 1.2 or newer -- built-in Xinerama */
339 # ifdef HAVE_RANDR_12
340 int xsc = ScreenCount (dpy);
342 /* Add up the virtual screens on each X screen. */
343 for (i = 0; i < xsc; i++)
345 XRRScreenResources *res =
346 XRRGetScreenResources (dpy, RootWindow (dpy, i));
347 nscreens += res->noutput;
348 XRRFreeScreenResources (res);
350 # endif /* HAVE_RANDR_12 */
353 monitors = (monitor **) calloc (nscreens + 1, sizeof(*monitors));
354 if (!monitors) return 0;
356 for (i = 0, j = 0; i < ScreenCount (dpy); i++)
358 Screen *screen = ScreenOfDisplay (dpy, i);
360 if (! new_randr_p) /* RANDR 1.0 */
362 XRRScreenConfiguration *rrc;
363 monitor *m = (monitor *) calloc (1, sizeof (monitor));
368 rrc = XRRGetScreenInfo (dpy, RootWindowOfScreen (screen));
373 XRRScreenSize *rrsizes;
376 size = XRRConfigCurrentConfiguration (rrc, &rot);
377 rrsizes = XRRConfigSizes (rrc, &nsizes);
379 if (nsizes <= 0) /* WTF? Shouldn't happen but does. */
381 m->width = DisplayWidth (dpy, i);
382 m->height = DisplayHeight (dpy, i);
384 else if (rot & (RR_Rotate_90|RR_Rotate_270))
386 m->width = rrsizes[size].height;
387 m->height = rrsizes[size].width;
391 m->width = rrsizes[size].width;
392 m->height = rrsizes[size].height;
395 /* don't free 'rrsizes' */
396 XRRFreeScreenConfigInfo (rrc);
399 else /* RANDR 1.2 or newer */
401 # ifdef HAVE_RANDR_12
403 XRRScreenResources *res =
404 XRRGetScreenResources (dpy, RootWindowOfScreen (screen));
405 for (k = 0; k < res->noutput; k++)
407 monitor *m = (monitor *) calloc (1, sizeof (monitor));
408 XRROutputInfo *rroi = XRRGetOutputInfo (dpy, res,
410 RRCrtc crtc = (rroi->crtc ? rroi->crtc : rroi->crtcs[0]);
411 XRRCrtcInfo *crtci = XRRGetCrtcInfo (dpy, res, crtc);
415 m->id = (i * 1000) + j;
416 m->desc = (rroi->name ? strdup (rroi->name) : 0);
420 if (crtci->rotation & (RR_Rotate_90|RR_Rotate_270))
422 m->width = crtci->height;
423 m->height = crtci->width;
427 m->width = crtci->width;
428 m->height = crtci->height;
433 if (rroi->connection == RR_Disconnected)
434 m->sanity = S_DISABLED;
435 /* #### do the same for RR_UnknownConnection? */
437 XRRFreeCrtcInfo (crtci);
438 XRRFreeOutputInfo (rroi);
440 XRRFreeScreenResources (res);
441 # endif /* HAVE_RANDR_12 */
448 #endif /* HAVE_RANDR */
452 basic_scan_monitors (Display *dpy)
454 int nscreens = ScreenCount (dpy);
456 monitor **monitors = (monitor **) calloc (nscreens + 1, sizeof(*monitors));
457 if (!monitors) return 0;
459 for (i = 0; i < nscreens; i++)
461 Screen *screen = ScreenOfDisplay (dpy, i);
462 monitor *m = (monitor *) calloc (1, sizeof (monitor));
468 m->width = WidthOfScreen (screen);
469 m->height = HeightOfScreen (screen);
475 #if defined(HAVE_RANDR) && defined(HAVE_XINERAMA)
477 /* From: Aaron Plattner <aplattner@nvidia.com>
478 Date: August 7, 2008 10:21:25 AM PDT
479 To: linux-bugs@nvidia.com
481 The NVIDIA X driver does not yet support RandR 1.2. The X server has
482 a compatibility layer in it that allows RandR 1.2 clients to talk to
483 RandR 1.1 drivers through an RandR 1.2 pseudo-output called "default".
484 This reports the total combined resolution of the TwinView display,
485 since it doesn't have any visibility into TwinView metamodes. There
486 is no way for the driver to prevent the server from turning on this
489 The intention is for X client applications to continue to use the
490 Xinerama extension to query the screen geometry. RandR 1.2 reports
491 its own Xinerama info for this purpose. I would recommend against
492 modifying xscreensaver to try to get this information from RandR.
495 randr_versus_xinerama_fight (Display *dpy, monitor **randr_monitors)
497 monitor **xinerama_monitors;
502 xinerama_monitors = xinerama_scan_monitors (dpy);
503 if (!xinerama_monitors)
504 return randr_monitors;
506 if (! layouts_differ_p (randr_monitors, xinerama_monitors))
508 free_monitors (xinerama_monitors);
509 return randr_monitors;
511 else if ( randr_monitors[0] && !randr_monitors[1] && /* 1 monitor */
512 xinerama_monitors[0] && xinerama_monitors[1]) /* >1 monitor */
515 "%s: WARNING: RANDR reports 1 screen but Xinerama\n"
516 "%s: reports multiple. Believing Xinerama.\n",
518 free_monitors (randr_monitors);
519 return xinerama_monitors;
524 "%s: WARNING: RANDR and Xinerama report different\n"
525 "%s: screen layouts! Believing RANDR.\n",
527 free_monitors (xinerama_monitors);
528 return randr_monitors;
532 #endif /* HAVE_RANDR && HAVE_XINERAMA */
535 #ifdef DEBUG_MULTISCREEN
537 /* If DEBUG_MULTISCREEN is defined, then in "-debug" mode, xscreensaver
538 will pretend that it is changing the number of connected monitors
539 every few seconds, using the geometries in the following list,
540 for stress-testing purposes.
543 debug_scan_monitors (Display *dpy)
545 static const char * const geoms[] = {
549 "800x600+0+22,800x600+800+22",
550 "800x600+0+22,800x600+800+22,800x600+300+622",
551 "800x600+0+22,800x600+800+22,800x600+0+622,800x600+800+622",
552 "640x480+0+22,640x480+640+22,640x480+0+502,640x480+640+502",
553 "640x480+240+22,640x480+0+502,640x480+640+502",
554 "640x480+0+200,640x480+640+200",
556 "320x200+0+22,320x200+320+22,320x200+640+22,320x200+960+22,320x200+0+222,320x200+320+222,320x200+640+222,320x200+960+222,320x200+0+422,320x200+320+422,320x200+640+422,320x200+960+422,320x200+0+622,320x200+320+622,320x200+640+622,320x200+960+622,320x200+0+822,320x200+320+822,320x200+640+822,320x200+960+822"
558 static int index = 0;
559 monitor **monitors = (monitor **) calloc (100, sizeof(*monitors));
561 Screen *screen = DefaultScreenOfDisplay (dpy);
563 char *s = strdup (geoms[index]);
564 char *token = strtok (s, ",");
567 monitor *m = calloc (1, sizeof (monitor));
571 if (4 != sscanf (token, "%dx%d+%d+%d%c",
572 &m->width, &m->height, &m->x, &m->y, &c))
576 monitors[nscreens++] = m;
577 token = strtok (0, ",");
581 index = (index+1) % countof(geoms);
585 #endif /* DEBUG_MULTISCREEN */
590 quadruple (monitor **monitors, Bool debug_p)
594 while (monitors[count])
596 monitors2 = (monitor **) calloc (count * 4 + 1, sizeof(*monitors));
597 if (!monitors2) abort();
599 for (i = 0, j = 0; i < count; i++)
602 for (k = 0; k < 4; k++)
604 monitors2[j+k] = (monitor *) calloc (1, sizeof (monitor));
605 *monitors2[j+k] = *monitors[i];
606 monitors2[j+k]->width /= (debug_p ? 4 : 2);
607 monitors2[j+k]->height /= 2;
608 monitors2[j+k]->id = (monitors[i]->id * 4) + k;
609 monitors2[j+k]->name = (monitors[i]->name
610 ? strdup (monitors[i]->name) : 0);
612 monitors2[j+1]->x += monitors2[j]->width;
613 monitors2[j+2]->y += monitors2[j]->height;
614 monitors2[j+3]->x += monitors2[j]->width;
615 monitors2[j+3]->y += monitors2[j]->height;
619 free_monitors (monitors);
622 #endif /* QUAD_MODE */
626 scan_monitors (saver_info *si)
628 saver_preferences *p = &si->prefs;
629 monitor **monitors = 0;
631 # ifdef DEBUG_MULTISCREEN
632 if (! monitors) monitors = debug_scan_monitors (si->dpy);
636 if (! p->getviewport_full_of_lies_p)
637 if (! monitors) monitors = randr_scan_monitors (si->dpy);
639 # ifdef HAVE_XINERAMA
640 monitors = randr_versus_xinerama_fight (si->dpy, monitors);
642 # endif /* HAVE_RANDR */
644 # ifdef HAVE_XF86VMODE
645 if (! monitors) monitors = vidmode_scan_monitors (si->dpy);
648 # ifdef HAVE_XINERAMA
649 if (! monitors) monitors = xinerama_scan_monitors (si->dpy);
652 if (! monitors) monitors = basic_scan_monitors (si->dpy);
656 monitors = quadruple (monitors, p->debug_p);
664 monitors_overlap_p (monitor *a, monitor *b)
666 /* Two rectangles overlap if the max of the tops is less than the
667 min of the bottoms and the max of the lefts is less than the min
672 # define MAX(A,B) ((A)>(B)?(A):(B))
673 # define MIN(A,B) ((A)<(B)?(A):(B))
675 int maxleft = MAX(a->x, b->x);
676 int maxtop = MAX(a->y, b->y);
677 int minright = MIN(a->x + a->width - 1, b->x + b->width);
678 int minbot = MIN(a->y + a->height - 1, b->y + b->height);
679 return (maxtop < minbot && maxleft < minright);
684 plausible_aspect_ratio_p (monitor **monitors)
686 /* Modern wide-screen monitors come in the following aspect ratios:
688 One monitor: If you tack a 640x480 monitor
689 onto the right, the ratio is:
691 852 x 480 --> 1.77 852+640 x 480 --> 3.11 "SD 480p"
692 1280 x 720 --> 1.78 1280+640 x 720 --> 2.67 "HD 720p"
693 1280 x 920 --> 1.39 1280+640 x 920 --> 2.09
694 1366 x 768 --> 1.78 1366+640 x 768 --> 2.61 "HD 768p"
695 1440 x 900 --> 1.60 1440+640 x 900 --> 2.31
696 1680 x 1050 --> 1.60 1680+640 x 1050 --> 2.21
697 1690 x 1050 --> 1.61 1690+640 x 1050 --> 2.22
698 1920 x 1080 --> 1.78 1920+640 x 1080 --> 2.37 "HD 1080p"
699 1920 x 1200 --> 1.60 1920+640 x 1200 --> 2.13
700 2560 x 1600 --> 1.60 2560+640 x 1600 --> 2.00
702 So that implies that if we ever see an aspect ratio >= 2.0,
703 we can be pretty sure that the X server is lying to us, and
704 that's actually two monitors, not one.
706 if (monitors[0] && !monitors[1] && /* exactly 1 monitor */
707 monitors[0]->height &&
708 monitors[0]->width / (double) monitors[0]->height >= 1.9)
715 /* Mark the ones that overlap, etc.
718 check_monitor_sanity (monitor **monitors)
722 while (monitors[count])
725 # define X1 monitors[i]->x
726 # define X2 monitors[j]->x
727 # define Y1 monitors[i]->y
728 # define Y2 monitors[j]->y
729 # define W1 monitors[i]->width
730 # define W2 monitors[j]->width
731 # define H1 monitors[i]->height
732 # define H2 monitors[j]->height
734 /* If a monitor is enclosed by any other monitor, that's insane.
736 for (i = 0; i < count; i++)
737 for (j = 0; j < count; j++)
739 monitors[i]->sanity == S_SANE &&
740 monitors[j]->sanity == S_SANE &&
741 monitors[i]->screen == monitors[j]->screen &&
744 (X2+W2) <= (X1+W1) &&
751 monitors[j]->sanity = S_DUPLICATE;
753 monitors[j]->sanity = S_ENCLOSED;
754 monitors[j]->enemy = i;
757 /* After checking for enclosure, check for other lossage against earlier
758 monitors. We do enclosure first so that we make sure to pick the
761 for (i = 0; i < count; i++)
762 for (j = 0; j < i; j++)
764 if (monitors[i]->sanity != S_SANE) continue; /* already marked */
765 if (monitors[j]->sanity != S_SANE) continue;
766 if (monitors[i]->screen != monitors[j]->screen) continue;
768 if (monitors_overlap_p (monitors[i], monitors[j]))
770 monitors[i]->sanity = S_OVERLAP;
771 monitors[i]->enemy = j;
775 /* Finally, make sure all monitors have sane positions and sizes.
776 Xinerama sometimes reports 1024x768 VPs at -1936862040, -1953705044.
778 for (i = 0; i < count; i++)
780 if (monitors[i]->sanity != S_SANE) continue; /* already marked */
781 if (X1 < 0 || Y1 < 0 ||
782 W1 <= 0 || H1 <= 0 ||
783 X1+W1 >= 0x7FFF || Y1+H1 >= 0x7FFF)
785 monitors[i]->sanity = S_OFFSCREEN;
786 monitors[i]->enemy = 0;
802 layouts_differ_p (monitor **a, monitor **b)
804 if (!a || !b) return True;
809 if ((*a)->screen != (*b)->screen ||
810 (*a)->x != (*b)->x ||
811 (*a)->y != (*b)->y ||
812 (*a)->width != (*b)->width ||
813 (*a)->height != (*b)->height)
826 describe_monitor_layout (saver_info *si)
828 monitor **monitors = si->monitor_layout;
832 int implausible_p = !plausible_aspect_ratio_p (monitors);
834 while (monitors[count])
836 if (monitors[count]->sanity == S_SANE)
844 fprintf (stderr, "%s: no screens!\n", blurb());
848 fprintf (stderr, "%s: screens in use: %d\n", blurb(), good_count);
849 for (i = 0; i < count; i++)
851 monitor *m = monitors[i];
852 if (m->sanity != S_SANE) continue;
853 fprintf (stderr, "%s: %3d/%d: %dx%d+%d+%d",
854 blurb(), m->id, screen_number (m->screen),
855 m->width, m->height, m->x, m->y);
856 if (m->desc && *m->desc) fprintf (stderr, " (%s)", m->desc);
857 fprintf (stderr, "\n");
861 fprintf (stderr, "%s: rejected screens: %d\n", blurb(), bad_count);
862 for (i = 0; i < count; i++)
864 monitor *m = monitors[i];
865 monitor *e = monitors[m->enemy];
866 if (m->sanity == S_SANE) continue;
867 fprintf (stderr, "%s: %3d/%d: %dx%d+%d+%d",
868 blurb(), m->id, screen_number (m->screen),
869 m->width, m->height, m->x, m->y);
870 if (m->desc && *m->desc) fprintf (stderr, " (%s)", m->desc);
871 fprintf (stderr, " -- ");
874 case S_SANE: abort(); break;
876 fprintf (stderr, "enclosed by %d (%dx%d+%d+%d)\n",
877 e->id, e->width, e->height, e->x, e->y);
880 fprintf (stderr, "duplicate of %d\n", e->id);
883 fprintf (stderr, "overlaps %d (%dx%d+%d+%d)\n",
884 e->id, e->width, e->height, e->x, e->y);
887 fprintf (stderr, "off screen (%dx%d)\n",
888 WidthOfScreen (e->screen),
889 HeightOfScreen (e->screen));
892 fprintf (stderr, "output disabled\n");
900 "%s: WARNING: single screen aspect ratio is %dx%d = %.2f\n"
901 "%s: probable X server bug in Xinerama/RANDR!\n",
902 blurb(), monitors[0]->width, monitors[0]->height,
903 monitors[0]->width / (double) monitors[0]->height,
909 /* Synchronize the contents of si->ssi to the current state of the monitors.
910 Doesn't change anything if nothing has changed; otherwise, alters and
911 reuses existing saver_screen_info structs as much as possible.
912 Returns True if anything changed.
915 update_screen_layout (saver_info *si)
917 monitor **monitors = scan_monitors (si);
921 int seen_screens[100] = { 0, };
923 if (! layouts_differ_p (monitors, si->monitor_layout))
925 free_monitors (monitors);
929 free_monitors (si->monitor_layout);
930 si->monitor_layout = monitors;
931 check_monitor_sanity (si->monitor_layout);
933 while (monitors[count])
935 if (monitors[count]->sanity == S_SANE)
940 if (si->ssi_count == 0)
943 si->screens = (saver_screen_info *)
944 calloc (sizeof(*si->screens), si->ssi_count);
947 if (si->ssi_count <= good_count)
949 si->ssi_count = good_count + 10;
950 si->screens = (saver_screen_info *)
951 realloc (si->screens, sizeof(*si->screens) * si->ssi_count);
952 memset (si->screens + si->nscreens, 0,
953 sizeof(*si->screens) * (si->ssi_count - si->nscreens));
956 if (! si->screens) abort();
958 si->nscreens = good_count;
960 /* Regenerate the list of GL visuals as needed. */
961 if (si->best_gl_visuals)
962 free (si->best_gl_visuals);
963 si->best_gl_visuals = 0;
965 for (i = 0, j = 0; i < count; i++)
967 monitor *m = monitors[i];
968 saver_screen_info *ssi = &si->screens[j];
969 Screen *old_screen = ssi->screen;
971 if (monitors[i]->sanity != S_SANE) continue;
976 sn = screen_number (m->screen);
977 ssi->screen = m->screen;
978 ssi->real_screen_number = sn;
979 ssi->real_screen_p = (seen_screens[sn] == 0);
982 ssi->default_visual =
983 get_visual_resource (ssi->screen, "visualID", "VisualID", False);
984 ssi->current_visual = ssi->default_visual;
985 ssi->current_depth = visual_depth (ssi->screen, ssi->current_visual);
987 /* If the screen changed (or if this is the first time) we need
988 a new toplevel shell for this screen's depth.
990 if (ssi->screen != old_screen)
991 initialize_screen_root_widget (ssi);
993 ssi->poll_mouse_last_root_x = -1;
994 ssi->poll_mouse_last_root_y = -1;
998 ssi->width = m->width;
999 ssi->height = m->height;
1001 # ifndef DEBUG_MULTISCREEN
1003 saver_preferences *p = &si->prefs;
1016 si->default_screen = &si->screens[0];