aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2021-10-05 07:54:53 -0700
committerNicholas Noll <nbnoll@eml.cc>2021-10-05 07:54:53 -0700
commit2e80e18c190b737338f8000aafe685719b4899a1 (patch)
treeddcc74b7cf9c56fe2ed9aa7b138a1396e5923fc4
parent08a6da05412961ddf629415a92749b02d875fa62 (diff)
feat(dwm): spatial movement and attach bottom
-rw-r--r--sys/cmd/dwm/client.c13
-rw-r--r--sys/cmd/dwm/config.h16
-rw-r--r--sys/cmd/dwm/dwm.c6
-rw-r--r--sys/cmd/dwm/dwm.h2
-rw-r--r--sys/cmd/dwm/hook.c109
5 files changed, 128 insertions, 18 deletions
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
@@ -129,6 +129,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)
{
c->snext = c->mon->stack;
@@ -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,25 +24,116 @@ 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)
{
Client *c = nil, *f;
@@ -60,7 +151,7 @@ rotatestack(Arg *arg)
attach(c);
detachstack(c);
attachstack(c);
- }
+ }
} else {
if ((c = nexttiled(selmon->clients))) {
detach(c);