dwm-meillo

view view.c @ 572:427708bf5f36

added a similiar patch to Daves solution to indicate if there are clients with a specific tag
author arg@mig29
date Wed, 22 Nov 2006 14:57:09 +0100
parents b5435d3fb7b0
children 797e27162b43
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 minclient(void) {
10 Client *c, *min;
12 if((clients && clients->isfloat) || arrange == dofloat)
13 return clients; /* don't touch floating order */
14 for(min = c = clients; c; c = c->next)
15 if(c->weight < min->weight)
16 min = c;
17 return min;
18 }
20 static Client *
21 nexttiled(Client *c) {
22 for(c = getnext(c); c && c->isfloat; c = getnext(c->next));
23 return c;
24 }
26 static void
27 reorder(void) {
28 Client *c, *newclients, *tail;
30 newclients = tail = NULL;
31 while((c = minclient())) {
32 detach(c);
33 if(tail) {
34 c->prev = tail;
35 tail->next = c;
36 tail = c;
37 }
38 else
39 tail = newclients = c;
40 }
41 clients = newclients;
42 }
44 static void
45 togglemax(Client *c) {
46 XEvent ev;
48 if(c->isfixed)
49 return;
51 if((c->ismax = !c->ismax)) {
52 c->rx = c->x; c->x = wax;
53 c->ry = c->y; c->y = way;
54 c->rw = c->w; c->w = waw - 2 * BORDERPX;
55 c->rh = c->h; c->h = wah - 2 * BORDERPX;
56 }
57 else {
58 c->x = c->rx;
59 c->y = c->ry;
60 c->w = c->rw;
61 c->h = c->rh;
62 }
63 resize(c, True, TopLeft);
64 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
65 }
67 /* extern */
69 void (*arrange)(void) = DEFMODE;
71 void
72 detach(Client *c) {
73 if(c->prev)
74 c->prev->next = c->next;
75 if(c->next)
76 c->next->prev = c->prev;
77 if(c == clients)
78 clients = c->next;
79 c->next = c->prev = NULL;
80 }
82 void
83 dofloat(void) {
84 Client *c;
86 for(c = clients; c; c = c->next) {
87 if(isvisible(c)) {
88 resize(c, True, TopLeft);
89 }
90 else
91 ban(c);
92 }
93 if(!sel || !isvisible(sel)) {
94 for(c = stack; c && !isvisible(c); c = c->snext);
95 focus(c);
96 }
97 restack();
98 }
100 void
101 dotile(void) {
102 unsigned int i, n, mpx, stackw, th;
103 Client *c;
105 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
106 n++;
107 mpx = (waw * master) / 1000;
108 stackw = waw - mpx;
110 for(i = 0, c = clients; c; c = c->next)
111 if(isvisible(c)) {
112 if(c->isfloat) {
113 resize(c, True, TopLeft);
114 continue;
115 }
116 c->ismax = False;
117 c->x = wax;
118 c->y = way;
119 if(n == 1) { /* only 1 window */
120 c->w = waw - 2 * BORDERPX;
121 c->h = wah - 2 * BORDERPX;
122 }
123 else if(i == 0) { /* master window */
124 c->w = waw - stackw - 2 * BORDERPX;
125 c->h = wah - 2 * BORDERPX;
126 th = wah / (n - 1);
127 }
128 else { /* tile window */
129 c->x += mpx;
130 c->w = stackw - 2 * BORDERPX;
131 if(th > bh) {
132 c->y = way + (i - 1) * th;
133 c->h = th - 2 * BORDERPX;
134 }
135 else /* fallback if th < bh */
136 c->h = wah - 2 * BORDERPX;
137 }
138 resize(c, False, TopLeft);
139 i++;
140 }
141 else
142 ban(c);
144 if(!sel || !isvisible(sel)) {
145 for(c = stack; c && !isvisible(c); c = c->snext);
146 focus(c);
147 }
148 restack();
149 }
151 void
152 focusnext(Arg *arg) {
153 Client *c;
155 if(!sel)
156 return;
157 if(!(c = getnext(sel->next)))
158 c = getnext(clients);
159 if(c) {
160 focus(c);
161 restack();
162 }
163 }
165 void
166 focusprev(Arg *arg) {
167 Client *c;
169 if(!sel)
170 return;
171 if(!(c = getprev(sel->prev))) {
172 for(c = clients; c && c->next; c = c->next);
173 c = getprev(c);
174 }
175 if(c) {
176 focus(c);
177 restack();
178 }
179 }
181 Bool
182 isvisible(Client *c) {
183 unsigned int i;
185 for(i = 0; i < ntags; i++)
186 if(c->tags[i] && seltag[i])
187 return True;
188 return False;
189 }
191 void
192 resizemaster(Arg *arg) {
193 if(arg->i == 0)
194 master = MASTER;
195 else {
196 if(master + arg->i > 950 || master + arg->i < 50)
197 return;
198 master += arg->i;
199 }
200 arrange();
201 }
203 void
204 restack(void) {
205 Client *c;
206 XEvent ev;
208 if(!sel) {
209 drawstatus();
210 return;
211 }
212 if(sel->isfloat || arrange == dofloat) {
213 XRaiseWindow(dpy, sel->win);
214 XRaiseWindow(dpy, sel->twin);
215 }
216 if(arrange != dofloat) {
217 if(!sel->isfloat) {
218 XLowerWindow(dpy, sel->twin);
219 XLowerWindow(dpy, sel->win);
220 }
221 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
222 if(c == sel)
223 continue;
224 XLowerWindow(dpy, c->twin);
225 XLowerWindow(dpy, c->win);
226 }
227 }
228 drawall();
229 XSync(dpy, False);
230 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
231 }
233 void
234 togglemode(Arg *arg) {
235 arrange = (arrange == dofloat) ? dotile : dofloat;
236 if(sel)
237 arrange();
238 else
239 drawstatus();
240 }
242 void
243 toggleview(Arg *arg) {
244 unsigned int i;
246 seltag[arg->i] = !seltag[arg->i];
247 for(i = 0; i < ntags && !seltag[i]; i++);
248 if(i == ntags)
249 seltag[arg->i] = True; /* cannot toggle last view */
250 reorder();
251 arrange();
252 }
254 void
255 view(Arg *arg) {
256 unsigned int i;
258 for(i = 0; i < ntags; i++)
259 seltag[i] = False;
260 seltag[arg->i] = True;
261 reorder();
262 arrange();
263 }
265 void
266 viewall(Arg *arg) {
267 unsigned int i;
269 for(i = 0; i < ntags; i++)
270 seltag[i] = True;
271 reorder();
272 arrange();
273 }
275 void
276 zoom(Arg *arg) {
277 unsigned int n;
278 Client *c;
280 if(!sel)
281 return;
282 if(sel->isfloat || (arrange == dofloat)) {
283 togglemax(sel);
284 return;
285 }
286 for(n = 0, c = clients; c; c = c->next)
287 if(isvisible(c) && !c->isfloat)
288 n++;
289 if(n < 2 || (arrange == dofloat))
290 return;
291 if((c = sel) == nexttiled(clients))
292 if(!(c = nexttiled(c->next)))
293 return;
294 detach(c);
295 if(clients)
296 clients->prev = c;
297 c->next = clients;
298 clients = c;
299 focus(c);
300 arrange();
301 }