summaryrefslogtreecommitdiff
path: root/dwm/patch/push.c
diff options
context:
space:
mode:
authorcoasteen <coasteen@proton.me>2026-07-09 10:42:28 +0330
committercoasteen <coasteen@proton.me>2026-07-09 10:42:28 +0330
commit8cbadb61604667b407b53ee1258433994fa4765a (patch)
tree97765fb29418fd6278fcb4cbb9760893afaf7a58 /dwm/patch/push.c
Diffstat (limited to 'dwm/patch/push.c')
-rwxr-xr-xdwm/patch/push.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/dwm/patch/push.c b/dwm/patch/push.c
new file mode 100755
index 0000000..68123a6
--- /dev/null
+++ b/dwm/patch/push.c
@@ -0,0 +1,74 @@
+static Client *
+nextc(Client *c, float f)
+{
+ if (!f)
+ return nexttiled(c);
+
+ for (; c && !ISVISIBLE(c); c = c->next);
+ return c;
+}
+
+static Client *
+prevc(Client *c, float f)
+{
+ Client *p, *r;
+
+ for (p = selmon->clients, r = NULL; c && p && p != c; p = p->next)
+ if ((f || !p->isfloating) && ISVISIBLE(p))
+ r = p;
+ return r;
+}
+
+static void
+pushup(const Arg *arg)
+{
+ Client *sel = selmon->sel;
+ Client *c;
+
+ if (!sel || (sel->isfloating && !arg->f))
+ return;
+ if ((c = prevc(sel, arg->f))) {
+ /* attach before c */
+ detach(sel);
+ sel->next = c;
+ if (selmon->clients == c)
+ selmon->clients = sel;
+ else {
+ for (c = selmon->clients; c->next != sel->next; c = c->next);
+ c->next = sel;
+ }
+ } else {
+ /* move to the end */
+ for (c = sel; c->next; c = c->next);
+ if (sel != c) {
+ detach(sel);
+ sel->next = NULL;
+ c->next = sel;
+ }
+ }
+ focus(sel);
+ arrange(selmon);
+}
+
+static void
+pushdown(const Arg *arg)
+{
+ Client *sel = selmon->sel;
+ Client *c;
+
+ if (!sel || (sel->isfloating && !arg->f))
+ return;
+ if ((c = nextc(sel->next, arg->f))) {
+ /* attach after c */
+ detach(sel);
+ sel->next = c->next;
+ c->next = sel;
+ } else {
+ /* move to the front */
+ detach(sel);
+ attach(sel);
+ }
+ focus(sel);
+ arrange(selmon);
+}
+