aewl
view view.c @ 576:8d7dbd11dc05
Added tag 2.3 for changeset 719b37b37b0df829d7cf017ac70e353088fe5849
author | arg@mig29 |
---|---|
date | Fri, 24 Nov 2006 15:46:32 +0100 |
parents | fe766305eed1 |
children | 37281ebc1b5b |
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 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, mpx, stackw, th;
73 Client *c;
75 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
76 n++;
77 mpx = (waw * master) / 1000;
78 stackw = waw - mpx;
80 for(i = 0, c = clients; c; c = c->next)
81 if(isvisible(c)) {
82 if(c->isfloat) {
83 resize(c, True, TopLeft);
84 continue;
85 }
86 c->ismax = False;
87 c->x = wax;
88 c->y = way;
89 if(n == 1) { /* only 1 window */
90 c->w = waw - 2 * BORDERPX;
91 c->h = wah - 2 * BORDERPX;
92 }
93 else if(i == 0) { /* master window */
94 c->w = waw - stackw - 2 * BORDERPX;
95 c->h = wah - 2 * BORDERPX;
96 th = wah / (n - 1);
97 }
98 else { /* tile window */
99 c->x += mpx;
100 c->w = stackw - 2 * BORDERPX;
101 if(th > bh) {
102 c->y = way + (i - 1) * th;
103 c->h = th - 2 * BORDERPX;
104 }
105 else /* fallback if th < bh */
106 c->h = wah - 2 * BORDERPX;
107 }
108 resize(c, False, TopLeft);
109 i++;
110 }
111 else
112 ban(c);
114 if(!sel || !isvisible(sel)) {
115 for(c = stack; c && !isvisible(c); c = c->snext);
116 focus(c);
117 }
118 restack();
119 }
121 void
122 focusnext(Arg *arg) {
123 Client *c;
125 if(!sel)
126 return;
127 if(!(c = getnext(sel->next)))
128 c = getnext(clients);
129 if(c) {
130 focus(c);
131 restack();
132 }
133 }
135 void
136 focusprev(Arg *arg) {
137 Client *c;
139 if(!sel)
140 return;
141 if(!(c = getprev(sel->prev))) {
142 for(c = clients; c && c->next; c = c->next);
143 c = getprev(c);
144 }
145 if(c) {
146 focus(c);
147 restack();
148 }
149 }
151 Bool
152 isvisible(Client *c) {
153 unsigned int i;
155 for(i = 0; i < ntags; i++)
156 if(c->tags[i] && seltag[i])
157 return True;
158 return False;
159 }
161 void
162 resizemaster(Arg *arg) {
163 if(arg->i == 0)
164 master = MASTER;
165 else {
166 if(master + arg->i > 950 || master + arg->i < 50)
167 return;
168 master += arg->i;
169 }
170 arrange();
171 }
173 void
174 restack(void) {
175 Client *c;
176 XEvent ev;
178 if(!sel) {
179 drawstatus();
180 return;
181 }
182 if(sel->isfloat || arrange == dofloat) {
183 XRaiseWindow(dpy, sel->win);
184 XRaiseWindow(dpy, sel->twin);
185 }
186 if(arrange != dofloat) {
187 if(!sel->isfloat) {
188 XLowerWindow(dpy, sel->twin);
189 XLowerWindow(dpy, sel->win);
190 }
191 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
192 if(c == sel)
193 continue;
194 XLowerWindow(dpy, c->twin);
195 XLowerWindow(dpy, c->win);
196 }
197 }
198 drawall();
199 XSync(dpy, False);
200 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
201 }
203 void
204 togglemode(Arg *arg) {
205 arrange = (arrange == dofloat) ? dotile : dofloat;
206 if(sel)
207 arrange();
208 else
209 drawstatus();
210 }
212 void
213 toggleview(Arg *arg) {
214 unsigned int i;
216 seltag[arg->i] = !seltag[arg->i];
217 for(i = 0; i < ntags && !seltag[i]; i++);
218 if(i == ntags)
219 seltag[arg->i] = True; /* cannot toggle last view */
220 arrange();
221 }
223 void
224 view(Arg *arg) {
225 unsigned int i;
227 for(i = 0; i < ntags; i++)
228 seltag[i] = False;
229 seltag[arg->i] = True;
230 arrange();
231 }
233 void
234 viewall(Arg *arg) {
235 unsigned int i;
237 for(i = 0; i < ntags; i++)
238 seltag[i] = True;
239 arrange();
240 }
242 void
243 zoom(Arg *arg) {
244 unsigned int n;
245 Client *c;
247 if(!sel)
248 return;
249 if(sel->isfloat || (arrange == dofloat)) {
250 togglemax(sel);
251 return;
252 }
253 for(n = 0, c = clients; c; c = c->next)
254 if(isvisible(c) && !c->isfloat)
255 n++;
256 if(n < 2 || (arrange == dofloat))
257 return;
258 if((c = sel) == nexttiled(clients))
259 if(!(c = nexttiled(c->next)))
260 return;
261 detach(c);
262 if(clients)
263 clients->prev = c;
264 c->next = clients;
265 clients = c;
266 focus(c);
267 arrange();
268 }