dwl-patches/patches/switchtotag/switchtotag.patch
2026-02-09 10:30:29 +01:00

116 lines
3.6 KiB
Diff

From bfcfb26b00cb93a359469cb8817861439818b430 Mon Sep 17 00:00:00 2001
From: Guido Cella <guido@guidocella.xyz>
Date: Mon, 30 Sep 2024 08:40:25 +0200
Subject: [PATCH] allow switching to the configured tag when a window opens
Add a rule option to switch to the configured tag when a window opens,
then switch back when it closes.
---
config.def.h | 6 +++---
dwl.c | 23 +++++++++++++++++++----
2 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/config.def.h b/config.def.h
index 8a6eda0..59e3ac5 100644
--- a/config.def.h
+++ b/config.def.h
@@ -21,9 +21,9 @@ static const float fullscreen_bg[] = {0.0f, 0.0f, 0.0f, 1.0f}; /* You ca
static int log_level = WLR_ERROR;
static const Rule rules[] = {
- /* app_id title tags mask isfloating monitor */
- { "Gimp_EXAMPLE", NULL, 0, 1, -1 }, /* Start on currently visible tags floating, not tiled */
- { "firefox_EXAMPLE", NULL, 1 << 8, 0, -1 }, /* Start on ONLY tag "9" */
+ /* app_id title tags mask switchtotag isfloating monitor */
+ { "Gimp_EXAMPLE", NULL, 0, 0 1, -1 }, /* Start on currently visible tags floating, not tiled */
+ { "firefox_EXAMPLE", NULL, 1 << 8, 1 0, -1 }, /* Start on ONLY tag "9" */
/* default/example rule: can be changed but cannot be eliminated; at least one rule must exist */
};
diff --git a/dwl.c b/dwl.c
index 44f3ad9..7a97d94 100644
--- a/dwl.c
+++ b/dwl.c
@@ -138,6 +138,7 @@ typedef struct {
unsigned int bw;
uint32_t tags;
int isfloating, isurgent, isfullscreen;
+ int switchtotag;
uint32_t resize; /* configure serial of a pending resize */
} Client;
@@ -226,6 +227,7 @@ typedef struct {
const char *id;
const char *title;
uint32_t tags;
+ bool switchtotag;
int isfloating;
int monitor;
} Rule;
@@ -241,7 +243,7 @@ typedef struct {
/* function declarations */
static void applybounds(Client *c, struct wlr_box *bbox);
-static void applyrules(Client *c);
+static void applyrules(Client *c, bool map);
static void arrange(Monitor *m);
static void arrangelayer(Monitor *m, struct wl_list *list,
struct wlr_box *usable_area, int exclusive);
@@ -474,7 +476,7 @@ applybounds(Client *c, struct wlr_box *bbox)
}
void
-applyrules(Client *c)
+applyrules(Client *c, bool map)
{
/* rule matching */
const char *appid, *title;
@@ -496,6 +498,11 @@ applyrules(Client *c)
if (r->monitor == i++)
mon = m;
}
+ if (r->switchtotag && map) {
+ c->switchtotag = selmon->tagset[selmon->seltags];
+ mon->seltags ^= 1;
+ mon->tagset[selmon->seltags] = r->tags & TAGMASK;
+ }
}
}
@@ -864,7 +871,7 @@ commitnotify(struct wl_listener *listener, void *data)
* a different monitor based on its title, this will likely select
* a wrong monitor.
*/
- applyrules(c);
+ applyrules(c, false);
if (c->mon) {
client_set_scale(client_surface(c), c->mon->wlr_output->scale);
}
@@ -1790,7 +1797,7 @@ mapnotify(struct wl_listener *listener, void *data)
c->isfloating = 1;
setmon(c, p->mon, p->tags);
} else {
- applyrules(c);
+ applyrules(c, true);
}
printstatus();
@@ -2831,6 +2838,14 @@ unmapnotify(struct wl_listener *listener, void *data)
wl_list_remove(&c->flink);
}
+ if (c->switchtotag) {
+ Arg a = { .ui = c->switchtotag };
+ // Call view() -> arrange() -> checkidleinhibitor() before
+ // wlr_scene_node_destroy() to prevent a rare use after free of
+ // tree->node.
+ view(&a);
+ }
+
wlr_scene_node_destroy(&c->scene->node);
printstatus();
motionnotify(0, NULL, 0, 0, 0, 0);
--
2.52.0