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