rev |
line source |
garbeam@5
|
1 /*
|
garbeam@5
|
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
garbeam@5
|
3 * See LICENSE file for license details.
|
garbeam@5
|
4 */
|
garbeam@5
|
5
|
garbeam@10
|
6 #include <stdlib.h>
|
garbeam@51
|
7 #include <stdio.h>
|
garbeam@5
|
8 #include <string.h>
|
garbeam@5
|
9 #include <X11/Xatom.h>
|
garbeam@32
|
10 #include <X11/Xutil.h>
|
garbeam@5
|
11
|
garbeam@43
|
12 #include "dwm.h"
|
garbeam@5
|
13
|
garbeam@53
|
14 void (*arrange)(Arg *) = tiling;
|
garbeam@49
|
15
|
garbeam@51
|
16 static Rule rule[] = {
|
garbeam@53
|
17 /* class instance tags floating */
|
garbeam@53
|
18 { "Firefox-bin", "Gecko", { [Twww] = "www" }, False },
|
garbeam@51
|
19 };
|
garbeam@50
|
20
|
garbeam@49
|
21 static Client *
|
garbeam@49
|
22 next(Client *c)
|
garbeam@49
|
23 {
|
garbeam@50
|
24 for(; c && !c->tags[tsel]; c = c->next);
|
garbeam@49
|
25 return c;
|
garbeam@49
|
26 }
|
garbeam@49
|
27
|
garbeam@50
|
28 void
|
garbeam@50
|
29 zoom(Arg *arg)
|
garbeam@49
|
30 {
|
garbeam@51
|
31 Client **l, *old;
|
garbeam@50
|
32
|
garbeam@51
|
33 if(!(old = sel))
|
garbeam@50
|
34 return;
|
garbeam@50
|
35
|
garbeam@50
|
36 for(l = &clients; *l && *l != sel; l = &(*l)->next);
|
garbeam@50
|
37 *l = sel->next;
|
garbeam@50
|
38
|
garbeam@51
|
39 old->next = clients; /* pop */
|
garbeam@51
|
40 clients = old;
|
garbeam@51
|
41 sel = old;
|
garbeam@50
|
42 arrange(NULL);
|
garbeam@50
|
43 focus(sel);
|
garbeam@49
|
44 }
|
garbeam@31
|
45
|
garbeam@27
|
46 void
|
garbeam@49
|
47 max(Arg *arg)
|
garbeam@28
|
48 {
|
garbeam@50
|
49 if(!sel)
|
garbeam@28
|
50 return;
|
garbeam@50
|
51 sel->x = sx;
|
garbeam@57
|
52 sel->y = sy + bh;
|
garbeam@50
|
53 sel->w = sw - 2 * sel->border;
|
garbeam@57
|
54 sel->h = sh - 2 * sel->border - bh;
|
garbeam@50
|
55 craise(sel);
|
garbeam@52
|
56 resize(sel, False);
|
garbeam@29
|
57 discard_events(EnterWindowMask);
|
garbeam@28
|
58 }
|
garbeam@28
|
59
|
garbeam@46
|
60 void
|
garbeam@50
|
61 view(Arg *arg)
|
garbeam@50
|
62 {
|
garbeam@54
|
63 Client *c;
|
garbeam@54
|
64
|
garbeam@50
|
65 tsel = arg->i;
|
garbeam@50
|
66 arrange(NULL);
|
garbeam@54
|
67
|
garbeam@62
|
68 if((c = next(clients)))
|
garbeam@62
|
69 focus(c);
|
garbeam@62
|
70
|
garbeam@54
|
71 for(c = clients; c; c = next(c->next))
|
garbeam@54
|
72 draw_client(c);
|
garbeam@57
|
73 draw_bar();
|
garbeam@50
|
74 }
|
garbeam@50
|
75
|
garbeam@50
|
76 void
|
garbeam@53
|
77 tappend(Arg *arg)
|
garbeam@49
|
78 {
|
garbeam@50
|
79 if(!sel)
|
garbeam@49
|
80 return;
|
garbeam@49
|
81
|
garbeam@53
|
82 sel->tags[arg->i] = tags[arg->i];
|
garbeam@53
|
83 arrange(NULL);
|
garbeam@53
|
84 }
|
garbeam@49
|
85
|
garbeam@53
|
86 void
|
garbeam@53
|
87 ttrunc(Arg *arg)
|
garbeam@53
|
88 {
|
garbeam@53
|
89 int i;
|
garbeam@53
|
90 if(!sel)
|
garbeam@53
|
91 return;
|
garbeam@53
|
92
|
garbeam@53
|
93 for(i = 0; i < TLast; i++)
|
garbeam@53
|
94 sel->tags[i] = NULL;
|
garbeam@53
|
95 tappend(arg);
|
garbeam@49
|
96 }
|
garbeam@49
|
97
|
garbeam@50
|
98 static void
|
garbeam@50
|
99 ban_client(Client *c)
|
garbeam@50
|
100 {
|
garbeam@50
|
101 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
|
garbeam@50
|
102 XMoveWindow(dpy, c->title, c->tx + 2 * sw, c->ty);
|
garbeam@50
|
103 }
|
garbeam@50
|
104
|
garbeam@49
|
105 void
|
garbeam@49
|
106 floating(Arg *arg)
|
garbeam@31
|
107 {
|
garbeam@31
|
108 Client *c;
|
garbeam@31
|
109
|
garbeam@46
|
110 arrange = floating;
|
garbeam@50
|
111 for(c = clients; c; c = c->next) {
|
garbeam@50
|
112 if(c->tags[tsel])
|
garbeam@52
|
113 resize(c, True);
|
garbeam@50
|
114 else
|
garbeam@50
|
115 ban_client(c);
|
garbeam@50
|
116 }
|
garbeam@50
|
117 if(sel && !sel->tags[tsel]) {
|
garbeam@50
|
118 if((sel = next(clients))) {
|
garbeam@50
|
119 craise(sel);
|
garbeam@50
|
120 focus(sel);
|
garbeam@50
|
121 }
|
garbeam@50
|
122 }
|
garbeam@31
|
123 discard_events(EnterWindowMask);
|
garbeam@31
|
124 }
|
garbeam@31
|
125
|
garbeam@46
|
126 void
|
garbeam@49
|
127 tiling(Arg *arg)
|
garbeam@27
|
128 {
|
garbeam@27
|
129 Client *c;
|
garbeam@51
|
130 int n, i, w, h;
|
garbeam@27
|
131
|
garbeam@51
|
132 w = sw - mw;
|
garbeam@46
|
133 arrange = tiling;
|
garbeam@51
|
134 for(n = 0, c = clients; c; c = c->next)
|
garbeam@53
|
135 if(c->tags[tsel] && !c->floating)
|
garbeam@51
|
136 n++;
|
garbeam@50
|
137
|
garbeam@57
|
138 if(n > 1)
|
garbeam@57
|
139 h = (sh - bh) / (n - 1);
|
garbeam@57
|
140 else
|
garbeam@57
|
141 h = sh - bh;
|
garbeam@27
|
142
|
garbeam@51
|
143 for(i = 0, c = clients; c; c = c->next) {
|
garbeam@50
|
144 if(c->tags[tsel]) {
|
garbeam@53
|
145 if(c->floating) {
|
garbeam@53
|
146 craise(c);
|
garbeam@53
|
147 resize(c, True);
|
garbeam@53
|
148 continue;
|
garbeam@53
|
149 }
|
garbeam@51
|
150 if(n == 1) {
|
garbeam@51
|
151 c->x = sx;
|
garbeam@57
|
152 c->y = sy + bh;
|
garbeam@52
|
153 c->w = sw - 2 * c->border;
|
garbeam@57
|
154 c->h = sh - 2 * c->border - bh;
|
garbeam@51
|
155 }
|
garbeam@52
|
156 else if(i == 0) {
|
garbeam@51
|
157 c->x = sx;
|
garbeam@57
|
158 c->y = sy + bh;
|
garbeam@52
|
159 c->w = mw - 2 * c->border;
|
garbeam@57
|
160 c->h = sh - 2 * c->border - bh;
|
garbeam@51
|
161 }
|
garbeam@51
|
162 else {
|
garbeam@51
|
163 c->x = sx + mw;
|
garbeam@57
|
164 c->y = sy + (i - 1) * h + bh;
|
garbeam@52
|
165 c->w = w - 2 * c->border;
|
garbeam@52
|
166 c->h = h - 2 * c->border;
|
garbeam@51
|
167 }
|
garbeam@52
|
168 resize(c, False);
|
garbeam@51
|
169 i++;
|
garbeam@50
|
170 }
|
garbeam@50
|
171 else
|
garbeam@50
|
172 ban_client(c);
|
garbeam@50
|
173 }
|
garbeam@50
|
174 if(sel && !sel->tags[tsel]) {
|
garbeam@50
|
175 if((sel = next(clients))) {
|
garbeam@50
|
176 craise(sel);
|
garbeam@50
|
177 focus(sel);
|
garbeam@27
|
178 }
|
garbeam@27
|
179 }
|
garbeam@29
|
180 discard_events(EnterWindowMask);
|
garbeam@27
|
181 }
|
garbeam@27
|
182
|
garbeam@27
|
183 void
|
garbeam@49
|
184 prevc(Arg *arg)
|
garbeam@27
|
185 {
|
garbeam@49
|
186 Client *c;
|
garbeam@27
|
187
|
garbeam@50
|
188 if(!sel)
|
garbeam@27
|
189 return;
|
garbeam@49
|
190
|
garbeam@50
|
191 if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) {
|
garbeam@49
|
192 craise(c);
|
garbeam@49
|
193 focus(c);
|
garbeam@49
|
194 }
|
garbeam@27
|
195 }
|
garbeam@27
|
196
|
garbeam@27
|
197 void
|
garbeam@49
|
198 nextc(Arg *arg)
|
garbeam@27
|
199 {
|
garbeam@49
|
200 Client *c;
|
garbeam@49
|
201
|
garbeam@50
|
202 if(!sel)
|
garbeam@49
|
203 return;
|
garbeam@49
|
204
|
garbeam@50
|
205 if(!(c = next(sel->next)))
|
garbeam@50
|
206 c = next(clients);
|
garbeam@49
|
207 if(c) {
|
garbeam@49
|
208 craise(c);
|
garbeam@50
|
209 c->revert = sel;
|
garbeam@49
|
210 focus(c);
|
garbeam@49
|
211 }
|
garbeam@49
|
212 }
|
garbeam@49
|
213
|
garbeam@49
|
214 void
|
garbeam@49
|
215 ckill(Arg *arg)
|
garbeam@49
|
216 {
|
garbeam@50
|
217 if(!sel)
|
garbeam@27
|
218 return;
|
garbeam@50
|
219 if(sel->proto & WM_PROTOCOL_DELWIN)
|
garbeam@50
|
220 send_message(sel->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
|
garbeam@27
|
221 else
|
garbeam@50
|
222 XKillClient(dpy, sel->win);
|
garbeam@27
|
223 }
|
garbeam@27
|
224
|
garbeam@26
|
225 static void
|
garbeam@26
|
226 resize_title(Client *c)
|
garbeam@26
|
227 {
|
garbeam@31
|
228 int i;
|
garbeam@31
|
229
|
garbeam@31
|
230 c->tw = 0;
|
garbeam@31
|
231 for(i = 0; i < TLast; i++)
|
garbeam@31
|
232 if(c->tags[i])
|
garbeam@43
|
233 c->tw += textw(c->tags[i]) + dc.font.height;
|
garbeam@43
|
234 c->tw += textw(c->name) + dc.font.height;
|
garbeam@26
|
235 if(c->tw > c->w)
|
garbeam@26
|
236 c->tw = c->w + 2;
|
garbeam@26
|
237 c->tx = c->x + c->w - c->tw + 2;
|
garbeam@26
|
238 c->ty = c->y;
|
garbeam@26
|
239 XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
|
garbeam@26
|
240 }
|
garbeam@18
|
241
|
garbeam@13
|
242 void
|
garbeam@13
|
243 update_name(Client *c)
|
garbeam@5
|
244 {
|
garbeam@5
|
245 XTextProperty name;
|
garbeam@5
|
246 int n;
|
garbeam@7
|
247 char **list = NULL;
|
garbeam@5
|
248
|
garbeam@5
|
249 name.nitems = 0;
|
garbeam@5
|
250 c->name[0] = 0;
|
garbeam@5
|
251 XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]);
|
garbeam@5
|
252 if(!name.nitems)
|
garbeam@5
|
253 XGetWMName(dpy, c->win, &name);
|
garbeam@5
|
254 if(!name.nitems)
|
garbeam@5
|
255 return;
|
garbeam@5
|
256 if(name.encoding == XA_STRING)
|
garbeam@5
|
257 strncpy(c->name, (char *)name.value, sizeof(c->name));
|
garbeam@5
|
258 else {
|
garbeam@5
|
259 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
|
garbeam@5
|
260 && n > 0 && *list)
|
garbeam@5
|
261 {
|
garbeam@5
|
262 strncpy(c->name, *list, sizeof(c->name));
|
garbeam@5
|
263 XFreeStringList(list);
|
garbeam@5
|
264 }
|
garbeam@5
|
265 }
|
garbeam@5
|
266 XFree(name.value);
|
garbeam@26
|
267 resize_title(c);
|
garbeam@5
|
268 }
|
garbeam@5
|
269
|
garbeam@10
|
270 void
|
garbeam@20
|
271 update_size(Client *c)
|
garbeam@20
|
272 {
|
garbeam@20
|
273 XSizeHints size;
|
garbeam@20
|
274 long msize;
|
garbeam@20
|
275 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
|
garbeam@20
|
276 size.flags = PSize;
|
garbeam@20
|
277 c->flags = size.flags;
|
garbeam@21
|
278 if(c->flags & PBaseSize) {
|
garbeam@21
|
279 c->basew = size.base_width;
|
garbeam@21
|
280 c->baseh = size.base_height;
|
garbeam@21
|
281 }
|
garbeam@21
|
282 else
|
garbeam@21
|
283 c->basew = c->baseh = 0;
|
garbeam@21
|
284 if(c->flags & PResizeInc) {
|
garbeam@21
|
285 c->incw = size.width_inc;
|
garbeam@21
|
286 c->inch = size.height_inc;
|
garbeam@21
|
287 }
|
garbeam@21
|
288 else
|
garbeam@21
|
289 c->incw = c->inch = 0;
|
garbeam@21
|
290 if(c->flags & PMaxSize) {
|
garbeam@21
|
291 c->maxw = size.max_width;
|
garbeam@21
|
292 c->maxh = size.max_height;
|
garbeam@21
|
293 }
|
garbeam@21
|
294 else
|
garbeam@21
|
295 c->maxw = c->maxh = 0;
|
garbeam@21
|
296 if(c->flags & PMinSize) {
|
garbeam@21
|
297 c->minw = size.min_width;
|
garbeam@21
|
298 c->minh = size.min_height;
|
garbeam@21
|
299 }
|
garbeam@21
|
300 else
|
garbeam@21
|
301 c->minw = c->minh = 0;
|
garbeam@29
|
302 if(c->flags & PWinGravity)
|
garbeam@29
|
303 c->grav = size.win_gravity;
|
garbeam@29
|
304 else
|
garbeam@29
|
305 c->grav = NorthWestGravity;
|
garbeam@20
|
306 }
|
garbeam@20
|
307
|
garbeam@20
|
308 void
|
garbeam@32
|
309 craise(Client *c)
|
garbeam@26
|
310 {
|
garbeam@26
|
311 XRaiseWindow(dpy, c->win);
|
garbeam@26
|
312 XRaiseWindow(dpy, c->title);
|
garbeam@26
|
313 }
|
garbeam@26
|
314
|
garbeam@26
|
315 void
|
garbeam@26
|
316 lower(Client *c)
|
garbeam@26
|
317 {
|
garbeam@26
|
318 XLowerWindow(dpy, c->title);
|
garbeam@26
|
319 XLowerWindow(dpy, c->win);
|
garbeam@26
|
320 }
|
garbeam@26
|
321
|
garbeam@26
|
322 void
|
garbeam@13
|
323 focus(Client *c)
|
garbeam@13
|
324 {
|
garbeam@52
|
325 Client *old = sel;
|
garbeam@52
|
326
|
garbeam@50
|
327 sel = c;
|
garbeam@52
|
328 if(old && old != c)
|
garbeam@52
|
329 draw_client(old);
|
garbeam@27
|
330 draw_client(c);
|
garbeam@26
|
331 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
|
garbeam@13
|
332 XFlush(dpy);
|
garbeam@45
|
333 discard_events(EnterWindowMask);
|
garbeam@13
|
334 }
|
garbeam@13
|
335
|
garbeam@51
|
336 static void
|
garbeam@51
|
337 init_tags(Client *c)
|
garbeam@51
|
338 {
|
garbeam@51
|
339 XClassHint ch;
|
garbeam@51
|
340 static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0;
|
garbeam@51
|
341 unsigned int i, j;
|
garbeam@51
|
342 Bool matched = False;
|
garbeam@51
|
343
|
garbeam@51
|
344 if(!len) {
|
garbeam@51
|
345 c->tags[tsel] = tags[tsel];
|
garbeam@51
|
346 return;
|
garbeam@51
|
347 }
|
garbeam@51
|
348
|
garbeam@51
|
349 if(XGetClassHint(dpy, c->win, &ch)) {
|
garbeam@51
|
350 if(ch.res_class && ch.res_name) {
|
garbeam@51
|
351 for(i = 0; i < len; i++)
|
garbeam@51
|
352 if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class))
|
garbeam@51
|
353 && !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance)))
|
garbeam@51
|
354 {
|
garbeam@51
|
355 for(j = 0; j < TLast; j++)
|
garbeam@51
|
356 c->tags[j] = rule[i].tags[j];
|
garbeam@53
|
357 c->floating = rule[i].floating;
|
garbeam@51
|
358 matched = True;
|
garbeam@51
|
359 break;
|
garbeam@51
|
360 }
|
garbeam@51
|
361 }
|
garbeam@51
|
362 if(ch.res_class)
|
garbeam@51
|
363 XFree(ch.res_class);
|
garbeam@51
|
364 if(ch.res_name)
|
garbeam@51
|
365 XFree(ch.res_name);
|
garbeam@51
|
366 }
|
garbeam@51
|
367
|
garbeam@51
|
368 if(!matched)
|
garbeam@51
|
369 c->tags[tsel] = tags[tsel];
|
garbeam@51
|
370 }
|
garbeam@51
|
371
|
garbeam@13
|
372 void
|
garbeam@10
|
373 manage(Window w, XWindowAttributes *wa)
|
garbeam@5
|
374 {
|
garbeam@50
|
375 Client *c, **l;
|
garbeam@5
|
376 XSetWindowAttributes twa;
|
garbeam@53
|
377 Window trans;
|
garbeam@5
|
378
|
garbeam@5
|
379 c = emallocz(sizeof(Client));
|
garbeam@5
|
380 c->win = w;
|
garbeam@22
|
381 c->tx = c->x = wa->x;
|
garbeam@22
|
382 c->ty = c->y = wa->y;
|
garbeam@57
|
383 if(c->y < bh)
|
garbeam@57
|
384 c->ty = c->y += bh;
|
garbeam@22
|
385 c->tw = c->w = wa->width;
|
garbeam@20
|
386 c->h = wa->height;
|
garbeam@57
|
387 c->th = bh;
|
garbeam@29
|
388 c->border = 1;
|
garbeam@50
|
389 c->proto = win_proto(c->win);
|
garbeam@20
|
390 update_size(c);
|
garbeam@26
|
391 XSelectInput(dpy, c->win,
|
garbeam@26
|
392 StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
|
garbeam@53
|
393 XGetTransientForHint(dpy, c->win, &trans);
|
garbeam@5
|
394 twa.override_redirect = 1;
|
garbeam@5
|
395 twa.background_pixmap = ParentRelative;
|
garbeam@23
|
396 twa.event_mask = ExposureMask;
|
garbeam@5
|
397
|
garbeam@22
|
398 c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
|
garbeam@20
|
399 0, DefaultDepth(dpy, screen), CopyFromParent,
|
garbeam@5
|
400 DefaultVisual(dpy, screen),
|
garbeam@5
|
401 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
|
garbeam@31
|
402
|
garbeam@21
|
403 update_name(c);
|
garbeam@51
|
404 init_tags(c);
|
garbeam@49
|
405
|
garbeam@50
|
406 for(l = &clients; *l; l = &(*l)->next);
|
garbeam@50
|
407 c->next = *l; /* *l == nil */
|
garbeam@50
|
408 *l = c;
|
garbeam@49
|
409
|
garbeam@19
|
410 XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
|
garbeam@19
|
411 GrabModeAsync, GrabModeSync, None, None);
|
garbeam@19
|
412 XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask,
|
garbeam@19
|
413 GrabModeAsync, GrabModeSync, None, None);
|
garbeam@19
|
414 XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask,
|
garbeam@18
|
415 GrabModeAsync, GrabModeSync, None, None);
|
garbeam@53
|
416
|
garbeam@53
|
417 if(!c->floating)
|
garbeam@53
|
418 c->floating = trans
|
garbeam@53
|
419 || ((c->maxw == c->minw) && (c->maxh == c->minh));
|
garbeam@53
|
420
|
garbeam@46
|
421 arrange(NULL);
|
garbeam@60
|
422 /* mapping the window now prevents flicker */
|
garbeam@60
|
423 if(c->tags[tsel]) {
|
garbeam@60
|
424 XMapRaised(dpy, c->win);
|
garbeam@60
|
425 XMapRaised(dpy, c->title);
|
garbeam@51
|
426 focus(c);
|
garbeam@60
|
427 }
|
garbeam@60
|
428 else {
|
garbeam@51
|
429 ban_client(c);
|
garbeam@60
|
430 XMapRaised(dpy, c->win);
|
garbeam@60
|
431 XMapRaised(dpy, c->title);
|
garbeam@60
|
432 }
|
garbeam@5
|
433 }
|
garbeam@9
|
434
|
garbeam@18
|
435 void
|
garbeam@29
|
436 gravitate(Client *c, Bool invert)
|
garbeam@29
|
437 {
|
garbeam@29
|
438 int dx = 0, dy = 0;
|
garbeam@29
|
439
|
garbeam@29
|
440 switch(c->grav) {
|
garbeam@29
|
441 case StaticGravity:
|
garbeam@29
|
442 case NorthWestGravity:
|
garbeam@29
|
443 case NorthGravity:
|
garbeam@29
|
444 case NorthEastGravity:
|
garbeam@29
|
445 dy = c->border;
|
garbeam@29
|
446 break;
|
garbeam@29
|
447 case EastGravity:
|
garbeam@29
|
448 case CenterGravity:
|
garbeam@29
|
449 case WestGravity:
|
garbeam@29
|
450 dy = -(c->h / 2) + c->border;
|
garbeam@29
|
451 break;
|
garbeam@29
|
452 case SouthEastGravity:
|
garbeam@29
|
453 case SouthGravity:
|
garbeam@29
|
454 case SouthWestGravity:
|
garbeam@29
|
455 dy = -c->h;
|
garbeam@29
|
456 break;
|
garbeam@29
|
457 default:
|
garbeam@29
|
458 break;
|
garbeam@29
|
459 }
|
garbeam@29
|
460
|
garbeam@29
|
461 switch (c->grav) {
|
garbeam@29
|
462 case StaticGravity:
|
garbeam@29
|
463 case NorthWestGravity:
|
garbeam@29
|
464 case WestGravity:
|
garbeam@29
|
465 case SouthWestGravity:
|
garbeam@29
|
466 dx = c->border;
|
garbeam@29
|
467 break;
|
garbeam@29
|
468 case NorthGravity:
|
garbeam@29
|
469 case CenterGravity:
|
garbeam@29
|
470 case SouthGravity:
|
garbeam@29
|
471 dx = -(c->w / 2) + c->border;
|
garbeam@29
|
472 break;
|
garbeam@29
|
473 case NorthEastGravity:
|
garbeam@29
|
474 case EastGravity:
|
garbeam@29
|
475 case SouthEastGravity:
|
garbeam@29
|
476 dx = -(c->w + c->border);
|
garbeam@29
|
477 break;
|
garbeam@29
|
478 default:
|
garbeam@29
|
479 break;
|
garbeam@29
|
480 }
|
garbeam@29
|
481
|
garbeam@29
|
482 if(invert) {
|
garbeam@29
|
483 dx = -dx;
|
garbeam@29
|
484 dy = -dy;
|
garbeam@29
|
485 }
|
garbeam@29
|
486 c->x += dx;
|
garbeam@29
|
487 c->y += dy;
|
garbeam@29
|
488 }
|
garbeam@29
|
489
|
garbeam@31
|
490
|
garbeam@29
|
491 void
|
garbeam@52
|
492 resize(Client *c, Bool inc)
|
garbeam@18
|
493 {
|
garbeam@18
|
494 XConfigureEvent e;
|
garbeam@18
|
495
|
garbeam@52
|
496 if(inc) {
|
garbeam@52
|
497 if(c->incw)
|
garbeam@52
|
498 c->w -= (c->w - c->basew) % c->incw;
|
garbeam@52
|
499 if(c->inch)
|
garbeam@52
|
500 c->h -= (c->h - c->baseh) % c->inch;
|
garbeam@52
|
501 }
|
garbeam@31
|
502 if(c->minw && c->w < c->minw)
|
garbeam@31
|
503 c->w = c->minw;
|
garbeam@31
|
504 if(c->minh && c->h < c->minh)
|
garbeam@31
|
505 c->h = c->minh;
|
garbeam@31
|
506 if(c->maxw && c->w > c->maxw)
|
garbeam@31
|
507 c->w = c->maxw;
|
garbeam@31
|
508 if(c->maxh && c->h > c->maxh)
|
garbeam@31
|
509 c->h = c->maxh;
|
garbeam@26
|
510 resize_title(c);
|
garbeam@55
|
511 XSetWindowBorderWidth(dpy, c->win, 1);
|
garbeam@20
|
512 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
|
garbeam@18
|
513 e.type = ConfigureNotify;
|
garbeam@18
|
514 e.event = c->win;
|
garbeam@18
|
515 e.window = c->win;
|
garbeam@20
|
516 e.x = c->x;
|
garbeam@20
|
517 e.y = c->y;
|
garbeam@20
|
518 e.width = c->w;
|
garbeam@20
|
519 e.height = c->h;
|
garbeam@29
|
520 e.border_width = c->border;
|
garbeam@18
|
521 e.above = None;
|
garbeam@18
|
522 e.override_redirect = False;
|
garbeam@18
|
523 XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
|
garbeam@18
|
524 XFlush(dpy);
|
garbeam@18
|
525 }
|
garbeam@18
|
526
|
garbeam@10
|
527 static int
|
garbeam@33
|
528 dummy_error_handler(Display *dsply, XErrorEvent *err)
|
garbeam@10
|
529 {
|
garbeam@10
|
530 return 0;
|
garbeam@10
|
531 }
|
garbeam@10
|
532
|
garbeam@10
|
533 void
|
garbeam@10
|
534 unmanage(Client *c)
|
garbeam@10
|
535 {
|
garbeam@50
|
536 Client **l;
|
garbeam@50
|
537
|
garbeam@10
|
538 XGrabServer(dpy);
|
garbeam@10
|
539 XSetErrorHandler(dummy_error_handler);
|
garbeam@10
|
540
|
garbeam@18
|
541 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
|
garbeam@10
|
542 XDestroyWindow(dpy, c->title);
|
garbeam@10
|
543
|
garbeam@50
|
544 for(l = &clients; *l && *l != c; l = &(*l)->next);
|
garbeam@50
|
545 *l = c->next;
|
garbeam@50
|
546 for(l = &clients; *l; l = &(*l)->next)
|
garbeam@50
|
547 if((*l)->revert == c)
|
garbeam@50
|
548 (*l)->revert = NULL;
|
garbeam@50
|
549 if(sel == c)
|
garbeam@50
|
550 sel = sel->revert ? sel->revert : clients;
|
garbeam@49
|
551
|
garbeam@10
|
552 free(c);
|
garbeam@10
|
553
|
garbeam@10
|
554 XFlush(dpy);
|
garbeam@10
|
555 XSetErrorHandler(error_handler);
|
garbeam@10
|
556 XUngrabServer(dpy);
|
garbeam@46
|
557 arrange(NULL);
|
garbeam@50
|
558 if(sel)
|
garbeam@50
|
559 focus(sel);
|
garbeam@10
|
560 }
|
garbeam@10
|
561
|
garbeam@23
|
562 Client *
|
garbeam@23
|
563 gettitle(Window w)
|
garbeam@23
|
564 {
|
garbeam@23
|
565 Client *c;
|
garbeam@50
|
566 for(c = clients; c; c = c->next)
|
garbeam@23
|
567 if(c->title == w)
|
garbeam@23
|
568 return c;
|
garbeam@23
|
569 return NULL;
|
garbeam@23
|
570 }
|
garbeam@10
|
571
|
garbeam@9
|
572 Client *
|
garbeam@9
|
573 getclient(Window w)
|
garbeam@9
|
574 {
|
garbeam@9
|
575 Client *c;
|
garbeam@50
|
576 for(c = clients; c; c = c->next)
|
garbeam@9
|
577 if(c->win == w)
|
garbeam@9
|
578 return c;
|
garbeam@9
|
579 return NULL;
|
garbeam@9
|
580 }
|
garbeam@13
|
581
|
garbeam@14
|
582 void
|
garbeam@14
|
583 draw_client(Client *c)
|
garbeam@14
|
584 {
|
garbeam@31
|
585 int i;
|
garbeam@52
|
586 if(c == sel) {
|
garbeam@57
|
587 draw_bar();
|
garbeam@52
|
588 XUnmapWindow(dpy, c->title);
|
garbeam@52
|
589 XSetWindowBorder(dpy, c->win, dc.fg);
|
garbeam@26
|
590 return;
|
garbeam@52
|
591 }
|
garbeam@52
|
592
|
garbeam@52
|
593 XSetWindowBorder(dpy, c->win, dc.bg);
|
garbeam@52
|
594 XMapWindow(dpy, c->title);
|
garbeam@14
|
595
|
garbeam@34
|
596 dc.x = dc.y = 0;
|
garbeam@14
|
597
|
garbeam@34
|
598 dc.w = 0;
|
garbeam@31
|
599 for(i = 0; i < TLast; i++) {
|
garbeam@31
|
600 if(c->tags[i]) {
|
garbeam@34
|
601 dc.x += dc.w;
|
garbeam@43
|
602 dc.w = textw(c->tags[i]) + dc.font.height;
|
garbeam@57
|
603 drawtext(c->tags[i], True);
|
garbeam@31
|
604 }
|
garbeam@31
|
605 }
|
garbeam@34
|
606 dc.x += dc.w;
|
garbeam@43
|
607 dc.w = textw(c->name) + dc.font.height;
|
garbeam@57
|
608 drawtext(c->name, True);
|
garbeam@34
|
609 XCopyArea(dpy, dc.drawable, c->title, dc.gc,
|
garbeam@22
|
610 0, 0, c->tw, c->th, 0, 0);
|
garbeam@21
|
611 XFlush(dpy);
|
garbeam@14
|
612 }
|