Mercurial > dwm-meillo
comparison tag.c @ 327:96d09fd98e89
separated several functions into view.c
author | Anselm R. Garbe <arg@10kloc.org> |
---|---|
date | Tue, 22 Aug 2006 16:50:21 +0200 |
parents | ec8a66a2b9cc |
children | 2a65e8b3d21a |
comparison
equal
deleted
inserted
replaced
326:73efaa15a635 | 327:96d09fd98e89 |
---|---|
28 RULES | 28 RULES |
29 | 29 |
30 static RReg *rreg = NULL; | 30 static RReg *rreg = NULL; |
31 static unsigned int len = 0; | 31 static unsigned int len = 0; |
32 | 32 |
33 void (*arrange)(Arg *) = DEFMODE; | |
34 | |
35 /* extern */ | 33 /* extern */ |
36 | |
37 void | |
38 dofloat(Arg *arg) | |
39 { | |
40 Client *c; | |
41 | |
42 for(c = clients; c; c = c->next) { | |
43 c->ismax = False; | |
44 if(isvisible(c)) { | |
45 resize(c, True, TopLeft); | |
46 } | |
47 else | |
48 ban(c); | |
49 } | |
50 if(!sel || !isvisible(sel)) | |
51 sel = getnext(clients); | |
52 if(sel) | |
53 focus(sel); | |
54 else | |
55 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); | |
56 restack(); | |
57 } | |
58 | |
59 void | |
60 dotile(Arg *arg) | |
61 { | |
62 int h, i, n, w; | |
63 Client *c; | |
64 | |
65 w = sw - mw; | |
66 for(n = 0, c = clients; c; c = c->next) | |
67 if(isvisible(c) && !c->isfloat) | |
68 n++; | |
69 | |
70 if(n > 1) | |
71 h = (sh - bh) / (n - 1); | |
72 else | |
73 h = sh - bh; | |
74 | |
75 for(i = 0, c = clients; c; c = c->next) { | |
76 c->ismax = False; | |
77 if(isvisible(c)) { | |
78 if(c->isfloat) { | |
79 resize(c, True, TopLeft); | |
80 continue; | |
81 } | |
82 if(n == 1) { | |
83 c->x = sx; | |
84 c->y = sy + bh; | |
85 c->w = sw - 2; | |
86 c->h = sh - 2 - bh; | |
87 } | |
88 else if(i == 0) { | |
89 c->x = sx; | |
90 c->y = sy + bh; | |
91 c->w = mw - 2; | |
92 c->h = sh - 2 - bh; | |
93 } | |
94 else if(h > bh) { | |
95 c->x = sx + mw; | |
96 c->y = sy + (i - 1) * h + bh; | |
97 c->w = w - 2; | |
98 if(i + 1 == n) | |
99 c->h = sh - c->y - 2; | |
100 else | |
101 c->h = h - 2; | |
102 } | |
103 else { /* fallback if h < bh */ | |
104 c->x = sx + mw; | |
105 c->y = sy + bh; | |
106 c->w = w - 2; | |
107 c->h = sh - 2 - bh; | |
108 } | |
109 resize(c, False, TopLeft); | |
110 i++; | |
111 } | |
112 else | |
113 ban(c); | |
114 } | |
115 if(!sel || !isvisible(sel)) | |
116 sel = getnext(clients); | |
117 if(sel) | |
118 focus(sel); | |
119 else | |
120 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); | |
121 restack(); | |
122 } | |
123 | 34 |
124 Client * | 35 Client * |
125 getnext(Client *c) | 36 getnext(Client *c) |
126 { | 37 { |
127 for(; c && !isvisible(c); c = c->next); | 38 for(; c && !isvisible(c); c = c->next); |
160 free(reg); | 71 free(reg); |
161 else | 72 else |
162 rreg[i].tregex = reg; | 73 rreg[i].tregex = reg; |
163 } | 74 } |
164 } | 75 } |
165 } | |
166 | |
167 Bool | |
168 isvisible(Client *c) | |
169 { | |
170 unsigned int i; | |
171 | |
172 for(i = 0; i < ntags; i++) | |
173 if(c->tags[i] && seltag[i]) | |
174 return True; | |
175 return False; | |
176 } | |
177 | |
178 void | |
179 restack() | |
180 { | |
181 static unsigned int nwins = 0; | |
182 static Window *wins = NULL; | |
183 unsigned int f, fi, m, mi, n; | |
184 Client *c; | |
185 XEvent ev; | |
186 | |
187 for(f = 0, m = 0, c = clients; c; c = c->next) | |
188 if(isvisible(c)) { | |
189 if(c->isfloat || arrange == dofloat) | |
190 f++; | |
191 else | |
192 m++; | |
193 } | |
194 if(!(n = 2 * (f + m))) { | |
195 drawstatus(); | |
196 return; | |
197 } | |
198 if(nwins < n) { | |
199 nwins = n; | |
200 wins = erealloc(wins, nwins * sizeof(Window)); | |
201 } | |
202 | |
203 fi = 0; | |
204 mi = 2 * f; | |
205 if(sel->isfloat || arrange == dofloat) { | |
206 wins[fi++] = sel->title; | |
207 wins[fi++] = sel->win; | |
208 } | |
209 else { | |
210 wins[mi++] = sel->title; | |
211 wins[mi++] = sel->win; | |
212 } | |
213 for(c = clients; c; c = c->next) | |
214 if(isvisible(c) && c != sel) { | |
215 if(c->isfloat || arrange == dofloat) { | |
216 wins[fi++] = c->title; | |
217 wins[fi++] = c->win; | |
218 } | |
219 else { | |
220 wins[mi++] = c->title; | |
221 wins[mi++] = c->win; | |
222 } | |
223 } | |
224 XRestackWindows(dpy, wins, n); | |
225 drawall(); | |
226 XSync(dpy, False); | |
227 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); | |
228 } | 76 } |
229 | 77 |
230 void | 78 void |
231 settags(Client *c) | 79 settags(Client *c) |
232 { | 80 { |
275 if(!isvisible(sel)) | 123 if(!isvisible(sel)) |
276 arrange(NULL); | 124 arrange(NULL); |
277 } | 125 } |
278 | 126 |
279 void | 127 void |
280 togglemode(Arg *arg) | |
281 { | |
282 arrange = arrange == dofloat ? dotile : dofloat; | |
283 if(sel) | |
284 arrange(NULL); | |
285 else | |
286 drawstatus(); | |
287 } | |
288 | |
289 void | |
290 toggletag(Arg *arg) | 128 toggletag(Arg *arg) |
291 { | 129 { |
292 unsigned int i; | 130 unsigned int i; |
293 | 131 |
294 if(!sel) | 132 if(!sel) |
300 sel->tags[arg->i] = True; | 138 sel->tags[arg->i] = True; |
301 settitle(sel); | 139 settitle(sel); |
302 if(!isvisible(sel)) | 140 if(!isvisible(sel)) |
303 arrange(NULL); | 141 arrange(NULL); |
304 } | 142 } |
305 | |
306 | |
307 void | |
308 toggleview(Arg *arg) | |
309 { | |
310 unsigned int i; | |
311 | |
312 seltag[arg->i] = !seltag[arg->i]; | |
313 for(i = 0; i < ntags && !seltag[i]; i++); | |
314 if(i == ntags) | |
315 seltag[arg->i] = True; /* cannot toggle last view */ | |
316 arrange(NULL); | |
317 } | |
318 | |
319 void | |
320 view(Arg *arg) | |
321 { | |
322 unsigned int i; | |
323 | |
324 for(i = 0; i < ntags; i++) | |
325 seltag[i] = False; | |
326 seltag[arg->i] = True; | |
327 arrange(NULL); | |
328 } |