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;
205 c->by = c->fy = c->ty += bh;
206 c->bw = c->fw = c->tw = wa->width;
207 c->fh = c->th = wa->height;
211 c->fx = sx + (random() % diff ? diff : 1);
213 c->fy = sx + (random() % diff ? diff : 1);
216 c->proto = getproto(c->win);
218 XSelectInput(dpy, c->win,
219 StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
220 XGetTransientForHint(dpy, c->win, &trans);
221 twa.override_redirect = 1;
222 twa.background_pixmap = ParentRelative;
223 twa.event_mask = ExposureMask;
225 c->title = XCreateWindow(dpy, root, c->bx, c->by, c->bw, c->bh,
226 0, DefaultDepth(dpy, screen), CopyFromParent,
227 DefaultVisual(dpy, screen),
228 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
235 XGrabButton(dpy, Button1, ControlMask, c->win, False, ButtonPressMask,
236 GrabModeAsync, GrabModeSync, None, None);
237 XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
238 GrabModeAsync, GrabModeSync, None, None);
239 XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask,
240 GrabModeAsync, GrabModeSync, None, None);
241 XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask,
242 GrabModeAsync, GrabModeSync, None, None);
246 || ((c->maxw == c->minw) && (c->maxh == c->minh));
253 /* mapping the window now prevents flicker */
255 XMapRaised(dpy, c->win);
256 XMapRaised(dpy, c->title);
261 XMapRaised(dpy, c->win);
262 XMapRaised(dpy, c->title);
274 *sel->w = sw - 2 * sel->border;
275 *sel->h = sh - 2 * sel->border - bh;
277 resize(sel, False, TopLeft);
284 for(l = &clients; *l && *l != c; l = &(*l)->next);
287 c->next = clients; /* pop */
293 resize(Client *c, Bool inc, Corner sticky)
296 int right = *c->x + *c->w;
297 int bottom = *c->y + *c->h;
301 *c->w -= (*c->w - c->basew) % c->incw;
303 *c->h -= (*c->h - c->baseh) % c->inch;
305 if(*c->x > sw) /* might happen on restart */
309 if(c->minw && *c->w < c->minw)
311 if(c->minh && *c->h < c->minh)
313 if(c->maxw && *c->w > c->maxw)
315 if(c->maxh && *c->h > c->maxh)
317 if(sticky == TopRight || sticky == BottomRight)
318 *c->x = right - *c->w;
319 if(sticky == BottomLeft || sticky == BottomRight)
320 *c->y = bottom - *c->h;
322 XSetWindowBorderWidth(dpy, c->win, 1);
323 XMoveResizeWindow(dpy, c->win, *c->x, *c->y, *c->w, *c->h);
324 e.type = ConfigureNotify;
331 e.border_width = c->border;
333 e.override_redirect = False;
334 XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
341 if((arrange == dotile) && !c->isfloat) {
360 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
362 c->flags = size.flags;
363 if(c->flags & PBaseSize) {
364 c->basew = size.base_width;
365 c->baseh = size.base_height;
368 c->basew = c->baseh = 0;
369 if(c->flags & PResizeInc) {
370 c->incw = size.width_inc;
371 c->inch = size.height_inc;
374 c->incw = c->inch = 0;
375 if(c->flags & PMaxSize) {
376 c->maxw = size.max_width;
377 c->maxh = size.max_height;
380 c->maxw = c->maxh = 0;
381 if(c->flags & PMinSize) {
382 c->minw = size.min_width;
383 c->minh = size.min_height;
386 c->minw = c->minh = 0;
387 if(c->flags & PWinGravity)
388 c->grav = size.win_gravity;
390 c->grav = NorthWestGravity;
402 XGetTextProperty(dpy, c->win, &name, netatom[NetWMName]);
404 XGetWMName(dpy, c->win, &name);
407 if(name.encoding == XA_STRING)
408 strncpy(c->name, (char *)name.value, sizeof(c->name));
410 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
413 strncpy(c->name, *list, sizeof(c->name));
414 XFreeStringList(list);
427 XSetErrorHandler(xerrordummy);
429 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
430 XDestroyWindow(dpy, c->title);
432 for(l = &clients; *l && *l != c; l = &(*l)->next);
434 for(l = &clients; *l; l = &(*l)->next)
435 if((*l)->revert == c)
438 sel = sel->revert ? sel->revert : clients;
443 XSetErrorHandler(xerror);
458 if(sel == getnext(clients, tsel) && sel->next) {
459 if((c = getnext(sel->next, tsel)))