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