From 1e391a31fd2216cf36dd734b41f69b99116164cf Mon Sep 17 00:00:00 2001 From: Jakub Date: Thu, 23 May 2024 19:37:03 -0400 Subject: [PATCH] reset layout patch --- config.def.h | 1 + dwm.c | 14 +++++ patches/behavior/dwm-resetlayout-6.2.diff | 65 +++++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 patches/behavior/dwm-resetlayout-6.2.diff diff --git a/config.def.h b/config.def.h index f4bbe55..fa7d131 100644 --- a/config.def.h +++ b/config.def.h @@ -120,6 +120,7 @@ static const Key keys[] = { { MODKEY, XK_d, incnmaster, {.i = -1 } }, { MODKEY, XK_h, setmfact, {.f = -0.05} }, { MODKEY, XK_l, setmfact, {.f = +0.05} }, + { MODKEY, XK_r, resetlayout, {0} }, { MODKEY, XK_Return, zoom, {0} }, { MODKEY, XK_Tab, view, {0} }, { MODKEY|ShiftMask, XK_c, killclient, {0} }, diff --git a/dwm.c b/dwm.c index ffc5fd5..71988c4 100644 --- a/dwm.c +++ b/dwm.c @@ -223,6 +223,7 @@ static void pop(Client *c); static void propertynotify(XEvent *e); 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); @@ -1735,6 +1736,16 @@ 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}; + + setlayout(&default_layout); + setmfact(&default_mfact); +} + void resize(Client *c, int x, int y, int w, int h, int interact) { @@ -1755,6 +1766,9 @@ resizeclient(Client *c, int x, int y, int w, int h) 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); + for (n = 0, nbc = nexttiled(c->mon->clients); nbc; nbc = nexttiled(nbc->next), n++); if (c->isfloating || c->mon->lt[c->mon->sellt]->arrange == NULL) { diff --git a/patches/behavior/dwm-resetlayout-6.2.diff b/patches/behavior/dwm-resetlayout-6.2.diff new file mode 100644 index 0000000..08747ad --- /dev/null +++ b/patches/behavior/dwm-resetlayout-6.2.diff @@ -0,0 +1,65 @@ +From 4df827a2ec7820f41bdb8576cc39b55fbf35be44 Mon Sep 17 00:00:00 2001 +From: Jack Bird +Date: Mon, 16 Aug 2021 23:25:16 +0100 +Subject: [PATCH] Patch applies cleanly + +--- + config.def.h | 1 + + dwm.c | 15 +++++++++++++++ + 2 files changed, 16 insertions(+) + +diff --git a/config.def.h b/config.def.h +index 1c0b587..5d118cf 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -70,6 +70,7 @@ static Key keys[] = { + { MODKEY, XK_d, incnmaster, {.i = -1 } }, + { MODKEY, XK_h, setmfact, {.f = -0.05} }, + { MODKEY, XK_l, setmfact, {.f = +0.05} }, ++ { MODKEY, XK_r, resetlayout, {0} }, + { MODKEY, XK_Return, zoom, {0} }, + { MODKEY, XK_Tab, view, {0} }, + { MODKEY|ShiftMask, XK_c, killclient, {0} }, +diff --git a/dwm.c b/dwm.c +index 4465af1..77727ea 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -188,6 +188,7 @@ static void pop(Client *); + static void propertynotify(XEvent *e); + 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); +@@ -1265,6 +1266,16 @@ 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}; ++ ++ setlayout(&default_layout); ++ setmfact(&default_mfact); ++} ++ + void + resize(Client *c, int x, int y, int w, int h, int interact) + { +@@ -1282,6 +1293,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); +-- +2.32.0 +