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@443
|
15 if((clients && clients->isfloat) || arrange == dofloat)
|
arg@443
|
16 return clients; /* don't touch floating order */
|
arg@382
|
17 for(min = c = clients; c; c = c->next)
|
arg@382
|
18 if(c->weight < min->weight)
|
arg@382
|
19 min = c;
|
arg@382
|
20 return min;
|
arg@382
|
21 }
|
arg@382
|
22
|
arg@442
|
23 static void
|
arg@381
|
24 reorder()
|
arg@380
|
25 {
|
arg@382
|
26 Client *c, *newclients, *tail;
|
arg@380
|
27
|
arg@382
|
28 newclients = tail = NULL;
|
arg@382
|
29 while((c = minclient())) {
|
arg@381
|
30 detach(c);
|
arg@382
|
31 if(tail) {
|
arg@382
|
32 c->prev = tail;
|
arg@382
|
33 tail->next = c;
|
arg@382
|
34 tail = c;
|
arg@381
|
35 }
|
arg@381
|
36 else
|
arg@382
|
37 tail = newclients = c;
|
arg@380
|
38 }
|
arg@382
|
39 clients = newclients;
|
arg@380
|
40 }
|
arg@380
|
41
|
arg@430
|
42 static Client *
|
arg@430
|
43 nexttiled(Client *c)
|
arg@430
|
44 {
|
arg@433
|
45 for(c = getnext(c); c && c->isfloat; c = getnext(c->next));
|
arg@430
|
46 return c;
|
arg@430
|
47 }
|
arg@430
|
48
|
arg@327
|
49 /* extern */
|
arg@327
|
50
|
arg@327
|
51 void (*arrange)(Arg *) = DEFMODE;
|
arg@327
|
52
|
arg@327
|
53 void
|
arg@378
|
54 detach(Client *c)
|
arg@378
|
55 {
|
arg@378
|
56 if(c->prev)
|
arg@378
|
57 c->prev->next = c->next;
|
arg@378
|
58 if(c->next)
|
arg@378
|
59 c->next->prev = c->prev;
|
arg@378
|
60 if(c == clients)
|
arg@378
|
61 clients = c->next;
|
arg@378
|
62 c->next = c->prev = NULL;
|
arg@378
|
63 }
|
arg@378
|
64
|
arg@378
|
65 void
|
arg@327
|
66 dofloat(Arg *arg)
|
arg@327
|
67 {
|
arg@402
|
68 Client *c;
|
arg@400
|
69
|
arg@400
|
70 maximized = False;
|
arg@327
|
71
|
arg@327
|
72 for(c = clients; c; c = c->next) {
|
arg@327
|
73 if(isvisible(c)) {
|
arg@327
|
74 resize(c, True, TopLeft);
|
arg@327
|
75 }
|
arg@327
|
76 else
|
arg@327
|
77 ban(c);
|
arg@327
|
78 }
|
arg@401
|
79 if(!sel || !isvisible(sel))
|
arg@401
|
80 focus(getnext(clients));
|
arg@327
|
81 restack();
|
arg@327
|
82 }
|
arg@327
|
83
|
arg@327
|
84 void
|
arg@327
|
85 dotile(Arg *arg)
|
arg@327
|
86 {
|
arg@327
|
87 int h, i, n, w;
|
arg@402
|
88 Client *c;
|
arg@400
|
89
|
arg@400
|
90 maximized = False;
|
arg@327
|
91
|
arg@327
|
92 w = sw - mw;
|
arg@430
|
93 for(n = 0, c = clients; c; c = c->next)
|
arg@430
|
94 if(isvisible(c) && !c->isfloat)
|
arg@327
|
95 n++;
|
arg@327
|
96
|
arg@327
|
97 if(n > 1)
|
arg@327
|
98 h = (sh - bh) / (n - 1);
|
arg@327
|
99 else
|
arg@327
|
100 h = sh - bh;
|
arg@327
|
101
|
arg@327
|
102 for(i = 0, c = clients; c; c = c->next) {
|
arg@327
|
103 if(isvisible(c)) {
|
arg@327
|
104 if(c->isfloat) {
|
arg@327
|
105 resize(c, True, TopLeft);
|
arg@327
|
106 continue;
|
arg@327
|
107 }
|
arg@327
|
108 if(n == 1) {
|
arg@327
|
109 c->x = sx;
|
arg@327
|
110 c->y = sy + bh;
|
arg@327
|
111 c->w = sw - 2;
|
arg@327
|
112 c->h = sh - 2 - bh;
|
arg@327
|
113 }
|
arg@327
|
114 else if(i == 0) {
|
arg@327
|
115 c->x = sx;
|
arg@327
|
116 c->y = sy + bh;
|
arg@327
|
117 c->w = mw - 2;
|
arg@327
|
118 c->h = sh - 2 - bh;
|
arg@327
|
119 }
|
arg@327
|
120 else if(h > bh) {
|
arg@327
|
121 c->x = sx + mw;
|
arg@327
|
122 c->y = sy + (i - 1) * h + bh;
|
arg@327
|
123 c->w = w - 2;
|
arg@327
|
124 if(i + 1 == n)
|
arg@327
|
125 c->h = sh - c->y - 2;
|
arg@327
|
126 else
|
arg@327
|
127 c->h = h - 2;
|
arg@327
|
128 }
|
arg@327
|
129 else { /* fallback if h < bh */
|
arg@327
|
130 c->x = sx + mw;
|
arg@327
|
131 c->y = sy + bh;
|
arg@327
|
132 c->w = w - 2;
|
arg@327
|
133 c->h = sh - 2 - bh;
|
arg@327
|
134 }
|
arg@327
|
135 resize(c, False, TopLeft);
|
arg@327
|
136 i++;
|
arg@327
|
137 }
|
arg@327
|
138 else
|
arg@327
|
139 ban(c);
|
arg@327
|
140 }
|
arg@401
|
141 if(!sel || !isvisible(sel))
|
arg@401
|
142 focus(getnext(clients));
|
arg@327
|
143 restack();
|
arg@327
|
144 }
|
arg@327
|
145
|
arg@327
|
146 void
|
arg@327
|
147 focusnext(Arg *arg)
|
arg@327
|
148 {
|
arg@327
|
149 Client *c;
|
arg@327
|
150
|
arg@327
|
151 if(!sel)
|
arg@327
|
152 return;
|
arg@327
|
153
|
arg@327
|
154 if(!(c = getnext(sel->next)))
|
arg@327
|
155 c = getnext(clients);
|
arg@327
|
156 if(c) {
|
arg@327
|
157 focus(c);
|
arg@327
|
158 restack();
|
arg@327
|
159 }
|
arg@327
|
160 }
|
arg@327
|
161
|
arg@327
|
162 void
|
arg@327
|
163 focusprev(Arg *arg)
|
arg@327
|
164 {
|
arg@327
|
165 Client *c;
|
arg@327
|
166
|
arg@327
|
167 if(!sel)
|
arg@327
|
168 return;
|
arg@327
|
169
|
arg@327
|
170 if(!(c = getprev(sel->prev))) {
|
arg@327
|
171 for(c = clients; c && c->next; c = c->next);
|
arg@327
|
172 c = getprev(c);
|
arg@327
|
173 }
|
arg@327
|
174 if(c) {
|
arg@327
|
175 focus(c);
|
arg@327
|
176 restack();
|
arg@327
|
177 }
|
arg@327
|
178 }
|
arg@327
|
179
|
arg@420
|
180 Bool
|
arg@420
|
181 isvisible(Client *c)
|
arg@420
|
182 {
|
arg@420
|
183 unsigned int i;
|
arg@420
|
184
|
arg@420
|
185 for(i = 0; i < ntags; i++)
|
arg@420
|
186 if(c->tags[i] && seltag[i])
|
arg@420
|
187 return True;
|
arg@420
|
188 return False;
|
arg@420
|
189 }
|
arg@420
|
190
|
arg@415
|
191 void
|
arg@422
|
192 resizecol(Arg *arg)
|
arg@415
|
193 {
|
arg@423
|
194 unsigned int n;
|
arg@423
|
195 Client *c;
|
arg@418
|
196
|
arg@430
|
197 for(n = 0, c = clients; c; c = c->next)
|
arg@430
|
198 if(isvisible(c) && !c->isfloat)
|
arg@423
|
199 n++;
|
arg@423
|
200 if(!sel || sel->isfloat || n < 2 || (arrange != dotile) || maximized)
|
arg@415
|
201 return;
|
arg@423
|
202
|
arg@415
|
203 if(sel == getnext(clients)) {
|
arg@425
|
204 if(mw + arg->i > sw - 100 || mw + arg->i < 100)
|
arg@415
|
205 return;
|
arg@415
|
206 mw += arg->i;
|
arg@415
|
207 }
|
arg@415
|
208 else {
|
arg@425
|
209 if(mw - arg->i > sw - 100 || mw - arg->i < 100)
|
arg@415
|
210 return;
|
arg@415
|
211 mw -= arg->i;
|
arg@415
|
212 }
|
arg@415
|
213 arrange(NULL);
|
arg@415
|
214 }
|
arg@415
|
215
|
arg@327
|
216 void
|
arg@327
|
217 restack()
|
arg@327
|
218 {
|
arg@327
|
219 Client *c;
|
arg@327
|
220 XEvent ev;
|
arg@436
|
221
|
arg@437
|
222 if(!sel) {
|
arg@437
|
223 drawstatus();
|
arg@436
|
224 return;
|
arg@437
|
225 }
|
arg@436
|
226 if(sel->isfloat || arrange == dofloat) {
|
arg@436
|
227 XRaiseWindow(dpy, sel->win);
|
arg@436
|
228 XRaiseWindow(dpy, sel->twin);
|
arg@436
|
229 }
|
arg@436
|
230 if(arrange != dofloat)
|
arg@436
|
231 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
|
arg@436
|
232 XLowerWindow(dpy, c->twin);
|
arg@436
|
233 XLowerWindow(dpy, c->win);
|
arg@327
|
234 }
|
arg@327
|
235 drawall();
|
arg@327
|
236 XSync(dpy, False);
|
arg@327
|
237 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
|
arg@327
|
238 }
|
arg@327
|
239
|
arg@327
|
240 void
|
arg@327
|
241 togglemode(Arg *arg)
|
arg@327
|
242 {
|
arg@333
|
243 arrange = (arrange == dofloat) ? dotile : dofloat;
|
arg@327
|
244 if(sel)
|
arg@327
|
245 arrange(NULL);
|
arg@327
|
246 else
|
arg@327
|
247 drawstatus();
|
arg@327
|
248 }
|
arg@327
|
249
|
arg@327
|
250 void
|
arg@327
|
251 toggleview(Arg *arg)
|
arg@327
|
252 {
|
arg@327
|
253 unsigned int i;
|
arg@327
|
254
|
arg@327
|
255 seltag[arg->i] = !seltag[arg->i];
|
arg@327
|
256 for(i = 0; i < ntags && !seltag[i]; i++);
|
arg@327
|
257 if(i == ntags)
|
arg@327
|
258 seltag[arg->i] = True; /* cannot toggle last view */
|
arg@381
|
259 reorder();
|
arg@327
|
260 arrange(NULL);
|
arg@327
|
261 }
|
arg@327
|
262
|
arg@327
|
263 void
|
arg@327
|
264 view(Arg *arg)
|
arg@327
|
265 {
|
arg@327
|
266 unsigned int i;
|
arg@327
|
267
|
arg@327
|
268 for(i = 0; i < ntags; i++)
|
arg@327
|
269 seltag[i] = False;
|
arg@327
|
270 seltag[arg->i] = True;
|
arg@381
|
271 reorder();
|
arg@327
|
272 arrange(NULL);
|
arg@327
|
273 }
|
arg@327
|
274
|
arg@327
|
275 void
|
arg@395
|
276 viewall(Arg *arg)
|
arg@395
|
277 {
|
arg@395
|
278 unsigned int i;
|
arg@395
|
279
|
arg@395
|
280 for(i = 0; i < ntags; i++)
|
arg@395
|
281 seltag[i] = True;
|
arg@397
|
282 reorder();
|
arg@395
|
283 arrange(NULL);
|
arg@395
|
284 }
|
arg@395
|
285
|
arg@395
|
286 void
|
arg@327
|
287 zoom(Arg *arg)
|
arg@327
|
288 {
|
arg@423
|
289 unsigned int n;
|
arg@423
|
290 Client *c;
|
arg@327
|
291
|
arg@430
|
292 for(n = 0, c = clients; c; c = c->next)
|
arg@430
|
293 if(isvisible(c) && !c->isfloat)
|
arg@423
|
294 n++;
|
arg@423
|
295 if(!sel || sel->isfloat || n < 2 || (arrange != dotile) || maximized)
|
arg@327
|
296 return;
|
arg@327
|
297
|
arg@430
|
298 if((c = sel) == nexttiled(clients))
|
arg@433
|
299 if(!(c = nexttiled(c->next)))
|
arg@429
|
300 return;
|
arg@443
|
301 detach(c);
|
arg@443
|
302 if(clients)
|
arg@443
|
303 clients->prev = c;
|
arg@443
|
304 c->next = clients;
|
arg@443
|
305 clients = c;
|
arg@378
|
306 focus(c);
|
arg@327
|
307 arrange(NULL);
|
arg@327
|
308 }
|