aboutsummaryrefslogtreecommitdiffstats
path: root/dwl.c
diff options
context:
space:
mode:
authorAlexander Leonhardt <equinox.salexander@gmail.com>
2026-09-05 12:20:46 +0200
committerAlexander Leonhardt <equinox.salexander@gmail.com>
2026-09-05 12:20:46 +0200
commit531a526b76e6a65af47351062362f2e8e8d6abd9 (patch)
tree805c84b81f20a92b7834a671fe4ea6b70a569209 /dwl.c
parent2554be4300170799a64c68b02a420b4fcdb90431 (diff)
downloaddwl-531a526b76e6a65af47351062362f2e8e8d6abd9.tar.gz
dwl-531a526b76e6a65af47351062362f2e8e8d6abd9.tar.bz2
dwl-531a526b76e6a65af47351062362f2e8e8d6abd9.zip
Added changes
Diffstat (limited to 'dwl.c')
-rw-r--r--dwl.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/dwl.c b/dwl.c
index 101a45f..ef26de8 100644
--- a/dwl.c
+++ b/dwl.c
@@ -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 */