sites

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

dwm-transfer-6.2.diff (2691B)


      1 From 57500f9154a3aa99f38f98d552915b8570b7cfdf Mon Sep 17 00:00:00 2001
      2 From: Miles Alan <m@milesalan.com>
      3 Date: Sat, 25 Jan 2020 22:47:38 -0600
      4 Subject: [PATCH] Add transfer function which transfers tiled client between
      5  the stack & master. Adjusts the nmaster variable accordingly (e.g. if moving
      6  to master, nmaster++ and if moving to stack nmaster--).
      7 
      8 Default keybinding added to config.def.h is Mod+x
      9 ---
     10  config.def.h |  1 +
     11  dwm.c        | 34 ++++++++++++++++++++++++++++++++++
     12  2 files changed, 35 insertions(+)
     13 
     14 diff --git a/config.def.h b/config.def.h
     15 index 1c0b587..67ec8ae 100644
     16 --- a/config.def.h
     17 +++ b/config.def.h
     18 @@ -70,6 +70,7 @@ static Key keys[] = {
     19  	{ MODKEY,                       XK_d,      incnmaster,     {.i = -1 } },
     20  	{ MODKEY,                       XK_h,      setmfact,       {.f = -0.05} },
     21  	{ MODKEY,                       XK_l,      setmfact,       {.f = +0.05} },
     22 +	{ MODKEY,                       XK_x,      transfer,       {0} },
     23  	{ MODKEY,                       XK_Return, zoom,           {0} },
     24  	{ MODKEY,                       XK_Tab,    view,           {0} },
     25  	{ MODKEY|ShiftMask,             XK_c,      killclient,     {0} },
     26 diff --git a/dwm.c b/dwm.c
     27 index 4465af1..ada794b 100644
     28 --- a/dwm.c
     29 +++ b/dwm.c
     30 @@ -213,6 +213,7 @@ static void togglebar(const Arg *arg);
     31  static void togglefloating(const Arg *arg);
     32  static void toggletag(const Arg *arg);
     33  static void toggleview(const Arg *arg);
     34 +static void transfer(const Arg *arg);
     35  static void unfocus(Client *c, int setfocus);
     36  static void unmanage(Client *c, int destroyed);
     37  static void unmapnotify(XEvent *e);
     38 @@ -2147,3 +2148,36 @@ main(int argc, char *argv[])
     39  	XCloseDisplay(dpy);
     40  	return EXIT_SUCCESS;
     41  }
     42 +
     43 +void
     44 +transfer(const Arg *arg) {
     45 +	Client *c, *mtail = selmon->clients, *stail = NULL, *insertafter;
     46 +	int transfertostack = 0, i, nmasterclients;
     47 +
     48 +	for (i = 0, c = selmon->clients; c; c = c->next) {
     49 +		if (!ISVISIBLE(c) || c->isfloating) continue;
     50 +		if (selmon->sel == c) { transfertostack = i < selmon->nmaster && selmon->nmaster != 0; }
     51 +		if (i < selmon->nmaster) { nmasterclients++; mtail = c; }
     52 +		stail = c;
     53 +		i++;
     54 +	}
     55 +	if (!selmon->sel || selmon->sel->isfloating || i == 0) {
     56 +		return;
     57 +	} else if (transfertostack) {
     58 +		selmon->nmaster = MIN(i, selmon->nmaster) - 1;
     59 +		insertafter = stail;
     60 +	} else {
     61 +		selmon->nmaster = selmon->nmaster + 1;
     62 +		insertafter = mtail;
     63 +	}
     64 +	if (insertafter != selmon->sel) {
     65 +		detach(selmon->sel);
     66 +		if (selmon->nmaster == 1 && !transfertostack) {
     67 +		 attach(selmon->sel); // Head prepend case
     68 +		} else {
     69 +			selmon->sel->next = insertafter->next;
     70 +			insertafter->next = selmon->sel;
     71 +		}
     72 +	}
     73 +	arrange(selmon);
     74 +}
     75 -- 
     76 2.23.1
     77