diff --git a/config.def.h b/config.def.h index 997a1e0..d3bcbea 100644 --- a/config.def.h +++ b/config.def.h @@ -85,7 +85,8 @@ static const Layout layouts[] = { { 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 } } diff --git a/dwm.c b/dwm.c index 8435618..97b4caf 100644 --- a/dwm.c +++ b/dwm.c @@ -273,6 +273,7 @@ static int xerrordummy(Display *dpy, XErrorEvent *ee); static int xerrorstart(Display *dpy, XErrorEvent *ee); static void xinitvisual(); static void zoom(const Arg *arg); +static void swaptags(const Arg *arg); static void autostart_exec(void); static pid_t getparentprocess(pid_t p); @@ -3121,6 +3122,28 @@ zoom(const Arg *arg) arrange(c->mon); } +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); +} + int main(int argc, char *argv[]) { diff --git a/patches/functions/dwm-swaptags-6.2.diff b/patches/functions/dwm-swaptags-6.2.diff new file mode 100644 index 0000000..e9d51c9 --- /dev/null +++ b/patches/functions/dwm-swaptags-6.2.diff @@ -0,0 +1,68 @@ +From 9513cc776dc8114967988d4abc32fd7f37446ddb Mon Sep 17 00:00:00 2001 +From: fossy +Date: Sun, 28 Nov 2021 21:34:37 +0100 +Subject: [PATCH] Move function and it's prototype from config.def.h to dwm.c + +--- + config.def.h | 3 ++- + dwm.c | 23 +++++++++++++++++++++++ + 2 files changed, 25 insertions(+), 1 deletion(-) + +diff --git a/config.def.h b/config.def.h +index a2ac963..f31a66d 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -50,7 +50,8 @@ static const Layout layouts[] = { + { 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 } } +diff --git a/dwm.c b/dwm.c +index 5e4d494..d11addd 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -234,6 +234,7 @@ static int xerror(Display *dpy, XErrorEvent *ee); + static int xerrordummy(Display *dpy, XErrorEvent *ee); + static int xerrorstart(Display *dpy, XErrorEvent *ee); + static void zoom(const Arg *arg); ++static void swaptags(const Arg *arg); + + /* variables */ + static const char broken[] = "broken"; +@@ -2127,6 +2128,28 @@ zoom(const Arg *arg) + pop(c); + } + ++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); ++} ++ + int + main(int argc, char *argv[]) + { +-- +2.34.1 +