commit 67101c1a40ed256fa88f052fd48a1f1f0238d713
parent 8fbb6ab3d8e6434c456afc9bccd7b1eb1a14a60b
Author: elbachir-one <bachiralfa@gmail.com>
Date: Sun, 22 Sep 2024 05:26:01 +0100
[dwm][patch][autoswitch] fixed manual switch of monocle mode
Diffstat:
3 files changed, 159 insertions(+), 142 deletions(-)
diff --git a/dwm.suckless.org/patches/autoswitch/dwm-autoswitch-20240919-5096afab.diff b/dwm.suckless.org/patches/autoswitch/dwm-autoswitch-20240919-5096afab.diff
@@ -1,141 +0,0 @@
-From 5096afab5ccc582ba8c25f795e44a5e4c4761925 Mon Sep 17 00:00:00 2001
-From: elbachir-one <bachiralfa@gmail.com>
-Date: Thu, 19 Sep 2024 05:28:42 +0100
-Subject: [PATCH] Automatically switch to monocle mode after opening N window
-
----
- config.def.h | 7 +++---
- dwm.c | 62 ++++++++++++++++++++++++++++++++++++++--------------
- 2 files changed, 49 insertions(+), 20 deletions(-)
-
-diff --git a/config.def.h b/config.def.h
-index 9efa774..32fafc9 100644
---- a/config.def.h
-+++ b/config.def.h
-@@ -5,6 +5,7 @@ static const unsigned int borderpx = 1; /* border pixel of windows */
- static const unsigned int snap = 32; /* snap pixel */
- static const int showbar = 1; /* 0 means no bar */
- static const int topbar = 1; /* 0 means bottom bar */
-+static const int monoclemode = 4; /* automatically switch to monocle mode after opening 4 windows */
- static const char *fonts[] = { "monospace:size=10" };
- static const char dmenufont[] = "monospace:size=10";
- static const char col_gray1[] = "#222222";
-@@ -40,8 +41,8 @@ static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen win
- static const Layout layouts[] = {
- /* symbol arrange function */
- { "[]=", tile }, /* first entry is default */
-- { "><>", NULL }, /* no layout function means floating behavior */
- { "[M]", monocle },
-+ { "><>", NULL }, /* no layout function means floating behavior */
- };
-
- /* key definitions */
-@@ -75,8 +76,8 @@ static const Key keys[] = {
- { MODKEY, XK_Tab, view, {0} },
- { MODKEY|ShiftMask, XK_c, killclient, {0} },
- { MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
-- { MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
-- { MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
-+ { MODKEY, XK_m, setlayout, {.v = &layouts[1]} },
-+ { MODKEY, XK_f, setlayout, {.v = &layouts[2]} },
- { MODKEY, XK_space, setlayout, {0} },
- { MODKEY|ShiftMask, XK_space, togglefloating, {0} },
- { MODKEY, XK_0, view, {.ui = ~0 } },
-diff --git a/dwm.c b/dwm.c
-index 67c6b2b..f8add6d 100644
---- a/dwm.c
-+++ b/dwm.c
-@@ -227,6 +227,7 @@ static void updatetitle(Client *c);
- static void updatewindowtype(Client *c);
- static void updatewmhints(Client *c);
- static void view(const Arg *arg);
-+static int visibleclientcount(Monitor *m);
- static Client *wintoclient(Window w);
- static Monitor *wintomon(Window w);
- static int xerror(Display *dpy, XErrorEvent *ee);
-@@ -382,15 +383,25 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact)
- void
- arrange(Monitor *m)
- {
-- if (m)
-- showhide(m->stack);
-- else for (m = mons; m; m = m->next)
-+ if (!m)
-+ for (m = mons; m; m = m->next)
-+ showhide(m->stack);
-+ else
- showhide(m->stack);
-- if (m) {
-- arrangemon(m);
-- restack(m);
-- } else for (m = mons; m; m = m->next)
-- arrangemon(m);
-+
-+ for (Monitor *mon = (m ? m : mons); mon; mon = (m ? NULL : mon->next)) {
-+ unsigned int n = visibleclientcount(mon);
-+
-+ if (n >= monoclemode && mon->lt[mon->sellt]->arrange != monocle)
-+ setlayout(&(Arg) {.v = &layouts[1]});
-+
-+ if (n < monoclemode && mon->lt[mon->sellt]->arrange == monocle)
-+ setlayout(&(Arg) {.v = &layouts[0]});
-+
-+ arrangemon(mon);
-+ if (!m)
-+ restack(mon);
-+ }
- }
-
- void
-@@ -1510,15 +1521,19 @@ setfullscreen(Client *c, int fullscreen)
- void
- setlayout(const Arg *arg)
- {
-- if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
-- selmon->sellt ^= 1;
-- if (arg && arg->v)
-- selmon->lt[selmon->sellt] = (Layout *)arg->v;
-- strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol);
-- if (selmon->sel)
-- arrange(selmon);
-- else
-- drawbar(selmon);
-+ if (!arg || !arg->v)
-+ return;
-+
-+ Layout *newlayout = (Layout *)arg->v;
-+ if (newlayout != selmon->lt[selmon->sellt]) {
-+ selmon->lt[selmon->sellt] = newlayout;
-+ strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof(selmon->ltsymbol));
-+ selmon->ltsymbol[sizeof(selmon->ltsymbol) - 1] = '\0';
-+ if (selmon->sel)
-+ arrange(selmon);
-+ else
-+ drawbar(selmon);
-+ }
- }
-
- /* arg > 1.0 will set mfact absolutely */
-@@ -2062,6 +2077,19 @@ view(const Arg *arg)
- arrange(selmon);
- }
-
-+int
-+visibleclientcount(Monitor *m)
-+{
-+ unsigned int count = 0;
-+ Client *c;
-+ for (c = m->clients; c; c = c->next) {
-+ if (ISVISIBLE(c)) {
-+ count++;
-+ }
-+ }
-+ return count;
-+}
-+
- Client *
- wintoclient(Window w)
- {
---
-2.46.0
-
diff --git a/dwm.suckless.org/patches/autoswitch/dwm-autoswitch-20240921-c282f865.diff b/dwm.suckless.org/patches/autoswitch/dwm-autoswitch-20240921-c282f865.diff
@@ -0,0 +1,158 @@
+From c282f86559f3c7858e34888c1fa0204c22ede89c Mon Sep 17 00:00:00 2001
+From: elbachir-one <bachiralfa@gmail.com>
+Date: Sat, 21 Sep 2024 22:59:53 +0100
+Subject: [PATCH] Allowing manual switch of monocle mode.
+
+---
+ config.def.h | 7 ++---
+ dwm.c | 72 +++++++++++++++++++++++++++++++++++++++-------------
+ 2 files changed, 59 insertions(+), 20 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index 9efa774..32fafc9 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -5,6 +5,7 @@ static const unsigned int borderpx = 1; /* border pixel of windows */
+ static const unsigned int snap = 32; /* snap pixel */
+ static const int showbar = 1; /* 0 means no bar */
+ static const int topbar = 1; /* 0 means bottom bar */
++static const int monoclemode = 4; /* automatically switch to monocle mode after opening 4 windows */
+ static const char *fonts[] = { "monospace:size=10" };
+ static const char dmenufont[] = "monospace:size=10";
+ static const char col_gray1[] = "#222222";
+@@ -40,8 +41,8 @@ static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen win
+ static const Layout layouts[] = {
+ /* symbol arrange function */
+ { "[]=", tile }, /* first entry is default */
+- { "><>", NULL }, /* no layout function means floating behavior */
+ { "[M]", monocle },
++ { "><>", NULL }, /* no layout function means floating behavior */
+ };
+
+ /* key definitions */
+@@ -75,8 +76,8 @@ static const Key keys[] = {
+ { MODKEY, XK_Tab, view, {0} },
+ { MODKEY|ShiftMask, XK_c, killclient, {0} },
+ { MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
+- { MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
+- { MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
++ { MODKEY, XK_m, setlayout, {.v = &layouts[1]} },
++ { MODKEY, XK_f, setlayout, {.v = &layouts[2]} },
+ { MODKEY, XK_space, setlayout, {0} },
+ { MODKEY|ShiftMask, XK_space, togglefloating, {0} },
+ { MODKEY, XK_0, view, {.ui = ~0 } },
+diff --git a/dwm.c b/dwm.c
+index 67c6b2b..9561896 100644
+--- a/dwm.c
++++ b/dwm.c
+@@ -130,6 +130,7 @@ struct Monitor {
+ Monitor *next;
+ Window barwin;
+ const Layout *lt[2];
++ int manualswitch;
+ };
+
+ typedef struct {
+@@ -227,6 +228,7 @@ static void updatetitle(Client *c);
+ static void updatewindowtype(Client *c);
+ static void updatewmhints(Client *c);
+ static void view(const Arg *arg);
++static int visibleclientcount(Monitor *m);
+ static Client *wintoclient(Window w);
+ static Monitor *wintomon(Window w);
+ static int xerror(Display *dpy, XErrorEvent *ee);
+@@ -382,15 +384,31 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact)
+ void
+ arrange(Monitor *m)
+ {
+- if (m)
+- showhide(m->stack);
+- else for (m = mons; m; m = m->next)
++ if (!m)
++ for (m = mons; m; m = m->next)
++ showhide(m->stack);
++ else
+ showhide(m->stack);
+- if (m) {
+- arrangemon(m);
+- restack(m);
+- } else for (m = mons; m; m = m->next)
+- arrangemon(m);
++
++ for (Monitor *mon = (m ? m : mons); mon; mon = (m ? NULL : mon->next)) {
++ unsigned int n = visibleclientcount(mon);
++
++ if (!mon->manualswitch) {
++ if (n >= monoclemode && mon->lt[mon->sellt]->arrange != monocle) {
++ setlayout(&(Arg) {.v = &layouts[1]});
++ } else if (n < monoclemode && mon->lt[mon->sellt]->arrange == monocle) {
++ setlayout(&(Arg) {.v = &layouts[0]});
++ }
++ }
++
++ if (mon->manualswitch && (n < monoclemode || n >= monoclemode)) {
++ mon->manualswitch = 0;
++ }
++
++ arrangemon(mon);
++ if (!m)
++ restack(mon);
++ }
+ }
+
+ void
+@@ -1510,15 +1528,22 @@ setfullscreen(Client *c, int fullscreen)
+ void
+ setlayout(const Arg *arg)
+ {
+- if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
+- selmon->sellt ^= 1;
+- if (arg && arg->v)
+- selmon->lt[selmon->sellt] = (Layout *)arg->v;
+- strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol);
+- if (selmon->sel)
+- arrange(selmon);
+- else
+- drawbar(selmon);
++ if (!arg || !arg->v)
++ return;
++
++ Layout *newlayout = (Layout *)arg->v;
++ if (newlayout != selmon->lt[selmon->sellt]) {
++ selmon->lt[selmon->sellt] = newlayout;
++ strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof(selmon->ltsymbol));
++ selmon->ltsymbol[sizeof(selmon->ltsymbol) - 1] = '\0';
++
++ selmon->manualswitch = 1;
++
++ if (selmon->sel)
++ arrange(selmon);
++ else
++ drawbar(selmon);
++ }
+ }
+
+ /* arg > 1.0 will set mfact absolutely */
+@@ -2062,6 +2087,19 @@ view(const Arg *arg)
+ arrange(selmon);
+ }
+
++int
++visibleclientcount(Monitor *m)
++{
++ unsigned int count = 0;
++ Client *c;
++ for (c = m->clients; c; c = c->next) {
++ if (ISVISIBLE(c)) {
++ count++;
++ }
++ }
++ return count;
++}
++
+ Client *
+ wintoclient(Window w)
+ {
+--
+2.46.0
+
diff --git a/dwm.suckless.org/patches/autoswitch/index.md b/dwm.suckless.org/patches/autoswitch/index.md
@@ -14,7 +14,7 @@ This patch is inspired by a Reddit post [this post](https://www.reddit.com/r/suc
Download
--------
-* [dwm-autoswitch-20240919-5096afab.diff](dwm-autoswitch-20240919-5096afab.diff) (2024-09-19)
+* [dwm-autoswitch-20240921-c282f865.diff](dwm-autoswitch-20240921-c282f865.diff) (2024-09-21)
Author
------