summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMalfurious <m@lfurio.us>2024-02-29 11:52:31 -0500
committerMatt Hunter <m@lfurio.us>2026-01-18 00:18:46 -0500
commitcc76324a76064f130d0bdce6b6af266162774b60 (patch)
treea052dd100e7b1c3a93cbe991e80e9003cb1c117a
parentbeed57c13b21878f27778d3e76dd60f656fe9092 (diff)
downloaddwm-cc76324a76064f130d0bdce6b6af266162774b60.tar.gz
dwm-cc76324a76064f130d0bdce6b6af266162774b60.zip
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.
-rw-r--r--config.def.h1
-rw-r--r--dwm.c16
2 files changed, 17 insertions, 0 deletions
diff --git a/config.def.h b/config.def.h
index af11a0e..d969b02 100644
--- a/config.def.h
+++ b/config.def.h
@@ -93,6 +93,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 6d2c4fd..d8f0f96 100644
--- a/dwm.c
+++ b/dwm.c
@@ -201,6 +201,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)
}
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)
{
if (applysizehints(c, &x, &y, &w, &h, interact))
@@ -2062,6 +2075,9 @@ unmanage(Client *c, int destroyed)
focus(NULL);
updateclientlist();
arrange(m);
+
+ if (nexttiled(m->clients) == NULL)
+ resetlayout(NULL);
}
void