2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
13 #define CLIENT_MASK (StructureNotifyMask | PropertyChangeMask | EnterWindowMask)
16 update_name(Client *c)
24 XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]);
26 XGetWMName(dpy, c->win, &name);
29 if(name.encoding == XA_STRING)
30 strncpy(c->name, (char *)name.value, sizeof(c->name));
32 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
35 strncpy(c->name, *list, sizeof(c->name));
36 XFreeStringList(list);
43 update_size(Client *c)
47 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
49 c->flags = size.flags;
50 if(c->flags & PBaseSize) {
51 c->basew = size.base_width;
52 c->baseh = size.base_height;
55 c->basew = c->baseh = 0;
56 if(c->flags & PResizeInc) {
57 c->incw = size.width_inc;
58 c->inch = size.height_inc;
61 c->incw = c->inch = 0;
62 if(c->flags & PMaxSize) {
63 c->maxw = size.max_width;
64 c->maxh = size.max_height;
67 c->maxw = c->maxh = 0;
68 if(c->flags & PMinSize) {
69 c->minw = size.min_width;
70 c->minh = size.min_height;
73 c->minw = c->minh = 0;
82 for(l=&stack; *l && *l != c; l=&(*l)->snext);
87 XRaiseWindow(dpy, c->win);
88 XRaiseWindow(dpy, c->title);
89 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
91 XMapWindow(dpy, old->title);
94 XUnmapWindow(dpy, c->title);
100 manage(Window w, XWindowAttributes *wa)
103 XSetWindowAttributes twa;
105 c = emallocz(sizeof(Client));
107 c->tx = c->x = wa->x;
108 c->ty = c->y = wa->y;
109 c->tw = c->w = wa->width;
111 c->th = barrect.height;
113 XSetWindowBorderWidth(dpy, c->win, 1);
114 XSetWindowBorder(dpy, c->win, brush.border);
115 XSelectInput(dpy, c->win, CLIENT_MASK);
116 XGetTransientForHint(dpy, c->win, &c->trans);
117 twa.override_redirect = 1;
118 twa.background_pixmap = ParentRelative;
119 twa.event_mask = SubstructureNotifyMask | ExposureMask;
121 c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
122 0, DefaultDepth(dpy, screen), CopyFromParent,
123 DefaultVisual(dpy, screen),
124 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
127 for(l=&clients; *l; l=&(*l)->next);
128 c->next = *l; /* *l == nil */
132 XMapWindow(dpy, c->win);
133 XMapWindow(dpy, c->title);
134 XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
135 GrabModeAsync, GrabModeSync, None, None);
136 XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask,
137 GrabModeAsync, GrabModeSync, None, None);
138 XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask,
139 GrabModeAsync, GrabModeSync, None, None);
149 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
150 e.type = ConfigureNotify;
159 e.override_redirect = False;
160 XSelectInput(dpy, c->win, CLIENT_MASK & ~StructureNotifyMask);
161 XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
162 XSelectInput(dpy, c->win, CLIENT_MASK);
167 dummy_error_handler(Display *dpy, XErrorEvent *error)
178 XSetErrorHandler(dummy_error_handler);
180 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
181 XDestroyWindow(dpy, c->title);
183 for(l=&clients; *l && *l != c; l=&(*l)->next);
186 for(l=&stack; *l && *l != c; l=&(*l)->snext);
192 XSetErrorHandler(error_handler);
194 discard_events(EnterWindowMask);
204 for(c = clients; c; c = c->next)
211 draw_client(Client *c)
216 c->tw = textwidth(&brush.font, c->name) + labelheight(&brush.font);
217 c->tx = c->x + c->w - c->tw + 2;
219 XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
221 brush.rect.x = brush.rect.y = 0;
222 brush.rect.width = c->tw;
223 brush.rect.height = c->th;
225 draw(dpy, &brush, True, c->name);
226 XCopyArea(dpy, brush.drawable, c->title, brush.gc,
227 0, 0, c->tw, c->th, 0, 0);