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 void (*arrange)(Arg *) = tiling;
16 static Rule rule[] = {
17 /* class instance tags floating */
18 { "Firefox-bin", "Gecko", { [Twww] = "www" }, False },
24 for(; c && !c->tags[tsel]; c = c->next);
36 for(l = &clients; *l && *l != sel; l = &(*l)->next);
39 old->next = clients; /* pop */
53 sel->w = sw - 2 * sel->border;
54 sel->h = sh - 2 * sel->border;
57 discard_events(EnterWindowMask);
68 for(c = clients; c; c = next(c->next))
78 sel->tags[arg->i] = tags[arg->i];
89 for(i = 0; i < TLast; i++)
97 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
98 XMoveWindow(dpy, c->title, c->tx + 2 * sw, c->ty);
107 for(c = clients; c; c = c->next) {
113 if(sel && !sel->tags[tsel]) {
114 if((sel = next(clients))) {
119 discard_events(EnterWindowMask);
130 for(n = 0, c = clients; c; c = c->next)
131 if(c->tags[tsel] && !c->floating)
134 h = (n > 1) ? sh / (n - 1) : sh;
136 for(i = 0, c = clients; c; c = c->next) {
146 c->w = sw - 2 * c->border;
147 c->h = sh - 2 * c->border;
152 c->w = mw - 2 * c->border;
153 c->h = sh - 2 * c->border;
157 c->y = sy + (i - 1) * h;
158 c->w = w - 2 * c->border;
159 c->h = h - 2 * c->border;
167 if(sel && !sel->tags[tsel]) {
168 if((sel = next(clients))) {
173 discard_events(EnterWindowMask);
184 if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) {
198 if(!(c = next(sel->next)))
212 if(sel->proto & WM_PROTOCOL_DELWIN)
213 send_message(sel->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
215 XKillClient(dpy, sel->win);
219 resize_title(Client *c)
224 for(i = 0; i < TLast; i++)
226 c->tw += textw(c->tags[i]) + dc.font.height;
227 c->tw += textw(c->name) + dc.font.height;
230 c->tx = c->x + c->w - c->tw + 2;
232 XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
236 update_name(Client *c)
244 XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]);
246 XGetWMName(dpy, c->win, &name);
249 if(name.encoding == XA_STRING)
250 strncpy(c->name, (char *)name.value, sizeof(c->name));
252 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
255 strncpy(c->name, *list, sizeof(c->name));
256 XFreeStringList(list);
264 update_size(Client *c)
268 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
270 c->flags = size.flags;
271 if(c->flags & PBaseSize) {
272 c->basew = size.base_width;
273 c->baseh = size.base_height;
276 c->basew = c->baseh = 0;
277 if(c->flags & PResizeInc) {
278 c->incw = size.width_inc;
279 c->inch = size.height_inc;
282 c->incw = c->inch = 0;
283 if(c->flags & PMaxSize) {
284 c->maxw = size.max_width;
285 c->maxh = size.max_height;
288 c->maxw = c->maxh = 0;
289 if(c->flags & PMinSize) {
290 c->minw = size.min_width;
291 c->minh = size.min_height;
294 c->minw = c->minh = 0;
295 if(c->flags & PWinGravity)
296 c->grav = size.win_gravity;
298 c->grav = NorthWestGravity;
304 XRaiseWindow(dpy, c->win);
305 XRaiseWindow(dpy, c->title);
311 XLowerWindow(dpy, c->title);
312 XLowerWindow(dpy, c->win);
324 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
326 discard_events(EnterWindowMask);
333 static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0;
335 Bool matched = False;
338 c->tags[tsel] = tags[tsel];
342 if(XGetClassHint(dpy, c->win, &ch)) {
343 if(ch.res_class && ch.res_name) {
344 for(i = 0; i < len; i++)
345 if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class))
346 && !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance)))
348 for(j = 0; j < TLast; j++)
349 c->tags[j] = rule[i].tags[j];
350 c->floating = rule[i].floating;
362 c->tags[tsel] = tags[tsel];
366 manage(Window w, XWindowAttributes *wa)
369 XSetWindowAttributes twa;
372 c = emallocz(sizeof(Client));
374 c->tx = c->x = wa->x;
375 c->ty = c->y = wa->y;
376 c->tw = c->w = wa->width;
380 c->proto = win_proto(c->win);
382 XSelectInput(dpy, c->win,
383 StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
384 XGetTransientForHint(dpy, c->win, &trans);
385 twa.override_redirect = 1;
386 twa.background_pixmap = ParentRelative;
387 twa.event_mask = ExposureMask;
389 c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
390 0, DefaultDepth(dpy, screen), CopyFromParent,
391 DefaultVisual(dpy, screen),
392 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
397 for(l = &clients; *l; l = &(*l)->next);
398 c->next = *l; /* *l == nil */
401 XMapRaised(dpy, c->win);
402 XMapRaised(dpy, c->title);
403 XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
404 GrabModeAsync, GrabModeSync, None, None);
405 XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask,
406 GrabModeAsync, GrabModeSync, None, None);
407 XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask,
408 GrabModeAsync, GrabModeSync, None, None);
412 || ((c->maxw == c->minw) && (c->maxh == c->minh));
422 gravitate(Client *c, Bool invert)
428 case NorthWestGravity:
430 case NorthEastGravity:
436 dy = -(c->h / 2) + c->border;
438 case SouthEastGravity:
440 case SouthWestGravity:
449 case NorthWestGravity:
451 case SouthWestGravity:
457 dx = -(c->w / 2) + c->border;
459 case NorthEastGravity:
461 case SouthEastGravity:
462 dx = -(c->w + c->border);
478 resize(Client *c, Bool inc)
484 c->w -= (c->w - c->basew) % c->incw;
486 c->h -= (c->h - c->baseh) % c->inch;
488 if(c->minw && c->w < c->minw)
490 if(c->minh && c->h < c->minh)
492 if(c->maxw && c->w > c->maxw)
494 if(c->maxh && c->h > c->maxh)
497 XSetWindowBorderWidth(dpy, c->win, 1);
498 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
499 e.type = ConfigureNotify;
506 e.border_width = c->border;
508 e.override_redirect = False;
509 XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
514 dummy_error_handler(Display *dsply, XErrorEvent *err)
525 XSetErrorHandler(dummy_error_handler);
527 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
528 XDestroyWindow(dpy, c->title);
530 for(l = &clients; *l && *l != c; l = &(*l)->next);
532 for(l = &clients; *l; l = &(*l)->next)
533 if((*l)->revert == c)
536 sel = sel->revert ? sel->revert : clients;
541 XSetErrorHandler(error_handler);
552 for(c = clients; c; c = c->next)
562 for(c = clients; c; c = c->next)
569 draw_client(Client *c)
573 XUnmapWindow(dpy, c->title);
574 XSetWindowBorder(dpy, c->win, dc.fg);
578 XSetWindowBorder(dpy, c->win, dc.bg);
579 XMapWindow(dpy, c->title);
585 for(i = 0; i < TLast; i++) {
588 dc.w = textw(c->tags[i]) + dc.font.height;
589 draw(True, c->tags[i]);
593 dc.w = textw(c->name) + dc.font.height;
595 XCopyArea(dpy, dc.drawable, c->title, dc.gc,
596 0, 0, c->tw, c->th, 0, 0);