dwm-meillo
view view.c @ 674:5d79c351e30a
implemented nmaster appearance in mode label (using %u)
author | Anselm R. Garbe <arg@suckless.org> |
---|---|
date | Mon, 08 Jan 2007 17:33:24 +0100 |
parents | 3e0f11a44293 |
children | 1438e35b622e |
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, TopLeft);
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, TopLeft);
60 }
61 else
62 ban(c);
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 mw = (n > nmaster) ? (waw * master) / 1000 : waw;
80 mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
81 tw = waw - mw;
82 th = (n > nmaster) ? wah / (n - nmaster) : 0;
84 for(i = 0, c = clients; c; c = c->next)
85 if(isvisible(c)) {
86 if(c->isfloat) {
87 resize(c, True, TopLeft);
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 > bh) {
102 c->y += (i - nmaster) * 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 void
152 incnmaster(Arg *arg) {
153 if((arrange == dofloat) || (nmaster + arg->i < 1) || (wah / (nmaster + arg->i) < bh))
154 return;
155 nmaster += arg->i;
156 snprintf(mtext, sizeof mtext, arrange == dofloat ? FLOATSYMBOL : TILESYMBOL, nmaster);
157 bmw = textw(mtext);
158 if(sel)
159 arrange();
160 else
161 drawstatus();
162 }
164 Bool
165 isvisible(Client *c) {
166 unsigned int i;
168 for(i = 0; i < ntags; i++)
169 if(c->tags[i] && seltag[i])
170 return True;
171 return False;
172 }
174 void
175 resizemaster(Arg *arg) {
176 if(arg->i == 0)
177 master = MASTER;
178 else {
179 if(master + arg->i > 950 || master + arg->i < 50)
180 return;
181 master += arg->i;
182 }
183 arrange();
184 }
186 void
187 restack(void) {
188 Client *c;
189 XEvent ev;
191 if(!sel) {
192 drawstatus();
193 return;
194 }
195 if(sel->isfloat || arrange == dofloat) {
196 XRaiseWindow(dpy, sel->win);
197 XRaiseWindow(dpy, sel->twin);
198 }
199 if(arrange != dofloat) {
200 if(!sel->isfloat) {
201 XLowerWindow(dpy, sel->twin);
202 XLowerWindow(dpy, sel->win);
203 }
204 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
205 if(c == sel)
206 continue;
207 XLowerWindow(dpy, c->twin);
208 XLowerWindow(dpy, c->win);
209 }
210 }
211 drawall();
212 XSync(dpy, False);
213 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
214 }
216 void
217 togglefloat(Arg *arg) {
218 if (!sel || arrange == dofloat)
219 return;
220 sel->isfloat = !sel->isfloat;
221 arrange();
222 }
224 void
225 togglemode(Arg *arg) {
226 arrange = (arrange == dofloat) ? dotile : dofloat;
227 snprintf(mtext, sizeof mtext, arrange == dofloat ? FLOATSYMBOL : TILESYMBOL, nmaster);
228 bmw = textw(mtext);
229 if(sel)
230 arrange();
231 else
232 drawstatus();
233 }
235 void
236 toggleview(Arg *arg) {
237 unsigned int i;
239 seltag[arg->i] = !seltag[arg->i];
240 for(i = 0; i < ntags && !seltag[i]; i++);
241 if(i == ntags)
242 seltag[arg->i] = True; /* cannot toggle last view */
243 arrange();
244 }
246 void
247 view(Arg *arg) {
248 unsigned int i;
250 for(i = 0; i < ntags; i++)
251 seltag[i] = (arg->i == -1) ? True : False;
252 if(arg->i >= 0 && arg->i < ntags)
253 seltag[arg->i] = True;
254 arrange();
255 }
257 void
258 zoom(Arg *arg) {
259 unsigned int n;
260 Client *c;
262 if(!sel)
263 return;
264 if(sel->isfloat || (arrange == dofloat)) {
265 togglemax(sel);
266 return;
267 }
268 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
269 n++;
271 if((c = sel) == nexttiled(clients))
272 if(!(c = nexttiled(c->next)))
273 return;
274 detach(c);
275 if(clients)
276 clients->prev = c;
277 c->next = clients;
278 clients = c;
279 focus(c);
280 arrange();
281 }