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/client.c | 13 +++++- sys/cmd/dwm/config.h | 16 +++++--- sys/cmd/dwm/dwm.c | 6 ++- sys/cmd/dwm/dwm.h | 2 + sys/cmd/dwm/hook.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++----- 5 files changed, 128 insertions(+), 18 deletions(-) (limited to 'sys') diff --git a/sys/cmd/dwm/client.c b/sys/cmd/dwm/client.c index 383dca9..fa04f5f 100644 --- a/sys/cmd/dwm/client.c +++ b/sys/cmd/dwm/client.c @@ -128,6 +128,16 @@ enqueue(Client *c) } } +void +attachbottom(Client *c) +{ + Client **tc; + c->next = nil; + for (tc = &c->mon->clients; *tc; tc = &(*tc)->next) + ; + *tc = c; +} + void attachstack(Client *c) { @@ -307,7 +317,8 @@ sendtomon(Client *c, Monitor *m) detachstack(c); c->mon = m; c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */ - attach(c); + /* attach(c); */ + attachbottom(c); attachstack(c); focus(nil); arrange(nil); diff --git a/sys/cmd/dwm/config.h b/sys/cmd/dwm/config.h index 27521b5..cb1ccdb 100644 --- a/sys/cmd/dwm/config.h +++ b/sys/cmd/dwm/config.h @@ -81,14 +81,18 @@ static Key keys[] = { { MODKEY, XK_s, togglescratch, {.v = scratchcmd} }, { MODKEY, XK_b, togglebar, {0} }, { MODKEY, XK_f, togglefocus, {0} }, - { MODKEY, XK_j, focusstack, {.i = +1 } }, - { MODKEY, XK_k, focusstack, {.i = -1 } }, - { MODKEY|ShiftMask, XK_j, rotatestack, {.i = +1 } }, - { MODKEY|ShiftMask, XK_k, rotatestack, {.i = -1 } }, + { MODKEY, XK_Up, focusstack, {.i = +1 } }, + { MODKEY, XK_Down, focusstack, {.i = -1 } }, + { MODKEY|ShiftMask, XK_Up, rotatestack, {.i = +1 } }, + { MODKEY|ShiftMask, XK_Down, rotatestack, {.i = -1 } }, { MODKEY, XK_i, incnmaster, {.i = +1 } }, { MODKEY, XK_o, incnmaster, {.i = -1 } }, - { MODKEY, XK_h, setmfact, {.f = -0.05} }, - { MODKEY, XK_l, setmfact, {.f = +0.05} }, + { MODKEY, XK_h, focusdirection, {.i = 'l'} }, + { MODKEY, XK_l, focusdirection, {.i = 'r'} }, + { MODKEY, XK_k, focusdirection, {.i = 'u'} }, + { MODKEY, XK_j, focusdirection, {.i = 'd'} }, + { MODKEY|ShiftMask, XK_h, setmfact, {.f = -0.05} }, + { MODKEY|ShiftMask, XK_l, setmfact, {.f = +0.05} }, { MODKEY|ShiftMask, XK_Return, zoom, {0} }, { MODKEY, XK_Tab, view, {0} }, { MODKEY|ShiftMask, XK_q, killclient, {0} }, diff --git a/sys/cmd/dwm/dwm.c b/sys/cmd/dwm/dwm.c index a6d2bd2..a432ab8 100644 --- a/sys/cmd/dwm/dwm.c +++ b/sys/cmd/dwm/dwm.c @@ -559,7 +559,8 @@ manage(Window w, XWindowAttributes *wa) if (c->isfloating) XRaiseWindow(dpy, c->win); - attach(c); + /* attach(c); */ + attachbottom(c); attachstack(c); XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend, @@ -1001,7 +1002,8 @@ updategeom(void) m->clients = c->next; detachstack(c); c->mon = mons; - attach(c); + /* attach(c); */ + attachbottom(c); attachstack(c); } if (m == selmon) diff --git a/sys/cmd/dwm/dwm.h b/sys/cmd/dwm/dwm.h index 3a94248..a934287 100644 --- a/sys/cmd/dwm/dwm.h +++ b/sys/cmd/dwm/dwm.h @@ -243,6 +243,7 @@ void arrange(Monitor *m); void arrangemon(Monitor *m); void attach(Client *c); void enqueue(Client *c); +void attachbottom(Client *c); void attachstack(Client *c); void enqueuestack(Client *c); void buttonpress(XEvent *e); @@ -266,6 +267,7 @@ void focus(Client *c); void focusin(XEvent *e); void focusmon(Arg *arg); void focusstack(Arg *arg); +void focusdirection(Arg *arg); void rotatestack(Arg *arg); Atom getatomprop(Client *c, Atom prop); int getrootptr(int *x, int *y); 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