dwm-meillo

view view.c @ 549:fd1061442711

applied sanders try2 patch
author arg@mig29
date Fri, 27 Oct 2006 13:28:26 +0200
parents 3d23384eb5ab
children e249e2952a32
line source
1 /* (C)opyright MMVI 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 minclient(void) {
10 Client *c, *min;
12 if((clients && clients->isfloat) || arrange == dofloat)
13 return clients; /* don't touch floating order */
14 for(min = c = clients; c; c = c->next)
15 if(c->weight < min->weight)
16 min = c;
17 return min;
18 }
20 static Client *
21 nexttiled(Client *c) {
22 for(c = getnext(c); c && c->isfloat; c = getnext(c->next));
23 return c;
24 }
26 static void
27 reorder(void) {
28 Client *c, *newclients, *tail;
30 newclients = tail = NULL;
31 while((c = minclient())) {
32 detach(c);
33 if(tail) {
34 c->prev = tail;
35 tail->next = c;
36 tail = c;
37 }
38 else
39 tail = newclients = c;
40 }
41 clients = newclients;
42 }
44 static void
45 togglemax(Client *c) {
46 XEvent ev;
48 if(c->isfixed)
49 return;
51 if((c->ismax = !c->ismax)) {
52 c->rx = c->x; c->x = sx;
53 c->ry = c->y; c->y = bh;
54 c->rw = c->w; c->w = sw - 2 * BORDERPX;
55 c->rh = c->h; c->h = sh - bh - 2 * BORDERPX;
56 }
57 else {
58 c->x = c->rx;
59 c->y = c->ry;
60 c->w = c->rw;
61 c->h = c->rh;
62 }
63 resize(c, True, TopLeft);
64 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
65 }
67 /* extern */
69 void (*arrange)(void) = DEFMODE;
71 void
72 detach(Client *c) {
73 if(c->prev)
74 c->prev->next = c->next;
75 if(c->next)
76 c->next->prev = c->prev;
77 if(c == clients)
78 clients = c->next;
79 c->next = c->prev = NULL;
80 }
82 void
83 dofloat(void) {
84 Client *c;
86 for(c = clients; c; c = c->next) {
87 if(isvisible(c)) {
88 resize(c, True, TopLeft);
89 }
90 else
91 ban(c);
92 }
93 if(!sel || !isvisible(sel)) {
94 for(c = stack; c && !isvisible(c); c = c->snext);
95 focus(c);
96 }
97 restack();
98 }
100 void
101 dotile(void) {
102 unsigned int i, n, mpx, stackw, stackh, th;
103 Client *c;
105 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
106 n++;
107 mpx = (sw * master) / 1000;
108 stackw = sw - mpx;
109 stackh = sh - bh;
110 th = stackh;
111 if(n > 1)
112 th /= (n - 1);
114 for(i = 0, c = clients; c; c = c->next)
115 if(isvisible(c)) {
116 if(c->isfloat) {
117 resize(c, True, TopLeft);
118 continue;
119 }
120 c->ismax = False;
121 c->x = sx;
122 c->y = sy + bh;
123 if(n == 1) { /* only 1 window */
124 c->w = sw - 2 * BORDERPX;
125 c->h = sh - 2 * BORDERPX - bh;
126 }
127 else if(i == 0) { /* master window */
128 c->w = mpx - 2 * BORDERPX;
129 c->h = sh - bh - 2 * BORDERPX;
130 }
131 else { /* tile window */
132 c->x += mpx;
133 c->w = stackw - 2 * BORDERPX;
134 if(th > bh) {
135 c->y = sy + (i - 1) * th + bh;
136 if(i + 1 == n)
137 c->h = sh - c->y - 2 * BORDERPX;
138 else
139 c->h = th - 2 * BORDERPX;
140 }
141 else /* fallback if th < bh */
142 c->h = stackh - 2 * BORDERPX;
143 }
144 resize(c, False, TopLeft);
145 i++;
146 }
147 else
148 ban(c);
150 if(!sel || !isvisible(sel)) {
151 for(c = stack; c && !isvisible(c); c = c->snext);
152 focus(c);
153 }
154 restack();
155 }
157 void
158 focusnext(Arg *arg) {
159 Client *c;
161 if(!sel)
162 return;
163 if(!(c = getnext(sel->next)))
164 c = getnext(clients);
165 if(c) {
166 focus(c);
167 restack();
168 }
169 }
171 void
172 focusprev(Arg *arg) {
173 Client *c;
175 if(!sel)
176 return;
177 if(!(c = getprev(sel->prev))) {
178 for(c = clients; c && c->next; c = c->next);
179 c = getprev(c);
180 }
181 if(c) {
182 focus(c);
183 restack();
184 }
185 }
187 Bool
188 isvisible(Client *c) {
189 unsigned int i;
191 for(i = 0; i < ntags; i++)
192 if(c->tags[i] && seltag[i])
193 return True;
194 return False;
195 }
197 void
198 resizecol(Arg *arg) {
199 unsigned int n;
200 Client *c;
202 for(n = 0, c = clients; c; c = c->next)
203 if(isvisible(c) && !c->isfloat)
204 n++;
205 if(!sel || sel->isfloat || n < 2 || (arrange == dofloat))
206 return;
207 if(sel == getnext(clients)) {
208 if(master + arg->i > 950 || master + arg->i < 50)
209 return;
210 master += arg->i;
211 }
212 else {
213 if(master - arg->i > 950 || master - arg->i < 50)
214 return;
215 master -= arg->i;
216 }
217 arrange();
218 }
220 void
221 restack(void) {
222 Client *c;
223 XEvent ev;
225 if(!sel) {
226 drawstatus();
227 return;
228 }
229 if(sel->isfloat || arrange == dofloat) {
230 XRaiseWindow(dpy, sel->win);
231 XRaiseWindow(dpy, sel->twin);
232 }
233 if(arrange != dofloat) {
234 if(!sel->isfloat) {
235 XLowerWindow(dpy, sel->twin);
236 XLowerWindow(dpy, sel->win);
237 }
238 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
239 if(c == sel)
240 continue;
241 XLowerWindow(dpy, c->twin);
242 XLowerWindow(dpy, c->win);
243 }
244 }
245 drawall();
246 XSync(dpy, False);
247 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
248 }
250 void
251 togglemode(Arg *arg) {
252 arrange = (arrange == dofloat) ? dotile : dofloat;
253 if(sel)
254 arrange();
255 else
256 drawstatus();
257 }
259 void
260 toggleview(Arg *arg) {
261 unsigned int i;
263 seltag[arg->i] = !seltag[arg->i];
264 for(i = 0; i < ntags && !seltag[i]; i++);
265 if(i == ntags)
266 seltag[arg->i] = True; /* cannot toggle last view */
267 reorder();
268 arrange();
269 }
271 void
272 view(Arg *arg) {
273 unsigned int i;
275 for(i = 0; i < ntags; i++)
276 seltag[i] = False;
277 seltag[arg->i] = True;
278 reorder();
279 arrange();
280 }
282 void
283 viewall(Arg *arg) {
284 unsigned int i;
286 for(i = 0; i < ntags; i++)
287 seltag[i] = True;
288 reorder();
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 = clients; c; c = c->next)
304 if(isvisible(c) && !c->isfloat)
305 n++;
306 if(n < 2 || (arrange == dofloat))
307 return;
308 if((c = sel) == nexttiled(clients))
309 if(!(c = nexttiled(c->next)))
310 return;
311 detach(c);
312 if(clients)
313 clients->prev = c;
314 c->next = clients;
315 clients = c;
316 focus(c);
317 arrange();
318 }