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));
112 XSetWindowBorderWidth(dpy, c->win, 1);
113 XSelectInput(dpy, c->win, CLIENT_MASK);
114 XGetTransientForHint(dpy, c->win, &c->trans);
115 twa.override_redirect = 1;
116 twa.background_pixmap = ParentRelative;
117 twa.event_mask = ExposureMask;
119 c->title = XCreateWindow(dpy, root, c->x, c->y, c->w, barrect.height,
120 0, DefaultDepth(dpy, screen), CopyFromParent,
121 DefaultVisual(dpy, screen),
122 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
125 for(l=&clients; *l; l=&(*l)->next);
126 c->next = *l; /* *l == nil */
130 XMapWindow(dpy, c->win);
131 XMapWindow(dpy, c->title);
132 XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
133 GrabModeAsync, GrabModeSync, None, None);
134 XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask,
135 GrabModeAsync, GrabModeSync, None, None);
136 XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask,
137 GrabModeAsync, GrabModeSync, None, None);
147 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
148 XMoveResizeWindow(dpy, c->title, c->x + c->w / 3, c->y, 2 * c->w / 3, barrect.height);
149 e.type = ConfigureNotify;
158 e.override_redirect = False;
159 XSelectInput(dpy, c->win, CLIENT_MASK & ~StructureNotifyMask);
160 XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
161 XSelectInput(dpy, c->win, CLIENT_MASK);
166 dummy_error_handler(Display *dpy, XErrorEvent *error)
177 XSetErrorHandler(dummy_error_handler);
179 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
180 XUnmapWindow(dpy, 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)
218 brush.rect.x = brush.rect.y = 0;
219 brush.rect.width = 2 * c->w / 3;
220 brush.rect.height = barrect.height;
222 draw(dpy, &brush, True, c->name);
223 XCopyArea(dpy, brush.drawable, c->title, brush.gc, 0, 0,
224 brush.rect.width, brush.rect.height, 0, 0);