From 1a4d4b0f6cd663c3dee2b6167993cd709cfc91cc Mon Sep 17 00:00:00 2001 From: Malfurious Date: Tue, 8 Feb 2022 06:52:48 -0500 Subject: patch: resetlayout Resets the layout and mfact if there is only one client visible. This is an edited patch that also resets nmaster to its default value as well. This applies cleanly to vanilla dwm, but is mostly only useful alongside the pertag patch, since otherwise all layouts and mfacts will be reset. You can also set a binding to trigger this on demand, see the new call to resetlayout in config.def.h. --- dwm.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'dwm.c') diff --git a/dwm.c b/dwm.c index 2af7979..f4965e8 100644 --- a/dwm.c +++ b/dwm.c @@ -197,6 +197,7 @@ static void pushdown(const Arg *arg); static void pushup(const Arg *arg); static void quit(const Arg *arg); static Monitor *recttomon(int x, int y, int w, int h); +static void resetlayout(const Arg *arg); static void resize(Client *c, int x, int y, int w, int h, int interact); static void resizeclient(Client *c, int x, int y, int w, int h); static void resizemouse(const Arg *arg); @@ -1388,6 +1389,18 @@ recttomon(int x, int y, int w, int h) return r; } +void +resetlayout(const Arg *arg) +{ + Arg default_layout = {.v = &layouts[0]}; + Arg default_mfact = {.f = mfact + 1}; + Arg default_nmaster = {.i = nmaster - selmon->nmaster}; + + setlayout(&default_layout); + setmfact(&default_mfact); + incnmaster(&default_nmaster); +} + void resize(Client *c, int x, int y, int w, int h, int interact) { @@ -1405,6 +1418,10 @@ resizeclient(Client *c, int x, int y, int w, int h) c->oldw = c->w; c->w = wc.width = w; c->oldh = c->h; c->h = wc.height = h; wc.border_width = c->bw; + + if ((nexttiled(c->mon->clients) == c) && !(nexttiled(c->next))) + resetlayout(NULL); + XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc); configure(c); XSync(dpy, False); -- cgit v1.2.3