From 2e80e18c190b737338f8000aafe685719b4899a1 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Tue, 5 Oct 2021 07:54:53 -0700 Subject: feat(dwm): spatial movement and attach bottom --- sys/cmd/dwm/hook.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 100 insertions(+), 9 deletions(-) (limited to 'sys/cmd/dwm/hook.c') diff --git a/sys/cmd/dwm/hook.c b/sys/cmd/dwm/hook.c index cc96ead..9758965 100644 --- a/sys/cmd/dwm/hook.c +++ b/sys/cmd/dwm/hook.c @@ -24,24 +24,115 @@ focusstack(Arg *arg) if (!selmon->sel) return; if (arg->i > 0) { - for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next); - if (!c) - for (c = selmon->clients; c && !ISVISIBLE(c); c = c->next); + for(c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next); + if(!c) + for(c = selmon->clients; c && !ISVISIBLE(c); c = c->next); } else { - for (i = selmon->clients; i != selmon->sel; i = i->next) - if (ISVISIBLE(i)) + for(i = selmon->clients; i != selmon->sel; i = i->next) + if(ISVISIBLE(i)) c = i; - if (!c) - for (; i; i = i->next) + if(!c) + for(; i; i = i->next) if (ISVISIBLE(i)) c = i; } - if (c) { + if(c) { focus(c); restack(selmon); } } +void +focusdirection(Arg *arg) +{ + Monitor *m; + Client *it, *c; + int x, y, cx, cy; + + if(!selmon || !selmon->sel) + return; + + c = selmon->sel; + x = c->x, y = c->y; + + c = nil; + switch(arg->i) { + case 'l': + cx = INT_MIN; + cy = y; + for(m=mons; m; m=m->next) { + for(it=m->clients; it; it = it->next) { + if(ISVISIBLE(it) && (it->x < x)) { + if((it->x > cx) || ((it->x == cx) && abs(y-it->y) < abs(y-cy))) { + c = it; + cx = it->x; + cy = it->y; + } + } + } + } + break; + + case 'r': + cx = INT_MAX; + cy = y; + for(m=mons; m; m=m->next) { + for(it=m->clients; it; it = it->next) { + if(ISVISIBLE(it) && (it->x > x)) { + if((it->x < cx) || ((it->x == cx) && abs(y-it->y) < abs(y-cy))) { + c = it; + cx = it->x; + cy = it->y; + } + } + } + } + break; + + case 'u': + cx = x; + cy = INT_MIN; + for(m=mons; m; m=m->next) { + for(it=m->clients; it; it = it->next) { + if(ISVISIBLE(it) && (it->y < y)) { + if((it->y > cy) || ((it->y == cy) && abs(x-it->x) < abs(x-cx))) { + c = it; + cx = it->x; + cy = it->y; + } + } + } + } + break; + + case 'd': + cx = x; + cy = INT_MAX; + for(m=mons; m; m=m->next) { + for(it=m->clients; it; it = it->next) { + if(ISVISIBLE(it) && (it->y > y)) { + if((it->y < cy) || ((it->y == cy) && abs(x-it->x) < abs(x-cx))) { + c = it; + cx = it->x; + cy = it->y; + } + } + } + } + break; + + default: + ; + } + + if(c) { + focus(c); + restack(selmon); + if(c->mon != selmon) + restack(c->mon); + } +} + void rotatestack(Arg *arg) { @@ -60,7 +151,7 @@ rotatestack(Arg *arg) attach(c); detachstack(c); attachstack(c); - } + } } else { if ((c = nexttiled(selmon->clients))) { detach(c); -- cgit v1.2.1