summaryrefslogtreecommitdiff
path: root/patches/dwl-namedscratchpads.diff
blob: a83d32211b4409e07b9de1cef1031869b2f6adc9 (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
From 13402c1ccead7a6775520bd1ceef31611583c965 Mon Sep 17 00:00:00 2001
From: Louis-Michel Raynauld <louismichel@pweb.ca>
Date: Fri, 29 Jul 2022 23:09:10 -0700
Subject: [PATCH 1/2] port dwm "namedscratchpads" patch to dwl

---
 config.def.h |  9 +++++++--
 dwl.c        | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/config.def.h b/config.def.h
index 190b0da4..b5f87336 100644
--- a/config.def.h
+++ b/config.def.h
@@ -10,11 +10,12 @@ static const float focuscolor[]     = {1.0, 0.0, 0.0, 1.0};
 static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
 
 static const Rule rules[] = {
-	/* app_id     title       tags mask     isfloating   monitor */
+	/* app_id     title       tags mask     isfloating   monitor scratchkey */
 	/* examples:
 	{ "Gimp",     NULL,       0,            1,           -1 },
 	*/
-	{ "firefox",  NULL,       1 << 8,       0,           -1 },
+	{ "firefox",  NULL,       1 << 8,       0,           -1,      0  },
+	{ NULL,     "scratchpad", 0,            1,           -1,     's' },
 };
 
 /* layout(s) */
@@ -66,11 +67,15 @@ static const int natural_scrolling = 0;
 static const char *termcmd[] = { "alacritty", NULL };
 static const char *menucmd[] = { "bemenu-run", NULL };
 
+/* named scratchpads - First arg only serves to match against key in rules*/
+static const char *scratchpadcmd[] = { "s", "alacritty", "-t", "scratchpad", 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,                    XKB_KEY_grave,      togglescratch,  {.v = scratchpadcmd } },
 	{ 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 b09fc6f9..f21488c0 100644
--- a/dwl.c
+++ b/dwl.c
@@ -118,6 +118,7 @@ typedef struct {
 	int isfloating, isurgent;
 	uint32_t resize; /* configure serial of a pending resize */
 	int isfullscreen;
+	char scratchkey;
 } Client;
 
 typedef struct {
@@ -198,6 +199,7 @@ typedef struct {
 	unsigned int tags;
 	int isfloating;
 	int monitor;
+	const char scratchkey;
 } Rule;
 
 /* function declarations */
@@ -273,12 +275,14 @@ static void setsel(struct wl_listener *listener, void *data);
 static void setup(void);
 static void sigchld(int unused);
 static void spawn(const Arg *arg);
+static void spawnscratch(const Arg *arg);
 static void startdrag(struct wl_listener *listener, void *data);
 static void tag(const Arg *arg);
 static void tagmon(const Arg *arg);
 static void tile(Monitor *m);
 static void togglefloating(const Arg *arg);
 static void togglefullscreen(const Arg *arg);
+static void togglescratch(const Arg *arg);
 static void toggletag(const Arg *arg);
 static void toggleview(const Arg *arg);
 static void unmaplayersurface(LayerSurface *layersurface);
@@ -457,6 +461,7 @@ applyrules(Client *c)
 	Monitor *mon = selmon, *m;
 
 	c->isfloating = client_is_float_type(c);
+	c->scratchkey = 0;
 	if (!(appid = client_get_appid(c)))
 		appid = broken;
 	if (!(title = client_get_title(c)))
@@ -466,6 +471,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;
 			i = 0;
 			wl_list_for_each(m, &mons, link)
@@ -2092,6 +2098,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)
 {
@@ -2176,6 +2192,32 @@ togglefullscreen(const Arg *arg)
 		setfullscreen(sel, !sel->isfullscreen);
 }
 
+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(NULL, 0);
+		if (VISIBLEON(c, selmon)) {
+			focusclient(c, 0);
+		}
+		arrange(selmon);
+
+	} else{
+		spawnscratch(arg);
+	}
+}
+
 void
 toggletag(const Arg *arg)
 {

From be5e75b1bad480a7eedd81ef68cc331687fbe7cd Mon Sep 17 00:00:00 2001
From: Louis-Michel Raynauld <louismichel@pweb.ca>
Date: Fri, 5 Aug 2022 22:20:59 -0700
Subject: [PATCH 2/2] Fix focus after hiding and make sure toggle scratchpad
 appears on top of others scratchpads if any.

---
 dwl.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/dwl.c b/dwl.c
index f21488c0..e0ecdb8e 100644
--- a/dwl.c
+++ b/dwl.c
@@ -2207,12 +2207,9 @@ togglescratch(const Arg *arg)
 
 	if (found) {
 		c->tags = VISIBLEON(c, selmon) ? 0 : selmon->tagset[selmon->seltags];
-		focusclient(NULL, 0);
-		if (VISIBLEON(c, selmon)) {
-			focusclient(c, 0);
-		}
-		arrange(selmon);
 
+		focusclient(c->tags == 0 ? focustop(selmon) : c, 1);
+		arrange(selmon);
 	} else{
 		spawnscratch(arg);
 	}