Hello,
I wrote a small patch for dwm 6.2 which enables it to swap the contents of
two tags (i.e. the clients which are visible in one are moved to the other
and vice-versa).
This is my first time actually hacking into dwm's code on my own (so far I
had only applied patches others had made or changed defaults).
I was looking forward to receive some feedback and/or corrections to my
modifications.
Thanks in advance,
Ricardo Jesus
diff --git a/config.def.h b/config.def.h
index 1c0b587..2257afd 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} }, \
+ { Mod1Mask|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);
+}