From 197c218304eb31ec7ebaebedc485351f92587bfa Mon Sep 17 00:00:00 2001 From: bakkeby Date: Mon, 4 Jul 2022 13:56:39 +0200 Subject: [PATCH] Adding shiftswaptags patch ref. #270 --- config.def.h | 18 +++++++++++++++++- patch/include.c | 3 +++ patch/include.h | 3 +++ patch/shiftswaptags.c | 20 ++++++++++++++++++++ patch/shiftswaptags.h | 1 + patch/swaptags.c | 1 - patches.def.h | 6 ++++++ 7 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 patch/shiftswaptags.c create mode 100644 patch/shiftswaptags.h diff --git a/config.def.h b/config.def.h index d723ac1..da67f20 100644 --- a/config.def.h +++ b/config.def.h @@ -999,6 +999,10 @@ static Key keys[] = { { MODKEY|ControlMask, XK_Left, shiftboth, { .i = -1 } }, // note keybinding conflict with focusadjacenttag tagandviewtoleft { MODKEY|ControlMask, XK_Right, shiftboth, { .i = +1 } }, // note keybinding conflict with focusadjacenttag tagandviewtoright #endif // SHIFTBOTH_PATCH + #if SHIFTSWAPTAGS_PATCH && SWAPTAGS_PATCH + { MODKEY|Mod4Mask|ShiftMask, XK_Left, shiftswaptags, { .i = -1 } }, + { MODKEY|Mod4Mask|ShiftMask, XK_Right, shiftswaptags, { .i = +1 } }, + #endif // SHIFTSWAPTAGS_PATCH #if BAR_WINTITLEACTIONS_PATCH { MODKEY|ControlMask, XK_z, showhideclient, {0} }, #endif // BAR_WINTITLEACTIONS_PATCH @@ -1433,6 +1437,9 @@ static Signal signals[] = { { "viewall", viewallex }, { "viewex", viewex }, { "toggleview", toggleview }, + #if SHIFTBOTH_PATCH + { "shiftboth", shiftboth }, + #endif // SHIFTBOTH_PATCH #if SHIFTTAG_PATCH { "shifttag", shifttag }, #endif // SHIFTTAG_PATCH @@ -1445,6 +1452,9 @@ static Signal signals[] = { #if SHIFTVIEW_CLIENTS_PATCH { "shiftviewclients", shiftviewclients }, #endif // SHIFTVIEW_CLIENTS_PATCH + #if SHIFTSWAPTAGS_PATCH && SWAPTAGS_PATCH + { "shiftswaptags", shiftswaptags }, + #endif // SHIFTSWAPTAGS_PATCH #if SELFRESTART_PATCH { "self_restart", self_restart }, #endif // SELFRESTART_PATCH @@ -1627,9 +1637,12 @@ static IPCCommand ipccommands[] = { #if SETBORDERPX_PATCH IPCCOMMAND( setborderpx, 1, {ARG_TYPE_SINT} ), #endif // SETBORDERPX_PATCH + #if SHIFTBOTH_PATCH + IPCCOMMAND( shiftboth, 1, {ARG_TYPE_SINT} ), + #endif // SHIFTBOTH_PATCH #if SHIFTTAG_PATCH IPCCOMMAND( shifttag, 1, {ARG_TYPE_SINT} ), - #endif // SHIFTVIEW_PATCH + #endif // SHIFTTAG_PATCH #if SHIFTTAGCLIENTS_PATCH IPCCOMMAND( shifttagclients, 1, {ARG_TYPE_SINT} ), #endif // SHIFTVIEWCLIENTS_PATCH @@ -1639,6 +1652,9 @@ static IPCCommand ipccommands[] = { #if SHIFTVIEW_CLIENTS_PATCH IPCCOMMAND( shiftviewclients, 1, {ARG_TYPE_SINT} ), #endif // SHIFTVIEW_CLIENTS_PATCH + #if SHIFTSWAPTAGS_PATCH && SWAPTAGS_PATCH + IPCCOMMAND( shiftswaptags, 1, {ARG_TYPE_SINT} ), + #endif // SHIFTSWAPTAGS_PATCH #if STACKER_PATCH IPCCOMMAND( pushstack, 1, {ARG_TYPE_SINT} ), #endif // STACKER_PATCH diff --git a/patch/include.c b/patch/include.c index a4130da..5318ea2 100644 --- a/patch/include.c +++ b/patch/include.c @@ -235,6 +235,9 @@ #if SHIFTBOTH_PATCH #include "shiftboth.c" #endif +#if SHIFTSWAPTAGS_PATCH && SWAPTAGS_PATCH +#include "shiftswaptags.c" +#endif #if SHIFTTAG_PATCH #include "shifttag.c" #endif diff --git a/patch/include.h b/patch/include.h index 095bd70..6803c5d 100644 --- a/patch/include.h +++ b/patch/include.h @@ -237,6 +237,9 @@ #if SHIFTBOTH_PATCH #include "shiftboth.h" #endif +#if SHIFTSWAPTAGS_PATCH && SWAPTAGS_PATCH +#include "shiftswaptags.h" +#endif #if SHIFTTAG_PATCH #include "shifttag.h" #endif diff --git a/patch/shiftswaptags.c b/patch/shiftswaptags.c new file mode 100644 index 0000000..d9f797a --- /dev/null +++ b/patch/shiftswaptags.c @@ -0,0 +1,20 @@ +/* swaps "tags" (all the clients) with the next/prev tag. */ +void +shiftswaptags(const Arg *arg) +{ + Arg shifted; + #if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH + shifted.ui = selmon->tagset[selmon->seltags]; + #else + shifted.ui = selmon->tagset[selmon->seltags]; + #endif // SCRATCHPADS_PATCH + + if (arg->i > 0) /* left circular shift */ + shifted.ui = ((shifted.ui << arg->i) | (shifted.ui >> (NUMTAGS - arg->i))); + else /* right circular shift */ + shifted.ui = ((shifted.ui >> -arg->i) | (shifted.ui << (NUMTAGS + arg->i))); + #if SCRATCHPADS_PATCH && !RENAMED_SCRATCHPADS_PATCH + shifted.ui &= ~SPTAGMASK; + #endif // SCRATCHPADS_PATCH + swaptags(&shifted); +} diff --git a/patch/shiftswaptags.h b/patch/shiftswaptags.h new file mode 100644 index 0000000..1977e36 --- /dev/null +++ b/patch/shiftswaptags.h @@ -0,0 +1 @@ +static void shiftswaptags(const Arg *arg); diff --git a/patch/swaptags.c b/patch/swaptags.c index 7e1e920..d2341ef 100644 --- a/patch/swaptags.c +++ b/patch/swaptags.c @@ -28,4 +28,3 @@ swaptags(const Arg *arg) view(&((Arg) { .ui = newtag })); } - diff --git a/patches.def.h b/patches.def.h index 4b6719e..3f5a27f 100644 --- a/patches.def.h +++ b/patches.def.h @@ -974,6 +974,12 @@ */ #define SHIFTBOTH_PATCH 0 +/* Swaps all the clients on the current tag with all the client on the next/prev tag. + * Depends on the swaptags patch. + * https://dwm.suckless.org/patches/shift-tools/ + */ +#define SHIFTSWAPTAGS_PATCH 0 + /* Moves the current selected client to the adjacent tag. * Also see the focusadjacenttag patch. * https://dwm.suckless.org/patches/shift-tools/