-focus(Client *c)
-{
- Client **l, *old;
-
- old = stack;
- for(l=&stack; *l && *l != c; l=&(*l)->snext);
- eassert(*l == c);
- *l = c->snext;
- c->snext = stack;
- stack = c;
- XRaiseWindow(dpy, c->win);
- XRaiseWindow(dpy, c->title);
- XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
- if(old && old != c) {
- XMapWindow(dpy, old->title);
- draw_client(old);
- }
- XUnmapWindow(dpy, c->title);
- draw_bar();
- discard_events(EnterWindowMask);
- XFlush(dpy);
-}
-
-void
-manage(Window w, XWindowAttributes *wa)
-{
- Client *c, **l;
- XSetWindowAttributes twa;
-
- c = emallocz(sizeof(Client));
- c->win = w;
- c->tx = c->x = wa->x;
- c->ty = c->y = wa->y;
- c->tw = c->w = wa->width;
- c->h = wa->height;
- c->th = barrect.height;
- update_size(c);
- XSetWindowBorderWidth(dpy, c->win, 1);
- XSetWindowBorder(dpy, c->win, brush.border);
- XSelectInput(dpy, c->win, CLIENT_MASK);
- XGetTransientForHint(dpy, c->win, &c->trans);
- twa.override_redirect = 1;
- twa.background_pixmap = ParentRelative;
- twa.event_mask = ExposureMask;
-
- c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
- 0, DefaultDepth(dpy, screen), CopyFromParent,
- DefaultVisual(dpy, screen),
- CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
- update_name(c);
-
- for(l=&clients; *l; l=&(*l)->next);
- c->next = *l; /* *l == nil */
- *l = c;
- c->snext = stack;
- stack = c;
- XMapWindow(dpy, c->win);
- XMapWindow(dpy, c->title);
- XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
- GrabModeAsync, GrabModeSync, None, None);
- XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask,
- GrabModeAsync, GrabModeSync, None, None);
- XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask,
- GrabModeAsync, GrabModeSync, None, None);
- resize(c);
- focus(c);
-}
-
-void
-resize(Client *c)
-{
- XConfigureEvent e;
-
- XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
- e.type = ConfigureNotify;
- e.event = c->win;
- e.window = c->win;
- e.x = c->x;
- e.y = c->y;
- e.width = c->w;
- e.height = c->h;
- e.border_width = 0;
- e.above = None;
- e.override_redirect = False;
- XSelectInput(dpy, c->win, CLIENT_MASK & ~StructureNotifyMask);
- XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
- XSelectInput(dpy, c->win, CLIENT_MASK);
- XFlush(dpy);
-}