-
Notifications
You must be signed in to change notification settings - Fork 6
/
dwm-hide-and-restore.diff
189 lines (186 loc) · 5.66 KB
/
dwm-hide-and-restore.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
diff --git a/config.def.h b/config.def.h
index 1c0b587..b4cb248 100644
--- a/config.def.h
+++ b/config.def.h
@@ -70,6 +70,10 @@ static Key keys[] = {
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
{ MODKEY, XK_l, setmfact, {.f = +0.05} },
+ {MODKEY, XK_o, hidewin, {0}},
+ {MODKEY|ShiftMask, XK_o, restorewin, {0}},
+ {MODKEY, XK_w, hideotherwins, {0}},
+ {MODKEY|ShiftMask, XK_w, restoreotherwins, {0}},
{ MODKEY, XK_Return, zoom, {0} },
{ MODKEY, XK_Tab, view, {0} },
{ MODKEY|ShiftMask, XK_q, killclient, {0} },
diff --git a/dwm.c b/dwm.c
index 4465af1..8046d56 100644
--- a/dwm.c
+++ b/dwm.c
@@ -213,6 +213,12 @@ static void togglebar(const Arg *arg);
static void togglefloating(const Arg *arg);
static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg);
+static void hidewin(const Arg *arg);
+static void restorewin(const Arg *arg);
+static void hideotherwins(const Arg *arg);
+static void restoreotherwins(const Arg *arg);
+static int issinglewin(const Arg *arg);
+static void focuswin(const Arg *arg);
static void unfocus(Client *c, int setfocus);
static void unmanage(Client *c, int destroyed);
static void unmapnotify(XEvent *e);
@@ -268,6 +274,10 @@ static Drw *drw;
static Monitor *mons, *selmon;
static Window root, wmcheckwin;
+#define hiddenWinStackMax 100
+static int hiddenWinStackTop = -1;
+static Client *hiddenWinStack[hiddenWinStackMax];
+
/* configuration, allows nested code to access above variables */
#include "config.h"
@@ -834,19 +834,24 @@ focusstack(const Arg *arg)
{
Client *c = NULL, *i;
+ if (issinglewin(arg)) {
+ focuswin(arg);
+ return;
+ }
+
if (!selmon->sel)
return;
if (arg->i > 0) {
- for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next);
+ for (c = selmon->sel->next; c && (!ISVISIBLE(c) || HIDDEN(c)); c = c->next);
if (!c)
- for (c = selmon->clients; c && !ISVISIBLE(c); c = c->next);
+ for (c = selmon->clients; c && (!ISVISIBLE(c) || HIDDEN(c)); c = c->next);
} else {
for (i = selmon->clients; i != selmon->sel; i = i->next)
- if (ISVISIBLE(i))
+ if (ISVISIBLE(i) && !HIDDEN(i))
c = i;
if (!c)
for (; i; i = i->next)
- if (ISVISIBLE(i))
+ if (ISVISIBLE(i) && !HIDDEN(i))
c = i;
}
if (c) {
@@ -1734,6 +1744,118 @@ toggletag(const Arg *arg)
}
}
+void hidewin(const Arg *arg) {
+ if (!selmon->sel)
+ return;
+ Client *c = (Client *)selmon->sel;
+ hide(c);
+ hiddenWinStack[++hiddenWinStackTop] = c;
+}
+
+void restorewin(const Arg *arg) {
+ int i = hiddenWinStackTop;
+ while (i > -1) {
+ if (HIDDEN(hiddenWinStack[i]) &&
+ hiddenWinStack[i]->tags == selmon->tagset[selmon->seltags]) {
+ show(hiddenWinStack[i]);
+ focus(hiddenWinStack[i]);
+ restack(selmon);
+ for (int j = i; j < hiddenWinStackTop; ++j) {
+ hiddenWinStack[j] = hiddenWinStack[j + 1];
+ }
+ --hiddenWinStackTop;
+ return;
+ }
+ --i;
+ }
+}
+
+void hideotherwins(const Arg *arg) {
+ Client *c = NULL, *i;
+ if (!selmon->sel)
+ return;
+ c = (Client *)selmon->sel;
+ for (i = selmon->clients; i; i = i->next) {
+ if (i != c && ISVISIBLE(i)) {
+ hide(i);
+ hiddenWinStack[++hiddenWinStackTop] = i;
+ }
+ }
+}
+
+void restoreotherwins(const Arg *arg) {
+ int i;
+ for (i = 0; i <= hiddenWinStackTop; ++i) {
+ if (HIDDEN(hiddenWinStack[i]) &&
+ hiddenWinStack[i]->tags == selmon->tagset[selmon->seltags]) {
+ show(hiddenWinStack[i]);
+ restack(selmon);
+ memcpy(hiddenWinStack + i, hiddenWinStack + i + 1,
+ (hiddenWinStackTop - i) * sizeof(Client *));
+ --hiddenWinStackTop;
+ --i;
+ }
+ }
+}
+
+int issinglewin(const Arg *arg) {
+ Client *c = NULL;
+ int cot = 0;
+ int tag = selmon->tagset[selmon->seltags];
+ for (c = selmon->clients; c; c = c->next) {
+ if (ISVISIBLE(c) && !HIDDEN(c) && c->tags == tag) {
+ cot++;
+ }
+ if (cot > 1) {
+ return 0;
+ }
+ }
+ return 1;
+}
+
+void focuswin(const Arg *arg) {
+ Client *c = NULL, *i;
+ int j, k;
+
+ if (arg->i > 0) {
+ for (c = selmon->sel->next;
+ c && !(c->tags == selmon->tagset[selmon->seltags]); c = c->next)
+ ;
+ if (!c)
+ for (c = selmon->clients;
+ c && !(c->tags == selmon->tagset[selmon->seltags]);
+ c = c->next)
+ ;
+ } else {
+ for (i = selmon->clients; i != selmon->sel; i = i->next)
+ if (i->tags == selmon->tagset[selmon->seltags])
+ c = i;
+ if (!c)
+ for (; i; i = i->next)
+ if (i->tags == selmon->tagset[selmon->seltags])
+ c = i;
+ }
+
+ i = selmon->sel;
+
+ if (c && c != i) {
+ hide(i);
+ for (j = 0; j <= hiddenWinStackTop; ++j) {
+ if (HIDDEN(hiddenWinStack[j]) &&
+ hiddenWinStack[j]->tags == selmon->tagset[selmon->seltags] &&
+ hiddenWinStack[j] == c) {
+ show(c);
+ focus(c);
+ restack(selmon);
+ memcpy(hiddenWinStack + j, hiddenWinStack + j + 1,
+ (hiddenWinStackTop - j) * sizeof(Client *));
+ hiddenWinStack[hiddenWinStackTop] = i;
+ return;
+ }
+ }
+ }
+}
+
void
toggleview(const Arg *arg)
{