dwm-bulkill-safe-20231029-9f88553.diff (2673B)
1 From c40d70e238b7e5e8ebfd16b435c56af55a541912 Mon Sep 17 00:00:00 2001 2 From: ysl2 <www.songli.yu@gmail.com> 3 Date: Sun, 29 Oct 2023 15:39:46 +0800 4 Subject: [PATCH] Bulk kill: arg.ui == 0 for normal kill current client; arg.ui 5 == 1 for kill other clients in current tag (except current focusing client); 6 arg.ui == 2 for kill all clients in current tag (include focusing client). 7 8 --- 9 bulkill.c | 35 +++++++++++++++++++++++++++++++++++ 10 config.def.h | 3 +++ 11 2 files changed, 38 insertions(+) 12 create mode 100644 bulkill.c 13 14 diff --git a/bulkill.c b/bulkill.c 15 new file mode 100644 16 index 0000000..732852e 17 --- /dev/null 18 +++ b/bulkill.c 19 @@ -0,0 +1,35 @@ 20 +static void killthis(Client *c); 21 +static void bulkill(const Arg *arg); 22 + 23 +void 24 +killthis(Client *c) { 25 + if (!sendevent(c, wmatom[WMDelete])) { 26 + XGrabServer(dpy); 27 + XSetErrorHandler(xerrordummy); 28 + XSetCloseDownMode(dpy, DestroyAll); 29 + XKillClient(dpy, c->win); 30 + XSync(dpy, False); 31 + XSetErrorHandler(xerror); 32 + XUngrabServer(dpy); 33 + } 34 +} 35 + 36 +void 37 +bulkill(const Arg *arg) 38 +{ 39 + Client *c; 40 + 41 + if (!selmon->sel) 42 + return; 43 + 44 + if (!arg->ui || arg->ui == 0) { 45 + killthis(selmon->sel); 46 + return; 47 + } 48 + 49 + for (c = selmon->clients; c; c = c->next) { 50 + if (!ISVISIBLE(c) || (arg->ui == 1 && c == selmon->sel)) 51 + continue; 52 + killthis(c); 53 + } 54 +} 55 diff --git a/config.def.h b/config.def.h 56 index 9efa774..28cfd78 100644 57 --- a/config.def.h 58 +++ b/config.def.h 59 @@ -60,6 +60,7 @@ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() 60 static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; 61 static const char *termcmd[] = { "st", NULL }; 62 63 +#include "bulkill.c" 64 static const Key keys[] = { 65 /* modifier key function argument */ 66 { MODKEY, XK_p, spawn, {.v = dmenucmd } }, 67 @@ -74,6 +75,8 @@ static const Key keys[] = { 68 { MODKEY, XK_Return, zoom, {0} }, 69 { MODKEY, XK_Tab, view, {0} }, 70 { MODKEY|ShiftMask, XK_c, killclient, {0} }, 71 + { MODKEY|ControlMask, XK_c, bulkill, {.ui = 1} }, // kill unselect 72 + { MODKEY|ShiftMask|ControlMask, XK_c, bulkill, {.ui = 2} }, // killall 73 { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, 74 { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, 75 { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, 76 -- 77 2.20.1 78