- /* window area geometry */
- if(XineramaIsActive(dpy) && (info = XineramaQueryScreens(dpy, &n))) {
- nmons = (unsigned int)n;
- for(c = clients; c; c = c->next)
- if(c->mon >= nmons)
- c->mon = nmons - 1;
- if(!(mon = (Monitor *)realloc(mon, sizeof(Monitor) * nmons)))
- die("fatal: could not realloc() %u bytes\n", sizeof(Monitor) * nmons);
- pquery = XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui);
- for(i = 0; i < nmons; 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;
- 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;
- if(pquery && INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height))
- selmon = &mon[i];
+#ifdef XINERAMA
+ XineramaScreenInfo *info = NULL;
+ Bool *flags = NULL;
+
+ if(XineramaIsActive(dpy))
+ info = XineramaQueryScreens(dpy, &n);
+ flags = (Bool *)malloc(sizeof(Bool) * n);
+ for(i = 0; i < n; i++)
+ flags[i] = False;
+ /* next double-loop seeks any combination of retrieved Xinerama info
+ * with existing monitors, this is used to avoid unnecessary
+ * re-allocations of monitor structs */
+ for(i = 0, nn = n; i < n; i++)
+ for(j = 0, m = mons; m; m = m->next, j++)
+ if(!flags[j]) {
+ if((flags[j] = (
+ info[i].x_org == m->mx
+ && info[i].y_org == m->my
+ && info[i].width == m->mw
+ && info[i].height == m->mh)
+ ))
+ --nn;
+ }
+ if(nn == 0) { /* no need to re-allocate monitors */
+ j = 0;
+ for(i = 0, m = mons; m; m = m->next, i++) {
+ m->num = info[i].screen_number;
+ if(info[i].x_org != m->mx
+ || info[i].y_org != m->my
+ || info[i].width != m->mw
+ || info[i].height != m->mh)
+ {
+ m->mx = m->wx = info[i].x_org;
+ m->my = m->wy = info[i].y_org;
+ m->mw = m->ww = info[i].width;
+ m->mh = m->wh = info[i].height;
+ updatebarpos(m);
+ j++;
+ }
+ }
+ XFree(info);
+ free(flags);
+ return j > 0;
+ }
+ /* next algorithm only considers unique geometries as separate screens */
+ for(i = 0; i < n; i++)
+ flags[i] = False; /* used for ignoring certain monitors */
+ for(i = 0, nn = n; i < n; i++)
+ for(j = 0; j < n; j++)
+ if(i != j && !flags[i]) {
+ if((flags[i] = (
+ info[i].x_org == info[j].x_org
+ && info[i].y_org == info[j].y_org
+ && info[i].width == info[j].width
+ && info[i].height == info[j].height)
+ ))
+ --nn;
+ }
+#endif /* XINERAMA */
+ /* allocate monitor(s) for the new geometry setup */
+ for(i = 0; i < nn; i++) {
+ if(!(m = (Monitor *)malloc(sizeof(Monitor))))
+ die("fatal: could not malloc() %u bytes\n", sizeof(Monitor));
+ m->next = newmons;
+ newmons = m;
+ }
+ /* initialise monitor(s) */
+#ifdef XINERAMA
+ if(XineramaIsActive(dpy)) {
+ for(i = 0, m = newmons; m && i < n; i++) {
+ if(!flags[i]) { /* only use screens that aren't dublettes */
+ m->num = info[i].screen_number;
+ m->mx = m->wx = info[i].x_org;
+ m->my = m->wy = info[i].y_org;
+ m->mw = m->ww = info[i].width;
+ m->mh = m->wh = info[i].height;
+ m = m->next;
+ }