From 83a7b16a864bf36525c9dd3d53c1895de5de3864 Mon Sep 17 00:00:00 2001 From: bakkeby Date: Fri, 17 Jan 2020 09:54:23 +0100 Subject: [PATCH] Adding inplacerotate patch --- README.md | 5 ++++ config.def.h | 4 ++++ patch/include.c | 7 ++++-- patch/include.h | 3 +++ patch/inplacerotate.c | 53 +++++++++++++++++++++++++++++++++++++++++++ patch/inplacerotate.h | 1 + patches.h | 8 ++++++- 7 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 patch/inplacerotate.c create mode 100644 patch/inplacerotate.h diff --git a/README.md b/README.md index 556ee2b..8af73dc 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t ### Changelog: +2020-01-17 - Added inplacerotate patch + 2019-12-15 - Updated dragmfact patch to include fix patch to make it work with multiple monitors 2019-11-26 - Added dmenumatchtop patch, added improvements to the switchtag patch based on ideas from the switchtotag patch @@ -190,6 +192,9 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t - sometimes dwm crashes when it cannot render some glyphs in window titles (usually emoji) - this patch is essentially a hack to ignore any errors when drawing text on the status bar and may be removed if a more appropriate solution comes up + - [inplacerotate](https://dwm.suckless.org/patches/inplacerotate/) + - allows rotation of all clients in the master or stack area without affecting the other area + - [ispermanent](https://dwm.suckless.org/patches/ispermanent/) - adds rule option for clients to avoid accidental termination by killclient for sticky windows diff --git a/config.def.h b/config.def.h index 536cef2..bf069d1 100644 --- a/config.def.h +++ b/config.def.h @@ -530,6 +530,10 @@ static Key keys[] = { { MODKEY|Mod4Mask, XK_j, rotatestack, {.i = +1 } }, { MODKEY|Mod4Mask, XK_k, rotatestack, {.i = -1 } }, #endif // ROTATESTACK_PATCH + #if INPLACEROTATE_PATCH + { MODKEY|Mod4Mask|ShiftMask, XK_j, inplacerotate, {.i = +1} }, + { MODKEY|Mod4Mask|ShiftMask, XK_k, inplacerotate, {.i = -1} }, + #endif // INPLACEROTATE_PATCH #if PUSH_PATCH || PUSH_NO_MASTER_PATCH { MODKEY|ControlMask, XK_j, pushdown, {0} }, { MODKEY|ControlMask, XK_k, pushup, {0} }, diff --git a/patch/include.c b/patch/include.c index 346839c..2e9cbf2 100644 --- a/patch/include.c +++ b/patch/include.c @@ -32,6 +32,9 @@ #if EWMHTAGS_PATCH #include "ewmhtags.c" #endif +#if EXRESIZE_PATCH +#include "exresize.c" +#endif #if FAKEFULLSCREEN_CLIENT_PATCH #include "fakefullscreenclient.c" #endif @@ -47,8 +50,8 @@ #if HOLDBAR_PATCH #include "holdbar.c" #endif -#if EXRESIZE_PATCH -#include "exresize.c" +#if INPLACEROTATE_PATCH +#include "inplacerotate.c" #endif #if KILLUNSEL_PATCH #include "killunsel.c" diff --git a/patch/include.h b/patch/include.h index bce929e..06f4f0a 100644 --- a/patch/include.h +++ b/patch/include.h @@ -50,6 +50,9 @@ #if HOLDBAR_PATCH #include "holdbar.h" #endif +#if INPLACEROTATE_PATCH +#include "inplacerotate.h" +#endif #if KILLUNSEL_PATCH #include "killunsel.h" #endif diff --git a/patch/inplacerotate.c b/patch/inplacerotate.c new file mode 100644 index 0000000..28eb289 --- /dev/null +++ b/patch/inplacerotate.c @@ -0,0 +1,53 @@ +void +insertclient(Client *item, Client *insertItem, int after) +{ + Client *c; + if (item == NULL || insertItem == NULL || item == insertItem) return; + detach(insertItem); + if (!after && selmon->clients == item) { + attach(insertItem); + return; + } + if (after) { + c = item; + } else { + for (c = selmon->clients; c; c = c->next) { if (c->next == item) break; } + } + insertItem->next = c->next; + c->next = insertItem; +} + +void +inplacerotate(const Arg *arg) +{ + if (!selmon->sel || (selmon->sel->isfloating && !arg->f)) return; + + unsigned int selidx = 0, i = 0; + Client *c = NULL, *stail = NULL, *mhead = NULL, *mtail = NULL, *shead = NULL; + + // Shift client + for (c = selmon->clients; c; c = c->next) { + if (ISVISIBLE(c) && !(c->isfloating)) { + if (selmon->sel == c) { selidx = i; } + if (i == selmon->nmaster - 1) { mtail = c; } + if (i == selmon->nmaster) { shead = c; } + if (mhead == NULL) { mhead = c; } + stail = c; + i++; + } + } + if (arg->i < 0 && selidx >= selmon->nmaster) insertclient(stail, shead, 1); + if (arg->i > 0 && selidx >= selmon->nmaster) insertclient(shead, stail, 0); + if (arg->i < 0 && selidx < selmon->nmaster) insertclient(mtail, mhead, 1); + if (arg->i > 0 && selidx < selmon->nmaster) insertclient(mhead, mtail, 0); + + // Restore focus position + i = 0; + for (c = selmon->clients; c; c = c->next) { + if (!ISVISIBLE(c) || (c->isfloating)) continue; + if (i == selidx) { focus(c); break; } + i++; + } + arrange(selmon); + focus(c); +} \ No newline at end of file diff --git a/patch/inplacerotate.h b/patch/inplacerotate.h new file mode 100644 index 0000000..2767ad1 --- /dev/null +++ b/patch/inplacerotate.h @@ -0,0 +1 @@ +static void inplacerotate(const Arg *arg); \ No newline at end of file diff --git a/patches.h b/patches.h index fdf770e..3ddaf51 100644 --- a/patches.h +++ b/patches.h @@ -233,6 +233,12 @@ */ #define HOLDBAR_PATCH 0 +/* This patch provides a keybinding to rotate all clients in the currently selected + * area (master or stack) without affecting the other area. + * https://dwm.suckless.org/patches/inplacerotate/ + */ +#define INPLACEROTATE_PATCH 0 + /* Adds rule option for clients to avoid accidental termination by killclient for sticky windows. * https://dwm.suckless.org/patches/ispermanent/ */ @@ -355,7 +361,7 @@ */ #define ROTATESTACK_PATCH 0 -/* This patch aves size and position of every floating window before it is forced +/* This patch saves size and position of every floating window before it is forced * into tiled mode. If the window is made floating again then the old dimensions * will be restored. * https://dwm.suckless.org/patches/save_floats/