dwm-meillo
view view.c @ 610:29f7d5cc996c
Added tag 2.5 for changeset dcbbfabc8ecc5f33a6cc950584de87da1a368045
author | arg@mig29 |
---|---|
date | Mon, 04 Dec 2006 15:39:43 +0100 |
parents | d9e9df9fdce6 |
children | c7f84f23ec5a |
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 = mpx - 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 += (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 togglefloat(Arg *arg) {
205 if (!sel || arrange == dofloat)
206 return;
207 sel->isfloat = !sel->isfloat;
208 arrange();
209 }
211 void
212 togglemode(Arg *arg) {
213 arrange = (arrange == dofloat) ? dotile : dofloat;
214 if(sel)
215 arrange();
216 else
217 drawstatus();
218 }
220 void
221 toggleview(Arg *arg) {
222 unsigned int i;
224 seltag[arg->i] = !seltag[arg->i];
225 for(i = 0; i < ntags && !seltag[i]; i++);
226 if(i == ntags)
227 seltag[arg->i] = True; /* cannot toggle last view */
228 arrange();
229 }
231 void
232 view(Arg *arg) {
233 unsigned int i;
235 for(i = 0; i < ntags; i++)
236 seltag[i] = (arg->i == -1) ? True : False;
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 }