summaryrefslogtreecommitdiffstats
path: root/dwl-patches/patches/switchtotag/switchtotag.patch
blob: bbe1638e9478df2a63eb2c0dff1a6d887fe71a8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
From 08cfc2eceb34316cfd7eaf591a8a631e3d58ff3a 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 22d2171..52ea128 100644
--- a/config.def.h
+++ b/config.def.h
@@ -22,10 +22,10 @@ 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   monitor */
+	/* app_id             title       tags mask     switchtotag   isfloating   monitor */
 	/* examples: */
-	{ "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" */
+	{ "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" */
 };
 
 /* layout(s) */
diff --git a/dwl.c b/dwl.c
index dc0c861..621b614 100644
--- a/dwl.c
+++ b/dwl.c
@@ -142,6 +142,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;
 
@@ -230,6 +231,7 @@ typedef struct {
 	const char *id;
 	const char *title;
 	uint32_t tags;
+	bool switchtotag;
 	int isfloating;
 	int monitor;
 } Rule;
@@ -245,7 +247,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);
@@ -449,7 +451,7 @@ applybounds(Client *c, struct wlr_box *bbox)
 }
 
 void
-applyrules(Client *c)
+applyrules(Client *c, bool map)
 {
 	/* rule matching */
 	const char *appid, *title;
@@ -472,6 +474,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;
+			}
 		}
 	}
 	setmon(c, mon, newtags);
@@ -795,7 +802,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);
 		}
@@ -1733,7 +1740,7 @@ mapnotify(struct wl_listener *listener, void *data)
 		c->isfloating = 1;
 		setmon(c, p->mon, p->tags);
 	} else {
-		applyrules(c);
+		applyrules(c, true);
 	}
 	printstatus();
 
@@ -2769,6 +2776,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.46.0