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@327
|
6
|
arg@522
|
7 #define MINDIM 100
|
arg@522
|
8
|
arg@380
|
9 /* static */
|
arg@380
|
10
|
arg@382
|
11 static Client *
|
arg@487
|
12 minclient(void) {
|
arg@382
|
13 Client *c, *min;
|
arg@382
|
14
|
arg@443
|
15 if((clients && clients->isfloat) || arrange == dofloat)
|
arg@443
|
16 return clients; /* don't touch floating order */
|
arg@382
|
17 for(min = c = clients; c; c = c->next)
|
arg@382
|
18 if(c->weight < min->weight)
|
arg@382
|
19 min = c;
|
arg@382
|
20 return min;
|
arg@382
|
21 }
|
arg@382
|
22
|
arg@480
|
23 static Client *
|
arg@480
|
24 nexttiled(Client *c) {
|
arg@480
|
25 for(c = getnext(c); c && c->isfloat; c = getnext(c->next));
|
arg@480
|
26 return c;
|
arg@480
|
27 }
|
arg@480
|
28
|
arg@442
|
29 static void
|
arg@487
|
30 reorder(void) {
|
arg@382
|
31 Client *c, *newclients, *tail;
|
arg@380
|
32
|
arg@382
|
33 newclients = tail = NULL;
|
arg@382
|
34 while((c = minclient())) {
|
arg@381
|
35 detach(c);
|
arg@382
|
36 if(tail) {
|
arg@382
|
37 c->prev = tail;
|
arg@382
|
38 tail->next = c;
|
arg@382
|
39 tail = c;
|
arg@381
|
40 }
|
arg@381
|
41 else
|
arg@382
|
42 tail = newclients = c;
|
arg@380
|
43 }
|
arg@382
|
44 clients = newclients;
|
arg@380
|
45 }
|
arg@380
|
46
|
arg@480
|
47 static void
|
arg@480
|
48 togglemax(Client *c)
|
arg@480
|
49 {
|
arg@481
|
50 XEvent ev;
|
arg@480
|
51 if((c->ismax = !c->ismax)) {
|
arg@480
|
52 c->rx = c->x; c->x = sx;
|
arg@480
|
53 c->ry = c->y; c->y = bh;
|
arg@502
|
54 c->rw = c->w; c->w = sw - 2 * BORDERPX;
|
arg@502
|
55 c->rh = c->h; c->h = sh - bh - 2 * BORDERPX;
|
arg@480
|
56 }
|
arg@480
|
57 else {
|
arg@480
|
58 c->x = c->rx;
|
arg@480
|
59 c->y = c->ry;
|
arg@481
|
60 c->w = c->rw;
|
arg@481
|
61 c->h = c->rh;
|
arg@480
|
62 }
|
arg@480
|
63 resize(c, True, TopLeft);
|
arg@480
|
64 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
|
arg@430
|
65 }
|
arg@430
|
66
|
arg@327
|
67 /* extern */
|
arg@327
|
68
|
arg@327
|
69 void (*arrange)(Arg *) = DEFMODE;
|
arg@505
|
70 StackPos stackpos = STACKPOS;
|
arg@327
|
71
|
arg@327
|
72 void
|
arg@461
|
73 detach(Client *c) {
|
arg@378
|
74 if(c->prev)
|
arg@378
|
75 c->prev->next = c->next;
|
arg@378
|
76 if(c->next)
|
arg@378
|
77 c->next->prev = c->prev;
|
arg@378
|
78 if(c == clients)
|
arg@378
|
79 clients = c->next;
|
arg@378
|
80 c->next = c->prev = NULL;
|
arg@378
|
81 }
|
arg@378
|
82
|
arg@378
|
83 void
|
arg@461
|
84 dofloat(Arg *arg) {
|
arg@402
|
85 Client *c;
|
arg@400
|
86
|
arg@327
|
87 for(c = clients; c; c = c->next) {
|
arg@327
|
88 if(isvisible(c)) {
|
arg@327
|
89 resize(c, True, TopLeft);
|
arg@327
|
90 }
|
arg@327
|
91 else
|
arg@327
|
92 ban(c);
|
arg@327
|
93 }
|
arg@446
|
94 if(!sel || !isvisible(sel)) {
|
arg@450
|
95 for(c = stack; c && !isvisible(c); c = c->snext);
|
arg@450
|
96 focus(c);
|
arg@446
|
97 }
|
arg@327
|
98 restack();
|
arg@327
|
99 }
|
arg@327
|
100
|
arg@504
|
101 /* This algorithm is based on a (M)aster area and a (S)tacking area.
|
arg@504
|
102 * It supports following arrangements:
|
arg@507
|
103 * SSMMM MMMMM MMMSS
|
arg@507
|
104 * SSMMM SSSSS MMMSS
|
arg@504
|
105 */
|
arg@327
|
106 void
|
arg@461
|
107 dotile(Arg *arg) {
|
arg@507
|
108 int i, n, stackw, stackh, tw, th;
|
arg@402
|
109 Client *c;
|
arg@400
|
110
|
arg@488
|
111 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
|
arg@488
|
112 n++;
|
arg@327
|
113
|
arg@507
|
114 if(stackpos == StackBottom) {
|
arg@507
|
115 stackw = sw;
|
arg@507
|
116 stackh = sh - bh - master;
|
arg@507
|
117 }
|
arg@507
|
118 else {
|
arg@507
|
119 stackw = sw - master;
|
arg@507
|
120 stackh = sh - bh;
|
arg@507
|
121 }
|
arg@507
|
122
|
arg@511
|
123 tw = stackw;
|
arg@511
|
124 if(n > 1)
|
arg@511
|
125 th = stackh / (n - 1);
|
arg@511
|
126 else
|
arg@507
|
127 th = stackh;
|
arg@327
|
128
|
arg@327
|
129 for(i = 0, c = clients; c; c = c->next) {
|
arg@327
|
130 if(isvisible(c)) {
|
arg@327
|
131 if(c->isfloat) {
|
arg@327
|
132 resize(c, True, TopLeft);
|
arg@327
|
133 continue;
|
arg@327
|
134 }
|
arg@488
|
135 c->ismax = False;
|
arg@507
|
136 if(n == 1) { /* only 1 window */
|
arg@327
|
137 c->x = sx;
|
arg@327
|
138 c->y = sy + bh;
|
arg@502
|
139 c->w = sw - 2 * BORDERPX;
|
arg@502
|
140 c->h = sh - 2 * BORDERPX - bh;
|
arg@327
|
141 }
|
arg@507
|
142 else if(i == 0) { /* master window */
|
arg@522
|
143 c->x = sx;
|
arg@522
|
144 if(stackpos == StackLeft)
|
arg@522
|
145 c->x += stackw;
|
arg@522
|
146 c->y = sy + bh;
|
arg@508
|
147 switch(stackpos) {
|
arg@508
|
148 case StackLeft:
|
arg@522
|
149 case StackRight:
|
arg@507
|
150 c->w = master - 2 * BORDERPX;
|
arg@508
|
151 c->h = sh - bh - 2 * BORDERPX;
|
arg@508
|
152 break;
|
arg@508
|
153 case StackBottom:
|
arg@508
|
154 c->w = sw - 2 * BORDERPX;
|
arg@507
|
155 c->h = master - 2 * BORDERPX;
|
arg@508
|
156 break;
|
arg@507
|
157 }
|
arg@507
|
158 }
|
arg@522
|
159 else if(th > bh) { /* tile window */
|
arg@522
|
160 c->x = sx;
|
arg@522
|
161 if(stackpos == StackRight)
|
arg@522
|
162 c->x += master;
|
arg@507
|
163 c->w = tw - 2 * BORDERPX;
|
arg@507
|
164 c->h = th - 2 * BORDERPX;
|
arg@508
|
165 switch(stackpos) {
|
arg@508
|
166 case StackLeft:
|
arg@522
|
167 case StackRight:
|
arg@511
|
168 c->y = sy + (i - 1) * th + bh;
|
arg@511
|
169 if(i + 1 == n)
|
arg@511
|
170 c->h = sh - c->y - 2 * BORDERPX;
|
arg@508
|
171 break;
|
arg@508
|
172 case StackBottom:
|
arg@511
|
173 c->y = sy + master + (i - 1) * th + bh;
|
arg@511
|
174 if(i + 1 == n)
|
arg@511
|
175 c->h = sh - c->y - 2 * BORDERPX;
|
arg@508
|
176 break;
|
arg@507
|
177 }
|
arg@507
|
178 }
|
arg@511
|
179 else { /* fallback if th < bh */
|
arg@522
|
180 c->x = sx;
|
arg@522
|
181 if(stackpos == StackRight)
|
arg@522
|
182 c->x += master;
|
arg@522
|
183 c->y = sy + bh;
|
arg@522
|
184 if(stackpos == StackBottom)
|
arg@522
|
185 c->y += master;
|
arg@507
|
186 c->w = stackw - 2 * BORDERPX;
|
arg@507
|
187 c->h = stackh - 2 * BORDERPX;
|
arg@327
|
188 }
|
arg@327
|
189 resize(c, False, TopLeft);
|
arg@327
|
190 i++;
|
arg@327
|
191 }
|
arg@327
|
192 else
|
arg@327
|
193 ban(c);
|
arg@327
|
194 }
|
arg@446
|
195 if(!sel || !isvisible(sel)) {
|
arg@450
|
196 for(c = stack; c && !isvisible(c); c = c->snext);
|
arg@450
|
197 focus(c);
|
arg@446
|
198 }
|
arg@327
|
199 restack();
|
arg@327
|
200 }
|
arg@327
|
201
|
arg@327
|
202 void
|
arg@461
|
203 focusnext(Arg *arg) {
|
arg@327
|
204 Client *c;
|
arg@327
|
205
|
arg@327
|
206 if(!sel)
|
arg@327
|
207 return;
|
arg@327
|
208
|
arg@327
|
209 if(!(c = getnext(sel->next)))
|
arg@327
|
210 c = getnext(clients);
|
arg@327
|
211 if(c) {
|
arg@327
|
212 focus(c);
|
arg@327
|
213 restack();
|
arg@327
|
214 }
|
arg@327
|
215 }
|
arg@327
|
216
|
arg@327
|
217 void
|
arg@461
|
218 focusprev(Arg *arg) {
|
arg@327
|
219 Client *c;
|
arg@327
|
220
|
arg@327
|
221 if(!sel)
|
arg@327
|
222 return;
|
arg@327
|
223
|
arg@327
|
224 if(!(c = getprev(sel->prev))) {
|
arg@327
|
225 for(c = clients; c && c->next; c = c->next);
|
arg@327
|
226 c = getprev(c);
|
arg@327
|
227 }
|
arg@327
|
228 if(c) {
|
arg@327
|
229 focus(c);
|
arg@327
|
230 restack();
|
arg@327
|
231 }
|
arg@327
|
232 }
|
arg@327
|
233
|
arg@420
|
234 Bool
|
arg@461
|
235 isvisible(Client *c) {
|
arg@420
|
236 unsigned int i;
|
arg@420
|
237
|
arg@420
|
238 for(i = 0; i < ntags; i++)
|
arg@420
|
239 if(c->tags[i] && seltag[i])
|
arg@420
|
240 return True;
|
arg@420
|
241 return False;
|
arg@420
|
242 }
|
arg@420
|
243
|
arg@415
|
244 void
|
arg@461
|
245 resizecol(Arg *arg) {
|
arg@521
|
246 int s;
|
arg@423
|
247 unsigned int n;
|
arg@423
|
248 Client *c;
|
arg@418
|
249
|
arg@430
|
250 for(n = 0, c = clients; c; c = c->next)
|
arg@430
|
251 if(isvisible(c) && !c->isfloat)
|
arg@423
|
252 n++;
|
arg@486
|
253 if(!sel || sel->isfloat || n < 2 || (arrange == dofloat))
|
arg@415
|
254 return;
|
arg@423
|
255
|
arg@521
|
256 s = stackpos == StackBottom ? sh - bh : sw;
|
arg@415
|
257 if(sel == getnext(clients)) {
|
arg@522
|
258 if(master + arg->i > s - MINDIM || master + arg->i < MINDIM)
|
arg@415
|
259 return;
|
arg@505
|
260 master += arg->i;
|
arg@415
|
261 }
|
arg@415
|
262 else {
|
arg@522
|
263 if(master - arg->i > s - MINDIM || master - arg->i < MINDIM)
|
arg@415
|
264 return;
|
arg@505
|
265 master -= arg->i;
|
arg@415
|
266 }
|
arg@415
|
267 arrange(NULL);
|
arg@415
|
268 }
|
arg@415
|
269
|
arg@327
|
270 void
|
arg@487
|
271 restack(void) {
|
arg@327
|
272 Client *c;
|
arg@327
|
273 XEvent ev;
|
arg@481
|
274
|
arg@437
|
275 if(!sel) {
|
arg@437
|
276 drawstatus();
|
arg@436
|
277 return;
|
arg@437
|
278 }
|
arg@436
|
279 if(sel->isfloat || arrange == dofloat) {
|
arg@436
|
280 XRaiseWindow(dpy, sel->win);
|
arg@436
|
281 XRaiseWindow(dpy, sel->twin);
|
arg@436
|
282 }
|
arg@512
|
283 if(arrange != dofloat) {
|
arg@512
|
284 if(!sel->isfloat) {
|
arg@512
|
285 XLowerWindow(dpy, sel->twin);
|
arg@512
|
286 XLowerWindow(dpy, sel->win);
|
arg@512
|
287 }
|
arg@436
|
288 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
|
arg@512
|
289 if(c == sel)
|
arg@512
|
290 continue;
|
arg@436
|
291 XLowerWindow(dpy, c->twin);
|
arg@436
|
292 XLowerWindow(dpy, c->win);
|
arg@327
|
293 }
|
arg@512
|
294 }
|
arg@327
|
295 drawall();
|
arg@327
|
296 XSync(dpy, False);
|
arg@327
|
297 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
|
arg@327
|
298 }
|
arg@327
|
299
|
arg@327
|
300 void
|
arg@461
|
301 togglemode(Arg *arg) {
|
arg@333
|
302 arrange = (arrange == dofloat) ? dotile : dofloat;
|
arg@327
|
303 if(sel)
|
arg@327
|
304 arrange(NULL);
|
arg@327
|
305 else
|
arg@327
|
306 drawstatus();
|
arg@327
|
307 }
|
arg@327
|
308
|
arg@327
|
309 void
|
arg@461
|
310 toggleview(Arg *arg) {
|
arg@327
|
311 unsigned int i;
|
arg@327
|
312
|
arg@327
|
313 seltag[arg->i] = !seltag[arg->i];
|
arg@327
|
314 for(i = 0; i < ntags && !seltag[i]; i++);
|
arg@327
|
315 if(i == ntags)
|
arg@327
|
316 seltag[arg->i] = True; /* cannot toggle last view */
|
arg@381
|
317 reorder();
|
arg@327
|
318 arrange(NULL);
|
arg@327
|
319 }
|
arg@327
|
320
|
arg@327
|
321 void
|
arg@508
|
322 togglestackpos(Arg *arg) {
|
arg@508
|
323 if(arrange == dofloat)
|
arg@508
|
324 return;
|
arg@508
|
325 if(stackpos == StackBottom)
|
arg@508
|
326 stackpos = STACKPOS;
|
arg@508
|
327 else
|
arg@508
|
328 stackpos = StackBottom;
|
arg@515
|
329 master = ((stackpos == StackBottom ? sh - bh : sw) * MASTER) / 100;
|
arg@508
|
330 arrange(NULL);
|
arg@508
|
331 }
|
arg@508
|
332
|
arg@508
|
333 void
|
arg@461
|
334 view(Arg *arg) {
|
arg@327
|
335 unsigned int i;
|
arg@327
|
336
|
arg@327
|
337 for(i = 0; i < ntags; i++)
|
arg@327
|
338 seltag[i] = False;
|
arg@327
|
339 seltag[arg->i] = True;
|
arg@381
|
340 reorder();
|
arg@327
|
341 arrange(NULL);
|
arg@327
|
342 }
|
arg@327
|
343
|
arg@327
|
344 void
|
arg@461
|
345 viewall(Arg *arg) {
|
arg@395
|
346 unsigned int i;
|
arg@395
|
347
|
arg@395
|
348 for(i = 0; i < ntags; i++)
|
arg@395
|
349 seltag[i] = True;
|
arg@397
|
350 reorder();
|
arg@395
|
351 arrange(NULL);
|
arg@395
|
352 }
|
arg@395
|
353
|
arg@508
|
354
|
arg@508
|
355
|
arg@395
|
356 void
|
arg@461
|
357 zoom(Arg *arg) {
|
arg@423
|
358 unsigned int n;
|
arg@423
|
359 Client *c;
|
arg@473
|
360
|
arg@473
|
361 if(!sel)
|
arg@473
|
362 return;
|
arg@473
|
363
|
arg@473
|
364 if(sel->isfloat || (arrange == dofloat)) {
|
arg@480
|
365 togglemax(sel);
|
arg@473
|
366 return;
|
arg@473
|
367 }
|
arg@327
|
368
|
arg@430
|
369 for(n = 0, c = clients; c; c = c->next)
|
arg@430
|
370 if(isvisible(c) && !c->isfloat)
|
arg@423
|
371 n++;
|
arg@486
|
372 if(n < 2 || (arrange == dofloat))
|
arg@327
|
373 return;
|
arg@327
|
374
|
arg@430
|
375 if((c = sel) == nexttiled(clients))
|
arg@433
|
376 if(!(c = nexttiled(c->next)))
|
arg@429
|
377 return;
|
arg@443
|
378 detach(c);
|
arg@443
|
379 if(clients)
|
arg@443
|
380 clients->prev = c;
|
arg@443
|
381 c->next = clients;
|
arg@443
|
382 clients = c;
|
arg@378
|
383 focus(c);
|
arg@327
|
384 arrange(NULL);
|
arg@327
|
385 }
|