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