2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
18 int n, cols, rows, gw, gh, i, j;
23 for(n = 0, c = clients; c; c = c->next, n++);
25 if(modff(rt, &fd) < 0.5)
35 gh = (sh - bh - 1) / rows;
37 for(i = j = 0, c = clients; c; c = c->next) {
53 const char *arg = aux;
58 if(!strncmp(arg, "next", 5))
59 c = stack->snext ? stack->snext : stack;
60 else if(!strncmp(arg, "prev", 5))
61 for(c = stack; c && c->snext; c = c->snext);
75 if(c->proto & WM_PROTOCOL_DELWIN)
76 send_message(c->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
78 XKillClient(dpy, c->win);
82 resize_title(Client *c)
84 c->tw = textw(&brush.font, c->name) + bh;
87 c->tx = c->x + c->w - c->tw + 2;
89 XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
93 update_name(Client *c)
101 XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]);
103 XGetWMName(dpy, c->win, &name);
106 if(name.encoding == XA_STRING)
107 strncpy(c->name, (char *)name.value, sizeof(c->name));
109 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
112 strncpy(c->name, *list, sizeof(c->name));
113 XFreeStringList(list);
121 update_size(Client *c)
125 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
127 c->flags = size.flags;
128 if(c->flags & PBaseSize) {
129 c->basew = size.base_width;
130 c->baseh = size.base_height;
133 c->basew = c->baseh = 0;
134 if(c->flags & PResizeInc) {
135 c->incw = size.width_inc;
136 c->inch = size.height_inc;
139 c->incw = c->inch = 0;
140 if(c->flags & PMaxSize) {
141 c->maxw = size.max_width;
142 c->maxh = size.max_height;
145 c->maxw = c->maxh = 0;
146 if(c->flags & PMinSize) {
147 c->minw = size.min_width;
148 c->minh = size.min_height;
151 c->minw = c->minh = 0;
157 XRaiseWindow(dpy, c->win);
158 XRaiseWindow(dpy, c->title);
164 XLowerWindow(dpy, c->title);
165 XLowerWindow(dpy, c->win);
174 for(l = &stack; *l && *l != c; l = &(*l)->snext);
179 if(old && old != c) {
180 XMapWindow(dpy, old->title);
183 XUnmapWindow(dpy, c->title);
185 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
190 manage(Window w, XWindowAttributes *wa)
193 XSetWindowAttributes twa;
195 c = emallocz(sizeof(Client));
197 c->tx = c->x = wa->x;
198 c->ty = c->y = wa->y;
201 c->tw = c->w = wa->width;
205 XSetWindowBorderWidth(dpy, c->win, 1);
206 XSetWindowBorder(dpy, c->win, brush.border);
207 XSelectInput(dpy, c->win,
208 StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
209 XGetTransientForHint(dpy, c->win, &c->trans);
210 twa.override_redirect = 1;
211 twa.background_pixmap = ParentRelative;
212 twa.event_mask = ExposureMask;
214 c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
215 0, DefaultDepth(dpy, screen), CopyFromParent,
216 DefaultVisual(dpy, screen),
217 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
220 for(l=&clients; *l; l=&(*l)->next);
221 c->next = *l; /* *l == nil */
225 XMapRaised(dpy, c->win);
226 XMapRaised(dpy, c->title);
227 XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
228 GrabModeAsync, GrabModeSync, None, None);
229 XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask,
230 GrabModeAsync, GrabModeSync, None, None);
231 XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask,
232 GrabModeAsync, GrabModeSync, None, None);
243 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
244 e.type = ConfigureNotify;
253 e.override_redirect = False;
254 XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
259 dummy_error_handler(Display *dpy, XErrorEvent *error)
270 XSetErrorHandler(dummy_error_handler);
272 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
273 XDestroyWindow(dpy, c->title);
275 for(l=&clients; *l && *l != c; l=&(*l)->next);
278 for(l=&stack; *l && *l != c; l=&(*l)->snext);
284 XSetErrorHandler(error_handler);
294 for(c = clients; c; c = c->next)
304 for(c = clients; c; c = c->next)
311 draw_client(Client *c)
318 brush.x = brush.y = 0;
322 draw(dpy, &brush, True, c->name);
323 XCopyArea(dpy, brush.drawable, c->title, brush.gc,
324 0, 0, c->tw, c->th, 0, 0);