diff options
| author | Alexander Leonhardt <equinox.salexander@gmail.com> | |
|---|---|---|
| 2026-09-05 12:20:46 +0200 | ||
| committer | Alexander Leonhardt <equinox.salexander@gmail.com> | |
| 2026-09-05 12:20:46 +0200 | ||
| commit | 531a526b76e6a65af47351062362f2e8e8d6abd9 (patch) | |
| tree | 805c84b81f20a92b7834a671fe4ea6b70a569209 | |
| parent | 2554be4300170799a64c68b02a420b4fcdb90431 (diff) | |
| download | dwl-531a526b76e6a65af47351062362f2e8e8d6abd9.tar.gz dwl-531a526b76e6a65af47351062362f2e8e8d6abd9.tar.bz2 dwl-531a526b76e6a65af47351062362f2e8e8d6abd9.zip | |
Added changes
diff --git a/config.def.h b/config.def.h index aa108b2..ff39ccd 100644 --- a/config.def.h +++ b/config.def.h @@ -146,6 +146,10 @@ static const Key keys[] = { { MODKEY, XKB_KEY_period, focusmon, {.i = WLR_DIRECTION_RIGHT} }, { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_less, tagmon, {.i = WLR_DIRECTION_LEFT} }, { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_greater, tagmon, {.i = WLR_DIRECTION_RIGHT} }, + { MODKEY|WLR_MODIFIER_CTRL, XKB_KEY_h, focusdir, {.ui = 0} }, + { MODKEY|WLR_MODIFIER_CTRL, XKB_KEY_l, focusdir, {.ui = 1} }, + { MODKEY|WLR_MODIFIER_CTRL, XKB_KEY_k, focusdir, {.ui = 2} }, + { MODKEY|WLR_MODIFIER_CTRL, XKB_KEY_j, focusdir, {.ui = 3} }, TAGKEYS( XKB_KEY_1, XKB_KEY_exclam, 0), TAGKEYS( XKB_KEY_2, XKB_KEY_at, 1), TAGKEYS( XKB_KEY_3, XKB_KEY_numbersign, 2), @@ -1,6 +1,7 @@ /* * See LICENSE file for copyright and license details. */ +#include <limits.h> #include <getopt.h> #include <libinput.h> #include <linux/input-event-codes.h> @@ -286,6 +287,7 @@ static Monitor *dirtomon(enum wlr_direction dir); static void focusclient(Client *c, int lift); static void focusmon(const Arg *arg); static void focusstack(const Arg *arg); +static void focusdir(const Arg *arg); static Client *focustop(Monitor *m); static void fullscreennotify(struct wl_listener *listener, void *data); static void gpureset(struct wl_listener *listener, void *data); @@ -1512,6 +1514,49 @@ focusstack(const Arg *arg) focusclient(c, 1); } +void focusdir(const Arg *arg) +{ + /* Focus the left, right, up, down client relative to the current focused client on selmon */ + Client *c, *sel = focustop(selmon); + int dist=INT_MAX; + Client *newsel = NULL; + int newdist=INT_MAX; + if (!sel || sel->isfullscreen) + return; + + wl_list_for_each(c, &clients, link) { + if (!VISIBLEON(c, selmon)) + continue; /* skip non visible windows */ + + if (arg->ui == 0 && sel->geom.x <= c->geom.x) { + /* Client isn't on our left */ + continue; + } + if (arg->ui == 1 && sel->geom.x >= c->geom.x) { + /* Client isn't on our right */ + continue; + } + if (arg->ui == 2 && sel->geom.y <= c->geom.y) { + /* Client isn't above us */ + continue; + } + if (arg->ui == 3 && sel->geom.y >= c->geom.y) { + /* Client isn't below us */ + continue; + } + + dist=abs(sel->geom.x-c->geom.x)+abs(sel->geom.y-c->geom.y); + if (dist < newdist){ + newdist = dist; + newsel=c; + } + } + if (newsel != NULL){ + focusclient(newsel, 1); + } +} + + /* We probably should change the name of this: it sounds like it * will focus the topmost client of this mon, when actually will * only return that client */ |