Xinqi Bao's Git

renamed MASTER into MWFACT, master into mwfact, and incmaster into addtomwfact
[dwm.git] / tile.c
1 /* See LICENSE file for copyright and license details. */
2 #include "dwm.h"
3 #include <stdio.h>
4
5 /* static */
6
7 static double mwfact = MWFACT;
8
9 /* extern */
10
11 void
12 addtomwfact(const char *arg) {
13 double delta;
14
15 if(lt->arrange != tile)
16 return;
17
18 /* arg handling, manipulate mwfact */
19 if(arg && (1 == sscanf(arg, "%lf", &delta))) {
20 if(delta + mwfact > 0.1 && delta + mwfact < 0.9)
21 mwfact += delta;
22 }
23 lt->arrange();
24 }
25
26 void
27 tile(void) {
28 unsigned int i, n, nx, ny, nw, nh, mw, th;
29 Client *c;
30
31 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
32 n++;
33
34 /* window geoms */
35 mw = (n == 1) ? waw : mwfact * waw;
36 th = (n > 1) ? wah / (n - 1) : 0;
37 if(n > 1 && th < bh)
38 th = wah;
39
40 nx = wax;
41 ny = way;
42 for(i = 0, c = clients; c; c = c->next)
43 if(isvisible(c)) {
44 unban(c);
45 if(c->isfloating)
46 continue;
47 c->ismax = False;
48 if(i == 0) { /* master */
49 nw = mw - 2 * c->border;
50 nh = wah - 2 * c->border;
51 }
52 else { /* tile window */
53 if(i == 1) {
54 ny = way;
55 nx += mw;
56 }
57 nw = waw - mw - 2 * c->border;
58 if(i + 1 == n) /* remainder */
59 nh = (way + wah) - ny - 2 * c->border;
60 else
61 nh = th - 2 * c->border;
62 }
63 resize(c, nx, ny, nw, nh, False);
64 if(n > 1 && th != wah)
65 ny += nh + 2 * c->border;
66 i++;
67 }
68 else
69 ban(c);
70 focus(NULL);
71 restack();
72 }
73
74 void
75 zoom(const char *arg) {
76 Client *c;
77
78 if(!sel || lt->arrange == floating || sel->isfloating)
79 return;
80 if((c = sel) == nexttiled(clients))
81 if(!(c = nexttiled(c->next)))
82 return;
83 detach(c);
84 attach(c);
85 focus(c);
86 lt->arrange();
87 }