aewl
view view.c @ 654:04734db9a219
allowing zoom within master area as well
author | Anselm R. Garbe <arg@suckless.org> |
---|---|
date | Fri, 05 Jan 2007 15:08:25 +0100 |
parents | b9f4efd21473 |
children | c30805f6bb08 |
line source
1 /* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
2 * See LICENSE file for license details.
3 */
4 #include "dwm.h"
6 /* static */
8 static Client *
9 nexttiled(Client *c) {
10 for(c = getnext(c); c && c->isfloat; c = getnext(c->next));
11 return c;
12 }
14 static Bool
15 ismaster(Client *c) {
16 Client *cl;
17 unsigned int i;
19 for(cl = nexttiled(clients), i = 0; cl && cl != c; cl = nexttiled(cl->next), i++);
20 return i < nmaster;
21 }
23 static void
24 pop(Client *c) {
25 detach(c);
26 if(clients)
27 clients->prev = c;
28 c->next = clients;
29 clients = c;
30 }
32 static void
33 swap(Client *c1, Client *c2) {
34 Client tmp = *c1;
35 Client *cp = c1->prev;
36 Client *cn = c1->next;
38 *c1 = *c2;
39 c1->prev = cp;
40 c1->next = cn;
41 cp = c2->prev;
42 cn = c2->next;
43 *c2 = tmp;
44 c2->prev = cp;
45 c2->next = cn;
46 }
48 static void
49 togglemax(Client *c) {
50 XEvent ev;
52 if(c->isfixed)
53 return;
55 if((c->ismax = !c->ismax)) {
56 c->rx = c->x; c->x = wax;
57 c->ry = c->y; c->y = way;
58 c->rw = c->w; c->w = waw - 2 * BORDERPX;
59 c->rh = c->h; c->h = wah - 2 * BORDERPX;
60 }
61 else {
62 c->x = c->rx;
63 c->y = c->ry;
64 c->w = c->rw;
65 c->h = c->rh;
66 }
67 resize(c, True, TopLeft);
68 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
69 }
71 static Client *
72 topofstack() {
73 Client *c;
74 unsigned int i;
76 for(c = nexttiled(clients), i = 0; c && i < nmaster; c = nexttiled(c->next), i++);
77 return (i < nmaster) ? NULL : c;
78 }
80 /* extern */
82 void (*arrange)(void) = DEFMODE;
84 void
85 detach(Client *c) {
86 if(c->prev)
87 c->prev->next = c->next;
88 if(c->next)
89 c->next->prev = c->prev;
90 if(c == clients)
91 clients = c->next;
92 c->next = c->prev = NULL;
93 }
95 void
96 dofloat(void) {
97 Client *c;
99 for(c = clients; c; c = c->next) {
100 if(isvisible(c)) {
101 resize(c, True, TopLeft);
102 }
103 else
104 ban(c);
105 }
106 if(!sel || !isvisible(sel)) {
107 for(c = stack; c && !isvisible(c); c = c->snext);
108 focus(c);
109 }
110 restack();
111 }
113 void
114 dotile(void) {
115 unsigned int i, n, mw, mh, tw, th;
116 Client *c;
118 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
119 n++;
120 /* window geoms */
121 mw = (n > nmaster) ? (waw * master) / 1000 : waw;
122 mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
123 tw = waw - mw;
124 th = (n > nmaster) ? wah / (n - nmaster) : 0;
126 for(i = 0, c = clients; c; c = c->next)
127 if(isvisible(c)) {
128 if(c->isfloat) {
129 resize(c, True, TopLeft);
130 continue;
131 }
132 c->ismax = False;
133 c->x = wax;
134 c->y = way;
135 if(i < nmaster) {
136 c->y += i * mh;
137 c->w = mw - 2 * BORDERPX;
138 c->h = mh - 2 * BORDERPX;
139 }
140 else { /* tile window */
141 c->x += mw;
142 c->w = tw - 2 * BORDERPX;
143 if(th > bh) {
144 c->y += (i - nmaster) * th;
145 c->h = th - 2 * BORDERPX;
146 }
147 else /* fallback if th < bh */
148 c->h = wah - 2 * BORDERPX;
149 }
150 resize(c, False, TopLeft);
151 i++;
152 }
153 else
154 ban(c);
156 if(!sel || !isvisible(sel)) {
157 for(c = stack; c && !isvisible(c); c = c->snext);
158 focus(c);
159 }
160 restack();
161 }
163 void
164 focusnext(Arg *arg) {
165 Client *c;
167 if(!sel)
168 return;
169 if(!(c = getnext(sel->next)))
170 c = getnext(clients);
171 if(c) {
172 focus(c);
173 restack();
174 }
175 }
177 void
178 focusprev(Arg *arg) {
179 Client *c;
181 if(!sel)
182 return;
183 if(!(c = getprev(sel->prev))) {
184 for(c = clients; c && c->next; c = c->next);
185 c = getprev(c);
186 }
187 if(c) {
188 focus(c);
189 restack();
190 }
191 }
193 void
194 incnmaster(Arg *arg) {
195 if(nmaster + arg->i < 1)
196 return;
197 nmaster += arg->i;
198 arrange();
199 }
201 Bool
202 isvisible(Client *c) {
203 unsigned int i;
205 for(i = 0; i < ntags; i++)
206 if(c->tags[i] && seltag[i])
207 return True;
208 return False;
209 }
211 void
212 resizemaster(Arg *arg) {
213 if(arg->i == 0)
214 master = MASTER;
215 else {
216 if(master + arg->i > 950 || master + arg->i < 50)
217 return;
218 master += arg->i;
219 }
220 arrange();
221 }
223 void
224 restack(void) {
225 Client *c;
226 XEvent ev;
228 if(!sel) {
229 drawstatus();
230 return;
231 }
232 if(sel->isfloat || arrange == dofloat) {
233 XRaiseWindow(dpy, sel->win);
234 XRaiseWindow(dpy, sel->twin);
235 }
236 if(arrange != dofloat) {
237 if(!sel->isfloat) {
238 XLowerWindow(dpy, sel->twin);
239 XLowerWindow(dpy, sel->win);
240 }
241 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
242 if(c == sel)
243 continue;
244 XLowerWindow(dpy, c->twin);
245 XLowerWindow(dpy, c->win);
246 }
247 }
248 drawall();
249 XSync(dpy, False);
250 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
251 }
253 void
254 togglefloat(Arg *arg) {
255 if (!sel || arrange == dofloat)
256 return;
257 sel->isfloat = !sel->isfloat;
258 arrange();
259 }
261 void
262 togglemode(Arg *arg) {
263 arrange = (arrange == dofloat) ? dotile : dofloat;
264 if(sel)
265 arrange();
266 else
267 drawstatus();
268 }
270 void
271 toggleview(Arg *arg) {
272 unsigned int i;
274 seltag[arg->i] = !seltag[arg->i];
275 for(i = 0; i < ntags && !seltag[i]; i++);
276 if(i == ntags)
277 seltag[arg->i] = True; /* cannot toggle last view */
278 arrange();
279 }
281 void
282 view(Arg *arg) {
283 unsigned int i;
285 for(i = 0; i < ntags; i++)
286 seltag[i] = (arg->i == -1) ? True : False;
287 if(arg->i >= 0 && arg->i < ntags)
288 seltag[arg->i] = True;
289 arrange();
290 }
292 void
293 zoom(Arg *arg) {
294 unsigned int n;
295 Client *c;
297 if(!sel)
298 return;
299 if(sel->isfloat || (arrange == dofloat)) {
300 togglemax(sel);
301 return;
302 }
303 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
304 n++;
306 c = sel;
307 if(n <= nmaster || (arrange == dofloat))
308 pop(c);
309 else if(ismaster(sel)) {
310 if(!(c = topofstack()))
311 return;
312 swap(c, sel);
313 c = sel;
314 }
315 else
316 pop(c);
318 focus(c);
319 arrange();
320 }