layout_gapplessgrid.c (2246B)
1 #if VANITYGAPS_PATCH 2 void 3 gaplessgrid(Monitor *m) 4 { 5 unsigned int i, n; 6 int x, y, cols, rows, ch, cw, cn, rn, rrest, crest; // counters 7 int oh, ov, ih, iv; 8 Client *c; 9 10 getgaps(m, &oh, &ov, &ih, &iv, &n); 11 if (n == 0) 12 return; 13 14 /* grid dimensions */ 15 for (cols = 0; cols <= n/2; cols++) 16 if (cols*cols >= n) 17 break; 18 if (n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */ 19 cols = 2; 20 rows = n/cols; 21 cn = rn = 0; // reset column no, row no, client count 22 23 ch = (m->wh - 2*oh - ih * (rows - 1)) / rows; 24 cw = (m->ww - 2*ov - iv * (cols - 1)) / cols; 25 rrest = (m->wh - 2*oh - ih * (rows - 1)) - ch * rows; 26 crest = (m->ww - 2*ov - iv * (cols - 1)) - cw * cols; 27 x = m->wx + ov; 28 y = m->wy + oh; 29 30 for (i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) { 31 if (i/rows + 1 > cols - n%cols) { 32 rows = n/cols + 1; 33 ch = (m->wh - 2*oh - ih * (rows - 1)) / rows; 34 rrest = (m->wh - 2*oh - ih * (rows - 1)) - ch * rows; 35 } 36 resize(c, 37 x, 38 y + rn*(ch + ih) + MIN(rn, rrest), 39 cw + (cn < crest ? 1 : 0) - 2*c->bw, 40 ch + (rn < rrest ? 1 : 0) - 2*c->bw, 41 0); 42 rn++; 43 if (rn >= rows) { 44 rn = 0; 45 x += cw + ih + (cn < crest ? 1 : 0); 46 cn++; 47 } 48 } 49 } 50 #else 51 void 52 gaplessgrid(Monitor *m) 53 { 54 unsigned int i, n; 55 int x, y, cols, rows, ch, cw, cn, rn, rrest, crest; // counters 56 Client *c; 57 58 for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); 59 if (n == 0) 60 return; 61 62 /* grid dimensions */ 63 for (cols = 0; cols <= n/2; cols++) 64 if (cols*cols >= n) 65 break; 66 if (n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */ 67 cols = 2; 68 rows = n/cols; 69 cn = rn = 0; // reset column no, row no, client count 70 71 ch = m->wh / rows; 72 cw = m->ww / cols; 73 rrest = m->wh - ch * rows; 74 crest = m->ww - cw * cols; 75 x = m->wx; 76 y = m->wy; 77 78 for (i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) { 79 if (i/rows + 1 > cols - n%cols) { 80 rows = n/cols + 1; 81 ch = m->wh / rows; 82 rrest = m->wh - ch * rows; 83 } 84 resize(c, 85 x, 86 y + rn*ch + MIN(rn, rrest), 87 cw + (cn < crest ? 1 : 0) - 2*c->bw, 88 ch + (rn < rrest ? 1 : 0) - 2*c->bw, 89 0); 90 rn++; 91 if (rn >= rows) { 92 rn = 0; 93 x += cw + (cn < crest ? 1 : 0); 94 cn++; 95 } 96 } 97 } 98 #endif 99