This repository has been archived by the owner on Mar 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdwm-scratchpad-20200727-bb2e7222baeec7776930354d0e9f210cc2aaad5f.diff
166 lines (160 loc) · 4.11 KB
/
dwm-scratchpad-20200727-bb2e7222baeec7776930354d0e9f210cc2aaad5f.diff
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
diff --git a/config.def.h b/config.def.h
index 1c0b587..48cf601 100644
--- a/config.def.h
+++ b/config.def.h
@@ -94,6 +94,9 @@ static Key keys[] = {
TAGKEYS( XK_8, 7)
TAGKEYS( XK_9, 8)
{ MODKEY|ShiftMask, XK_q, quit, {0} },
+ { MODKEY, XK_minus, scratchpad_show, {0} },
+ { MODKEY|ShiftMask, XK_minus, scratchpad_hide, {0} },
+ { MODKEY, XK_equal,scratchpad_remove,{0} },
};
/* button definitions */
diff --git a/dwm.c b/dwm.c
index 9fd0286..c647493 100644
--- a/dwm.c
+++ b/dwm.c
@@ -195,6 +195,12 @@ static void resizemouse(const Arg *arg);
static void restack(Monitor *m);
static void run(void);
static void scan(void);
+static void scratchpad_hide ();
+static _Bool scratchpad_last_showed_is_killed (void);
+static void scratchpad_remove ();
+static void scratchpad_show ();
+static void scratchpad_show_client (Client * c);
+static void scratchpad_show_first (void);
static int sendevent(Client *c, Atom proto);
static void sendmon(Client *c, Monitor *m);
static void setclientstate(Client *c, long state);
@@ -269,11 +275,15 @@ static Drw *drw;
static Monitor *mons, *selmon;
static Window root, wmcheckwin;
+/* scratchpad */
+# define SCRATCHPAD_MASK (1u << sizeof tags / sizeof * tags)
+static Client * scratchpad_last_showed = NULL;
+
/* configuration, allows nested code to access above variables */
#include "config.h"
/* compile-time check if all tags fit into an unsigned int bit array. */
-struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
+struct NumTags { char limitexceeded[LENGTH(tags) > 30 ? -1 : 1]; };
/* function implementations */
void
@@ -309,7 +319,8 @@ applyrules(Client *c)
XFree(ch.res_class);
if (ch.res_name)
XFree(ch.res_name);
- c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags];
+ if (c->tags != SCRATCHPAD_MASK)
+ c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags];
}
int
@@ -1408,6 +1419,98 @@ scan(void)
}
}
+static void scratchpad_hide ()
+{
+ if (selmon -> sel)
+ {
+ selmon -> sel -> tags = SCRATCHPAD_MASK;
+ selmon -> sel -> isfloating = 1;
+ focus(NULL);
+ arrange(selmon);
+ }
+}
+
+static _Bool scratchpad_last_showed_is_killed (void)
+{
+ _Bool killed = 1;
+ for (Client * c = selmon -> clients; c != NULL; c = c -> next)
+ {
+ if (c == scratchpad_last_showed)
+ {
+ killed = 0;
+ break;
+ }
+ }
+ return killed;
+}
+
+static void scratchpad_remove ()
+{
+ if (selmon -> sel && scratchpad_last_showed != NULL && selmon -> sel == scratchpad_last_showed)
+ scratchpad_last_showed = NULL;
+}
+
+static void scratchpad_show ()
+{
+ if (scratchpad_last_showed == NULL || scratchpad_last_showed_is_killed ())
+ scratchpad_show_first ();
+ else
+ {
+ if (scratchpad_last_showed -> tags != SCRATCHPAD_MASK)
+ {
+ scratchpad_last_showed -> tags = SCRATCHPAD_MASK;
+ focus(NULL);
+ arrange(selmon);
+ }
+ else
+ {
+ _Bool found_current = 0;
+ _Bool found_next = 0;
+ for (Client * c = selmon -> clients; c != NULL; c = c -> next)
+ {
+ if (found_current == 0)
+ {
+ if (c == scratchpad_last_showed)
+ {
+ found_current = 1;
+ continue;
+ }
+ }
+ else
+ {
+ if (c -> tags == SCRATCHPAD_MASK)
+ {
+ found_next = 1;
+ scratchpad_show_client (c);
+ break;
+ }
+ }
+ }
+ if (found_next == 0) scratchpad_show_first ();
+ }
+ }
+}
+
+static void scratchpad_show_client (Client * c)
+{
+ scratchpad_last_showed = c;
+ c -> tags = selmon->tagset[selmon->seltags];
+ focus(c);
+ arrange(selmon);
+}
+
+static void scratchpad_show_first (void)
+{
+ for (Client * c = selmon -> clients; c != NULL; c = c -> next)
+ {
+ if (c -> tags == SCRATCHPAD_MASK)
+ {
+ scratchpad_show_client (c);
+ break;
+ }
+ }
+}
+
void
sendmon(Client *c, Monitor *m)
{
@@ -1781,6 +1884,8 @@ unmanage(Client *c, int destroyed)
XSetErrorHandler(xerror);
XUngrabServer(dpy);
}
+ if (scratchpad_last_showed == c)
+ scratchpad_last_showed = NULL;
free(c);
focus(NULL);
updateclientlist();