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