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@327
|
6
|
arg@380
|
7 /* static */
|
arg@380
|
8
|
arg@382
|
9 static Client *
|
arg@487
|
10 minclient(void) {
|
arg@382
|
11 Client *c, *min;
|
arg@382
|
12
|
arg@443
|
13 if((clients && clients->isfloat) || arrange == dofloat)
|
arg@443
|
14 return clients; /* don't touch floating order */
|
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@480
|
21 static Client *
|
arg@480
|
22 nexttiled(Client *c) {
|
arg@480
|
23 for(c = getnext(c); c && c->isfloat; c = getnext(c->next));
|
arg@480
|
24 return c;
|
arg@480
|
25 }
|
arg@480
|
26
|
arg@442
|
27 static void
|
arg@487
|
28 reorder(void) {
|
arg@382
|
29 Client *c, *newclients, *tail;
|
arg@380
|
30
|
arg@382
|
31 newclients = tail = NULL;
|
arg@382
|
32 while((c = minclient())) {
|
arg@381
|
33 detach(c);
|
arg@382
|
34 if(tail) {
|
arg@382
|
35 c->prev = tail;
|
arg@382
|
36 tail->next = c;
|
arg@382
|
37 tail = c;
|
arg@381
|
38 }
|
arg@381
|
39 else
|
arg@382
|
40 tail = newclients = c;
|
arg@380
|
41 }
|
arg@382
|
42 clients = newclients;
|
arg@380
|
43 }
|
arg@380
|
44
|
arg@480
|
45 static void
|
arg@480
|
46 togglemax(Client *c)
|
arg@480
|
47 {
|
arg@481
|
48 XEvent ev;
|
arg@480
|
49 if((c->ismax = !c->ismax)) {
|
arg@480
|
50 c->rx = c->x; c->x = sx;
|
arg@480
|
51 c->ry = c->y; c->y = bh;
|
arg@502
|
52 c->rw = c->w; c->w = sw - 2 * BORDERPX;
|
arg@502
|
53 c->rh = c->h; c->h = sh - bh - 2 * BORDERPX;
|
arg@480
|
54 }
|
arg@480
|
55 else {
|
arg@480
|
56 c->x = c->rx;
|
arg@480
|
57 c->y = c->ry;
|
arg@481
|
58 c->w = c->rw;
|
arg@481
|
59 c->h = c->rh;
|
arg@480
|
60 }
|
arg@480
|
61 resize(c, True, TopLeft);
|
arg@480
|
62 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
|
arg@430
|
63 }
|
arg@430
|
64
|
arg@327
|
65 /* extern */
|
arg@327
|
66
|
arg@327
|
67 void (*arrange)(Arg *) = DEFMODE;
|
arg@327
|
68
|
arg@327
|
69 void
|
arg@461
|
70 detach(Client *c) {
|
arg@378
|
71 if(c->prev)
|
arg@378
|
72 c->prev->next = c->next;
|
arg@378
|
73 if(c->next)
|
arg@378
|
74 c->next->prev = c->prev;
|
arg@378
|
75 if(c == clients)
|
arg@378
|
76 clients = c->next;
|
arg@378
|
77 c->next = c->prev = NULL;
|
arg@378
|
78 }
|
arg@378
|
79
|
arg@378
|
80 void
|
arg@461
|
81 dofloat(Arg *arg) {
|
arg@402
|
82 Client *c;
|
arg@400
|
83
|
arg@327
|
84 for(c = clients; c; c = c->next) {
|
arg@327
|
85 if(isvisible(c)) {
|
arg@327
|
86 resize(c, True, TopLeft);
|
arg@327
|
87 }
|
arg@327
|
88 else
|
arg@327
|
89 ban(c);
|
arg@327
|
90 }
|
arg@446
|
91 if(!sel || !isvisible(sel)) {
|
arg@450
|
92 for(c = stack; c && !isvisible(c); c = c->snext);
|
arg@450
|
93 focus(c);
|
arg@446
|
94 }
|
arg@327
|
95 restack();
|
arg@327
|
96 }
|
arg@327
|
97
|
arg@504
|
98 /* This algorithm is based on a (M)aster area and a (S)tacking area.
|
arg@504
|
99 * It supports following arrangements:
|
arg@507
|
100 * SSMMM MMMMM MMMSS
|
arg@507
|
101 * SSMMM SSSSS MMMSS
|
arg@504
|
102 */
|
arg@327
|
103 void
|
arg@461
|
104 dotile(Arg *arg) {
|
arg@530
|
105 unsigned int i, n, md, stackw, stackh, th;
|
arg@402
|
106 Client *c;
|
arg@400
|
107
|
arg@488
|
108 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
|
arg@488
|
109 n++;
|
arg@327
|
110
|
arg@530
|
111 md = (sw * master) / 1000;
|
arg@530
|
112 stackw = sw - md;
|
arg@530
|
113 stackh = sh - bh;
|
arg@507
|
114
|
arg@530
|
115 th = stackh;
|
arg@511
|
116 if(n > 1)
|
arg@530
|
117 th /= (n - 1);
|
arg@327
|
118
|
arg@327
|
119 for(i = 0, c = clients; c; c = c->next) {
|
arg@327
|
120 if(isvisible(c)) {
|
arg@327
|
121 if(c->isfloat) {
|
arg@327
|
122 resize(c, True, TopLeft);
|
arg@327
|
123 continue;
|
arg@327
|
124 }
|
arg@488
|
125 c->ismax = False;
|
arg@523
|
126 c->x = sx;
|
arg@523
|
127 c->y = sy + bh;
|
arg@507
|
128 if(n == 1) { /* only 1 window */
|
arg@502
|
129 c->w = sw - 2 * BORDERPX;
|
arg@502
|
130 c->h = sh - 2 * BORDERPX - bh;
|
arg@327
|
131 }
|
arg@507
|
132 else if(i == 0) { /* master window */
|
arg@530
|
133 c->w = md - 2 * BORDERPX;
|
arg@530
|
134 c->h = sh - bh - 2 * BORDERPX;
|
arg@507
|
135 }
|
arg@523
|
136 else { /* tile window */
|
arg@530
|
137 c->x += md;
|
arg@523
|
138 if(th > bh) {
|
arg@530
|
139 c->y = sy + (i - 1) * th + bh;
|
arg@530
|
140 if(i + 1 == n)
|
arg@530
|
141 c->h = sh - c->y - 2 * BORDERPX;
|
arg@530
|
142 c->w = stackw - 2 * BORDERPX;
|
arg@523
|
143 c->h = th - 2 * BORDERPX;
|
arg@507
|
144 }
|
arg@523
|
145 else { /* fallback if th < bh */
|
arg@523
|
146 c->w = stackw - 2 * BORDERPX;
|
arg@523
|
147 c->h = stackh - 2 * BORDERPX;
|
arg@523
|
148 }
|
arg@327
|
149 }
|
arg@327
|
150 resize(c, False, TopLeft);
|
arg@327
|
151 i++;
|
arg@327
|
152 }
|
arg@327
|
153 else
|
arg@327
|
154 ban(c);
|
arg@327
|
155 }
|
arg@446
|
156 if(!sel || !isvisible(sel)) {
|
arg@450
|
157 for(c = stack; c && !isvisible(c); c = c->snext);
|
arg@450
|
158 focus(c);
|
arg@446
|
159 }
|
arg@327
|
160 restack();
|
arg@327
|
161 }
|
arg@327
|
162
|
arg@327
|
163 void
|
arg@461
|
164 focusnext(Arg *arg) {
|
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 = getnext(sel->next)))
|
arg@327
|
171 c = getnext(clients);
|
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 void
|
arg@461
|
179 focusprev(Arg *arg) {
|
arg@327
|
180 Client *c;
|
arg@327
|
181
|
arg@327
|
182 if(!sel)
|
arg@327
|
183 return;
|
arg@327
|
184
|
arg@327
|
185 if(!(c = getprev(sel->prev))) {
|
arg@327
|
186 for(c = clients; c && c->next; c = c->next);
|
arg@327
|
187 c = getprev(c);
|
arg@327
|
188 }
|
arg@327
|
189 if(c) {
|
arg@327
|
190 focus(c);
|
arg@327
|
191 restack();
|
arg@327
|
192 }
|
arg@327
|
193 }
|
arg@327
|
194
|
arg@420
|
195 Bool
|
arg@461
|
196 isvisible(Client *c) {
|
arg@420
|
197 unsigned int i;
|
arg@420
|
198
|
arg@420
|
199 for(i = 0; i < ntags; i++)
|
arg@420
|
200 if(c->tags[i] && seltag[i])
|
arg@420
|
201 return True;
|
arg@420
|
202 return False;
|
arg@420
|
203 }
|
arg@420
|
204
|
arg@415
|
205 void
|
arg@461
|
206 resizecol(Arg *arg) {
|
arg@423
|
207 unsigned int n;
|
arg@423
|
208 Client *c;
|
arg@418
|
209
|
arg@430
|
210 for(n = 0, c = clients; c; c = c->next)
|
arg@430
|
211 if(isvisible(c) && !c->isfloat)
|
arg@423
|
212 n++;
|
arg@486
|
213 if(!sel || sel->isfloat || n < 2 || (arrange == dofloat))
|
arg@415
|
214 return;
|
arg@423
|
215
|
arg@415
|
216 if(sel == getnext(clients)) {
|
arg@529
|
217 if(master + arg->i > 950 || master + arg->i < 50)
|
arg@415
|
218 return;
|
arg@505
|
219 master += arg->i;
|
arg@415
|
220 }
|
arg@415
|
221 else {
|
arg@529
|
222 if(master - arg->i > 950 || master - arg->i < 50)
|
arg@415
|
223 return;
|
arg@505
|
224 master -= arg->i;
|
arg@415
|
225 }
|
arg@415
|
226 arrange(NULL);
|
arg@415
|
227 }
|
arg@415
|
228
|
arg@327
|
229 void
|
arg@487
|
230 restack(void) {
|
arg@327
|
231 Client *c;
|
arg@327
|
232 XEvent ev;
|
arg@481
|
233
|
arg@437
|
234 if(!sel) {
|
arg@437
|
235 drawstatus();
|
arg@436
|
236 return;
|
arg@437
|
237 }
|
arg@436
|
238 if(sel->isfloat || arrange == dofloat) {
|
arg@436
|
239 XRaiseWindow(dpy, sel->win);
|
arg@436
|
240 XRaiseWindow(dpy, sel->twin);
|
arg@436
|
241 }
|
arg@512
|
242 if(arrange != dofloat) {
|
arg@512
|
243 if(!sel->isfloat) {
|
arg@512
|
244 XLowerWindow(dpy, sel->twin);
|
arg@512
|
245 XLowerWindow(dpy, sel->win);
|
arg@512
|
246 }
|
arg@436
|
247 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
|
arg@512
|
248 if(c == sel)
|
arg@512
|
249 continue;
|
arg@436
|
250 XLowerWindow(dpy, c->twin);
|
arg@436
|
251 XLowerWindow(dpy, c->win);
|
arg@327
|
252 }
|
arg@512
|
253 }
|
arg@327
|
254 drawall();
|
arg@327
|
255 XSync(dpy, False);
|
arg@327
|
256 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
|
arg@327
|
257 }
|
arg@327
|
258
|
arg@327
|
259 void
|
arg@461
|
260 togglemode(Arg *arg) {
|
arg@333
|
261 arrange = (arrange == dofloat) ? dotile : dofloat;
|
arg@327
|
262 if(sel)
|
arg@327
|
263 arrange(NULL);
|
arg@327
|
264 else
|
arg@327
|
265 drawstatus();
|
arg@327
|
266 }
|
arg@327
|
267
|
arg@327
|
268 void
|
arg@461
|
269 toggleview(Arg *arg) {
|
arg@327
|
270 unsigned int i;
|
arg@327
|
271
|
arg@327
|
272 seltag[arg->i] = !seltag[arg->i];
|
arg@327
|
273 for(i = 0; i < ntags && !seltag[i]; i++);
|
arg@327
|
274 if(i == ntags)
|
arg@327
|
275 seltag[arg->i] = True; /* cannot toggle last view */
|
arg@381
|
276 reorder();
|
arg@327
|
277 arrange(NULL);
|
arg@327
|
278 }
|
arg@327
|
279
|
arg@327
|
280 void
|
arg@461
|
281 view(Arg *arg) {
|
arg@327
|
282 unsigned int i;
|
arg@327
|
283
|
arg@327
|
284 for(i = 0; i < ntags; i++)
|
arg@327
|
285 seltag[i] = False;
|
arg@327
|
286 seltag[arg->i] = True;
|
arg@381
|
287 reorder();
|
arg@327
|
288 arrange(NULL);
|
arg@327
|
289 }
|
arg@327
|
290
|
arg@327
|
291 void
|
arg@461
|
292 viewall(Arg *arg) {
|
arg@395
|
293 unsigned int i;
|
arg@395
|
294
|
arg@395
|
295 for(i = 0; i < ntags; i++)
|
arg@395
|
296 seltag[i] = True;
|
arg@397
|
297 reorder();
|
arg@395
|
298 arrange(NULL);
|
arg@395
|
299 }
|
arg@395
|
300
|
arg@508
|
301
|
arg@508
|
302
|
arg@395
|
303 void
|
arg@461
|
304 zoom(Arg *arg) {
|
arg@423
|
305 unsigned int n;
|
arg@423
|
306 Client *c;
|
arg@473
|
307
|
arg@473
|
308 if(!sel)
|
arg@473
|
309 return;
|
arg@473
|
310
|
arg@473
|
311 if(sel->isfloat || (arrange == dofloat)) {
|
arg@480
|
312 togglemax(sel);
|
arg@473
|
313 return;
|
arg@473
|
314 }
|
arg@327
|
315
|
arg@430
|
316 for(n = 0, c = clients; c; c = c->next)
|
arg@430
|
317 if(isvisible(c) && !c->isfloat)
|
arg@423
|
318 n++;
|
arg@486
|
319 if(n < 2 || (arrange == dofloat))
|
arg@327
|
320 return;
|
arg@327
|
321
|
arg@430
|
322 if((c = sel) == nexttiled(clients))
|
arg@433
|
323 if(!(c = nexttiled(c->next)))
|
arg@429
|
324 return;
|
arg@443
|
325 detach(c);
|
arg@443
|
326 if(clients)
|
arg@443
|
327 clients->prev = c;
|
arg@443
|
328 c->next = clients;
|
arg@443
|
329 clients = c;
|
arg@378
|
330 focus(c);
|
arg@327
|
331 arrange(NULL);
|
arg@327
|
332 }
|