[wiki] [sites] [dwm][patch][bulkill] Add bulkill patch for newest git version dwm (current in dwm-6.4 release). || ysl2

From: <git_AT_suckless.org>
Date: Sun, 29 Oct 2023 10:05:10 +0100

commit 05dfa80b83c30084bacf77c557fef8ba5a04c9ae
Author: ysl2 <www.songli.yu_AT_gmail.com>
Date: Sun Oct 29 17:04:13 2023 +0800

    [dwm][patch][bulkill] Add bulkill patch for newest git version dwm (current in dwm-6.4 release).

diff --git a/dwm.suckless.org/patches/bulkill/dwm-bulkill-20231029-9f88553.diff b/dwm.suckless.org/patches/bulkill/dwm-bulkill-20231029-9f88553.diff
new file mode 100644
index 00000000..611a56dc
--- /dev/null
+++ b/dwm.suckless.org/patches/bulkill/dwm-bulkill-20231029-9f88553.diff
_AT_@ -0,0 +1,86 @@
+From 70a21457fdbcbcdf26efb1329dd29872b7fcd8e3 Mon Sep 17 00:00:00 2001
+From: ysl2 <www.songli.yu_AT_gmail.com>
+Date: Sun, 29 Oct 2023 15:45:05 +0800
+Subject: [PATCH] Give killclient an augument to control the beheviour: arg.ui
+ == 0 for normal kill current client; arg.ui == 1 for kill other clients in
+ current tag (except current focusing client); arg.ui == 2 for kill all
+ clients in current tag (include focusing client).
+
+---
+ config.def.h | 2 ++
+ dwm.c | 30 ++++++++++++++++++++++++------
+ 2 files changed, 26 insertions(+), 6 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index 9efa774..d39e6dd 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -74,6 +74,8 @@ static const Key keys[] = {
+ { MODKEY, XK_Return, zoom, {0} },
+ { MODKEY, XK_Tab, view, {0} },
+ { MODKEY|ShiftMask, XK_c, killclient, {0} },
++ { MODKEY|ControlMask, XK_c, killclient, {.ui = 1} }, // kill unselect
++ { MODKEY|ShiftMask|ControlMask, XK_c, killclient, {.ui = 2} }, // killall
+ { MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
+ { MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
+ { MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
+diff --git a/dwm.c b/dwm.c
+index f1d86b2..011744d 100644
+--- a/dwm.c
++++ b/dwm.c
+_AT_@ -177,6 +177,7 @@ static void grabbuttons(Client *c, int focused);
+ static void grabkeys(void);
+ static void incnmaster(const Arg *arg);
+ static void keypress(XEvent *e);
++static void killthis(Client *c);
+ static void killclient(const Arg *arg);
+ static void manage(Window w, XWindowAttributes *wa);
+ static void mappingnotify(XEvent *e);
+_AT_@ -1013,21 +1014,38 @@ keypress(XEvent *e)
+ }
+
+ void
+-killclient(const Arg *arg)
+-{
+- if (!selmon->sel)
+- return;
+- if (!sendevent(selmon->sel, wmatom[WMDelete])) {
++killthis(Client *c) {
++ if (!sendevent(c, wmatom[WMDelete])) {
+ XGrabServer(dpy);
+ XSetErrorHandler(xerrordummy);
+ XSetCloseDownMode(dpy, DestroyAll);
+- XKillClient(dpy, selmon->sel->win);
++ XKillClient(dpy, c->win);
+ XSync(dpy, False);
+ XSetErrorHandler(xerror);
+ XUngrabServer(dpy);
+ }
+ }
+
++void
++killclient(const Arg *arg)
++{
++ Client *c;
++
++ if (!selmon->sel)
++ return;
++
++ if (!arg->ui || arg->ui == 0) {
++ killthis(selmon->sel);
++ return;
++ }
++
++ for (c = selmon->clients; c; c = c->next) {
++ if (!ISVISIBLE(c) || (arg->ui == 1 && c == selmon->sel))
++ continue;
++ killthis(c);
++ }
++}
++
+ void
+ manage(Window w, XWindowAttributes *wa)
+ {
+--
+2.20.1
+
diff --git a/dwm.suckless.org/patches/bulkill/dwm-bulkill-safe-20231029-9f88553.diff b/dwm.suckless.org/patches/bulkill/dwm-bulkill-safe-20231029-9f88553.diff
new file mode 100644
index 00000000..9ca9ae06
--- /dev/null
+++ b/dwm.suckless.org/patches/bulkill/dwm-bulkill-safe-20231029-9f88553.diff
_AT_@ -0,0 +1,78 @@
+From c40d70e238b7e5e8ebfd16b435c56af55a541912 Mon Sep 17 00:00:00 2001
+From: ysl2 <www.songli.yu_AT_gmail.com>
+Date: Sun, 29 Oct 2023 15:39:46 +0800
+Subject: [PATCH] Bulk kill: arg.ui == 0 for normal kill current client; arg.ui
+ == 1 for kill other clients in current tag (except current focusing client);
+ arg.ui == 2 for kill all clients in current tag (include focusing client).
+
+---
+ bulkill.c | 35 +++++++++++++++++++++++++++++++++++
+ config.def.h | 3 +++
+ 2 files changed, 38 insertions(+)
+ create mode 100644 bulkill.c
+
+diff --git a/bulkill.c b/bulkill.c
+new file mode 100644
+index 0000000..732852e
+--- /dev/null
++++ b/bulkill.c
+_AT_@ -0,0 +1,35 @@
++static void killthis(Client *c);
++static void bulkill(const Arg *arg);
++
++void
++killthis(Client *c) {
++ if (!sendevent(c, wmatom[WMDelete])) {
++ XGrabServer(dpy);
++ XSetErrorHandler(xerrordummy);
++ XSetCloseDownMode(dpy, DestroyAll);
++ XKillClient(dpy, c->win);
++ XSync(dpy, False);
++ XSetErrorHandler(xerror);
++ XUngrabServer(dpy);
++ }
++}
++
++void
++bulkill(const Arg *arg)
++{
++ Client *c;
++
++ if (!selmon->sel)
++ return;
++
++ if (!arg->ui || arg->ui == 0) {
++ killthis(selmon->sel);
++ return;
++ }
++
++ for (c = selmon->clients; c; c = c->next) {
++ if (!ISVISIBLE(c) || (arg->ui == 1 && c == selmon->sel))
++ continue;
++ killthis(c);
++ }
++}
+diff --git a/config.def.h b/config.def.h
+index 9efa774..28cfd78 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -60,6 +60,7 @@ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn()
+ static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
+ static const char *termcmd[] = { "st", NULL };
+
++#include "bulkill.c"
+ static const Key keys[] = {
+ /* modifier key function argument */
+ { MODKEY, XK_p, spawn, {.v = dmenucmd } },
+_AT_@ -74,6 +75,8 @@ static const Key keys[] = {
+ { MODKEY, XK_Return, zoom, {0} },
+ { MODKEY, XK_Tab, view, {0} },
+ { MODKEY|ShiftMask, XK_c, killclient, {0} },
++ { MODKEY|ControlMask, XK_c, bulkill, {.ui = 1} }, // kill unselect
++ { MODKEY|ShiftMask|ControlMask, XK_c, bulkill, {.ui = 2} }, // killall
+ { MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
+ { MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
+ { MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
+--
+2.20.1
+
diff --git a/dwm.suckless.org/patches/bulkill/dwm-bulkill-systray-20231029-9f88553.diff b/dwm.suckless.org/patches/bulkill/dwm-bulkill-systray-20231029-9f88553.diff
new file mode 100644
index 00000000..b257c28a
--- /dev/null
+++ b/dwm.suckless.org/patches/bulkill/dwm-bulkill-systray-20231029-9f88553.diff
_AT_@ -0,0 +1,87 @@
+From 82eb2e651e54560540e77ba5dd292803cec8a6e3 Mon Sep 17 00:00:00 2001
+From: ysl2 <www.songli.yu_AT_gmail.com>
+Date: Sun, 29 Oct 2023 15:42:52 +0800
+Subject: [PATCH] Give killclient an augument to control the beheviour: arg.ui
+ == 0 for normal kill current client; arg.ui == 1 for kill other clients in
+ current tag (except current focusing client); arg.ui == 2 for kill all
+ clients in current tag (include focusing client).
+
+---
+ config.def.h | 2 ++
+ dwm.c | 31 ++++++++++++++++++++++++-------
+ 2 files changed, 26 insertions(+), 7 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index 750529d..ef1efe8 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -79,6 +79,8 @@ static const Key keys[] = {
+ { MODKEY, XK_Return, zoom, {0} },
+ { MODKEY, XK_Tab, view, {0} },
+ { MODKEY|ShiftMask, XK_c, killclient, {0} },
++ { MODKEY|ControlMask, XK_c, killclient, {.ui = 1} }, // kill unselect
++ { MODKEY|ShiftMask|ControlMask, XK_c, killclient, {.ui = 2} }, // killall
+ { MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
+ { MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
+ { MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
+diff --git a/dwm.c b/dwm.c
+index f9e7e4a..9819ec5 100644
+--- a/dwm.c
++++ b/dwm.c
+_AT_@ -199,6 +199,7 @@ static void grabbuttons(Client *c, int focused);
+ static void grabkeys(void);
+ static void incnmaster(const Arg *arg);
+ static void keypress(XEvent *e);
++static void killthis(Window w);
+ static void killclient(const Arg *arg);
+ static void manage(Window w, XWindowAttributes *wa);
+ static void mappingnotify(XEvent *e);
+_AT_@ -1131,22 +1132,38 @@ keypress(XEvent *e)
+ }
+
+ void
+-killclient(const Arg *arg)
+-{
+- if (!selmon->sel)
+- return;
+-
+- if (!sendevent(selmon->sel->win, wmatom[WMDelete], NoEventMask, wmatom[WMDelete], CurrentTime, 0 , 0, 0)) {
++killthis(Window w) {
++ if (!sendevent(w, wmatom[WMDelete], NoEventMask, wmatom[WMDelete], CurrentTime, 0, 0, 0)) {
+ XGrabServer(dpy);
+ XSetErrorHandler(xerrordummy);
+ XSetCloseDownMode(dpy, DestroyAll);
+- XKillClient(dpy, selmon->sel->win);
++ XKillClient(dpy, w);
+ XSync(dpy, False);
+ XSetErrorHandler(xerror);
+ XUngrabServer(dpy);
+ }
+ }
+
++void
++killclient(const Arg *arg)
++{
++ Client *c;
++
++ if (!selmon->sel)
++ return;
++
++ if (!arg->ui || arg->ui == 0) {
++ killthis(selmon->sel->win);
++ return;
++ }
++
++ for (c = selmon->clients; c; c = c->next) {
++ if (!ISVISIBLE(c) || (arg->ui == 1 && c == selmon->sel))
++ continue;
++ killthis(c->win);
++ }
++}
++
+ void
+ manage(Window w, XWindowAttributes *wa)
+ {
+--
+2.20.1
+
diff --git a/dwm.suckless.org/patches/bulkill/dwm-bulkill-systray-safe-20231029-9f88553.diff b/dwm.suckless.org/patches/bulkill/dwm-bulkill-systray-safe-20231029-9f88553.diff
new file mode 100644
index 00000000..8e56d578
--- /dev/null
+++ b/dwm.suckless.org/patches/bulkill/dwm-bulkill-systray-safe-20231029-9f88553.diff
_AT_@ -0,0 +1,79 @@
+From 754f493ef44d4a0f7b59e8c95e50b911631ac60b Mon Sep 17 00:00:00 2001
+From: ysl2 <www.songli.yu_AT_gmail.com>
+Date: Sun, 29 Oct 2023 15:40:44 +0800
+Subject: [PATCH] Bulk kill: arg.ui == 0 for normal kill current client; arg.ui
+ == 1 for kill other clients in current tag (except current focusing client);
+ arg.ui == 2 for kill all clients in current tag (include focusing client).
+
+---
+ bulkill.c | 36 ++++++++++++++++++++++++++++++++++++
+ config.def.h | 3 +++
+ 2 files changed, 39 insertions(+)
+ create mode 100644 bulkill.c
+
+diff --git a/bulkill.c b/bulkill.c
+new file mode 100644
+index 0000000..c73958f
+--- /dev/null
++++ b/bulkill.c
+_AT_@ -0,0 +1,36 @@
++static void killthis(Window w);
++static void bulkill(const Arg *arg);
++
++void
++killthis(Window w) {
++ if (!sendevent(w, wmatom[WMDelete], NoEventMask, wmatom[WMDelete], CurrentTime, 0, 0, 0)) {
++ XGrabServer(dpy);
++ XSetErrorHandler(xerrordummy);
++ XSetCloseDownMode(dpy, DestroyAll);
++ XKillClient(dpy, w);
++ XSync(dpy, False);
++ XSetErrorHandler(xerror);
++ XUngrabServer(dpy);
++ }
++}
++
++void
++bulkill(const Arg *arg)
++{
++ Client *c;
++
++ if (!selmon->sel)
++ return;
++
++ if (!arg->ui || arg->ui == 0) {
++ killthis(selmon->sel->win);
++ return;
++ }
++
++ for (c = selmon->clients; c; c = c->next) {
++ if (!ISVISIBLE(c) || (arg->ui == 1 && c == selmon->sel))
++ continue;
++ killthis(c->win);
++ }
++}
++
+diff --git a/config.def.h b/config.def.h
+index 750529d..4d4bcef 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -65,6 +65,7 @@ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn()
+ static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
+ static const char *termcmd[] = { "st", NULL };
+
++#include "bulkill.c"
+ static const Key keys[] = {
+ /* modifier key function argument */
+ { MODKEY, XK_p, spawn, {.v = dmenucmd } },
+_AT_@ -79,6 +80,8 @@ static const Key keys[] = {
+ { MODKEY, XK_Return, zoom, {0} },
+ { MODKEY, XK_Tab, view, {0} },
+ { MODKEY|ShiftMask, XK_c, killclient, {0} },
++ { MODKEY|ControlMask, XK_c, bulkill, {.ui = 1} }, // kill unselect
++ { MODKEY|ShiftMask|ControlMask, XK_c, bulkill, {.ui = 2} }, // killall
+ { MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
+ { MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
+ { MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
+--
+2.20.1
+
diff --git a/dwm.suckless.org/patches/bulkill/index.md b/dwm.suckless.org/patches/bulkill/index.md
new file mode 100644
index 00000000..91b68b3e
--- /dev/null
+++ b/dwm.suckless.org/patches/bulkill/index.md
_AT_@ -0,0 +1,40 @@
+bulkill
+=======
+
+Description
+-----------
+
+Built-in dwm provides `MOD+Shift+c` to close current window.
+
+We add:
+
+* `MOD+Ctrl+c` to directly close all windows in current tag, but except current window.
+* `MOD+Ctrl+Shift+c` to directly close all windows in current tag, include current window.
+
+Download
+--------
+
+* `safe`: will not change original `dwm.c` file. We add a standalone `bulkill.c` to achieve the goal, but code will be slightly redundant.
+* Without `safe`: Directly integrate into default `killclient` function in `dwm.c`, less code redundancy.
+* `systray`: will be compatible with `systray` patch, but you should patch the `systray` first, then patch ours.
+
+Recommend:
+
+* If you are a newbie and you afraid the forthcoming patch might mess things up, use `safe` version.
+* If you pursue ultimate clean code, use the non-`safe` version.
+
+* [dwm-bulkill-20231029-9f88553.diff](dwm-bulkill-20231029-9f88553.diff)
+* [dwm-bulkill-safe-20231029-9f88553.diff](dwm-bulkill-safe-20231029-9f88553.diff)
+* [dwm-bulkill-systray-20231029-9f88553.diff](dwm-bulkill-systray-20231029-9f88553.diff)
+* [dwm-bulkill-systray-safe-20231029-9f88553.diff](dwm-bulkill-systray-safe-20231029-9f88553.diff)
+
+References
+----------
+
+* https://www.reddit.com/r/dwm/comments/rybfeu/kill_all_windows_in_a_workspace_same_tag
+
+
+Authors
+-------
+
+* Songli Yu - <www.songli.yu_AT_gmail.com>
Received on Sun Oct 29 2023 - 10:05:10 CET

This archive was generated by hypermail 2.3.0 : Sun Oct 29 2023 - 10:12:49 CET