diff options
| author | bakkeby <[email protected]> | 2020-07-15 08:57:30 +0200 |
|---|---|---|
| committer | bakkeby <[email protected]> | 2020-07-15 08:57:30 +0200 |
| commit | 903b32ac8b4a69b37981874f23b15a9f65f2a20d (patch) | |
| tree | b7aff3bdd522721a03cbfdaea8adf15fefd90463 /patch/layout_grid.c | |
| parent | 1584a32063cd252ec726dd18747c5f91f12f8be9 (diff) | |
| download | dwm-flexipatch-903b32ac8b4a69b37981874f23b15a9f65f2a20d.tar.gz dwm-flexipatch-903b32ac8b4a69b37981874f23b15a9f65f2a20d.zip | |
Major refactoring in preparation for bar modules
Diffstat (limited to 'patch/layout_grid.c')
| -rw-r--r-- | patch/layout_grid.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/patch/layout_grid.c b/patch/layout_grid.c new file mode 100644 index 0000000..df19896 --- /dev/null +++ b/patch/layout_grid.c @@ -0,0 +1,60 @@ +#if VANITYGAPS_PATCH +void +grid(Monitor *m) +{ + unsigned int i, n; + int cx, cy, cw, ch, cc, cr, chrest, cwrest, cols, rows; + int oh, ov, ih, iv; + Client *c; + + getgaps(m, &oh, &ov, &ih, &iv, &n); + + /* grid dimensions */ + for (rows = 0; rows <= n/2; rows++) + if (rows*rows >= n) + break; + cols = (rows && (rows - 1) * rows >= n) ? rows - 1 : rows; + + /* window geoms (cell height/width) */ + ch = (m->wh - 2*oh - ih * (rows - 1)) / (rows ? rows : 1); + cw = (m->ww - 2*ov - iv * (cols - 1)) / (cols ? cols : 1); + chrest = (m->wh - 2*oh - ih * (rows - 1)) - ch * rows; + cwrest = (m->ww - 2*ov - iv * (cols - 1)) - cw * cols; + for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) { + cc = i / rows; + cr = i % rows; + cx = m->wx + ov + cc * (cw + iv) + MIN(cc, cwrest); + cy = m->wy + oh + cr * (ch + ih) + MIN(cr, chrest); + resize(c, cx, cy, cw + (cc < cwrest ? 1 : 0) - 2*c->bw, ch + (cr < chrest ? 1 : 0) - 2*c->bw, False); + } +} +#else +void +grid(Monitor *m) +{ + unsigned int i, n; + int cx, cy, cw, ch, cc, cr, chrest, cwrest, cols, rows; + Client *c; + + for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); + + /* grid dimensions */ + for (rows = 0; rows <= n/2; rows++) + if (rows*rows >= n) + break; + cols = (rows && (rows - 1) * rows >= n) ? rows - 1 : rows; + + /* window geoms (cell height/width) */ + ch = m->wh / (rows ? rows : 1); + cw = m->ww / (cols ? cols : 1); + chrest = m->wh - ch * rows; + cwrest = m->ww - cw * cols; + for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) { + cc = i / rows; + cr = i % rows; + cx = m->wx + cc * cw + MIN(cc, cwrest); + cy = m->wy + cr * ch + MIN(cr, chrest); + resize(c, cx, cy, cw + (cc < cwrest ? 1 : 0) - 2*c->bw, ch + (cr < chrest ? 1 : 0) - 2*c->bw, False); + } +} +#endif
\ No newline at end of file |
