From 4a50263148565e571ddc483fd4fc0083b28f160f Mon Sep 17 00:00:00 2001 From: Rutherther Date: Fri, 19 Jul 2024 16:05:28 +0200 Subject: [PATCH] Focus nth client --- config.def.h | 1 + dwl.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/config.def.h b/config.def.h index 22d2171d678e2bc79c22d0d2635d1af26c77e5f8..f64ef9393de26803c551469dfc78a335daa87b4c 100644 --- a/config.def.h +++ b/config.def.h @@ -148,6 +148,7 @@ 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, XKB_KEY_m, focusnthclient, {0} }, TAGKEYS( XKB_KEY_1, XKB_KEY_exclam, 0), TAGKEYS( XKB_KEY_2, XKB_KEY_at, 1), TAGKEYS( XKB_KEY_3, XKB_KEY_numbersign, 2), diff --git a/dwl.c b/dwl.c index 5bf995e66830363954d5e5a7ce93cf0d005becd7..fe27a553ae1ad0c3bc7f2e708427c031d09af330 100644 --- a/dwl.c +++ b/dwl.c @@ -288,6 +288,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 focusnthclient(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); @@ -2687,6 +2688,26 @@ tagmon(const Arg *arg) setmon(sel, dirtomon(arg->i), 0); } +void +focusnthclient(const Arg *arg) +{ + Client *c; + unsigned int i = arg->ui; + + wl_list_for_each(c, &clients, link) { + if (!VISIBLEON(c, selmon) || c->isfloating) { + continue; + } + + if (i == 0) { + focusclient(c, 1); + return; + } + + i--; + } +} + void tile(Monitor *m) {