aewl

view view.c @ 673:d47d6e28441b

Added tag 2.9 for changeset 3a5910fac3cc
author Anselm R. Garbe <arg@suckless.org>
date Mon, 08 Jan 2007 13:01:37 +0100
parents 4b8096176bbe
children 5d79c351e30a
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 void
15 togglemax(Client *c) {
16 XEvent ev;
18 if(c->isfixed)
19 return;
21 if((c->ismax = !c->ismax)) {
22 c->rx = c->x; c->x = wax;
23 c->ry = c->y; c->y = way;
24 c->rw = c->w; c->w = waw - 2 * BORDERPX;
25 c->rh = c->h; c->h = wah - 2 * BORDERPX;
26 }
27 else {
28 c->x = c->rx;
29 c->y = c->ry;
30 c->w = c->rw;
31 c->h = c->rh;
32 }
33 resize(c, True, TopLeft);
34 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
35 }
37 /* extern */
39 void (*arrange)(void) = DEFMODE;
41 void
42 detach(Client *c) {
43 if(c->prev)
44 c->prev->next = c->next;
45 if(c->next)
46 c->next->prev = c->prev;
47 if(c == clients)
48 clients = c->next;
49 c->next = c->prev = NULL;
50 }
52 void
53 dofloat(void) {
54 Client *c;
56 for(c = clients; c; c = c->next) {
57 if(isvisible(c)) {
58 resize(c, True, TopLeft);
59 }
60 else
61 ban(c);
62 }
63 if(!sel || !isvisible(sel)) {
64 for(c = stack; c && !isvisible(c); c = c->snext);
65 focus(c);
66 }
67 restack();
68 }
70 void
71 dotile(void) {
72 unsigned int i, n, mw, mh, tw, th;
73 Client *c;
75 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
76 n++;
77 /* window geoms */
78 mw = (n > nmaster) ? (waw * master) / 1000 : waw;
79 mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
80 tw = waw - mw;
81 th = (n > nmaster) ? wah / (n - nmaster) : 0;
83 for(i = 0, c = clients; c; c = c->next)
84 if(isvisible(c)) {
85 if(c->isfloat) {
86 resize(c, True, TopLeft);
87 continue;
88 }
89 c->ismax = False;
90 c->x = wax;
91 c->y = way;
92 if(i < nmaster) {
93 c->y += i * mh;
94 c->w = mw - 2 * BORDERPX;
95 c->h = mh - 2 * BORDERPX;
96 }
97 else { /* tile window */
98 c->x += mw;
99 c->w = tw - 2 * BORDERPX;
100 if(th > bh) {
101 c->y += (i - nmaster) * th;
102 c->h = th - 2 * BORDERPX;
103 }
104 else /* fallback if th < bh */
105 c->h = wah - 2 * BORDERPX;
106 }
107 resize(c, False, TopLeft);
108 i++;
109 }
110 else
111 ban(c);
113 if(!sel || !isvisible(sel)) {
114 for(c = stack; c && !isvisible(c); c = c->snext);
115 focus(c);
116 }
117 restack();
118 }
120 void
121 focusnext(Arg *arg) {
122 Client *c;
124 if(!sel)
125 return;
126 if(!(c = getnext(sel->next)))
127 c = getnext(clients);
128 if(c) {
129 focus(c);
130 restack();
131 }
132 }
134 void
135 focusprev(Arg *arg) {
136 Client *c;
138 if(!sel)
139 return;
140 if(!(c = getprev(sel->prev))) {
141 for(c = clients; c && c->next; c = c->next);
142 c = getprev(c);
143 }
144 if(c) {
145 focus(c);
146 restack();
147 }
148 }
150 void
151 incnmaster(Arg *arg) {
152 if((nmaster + arg->i < 1) || (wah / (nmaster + arg->i) < bh))
153 return;
154 nmaster += arg->i;
155 arrange();
156 }
158 Bool
159 isvisible(Client *c) {
160 unsigned int i;
162 for(i = 0; i < ntags; i++)
163 if(c->tags[i] && seltag[i])
164 return True;
165 return False;
166 }
168 void
169 resizemaster(Arg *arg) {
170 if(arg->i == 0)
171 master = MASTER;
172 else {
173 if(master + arg->i > 950 || master + arg->i < 50)
174 return;
175 master += arg->i;
176 }
177 arrange();
178 }
180 void
181 restack(void) {
182 Client *c;
183 XEvent ev;
185 if(!sel) {
186 drawstatus();
187 return;
188 }
189 if(sel->isfloat || arrange == dofloat) {
190 XRaiseWindow(dpy, sel->win);
191 XRaiseWindow(dpy, sel->twin);
192 }
193 if(arrange != dofloat) {
194 if(!sel->isfloat) {
195 XLowerWindow(dpy, sel->twin);
196 XLowerWindow(dpy, sel->win);
197 }
198 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
199 if(c == sel)
200 continue;
201 XLowerWindow(dpy, c->twin);
202 XLowerWindow(dpy, c->win);
203 }
204 }
205 drawall();
206 XSync(dpy, False);
207 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
208 }
210 void
211 togglefloat(Arg *arg) {
212 if (!sel || arrange == dofloat)
213 return;
214 sel->isfloat = !sel->isfloat;
215 arrange();
216 }
218 void
219 togglemode(Arg *arg) {
220 arrange = (arrange == dofloat) ? dotile : dofloat;
221 if(sel)
222 arrange();
223 else
224 drawstatus();
225 }
227 void
228 toggleview(Arg *arg) {
229 unsigned int i;
231 seltag[arg->i] = !seltag[arg->i];
232 for(i = 0; i < ntags && !seltag[i]; i++);
233 if(i == ntags)
234 seltag[arg->i] = True; /* cannot toggle last view */
235 arrange();
236 }
238 void
239 view(Arg *arg) {
240 unsigned int i;
242 for(i = 0; i < ntags; i++)
243 seltag[i] = (arg->i == -1) ? True : False;
244 if(arg->i >= 0 && arg->i < ntags)
245 seltag[arg->i] = True;
246 arrange();
247 }
249 void
250 zoom(Arg *arg) {
251 unsigned int n;
252 Client *c;
254 if(!sel)
255 return;
256 if(sel->isfloat || (arrange == dofloat)) {
257 togglemax(sel);
258 return;
259 }
260 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
261 n++;
263 if((c = sel) == nexttiled(clients))
264 if(!(c = nexttiled(c->next)))
265 return;
266 detach(c);
267 if(clients)
268 clients->prev = c;
269 c->next = clients;
270 clients = c;
271 focus(c);
272 arrange();
273 }