summaryrefslogtreecommitdiffhomepage
path: root/patch/focusdir.c
diff options
context:
space:
mode:
authorbakkeby <[email protected]>2021-02-11 12:29:48 +0100
committerbakkeby <[email protected]>2021-02-11 12:29:48 +0100
commit9fcfa8d6ce45d7c7530f447c200ab8977c997e78 (patch)
treec0d004e877d093cbb8988b5403f99f10b2dc2615 /patch/focusdir.c
parent1d092253e3b9ee5e310957d83edb2effad10cdb8 (diff)
downloaddwm-flexipatch-9fcfa8d6ce45d7c7530f447c200ab8977c997e78.tar.gz
dwm-flexipatch-9fcfa8d6ce45d7c7530f447c200ab8977c997e78.zip
Adding focusdir patch
Diffstat (limited to 'patch/focusdir.c')
-rw-r--r--patch/focusdir.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/patch/focusdir.c b/patch/focusdir.c
new file mode 100644
index 0000000..1807e42
--- /dev/null
+++ b/patch/focusdir.c
@@ -0,0 +1,65 @@
+void
+focusdir(const Arg *arg)
+{
+ Client *s = selmon->sel, *f = NULL, *c, *next;
+
+ if (!s)
+ return;
+
+ unsigned int score = -1;
+ unsigned int client_score;
+ int dist;
+ int dirweight = 20;
+ int isfloating = s->isfloating;
+
+ 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) || c->isfloating != isfloating) // || 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) {
+ focus(f);
+ restack(f->mon);
+ }
+} \ No newline at end of file