summaryrefslogtreecommitdiff
path: root/patch/inplacerotate.c
diff options
context:
space:
mode:
authorBear <bear@bengtsson.win>2021-12-27 09:29:58 +0000
committerBear <bear@bengtsson.win>2021-12-27 09:29:58 +0000
commit69262b01ced79c2d776fab9b889926d1816a1e7a (patch)
treef304cd6fa8734e83a7772d07dc9b484781565155 /patch/inplacerotate.c
Added DWM
Diffstat (limited to 'patch/inplacerotate.c')
-rw-r--r--patch/inplacerotate.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/patch/inplacerotate.c b/patch/inplacerotate.c
new file mode 100644
index 0000000..b700e04
--- /dev/null
+++ b/patch/inplacerotate.c
@@ -0,0 +1,84 @@
+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++;
+ }
+ }
+
+ switch(arg->i) {
+ case 1:
+ if (selidx >= selmon->nmaster)
+ insertclient(shead, stail, 0);
+ else
+ insertclient(mhead, mtail, 0);
+ break;
+ case -1:
+ if (selidx >= selmon->nmaster)
+ insertclient(stail, shead, 1);
+ else
+ insertclient(mtail, mhead, 1);
+ break;
+ case 2:
+ insertclient(selmon->clients, stail, 0);
+ break;
+ case -2:
+ insertclient(stail, selmon->clients, 1);
+ break;
+ }
+
+ // 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);
+}
+