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