aewl

view view.c @ 643:e90bf387bf6f

next version will contain updated copyright notice
author arg@mig29
date Tue, 02 Jan 2007 15:37:58 +0100
parents 276238ad9516
children 1ed8c40dde36
line source
1 /* (C)opyright MMVII 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 nexttiled(Client *c) {
10 for(c = getnext(c); c && c->isfloat; c = getnext(c->next));
11 return c;
12 }
14 static void
15 togglemax(Client *c) {
16 XEvent ev;
18 if(c->isfixed)
19 return;
21 if((c->ismax = !c->ismax)) {
22 c->rx = c->x; c->x = wax;
23 c->ry = c->y; c->y = way;
24 c->rw = c->w; c->w = waw - 2 * BORDERPX;
25 c->rh = c->h; c->h = wah - 2 * BORDERPX;
26 }
27 else {
28 c->x = c->rx;
29 c->y = c->ry;
30 c->w = c->rw;
31 c->h = c->rh;
32 }
33 resize(c, True, TopLeft);
34 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
35 }
37 /* extern */
39 void (*arrange)(void) = DEFMODE;
41 void
42 detach(Client *c) {
43 if(c->prev)
44 c->prev->next = c->next;
45 if(c->next)
46 c->next->prev = c->prev;
47 if(c == clients)
48 clients = c->next;
49 c->next = c->prev = NULL;
50 }
52 void
53 dofloat(void) {
54 Client *c;
56 for(c = clients; c; c = c->next) {
57 if(isvisible(c)) {
58 resize(c, True, TopLeft);
59 }
60 else
61 ban(c);
62 }
63 if(!sel || !isvisible(sel)) {
64 for(c = stack; c && !isvisible(c); c = c->snext);
65 focus(c);
66 }
67 restack();
68 }
70 void
71 dotile(void) {
72 unsigned int i, n, mpw, th;
73 Client *c;
75 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
76 n++;
77 mpw = (waw * master) / 1000;
79 for(i = 0, c = clients; c; c = c->next)
80 if(isvisible(c)) {
81 if(c->isfloat) {
82 resize(c, True, TopLeft);
83 continue;
84 }
85 c->ismax = False;
86 c->x = wax;
87 c->y = way;
88 if(n == 1) { /* only 1 window */
89 c->w = waw - 2 * BORDERPX;
90 c->h = wah - 2 * BORDERPX;
91 }
92 else if(i == 0) { /* master window */
93 c->w = mpw - 2 * BORDERPX;
94 c->h = wah - 2 * BORDERPX;
95 th = wah / (n - 1);
96 }
97 else { /* tile window */
98 c->x += mpw;
99 c->w = (waw - mpw) - 2 * BORDERPX;
100 if(th > bh) {
101 c->y += (i - 1) * th;
102 c->h = th - 2 * BORDERPX;
103 }
104 else /* fallback if th < bh */
105 c->h = wah - 2 * BORDERPX;
106 }
107 resize(c, False, TopLeft);
108 i++;
109 }
110 else
111 ban(c);
113 if(!sel || !isvisible(sel)) {
114 for(c = stack; c && !isvisible(c); c = c->snext);
115 focus(c);
116 }
117 restack();
118 }
120 void
121 focusnext(Arg *arg) {
122 Client *c;
124 if(!sel)
125 return;
126 if(!(c = getnext(sel->next)))
127 c = getnext(clients);
128 if(c) {
129 focus(c);
130 restack();
131 }
132 }
134 void
135 focusprev(Arg *arg) {
136 Client *c;
138 if(!sel)
139 return;
140 if(!(c = getprev(sel->prev))) {
141 for(c = clients; c && c->next; c = c->next);
142 c = getprev(c);
143 }
144 if(c) {
145 focus(c);
146 restack();
147 }
148 }
150 Bool
151 isvisible(Client *c) {
152 unsigned int i;
154 for(i = 0; i < ntags; i++)
155 if(c->tags[i] && seltag[i])
156 return True;
157 return False;
158 }
160 void
161 resizemaster(Arg *arg) {
162 if(arg->i == 0)
163 master = MASTER;
164 else {
165 if(master + arg->i > 950 || master + arg->i < 50)
166 return;
167 master += arg->i;
168 }
169 arrange();
170 }
172 void
173 restack(void) {
174 Client *c;
175 XEvent ev;
177 if(!sel) {
178 drawstatus();
179 return;
180 }
181 if(sel->isfloat || arrange == dofloat) {
182 XRaiseWindow(dpy, sel->win);
183 XRaiseWindow(dpy, sel->twin);
184 }
185 if(arrange != dofloat) {
186 if(!sel->isfloat) {
187 XLowerWindow(dpy, sel->twin);
188 XLowerWindow(dpy, sel->win);
189 }
190 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
191 if(c == sel)
192 continue;
193 XLowerWindow(dpy, c->twin);
194 XLowerWindow(dpy, c->win);
195 }
196 }
197 drawall();
198 XSync(dpy, False);
199 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
200 }
202 void
203 togglefloat(Arg *arg) {
204 if (!sel || arrange == dofloat)
205 return;
206 sel->isfloat = !sel->isfloat;
207 arrange();
208 }
210 void
211 togglemode(Arg *arg) {
212 arrange = (arrange == dofloat) ? dotile : dofloat;
213 if(sel)
214 arrange();
215 else
216 drawstatus();
217 }
219 void
220 toggleview(Arg *arg) {
221 unsigned int i;
223 seltag[arg->i] = !seltag[arg->i];
224 for(i = 0; i < ntags && !seltag[i]; i++);
225 if(i == ntags)
226 seltag[arg->i] = True; /* cannot toggle last view */
227 arrange();
228 }
230 void
231 view(Arg *arg) {
232 unsigned int i;
234 for(i = 0; i < ntags; i++)
235 seltag[i] = (arg->i == -1) ? True : False;
236 if(arg->i >= 0 && arg->i < ntags)
237 seltag[arg->i] = True;
238 arrange();
239 }
241 void
242 zoom(Arg *arg) {
243 unsigned int n;
244 Client *c;
246 if(!sel)
247 return;
248 if(sel->isfloat || (arrange == dofloat)) {
249 togglemax(sel);
250 return;
251 }
252 for(n = 0, c = clients; c; c = c->next)
253 if(isvisible(c) && !c->isfloat)
254 n++;
255 if(n < 2 || (arrange == dofloat))
256 return;
257 if((c = sel) == nexttiled(clients))
258 if(!(c = nexttiled(c->next)))
259 return;
260 detach(c);
261 if(clients)
262 clients->prev = c;
263 c->next = clients;
264 clients = c;
265 focus(c);
266 arrange();
267 }