From 70a21457fdbcbcdf26efb1329dd29872b7fcd8e3 Mon Sep 17 00:00:00 2001 From: ysl2 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 @@ -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 @@ -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); @@ -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