From c487d2524a1c8429b74285ef05557fb408483da0 Mon Sep 17 00:00:00 2001 From: Malfurious Date: Thu, 29 Feb 2024 11:52:31 -0500 Subject: patch: resetlayout Resets the layout and mfact if there is only one client visible. 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. This patch also resets nmaster to its default value as well. --- config.def.h | 1 + dwm.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/config.def.h b/config.def.h index c0dfdd4..9f6f41e 100644 --- a/config.def.h +++ b/config.def.h @@ -97,6 +97,7 @@ static const Key keys[] = { { MODKEY, XK_l, setmfact, {.f = +0.05} }, { MODKEY|ShiftMask, XK_j, pushdown, {0} }, { MODKEY|ShiftMask, XK_k, pushup, {0} }, + { MODKEY, XK_r, resetlayout, {0} }, { MODKEY, XK_Return, zoom, {0} }, { MODKEY, XK_Tab, view, {0} }, { MODKEY, XK_q, killclient, {0} }, diff --git a/dwm.c b/dwm.c index 51736fe..11bce9a 100644 --- a/dwm.c +++ b/dwm.c @@ -202,6 +202,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); @@ -1490,6 +1491,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) { @@ -2062,6 +2075,9 @@ unmanage(Client *c, int destroyed) focus(NULL); updateclientlist(); arrange(m); + + if (nexttiled(m->clients) == NULL) + resetlayout(NULL); } void -- cgit v1.2.3