- if(XineramaIsActive(dpy)) {
- info = XineramaQueryScreens(dpy, &i);
- wx = info[0].x_org;
- wy = showbar && topbar ? info[0].y_org + bh : info[0].y_org;
- ww = info[0].width;
- wh = showbar ? info[0].height - bh : info[0].height;
+ if(XineramaIsActive(dpy) && (info = XineramaQueryScreens(dpy, &n))) {
+ if(n != nmons) {
+ for(c = clients; c; c = c->next)
+ if(c->mon >= n)
+ c->mon = n - 1;
+ if(!(mon = (Monitor *)realloc(mon, sizeof(Monitor) * n)))
+ die("fatal: could not realloc() %u bytes\n", sizeof(Monitor) * nmons);
+ }
+ for(i = 0; i < n ; i++) {
+ /* TODO: consider re-using XineramaScreenInfo */
+ mon[i].symbol[0] = '[';
+ mon[i].symbol[1] = '0' + info[i].screen_number;
+ mon[i].symbol[2] = ']';
+ mon[i].symbol[3] = 0;
+ if(!selmon) { /* not initialised yet */
+ mon[i].mfact = mfact;
+ mon[i].showbar = showbar;
+ mon[i].topbar = topbar;
+ }
+ mon[i].wx = info[i].x_org;
+ mon[i].wy = mon[i].showbar && mon[i].topbar ? info[i].y_org + bh : info[i].y_org;
+ mon[i].ww = info[i].width;
+ mon[i].wh = mon[i].showbar ? info[i].height - bh : info[i].height;
+ mon[i].seltags = 0;
+ mon[i].sellt = 0;
+ if(mon[i].showbar)
+ mon[i].by = mon[i].topbar ? info[i].y_org : mon[i].wy + mon[i].wh;
+ else
+ mon[i].by = -bh;
+ }
+ nmons = (unsigned int)n;
+ if(!selmon) {
+ selmon = &mon[0];
+ int di, x, y;
+ unsigned int dui;
+ Window dummy;
+ if(XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui))
+ for(i = 0; i < nmons; i++)
+ if(INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height)) {
+ selmon = &mon[i];
+ break;
+ }
+ }