dwm-meillo

view view.c @ 749:6692d7e7e156

added maxlayout by mitch, moved config.h to config.meillo.h, some smaller modifications
author meillo@marmaro.de
date Sun, 11 Feb 2007 17:20:22 +0100
parents 0f91934037b0
children
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"
5 #include <stdio.h>
7 /* static */
9 static Client *
10 nexttiled(Client *c) {
11 for(c = getnext(c); c && c->isfloat; c = getnext(c->next));
12 return c;
13 }
15 static void
16 togglemax(Client *c) {
17 XEvent ev;
19 if(c->isfixed)
20 return;
22 if((c->ismax = !c->ismax)) {
23 c->rx = c->x; c->x = wax;
24 c->ry = c->y; c->y = way;
25 c->rw = c->w; c->w = waw - 2 * BORDERPX;
26 c->rh = c->h; c->h = wah - 2 * BORDERPX;
27 }
28 else {
29 c->x = c->rx;
30 c->y = c->ry;
31 c->w = c->rw;
32 c->h = c->rh;
33 }
34 resize(c, True);
35 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
36 }
38 /* extern */
40 void (*arrange)(void) = DEFMODE;
42 void
43 detach(Client *c) {
44 if(c->prev)
45 c->prev->next = c->next;
46 if(c->next)
47 c->next->prev = c->prev;
48 if(c == clients)
49 clients = c->next;
50 c->next = c->prev = NULL;
51 }
53 void
54 dofloat(void) {
55 Client *c;
57 for(c = clients; c; c = c->next) {
58 if(isvisible(c)) {
59 resize(c, True);
60 }
61 else
62 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
63 }
64 if(!sel || !isvisible(sel)) {
65 for(c = stack; c && !isvisible(c); c = c->snext);
66 focus(c);
67 }
68 restack();
69 }
71 void
72 dotile(void) {
73 unsigned int i, n, mw, mh, tw, th;
74 Client *c;
76 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
77 n++;
78 /* window geoms */
79 mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
80 mw = (n > nmaster) ? (waw * master) / 1000 : waw;
81 th = (n > nmaster) ? wah / (n - nmaster) : 0;
82 tw = waw - mw;
84 for(i = 0, c = clients; c; c = c->next)
85 if(isvisible(c)) {
86 if(c->isfloat) {
87 resize(c, True);
88 continue;
89 }
90 c->ismax = False;
91 c->x = wax;
92 c->y = way;
93 if(i < nmaster) {
94 c->y += i * mh;
95 c->w = mw - 2 * BORDERPX;
96 c->h = mh - 2 * BORDERPX;
97 }
98 else { /* tile window */
99 c->x += mw;
100 c->w = tw - 2 * BORDERPX;
101 if(th > 2 * BORDERPX) {
102 c->y += (i - nmaster) * th;
103 c->h = th - 2 * BORDERPX;
104 }
105 else /* fallback if th <= 2 * BORDERPX */
106 c->h = wah - 2 * BORDERPX;
107 }
108 resize(c, False);
109 i++;
110 }
111 else
112 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
113 if(!sel || !isvisible(sel)) {
114 for(c = stack; c && !isvisible(c); c = c->snext);
115 focus(c);
116 }
117 restack();
118 }
120 /* begin code by mitch */
121 void
122 arrangemax(Client *c) {
123 if(c == sel) {
124 c->ismax = True;
125 c->x = sx;
126 c->y = bh;
127 c->w = sw - 2 * BORDERPX;
128 c->h = sh - bh - 2 * BORDERPX;
129 XRaiseWindow(dpy, c->win);
130 } else {
131 c->ismax = False;
132 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
133 XLowerWindow(dpy, c->win);
134 }
135 }
137 void
138 domax(void) {
139 Client *c;
141 for(c = clients; c; c = c->next) {
142 if(isvisible(c)) {
143 if(c->isfloat) {
144 resize(c, True);
145 continue;
146 }
147 arrangemax(c);
148 resize(c, False);
149 } else {
150 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
151 }
153 }
154 if(!sel || !isvisible(sel)) {
155 for(c = stack; c && !isvisible(c); c = c->snext);
156 focus(c);
157 }
158 restack();
159 }
160 /* end code by mitch */
162 void
163 focusnext(Arg *arg) {
164 Client *c;
166 if(!sel)
167 return;
168 if(!(c = getnext(sel->next)))
169 c = getnext(clients);
170 if(c) {
171 focus(c);
172 restack();
173 }
174 }
176 void
177 focusprev(Arg *arg) {
178 Client *c;
180 if(!sel)
181 return;
182 if(!(c = getprev(sel->prev))) {
183 for(c = clients; c && c->next; c = c->next);
184 c = getprev(c);
185 }
186 if(c) {
187 focus(c);
188 restack();
189 }
190 }
192 void
193 incnmaster(Arg *arg) {
194 if((arrange == dofloat) || (nmaster + arg->i < 1)
195 || (wah / (nmaster + arg->i) <= 2 * BORDERPX))
196 return;
197 nmaster += arg->i;
198 if(sel)
199 arrange();
200 else
201 drawstatus();
202 }
204 Bool
205 isvisible(Client *c) {
206 unsigned int i;
208 for(i = 0; i < ntags; i++)
209 if(c->tags[i] && seltag[i])
210 return True;
211 return False;
212 }
214 void
215 resizemaster(Arg *arg) {
216 if(arg->i == 0)
217 master = MASTER;
218 else {
219 if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX
220 || waw * (master + arg->i) / 1000 <= 2 * BORDERPX)
221 return;
222 master += arg->i;
223 }
224 arrange();
225 }
227 void
228 restack(void) {
229 Client *c;
230 XEvent ev;
232 drawstatus();
233 if(!sel)
234 return;
235 if(sel->isfloat || arrange == dofloat)
236 XRaiseWindow(dpy, sel->win);
238 /* begin code by mitch */
239 if(arrange == domax) {
240 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
241 arrangemax(c);
242 resize(c, False);
243 }
245 } else if (arrange == dotile) {
246 /* end code by mitch */
248 if(!sel->isfloat)
249 XLowerWindow(dpy, sel->win);
250 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
251 if(c == sel)
252 continue;
253 XLowerWindow(dpy, c->win);
254 }
255 }
256 XSync(dpy, False);
257 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
258 }
260 void
261 togglefloat(Arg *arg) {
262 if (!sel || arrange == dofloat)
263 return;
264 sel->isfloat = !sel->isfloat;
265 arrange();
266 }
268 void
269 togglemode(Arg *arg) {
270 /* only toggle between tile and max - float is just available through togglefloat */
271 arrange = (arrange == dotile) ? domax : dotile;
272 if(sel)
273 arrange();
274 else
275 drawstatus();
276 }
278 void
279 toggleview(Arg *arg) {
280 unsigned int i;
282 seltag[arg->i] = !seltag[arg->i];
283 for(i = 0; i < ntags && !seltag[i]; i++);
284 if(i == ntags)
285 seltag[arg->i] = True; /* cannot toggle last view */
286 arrange();
287 }
289 void
290 view(Arg *arg) {
291 unsigned int i;
293 for(i = 0; i < ntags; i++)
294 seltag[i] = (arg->i == -1) ? True : False;
295 if(arg->i >= 0 && arg->i < ntags)
296 seltag[arg->i] = True;
297 arrange();
298 }
300 void
301 zoom(Arg *arg) {
302 unsigned int n;
303 Client *c;
305 if(!sel)
306 return;
307 if(sel->isfloat || (arrange == dofloat)) {
308 togglemax(sel);
309 return;
310 }
311 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
312 n++;
314 if((c = sel) == nexttiled(clients))
315 if(!(c = nexttiled(c->next)))
316 return;
317 detach(c);
318 if(clients)
319 clients->prev = c;
320 c->next = clients;
321 clients = c;
322 focus(c);
323 arrange();
324 }