2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
22 stack->h = sh - bh - 2;
30 int n, cols, rows, gw, gh, i, j;
35 for(n = 0, c = clients; c; c = c->next, n++);
37 if(modff(rt, &fd) < 0.5)
47 gh = (sh - bh - 1) / rows;
49 for(i = j = 0, c = clients; c; c = c->next) {
65 const char *arg = aux;
70 if(!strncmp(arg, "next", 5))
71 c = stack->snext ? stack->snext : stack;
72 else if(!strncmp(arg, "prev", 5))
73 for(c = stack; c && c->snext; c = c->snext);
87 if(c->proto & WM_PROTOCOL_DELWIN)
88 send_message(c->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
90 XKillClient(dpy, c->win);
94 resize_title(Client *c)
96 c->tw = textw(&brush.font, c->name) + bh;
99 c->tx = c->x + c->w - c->tw + 2;
101 XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
105 update_name(Client *c)
113 XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]);
115 XGetWMName(dpy, c->win, &name);
118 if(name.encoding == XA_STRING)
119 strncpy(c->name, (char *)name.value, sizeof(c->name));
121 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
124 strncpy(c->name, *list, sizeof(c->name));
125 XFreeStringList(list);
133 update_size(Client *c)
137 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
139 c->flags = size.flags;
140 if(c->flags & PBaseSize) {
141 c->basew = size.base_width;
142 c->baseh = size.base_height;
145 c->basew = c->baseh = 0;
146 if(c->flags & PResizeInc) {
147 c->incw = size.width_inc;
148 c->inch = size.height_inc;
151 c->incw = c->inch = 0;
152 if(c->flags & PMaxSize) {
153 c->maxw = size.max_width;
154 c->maxh = size.max_height;
157 c->maxw = c->maxh = 0;
158 if(c->flags & PMinSize) {
159 c->minw = size.min_width;
160 c->minh = size.min_height;
163 c->minw = c->minh = 0;
169 XRaiseWindow(dpy, c->win);
170 XRaiseWindow(dpy, c->title);
176 XLowerWindow(dpy, c->title);
177 XLowerWindow(dpy, c->win);
186 for(l = &stack; *l && *l != c; l = &(*l)->snext);
191 if(old && old != c) {
192 XMapWindow(dpy, old->title);
195 XUnmapWindow(dpy, c->title);
197 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
202 manage(Window w, XWindowAttributes *wa)
205 XSetWindowAttributes twa;
207 c = emallocz(sizeof(Client));
209 c->tx = c->x = wa->x;
210 c->ty = c->y = wa->y;
213 c->tw = c->w = wa->width;
217 XSetWindowBorderWidth(dpy, c->win, 1);
218 XSetWindowBorder(dpy, c->win, brush.border);
219 XSelectInput(dpy, c->win,
220 StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
221 XGetTransientForHint(dpy, c->win, &c->trans);
222 twa.override_redirect = 1;
223 twa.background_pixmap = ParentRelative;
224 twa.event_mask = ExposureMask;
226 c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
227 0, DefaultDepth(dpy, screen), CopyFromParent,
228 DefaultVisual(dpy, screen),
229 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
232 for(l=&clients; *l; l=&(*l)->next);
233 c->next = *l; /* *l == nil */
237 XMapRaised(dpy, c->win);
238 XMapRaised(dpy, c->title);
239 XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
240 GrabModeAsync, GrabModeSync, None, None);
241 XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask,
242 GrabModeAsync, GrabModeSync, None, None);
243 XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask,
244 GrabModeAsync, GrabModeSync, None, None);
255 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
256 e.type = ConfigureNotify;
265 e.override_redirect = False;
266 XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
271 dummy_error_handler(Display *dpy, XErrorEvent *error)
282 XSetErrorHandler(dummy_error_handler);
284 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
285 XDestroyWindow(dpy, c->title);
287 for(l=&clients; *l && *l != c; l=&(*l)->next);
290 for(l=&stack; *l && *l != c; l=&(*l)->snext);
296 XSetErrorHandler(error_handler);
306 for(c = clients; c; c = c->next)
316 for(c = clients; c; c = c->next)
323 draw_client(Client *c)
330 brush.x = brush.y = 0;
334 draw(dpy, &brush, True, c->name);
335 XCopyArea(dpy, brush.drawable, c->title, brush.gc,
336 0, 0, c->tw, c->th, 0, 0);