2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
14 resize_title(Client *c)
16 c->tw = textw(&brush.font, c->name) + bh;
19 c->tx = c->x + c->w - c->tw + 2;
21 XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
25 update_name(Client *c)
33 XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]);
35 XGetWMName(dpy, c->win, &name);
38 if(name.encoding == XA_STRING)
39 strncpy(c->name, (char *)name.value, sizeof(c->name));
41 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
44 strncpy(c->name, *list, sizeof(c->name));
45 XFreeStringList(list);
53 update_size(Client *c)
57 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
59 c->flags = size.flags;
60 if(c->flags & PBaseSize) {
61 c->basew = size.base_width;
62 c->baseh = size.base_height;
65 c->basew = c->baseh = 0;
66 if(c->flags & PResizeInc) {
67 c->incw = size.width_inc;
68 c->inch = size.height_inc;
71 c->incw = c->inch = 0;
72 if(c->flags & PMaxSize) {
73 c->maxw = size.max_width;
74 c->maxh = size.max_height;
77 c->maxw = c->maxh = 0;
78 if(c->flags & PMinSize) {
79 c->minw = size.min_width;
80 c->minh = size.min_height;
83 c->minw = c->minh = 0;
89 XRaiseWindow(dpy, c->win);
90 XRaiseWindow(dpy, c->title);
96 XLowerWindow(dpy, c->title);
97 XLowerWindow(dpy, c->win);
106 for(l = &stack; *l && *l != c; l = &(*l)->snext);
111 if(old && old != c) {
112 XMapWindow(dpy, old->title);
115 XUnmapWindow(dpy, c->title);
117 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
122 manage(Window w, XWindowAttributes *wa)
125 XSetWindowAttributes twa;
127 c = emallocz(sizeof(Client));
129 c->tx = c->x = wa->x;
130 c->ty = c->y = wa->y;
133 c->tw = c->w = wa->width;
137 XSetWindowBorderWidth(dpy, c->win, 1);
138 XSetWindowBorder(dpy, c->win, brush.border);
139 XSelectInput(dpy, c->win,
140 StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
141 XGetTransientForHint(dpy, c->win, &c->trans);
142 twa.override_redirect = 1;
143 twa.background_pixmap = ParentRelative;
144 twa.event_mask = ExposureMask;
146 c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
147 0, DefaultDepth(dpy, screen), CopyFromParent,
148 DefaultVisual(dpy, screen),
149 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
152 for(l=&clients; *l; l=&(*l)->next);
153 c->next = *l; /* *l == nil */
157 XMapRaised(dpy, c->win);
158 XMapRaised(dpy, c->title);
159 XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
160 GrabModeAsync, GrabModeSync, None, None);
161 XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask,
162 GrabModeAsync, GrabModeSync, None, None);
163 XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask,
164 GrabModeAsync, GrabModeSync, None, None);
175 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
176 e.type = ConfigureNotify;
185 e.override_redirect = False;
186 XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
191 dummy_error_handler(Display *dpy, XErrorEvent *error)
202 XSetErrorHandler(dummy_error_handler);
204 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
205 XDestroyWindow(dpy, c->title);
207 for(l=&clients; *l && *l != c; l=&(*l)->next);
210 for(l=&stack; *l && *l != c; l=&(*l)->snext);
216 XSetErrorHandler(error_handler);
226 for(c = clients; c; c = c->next)
236 for(c = clients; c; c = c->next)
243 draw_client(Client *c)
250 brush.x = brush.y = 0;
254 draw(dpy, &brush, True, c->name);
255 XCopyArea(dpy, brush.drawable, c->title, brush.gc,
256 0, 0, c->tw, c->th, 0, 0);