diff options
author | Malfurious <m@lfurio.us> | 2022-01-27 03:34:55 -0500 |
---|---|---|
committer | Malfurious <m@lfurio.us> | 2023-06-03 22:02:57 -0400 |
commit | a89081aab07e0f1fe82c93f0ea1e1bc86b380664 (patch) | |
tree | 0a8ca666683fe007f8177c3857a868db95b2e722 | |
parent | a70fd955bacbc6465d1ed7d523477f0cd4725ab7 (diff) | |
download | dwm-a89081aab07e0f1fe82c93f0ea1e1bc86b380664.tar.gz dwm-a89081aab07e0f1fe82c93f0ea1e1bc86b380664.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 :-)
-rw-r--r-- | config.def.h | 2 | ||||
-rw-r--r-- | dwm.c | 29 |
2 files changed, 31 insertions, 0 deletions
diff --git a/config.def.h b/config.def.h index 477c1d0..a3b6c1a 100644 --- a/config.def.h +++ b/config.def.h @@ -50,6 +50,7 @@ static const Layout layouts[] = { { "|M|", centeredmaster }, { ">M>", centeredfloatingmaster }, { "|||", col }, + { "HHH", grid }, }; /* key definitions */ @@ -95,6 +96,7 @@ static const Key keys[] = { { MODKEY, XK_u, setlayout, {.v = &layouts[3]} }, { MODKEY, XK_o, setlayout, {.v = &layouts[4]} }, { MODKEY, XK_c, setlayout, {.v = &layouts[5]} }, + { MODKEY, XK_g, setlayout, {.v = &layouts[6]} }, { MODKEY, XK_comma, focusmon, {.i = -1 } }, { MODKEY, XK_period, focusmon, {.i = +1 } }, { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, @@ -238,6 +238,7 @@ static void xinitvisual(); static void zoom(const Arg *arg); static void centeredmaster(Monitor *m); static void centeredfloatingmaster(Monitor *m); +static void grid(Monitor *m); /* variables */ static const char broken[] = "broken"; @@ -2329,3 +2330,31 @@ centeredfloatingmaster(Monitor *m) tx += WIDTH(c); } } + +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++; + } +} |