Hello,

I've written a small patch that allows dwm to swap the contents of two tags.

As this is my first time actually hacking into dwm's code I'm looking forward to receiving some feedback. Also, if more people find this useful I would like to make it publicly available in https://dwm.suckless.org/patches/ .

I sent this patch to [email protected] but I think it belongs better here.

Best regards,
Ricardo Jesus
>From 66122d908f338538f4af0e09332dec80b90524d8 Mon Sep 17 00:00:00 2001
From: Ricardo Jesus <[email protected]>
Date: Sat, 29 Jun 2019 11:48:54 +0100
Subject: [PATCH] Allow swapping the contents of two tags

---
 config.def.h | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/config.def.h b/config.def.h
index 1c0b587..701f8da 100644
--- a/config.def.h
+++ b/config.def.h
@@ -43,13 +43,16 @@ static const Layout layouts[] = {
 	{ "[M]",      monocle },
 };
 
+void swaptags(const Arg *arg);
+
 /* key definitions */
 #define MODKEY Mod1Mask
 #define TAGKEYS(KEY,TAG) \
 	{ MODKEY,                       KEY,      view,           {.ui = 1 << TAG} }, \
 	{ MODKEY|ControlMask,           KEY,      toggleview,     {.ui = 1 << TAG} }, \
 	{ MODKEY|ShiftMask,             KEY,      tag,            {.ui = 1 << TAG} }, \
-	{ MODKEY|ControlMask|ShiftMask, KEY,      toggletag,      {.ui = 1 << TAG} },
+	{ MODKEY|ControlMask|ShiftMask, KEY,      toggletag,      {.ui = 1 << TAG} }, \
+	{ Mod4Mask|ShiftMask,           KEY,      swaptags,       {.ui = 1 << TAG} },
 
 /* helper for spawning shell commands in the pre dwm-5.0 fashion */
 #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
@@ -113,3 +116,24 @@ static Button buttons[] = {
 	{ ClkTagBar,            MODKEY,         Button3,        toggletag,      {0} },
 };
 
+void
+swaptags(const Arg *arg)
+{
+	unsigned int newtag = arg->ui & TAGMASK;
+	unsigned int curtag = selmon->tagset[selmon->seltags];
+
+	if (newtag == curtag || !curtag || (curtag & (curtag-1)))
+		return;
+
+	for (Client *c = selmon->clients; c != NULL; c = c->next) {
+		if((c->tags & newtag) || (c->tags & curtag))
+			c->tags ^= curtag ^ newtag;
+
+		if(!c->tags) c->tags = newtag;
+	}
+
+	selmon->tagset[selmon->seltags] = newtag;
+
+	focus(NULL);
+	arrange(selmon);
+}
-- 
2.22.0

Reply via email to