layout_nrowgrid.c (2151B)
1 #if VANITYGAPS_PATCH 2 void 3 nrowgrid(Monitor *m) 4 { 5 unsigned int n = 0, i = 0, ri = 0, ci = 0; /* counters */ 6 int oh, ov, ih, iv; /* vanitygap settings */ 7 unsigned int cx, cy, cw, ch; /* client geometry */ 8 unsigned int uw = 0, uh = 0, uc = 0; /* utilization trackers */ 9 unsigned int cols, rows = m->nmaster + 1; 10 Client *c; 11 12 /* count clients */ 13 getgaps(m, &oh, &ov, &ih, &iv, &n); 14 15 /* nothing to do here */ 16 if (n == 0) 17 return; 18 19 /* force 2 clients to always split vertically */ 20 if (FORCE_VSPLIT && n == 2) 21 rows = 1; 22 23 /* never allow empty rows */ 24 if (n < rows) 25 rows = n; 26 27 /* define first row */ 28 cols = n / rows; 29 uc = cols; 30 cy = m->wy + oh; 31 ch = (m->wh - 2*oh - ih*(rows - 1)) / rows; 32 uh = ch; 33 34 for (c = nexttiled(m->clients); c; c = nexttiled(c->next), i++, ci++) { 35 if (ci == cols) { 36 uw = 0; 37 ci = 0; 38 ri++; 39 40 /* next row */ 41 cols = (n - uc) / (rows - ri); 42 uc += cols; 43 cy = m->wy + oh + uh + ih; 44 uh += ch + ih; 45 } 46 47 cx = m->wx + ov + uw; 48 cw = (m->ww - 2*ov - uw) / (cols - ci); 49 uw += cw + iv; 50 51 resize(c, cx, cy, cw - (2*c->bw), ch - (2*c->bw), 0); 52 } 53 } 54 #else 55 void 56 nrowgrid(Monitor *m) 57 { 58 unsigned int n = 0, i = 0, ri = 0, ci = 0; /* counters */ 59 unsigned int cx, cy, cw, ch; /* client geometry */ 60 unsigned int uw = 0, uh = 0, uc = 0; /* utilization trackers */ 61 unsigned int cols, rows = m->nmaster + 1; 62 Client *c; 63 64 for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); 65 if (n == 0) 66 return; 67 68 /* force 2 clients to always split vertically */ 69 if (FORCE_VSPLIT && n == 2) 70 rows = 1; 71 72 /* never allow empty rows */ 73 if (n < rows) 74 rows = n; 75 76 /* define first row */ 77 cols = n / rows; 78 uc = cols; 79 cy = m->wy; 80 ch = m->wh / rows; 81 uh = ch; 82 83 for (c = nexttiled(m->clients); c; c = nexttiled(c->next), i++, ci++) { 84 if (ci == cols) { 85 uw = 0; 86 ci = 0; 87 ri++; 88 89 /* next row */ 90 cols = (n - uc) / (rows - ri); 91 uc += cols; 92 cy = m->wy + uh; 93 uh += ch; 94 } 95 96 cx = m->wx + uw; 97 cw = (m->ww - uw) / (cols - ci); 98 uw += cw; 99 100 resize(c, cx, cy, cw - (2*c->bw), ch - (2*c->bw), 0); 101 } 102 } 103 #endif 104