rev |
line source |
arg@327
|
1 /*
|
arg@327
|
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
arg@327
|
3 * See LICENSE file for license details.
|
arg@327
|
4 */
|
arg@327
|
5 #include "dwm.h"
|
arg@382
|
6 #include <stdio.h>
|
arg@327
|
7
|
arg@380
|
8 /* static */
|
arg@380
|
9
|
arg@382
|
10 static Client *
|
arg@382
|
11 minclient()
|
arg@382
|
12 {
|
arg@382
|
13 Client *c, *min;
|
arg@382
|
14
|
arg@382
|
15 for(min = c = clients; c; c = c->next)
|
arg@382
|
16 if(c->weight < min->weight)
|
arg@382
|
17 min = c;
|
arg@382
|
18 return min;
|
arg@382
|
19 }
|
arg@382
|
20
|
arg@382
|
21
|
arg@381
|
22 static void
|
arg@381
|
23 reorder()
|
arg@380
|
24 {
|
arg@382
|
25 Client *c, *newclients, *tail;
|
arg@380
|
26
|
arg@382
|
27 newclients = tail = NULL;
|
arg@382
|
28 while((c = minclient())) {
|
arg@381
|
29 detach(c);
|
arg@382
|
30 if(tail) {
|
arg@382
|
31 c->prev = tail;
|
arg@382
|
32 tail->next = c;
|
arg@382
|
33 tail = c;
|
arg@381
|
34 }
|
arg@381
|
35 else
|
arg@382
|
36 tail = newclients = c;
|
arg@380
|
37 }
|
arg@382
|
38 clients = newclients;
|
arg@380
|
39 }
|
arg@380
|
40
|
arg@327
|
41 /* extern */
|
arg@327
|
42
|
arg@327
|
43 void (*arrange)(Arg *) = DEFMODE;
|
arg@327
|
44
|
arg@327
|
45 void
|
arg@378
|
46 detach(Client *c)
|
arg@378
|
47 {
|
arg@378
|
48 if(c->prev)
|
arg@378
|
49 c->prev->next = c->next;
|
arg@378
|
50 if(c->next)
|
arg@378
|
51 c->next->prev = c->prev;
|
arg@378
|
52 if(c == clients)
|
arg@378
|
53 clients = c->next;
|
arg@378
|
54 c->next = c->prev = NULL;
|
arg@378
|
55 }
|
arg@378
|
56
|
arg@378
|
57 void
|
arg@327
|
58 dofloat(Arg *arg)
|
arg@327
|
59 {
|
arg@402
|
60 Client *c;
|
arg@400
|
61
|
arg@400
|
62 maximized = False;
|
arg@327
|
63
|
arg@327
|
64 for(c = clients; c; c = c->next) {
|
arg@327
|
65 if(isvisible(c)) {
|
arg@327
|
66 resize(c, True, TopLeft);
|
arg@327
|
67 }
|
arg@327
|
68 else
|
arg@327
|
69 ban(c);
|
arg@327
|
70 }
|
arg@401
|
71 if(!sel || !isvisible(sel))
|
arg@401
|
72 focus(getnext(clients));
|
arg@327
|
73 restack();
|
arg@327
|
74 }
|
arg@327
|
75
|
arg@327
|
76 void
|
arg@327
|
77 dotile(Arg *arg)
|
arg@327
|
78 {
|
arg@327
|
79 int h, i, n, w;
|
arg@402
|
80 Client *c;
|
arg@400
|
81
|
arg@400
|
82 maximized = False;
|
arg@327
|
83
|
arg@327
|
84 w = sw - mw;
|
arg@429
|
85 for(n = 0, c = clients; c && !c->isfloat; c = c->next)
|
arg@429
|
86 if(isvisible(c))
|
arg@327
|
87 n++;
|
arg@327
|
88
|
arg@327
|
89 if(n > 1)
|
arg@327
|
90 h = (sh - bh) / (n - 1);
|
arg@327
|
91 else
|
arg@327
|
92 h = sh - bh;
|
arg@327
|
93
|
arg@327
|
94 for(i = 0, c = clients; c; c = c->next) {
|
arg@327
|
95 if(isvisible(c)) {
|
arg@327
|
96 if(c->isfloat) {
|
arg@327
|
97 resize(c, True, TopLeft);
|
arg@327
|
98 continue;
|
arg@327
|
99 }
|
arg@327
|
100 if(n == 1) {
|
arg@327
|
101 c->x = sx;
|
arg@327
|
102 c->y = sy + bh;
|
arg@327
|
103 c->w = sw - 2;
|
arg@327
|
104 c->h = sh - 2 - bh;
|
arg@327
|
105 }
|
arg@327
|
106 else if(i == 0) {
|
arg@327
|
107 c->x = sx;
|
arg@327
|
108 c->y = sy + bh;
|
arg@327
|
109 c->w = mw - 2;
|
arg@327
|
110 c->h = sh - 2 - bh;
|
arg@327
|
111 }
|
arg@327
|
112 else if(h > bh) {
|
arg@327
|
113 c->x = sx + mw;
|
arg@327
|
114 c->y = sy + (i - 1) * h + bh;
|
arg@327
|
115 c->w = w - 2;
|
arg@327
|
116 if(i + 1 == n)
|
arg@327
|
117 c->h = sh - c->y - 2;
|
arg@327
|
118 else
|
arg@327
|
119 c->h = h - 2;
|
arg@327
|
120 }
|
arg@327
|
121 else { /* fallback if h < bh */
|
arg@327
|
122 c->x = sx + mw;
|
arg@327
|
123 c->y = sy + bh;
|
arg@327
|
124 c->w = w - 2;
|
arg@327
|
125 c->h = sh - 2 - bh;
|
arg@327
|
126 }
|
arg@327
|
127 resize(c, False, TopLeft);
|
arg@327
|
128 i++;
|
arg@327
|
129 }
|
arg@327
|
130 else
|
arg@327
|
131 ban(c);
|
arg@327
|
132 }
|
arg@401
|
133 if(!sel || !isvisible(sel))
|
arg@401
|
134 focus(getnext(clients));
|
arg@327
|
135 restack();
|
arg@327
|
136 }
|
arg@327
|
137
|
arg@327
|
138 void
|
arg@327
|
139 focusnext(Arg *arg)
|
arg@327
|
140 {
|
arg@327
|
141 Client *c;
|
arg@327
|
142
|
arg@327
|
143 if(!sel)
|
arg@327
|
144 return;
|
arg@327
|
145
|
arg@327
|
146 if(!(c = getnext(sel->next)))
|
arg@327
|
147 c = getnext(clients);
|
arg@327
|
148 if(c) {
|
arg@327
|
149 focus(c);
|
arg@327
|
150 restack();
|
arg@327
|
151 }
|
arg@327
|
152 }
|
arg@327
|
153
|
arg@327
|
154 void
|
arg@327
|
155 focusprev(Arg *arg)
|
arg@327
|
156 {
|
arg@327
|
157 Client *c;
|
arg@327
|
158
|
arg@327
|
159 if(!sel)
|
arg@327
|
160 return;
|
arg@327
|
161
|
arg@327
|
162 if(!(c = getprev(sel->prev))) {
|
arg@327
|
163 for(c = clients; c && c->next; c = c->next);
|
arg@327
|
164 c = getprev(c);
|
arg@327
|
165 }
|
arg@327
|
166 if(c) {
|
arg@327
|
167 focus(c);
|
arg@327
|
168 restack();
|
arg@327
|
169 }
|
arg@327
|
170 }
|
arg@327
|
171
|
arg@420
|
172 Bool
|
arg@420
|
173 isvisible(Client *c)
|
arg@420
|
174 {
|
arg@420
|
175 unsigned int i;
|
arg@420
|
176
|
arg@420
|
177 for(i = 0; i < ntags; i++)
|
arg@420
|
178 if(c->tags[i] && seltag[i])
|
arg@420
|
179 return True;
|
arg@420
|
180 return False;
|
arg@420
|
181 }
|
arg@420
|
182
|
arg@415
|
183 void
|
arg@422
|
184 resizecol(Arg *arg)
|
arg@415
|
185 {
|
arg@423
|
186 unsigned int n;
|
arg@423
|
187 Client *c;
|
arg@418
|
188
|
arg@429
|
189 for(n = 0, c = clients; c && !c->isfloat; c = c->next)
|
arg@429
|
190 if(isvisible(c))
|
arg@423
|
191 n++;
|
arg@423
|
192 if(!sel || sel->isfloat || n < 2 || (arrange != dotile) || maximized)
|
arg@415
|
193 return;
|
arg@423
|
194
|
arg@415
|
195 if(sel == getnext(clients)) {
|
arg@425
|
196 if(mw + arg->i > sw - 100 || mw + arg->i < 100)
|
arg@415
|
197 return;
|
arg@415
|
198 mw += arg->i;
|
arg@415
|
199 }
|
arg@415
|
200 else {
|
arg@425
|
201 if(mw - arg->i > sw - 100 || mw - arg->i < 100)
|
arg@415
|
202 return;
|
arg@415
|
203 mw -= arg->i;
|
arg@415
|
204 }
|
arg@415
|
205 arrange(NULL);
|
arg@415
|
206 }
|
arg@415
|
207
|
arg@327
|
208 void
|
arg@327
|
209 restack()
|
arg@327
|
210 {
|
arg@327
|
211 static unsigned int nwins = 0;
|
arg@327
|
212 static Window *wins = NULL;
|
arg@327
|
213 unsigned int f, fi, m, mi, n;
|
arg@327
|
214 Client *c;
|
arg@327
|
215 XEvent ev;
|
arg@327
|
216
|
arg@327
|
217 for(f = 0, m = 0, c = clients; c; c = c->next)
|
arg@327
|
218 if(isvisible(c)) {
|
arg@327
|
219 if(c->isfloat || arrange == dofloat)
|
arg@327
|
220 f++;
|
arg@327
|
221 else
|
arg@327
|
222 m++;
|
arg@327
|
223 }
|
arg@327
|
224 if(!(n = 2 * (f + m))) {
|
arg@327
|
225 drawstatus();
|
arg@327
|
226 return;
|
arg@327
|
227 }
|
arg@327
|
228 if(nwins < n) {
|
arg@327
|
229 nwins = n;
|
arg@327
|
230 wins = erealloc(wins, nwins * sizeof(Window));
|
arg@327
|
231 }
|
arg@327
|
232
|
arg@327
|
233 fi = 0;
|
arg@327
|
234 mi = 2 * f;
|
arg@414
|
235 if(sel) {
|
arg@414
|
236 if(sel->isfloat || arrange == dofloat) {
|
arg@414
|
237 wins[fi++] = sel->twin;
|
arg@414
|
238 wins[fi++] = sel->win;
|
arg@414
|
239 }
|
arg@414
|
240 else {
|
arg@414
|
241 wins[mi++] = sel->twin;
|
arg@414
|
242 wins[mi++] = sel->win;
|
arg@414
|
243 }
|
arg@327
|
244 }
|
arg@327
|
245 for(c = clients; c; c = c->next)
|
arg@327
|
246 if(isvisible(c) && c != sel) {
|
arg@327
|
247 if(c->isfloat || arrange == dofloat) {
|
arg@342
|
248 wins[fi++] = c->twin;
|
arg@327
|
249 wins[fi++] = c->win;
|
arg@327
|
250 }
|
arg@327
|
251 else {
|
arg@342
|
252 wins[mi++] = c->twin;
|
arg@327
|
253 wins[mi++] = c->win;
|
arg@327
|
254 }
|
arg@327
|
255 }
|
arg@327
|
256 XRestackWindows(dpy, wins, n);
|
arg@327
|
257 drawall();
|
arg@327
|
258 XSync(dpy, False);
|
arg@327
|
259 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
|
arg@327
|
260 }
|
arg@327
|
261
|
arg@327
|
262 void
|
arg@327
|
263 togglemode(Arg *arg)
|
arg@327
|
264 {
|
arg@333
|
265 arrange = (arrange == dofloat) ? dotile : dofloat;
|
arg@327
|
266 if(sel)
|
arg@327
|
267 arrange(NULL);
|
arg@327
|
268 else
|
arg@327
|
269 drawstatus();
|
arg@327
|
270 }
|
arg@327
|
271
|
arg@327
|
272 void
|
arg@327
|
273 toggleview(Arg *arg)
|
arg@327
|
274 {
|
arg@327
|
275 unsigned int i;
|
arg@327
|
276
|
arg@327
|
277 seltag[arg->i] = !seltag[arg->i];
|
arg@327
|
278 for(i = 0; i < ntags && !seltag[i]; i++);
|
arg@327
|
279 if(i == ntags)
|
arg@327
|
280 seltag[arg->i] = True; /* cannot toggle last view */
|
arg@381
|
281 reorder();
|
arg@327
|
282 arrange(NULL);
|
arg@327
|
283 }
|
arg@327
|
284
|
arg@327
|
285 void
|
arg@327
|
286 view(Arg *arg)
|
arg@327
|
287 {
|
arg@327
|
288 unsigned int i;
|
arg@327
|
289
|
arg@327
|
290 for(i = 0; i < ntags; i++)
|
arg@327
|
291 seltag[i] = False;
|
arg@327
|
292 seltag[arg->i] = True;
|
arg@381
|
293 reorder();
|
arg@327
|
294 arrange(NULL);
|
arg@327
|
295 }
|
arg@327
|
296
|
arg@327
|
297 void
|
arg@395
|
298 viewall(Arg *arg)
|
arg@395
|
299 {
|
arg@395
|
300 unsigned int i;
|
arg@395
|
301
|
arg@395
|
302 for(i = 0; i < ntags; i++)
|
arg@395
|
303 seltag[i] = True;
|
arg@397
|
304 reorder();
|
arg@395
|
305 arrange(NULL);
|
arg@395
|
306 }
|
arg@395
|
307
|
arg@395
|
308 void
|
arg@327
|
309 zoom(Arg *arg)
|
arg@327
|
310 {
|
arg@423
|
311 unsigned int n;
|
arg@423
|
312 Client *c;
|
arg@327
|
313
|
arg@429
|
314 for(n = 0, c = clients; c && !c->isfloat; c = c->next)
|
arg@429
|
315 if(isvisible(c))
|
arg@423
|
316 n++;
|
arg@423
|
317 if(!sel || sel->isfloat || n < 2 || (arrange != dotile) || maximized)
|
arg@327
|
318 return;
|
arg@327
|
319
|
arg@429
|
320 if((c = sel) == getnext(clients))
|
arg@429
|
321 if(!(c = getnext(c->next)) || c->isfloat)
|
arg@429
|
322 return;
|
arg@378
|
323 detach(c);
|
arg@381
|
324 c->next = clients;
|
arg@381
|
325 clients->prev = c;
|
arg@381
|
326 clients = c;
|
arg@378
|
327 focus(c);
|
arg@327
|
328 arrange(NULL);
|
arg@327
|
329 }
|