|
1 /* |
|
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> |
|
3 * See LICENSE file for license details. |
|
4 */ |
|
5 |
|
6 #include <string.h> |
|
7 #include <X11/Xatom.h> |
|
8 |
|
9 #include "util.h" |
|
10 #include "wm.h" |
|
11 |
|
12 static void |
|
13 update_client_name(Client *c) |
|
14 { |
|
15 XTextProperty name; |
|
16 int n; |
|
17 char **list = 0; |
|
18 |
|
19 name.nitems = 0; |
|
20 c->name[0] = 0; |
|
21 XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]); |
|
22 if(!name.nitems) |
|
23 XGetWMName(dpy, c->win, &name); |
|
24 if(!name.nitems) |
|
25 return; |
|
26 if(name.encoding == XA_STRING) |
|
27 strncpy(c->name, (char *)name.value, sizeof(c->name)); |
|
28 else { |
|
29 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success |
|
30 && n > 0 && *list) |
|
31 { |
|
32 strncpy(c->name, *list, sizeof(c->name)); |
|
33 XFreeStringList(list); |
|
34 } |
|
35 } |
|
36 XFree(name.value); |
|
37 } |
|
38 |
|
39 Client * |
|
40 create_client(Window w, XWindowAttributes *wa) |
|
41 { |
|
42 Client *c; |
|
43 XSetWindowAttributes twa; |
|
44 long msize; |
|
45 |
|
46 c = emallocz(sizeof(Client)); |
|
47 c->win = w; |
|
48 c->r[RFloat].x = wa->x; |
|
49 c->r[RFloat].y = wa->y; |
|
50 c->r[RFloat].width = wa->width; |
|
51 c->r[RFloat].height = wa->height; |
|
52 c->border = wa->border_width; |
|
53 XSetWindowBorderWidth(dpy, c->win, 0); |
|
54 c->proto = win_proto(c->win); |
|
55 XGetTransientForHint(dpy, c->win, &c->trans); |
|
56 if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags) |
|
57 c->size.flags = PSize; |
|
58 c->fixedsize = |
|
59 (c->size.flags & PMinSize && c->size.flags & PMaxSize |
|
60 && c->size.min_width == c->size.max_width |
|
61 && c->size.min_height == c->size.max_height); |
|
62 XAddToSaveSet(dpy, c->win); |
|
63 update_client_name(c); |
|
64 twa.override_redirect = 1; |
|
65 twa.background_pixmap = ParentRelative; |
|
66 twa.event_mask = ExposureMask; |
|
67 |
|
68 c->title = XCreateWindow(dpy, root, c->r[RFloat].x, c->r[RFloat].y, |
|
69 c->r[RFloat].width, barrect.height, 0, |
|
70 DefaultDepth(dpy, screen), CopyFromParent, |
|
71 DefaultVisual(dpy, screen), |
|
72 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa); |
|
73 XFlush(dpy); |
|
74 |
|
75 #if 0 |
|
76 for(t=&client, i=0; *t; t=&(*t)->next, i++); |
|
77 c->next = *t; /* *t == nil */ |
|
78 *t = c; |
|
79 #endif |
|
80 return c; |
|
81 } |
|
82 |
|
83 void |
|
84 manage(Client *c) |
|
85 { |
|
86 XMapRaised(dpy, c->win); |
|
87 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); |
|
88 XFlush(dpy); |
|
89 } |