diff options
| author | Mitch Riedstra <mitch@riedstra.us> | 2020-11-01 08:25:00 -0500 |
|---|---|---|
| committer | Mitch Riedstra <mitch@riedstra.us> | 2020-11-01 08:25:00 -0500 |
| commit | 53a51c602342e302005800bbe7e986b0cbb72eac (patch) | |
| tree | 83a312eb686785af7cb1308cfdb58404261383b8 /layouts.c | |
| parent | 82a89c4ab4d1485b9ff352fdc11238d19b72f564 (diff) | |
| download | dwm-53a51c602342e302005800bbe7e986b0cbb72eac.tar.gz dwm-53a51c602342e302005800bbe7e986b0cbb72eac.tar.xz | |
Add a new grid layout ( https://dwm.suckless.org/patches/gridmode/ )
Diffstat (limited to 'layouts.c')
| -rw-r--r-- | layouts.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/layouts.c b/layouts.c new file mode 100644 index 0000000..d26acf3 --- /dev/null +++ b/layouts.c @@ -0,0 +1,27 @@ +void +grid(Monitor *m) { + unsigned int i, n, cx, cy, cw, ch, aw, ah, 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); + for(i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next)) { + cx = m->wx + (i / rows) * cw; + cy = m->wy + (i % rows) * ch; + /* adjust height/width of last row/column's windows */ + ah = ((i + 1) % rows == 0) ? m->wh - ch * rows : 0; + aw = (i >= rows * (cols - 1)) ? m->ww - cw * cols : 0; + resize(c, cx, cy, cw - 2 * c->bw + aw, ch - 2 * c->bw + ah, False); + i++; + } +} |
