add placedir

This commit is contained in:
Ray Andrew 2024-10-07 18:18:11 -05:00
parent 98c5f7c5b9
commit dd4fe6a489
3 changed files with 110 additions and 4 deletions

View file

@ -120,10 +120,14 @@ static const Key keys[] = {
{ MODKEY, XK_l, focusdir, {.i = 1 } },
{ MODKEY, XK_k, focusdir, {.i = 2 } },
{ MODKEY, XK_j, focusdir, {.i = 3 } },
{ MODKEY|ShiftMask, XK_h, placedir, {.i = 0 } },
{ MODKEY|ShiftMask, XK_l, placedir, {.i = 1 } },
{ MODKEY|ShiftMask, XK_k, placedir, {.i = 2 } },
{ MODKEY|ShiftMask, XK_l, placedir, {.i = 3 } },
{ MODKEY, XK_i, incnmaster, {.i = +1 } },
{ MODKEY, XK_d, incnmaster, {.i = -1 } },
{ MODKEY|ShiftMask, XK_h, setmfact, {.f = -0.05} },
{ MODKEY|ShiftMask, XK_l, setmfact, {.f = +0.05} },
{ MODKEY|ControlMask, XK_h, setmfact, {.f = -0.05} },
{ MODKEY|ControlMask, XK_l, setmfact, {.f = +0.05} },
{ MODKEY, XK_Tab, zoom, {0} },
{ MODKEY|ShiftMask, XK_Tab, view, {0} },
{ MODKEY|Mod1Mask, XK_u, incrgaps, {.i = +1 } },

View file

@ -120,10 +120,14 @@ static const Key keys[] = {
{ MODKEY, XK_l, focusdir, {.i = 1 } },
{ MODKEY, XK_k, focusdir, {.i = 2 } },
{ MODKEY, XK_j, focusdir, {.i = 3 } },
{ MODKEY|ShiftMask, XK_h, placedir, {.i = 0 } },
{ MODKEY|ShiftMask, XK_l, placedir, {.i = 1 } },
{ MODKEY|ShiftMask, XK_k, placedir, {.i = 2 } },
{ MODKEY|ShiftMask, XK_l, placedir, {.i = 3 } },
{ MODKEY, XK_i, incnmaster, {.i = +1 } },
{ MODKEY, XK_d, incnmaster, {.i = -1 } },
{ MODKEY|ShiftMask, XK_h, setmfact, {.f = -0.05} },
{ MODKEY|ShiftMask, XK_l, setmfact, {.f = +0.05} },
{ MODKEY|ControlMask, XK_h, setmfact, {.f = -0.05} },
{ MODKEY|ControlMask, XK_l, setmfact, {.f = +0.05} },
{ MODKEY, XK_Tab, zoom, {0} },
{ MODKEY|ShiftMask, XK_Tab, view, {0} },
{ MODKEY|Mod1Mask, XK_u, incrgaps, {.i = +1 } },

98
dwm.c
View file

@ -230,6 +230,7 @@ static void monocle(Monitor *m);
static void motionnotify(XEvent *e);
static void movemouse(const Arg *arg);
static Client *nexttiled(Client *c);
static void placedir(const Arg *arg);
static void pop(Client *c);
static void propertynotify(XEvent *e);
static void quit(const Arg *arg);
@ -1521,6 +1522,103 @@ nexttiled(Client *c)
return c;
}
void
placedir(const Arg *arg)
{
Client *s = selmon->sel, *f = NULL, *c, *next, *fprior, *sprior;
if (!s || s->isfloating)
return;
unsigned int score = -1;
unsigned int client_score;
int dist;
int dirweight = 20;
next = s->next;
if (!next)
next = s->mon->clients;
for (c = next; c != s; c = next) {
next = c->next;
if (!next)
next = s->mon->clients;
if (!ISVISIBLE(c)) // || HIDDEN(c)
continue;
switch (arg->i) {
case 0: // left
dist = s->x - c->x - c->w;
client_score =
dirweight * MIN(abs(dist), abs(dist + s->mon->ww)) +
abs(s->y - c->y);
break;
case 1: // right
dist = c->x - s->x - s->w;
client_score =
dirweight * MIN(abs(dist), abs(dist + s->mon->ww)) +
abs(c->y - s->y);
break;
case 2: // up
dist = s->y - c->y - c->h;
client_score =
dirweight * MIN(abs(dist), abs(dist + s->mon->wh)) +
abs(s->x - c->x);
break;
default:
case 3: // down
dist = c->y - s->y - s->h;
client_score =
dirweight * MIN(abs(dist), abs(dist + s->mon->wh)) +
abs(c->x - s->x);
break;
}
if (((arg->i == 0 || arg->i == 2) && client_score <= score) || client_score < score) {
score = client_score;
f = c;
}
}
if (f && f != s) {
for (fprior = f->mon->clients; fprior && fprior->next != f; fprior = fprior->next);
for (sprior = s->mon->clients; sprior && sprior->next != s; sprior = sprior->next);
if (s == fprior) {
next = f->next;
if (sprior)
sprior->next = f;
else
f->mon->clients = f;
f->next = s;
s->next = next;
} else if (f == sprior) {
next = s->next;
if (fprior)
fprior->next = s;
else
s->mon->clients = s;
s->next = f;
f->next = next;
} else { // clients are not adjacent to each other
next = f->next;
f->next = s->next;
s->next = next;
if (fprior)
fprior->next = s;
else
s->mon->clients = s;
if (sprior)
sprior->next = f;
else
f->mon->clients = f;
}
arrange(f->mon);
}
}
void
pop(Client *c)
{