layout_grid.c (1764B)
1 #if VANITYGAPS_PATCH 2 void 3 grid(Monitor *m) 4 { 5 unsigned int i, n; 6 int cx, cy, cw, ch, cc, cr, chrest, cwrest, cols, rows; 7 int oh, ov, ih, iv; 8 Client *c; 9 10 getgaps(m, &oh, &ov, &ih, &iv, &n); 11 12 /* grid dimensions */ 13 for (rows = 0; rows <= n/2; rows++) 14 if (rows*rows >= n) 15 break; 16 cols = (rows && (rows - 1) * rows >= n) ? rows - 1 : rows; 17 18 /* window geoms (cell height/width) */ 19 ch = (m->wh - 2*oh - ih * (rows - 1)) / (rows ? rows : 1); 20 cw = (m->ww - 2*ov - iv * (cols - 1)) / (cols ? cols : 1); 21 chrest = (m->wh - 2*oh - ih * (rows - 1)) - ch * rows; 22 cwrest = (m->ww - 2*ov - iv * (cols - 1)) - cw * cols; 23 for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) { 24 cc = i / rows; 25 cr = i % rows; 26 cx = m->wx + ov + cc * (cw + iv) + MIN(cc, cwrest); 27 cy = m->wy + oh + cr * (ch + ih) + MIN(cr, chrest); 28 resize(c, cx, cy, cw + (cc < cwrest ? 1 : 0) - 2*c->bw, ch + (cr < chrest ? 1 : 0) - 2*c->bw, False); 29 } 30 } 31 #else 32 void 33 grid(Monitor *m) 34 { 35 unsigned int i, n; 36 int cx, cy, cw, ch, cc, cr, chrest, cwrest, cols, rows; 37 Client *c; 38 39 for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); 40 41 /* grid dimensions */ 42 for (rows = 0; rows <= n/2; rows++) 43 if (rows*rows >= n) 44 break; 45 cols = (rows && (rows - 1) * rows >= n) ? rows - 1 : rows; 46 47 /* window geoms (cell height/width) */ 48 ch = m->wh / (rows ? rows : 1); 49 cw = m->ww / (cols ? cols : 1); 50 chrest = m->wh - ch * rows; 51 cwrest = m->ww - cw * cols; 52 for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) { 53 cc = i / rows; 54 cr = i % rows; 55 cx = m->wx + cc * cw + MIN(cc, cwrest); 56 cy = m->wy + cr * ch + MIN(cr, chrest); 57 resize(c, cx, cy, cw + (cc < cwrest ? 1 : 0) - 2*c->bw, ch + (cr < chrest ? 1 : 0) - 2*c->bw, False); 58 } 59 } 60 #endif 61