aewl

view view.c @ 492:5df494262dfd

removed useless debug info
author arg@mmvi
date Tue, 26 Sep 2006 08:17:35 +0200
parents be4f90c03582
children 9aa3d06199cb
line source
1 /*
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
4 */
5 #include "dwm.h"
7 /* static */
9 static Client *
10 minclient(void) {
11 Client *c, *min;
13 if((clients && clients->isfloat) || arrange == dofloat)
14 return clients; /* don't touch floating order */
15 for(min = c = clients; c; c = c->next)
16 if(c->weight < min->weight)
17 min = c;
18 return min;
19 }
21 static Client *
22 nexttiled(Client *c) {
23 for(c = getnext(c); c && c->isfloat; c = getnext(c->next));
24 return c;
25 }
27 static void
28 reorder(void) {
29 Client *c, *newclients, *tail;
31 newclients = tail = NULL;
32 while((c = minclient())) {
33 detach(c);
34 if(tail) {
35 c->prev = tail;
36 tail->next = c;
37 tail = c;
38 }
39 else
40 tail = newclients = c;
41 }
42 clients = newclients;
43 }
45 static void
46 togglemax(Client *c)
47 {
48 XEvent ev;
49 if((c->ismax = !c->ismax)) {
50 c->rx = c->x; c->x = sx;
51 c->ry = c->y; c->y = bh;
52 c->rw = c->w; c->w = sw;
53 c->rh = c->h; c->h = sh - bh - 2;
54 }
55 else {
56 c->x = c->rx;
57 c->y = c->ry;
58 c->w = c->rw;
59 c->h = c->rh;
60 }
61 resize(c, True, TopLeft);
62 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
63 }
65 /* extern */
67 void (*arrange)(Arg *) = DEFMODE;
69 void
70 detach(Client *c) {
71 if(c->prev)
72 c->prev->next = c->next;
73 if(c->next)
74 c->next->prev = c->prev;
75 if(c == clients)
76 clients = c->next;
77 c->next = c->prev = NULL;
78 }
80 void
81 dofloat(Arg *arg) {
82 Client *c;
84 for(c = clients; c; c = c->next) {
85 if(isvisible(c)) {
86 resize(c, True, TopLeft);
87 }
88 else
89 ban(c);
90 }
91 if(!sel || !isvisible(sel)) {
92 for(c = stack; c && !isvisible(c); c = c->snext);
93 focus(c);
94 }
95 restack();
96 }
98 void
99 dotile(Arg *arg) {
100 int h, i, n, w;
101 Client *c;
103 w = sw - mw;
104 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
105 n++;
107 if(n > 1)
108 h = (sh - bh) / (n - 1);
109 else
110 h = sh - bh;
112 for(i = 0, c = clients; c; c = c->next) {
113 if(isvisible(c)) {
114 if(c->isfloat) {
115 resize(c, True, TopLeft);
116 continue;
117 }
118 c->ismax = False;
119 if(n == 1) {
120 c->x = sx;
121 c->y = sy + bh;
122 c->w = sw - 2;
123 c->h = sh - 2 - bh;
124 }
125 else if(i == 0) {
126 c->x = sx;
127 c->y = sy + bh;
128 c->w = mw - 2;
129 c->h = sh - 2 - bh;
130 }
131 else if(h > bh) {
132 c->x = sx + mw;
133 c->y = sy + (i - 1) * h + bh;
134 c->w = w - 2;
135 if(i + 1 == n)
136 c->h = sh - c->y - 2;
137 else
138 c->h = h - 2;
139 }
140 else { /* fallback if h < bh */
141 c->x = sx + mw;
142 c->y = sy + bh;
143 c->w = w - 2;
144 c->h = sh - 2 - bh;
145 }
146 resize(c, False, TopLeft);
147 i++;
148 }
149 else
150 ban(c);
151 }
152 if(!sel || !isvisible(sel)) {
153 for(c = stack; c && !isvisible(c); c = c->snext);
154 focus(c);
155 }
156 restack();
157 }
159 void
160 focusnext(Arg *arg) {
161 Client *c;
163 if(!sel)
164 return;
166 if(!(c = getnext(sel->next)))
167 c = getnext(clients);
168 if(c) {
169 focus(c);
170 restack();
171 }
172 }
174 void
175 focusprev(Arg *arg) {
176 Client *c;
178 if(!sel)
179 return;
181 if(!(c = getprev(sel->prev))) {
182 for(c = clients; c && c->next; c = c->next);
183 c = getprev(c);
184 }
185 if(c) {
186 focus(c);
187 restack();
188 }
189 }
191 Bool
192 isvisible(Client *c) {
193 unsigned int i;
195 for(i = 0; i < ntags; i++)
196 if(c->tags[i] && seltag[i])
197 return True;
198 return False;
199 }
201 void
202 resizecol(Arg *arg) {
203 unsigned int n;
204 Client *c;
206 for(n = 0, c = clients; c; c = c->next)
207 if(isvisible(c) && !c->isfloat)
208 n++;
209 if(!sel || sel->isfloat || n < 2 || (arrange == dofloat))
210 return;
212 if(sel == getnext(clients)) {
213 if(mw + arg->i > sw - 100 || mw + arg->i < 100)
214 return;
215 mw += arg->i;
216 }
217 else {
218 if(mw - arg->i > sw - 100 || mw - arg->i < 100)
219 return;
220 mw -= arg->i;
221 }
222 arrange(NULL);
223 }
225 void
226 restack(void) {
227 Client *c;
228 XEvent ev;
230 if(!sel) {
231 drawstatus();
232 return;
233 }
234 if(sel->isfloat || arrange == dofloat) {
235 XRaiseWindow(dpy, sel->win);
236 XRaiseWindow(dpy, sel->twin);
237 }
238 if(arrange != dofloat)
239 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
240 XLowerWindow(dpy, c->twin);
241 XLowerWindow(dpy, c->win);
242 }
243 drawall();
244 XSync(dpy, False);
245 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
246 }
248 void
249 togglemode(Arg *arg) {
250 arrange = (arrange == dofloat) ? dotile : dofloat;
251 if(sel)
252 arrange(NULL);
253 else
254 drawstatus();
255 }
257 void
258 toggleview(Arg *arg) {
259 unsigned int i;
261 seltag[arg->i] = !seltag[arg->i];
262 for(i = 0; i < ntags && !seltag[i]; i++);
263 if(i == ntags)
264 seltag[arg->i] = True; /* cannot toggle last view */
265 reorder();
266 arrange(NULL);
267 }
269 void
270 view(Arg *arg) {
271 unsigned int i;
273 for(i = 0; i < ntags; i++)
274 seltag[i] = False;
275 seltag[arg->i] = True;
276 reorder();
277 arrange(NULL);
278 }
280 void
281 viewall(Arg *arg) {
282 unsigned int i;
284 for(i = 0; i < ntags; i++)
285 seltag[i] = True;
286 reorder();
287 arrange(NULL);
288 }
290 void
291 zoom(Arg *arg) {
292 unsigned int n;
293 Client *c;
295 if(!sel)
296 return;
298 if(sel->isfloat || (arrange == dofloat)) {
299 togglemax(sel);
300 return;
301 }
303 for(n = 0, c = clients; c; c = c->next)
304 if(isvisible(c) && !c->isfloat)
305 n++;
306 if(n < 2 || (arrange == dofloat))
307 return;
309 if((c = sel) == nexttiled(clients))
310 if(!(c = nexttiled(c->next)))
311 return;
312 detach(c);
313 if(clients)
314 clients->prev = c;
315 c->next = clients;
316 clients = c;
317 focus(c);
318 arrange(NULL);
319 }