+ struct swm_region *r;
+ int ncrtc = 0;
+
+ /* remove any old regions */
+
+ while ((r = TAILQ_FIRST(&screens[i].rl)) != NULL) {
+ r->ws->r = NULL;
+ XDestroyWindow(display, r->bar_window);
+ TAILQ_REMOVE(&screens[i].rl, r, entry);
+ TAILQ_INSERT_TAIL(&screens[i].orl, r, entry);
+ }
+
+ /* map virtual screens onto physical screens */
+#ifdef SWM_XRR_HAS_CRTC
+ if (xrandr_support) {
+ sr = XRRGetScreenResources(display, screens[i].root);
+ if (sr == NULL)
+ new_region(&screens[i], 0, 0,
+ DisplayWidth(display, i),
+ DisplayHeight(display, i));
+ else
+ ncrtc = sr->ncrtc;
+
+ for (c = 0, ci = NULL; c < ncrtc; c++) {
+ ci = XRRGetCrtcInfo(display, sr, sr->crtcs[c]);
+ if (ci->noutput == 0)
+ continue;
+
+ if (ci != NULL && ci->mode == None)
+ new_region(&screens[i], 0, 0,
+ DisplayWidth(display, i),
+ DisplayHeight(display, i));
+ else
+ new_region(&screens[i],
+ ci->x, ci->y, ci->width, ci->height);
+ }
+ if (ci)
+ XRRFreeCrtcInfo(ci);
+ XRRFreeScreenResources(sr);
+ } else
+#endif /* SWM_XRR_HAS_CRTC */
+ {
+ new_region(&screens[i], 0, 0, DisplayWidth(display, i),
+ DisplayHeight(display, i));
+ }
+}
+
+void
+screenchange(XEvent *e)
+{
+ XRRScreenChangeNotifyEvent *xe = (XRRScreenChangeNotifyEvent *)e;
+ struct swm_region *r;
+ struct ws_win *win;
+ int i;
+
+ DNPRINTF(SWM_D_EVENT, "screenchange: %d\n", xe->root);
+
+ if (!XRRUpdateConfiguration(e))
+ return;
+
+ /* silly event doesn't include the screen index */
+ for (i = 0; i < ScreenCount(display); i++)
+ if (screens[i].root == xe->root)
+ break;
+ if (i >= ScreenCount(display))
+ errx(1, "screenchange: screen not found\n");
+
+ /* brute force for now, just re-enumerate the regions */
+ scan_xrandr(i);
+
+ /* hide any windows that went away */
+ TAILQ_FOREACH(r, &screens[i].rl, entry)
+ TAILQ_FOREACH(win, &r->ws->winlist, entry)
+ XUnmapWindow(display, win->id);
+ stack();
+}
+
+void
+setup_screens(void)
+{