From bfa185fac49d62f4d2f313df0cb7cd98a7546ca5 Mon Sep 17 00:00:00 2001 From: Sravan Balaji Date: Sun, 30 Aug 2020 13:43:21 -0400 Subject: [PATCH] gridmode patch - Apply gridmode patch - Add patch link to README - Add new layout keybinding to man page --- README.md | 1 + config.h | 4 ++++ dwm.1 | 3 +++ layouts.c | 27 +++++++++++++++++++++++++++ 4 files changed, 35 insertions(+) create mode 100644 layouts.c diff --git a/README.md b/README.md index 90a8872..d79ae81 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ and (re)compiling the source code. * [autostart](https://dwm.suckless.org/patches/autostart/) * [centeredmaster](https://dwm.suckless.org/patches/centeredmaster/) * [combo](https://dwm.suckless.org/patches/combo/) +* [gridmode](https://dwm.suckless.org/patches/gridmode/) * [movestack](https://dwm.suckless.org/patches/movestack/) * [ru_gaps](https://dwm.suckless.org/patches/ru_gaps/) * [systray](https://dwm.suckless.org/patches/systray/) diff --git a/config.h b/config.h index 14b41e8..9723c0a 100644 --- a/config.h +++ b/config.h @@ -44,6 +44,7 @@ static const float mfact = 0.55; /* factor of master area size [0.05..0.95] static const int nmaster = 1; /* number of clients in master area */ static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */ +#include "layouts.c" static const Layout layouts[] = { /* symbol arrange function */ { "[]=", tile }, /* first entry is default */ @@ -51,6 +52,7 @@ static const Layout layouts[] = { { "[M]", monocle }, { "|M|", centeredmaster }, { ">M>", centeredfloatingmaster }, + { "HHH", grid }, }; /* key definitions */ @@ -83,6 +85,7 @@ static const char *playernextcmd[] = { "playerctl", "--player=playerctld", "nex static const char *playerprevcmd[] = { "playerctl", "--player=playerctld", "previous", NULL }; static const char *flameshotcmd[] = { "flameshot", "gui", NULL }; +/* key definitions */ static Key keys[] = { /* modifier key function argument */ { MODKEY, XK_p, spawn, {.v = rofiruncmd} }, @@ -108,6 +111,7 @@ static Key keys[] = { { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, { MODKEY, XK_u, setlayout, {.v = &layouts[3]} }, { MODKEY, XK_o, setlayout, {.v = &layouts[4]} }, + { MODKEY, XK_g, setlayout, {.v = &layouts[5]} }, { MODKEY, XK_space, setlayout, {0} }, { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, { MODKEY, XK_0, view, {.ui = ~0} }, diff --git a/dwm.1 b/dwm.1 index 6c0f349..a6d4fbc 100644 --- a/dwm.1 +++ b/dwm.1 @@ -131,6 +131,9 @@ Sets centered master layout. .B Mod1\-o Sets centered floating master layout. .TP +.B Mod1\-g +Sets grid layout. +.TP .B Mod1\-space Toggles between current and previous layout. .TP 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++; + } +}