summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormac <ra@afu.re>2025-08-28 11:50:02 -0400
committermac <ra@afu.re>2025-08-28 11:50:02 -0400
commite7279c88dfe3219a3e59dd9d15b7f5b78b1671ea (patch)
tree3c6f81dd43c947fb6ffb05b1fcada7f22cba4263
parent1bdeb27902fddb025d03498d4d5a9027c8ac1f51 (diff)
trying the named_scratchpad patch
-rw-r--r--config.def.h13
-rw-r--r--dwl.c40
2 files changed, 47 insertions, 6 deletions
diff --git a/config.def.h b/config.def.h
index 2190342..8c04523 100644
--- a/config.def.h
+++ b/config.def.h
@@ -31,12 +31,12 @@ static int log_level = WLR_ERROR;
/* NOTE: ALWAYS keep a rule declared even if you don't use rules (e.g leave at least one example) */
static const Rule rules[] = {
- /* app_id title tags mask isfloating isterm noswallow monitor */
+ /* app_id title tags mask isfloating isterm noswallow monitor scratchkey */
/* examples: */
- { "foot", NULL, 0, 0, 1, 1, -1 },
- { "Gimp_EXAMPLE", NULL, 0, 1, 0, 0, -1 }, /* Start on currently visible tags floating, not tiled */
- { "firefox_EXAMPLE", NULL, 1 << 8, 0, 0, 0, -1 }, /* Start on ONLY tag "9" */
- { "scratchpad", NULL, 0, 1, 1, 0, -1 },
+ { "foot", NULL, 0, 0, 1, 1, -1, 0 },
+ { "Gimp_EXAMPLE", NULL, 0, 1, 0, 0, -1, 0 }, /* Start on currently visible tags floating, not tiled */
+ { "firefox_EXAMPLE", NULL, 1 << 8, 0, 0, 0, -1, 0 }, /* Start on ONLY tag "9" */
+ { NULL, "scratchpad", 0, 1, 1, 0, -1, 's'},
};
/* layout(s) */
@@ -134,7 +134,7 @@ static const int cursor_timeout = 5;
/* commands */
static const char *termcmd[] = { "foot", NULL };
static const char *menucmd[] = { "bemenu-run", NULL };
-static const char *spcmd[] = { "foot", "--app-id", "scratchpad", "--window-size-chars=120x34", NULL };
+static const char *spcmd[] = { "s", "foot", "--app-id", "scratchpad", "--window-size-chars=120x34", NULL };
static const Key keys[] = {
/* Note that Shift changes certain key codes: c -> C, 2 -> at, etc. */
@@ -143,6 +143,7 @@ static const Key keys[] = {
/* modifier key function argument */
{ MODKEY, XKB_KEY_Return, spawn, {.v = termcmd} },
+ { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return, togglescratch, {.v = spcmd} },
{ MODKEY, XKB_KEY_a, spawn, {.v = menucmd} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_A, spawn, SHCMD(TERMINAL " -e abook -C ~/.config/abook/abookrc --datafile ~/.config/abook/addressbook") },
{ MODKEY, XKB_KEY_w, spawn, {.v = (const char*[]){ "firefox", NULL }} },
diff --git a/dwl.c b/dwl.c
index a662911..96dc373 100644
--- a/dwl.c
+++ b/dwl.c
@@ -142,6 +142,7 @@ struct Client {
unsigned int bw;
uint32_t tags;
int isfloating, isurgent, isfullscreen;
+ char scratchkey;
int isterm, noswallow;
uint32_t resize; /* configure serial of a pending resize */
pid_t pid;
@@ -249,6 +250,7 @@ typedef struct {
int isterm;
int noswallow;
int monitor;
+ const char scratchkey;
} Rule;
typedef struct {
@@ -374,6 +376,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 spawnscratch(const Arg *arg);
static void startdrag(struct wl_listener *listener, void *data);
static void swallow(Client *c, Client *toswallow);
static void tag(const Arg *arg);
@@ -386,6 +389,7 @@ static void togglefullscreen(const Arg *arg);
static void togglegaps(const Arg *arg);
static void toggleswallow(const Arg *arg);
static void toggleautoswallow(const Arg *arg);
+static void togglescratch(const Arg *arg);
static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg);
static void unlocksession(struct wl_listener *listener, void *data);
@@ -546,6 +550,8 @@ applyrules(Client *c)
const Rule *r;
Monitor *mon = selmon, *m;
+ c->scratchkey = 0;
+
appid = client_get_appid(c);
title = client_get_title(c);
@@ -555,6 +561,7 @@ applyrules(Client *c)
if ((!r->title || strstr(title, r->title))
&& (!r->id || strstr(appid, r->id))) {
c->isfloating = r->isfloating;
+ c->scratchkey = r->scratchkey;
newtags |= r->tags;
c->isterm = r->isterm;
c->noswallow = r->noswallow;
@@ -3086,6 +3093,16 @@ spawn(const Arg *arg)
}
}
+void spawnscratch(const Arg *arg)
+{
+ if (fork() == 0) {
+ dup2(STDERR_FILENO, STDOUT_FILENO);
+ setsid();
+ execvp(((char **)arg->v)[1], ((char **)arg->v)+1);
+ die("dwl: execvp %s failed:", ((char **)arg->v)[1]);
+ }
+}
+
void
startdrag(struct wl_listener *listener, void *data)
{
@@ -3291,6 +3308,29 @@ togglegaps(const Arg *arg)
}
void
+togglescratch(const Arg *arg)
+{
+ Client *c;
+ unsigned int found = 0;
+
+ /* search for first window that matches the scratchkey */
+ wl_list_for_each(c, &clients, link)
+ if (c->scratchkey == ((char**)arg->v)[0][0]) {
+ found = 1;
+ break;
+ }
+
+ if (found) {
+ c->tags = VISIBLEON(c, selmon) ? 0 : selmon->tagset[selmon->seltags];
+
+ focusclient(c->tags == 0 ? focustop(selmon) : c, 1);
+ arrange(selmon);
+ } else{
+ spawnscratch(arg);
+ }
+}
+
+void
toggletag(const Arg *arg)
{
uint32_t newtags;