+ sc = DefaultScreen(dpy);
+ wd = DisplayWidth(dpy, sc);
+ ht = DisplayHeight(dpy, sc);
+
+ /* --- Calculate and produce the necessary output --- *
+ *
+ * If we're meant to report on individual screens then try to collect
+ * information about them using the RANDR extension. If that doesn't
+ * exist, or the version is too ancient, or its otherwise not going to
+ * work, then pretend there's just one screen that's the size of the root
+ * window.
+ */
+
+ if (f & f_multi) {
+#ifdef HAVE_XRANDR
+ if (XRRQueryExtension(dpy, &rrev, &rrerr) &&
+ XRRQueryVersion(dpy, &rrmaj, &rrmin) &&
+ (rrmaj > 1 || (rrmaj == 1 && rrmin >= 2))) {
+ root = RootWindow(dpy, sc);
+ res = XRRGetScreenResources(dpy, root);
+ scr = xmalloc(res->ncrtc*sizeof(*scr)); j = 0;
+ for (i = 0; i < res->ncrtc; i++) {
+ crtc = XRRGetCrtcInfo(dpy, res, res->crtcs[i]);
+ if (crtc->mode) {
+ scr[j].x = crtc->x; scr[j].wd = crtc->width;
+ scr[j].y = crtc->y; scr[j].ht = crtc->height;
+ j++;
+ }
+ XRRFreeCrtcInfo(crtc);
+ }
+ nscr = j;
+ XRRFreeScreenResources(res);
+ } else
+#endif
+ {
+ /* --- The RANDR extension isn't available --- */
+
+ nscr = 1;
+ scr = xmalloc(sizeof(*scr));
+ scr->x = 0; scr->wd = wd;
+ scr->y = 0; scr->ht = ht;
+ }
+
+ /* --- Sort and report the screens --- *
+ *
+ * The chances are good that the screens reported by RANDR aren't in any
+ * especially useful order. Sort them into (my) reading order.
+ */
+
+ qsort(scr, nscr, sizeof(*scr), compare_screen);
+ print_var("XNSCR", -1, nscr);
+ for (j = 0; j < nscr; j++) {
+ print_var("X", j, scr[j].x);
+ print_var("Y", j, scr[j].y);
+ print_var("WIDTH", j, scr[j].wd);
+ print_var("HEIGHT", j, scr[j].ht);
+ }
+ } else {
+ print_var("XWIDTH", -1, wd);
+ print_var("XHEIGHT", -1, ht);