From 0d4564c840a06dfc1c913e8a5d09b487d84619eb Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Tue, 23 Apr 2024 15:12:58 +0530 Subject: Added patch dwm-inplacerotate --- config.def.h | 4 ++ config.h | 4 ++ dwm.c | 59 ++++++++++++++++++++ patches/dwm-inplacerotate-6.2.diff | 108 +++++++++++++++++++++++++++++++++++++ 4 files changed, 175 insertions(+) create mode 100644 patches/dwm-inplacerotate-6.2.diff diff --git a/config.def.h b/config.def.h index 2d938c6..2dbea52 100644 --- a/config.def.h +++ b/config.def.h @@ -86,6 +86,10 @@ static Key keys[] = { { MODKEY, XK_b, togglebar, {0} }, { MODKEY, XK_j, focusstack, {.i = +1 } }, { MODKEY, XK_k, focusstack, {.i = -1 } }, + { MODKEY|ShiftMask, XK_j, inplacerotate, {.i = +1} }, + { MODKEY|ShiftMask, XK_k, inplacerotate, {.i = -1} }, + { MODKEY|ShiftMask, XK_h, inplacerotate, {.i = +2} }, + { MODKEY|ShiftMask, XK_l, inplacerotate, {.i = -2} }, { MODKEY, XK_i, incnmaster, {.i = +1 } }, { MODKEY, XK_d, incnmaster, {.i = -1 } }, { MODKEY, XK_h, setmfact, {.f = -0.05} }, diff --git a/config.h b/config.h index 57dd3bc..8515964 100644 --- a/config.h +++ b/config.h @@ -117,6 +117,10 @@ static Key keys[] = { { MODKEY, XK_l, setmfact, {.f = +0.01} }, { MODKEY|ControlMask, XK_period, incnmaster, {.i = -1 } }, { MODKEY|ControlMask, XK_comma, incnmaster, {.i = +1 } }, + { MODKEY|ShiftMask, XK_k, inplacerotate, {.i = +1} }, + { MODKEY|ShiftMask, XK_j, inplacerotate, {.i = -1} }, + { MODKEY|ShiftMask, XK_h, inplacerotate, {.i = -2} }, + { MODKEY|ShiftMask, XK_l, inplacerotate, {.i = +2} }, { MODKEY, XK_c, zoom, {0} }, { MODKEY|ShiftMask, XK_t, setlayout, {.v = &layouts[0]} }, //tiling { MODKEY|ShiftMask, XK_f, setlayout, {.v = &layouts[1]} }, //floating diff --git a/dwm.c b/dwm.c index c02a701..19ee521 100644 --- a/dwm.c +++ b/dwm.c @@ -184,6 +184,7 @@ static int gettextprop(Window w, Atom atom, char *text, unsigned int size); static void grabbuttons(Client *c, int focused); static void grabkeys(void); static void incnmaster(const Arg *arg); +static void inplacerotate(const Arg *arg); static void keypress(XEvent *e); static void killclient(const Arg *arg); static void manage(Window w, XWindowAttributes *wa); @@ -2381,6 +2382,64 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } +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; + + // Determine positionings for insertclient + 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++; + } + } + + // All clients rotate + if (arg->i == 2) insertclient(selmon->clients, stail, 0); + if (arg->i == -2) insertclient(stail, selmon->clients, 1); + // Stack xor master rotate + if (arg->i == -1 && selidx >= selmon->nmaster) insertclient(stail, shead, 1); + if (arg->i == 1 && selidx >= selmon->nmaster) insertclient(shead, stail, 0); + if (arg->i == -1 && selidx < selmon->nmaster) insertclient(mtail, mhead, 1); + if (arg->i == 1 && 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); +} + void centeredmaster(Monitor *m) { diff --git a/patches/dwm-inplacerotate-6.2.diff b/patches/dwm-inplacerotate-6.2.diff new file mode 100644 index 0000000..d331368 --- /dev/null +++ b/patches/dwm-inplacerotate-6.2.diff @@ -0,0 +1,108 @@ +From 75012a6ab9cc1b6c319af7f4ae7d682b16a66ce3 Mon Sep 17 00:00:00 2001 +From: Miles Alan +Date: Sun, 26 Apr 2020 16:05:43 -0500 +Subject: [PATCH] Add inplacerotate fn to rotate all, master, or stacks clients + inplace + +CW (+2) or CCW (-2) Rotates all windows. +CW (+1) or CCW (-1) Rotates master xor stack windows (depending on focus). + +Focus position stays 'in-place' so the area of the screen you are focused +on remains unchanged. +--- + config.def.h | 4 ++++ + dwm.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 63 insertions(+) + +diff --git a/config.def.h b/config.def.h +index 1c0b587..9bcb792 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -66,6 +66,10 @@ static Key keys[] = { + { MODKEY, XK_b, togglebar, {0} }, + { MODKEY, XK_j, focusstack, {.i = +1 } }, + { MODKEY, XK_k, focusstack, {.i = -1 } }, ++ { MODKEY|ShiftMask, XK_j, inplacerotate, {.i = +1} }, ++ { MODKEY|ShiftMask, XK_k, inplacerotate, {.i = -1} }, ++ { MODKEY|ShiftMask, XK_h, inplacerotate, {.i = +2} }, ++ { MODKEY|ShiftMask, XK_l, inplacerotate, {.i = -2} }, + { MODKEY, XK_i, incnmaster, {.i = +1 } }, + { MODKEY, XK_d, incnmaster, {.i = -1 } }, + { MODKEY, XK_h, setmfact, {.f = -0.05} }, +diff --git a/dwm.c b/dwm.c +index 4465af1..3930680 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -175,6 +175,7 @@ static int gettextprop(Window w, Atom atom, char *text, unsigned int size); + static void grabbuttons(Client *c, int focused); + static void grabkeys(void); + static void incnmaster(const Arg *arg); ++static void inplacerotate(const Arg *arg); + static void keypress(XEvent *e); + static void killclient(const Arg *arg); + static void manage(Window w, XWindowAttributes *wa); +@@ -2147,3 +2148,61 @@ main(int argc, char *argv[]) + XCloseDisplay(dpy); + return EXIT_SUCCESS; + } ++ ++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; ++ ++ // Determine positionings for insertclient ++ 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++; ++ } ++ } ++ ++ // All clients rotate ++ if (arg->i == 2) insertclient(selmon->clients, stail, 0); ++ if (arg->i == -2) insertclient(stail, selmon->clients, 1); ++ // Stack xor master rotate ++ if (arg->i == -1 && selidx >= selmon->nmaster) insertclient(stail, shead, 1); ++ if (arg->i == 1 && selidx >= selmon->nmaster) insertclient(shead, stail, 0); ++ if (arg->i == -1 && selidx < selmon->nmaster) insertclient(mtail, mhead, 1); ++ if (arg->i == 1 && 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); ++} +-- +2.23.1 + -- cgit v1.2.3-13-gbd6f