rev |
line source |
arg@644
|
1 /* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
|
arg@327
|
2 * See LICENSE file for license details.
|
arg@327
|
3 */
|
arg@327
|
4 #include "dwm.h"
|
arg@327
|
5
|
arg@380
|
6 /* static */
|
arg@380
|
7
|
arg@382
|
8 static Client *
|
arg@480
|
9 nexttiled(Client *c) {
|
arg@480
|
10 for(c = getnext(c); c && c->isfloat; c = getnext(c->next));
|
arg@480
|
11 return c;
|
arg@480
|
12 }
|
arg@480
|
13
|
arg@651
|
14 static Bool
|
arg@651
|
15 ismaster(Client *c) {
|
arg@651
|
16 Client *cl;
|
arg@651
|
17 unsigned int i;
|
arg@651
|
18
|
arg@651
|
19 for(cl = nexttiled(clients), i = 0; cl && cl != c; cl = nexttiled(cl->next), i++);
|
arg@651
|
20 return i < nmaster;
|
arg@651
|
21 }
|
arg@651
|
22
|
arg@651
|
23 static void
|
arg@651
|
24 pop(Client *c) {
|
arg@651
|
25 detach(c);
|
arg@651
|
26 if(clients)
|
arg@651
|
27 clients->prev = c;
|
arg@651
|
28 c->next = clients;
|
arg@651
|
29 clients = c;
|
arg@651
|
30 }
|
arg@651
|
31
|
arg@651
|
32 static void
|
arg@651
|
33 swap(Client *c1, Client *c2) {
|
arg@651
|
34 Client tmp = *c1;
|
arg@658
|
35 Client *c1p = c1->prev;
|
arg@658
|
36 Client *c1n = c1->next;
|
arg@659
|
37 Client *c1s = c1->snext;
|
arg@658
|
38 Client *c2p = c2->prev;
|
arg@658
|
39 Client *c2n = c2->next;
|
arg@659
|
40 Client *c2s = c2->snext;
|
arg@651
|
41
|
arg@651
|
42 *c1 = *c2;
|
arg@651
|
43 *c2 = tmp;
|
arg@658
|
44 c1->prev = c1p;
|
arg@658
|
45 c1->next = c1n;
|
arg@659
|
46 c1->snext = c1s;
|
arg@658
|
47 c2->prev = c2p;
|
arg@658
|
48 c2->next = c2n;
|
arg@659
|
49 c2->snext = c2s;
|
arg@651
|
50 }
|
arg@651
|
51
|
arg@442
|
52 static void
|
arg@532
|
53 togglemax(Client *c) {
|
arg@481
|
54 XEvent ev;
|
arg@548
|
55
|
arg@549
|
56 if(c->isfixed)
|
arg@548
|
57 return;
|
arg@532
|
58
|
arg@480
|
59 if((c->ismax = !c->ismax)) {
|
arg@565
|
60 c->rx = c->x; c->x = wax;
|
arg@565
|
61 c->ry = c->y; c->y = way;
|
arg@565
|
62 c->rw = c->w; c->w = waw - 2 * BORDERPX;
|
arg@565
|
63 c->rh = c->h; c->h = wah - 2 * BORDERPX;
|
arg@480
|
64 }
|
arg@480
|
65 else {
|
arg@480
|
66 c->x = c->rx;
|
arg@480
|
67 c->y = c->ry;
|
arg@481
|
68 c->w = c->rw;
|
arg@481
|
69 c->h = c->rh;
|
arg@480
|
70 }
|
arg@480
|
71 resize(c, True, TopLeft);
|
arg@480
|
72 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
|
arg@430
|
73 }
|
arg@430
|
74
|
arg@651
|
75 static Client *
|
arg@651
|
76 topofstack() {
|
arg@651
|
77 Client *c;
|
arg@651
|
78 unsigned int i;
|
arg@651
|
79
|
arg@651
|
80 for(c = nexttiled(clients), i = 0; c && i < nmaster; c = nexttiled(c->next), i++);
|
arg@651
|
81 return (i < nmaster) ? NULL : c;
|
arg@651
|
82 }
|
arg@651
|
83
|
arg@327
|
84 /* extern */
|
arg@327
|
85
|
arg@533
|
86 void (*arrange)(void) = DEFMODE;
|
arg@327
|
87
|
arg@327
|
88 void
|
arg@461
|
89 detach(Client *c) {
|
arg@378
|
90 if(c->prev)
|
arg@378
|
91 c->prev->next = c->next;
|
arg@378
|
92 if(c->next)
|
arg@378
|
93 c->next->prev = c->prev;
|
arg@378
|
94 if(c == clients)
|
arg@378
|
95 clients = c->next;
|
arg@378
|
96 c->next = c->prev = NULL;
|
arg@378
|
97 }
|
arg@378
|
98
|
arg@378
|
99 void
|
arg@533
|
100 dofloat(void) {
|
arg@402
|
101 Client *c;
|
arg@400
|
102
|
arg@327
|
103 for(c = clients; c; c = c->next) {
|
arg@327
|
104 if(isvisible(c)) {
|
arg@327
|
105 resize(c, True, TopLeft);
|
arg@327
|
106 }
|
arg@327
|
107 else
|
arg@327
|
108 ban(c);
|
arg@327
|
109 }
|
arg@446
|
110 if(!sel || !isvisible(sel)) {
|
arg@450
|
111 for(c = stack; c && !isvisible(c); c = c->snext);
|
arg@450
|
112 focus(c);
|
arg@446
|
113 }
|
arg@327
|
114 restack();
|
arg@327
|
115 }
|
arg@327
|
116
|
arg@327
|
117 void
|
arg@533
|
118 dotile(void) {
|
arg@650
|
119 unsigned int i, n, mw, mh, tw, th;
|
arg@402
|
120 Client *c;
|
arg@400
|
121
|
arg@488
|
122 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
|
arg@488
|
123 n++;
|
arg@650
|
124 /* window geoms */
|
arg@650
|
125 mw = (n > nmaster) ? (waw * master) / 1000 : waw;
|
arg@650
|
126 mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
|
arg@650
|
127 tw = waw - mw;
|
arg@650
|
128 th = (n > nmaster) ? wah / (n - nmaster) : 0;
|
arg@327
|
129
|
arg@535
|
130 for(i = 0, c = clients; c; c = c->next)
|
arg@327
|
131 if(isvisible(c)) {
|
arg@327
|
132 if(c->isfloat) {
|
arg@327
|
133 resize(c, True, TopLeft);
|
arg@327
|
134 continue;
|
arg@327
|
135 }
|
arg@488
|
136 c->ismax = False;
|
arg@565
|
137 c->x = wax;
|
arg@565
|
138 c->y = way;
|
arg@650
|
139 if(i < nmaster) {
|
arg@650
|
140 c->y += i * mh;
|
arg@650
|
141 c->w = mw - 2 * BORDERPX;
|
arg@650
|
142 c->h = mh - 2 * BORDERPX;
|
arg@507
|
143 }
|
arg@523
|
144 else { /* tile window */
|
arg@650
|
145 c->x += mw;
|
arg@650
|
146 c->w = tw - 2 * BORDERPX;
|
arg@523
|
147 if(th > bh) {
|
arg@650
|
148 c->y += (i - nmaster) * th;
|
arg@565
|
149 c->h = th - 2 * BORDERPX;
|
arg@507
|
150 }
|
arg@531
|
151 else /* fallback if th < bh */
|
arg@565
|
152 c->h = wah - 2 * BORDERPX;
|
arg@327
|
153 }
|
arg@327
|
154 resize(c, False, TopLeft);
|
arg@535
|
155 i++;
|
arg@327
|
156 }
|
arg@327
|
157 else
|
arg@327
|
158 ban(c);
|
arg@532
|
159
|
arg@446
|
160 if(!sel || !isvisible(sel)) {
|
arg@450
|
161 for(c = stack; c && !isvisible(c); c = c->snext);
|
arg@450
|
162 focus(c);
|
arg@446
|
163 }
|
arg@327
|
164 restack();
|
arg@327
|
165 }
|
arg@327
|
166
|
arg@327
|
167 void
|
arg@461
|
168 focusnext(Arg *arg) {
|
arg@327
|
169 Client *c;
|
arg@327
|
170
|
arg@327
|
171 if(!sel)
|
arg@327
|
172 return;
|
arg@327
|
173 if(!(c = getnext(sel->next)))
|
arg@327
|
174 c = getnext(clients);
|
arg@327
|
175 if(c) {
|
arg@327
|
176 focus(c);
|
arg@327
|
177 restack();
|
arg@327
|
178 }
|
arg@327
|
179 }
|
arg@327
|
180
|
arg@327
|
181 void
|
arg@461
|
182 focusprev(Arg *arg) {
|
arg@327
|
183 Client *c;
|
arg@327
|
184
|
arg@327
|
185 if(!sel)
|
arg@327
|
186 return;
|
arg@327
|
187 if(!(c = getprev(sel->prev))) {
|
arg@327
|
188 for(c = clients; c && c->next; c = c->next);
|
arg@327
|
189 c = getprev(c);
|
arg@327
|
190 }
|
arg@327
|
191 if(c) {
|
arg@327
|
192 focus(c);
|
arg@327
|
193 restack();
|
arg@327
|
194 }
|
arg@327
|
195 }
|
arg@327
|
196
|
arg@650
|
197 void
|
arg@650
|
198 incnmaster(Arg *arg) {
|
arg@658
|
199 if((nmaster + arg->i < 1) || (wah / (nmaster + arg->i) < bh))
|
arg@650
|
200 return;
|
arg@650
|
201 nmaster += arg->i;
|
arg@650
|
202 arrange();
|
arg@650
|
203 }
|
arg@650
|
204
|
arg@420
|
205 Bool
|
arg@461
|
206 isvisible(Client *c) {
|
arg@420
|
207 unsigned int i;
|
arg@420
|
208
|
arg@420
|
209 for(i = 0; i < ntags; i++)
|
arg@420
|
210 if(c->tags[i] && seltag[i])
|
arg@420
|
211 return True;
|
arg@420
|
212 return False;
|
arg@420
|
213 }
|
arg@420
|
214
|
arg@415
|
215 void
|
arg@559
|
216 resizemaster(Arg *arg) {
|
arg@561
|
217 if(arg->i == 0)
|
arg@561
|
218 master = MASTER;
|
arg@561
|
219 else {
|
arg@561
|
220 if(master + arg->i > 950 || master + arg->i < 50)
|
arg@561
|
221 return;
|
arg@561
|
222 master += arg->i;
|
arg@561
|
223 }
|
arg@533
|
224 arrange();
|
arg@415
|
225 }
|
arg@415
|
226
|
arg@327
|
227 void
|
arg@487
|
228 restack(void) {
|
arg@327
|
229 Client *c;
|
arg@327
|
230 XEvent ev;
|
arg@481
|
231
|
arg@437
|
232 if(!sel) {
|
arg@437
|
233 drawstatus();
|
arg@436
|
234 return;
|
arg@437
|
235 }
|
arg@436
|
236 if(sel->isfloat || arrange == dofloat) {
|
arg@436
|
237 XRaiseWindow(dpy, sel->win);
|
arg@436
|
238 XRaiseWindow(dpy, sel->twin);
|
arg@436
|
239 }
|
arg@512
|
240 if(arrange != dofloat) {
|
arg@512
|
241 if(!sel->isfloat) {
|
arg@512
|
242 XLowerWindow(dpy, sel->twin);
|
arg@512
|
243 XLowerWindow(dpy, sel->win);
|
arg@512
|
244 }
|
arg@436
|
245 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
|
arg@512
|
246 if(c == sel)
|
arg@512
|
247 continue;
|
arg@436
|
248 XLowerWindow(dpy, c->twin);
|
arg@436
|
249 XLowerWindow(dpy, c->win);
|
arg@327
|
250 }
|
arg@512
|
251 }
|
arg@327
|
252 drawall();
|
arg@327
|
253 XSync(dpy, False);
|
arg@327
|
254 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
|
arg@327
|
255 }
|
arg@327
|
256
|
arg@327
|
257 void
|
arg@584
|
258 togglefloat(Arg *arg) {
|
arg@591
|
259 if (!sel || arrange == dofloat)
|
arg@584
|
260 return;
|
arg@584
|
261 sel->isfloat = !sel->isfloat;
|
arg@584
|
262 arrange();
|
arg@584
|
263 }
|
arg@584
|
264
|
arg@584
|
265 void
|
arg@461
|
266 togglemode(Arg *arg) {
|
arg@333
|
267 arrange = (arrange == dofloat) ? dotile : dofloat;
|
arg@327
|
268 if(sel)
|
arg@533
|
269 arrange();
|
arg@327
|
270 else
|
arg@327
|
271 drawstatus();
|
arg@327
|
272 }
|
arg@327
|
273
|
arg@327
|
274 void
|
arg@461
|
275 toggleview(Arg *arg) {
|
arg@327
|
276 unsigned int i;
|
arg@327
|
277
|
arg@327
|
278 seltag[arg->i] = !seltag[arg->i];
|
arg@327
|
279 for(i = 0; i < ntags && !seltag[i]; i++);
|
arg@327
|
280 if(i == ntags)
|
arg@327
|
281 seltag[arg->i] = True; /* cannot toggle last view */
|
arg@533
|
282 arrange();
|
arg@327
|
283 }
|
arg@327
|
284
|
arg@327
|
285 void
|
arg@461
|
286 view(Arg *arg) {
|
arg@327
|
287 unsigned int i;
|
arg@327
|
288
|
arg@327
|
289 for(i = 0; i < ntags; i++)
|
arg@594
|
290 seltag[i] = (arg->i == -1) ? True : False;
|
arg@611
|
291 if(arg->i >= 0 && arg->i < ntags)
|
arg@611
|
292 seltag[arg->i] = True;
|
arg@533
|
293 arrange();
|
arg@327
|
294 }
|
arg@327
|
295
|
arg@327
|
296 void
|
arg@461
|
297 zoom(Arg *arg) {
|
arg@651
|
298 unsigned int n;
|
arg@423
|
299 Client *c;
|
arg@473
|
300
|
arg@473
|
301 if(!sel)
|
arg@473
|
302 return;
|
arg@473
|
303 if(sel->isfloat || (arrange == dofloat)) {
|
arg@480
|
304 togglemax(sel);
|
arg@473
|
305 return;
|
arg@473
|
306 }
|
arg@650
|
307 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
|
arg@650
|
308 n++;
|
arg@654
|
309
|
arg@654
|
310 c = sel;
|
arg@658
|
311 if(arrange == dofloat)
|
arg@658
|
312 return;
|
arg@658
|
313 else if(n <= nmaster)
|
arg@654
|
314 pop(c);
|
arg@654
|
315 else if(ismaster(sel)) {
|
arg@651
|
316 if(!(c = topofstack()))
|
arg@651
|
317 return;
|
arg@651
|
318 swap(c, sel);
|
arg@651
|
319 c = sel;
|
arg@651
|
320 }
|
arg@651
|
321 else
|
arg@651
|
322 pop(c);
|
arg@650
|
323
|
arg@378
|
324 focus(c);
|
arg@533
|
325 arrange();
|
arg@327
|
326 }
|