2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
10 #include <X11/Xutil.h>
12 /* static functions */
15 resizetitle(Client *c)
20 for(i = 0; i < TLast; i++)
22 c->bw += textw(c->tags[i]);
23 c->bw += textw(c->name);
26 c->bx = *c->x + *c->w - c->bw + 2;
28 XMoveResizeWindow(dpy, c->title, c->bx, c->by, c->bw, c->bh);
32 xerrordummy(Display *dsply, XErrorEvent *ee)
37 /* extern functions */
42 XMoveWindow(dpy, c->win, *c->x + 2 * sw, *c->y);
43 XMoveWindow(dpy, c->title, c->bx + 2 * sw, c->by);
56 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
58 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
69 if(!(c = getnext(sel->next, tsel)))
70 c = getnext(clients, tsel);
86 if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) {
96 for(c = clients; c; c = c->next)
106 for(c = clients; c; c = c->next)
113 gravitate(Client *c, Bool invert)
119 case NorthWestGravity:
121 case NorthEastGravity:
127 dy = -(*c->h / 2) + c->border;
129 case SouthEastGravity:
131 case SouthWestGravity:
140 case NorthWestGravity:
142 case SouthWestGravity:
148 dx = -(*c->w / 2) + c->border;
150 case NorthEastGravity:
152 case SouthEastGravity:
153 dx = -(*c->w + c->border);
170 XRaiseWindow(dpy, c->win);
171 XRaiseWindow(dpy, c->title);
179 if(sel->proto & WM_PROTOCOL_DELWIN)
180 sendevent(sel->win, wmatom[WMProtocols], wmatom[WMDelete]);
182 XKillClient(dpy, sel->win);
188 XLowerWindow(dpy, c->title);
189 XLowerWindow(dpy, c->win);
193 manage(Window w, XWindowAttributes *wa)
197 XSetWindowAttributes twa;
200 c = emallocz(sizeof(Client));
202 c->bx = c->fx = c->tx = wa->x;
203 c->by = c->fy = c->ty = wa->y;
204 c->bw = c->fw = c->tw = wa->width;
205 c->fh = c->th = wa->height;
209 c->fx = random() % (diff ? diff : 1);
210 diff = sh - c->fh - bh;
211 c->fy = random() % (diff ? diff : 1);
214 c->by = c->fy = c->ty = bh;
217 c->proto = getproto(c->win);
219 XSelectInput(dpy, c->win,
220 StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
221 XGetTransientForHint(dpy, c->win, &trans);
222 twa.override_redirect = 1;
223 twa.background_pixmap = ParentRelative;
224 twa.event_mask = ExposureMask;
226 c->title = XCreateWindow(dpy, root, c->bx, c->by, c->bw, c->bh,
227 0, DefaultDepth(dpy, screen), CopyFromParent,
228 DefaultVisual(dpy, screen),
229 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
236 XGrabButton(dpy, Button1, ControlMask, c->win, False, ButtonPressMask,
237 GrabModeAsync, GrabModeSync, None, None);
238 XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
239 GrabModeAsync, GrabModeSync, None, None);
240 XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask,
241 GrabModeAsync, GrabModeSync, None, None);
242 XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask,
243 GrabModeAsync, GrabModeSync, None, None);
247 || ((c->maxw == c->minw) && (c->maxh == c->minh));
254 /* mapping the window now prevents flicker */
256 XMapRaised(dpy, c->win);
257 XMapRaised(dpy, c->title);
262 XMapRaised(dpy, c->win);
263 XMapRaised(dpy, c->title);
275 *sel->w = sw - 2 * sel->border;
276 *sel->h = sh - 2 * sel->border - bh;
278 resize(sel, False, TopLeft);
285 for(l = &clients; *l && *l != c; l = &(*l)->next);
288 c->next = clients; /* pop */
294 resize(Client *c, Bool inc, Corner sticky)
297 int right = *c->x + *c->w;
298 int bottom = *c->y + *c->h;
302 *c->w -= (*c->w - c->basew) % c->incw;
304 *c->h -= (*c->h - c->baseh) % c->inch;
306 if(*c->x > sw) /* might happen on restart */
310 if(c->minw && *c->w < c->minw)
312 if(c->minh && *c->h < c->minh)
314 if(c->maxw && *c->w > c->maxw)
316 if(c->maxh && *c->h > c->maxh)
318 if(sticky == TopRight || sticky == BottomRight)
319 *c->x = right - *c->w;
320 if(sticky == BottomLeft || sticky == BottomRight)
321 *c->y = bottom - *c->h;
323 XSetWindowBorderWidth(dpy, c->win, 1);
324 XMoveResizeWindow(dpy, c->win, *c->x, *c->y, *c->w, *c->h);
325 e.type = ConfigureNotify;
332 e.border_width = c->border;
334 e.override_redirect = False;
335 XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
342 if((arrange == dotile) && !c->isfloat) {
361 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
363 c->flags = size.flags;
364 if(c->flags & PBaseSize) {
365 c->basew = size.base_width;
366 c->baseh = size.base_height;
369 c->basew = c->baseh = 0;
370 if(c->flags & PResizeInc) {
371 c->incw = size.width_inc;
372 c->inch = size.height_inc;
375 c->incw = c->inch = 0;
376 if(c->flags & PMaxSize) {
377 c->maxw = size.max_width;
378 c->maxh = size.max_height;
381 c->maxw = c->maxh = 0;
382 if(c->flags & PMinSize) {
383 c->minw = size.min_width;
384 c->minh = size.min_height;
387 c->minw = c->minh = 0;
388 if(c->flags & PWinGravity)
389 c->grav = size.win_gravity;
391 c->grav = NorthWestGravity;
403 XGetTextProperty(dpy, c->win, &name, netatom[NetWMName]);
405 XGetWMName(dpy, c->win, &name);
408 if(name.encoding == XA_STRING)
409 strncpy(c->name, (char *)name.value, sizeof(c->name));
411 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
414 strncpy(c->name, *list, sizeof(c->name));
415 XFreeStringList(list);
428 XSetErrorHandler(xerrordummy);
430 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
431 XDestroyWindow(dpy, c->title);
433 for(l = &clients; *l && *l != c; l = &(*l)->next);
435 for(l = &clients; *l; l = &(*l)->next)
436 if((*l)->revert == c)
439 sel = sel->revert ? sel->revert : clients;
444 XSetErrorHandler(xerror);
459 if(sel == getnext(clients, tsel) && sel->next) {
460 if((c = getnext(sel->next, tsel)))