diff options
author | Malfurious <m@lfurio.us> | 2022-01-27 03:34:55 -0500 |
---|---|---|
committer | Malfurious <m@lfurio.us> | 2024-03-05 21:04:47 -0500 |
commit | 74eb25562964b4d42979b82805f01427147f717a (patch) | |
tree | ac1bbc15500af32c88662718d9482a223ad09f72 /dwm.c | |
parent | fc3bd6f412c6bc21b68b997bd58f27ef5ee003ca (diff) | |
download | dwm-74eb25562964b4d42979b82805f01427147f717a.tar.gz dwm-74eb25562964b4d42979b82805f01427147f717a.zip |
patch: gridmode
This patch adds an extra layout mode to dwm called grid in which the
windows are arranged in a grid of equal sizes. It comes in very handy,
especially with tools that operate on multiple windows at once; e.g.
Cluster SSH.
The patch would look a lot uglier without Jukka Salmi's constant help.
Thanks Jukka :-)
Diffstat (limited to 'dwm.c')
-rw-r--r-- | dwm.c | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -244,6 +244,7 @@ static int xerrorstart(Display *dpy, XErrorEvent *ee); static void xinitvisual(); static void zoom(const Arg *arg); static void centeredmaster(Monitor *m); +static void grid(Monitor *m); /* variables */ static const char broken[] = "broken"; @@ -2397,3 +2398,31 @@ centeredmaster(Monitor *m) } } } + +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++; + } +} |