- 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++;
- }
- }
+ if(XineramaIsActive(dpy)) {
+ int i, j, n, nn;
+ Client *c;
+ Monitor *m;
+ XineramaScreenInfo *info = XineramaQueryScreens(dpy, &nn);
+ XineramaScreenInfo *unique = NULL;
+
+ for(n = 0, m = mons; m; m = m->next, n++);
+ /* only consider unique geometries as separate screens */
+ if(!(unique = (XineramaScreenInfo *)malloc(sizeof(XineramaScreenInfo) * nn)))
+ die("fatal: could not malloc() %u bytes\n", sizeof(XineramaScreenInfo) * nn);
+ for(i = 0, j = 0; i < nn; i++)
+ if(isuniquegeom(unique, j, &info[i]))
+ memcpy(&unique[j++], &info[i], sizeof(XineramaScreenInfo));