1 /* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com> |
1 /* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com> |
2 * See LICENSE file for license details. |
2 * See LICENSE file for license details. |
3 */ |
3 */ |
4 #include "dwm.h" |
4 #include "dwm.h" |
5 #include <stdio.h> |
|
6 |
|
7 /* static */ |
|
8 |
|
9 static Client * |
|
10 nexttiled(Client *c) { |
|
11 for(; c && (c->isfloat || !isvisible(c)); c = c->next); |
|
12 return c; |
|
13 } |
|
14 |
|
15 static void |
|
16 togglemax(Client *c) { |
|
17 XEvent ev; |
|
18 |
|
19 if(c->isfixed) |
|
20 return; |
|
21 |
|
22 if((c->ismax = !c->ismax)) { |
|
23 c->rx = c->x; |
|
24 c->ry = c->y; |
|
25 c->rw = c->w; |
|
26 c->rh = c->h; |
|
27 resize(c, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True); |
|
28 } |
|
29 else |
|
30 resize(c, c->rx, c->ry, c->rw, c->rh, True); |
|
31 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); |
|
32 } |
|
33 |
5 |
34 /* extern */ |
6 /* extern */ |
35 |
7 |
36 void (*arrange)(void) = DEFMODE; |
8 void (*arrange)(void) = DEFMODE; |
37 |
9 |
68 } |
40 } |
69 restack(); |
41 restack(); |
70 } |
42 } |
71 |
43 |
72 void |
44 void |
73 dotile(void) { |
|
74 unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th; |
|
75 Client *c; |
|
76 |
|
77 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) |
|
78 n++; |
|
79 /* window geoms */ |
|
80 mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1); |
|
81 mw = (n > nmaster) ? (waw * master) / 1000 : waw; |
|
82 th = (n > nmaster) ? wah / (n - nmaster) : 0; |
|
83 tw = waw - mw; |
|
84 |
|
85 for(i = 0, c = clients; c; c = c->next) |
|
86 if(isvisible(c)) { |
|
87 if(c->isbanned) |
|
88 XMoveWindow(dpy, c->win, c->x, c->y); |
|
89 c->isbanned = False; |
|
90 if(c->isfloat) |
|
91 continue; |
|
92 c->ismax = False; |
|
93 nx = wax; |
|
94 ny = way; |
|
95 if(i < nmaster) { |
|
96 ny += i * mh; |
|
97 nw = mw - 2 * BORDERPX; |
|
98 nh = mh - 2 * BORDERPX; |
|
99 } |
|
100 else { /* tile window */ |
|
101 nx += mw; |
|
102 nw = tw - 2 * BORDERPX; |
|
103 if(th > 2 * BORDERPX) { |
|
104 ny += (i - nmaster) * th; |
|
105 nh = th - 2 * BORDERPX; |
|
106 } |
|
107 else /* fallback if th <= 2 * BORDERPX */ |
|
108 nh = wah - 2 * BORDERPX; |
|
109 } |
|
110 resize(c, nx, ny, nw, nh, False); |
|
111 i++; |
|
112 } |
|
113 else { |
|
114 c->isbanned = True; |
|
115 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); |
|
116 } |
|
117 if(!sel || !isvisible(sel)) { |
|
118 for(c = stack; c && !isvisible(c); c = c->snext); |
|
119 focus(c); |
|
120 } |
|
121 restack(); |
|
122 } |
|
123 |
|
124 void |
|
125 focusnext(Arg *arg) { |
45 focusnext(Arg *arg) { |
126 Client *c; |
46 Client *c; |
127 |
47 |
128 if(!sel) |
48 if(!sel) |
129 return; |
49 return; |
151 focus(c); |
71 focus(c); |
152 restack(); |
72 restack(); |
153 } |
73 } |
154 } |
74 } |
155 |
75 |
156 void |
|
157 incnmaster(Arg *arg) { |
|
158 if((arrange == dofloat) || (nmaster + arg->i < 1) |
|
159 || (wah / (nmaster + arg->i) <= 2 * BORDERPX)) |
|
160 return; |
|
161 nmaster += arg->i; |
|
162 if(sel) |
|
163 arrange(); |
|
164 else |
|
165 drawstatus(); |
|
166 } |
|
167 |
|
168 Bool |
76 Bool |
169 isvisible(Client *c) { |
77 isvisible(Client *c) { |
170 unsigned int i; |
78 unsigned int i; |
171 |
79 |
172 for(i = 0; i < ntags; i++) |
80 for(i = 0; i < ntags; i++) |
173 if(c->tags[i] && seltag[i]) |
81 if(c->tags[i] && seltag[i]) |
174 return True; |
82 return True; |
175 return False; |
83 return False; |
176 } |
84 } |
177 |
85 |
178 void |
86 Client * |
179 resizemaster(Arg *arg) { |
87 nextmanaged(Client *c) { |
180 if(arrange != dotile) |
88 for(; c && (c->isfloat || !isvisible(c)); c = c->next); |
181 return; |
89 return c; |
182 if(arg->i == 0) |
|
183 master = MASTER; |
|
184 else { |
|
185 if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX |
|
186 || waw * (master + arg->i) / 1000 <= 2 * BORDERPX) |
|
187 return; |
|
188 master += arg->i; |
|
189 } |
|
190 arrange(); |
|
191 } |
90 } |
192 |
91 |
193 void |
92 void |
194 restack(void) { |
93 restack(void) { |
195 Client *c; |
94 Client *c; |
201 if(sel->isfloat || arrange == dofloat) |
100 if(sel->isfloat || arrange == dofloat) |
202 XRaiseWindow(dpy, sel->win); |
101 XRaiseWindow(dpy, sel->win); |
203 if(arrange != dofloat) { |
102 if(arrange != dofloat) { |
204 if(!sel->isfloat) |
103 if(!sel->isfloat) |
205 XLowerWindow(dpy, sel->win); |
104 XLowerWindow(dpy, sel->win); |
206 for(c = nexttiled(clients); c; c = nexttiled(c->next)) { |
105 for(c = nextmanaged(clients); c; c = nextmanaged(c->next)) { |
207 if(c == sel) |
106 if(c == sel) |
208 continue; |
107 continue; |
209 XLowerWindow(dpy, c->win); |
108 XLowerWindow(dpy, c->win); |
210 } |
109 } |
211 } |
110 } |