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