summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--README.md5
-rw-r--r--config.def.h10
-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
-rw-r--r--patches.def.h5
8 files changed, 90 insertions, 4 deletions
diff --git a/README.md b/README.md
index 57d56aa..756e0fe 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t
### Changelog:
-2021-02-11 - Added the riodraw patch
+2021-02-11 - Added the riodraw and focusdir patches
2021-01-22 - Added the placemouse patch
@@ -338,6 +338,9 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t
- provides the ability to focus the tag on the immediate left or right of the currently focused tag
- it also allows to send the focused window either on the left or the right tag
+ - [focusdir](https://github.com/bakkeby/patches/wiki/focusdir)
+ - allows focusing on clients based on direction (up, down, left, right) instead of client order
+
- [focusmaster](https://dwm.suckless.org/patches/focusmaster/)
- a simple patch that just puts focus back to the master client
diff --git a/config.def.h b/config.def.h
index 9bad46f..58e6b1a 100644
--- a/config.def.h
+++ b/config.def.h
@@ -768,6 +768,12 @@ static Key keys[] = {
{ MODKEY, XK_j, focusstack, {.i = +1 } },
{ MODKEY, XK_k, focusstack, {.i = -1 } },
#endif // STACKER_PATCH
+ #if FOCUSDIR_PATCH
+ { MODKEY, XK_Left, focusdir, {.i = 0 } }, // left
+ { MODKEY, XK_Right, focusdir, {.i = 1 } }, // right
+ { MODKEY, XK_Up, focusdir, {.i = 2 } }, // up
+ { MODKEY, XK_Down, focusdir, {.i = 3 } }, // down
+ #endif // FOCUSDIR_PATCH
#if SWAPFOCUS_PATCH && PERTAG_PATCH
{ MODKEY, XK_s, swapfocus, {.i = -1 } },
#endif // SWAPFOCUS_PATCH
@@ -952,8 +958,8 @@ static Key keys[] = {
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
#if FOCUSADJACENTTAG_PATCH
- { MODKEY, XK_Left, viewtoleft, {0} },
- { MODKEY, XK_Right, viewtoright, {0} },
+ { MODKEY, XK_Left, viewtoleft, {0} }, // note keybinding conflict with focusdir
+ { MODKEY, XK_Right, viewtoright, {0} }, // note keybinding conflict with focusdir
{ MODKEY|ShiftMask, XK_Left, tagtoleft, {0} },
{ MODKEY|ShiftMask, XK_Right, tagtoright, {0} },
{ MODKEY|ControlMask, XK_Left, tagandviewtoleft, {0} },
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);
diff --git a/patches.def.h b/patches.def.h
index 737fec2..0a27b1c 100644
--- a/patches.def.h
+++ b/patches.def.h
@@ -520,6 +520,11 @@
*/
#define FOCUSADJACENTTAG_PATCH 0
+/* Allows focusing on clients based on direction (up, down, left, right) instead of client order.
+ * https://github.com/bakkeby/patches/wiki/focusdir/
+ */
+#define FOCUSDIR_PATCH 0
+
/* A simple patch that just puts focus back to the master client.
* https://dwm.suckless.org/patches/focusmaster/
*/