dwm-meillo

view view.c @ 561:b5435d3fb7b0

applied Jukkas patch
author arg@mig29
date Fri, 03 Nov 2006 08:29:39 +0100
parents a2c465098a3b
children fe766305eed1
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 resizemaster(Arg *arg) {
199 if(arg->i == 0)
200 master = MASTER;
201 else {
202 if(master + arg->i > 950 || master + arg->i < 50)
203 return;
204 master += arg->i;
205 }
206 arrange();
207 }
209 void
210 restack(void) {
211 Client *c;
212 XEvent ev;
214 if(!sel) {
215 drawstatus();
216 return;
217 }
218 if(sel->isfloat || arrange == dofloat) {
219 XRaiseWindow(dpy, sel->win);
220 XRaiseWindow(dpy, sel->twin);
221 }
222 if(arrange != dofloat) {
223 if(!sel->isfloat) {
224 XLowerWindow(dpy, sel->twin);
225 XLowerWindow(dpy, sel->win);
226 }
227 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
228 if(c == sel)
229 continue;
230 XLowerWindow(dpy, c->twin);
231 XLowerWindow(dpy, c->win);
232 }
233 }
234 drawall();
235 XSync(dpy, False);
236 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
237 }
239 void
240 togglemode(Arg *arg) {
241 arrange = (arrange == dofloat) ? dotile : dofloat;
242 if(sel)
243 arrange();
244 else
245 drawstatus();
246 }
248 void
249 toggleview(Arg *arg) {
250 unsigned int i;
252 seltag[arg->i] = !seltag[arg->i];
253 for(i = 0; i < ntags && !seltag[i]; i++);
254 if(i == ntags)
255 seltag[arg->i] = True; /* cannot toggle last view */
256 reorder();
257 arrange();
258 }
260 void
261 view(Arg *arg) {
262 unsigned int i;
264 for(i = 0; i < ntags; i++)
265 seltag[i] = False;
266 seltag[arg->i] = True;
267 reorder();
268 arrange();
269 }
271 void
272 viewall(Arg *arg) {
273 unsigned int i;
275 for(i = 0; i < ntags; i++)
276 seltag[i] = True;
277 reorder();
278 arrange();
279 }
281 void
282 zoom(Arg *arg) {
283 unsigned int n;
284 Client *c;
286 if(!sel)
287 return;
288 if(sel->isfloat || (arrange == dofloat)) {
289 togglemax(sel);
290 return;
291 }
292 for(n = 0, c = clients; c; c = c->next)
293 if(isvisible(c) && !c->isfloat)
294 n++;
295 if(n < 2 || (arrange == dofloat))
296 return;
297 if((c = sel) == nexttiled(clients))
298 if(!(c = nexttiled(c->next)))
299 return;
300 detach(c);
301 if(clients)
302 clients->prev = c;
303 c->next = clients;
304 clients = c;
305 focus(c);
306 arrange();
307 }