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@504
|
100 *
|
arg@504
|
101 * MMMS MMMM
|
arg@504
|
102 * MMMS MMMM
|
arg@504
|
103 * MMMS SSSS
|
arg@504
|
104 *
|
arg@504
|
105 * The stacking area can be set to arrange clients vertically or horizontally.
|
arg@504
|
106 * Through inverting the algorithm it can be used to achieve following setup in
|
arg@504
|
107 * a dual head environment (due to running two dwm instances concurrently on
|
arg@504
|
108 * the specific screen):
|
arg@504
|
109 *
|
arg@504
|
110 * SMM MMS MMM MMM
|
arg@504
|
111 * SMM MMS MMM MMM
|
arg@504
|
112 * SMM MMS SSS SSS
|
arg@504
|
113 *
|
arg@504
|
114 * This uses the center of the two screens for master areas.
|
arg@504
|
115 */
|
arg@327
|
116 void
|
arg@461
|
117 dotile(Arg *arg) {
|
arg@327
|
118 int h, i, n, w;
|
arg@402
|
119 Client *c;
|
arg@400
|
120
|
arg@327
|
121 w = sw - mw;
|
arg@488
|
122 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
|
arg@488
|
123 n++;
|
arg@327
|
124
|
arg@327
|
125 if(n > 1)
|
arg@327
|
126 h = (sh - bh) / (n - 1);
|
arg@327
|
127 else
|
arg@327
|
128 h = sh - bh;
|
arg@327
|
129
|
arg@327
|
130 for(i = 0, c = clients; c; c = c->next) {
|
arg@327
|
131 if(isvisible(c)) {
|
arg@327
|
132 if(c->isfloat) {
|
arg@327
|
133 resize(c, True, TopLeft);
|
arg@327
|
134 continue;
|
arg@327
|
135 }
|
arg@488
|
136 c->ismax = False;
|
arg@327
|
137 if(n == 1) {
|
arg@327
|
138 c->x = sx;
|
arg@327
|
139 c->y = sy + bh;
|
arg@502
|
140 c->w = sw - 2 * BORDERPX;
|
arg@502
|
141 c->h = sh - 2 * BORDERPX - bh;
|
arg@327
|
142 }
|
arg@327
|
143 else if(i == 0) {
|
arg@327
|
144 c->x = sx;
|
arg@327
|
145 c->y = sy + bh;
|
arg@502
|
146 c->w = mw - 2 * BORDERPX;
|
arg@502
|
147 c->h = sh - 2 * BORDERPX - bh;
|
arg@327
|
148 }
|
arg@327
|
149 else if(h > bh) {
|
arg@327
|
150 c->x = sx + mw;
|
arg@327
|
151 c->y = sy + (i - 1) * h + bh;
|
arg@502
|
152 c->w = w - 2 * BORDERPX;
|
arg@327
|
153 if(i + 1 == n)
|
arg@502
|
154 c->h = sh - c->y - 2 * BORDERPX;
|
arg@327
|
155 else
|
arg@502
|
156 c->h = h - 2 * BORDERPX;
|
arg@327
|
157 }
|
arg@327
|
158 else { /* fallback if h < bh */
|
arg@327
|
159 c->x = sx + mw;
|
arg@327
|
160 c->y = sy + bh;
|
arg@502
|
161 c->w = w - 2 * BORDERPX;
|
arg@502
|
162 c->h = sh - 2 * BORDERPX - bh;
|
arg@327
|
163 }
|
arg@327
|
164 resize(c, False, TopLeft);
|
arg@327
|
165 i++;
|
arg@327
|
166 }
|
arg@327
|
167 else
|
arg@327
|
168 ban(c);
|
arg@327
|
169 }
|
arg@446
|
170 if(!sel || !isvisible(sel)) {
|
arg@450
|
171 for(c = stack; c && !isvisible(c); c = c->snext);
|
arg@450
|
172 focus(c);
|
arg@446
|
173 }
|
arg@327
|
174 restack();
|
arg@327
|
175 }
|
arg@327
|
176
|
arg@327
|
177 void
|
arg@461
|
178 focusnext(Arg *arg) {
|
arg@327
|
179 Client *c;
|
arg@327
|
180
|
arg@327
|
181 if(!sel)
|
arg@327
|
182 return;
|
arg@327
|
183
|
arg@327
|
184 if(!(c = getnext(sel->next)))
|
arg@327
|
185 c = getnext(clients);
|
arg@327
|
186 if(c) {
|
arg@327
|
187 focus(c);
|
arg@327
|
188 restack();
|
arg@327
|
189 }
|
arg@327
|
190 }
|
arg@327
|
191
|
arg@327
|
192 void
|
arg@461
|
193 focusprev(Arg *arg) {
|
arg@327
|
194 Client *c;
|
arg@327
|
195
|
arg@327
|
196 if(!sel)
|
arg@327
|
197 return;
|
arg@327
|
198
|
arg@327
|
199 if(!(c = getprev(sel->prev))) {
|
arg@327
|
200 for(c = clients; c && c->next; c = c->next);
|
arg@327
|
201 c = getprev(c);
|
arg@327
|
202 }
|
arg@327
|
203 if(c) {
|
arg@327
|
204 focus(c);
|
arg@327
|
205 restack();
|
arg@327
|
206 }
|
arg@327
|
207 }
|
arg@327
|
208
|
arg@420
|
209 Bool
|
arg@461
|
210 isvisible(Client *c) {
|
arg@420
|
211 unsigned int i;
|
arg@420
|
212
|
arg@420
|
213 for(i = 0; i < ntags; i++)
|
arg@420
|
214 if(c->tags[i] && seltag[i])
|
arg@420
|
215 return True;
|
arg@420
|
216 return False;
|
arg@420
|
217 }
|
arg@420
|
218
|
arg@415
|
219 void
|
arg@461
|
220 resizecol(Arg *arg) {
|
arg@423
|
221 unsigned int n;
|
arg@423
|
222 Client *c;
|
arg@418
|
223
|
arg@430
|
224 for(n = 0, c = clients; c; c = c->next)
|
arg@430
|
225 if(isvisible(c) && !c->isfloat)
|
arg@423
|
226 n++;
|
arg@486
|
227 if(!sel || sel->isfloat || n < 2 || (arrange == dofloat))
|
arg@415
|
228 return;
|
arg@423
|
229
|
arg@415
|
230 if(sel == getnext(clients)) {
|
arg@425
|
231 if(mw + arg->i > sw - 100 || mw + arg->i < 100)
|
arg@415
|
232 return;
|
arg@415
|
233 mw += arg->i;
|
arg@415
|
234 }
|
arg@415
|
235 else {
|
arg@425
|
236 if(mw - arg->i > sw - 100 || mw - arg->i < 100)
|
arg@415
|
237 return;
|
arg@415
|
238 mw -= arg->i;
|
arg@415
|
239 }
|
arg@415
|
240 arrange(NULL);
|
arg@415
|
241 }
|
arg@415
|
242
|
arg@327
|
243 void
|
arg@487
|
244 restack(void) {
|
arg@327
|
245 Client *c;
|
arg@327
|
246 XEvent ev;
|
arg@481
|
247
|
arg@437
|
248 if(!sel) {
|
arg@437
|
249 drawstatus();
|
arg@436
|
250 return;
|
arg@437
|
251 }
|
arg@436
|
252 if(sel->isfloat || arrange == dofloat) {
|
arg@436
|
253 XRaiseWindow(dpy, sel->win);
|
arg@436
|
254 XRaiseWindow(dpy, sel->twin);
|
arg@436
|
255 }
|
arg@446
|
256 if(arrange != dofloat)
|
arg@436
|
257 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
|
arg@436
|
258 XLowerWindow(dpy, c->twin);
|
arg@436
|
259 XLowerWindow(dpy, c->win);
|
arg@327
|
260 }
|
arg@327
|
261 drawall();
|
arg@327
|
262 XSync(dpy, False);
|
arg@327
|
263 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
|
arg@327
|
264 }
|
arg@327
|
265
|
arg@327
|
266 void
|
arg@461
|
267 togglemode(Arg *arg) {
|
arg@333
|
268 arrange = (arrange == dofloat) ? dotile : dofloat;
|
arg@327
|
269 if(sel)
|
arg@327
|
270 arrange(NULL);
|
arg@327
|
271 else
|
arg@327
|
272 drawstatus();
|
arg@327
|
273 }
|
arg@327
|
274
|
arg@327
|
275 void
|
arg@461
|
276 toggleview(Arg *arg) {
|
arg@327
|
277 unsigned int i;
|
arg@327
|
278
|
arg@327
|
279 seltag[arg->i] = !seltag[arg->i];
|
arg@327
|
280 for(i = 0; i < ntags && !seltag[i]; i++);
|
arg@327
|
281 if(i == ntags)
|
arg@327
|
282 seltag[arg->i] = True; /* cannot toggle last view */
|
arg@381
|
283 reorder();
|
arg@327
|
284 arrange(NULL);
|
arg@327
|
285 }
|
arg@327
|
286
|
arg@327
|
287 void
|
arg@461
|
288 view(Arg *arg) {
|
arg@327
|
289 unsigned int i;
|
arg@327
|
290
|
arg@327
|
291 for(i = 0; i < ntags; i++)
|
arg@327
|
292 seltag[i] = False;
|
arg@327
|
293 seltag[arg->i] = True;
|
arg@381
|
294 reorder();
|
arg@327
|
295 arrange(NULL);
|
arg@327
|
296 }
|
arg@327
|
297
|
arg@327
|
298 void
|
arg@461
|
299 viewall(Arg *arg) {
|
arg@395
|
300 unsigned int i;
|
arg@395
|
301
|
arg@395
|
302 for(i = 0; i < ntags; i++)
|
arg@395
|
303 seltag[i] = True;
|
arg@397
|
304 reorder();
|
arg@395
|
305 arrange(NULL);
|
arg@395
|
306 }
|
arg@395
|
307
|
arg@395
|
308 void
|
arg@461
|
309 zoom(Arg *arg) {
|
arg@423
|
310 unsigned int n;
|
arg@423
|
311 Client *c;
|
arg@473
|
312
|
arg@473
|
313 if(!sel)
|
arg@473
|
314 return;
|
arg@473
|
315
|
arg@473
|
316 if(sel->isfloat || (arrange == dofloat)) {
|
arg@480
|
317 togglemax(sel);
|
arg@473
|
318 return;
|
arg@473
|
319 }
|
arg@327
|
320
|
arg@430
|
321 for(n = 0, c = clients; c; c = c->next)
|
arg@430
|
322 if(isvisible(c) && !c->isfloat)
|
arg@423
|
323 n++;
|
arg@486
|
324 if(n < 2 || (arrange == dofloat))
|
arg@327
|
325 return;
|
arg@327
|
326
|
arg@430
|
327 if((c = sel) == nexttiled(clients))
|
arg@433
|
328 if(!(c = nexttiled(c->next)))
|
arg@429
|
329 return;
|
arg@443
|
330 detach(c);
|
arg@443
|
331 if(clients)
|
arg@443
|
332 clients->prev = c;
|
arg@443
|
333 c->next = clients;
|
arg@443
|
334 clients = c;
|
arg@378
|
335 focus(c);
|
arg@327
|
336 arrange(NULL);
|
arg@327
|
337 }
|