From 8ca64c1b2eee4d78e85d1bd7fad2a9bded1bb157 Mon Sep 17 00:00:00 2001 From: Gravity Date: Sat, 20 Dec 2025 22:47:48 +0800 Subject: [PATCH] add spawnorfocus patch --- patches/spawnorfocus/README.md | 19 ++++++ patches/spawnorfocus/spawnorfocus.patch | 90 +++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 patches/spawnorfocus/README.md create mode 100644 patches/spawnorfocus/spawnorfocus.patch diff --git a/patches/spawnorfocus/README.md b/patches/spawnorfocus/README.md new file mode 100644 index 0000000..289aa73 --- /dev/null +++ b/patches/spawnorfocus/README.md @@ -0,0 +1,19 @@ +### Description + +Allows to assign a keybind to focus on a client with an app_id/title that contains a specified substring, or spawn command if there is no match. + +Originally taken the idea from [namedscratchpads](https://codeberg.org/dwl/dwl-patches/src/branch/main/patches/namedscratchpads) +and [clicseo](https://github.com/djpohly/dwl/issues/519) to make run or raise. + +### Download + +- [git branch](https://github.com/GravityShark/dwl-grav/tree/spawnorfocus) (not really properly maintained) +- [main 2025-12-09](/dwl/dwl-patches/raw/branch/main/patches/spawnorfocus/spawnorfocus.patch) + +### Authors + +- [GravityShark](https://codeberg.org/GravityShark) [[GitHub](https://github.com/GravityShark/)] +- [Ben Collerson](https://codeberg.org/bencc) +- [clicseo](https://github.com/clicseo) +- [wochap](https://codeberg.org/wochap) +- [Louis-Michel Raynauld](https://github.com/loumray) diff --git a/patches/spawnorfocus/spawnorfocus.patch b/patches/spawnorfocus/spawnorfocus.patch new file mode 100644 index 0000000..95fb52b --- /dev/null +++ b/patches/spawnorfocus/spawnorfocus.patch @@ -0,0 +1,90 @@ +From 331b960e84c4bf7638342ea4e27fb02bb2f84d4c Mon Sep 17 00:00:00 2001 +From: Gravity +Date: Sat, 20 Dec 2025 20:10:45 +0800 +Subject: [PATCH] spawnorfocus + +--- + config.def.h | 8 ++++++-- + dwl.c | 27 +++++++++++++++++++++++++++ + 2 files changed, 33 insertions(+), 2 deletions(-) + +diff --git a/config.def.h b/config.def.h +index 95c2afa..5b37429 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -119,14 +119,18 @@ static const enum libinput_config_tap_button_map button_map = LIBINPUT_CONFIG_TA + #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } + + /* commands */ +-static const char *termcmd[] = { "foot", NULL }; ++/* The third element is used by the 'spawnorfocus' function to match a title/app_id. ++ * If the third element is 'NULL', match on the first element instead */ ++static const char *termcmd[] = { "foot", NULL, NULL }; ++static const char *browsercmd[] = { "firefox", NULL, "Mozilla Firefox" }; + static const char *menucmd[] = { "wmenu-run", NULL }; + + static const Key keys[] = { + /* Note that Shift changes certain key codes: c -> C, 2 -> at, etc. */ + /* modifier key function argument */ + { MODKEY, XKB_KEY_p, spawn, {.v = menucmd} }, +- { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return, spawn, {.v = termcmd} }, ++ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return, spawnorfocus, {.v = termcmd} }, ++ { MODKEY, XKB_KEY_b, spawnorfocus, {.v = browsercmd} }, + { MODKEY, XKB_KEY_j, focusstack, {.i = +1} }, + { MODKEY, XKB_KEY_k, focusstack, {.i = -1} }, + { MODKEY, XKB_KEY_i, incnmaster, {.i = +1} }, +diff --git a/dwl.c b/dwl.c +index 12f441e..f902f3b 100644 +--- a/dwl.c ++++ b/dwl.c +@@ -8,6 +8,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -330,6 +331,7 @@ static void setpsel(struct wl_listener *listener, void *data); + static void setsel(struct wl_listener *listener, void *data); + static void setup(void); + static void spawn(const Arg *arg); ++static void spawnorfocus(const Arg *arg); + static void startdrag(struct wl_listener *listener, void *data); + static void tag(const Arg *arg); + static void tagmon(const Arg *arg); +@@ -2676,6 +2678,31 @@ spawn(const Arg *arg) + } + } + ++void ++spawnorfocus(const Arg *arg) ++{ ++ char *needle; ++ Client *c; ++ int i = 0; ++ ++ while (((char **)arg->v)[i++]); ++ needle = ((char **)arg->v)[i + 1] ? ((char **)arg->v)[i + 1] : ((char **)arg->v)[0]; ++ ++ wl_list_for_each(c, &clients, link) ++ if (strstr(client_get_title(c), needle) ++ || strstr(client_get_appid(c), needle)) { ++ selmon = c->mon; ++ if (!(c->tags & selmon->tagset[selmon->seltags])) ++ selmon->tagset[selmon->seltags] = c->tags; ++ ++ focusclient(c, 1); ++ arrange(selmon); ++ return; ++ } ++ ++ spawn(arg); ++} ++ + void + startdrag(struct wl_listener *listener, void *data) + { +-- +2.51.2 +