rev |
line source |
paulo@0
|
1 /* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
|
paulo@0
|
2 * See LICENSE file for license details.
|
paulo@0
|
3 */
|
paulo@0
|
4 #include "dwm.h"
|
paulo@0
|
5
|
paulo@0
|
6 unsigned int master = MASTER;
|
paulo@0
|
7 unsigned int nmaster = NMASTER;
|
paulo@0
|
8 unsigned int blw = 0;
|
paulo@0
|
9 Layout *lt = NULL;
|
paulo@0
|
10
|
paulo@0
|
11 /* static */
|
paulo@0
|
12
|
paulo@0
|
13 static unsigned int nlayouts = 0;
|
paulo@0
|
14
|
paulo@0
|
15 static void
|
paulo@0
|
16 spiral(void) {
|
paulo@0
|
17 unsigned int i, n, nx, ny, nw, nh;
|
paulo@0
|
18 Client *c;
|
paulo@0
|
19
|
paulo@0
|
20 nx = wax;
|
paulo@0
|
21 ny = way + wah;
|
paulo@0
|
22 nw = waw;
|
paulo@0
|
23 nh = wah;
|
paulo@0
|
24 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
|
paulo@0
|
25 n++;
|
paulo@0
|
26 for(i = 0, c = clients; c; c = c->next)
|
paulo@0
|
27 if(isvisible(c)) {
|
paulo@0
|
28 if(c->isbanned)
|
paulo@0
|
29 XMoveWindow(dpy, c->win, c->x, c->y);
|
paulo@0
|
30 c->isbanned = False;
|
paulo@0
|
31 if(c->isversatile)
|
paulo@0
|
32 continue;
|
paulo@0
|
33 c->ismax = False;
|
paulo@0
|
34 if((i % 2 && nh / 2 > 2 * c->border)
|
paulo@0
|
35 || (!(i % 2) && nw / 2 > 2 * c->border))
|
paulo@0
|
36 {
|
paulo@0
|
37 if(i < n - 1) {
|
paulo@0
|
38 if(i % 2)
|
paulo@0
|
39 nh /= 2;
|
paulo@0
|
40 else
|
paulo@0
|
41 nw /= 2;
|
paulo@0
|
42 if((i % 4) == 2)
|
paulo@0
|
43 nx += nw;
|
paulo@0
|
44 else if((i % 4) == 3)
|
paulo@0
|
45 ny += nh;
|
paulo@0
|
46 }
|
paulo@0
|
47 if((i % 4) == 0)
|
paulo@0
|
48 ny -= nh;
|
paulo@0
|
49 else if((i % 4) == 1)
|
paulo@0
|
50 nx += nw;
|
paulo@0
|
51 else if((i % 4) == 2)
|
paulo@0
|
52 ny += nh;
|
paulo@0
|
53 else
|
paulo@0
|
54 nx -= nw;
|
paulo@0
|
55 i++;
|
paulo@0
|
56 }
|
paulo@0
|
57 resize(c, nx, ny, nw - 2 * c->border, nh - 2 * c->border, False);
|
paulo@0
|
58 }
|
paulo@0
|
59 else {
|
paulo@0
|
60 c->isbanned = True;
|
paulo@0
|
61 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
|
paulo@0
|
62 }
|
paulo@0
|
63 if(!sel || !isvisible(sel)) {
|
paulo@0
|
64 for(c = stack; c && !isvisible(c); c = c->snext);
|
paulo@0
|
65 focus(c);
|
paulo@0
|
66 }
|
paulo@0
|
67 restack();
|
paulo@0
|
68 }
|
paulo@0
|
69
|
paulo@0
|
70 static void
|
paulo@0
|
71 spiral_h(void) {
|
paulo@0
|
72 unsigned int i, n, nx, ny, nw, nh;
|
paulo@0
|
73 Client *c;
|
paulo@0
|
74
|
paulo@0
|
75 nx = wax + waw;
|
paulo@0
|
76 ny = way;
|
paulo@0
|
77 nw = waw;
|
paulo@0
|
78 nh = wah;
|
paulo@0
|
79 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
|
paulo@0
|
80 n++;
|
paulo@0
|
81 for(i = 0, c = clients; c; c = c->next)
|
paulo@0
|
82 if(isvisible(c)) {
|
paulo@0
|
83 if(c->isbanned)
|
paulo@0
|
84 XMoveWindow(dpy, c->win, c->x, c->y);
|
paulo@0
|
85 c->isbanned = False;
|
paulo@0
|
86 if(c->isversatile)
|
paulo@0
|
87 continue;
|
paulo@0
|
88 c->ismax = False;
|
paulo@0
|
89 if((i % 2 && nw / 2 > 2 * c->border)
|
paulo@0
|
90 || (!(i % 2) && nh / 2 > 2 * c->border))
|
paulo@0
|
91 {
|
paulo@0
|
92 if(i < n - 1) {
|
paulo@0
|
93 if(i % 2)
|
paulo@0
|
94 nw /= 2;
|
paulo@0
|
95 else
|
paulo@0
|
96 nh /= 2;
|
paulo@0
|
97 if((i % 4) == 2)
|
paulo@0
|
98 ny += nh;
|
paulo@0
|
99 else if((i % 4) == 3)
|
paulo@0
|
100 nx += nw;
|
paulo@0
|
101 }
|
paulo@0
|
102 if((i % 4) == 0)
|
paulo@0
|
103 nx -= nw;
|
paulo@0
|
104 else if((i % 4) == 1)
|
paulo@0
|
105 ny += nh;
|
paulo@0
|
106 else if((i % 4) == 2)
|
paulo@0
|
107 nx += nw;
|
paulo@0
|
108 else
|
paulo@0
|
109 ny -= nh;
|
paulo@0
|
110 i++;
|
paulo@0
|
111 }
|
paulo@0
|
112 resize(c, nx, ny, nw - 2 * c->border, nh - 2 * c->border, False);
|
paulo@0
|
113 }
|
paulo@0
|
114 else {
|
paulo@0
|
115 c->isbanned = True;
|
paulo@0
|
116 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
|
paulo@0
|
117 }
|
paulo@0
|
118 if(!sel || !isvisible(sel)) {
|
paulo@0
|
119 for(c = stack; c && !isvisible(c); c = c->snext);
|
paulo@0
|
120 focus(c);
|
paulo@0
|
121 }
|
paulo@0
|
122 restack();
|
paulo@0
|
123 }
|
paulo@0
|
124
|
paulo@0
|
125 static void
|
paulo@0
|
126 monocle(void) {
|
paulo@0
|
127 Client *c;
|
paulo@0
|
128
|
paulo@0
|
129 for(c = clients; c; c = c->next)
|
paulo@0
|
130 if(isvisible(c) && c->isbanned) {
|
paulo@0
|
131 XMoveWindow(dpy, c->win, c->x, c->y);
|
paulo@0
|
132 c->isbanned = False;
|
paulo@0
|
133 }
|
paulo@0
|
134 else if(!isvisible(c)) {
|
paulo@0
|
135 c->isbanned = True;
|
paulo@0
|
136 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
|
paulo@0
|
137 }
|
paulo@0
|
138
|
paulo@0
|
139 for(c = nexttiled(clients); c; c = nexttiled(c->next))
|
paulo@0
|
140 resize(c, wax, way, waw - 2*c->border, wah - 2*c->border, False);
|
paulo@0
|
141
|
paulo@0
|
142 restack();
|
paulo@0
|
143 }
|
paulo@0
|
144
|
paulo@0
|
145 static void
|
paulo@0
|
146 bstack(void) {
|
paulo@0
|
147 unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th;
|
paulo@0
|
148 Client *c;
|
paulo@0
|
149
|
paulo@0
|
150 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
|
paulo@0
|
151 n++;
|
paulo@0
|
152 /* window geoms */
|
paulo@0
|
153 mh = (n > nmaster) ? (wah * master) / 1000 : wah;
|
paulo@0
|
154 mw = (n > nmaster) ? waw / nmaster : waw / (n > 0 ? n : 1);
|
paulo@0
|
155 th = wah - mh;
|
paulo@0
|
156 tw = (n > nmaster) ? waw / (n - nmaster) : 0;
|
paulo@0
|
157
|
paulo@0
|
158 for(i = 0, c = clients; c; c = c->next)
|
paulo@0
|
159 if(isvisible(c)) {
|
paulo@0
|
160 if(c->isbanned)
|
paulo@0
|
161 XMoveWindow(dpy, c->win, c->x, c->y);
|
paulo@0
|
162 c->isbanned = False;
|
paulo@0
|
163 if(c->isversatile)
|
paulo@0
|
164 continue;
|
paulo@0
|
165 c->ismax = False;
|
paulo@0
|
166 nx = wax;
|
paulo@0
|
167 ny = way;
|
paulo@0
|
168 if(i < nmaster) {
|
paulo@0
|
169 nx += i * mw;
|
paulo@0
|
170 nw = mw - 2 * BORDERPX;
|
paulo@0
|
171 nh = mh - 2 * BORDERPX;
|
paulo@0
|
172 }
|
paulo@0
|
173 else { /* tile window */
|
paulo@0
|
174 ny += mh;
|
paulo@0
|
175 nh = th - 2 * BORDERPX;
|
paulo@0
|
176 if(tw > 2 * BORDERPX) {
|
paulo@0
|
177 nx += (i - nmaster) * tw;
|
paulo@0
|
178 nw = tw - 2 * BORDERPX;
|
paulo@0
|
179 }
|
paulo@0
|
180 else /* fallback if th <= 2 * BORDERPX */
|
paulo@0
|
181 nw = waw - 2 * BORDERPX;
|
paulo@0
|
182 }
|
paulo@0
|
183 resize(c, nx, ny, nw, nh, False);
|
paulo@0
|
184 i++;
|
paulo@0
|
185 }
|
paulo@0
|
186 else {
|
paulo@0
|
187 c->isbanned = True;
|
paulo@0
|
188 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
|
paulo@0
|
189 }
|
paulo@0
|
190 if(!sel || !isvisible(sel)) {
|
paulo@0
|
191 for(c = stack; c && !isvisible(c); c = c->snext);
|
paulo@0
|
192 focus(c);
|
paulo@0
|
193 }
|
paulo@0
|
194 restack();
|
paulo@0
|
195 }
|
paulo@0
|
196
|
paulo@0
|
197 static void
|
paulo@0
|
198 grid(void) {
|
paulo@5
|
199 unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch;
|
paulo@0
|
200 Client *c;
|
paulo@0
|
201
|
paulo@0
|
202 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
|
paulo@0
|
203 n++;
|
paulo@5
|
204 if(n == 0)
|
paulo@5
|
205 return;
|
paulo@0
|
206
|
paulo@5
|
207 /* grid dimensions */
|
paulo@5
|
208 for(cols = 0; cols <= n/2; cols++)
|
paulo@5
|
209 if(cols*cols >= n)
|
paulo@0
|
210 break;
|
paulo@5
|
211 if(n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */
|
paulo@5
|
212 cols = 2;
|
paulo@5
|
213 rows = n/cols;
|
paulo@0
|
214
|
paulo@5
|
215 /* window geometries */
|
paulo@5
|
216 cw = cols ? waw / cols : waw;
|
paulo@5
|
217 cn = 0; /* current column number */
|
paulo@5
|
218 rn = 0; /* current row number */
|
paulo@0
|
219 for(i = 0, c = clients; c; c = c->next)
|
paulo@0
|
220 if(isvisible(c)) {
|
paulo@5
|
221 if(i/rows + 1 > cols - n%cols)
|
paulo@5
|
222 rows = n/cols + 1;
|
paulo@5
|
223 ch = rows ? wah / rows : wah;
|
paulo@5
|
224 cx = cn*cw;
|
paulo@5
|
225 cy = (TOPBAR ? dc.h : 0) + rn*ch;
|
paulo@5
|
226 resize(c, cx, cy, cw - 2 * BORDERPX, ch - 2 * BORDERPX, False);
|
paulo@5
|
227 rn++;
|
paulo@5
|
228 if(rn >= rows) {
|
paulo@5
|
229 rn = 0;
|
paulo@5
|
230 cn++;
|
paulo@5
|
231 }
|
paulo@0
|
232 i++;
|
paulo@0
|
233 }
|
paulo@0
|
234 else {
|
paulo@0
|
235 c->isbanned = True;
|
paulo@0
|
236 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
|
paulo@0
|
237 }
|
paulo@5
|
238
|
paulo@0
|
239 if(!sel || !isvisible(sel)) {
|
paulo@0
|
240 for(c = stack; c && !isvisible(c); c = c->snext);
|
paulo@0
|
241 focus(c);
|
paulo@0
|
242 }
|
paulo@0
|
243 restack();
|
paulo@0
|
244 }
|
paulo@0
|
245
|
paulo@0
|
246 static void
|
paulo@0
|
247 tile(void) {
|
paulo@0
|
248 unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th;
|
paulo@0
|
249 Client *c;
|
paulo@0
|
250
|
paulo@0
|
251 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
|
paulo@0
|
252 n++;
|
paulo@0
|
253 /* window geoms */
|
paulo@0
|
254 mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
|
paulo@0
|
255 mw = (n > nmaster) ? (waw * master) / 1000 : waw;
|
paulo@0
|
256 th = (n > nmaster) ? wah / (n - nmaster) : 0;
|
paulo@0
|
257 tw = waw - mw;
|
paulo@0
|
258
|
paulo@0
|
259 for(i = 0, c = clients; c; c = c->next)
|
paulo@0
|
260 if(isvisible(c)) {
|
paulo@0
|
261 if(c->isbanned)
|
paulo@0
|
262 XMoveWindow(dpy, c->win, c->x, c->y);
|
paulo@0
|
263 c->isbanned = False;
|
paulo@0
|
264 if(c->isversatile)
|
paulo@0
|
265 continue;
|
paulo@0
|
266 c->ismax = False;
|
paulo@0
|
267 nx = wax;
|
paulo@0
|
268 ny = way;
|
paulo@0
|
269 if(i < nmaster) {
|
paulo@0
|
270 ny += i * mh;
|
paulo@0
|
271 nw = mw - 2 * BORDERPX;
|
paulo@0
|
272 nh = mh - 2 * BORDERPX;
|
paulo@0
|
273 }
|
paulo@0
|
274 else { /* tile window */
|
paulo@0
|
275 nx += mw;
|
paulo@0
|
276 nw = tw - 2 * BORDERPX;
|
paulo@0
|
277 if(th > 2 * BORDERPX) {
|
paulo@0
|
278 ny += (i - nmaster) * th;
|
paulo@0
|
279 nh = th - 2 * BORDERPX;
|
paulo@0
|
280 }
|
paulo@0
|
281 else /* fallback if th <= 2 * BORDERPX */
|
paulo@0
|
282 nh = wah - 2 * BORDERPX;
|
paulo@0
|
283 }
|
paulo@0
|
284 resize(c, nx, ny, nw, nh, False);
|
paulo@0
|
285 i++;
|
paulo@0
|
286 }
|
paulo@0
|
287 else {
|
paulo@0
|
288 c->isbanned = True;
|
paulo@0
|
289 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
|
paulo@0
|
290 }
|
paulo@0
|
291 if(!sel || !isvisible(sel)) {
|
paulo@0
|
292 for(c = stack; c && !isvisible(c); c = c->snext);
|
paulo@0
|
293 focus(c);
|
paulo@0
|
294 }
|
paulo@0
|
295 restack();
|
paulo@0
|
296 }
|
paulo@0
|
297
|
paulo@0
|
298 LAYOUTS
|
paulo@0
|
299
|
paulo@0
|
300 /* extern */
|
paulo@0
|
301
|
paulo@0
|
302 void
|
paulo@0
|
303 focusnext(Arg *arg) {
|
paulo@0
|
304 Client *c;
|
paulo@0
|
305
|
paulo@0
|
306 if(!sel)
|
paulo@0
|
307 return;
|
paulo@0
|
308 for(c = sel->next; c && !isvisible(c); c = c->next);
|
paulo@0
|
309 if(!c)
|
paulo@0
|
310 for(c = clients; c && !isvisible(c); c = c->next);
|
paulo@0
|
311 if(c) {
|
paulo@0
|
312 focus(c);
|
paulo@0
|
313 restack();
|
paulo@0
|
314 }
|
paulo@0
|
315 }
|
paulo@0
|
316
|
paulo@0
|
317 void
|
paulo@0
|
318 focusprev(Arg *arg) {
|
paulo@0
|
319 Client *c;
|
paulo@0
|
320
|
paulo@0
|
321 if(!sel)
|
paulo@0
|
322 return;
|
paulo@0
|
323 for(c = sel->prev; c && !isvisible(c); c = c->prev);
|
paulo@0
|
324 if(!c) {
|
paulo@0
|
325 for(c = clients; c && c->next; c = c->next);
|
paulo@0
|
326 for(; c && !isvisible(c); c = c->prev);
|
paulo@0
|
327 }
|
paulo@0
|
328 if(c) {
|
paulo@0
|
329 focus(c);
|
paulo@0
|
330 restack();
|
paulo@0
|
331 }
|
paulo@0
|
332 }
|
paulo@0
|
333
|
paulo@0
|
334 void
|
paulo@0
|
335 incnmaster(Arg *arg) {
|
paulo@0
|
336 //if((lt->arrange != tile) || (nmaster + arg->i < 1)
|
paulo@0
|
337 //|| (wah / (nmaster + arg->i) <= 2 * BORDERPX))
|
paulo@0
|
338 // return;
|
paulo@0
|
339 if(nmaster + arg->i < 1 && nmaster + arg->i <= MAX_TASKS)
|
paulo@0
|
340 return;
|
paulo@0
|
341 nmaster += arg->i;
|
paulo@0
|
342 if(sel)
|
paulo@0
|
343 lt->arrange();
|
paulo@0
|
344 else
|
paulo@0
|
345 drawstatus();
|
paulo@0
|
346 }
|
paulo@0
|
347
|
paulo@0
|
348 void
|
paulo@0
|
349 initlayouts(void) {
|
paulo@0
|
350 unsigned int i, w;
|
paulo@0
|
351
|
paulo@0
|
352 lt = &layout[0];
|
paulo@0
|
353 nlayouts = sizeof layout / sizeof layout[0];
|
paulo@0
|
354 for(blw = i = 0; i < nlayouts; i++) {
|
paulo@0
|
355 w = textw(layout[i].symbol);
|
paulo@0
|
356 if(w > blw)
|
paulo@0
|
357 blw = w;
|
paulo@0
|
358 }
|
paulo@0
|
359 }
|
paulo@0
|
360
|
paulo@0
|
361 Client *
|
paulo@0
|
362 nexttiled(Client *c) {
|
paulo@0
|
363 for(; c && (c->isversatile || !isvisible(c)); c = c->next);
|
paulo@0
|
364 return c;
|
paulo@0
|
365 }
|
paulo@0
|
366
|
paulo@0
|
367 void
|
paulo@0
|
368 resizemaster(Arg *arg) {
|
paulo@0
|
369 //if(lt->arrange != tile)
|
paulo@0
|
370 // return;
|
paulo@0
|
371 if(arg->i == 0)
|
paulo@0
|
372 master = MASTER;
|
paulo@0
|
373 else {
|
paulo@0
|
374 //if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX
|
paulo@0
|
375 //|| waw * (master + arg->i) / 1000 <= 2 * BORDERPX)
|
paulo@0
|
376 // return;
|
paulo@0
|
377 master += arg->i;
|
paulo@0
|
378 }
|
paulo@0
|
379 lt->arrange();
|
paulo@0
|
380 }
|
paulo@0
|
381
|
paulo@0
|
382 void
|
paulo@0
|
383 restack(void) {
|
paulo@0
|
384 Client *c;
|
paulo@0
|
385 XEvent ev;
|
paulo@0
|
386
|
paulo@0
|
387 drawstatus();
|
paulo@0
|
388 if(!sel)
|
paulo@0
|
389 return;
|
paulo@0
|
390 if(sel->isversatile || lt->arrange == versatile)
|
paulo@0
|
391 XRaiseWindow(dpy, sel->win);
|
paulo@0
|
392 if(lt->arrange != versatile) {
|
paulo@0
|
393 if(!sel->isversatile)
|
paulo@0
|
394 XLowerWindow(dpy, sel->win);
|
paulo@0
|
395 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
|
paulo@0
|
396 if(c == sel)
|
paulo@0
|
397 continue;
|
paulo@0
|
398 XLowerWindow(dpy, c->win);
|
paulo@0
|
399 }
|
paulo@0
|
400 }
|
paulo@0
|
401 XSync(dpy, False);
|
paulo@0
|
402 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
|
paulo@0
|
403 }
|
paulo@0
|
404
|
paulo@0
|
405 void
|
paulo@0
|
406 setlayout(Arg *arg) {
|
paulo@1
|
407 int i;
|
paulo@0
|
408
|
paulo@1
|
409 if(arg->i < 0) {
|
paulo@0
|
410 for(i = 0; i < nlayouts && lt != &layout[i]; i++);
|
paulo@1
|
411 if(arg->i == -1)
|
paulo@1
|
412 lt = &layout[(i + 1) % nlayouts];
|
paulo@1
|
413 else if(arg->i == -2)
|
paulo@1
|
414 lt = &layout[(i - 1) >= 0 ? i - 1 : nlayouts - 1];
|
paulo@0
|
415 }
|
paulo@0
|
416 else {
|
paulo@0
|
417 if(arg->i < 0 || arg->i >= nlayouts)
|
paulo@0
|
418 return;
|
paulo@0
|
419 lt = &layout[arg->i];
|
paulo@0
|
420 }
|
paulo@0
|
421 if(sel)
|
paulo@0
|
422 lt->arrange();
|
paulo@0
|
423 else
|
paulo@0
|
424 drawstatus();
|
paulo@0
|
425 }
|
paulo@0
|
426
|
paulo@0
|
427 void
|
paulo@0
|
428 versatile(void) {
|
paulo@0
|
429 Client *c;
|
paulo@0
|
430
|
paulo@0
|
431 for(c = clients; c; c = c->next) {
|
paulo@0
|
432 if(isvisible(c)) {
|
paulo@0
|
433 if(c->isbanned)
|
paulo@0
|
434 XMoveWindow(dpy, c->win, c->x, c->y);
|
paulo@0
|
435 c->isbanned = False;
|
paulo@0
|
436 resize(c, c->x, c->y, c->w, c->h, True);
|
paulo@0
|
437 }
|
paulo@0
|
438 else {
|
paulo@0
|
439 c->isbanned = True;
|
paulo@0
|
440 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
|
paulo@0
|
441 }
|
paulo@0
|
442 }
|
paulo@0
|
443 if(!sel || !isvisible(sel)) {
|
paulo@0
|
444 for(c = stack; c && !isvisible(c); c = c->snext);
|
paulo@0
|
445 focus(c);
|
paulo@0
|
446 }
|
paulo@0
|
447 restack();
|
paulo@0
|
448 }
|