2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
10 #include <X11/Xutil.h>
14 static void (*arrange)(Arg *) = floating;
19 for(c = c->next; c && !c->tags[tsel]; c = c->next);
26 for(c = c->prev; c && !c->tags[tsel]; c = c->prev);
37 csel->w = sw - 2 * csel->border;
38 csel->h = sh - 2 * csel->border;
41 discard_events(EnterWindowMask);
53 if(csel->tags[arg->i])
54 csel->tags[arg->i] = NULL; /* toggle tag */
56 csel->tags[arg->i] = tags[arg->i];
68 for(c = csel; c; c = next(c))
70 discard_events(EnterWindowMask);
77 int n, cols, rows, gw, gh, i, j;
83 for(n = 0, c = csel; c; c = next(c), n++);
85 if(modff(rt, &fd) < 0.5)
97 for(i = j = 0, c = csel; c; c = next(c)) {
108 discard_events(EnterWindowMask);
119 if(!(c = prev(csel)))
123 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w / 2, c->h / 2);
136 if(!(c = next(csel)))
141 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w / 2, c->h / 2);
153 if(c->proto & WM_PROTOCOL_DELWIN)
154 send_message(c->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
156 XKillClient(dpy, c->win);
160 resize_title(Client *c)
165 for(i = 0; i < TLast; i++)
167 c->tw += textw(c->tags[i]) + dc.font.height;
168 c->tw += textw(c->name) + dc.font.height;
171 c->tx = c->x + c->w - c->tw + 2;
173 XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
177 update_name(Client *c)
185 XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]);
187 XGetWMName(dpy, c->win, &name);
190 if(name.encoding == XA_STRING)
191 strncpy(c->name, (char *)name.value, sizeof(c->name));
193 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
196 strncpy(c->name, *list, sizeof(c->name));
197 XFreeStringList(list);
205 update_size(Client *c)
209 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
211 c->flags = size.flags;
212 if(c->flags & PBaseSize) {
213 c->basew = size.base_width;
214 c->baseh = size.base_height;
217 c->basew = c->baseh = 0;
218 if(c->flags & PResizeInc) {
219 c->incw = size.width_inc;
220 c->inch = size.height_inc;
223 c->incw = c->inch = 0;
224 if(c->flags & PMaxSize) {
225 c->maxw = size.max_width;
226 c->maxh = size.max_height;
229 c->maxw = c->maxh = 0;
230 if(c->flags & PMinSize) {
231 c->minw = size.min_width;
232 c->minh = size.min_height;
235 c->minw = c->minh = 0;
236 if(c->flags & PWinGravity)
237 c->grav = size.win_gravity;
239 c->grav = NorthWestGravity;
245 XRaiseWindow(dpy, c->win);
246 XRaiseWindow(dpy, c->title);
252 XLowerWindow(dpy, c->title);
253 XLowerWindow(dpy, c->win);
259 if(csel && csel != c) {
260 XSetWindowBorder(dpy, csel->win, dc.bg);
261 XMapWindow(dpy, csel->title);
265 XUnmapWindow(dpy, c->title);
266 XSetWindowBorder(dpy, c->win, dc.fg);
268 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
270 discard_events(EnterWindowMask);
274 manage(Window w, XWindowAttributes *wa)
277 XSetWindowAttributes twa;
279 c = emallocz(sizeof(Client));
281 c->tx = c->x = wa->x;
282 c->ty = c->y = wa->y;
283 c->tw = c->w = wa->width;
288 XSelectInput(dpy, c->win,
289 StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
290 XGetTransientForHint(dpy, c->win, &c->trans);
291 twa.override_redirect = 1;
292 twa.background_pixmap = ParentRelative;
293 twa.event_mask = ExposureMask;
295 c->tags[tsel] = tags[tsel];
296 c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
297 0, DefaultDepth(dpy, screen), CopyFromParent,
298 DefaultVisual(dpy, screen),
299 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
311 XSetWindowBorderWidth(dpy, c->win, 1);
312 XMapRaised(dpy, c->win);
313 XMapRaised(dpy, c->title);
314 XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
315 GrabModeAsync, GrabModeSync, None, None);
316 XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask,
317 GrabModeAsync, GrabModeSync, None, None);
318 XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask,
319 GrabModeAsync, GrabModeSync, None, None);
321 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w / 2, c->h / 2);
326 gravitate(Client *c, Bool invert)
332 case NorthWestGravity:
334 case NorthEastGravity:
340 dy = -(c->h / 2) + c->border;
342 case SouthEastGravity:
344 case SouthWestGravity:
353 case NorthWestGravity:
355 case SouthWestGravity:
361 dx = -(c->w / 2) + c->border;
363 case NorthEastGravity:
365 case SouthEastGravity:
366 dx = -(c->w + c->border);
387 c->w -= (c->w - c->basew) % c->incw;
389 c->h -= (c->h - c->baseh) % c->inch;
390 if(c->minw && c->w < c->minw)
392 if(c->minh && c->h < c->minh)
394 if(c->maxw && c->w > c->maxw)
396 if(c->maxh && c->h > c->maxh)
399 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
400 e.type = ConfigureNotify;
407 e.border_width = c->border;
409 e.override_redirect = False;
410 XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
415 dummy_error_handler(Display *dsply, XErrorEvent *err)
424 XSetErrorHandler(dummy_error_handler);
426 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
427 XDestroyWindow(dpy, c->title);
430 c->prev->next = c->next;
435 c->next->prev = c->prev;
447 XSetErrorHandler(error_handler);
458 for(c = cstart; c; c = c->next)
468 for(c = cstart; c; c = c->next)
475 draw_client(Client *c)
485 for(i = 0; i < TLast; i++) {
488 dc.w = textw(c->tags[i]) + dc.font.height;
489 draw(True, c->tags[i]);
493 dc.w = textw(c->name) + dc.font.height;
495 XCopyArea(dpy, dc.drawable, c->title, dc.gc,
496 0, 0, c->tw, c->th, 0, 0);