mirror of
https://codeberg.org/dwl/dwl-patches.git
synced 2025-12-15 01:13:20 +00:00
88 lines
2.9 KiB
Diff
88 lines
2.9 KiB
Diff
From c7ce8e9511f6d8d651f671c4113b50fbd05fb77e Mon Sep 17 00:00:00 2001
|
|
From: Gravity <alternativegravitational@protonmail.com>
|
|
Date: Tue, 9 Dec 2025 07:46:19 +0800
|
|
Subject: [PATCH] spawnorfocus
|
|
|
|
---
|
|
config.def.h | 8 ++++++--
|
|
dwl.c | 25 +++++++++++++++++++++++++
|
|
2 files changed, 31 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/config.def.h b/config.def.h
|
|
index 95c2afa..9559f02 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 };
|
|
+/* Set the first item as title or app_id, then the command */
|
|
+/* or as NULL to use the command as title or app_id */
|
|
+static const char *termcmd[] = { NULL, "foot", NULL };
|
|
+static const char *browsercmd[] = { "Mozilla Firefox", "firefox", NULL };
|
|
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..ee9cd66 100644
|
|
--- a/dwl.c
|
|
+++ b/dwl.c
|
|
@@ -8,6 +8,7 @@
|
|
#include <signal.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
+#include <string.h>
|
|
#include <sys/wait.h>
|
|
#include <time.h>
|
|
#include <unistd.h>
|
|
@@ -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,29 @@ spawn(const Arg *arg)
|
|
}
|
|
}
|
|
|
|
+void
|
|
+spawnorfocus(const Arg *arg)
|
|
+{
|
|
+ char **argv = (char **)arg->v;
|
|
+ Client *c;
|
|
+ const Arg cmd = {.v = argv + 1};
|
|
+ const char *needle = argv[0] ? argv[0] : argv[1];
|
|
+
|
|
+ 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(&cmd);
|
|
+}
|
|
+
|
|
void
|
|
startdrag(struct wl_listener *listener, void *data)
|
|
{
|
|
--
|
|
2.51.2
|