diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2024-04-23 15:12:58 +0530 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2024-04-23 15:38:10 +0530 |
commit | 0d4564c840a06dfc1c913e8a5d09b487d84619eb (patch) | |
tree | 4e0617733d66f83b5ae301438df8cb933e787352 | |
parent | 323ea47a968707bd65c2783afad6923bfeb44565 (diff) | |
download | dwm-0d4564c840a06dfc1c913e8a5d09b487d84619eb.tar.gz dwm-0d4564c840a06dfc1c913e8a5d09b487d84619eb.tar.bz2 dwm-0d4564c840a06dfc1c913e8a5d09b487d84619eb.zip |
Added patch dwm-inplacerotate
-rw-r--r-- | config.def.h | 4 | ||||
-rw-r--r-- | config.h | 4 | ||||
-rw-r--r-- | dwm.c | 59 | ||||
-rw-r--r-- | patches/dwm-inplacerotate-6.2.diff | 108 |
4 files changed, 175 insertions, 0 deletions
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} }, @@ -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 @@ -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); @@ -2382,6 +2383,64 @@ main(int argc, char *argv[]) } 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) { unsigned int i, n, h, mw, mx, my, oty, ety, tw; 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 <m@milesalan.com> +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 + |