Add mov stack patch
This commit is contained in:
		
							parent
							
								
									6679c4349b
								
							
						
					
					
						commit
						aef49fcc62
					
				
					 5 changed files with 153 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -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 "movestack.c"
 | 
			
		||||
static Key keys[] = {
 | 
			
		||||
	/* modifier                     key        function        argument */
 | 
			
		||||
	{ MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
 | 
			
		||||
| 
						 | 
				
			
			@ -76,6 +77,8 @@ static Key keys[] = {
 | 
			
		|||
	{ MODKEY,                       XK_d,      incnmaster,     {.i = -1 } },
 | 
			
		||||
	{ MODKEY,                       XK_h,      setmfact,       {.f = -0.05} },
 | 
			
		||||
	{ MODKEY,                       XK_l,      setmfact,       {.f = +0.05} },
 | 
			
		||||
	{ MODKEY|ShiftMask,             XK_j,      movestack,      {.i = +1 } },
 | 
			
		||||
	{ MODKEY|ShiftMask,             XK_k,      movestack,      {.i = -1 } },
 | 
			
		||||
	{ MODKEY,                       XK_Return, zoom,           {0} },
 | 
			
		||||
	{ MODKEY,                       XK_Tab,    view,           {0} },
 | 
			
		||||
	{ MODKEY|ShiftMask,             XK_c,      killclient,     {0} },
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -82,6 +82,7 @@ static Key keys[] = {
 | 
			
		|||
	{ MODKEY,                       XK_t,      setlayout,      {.v = &layouts[0]} },
 | 
			
		||||
	{ MODKEY,                       XK_f,      setlayout,      {.v = &layouts[1]} },
 | 
			
		||||
	{ MODKEY,                       XK_m,      setlayout,      {.v = &layouts[2]} },
 | 
			
		||||
	{ MODKEY|ShiftMask,             XK_f,      fullscreen,     {0} },
 | 
			
		||||
	{ MODKEY,                       XK_space,  setlayout,      {0} },
 | 
			
		||||
	{ MODKEY|ShiftMask,             XK_space,  togglefloating, {0} },
 | 
			
		||||
	{ MODKEY,                       XK_0,      view,           {.ui = ~0 } },
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										6
									
								
								config.h
									
										
									
									
									
								
							
							
						
						
									
										6
									
								
								config.h
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -79,6 +79,8 @@ 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[]  = { TERMINAL, NULL };
 | 
			
		||||
 | 
			
		||||
#include "movestack.c"
 | 
			
		||||
 | 
			
		||||
static Key keys[] = {
 | 
			
		||||
	/* modifier                     key        function        argument */
 | 
			
		||||
	{ MODKEY|ShiftMask,                       XK_d,      spawn,          {.v = dmenucmd } },
 | 
			
		||||
| 
						 | 
				
			
			@ -101,6 +103,10 @@ static Key keys[] = {
 | 
			
		|||
	{ MODKEY,                       XK_l,      setmfact,       {.f = +0.05} },
 | 
			
		||||
//	{ MODKEY,                       XK_Return, zoom,           {0} },
 | 
			
		||||
	{ MODKEY,                       XK_Tab,    view,           {0} },
 | 
			
		||||
 | 
			
		||||
	{ MODKEY|ShiftMask,             XK_j,      movestack,      {.i = +1 } }, 
 | 
			
		||||
	{ MODKEY|ShiftMask,             XK_k,      movestack,      {.i = -1 } }, 
 | 
			
		||||
 | 
			
		||||
	// Quit from the foucsed window (kill)
 | 
			
		||||
	{ MODKEY|ShiftMask,             XK_q,      killclient,     {0} },
 | 
			
		||||
	// Tiled layout
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										48
									
								
								movestack.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								movestack.c
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,48 @@
 | 
			
		|||
void
 | 
			
		||||
movestack(const Arg *arg) {
 | 
			
		||||
	Client *c = NULL, *p = NULL, *pc = NULL, *i;
 | 
			
		||||
 | 
			
		||||
	if(arg->i > 0) {
 | 
			
		||||
		/* find the client after selmon->sel */
 | 
			
		||||
		for(c = selmon->sel->next; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
 | 
			
		||||
		if(!c)
 | 
			
		||||
			for(c = selmon->clients; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
	else {
 | 
			
		||||
		/* find the client before selmon->sel */
 | 
			
		||||
		for(i = selmon->clients; i != selmon->sel; i = i->next)
 | 
			
		||||
			if(ISVISIBLE(i) && !i->isfloating)
 | 
			
		||||
				c = i;
 | 
			
		||||
		if(!c)
 | 
			
		||||
			for(; i; i = i->next)
 | 
			
		||||
				if(ISVISIBLE(i) && !i->isfloating)
 | 
			
		||||
					c = i;
 | 
			
		||||
	}
 | 
			
		||||
	/* find the client before selmon->sel and c */
 | 
			
		||||
	for(i = selmon->clients; i && (!p || !pc); i = i->next) {
 | 
			
		||||
		if(i->next == selmon->sel)
 | 
			
		||||
			p = i;
 | 
			
		||||
		if(i->next == c)
 | 
			
		||||
			pc = i;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/* swap c and selmon->sel selmon->clients in the selmon->clients list */
 | 
			
		||||
	if(c && c != selmon->sel) {
 | 
			
		||||
		Client *temp = selmon->sel->next==c?selmon->sel:selmon->sel->next;
 | 
			
		||||
		selmon->sel->next = c->next==selmon->sel?c:c->next;
 | 
			
		||||
		c->next = temp;
 | 
			
		||||
 | 
			
		||||
		if(p && p != c)
 | 
			
		||||
			p->next = c;
 | 
			
		||||
		if(pc && pc != selmon->sel)
 | 
			
		||||
			pc->next = selmon->sel;
 | 
			
		||||
 | 
			
		||||
		if(selmon->sel == selmon->clients)
 | 
			
		||||
			selmon->clients = c;
 | 
			
		||||
		else if(c == selmon->clients)
 | 
			
		||||
			selmon->clients = selmon->sel;
 | 
			
		||||
 | 
			
		||||
		arrange(selmon);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										95
									
								
								patches/dwm-movestack-20211115-a786211.diff
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										95
									
								
								patches/dwm-movestack-20211115-a786211.diff
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,95 @@
 | 
			
		|||
From 9a4037dc0ef56f91c009317e78e9e3790dafbb58 Mon Sep 17 00:00:00 2001
 | 
			
		||||
From: BrunoCooper17 <BrunoCooper17@outlook.com>
 | 
			
		||||
Date: Mon, 15 Nov 2021 14:04:53 -0600
 | 
			
		||||
Subject: [PATCH] MoveStack patch
 | 
			
		||||
 | 
			
		||||
This plugin allows you to move clients around in the stack and swap them 
 | 
			
		||||
with the master. It emulates the behavior off mod+shift+j and mod+shift+k 
 | 
			
		||||
in Xmonad. movestack(+1) will swap the client with the current focus with 
 | 
			
		||||
the next client. movestack(-1) will swap the client with the current focus 
 | 
			
		||||
with the previous client.
 | 
			
		||||
---
 | 
			
		||||
 config.def.h |  3 +++
 | 
			
		||||
 movestack.c  | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 | 
			
		||||
 2 files changed, 51 insertions(+)
 | 
			
		||||
 create mode 100644 movestack.c
 | 
			
		||||
 | 
			
		||||
diff --git a/config.def.h b/config.def.h
 | 
			
		||||
index a2ac963..33efa5b 100644
 | 
			
		||||
--- a/config.def.h
 | 
			
		||||
+++ b/config.def.h
 | 
			
		||||
@@ -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 "movestack.c"
 | 
			
		||||
 static Key keys[] = {
 | 
			
		||||
 	/* modifier                     key        function        argument */
 | 
			
		||||
 	{ MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
 | 
			
		||||
@@ -71,6 +72,8 @@ static Key keys[] = {
 | 
			
		||||
 	{ MODKEY,                       XK_d,      incnmaster,     {.i = -1 } },
 | 
			
		||||
 	{ MODKEY,                       XK_h,      setmfact,       {.f = -0.05} },
 | 
			
		||||
 	{ MODKEY,                       XK_l,      setmfact,       {.f = +0.05} },
 | 
			
		||||
+	{ MODKEY|ShiftMask,             XK_j,      movestack,      {.i = +1 } },
 | 
			
		||||
+	{ MODKEY|ShiftMask,             XK_k,      movestack,      {.i = -1 } },
 | 
			
		||||
 	{ MODKEY,                       XK_Return, zoom,           {0} },
 | 
			
		||||
 	{ MODKEY,                       XK_Tab,    view,           {0} },
 | 
			
		||||
 	{ MODKEY|ShiftMask,             XK_c,      killclient,     {0} },
 | 
			
		||||
diff --git a/movestack.c b/movestack.c
 | 
			
		||||
new file mode 100644
 | 
			
		||||
index 0000000..520f4ae
 | 
			
		||||
--- /dev/null
 | 
			
		||||
+++ b/movestack.c
 | 
			
		||||
@@ -0,0 +1,48 @@
 | 
			
		||||
+void
 | 
			
		||||
+movestack(const Arg *arg) {
 | 
			
		||||
+	Client *c = NULL, *p = NULL, *pc = NULL, *i;
 | 
			
		||||
+
 | 
			
		||||
+	if(arg->i > 0) {
 | 
			
		||||
+		/* find the client after selmon->sel */
 | 
			
		||||
+		for(c = selmon->sel->next; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
 | 
			
		||||
+		if(!c)
 | 
			
		||||
+			for(c = selmon->clients; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
 | 
			
		||||
+
 | 
			
		||||
+	}
 | 
			
		||||
+	else {
 | 
			
		||||
+		/* find the client before selmon->sel */
 | 
			
		||||
+		for(i = selmon->clients; i != selmon->sel; i = i->next)
 | 
			
		||||
+			if(ISVISIBLE(i) && !i->isfloating)
 | 
			
		||||
+				c = i;
 | 
			
		||||
+		if(!c)
 | 
			
		||||
+			for(; i; i = i->next)
 | 
			
		||||
+				if(ISVISIBLE(i) && !i->isfloating)
 | 
			
		||||
+					c = i;
 | 
			
		||||
+	}
 | 
			
		||||
+	/* find the client before selmon->sel and c */
 | 
			
		||||
+	for(i = selmon->clients; i && (!p || !pc); i = i->next) {
 | 
			
		||||
+		if(i->next == selmon->sel)
 | 
			
		||||
+			p = i;
 | 
			
		||||
+		if(i->next == c)
 | 
			
		||||
+			pc = i;
 | 
			
		||||
+	}
 | 
			
		||||
+
 | 
			
		||||
+	/* swap c and selmon->sel selmon->clients in the selmon->clients list */
 | 
			
		||||
+	if(c && c != selmon->sel) {
 | 
			
		||||
+		Client *temp = selmon->sel->next==c?selmon->sel:selmon->sel->next;
 | 
			
		||||
+		selmon->sel->next = c->next==selmon->sel?c:c->next;
 | 
			
		||||
+		c->next = temp;
 | 
			
		||||
+
 | 
			
		||||
+		if(p && p != c)
 | 
			
		||||
+			p->next = c;
 | 
			
		||||
+		if(pc && pc != selmon->sel)
 | 
			
		||||
+			pc->next = selmon->sel;
 | 
			
		||||
+
 | 
			
		||||
+		if(selmon->sel == selmon->clients)
 | 
			
		||||
+			selmon->clients = c;
 | 
			
		||||
+		else if(c == selmon->clients)
 | 
			
		||||
+			selmon->clients = selmon->sel;
 | 
			
		||||
+
 | 
			
		||||
+		arrange(selmon);
 | 
			
		||||
+	}
 | 
			
		||||
+}
 | 
			
		||||
\ No newline at end of file
 | 
			
		||||
-- 
 | 
			
		||||
2.33.1
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue