summaryrefslogtreecommitdiffhomepage
path: root/patch
diff options
context:
space:
mode:
Diffstat (limited to 'patch')
-rw-r--r--patch/focusdir.c65
-rw-r--r--patch/focusdir.h1
-rw-r--r--patch/include.c3
-rw-r--r--patch/include.h3
-rw-r--r--patch/riodraw.c2
5 files changed, 73 insertions, 1 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
diff --git a/patch/focusdir.h b/patch/focusdir.h
new file mode 100644
index 0000000..f0f3e5e
--- /dev/null
+++ b/patch/focusdir.h
@@ -0,0 +1 @@
+static void focusdir(const Arg *arg); \ No newline at end of file
diff --git a/patch/include.c b/patch/include.c
index 6ddb2f9..7f79624 100644
--- a/patch/include.c
+++ b/patch/include.c
@@ -132,6 +132,9 @@
#if FOCUSADJACENTTAG_PATCH
#include "focusadjacenttag.c"
#endif
+#if FOCUSDIR_PATCH
+#include "focusdir.c"
+#endif
#if FOCUSMASTER_PATCH
#include "focusmaster.c"
#endif
diff --git a/patch/include.h b/patch/include.h
index b3fe1cb..9b3de50 100644
--- a/patch/include.h
+++ b/patch/include.h
@@ -129,6 +129,9 @@
#if FLOATPOS_PATCH
#include "floatpos.h"
#endif
+#if FOCUSDIR_PATCH
+#include "focusdir.h"
+#endif
#if FOCUSADJACENTTAG_PATCH
#include "focusadjacenttag.h"
#endif
diff --git a/patch/riodraw.c b/patch/riodraw.c
index ace3acc..66a7add 100644
--- a/patch/riodraw.c
+++ b/patch/riodraw.c
@@ -54,7 +54,7 @@ riodraw(const Arg *arg)
c = selmon->sel;
if (width > 50 && height > 50 && x > -40 && y > -40 && width < selmon->mw + 40 && height < selmon->mh + 40 &&
- (abs(c->w - width) > 20 || abs(c->h - height) > 20 || abs(c->x - x) > 20 || abs(c->y - y) > 20)) {
+ (abs(c->w - width) > 20 || abs(c->h - height) > 20 || abs(c->x - x) > 20 || abs(c->y - y) > 20)) {
if ((m = recttomon(x, y, width, height)) != selmon) {
sendmon(c, m);
unfocus(selmon->sel, 0, NULL);