From 46d94742858b0bba02d1299d2fa650fb5a044a53 Mon Sep 17 00:00:00 2001 From: Rutherther Date: Sat, 27 Apr 2024 21:25:16 +0200 Subject: [PATCH] feat: access nth monitor --- config.def.h | 4 +++- dwl.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/config.def.h b/config.def.h index 8847e58..3bb64dd 100644 --- a/config.def.h +++ b/config.def.h @@ -108,7 +108,9 @@ static const enum libinput_config_tap_button_map button_map = LIBINPUT_CONFIG_TA { MODKEY, KEY, view, {.ui = 1 << TAG} }, \ { MODKEY|WLR_MODIFIER_CTRL, KEY, toggleview, {.ui = 1 << TAG} }, \ { MODKEY|WLR_MODIFIER_SHIFT, SKEY, tag, {.ui = 1 << TAG} }, \ - { MODKEY|WLR_MODIFIER_CTRL|WLR_MODIFIER_SHIFT,SKEY,toggletag, {.ui = 1 << TAG} } + { MODKEY|WLR_MODIFIER_CTRL|WLR_MODIFIER_SHIFT,SKEY,toggletag, {.ui = 1 << TAG} }, \ + { WLR_MODIFIER_ALT, KEY, focusnthmon, {.ui = 1 << TAG }, \ + { WLR_MODIFIER_ALT|WLR_MODIFIER_SHIFT, SKEY, tagnthmon, {.ui = 1 << TAG } /* helper for spawning shell commands in the pre dwm-5.0 fashion */ #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } diff --git a/dwl.c b/dwl.c index bf763df..64a7783 100644 --- a/dwl.c +++ b/dwl.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -278,8 +279,10 @@ static void destroypointerconstraint(struct wl_listener *listener, void *data); static void destroysessionlock(struct wl_listener *listener, void *data); static void destroysessionmgr(struct wl_listener *listener, void *data); static Monitor *dirtomon(enum wlr_direction dir); +static Monitor *numtomon(int num); static void focusclient(Client *c, int lift); static void focusmon(const Arg *arg); +static void focusnthmon(const Arg *arg); static void focusstack(const Arg *arg); static Client *focustop(Monitor *m); static void fullscreennotify(struct wl_listener *listener, void *data); @@ -329,6 +332,7 @@ static void spawn(const Arg *arg); static void startdrag(struct wl_listener *listener, void *data); static void tag(const Arg *arg); static void tagmon(const Arg *arg); +static void tagnthmon(const Arg *arg); static void tile(Monitor *m); static void togglefloating(const Arg *arg); static void togglefullscreen(const Arg *arg); @@ -1233,6 +1237,22 @@ dirtomon(enum wlr_direction dir) return selmon; } +Monitor * +numtomon(int num) +{ + Monitor *m = NULL; + int i = 0; + + wl_list_for_each(m, &mons, link) { + if (!m->wlr_output->enabled) + i--; + if (i == num) + break; + i++; + } + return m; +} + void focusclient(Client *c, int lift) { @@ -1320,6 +1340,18 @@ focusmon(const Arg *arg) focusclient(focustop(selmon), 1); } +void +focusnthmon(const Arg *arg) +{ + Monitor *m; + if (arg->i > wl_list_length(&mons)) + return; + if ((m = numtomon(arg->i)) == selmon) + return; + selmon = m; + focusclient(focustop(selmon), 1); +} + void focusstack(const Arg *arg) { @@ -2569,6 +2601,15 @@ tagmon(const Arg *arg) setmon(sel, dirtomon(arg->i), 0); } +void +tagnthmon(const Arg *arg) +{ + Client *sel = focustop(selmon); + if (arg->i > wl_list_length(&mons)) + return; + setmon(sel, numtomon(arg->i), 0); +} + void tile(Monitor *m) { -- 2.48.1