sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

dwm-bulkill-20231029-9f88553.diff (2660B)


      1 From 70a21457fdbcbcdf26efb1329dd29872b7fcd8e3 Mon Sep 17 00:00:00 2001
      2 From: ysl2 <www.songli.yu@gmail.com>
      3 Date: Sun, 29 Oct 2023 15:45:05 +0800
      4 Subject: [PATCH] Give killclient an augument to control the beheviour: arg.ui
      5  == 0 for normal kill current client; arg.ui == 1 for kill other clients in
      6  current tag (except current focusing client); arg.ui == 2 for kill all
      7  clients in current tag (include focusing client).
      8 
      9 ---
     10  config.def.h |  2 ++
     11  dwm.c        | 30 ++++++++++++++++++++++++------
     12  2 files changed, 26 insertions(+), 6 deletions(-)
     13 
     14 diff --git a/config.def.h b/config.def.h
     15 index 9efa774..d39e6dd 100644
     16 --- a/config.def.h
     17 +++ b/config.def.h
     18 @@ -74,6 +74,8 @@ static const Key keys[] = {
     19  	{ MODKEY,                       XK_Return, zoom,           {0} },
     20  	{ MODKEY,                       XK_Tab,    view,           {0} },
     21  	{ MODKEY|ShiftMask,             XK_c,      killclient,     {0} },
     22 +    { MODKEY|ControlMask,           XK_c,      killclient,     {.ui = 1} },  // kill unselect
     23 +    { MODKEY|ShiftMask|ControlMask, XK_c,      killclient,     {.ui = 2} },  // killall
     24  	{ MODKEY,                       XK_t,      setlayout,      {.v = &layouts[0]} },
     25  	{ MODKEY,                       XK_f,      setlayout,      {.v = &layouts[1]} },
     26  	{ MODKEY,                       XK_m,      setlayout,      {.v = &layouts[2]} },
     27 diff --git a/dwm.c b/dwm.c
     28 index f1d86b2..011744d 100644
     29 --- a/dwm.c
     30 +++ b/dwm.c
     31 @@ -177,6 +177,7 @@ static void grabbuttons(Client *c, int focused);
     32  static void grabkeys(void);
     33  static void incnmaster(const Arg *arg);
     34  static void keypress(XEvent *e);
     35 +static void killthis(Client *c);
     36  static void killclient(const Arg *arg);
     37  static void manage(Window w, XWindowAttributes *wa);
     38  static void mappingnotify(XEvent *e);
     39 @@ -1013,21 +1014,38 @@ keypress(XEvent *e)
     40  }
     41  
     42  void
     43 -killclient(const Arg *arg)
     44 -{
     45 -	if (!selmon->sel)
     46 -		return;
     47 -	if (!sendevent(selmon->sel, wmatom[WMDelete])) {
     48 +killthis(Client *c) {
     49 +	if (!sendevent(c, wmatom[WMDelete])) {
     50  		XGrabServer(dpy);
     51  		XSetErrorHandler(xerrordummy);
     52  		XSetCloseDownMode(dpy, DestroyAll);
     53 -		XKillClient(dpy, selmon->sel->win);
     54 +		XKillClient(dpy, c->win);
     55  		XSync(dpy, False);
     56  		XSetErrorHandler(xerror);
     57  		XUngrabServer(dpy);
     58  	}
     59  }
     60  
     61 +void
     62 +killclient(const Arg *arg)
     63 +{
     64 +    Client *c;
     65 +
     66 +	if (!selmon->sel)
     67 +		return;
     68 +
     69 +    if (!arg->ui || arg->ui == 0) {
     70 +        killthis(selmon->sel);
     71 +        return;
     72 +    }
     73 +
     74 +    for (c = selmon->clients; c; c = c->next) {
     75 +        if (!ISVISIBLE(c) || (arg->ui == 1 && c == selmon->sel))
     76 +            continue;
     77 +        killthis(c);
     78 +    }
     79 +}
     80 +
     81  void
     82  manage(Window w, XWindowAttributes *wa)
     83  {
     84 -- 
     85 2.20.1
     86