Adding focusdir patch

pull/96/head
bakkeby 3 years ago
parent 1d092253e3
commit 9fcfa8d6ce

@ -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

@ -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} },

@ -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);
}
}

@ -0,0 +1 @@
static void focusdir(const Arg *arg);

@ -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

@ -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

@ -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);

@ -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/
*/

Loading…
Cancel
Save