dwm-meillo
view view.c @ 394:1da9a6b94ca9
implemented Button2 press on tags for toggletag on the focused client
author | Anselm R. Garbe <arg@10kloc.org> |
---|---|
date | Thu, 31 Aug 2006 17:49:04 +0200 |
parents | aba385c61b3b |
children | 7528080beb0e |
line source
1 /*
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
4 */
5 #include "dwm.h"
6 #include <stdio.h>
8 /* static */
10 static Client *
11 minclient()
12 {
13 Client *c, *min;
15 for(min = c = clients; c; c = c->next)
16 if(c->weight < min->weight)
17 min = c;
18 return min;
19 }
22 static void
23 reorder()
24 {
25 Client *c, *newclients, *tail;
27 newclients = tail = NULL;
28 while((c = minclient())) {
29 detach(c);
30 if(tail) {
31 c->prev = tail;
32 tail->next = c;
33 tail = c;
34 }
35 else
36 tail = newclients = c;
37 }
38 clients = newclients;
39 }
41 /* extern */
43 void (*arrange)(Arg *) = DEFMODE;
45 void
46 detach(Client *c)
47 {
48 if(c->prev)
49 c->prev->next = c->next;
50 if(c->next)
51 c->next->prev = c->prev;
52 if(c == clients)
53 clients = c->next;
54 c->next = c->prev = NULL;
55 }
57 void
58 dofloat(Arg *arg)
59 {
60 Client *c;
62 for(c = clients; c; c = c->next) {
63 c->ismax = False;
64 if(isvisible(c)) {
65 resize(c, True, TopLeft);
66 }
67 else
68 ban(c);
69 }
70 if(!sel || !isvisible(sel))
71 sel = getnext(clients);
72 if(sel)
73 focus(sel);
74 else
75 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
76 restack();
77 }
79 void
80 dotile(Arg *arg)
81 {
82 int h, i, n, w;
83 Client *c;
85 w = sw - mw;
86 for(n = 0, c = clients; c; c = c->next)
87 if(isvisible(c) && !c->isfloat)
88 n++;
90 if(n > 1)
91 h = (sh - bh) / (n - 1);
92 else
93 h = sh - bh;
95 for(i = 0, c = clients; c; c = c->next) {
96 c->ismax = False;
97 if(isvisible(c)) {
98 if(c->isfloat) {
99 resize(c, True, TopLeft);
100 continue;
101 }
102 if(n == 1) {
103 c->x = sx;
104 c->y = sy + bh;
105 c->w = sw - 2;
106 c->h = sh - 2 - bh;
107 }
108 else if(i == 0) {
109 c->x = sx;
110 c->y = sy + bh;
111 c->w = mw - 2;
112 c->h = sh - 2 - bh;
113 }
114 else if(h > bh) {
115 c->x = sx + mw;
116 c->y = sy + (i - 1) * h + bh;
117 c->w = w - 2;
118 if(i + 1 == n)
119 c->h = sh - c->y - 2;
120 else
121 c->h = h - 2;
122 }
123 else { /* fallback if h < bh */
124 c->x = sx + mw;
125 c->y = sy + bh;
126 c->w = w - 2;
127 c->h = sh - 2 - bh;
128 }
129 resize(c, False, TopLeft);
130 i++;
131 }
132 else
133 ban(c);
134 }
135 if(!sel || !isvisible(sel))
136 sel = getnext(clients);
137 if(sel)
138 focus(sel);
139 else
140 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
141 restack();
142 }
144 void
145 focusnext(Arg *arg)
146 {
147 Client *c;
149 if(!sel)
150 return;
152 if(!(c = getnext(sel->next)))
153 c = getnext(clients);
154 if(c) {
155 focus(c);
156 restack();
157 }
158 }
160 void
161 focusprev(Arg *arg)
162 {
163 Client *c;
165 if(!sel)
166 return;
168 if(!(c = getprev(sel->prev))) {
169 for(c = clients; c && c->next; c = c->next);
170 c = getprev(c);
171 }
172 if(c) {
173 focus(c);
174 restack();
175 }
176 }
178 Bool
179 isvisible(Client *c)
180 {
181 unsigned int i;
183 for(i = 0; i < ntags; i++)
184 if(c->tags[i] && seltag[i])
185 return True;
186 return False;
187 }
189 void
190 restack()
191 {
192 static unsigned int nwins = 0;
193 static Window *wins = NULL;
194 unsigned int f, fi, m, mi, n;
195 Client *c;
196 XEvent ev;
198 for(f = 0, m = 0, c = clients; c; c = c->next)
199 if(isvisible(c)) {
200 if(c->isfloat || arrange == dofloat)
201 f++;
202 else
203 m++;
204 }
205 if(!(n = 2 * (f + m))) {
206 drawstatus();
207 return;
208 }
209 if(nwins < n) {
210 nwins = n;
211 wins = erealloc(wins, nwins * sizeof(Window));
212 }
214 fi = 0;
215 mi = 2 * f;
216 if(sel->isfloat || arrange == dofloat) {
217 wins[fi++] = sel->twin;
218 wins[fi++] = sel->win;
219 }
220 else {
221 wins[mi++] = sel->twin;
222 wins[mi++] = sel->win;
223 }
224 for(c = clients; c; c = c->next)
225 if(isvisible(c) && c != sel) {
226 if(c->isfloat || arrange == dofloat) {
227 wins[fi++] = c->twin;
228 wins[fi++] = c->win;
229 }
230 else {
231 wins[mi++] = c->twin;
232 wins[mi++] = c->win;
233 }
234 }
235 XRestackWindows(dpy, wins, n);
236 drawall();
237 XSync(dpy, False);
238 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
239 }
241 void
242 togglemode(Arg *arg)
243 {
244 arrange = (arrange == dofloat) ? dotile : dofloat;
245 if(sel)
246 arrange(NULL);
247 else
248 drawstatus();
249 }
251 void
252 toggleview(Arg *arg)
253 {
254 unsigned int i;
256 seltag[arg->i] = !seltag[arg->i];
257 for(i = 0; i < ntags && !seltag[i]; i++);
258 if(i == ntags)
259 seltag[arg->i] = True; /* cannot toggle last view */
260 reorder();
261 arrange(NULL);
262 }
264 void
265 view(Arg *arg)
266 {
267 unsigned int i;
269 for(i = 0; i < ntags; i++)
270 seltag[i] = False;
271 seltag[arg->i] = True;
272 reorder();
273 arrange(NULL);
274 }
276 void
277 zoom(Arg *arg)
278 {
279 Client *c = sel;
281 if(!c || (arrange != dotile) || c->isfloat || c->ismax)
282 return;
284 if(c == getnext(clients))
285 if(!(c = getnext(c->next)))
286 return;
287 detach(c);
288 c->next = clients;
289 clients->prev = c;
290 clients = c;
291 focus(c);
292 arrange(NULL);
293 }