From e0a21f0869904eb819e559a14f46820279b993cc Mon Sep 17 00:00:00 2001 From: bakkeby Date: Fri, 4 Oct 2019 23:13:55 +0200 Subject: [PATCH] Adding movestack patch --- README.md | 5 ++++- config.def.h | 8 ++++++-- patch/include.c | 4 ++++ patch/include.h | 4 ++++ patch/movestack.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++ patch/movestack.h | 1 + patches.h | 5 +++++ 7 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 patch/movestack.c create mode 100644 patch/movestack.h diff --git a/README.md b/README.md index 97568c2..c336ef4 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t ### Changelog: -2019-10-04 - Added maximize and monoclesymbol patches +2019-10-04 - Added maximize, movestack and monoclesymbol patches 2019-10-03 - Added onlyquitonempty and switchcol patches @@ -146,6 +146,9 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t - always display the the monocle-symbol as defined in config.h if the monocle-layout is activated - do not display the number of open clients in the current tag + - [movestack](https://dwm.suckless.org/patches/movestack/) + - allows you to move clients around in the stack and swap them with the master + - [onlyquitonempty](https://dwm.suckless.org/patches/onlyquitonempty/) - makes it so dwm will only exit via quit() if no windows are open (in order to prevent accidental loss of work) diff --git a/config.def.h b/config.def.h index 1cda331..388cdea 100644 --- a/config.def.h +++ b/config.def.h @@ -320,8 +320,8 @@ static Key keys[] = { { MODKEY, XK_j, focusstack, {.i = +1 } }, { MODKEY, XK_k, focusstack, {.i = -1 } }, #if ROTATESTACK_PATCH - { MODKEY|ShiftMask, XK_j, rotatestack, {.i = +1 } }, - { MODKEY|ShiftMask, XK_k, rotatestack, {.i = -1 } }, + { MODKEY|Mod4Mask, XK_j, rotatestack, {.i = +1 } }, + { MODKEY|Mod4Mask, XK_k, rotatestack, {.i = -1 } }, #endif // ROTATESTACK_PATCH #if PUSH_PATCH || PUSH_NO_MASTER_PATCH { MODKEY|ControlMask, XK_j, pushdown, {0} }, @@ -336,6 +336,10 @@ static Key keys[] = { { MODKEY|ShiftMask, XK_l, setcfact, {.f = -0.25} }, { MODKEY|ShiftMask, XK_o, setcfact, {.f = 0.00} }, #endif // CFACTS_PATCH + #if MOVESTACK_PATCH + { MODKEY|ShiftMask, XK_j, movestack, {.i = +1 } }, + { MODKEY|ShiftMask, XK_k, movestack, {.i = -1 } }, + #endif // MOVESTACK_PATCH { MODKEY, XK_Return, zoom, {0} }, #if VANITYGAPS_PATCH { MODKEY|Mod4Mask, XK_u, incrgaps, {.i = +1 } }, diff --git a/patch/include.c b/patch/include.c index 3db5a6d..fa6905c 100644 --- a/patch/include.c +++ b/patch/include.c @@ -56,6 +56,10 @@ #include "maximize.c" #endif +#if MOVESTACK_PATCH +#include "movestack.c" +#endif + #if PERTAG_PATCH #include "pertag.c" #endif diff --git a/patch/include.h b/patch/include.h index afdbf87..f78287d 100644 --- a/patch/include.h +++ b/patch/include.h @@ -56,6 +56,10 @@ #include "maximize.h" #endif +#if MOVESTACK_PATCH +#include "movestack.h" +#endif + #if PERTAG_PATCH #include "pertag.h" #endif diff --git a/patch/movestack.c b/patch/movestack.c new file mode 100644 index 0000000..2406a87 --- /dev/null +++ b/patch/movestack.c @@ -0,0 +1,49 @@ +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 diff --git a/patch/movestack.h b/patch/movestack.h new file mode 100644 index 0000000..19ac5d8 --- /dev/null +++ b/patch/movestack.h @@ -0,0 +1 @@ +static void movestack(const Arg *arg); \ No newline at end of file diff --git a/patches.h b/patches.h index ff31936..026e38d 100644 --- a/patches.h +++ b/patches.h @@ -209,6 +209,11 @@ */ #define MONOCLESYMBOL_PATCH 0 +/* This patch allows you to move clients around in the stack and swap them with the master. + * https://dwm.suckless.org/patches/movestack/ + */ +#define MOVESTACK_PATCH 0 + /* This patch makes it so dwm will only exit via quit() if no windows are open. * This is to prevent you accidentally losing all your work. * https://dwm.suckless.org/patches/onlyquitonempty/