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)
196 XSetWindowAttributes twa;
199 c = emallocz(sizeof(Client));
201 c->bx = c->fx = c->tx = wa->x;
202 c->by = c->fy = c->ty = wa->y;
204 c->by = c->fy = c->ty += bh;
205 c->bw = c->fw = c->tw = wa->width;
206 c->fh = c->th = wa->height;
209 c->proto = getproto(c->win);
211 XSelectInput(dpy, c->win,
212 StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
213 XGetTransientForHint(dpy, c->win, &trans);
214 twa.override_redirect = 1;
215 twa.background_pixmap = ParentRelative;
216 twa.event_mask = ExposureMask;
218 c->title = XCreateWindow(dpy, root, c->bx, c->by, c->bw, c->bh,
219 0, DefaultDepth(dpy, screen), CopyFromParent,
220 DefaultVisual(dpy, screen),
221 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
228 XGrabButton(dpy, Button1, ControlMask, c->win, False, ButtonPressMask,
229 GrabModeAsync, GrabModeSync, None, None);
230 XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
231 GrabModeAsync, GrabModeSync, None, None);
232 XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask,
233 GrabModeAsync, GrabModeSync, None, None);
234 XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask,
235 GrabModeAsync, GrabModeSync, None, None);
239 || ((c->maxw == c->minw) && (c->maxh == c->minh));
246 /* mapping the window now prevents flicker */
248 XMapRaised(dpy, c->win);
249 XMapRaised(dpy, c->title);
254 XMapRaised(dpy, c->win);
255 XMapRaised(dpy, c->title);
267 *sel->w = sw - 2 * sel->border;
268 *sel->h = sh - 2 * sel->border - bh;
270 resize(sel, False, TopLeft);
277 for(l = &clients; *l && *l != c; l = &(*l)->next);
280 c->next = clients; /* pop */
286 resize(Client *c, Bool inc, Corner sticky)
289 int right = *c->x + *c->w;
290 int bottom = *c->y + *c->h;
294 *c->w -= (*c->w - c->basew) % c->incw;
296 *c->h -= (*c->h - c->baseh) % c->inch;
298 if(*c->x > sw) /* might happen on restart */
302 if(c->minw && *c->w < c->minw)
304 if(c->minh && *c->h < c->minh)
306 if(c->maxw && *c->w > c->maxw)
308 if(c->maxh && *c->h > c->maxh)
310 if(sticky == TopRight || sticky == BottomRight)
311 *c->x = right - *c->w;
312 if(sticky == BottomLeft || sticky == BottomRight)
313 *c->y = bottom - *c->h;
315 XSetWindowBorderWidth(dpy, c->win, 1);
316 XMoveResizeWindow(dpy, c->win, *c->x, *c->y, *c->w, *c->h);
317 e.type = ConfigureNotify;
324 e.border_width = c->border;
326 e.override_redirect = False;
327 XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
334 if((arrange == dotile) && !c->isfloat) {
353 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
355 c->flags = size.flags;
356 if(c->flags & PBaseSize) {
357 c->basew = size.base_width;
358 c->baseh = size.base_height;
361 c->basew = c->baseh = 0;
362 if(c->flags & PResizeInc) {
363 c->incw = size.width_inc;
364 c->inch = size.height_inc;
367 c->incw = c->inch = 0;
368 if(c->flags & PMaxSize) {
369 c->maxw = size.max_width;
370 c->maxh = size.max_height;
373 c->maxw = c->maxh = 0;
374 if(c->flags & PMinSize) {
375 c->minw = size.min_width;
376 c->minh = size.min_height;
379 c->minw = c->minh = 0;
380 if(c->flags & PWinGravity)
381 c->grav = size.win_gravity;
383 c->grav = NorthWestGravity;
395 XGetTextProperty(dpy, c->win, &name, netatom[NetWMName]);
397 XGetWMName(dpy, c->win, &name);
400 if(name.encoding == XA_STRING)
401 strncpy(c->name, (char *)name.value, sizeof(c->name));
403 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
406 strncpy(c->name, *list, sizeof(c->name));
407 XFreeStringList(list);
420 XSetErrorHandler(xerrordummy);
422 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
423 XDestroyWindow(dpy, c->title);
425 for(l = &clients; *l && *l != c; l = &(*l)->next);
427 for(l = &clients; *l; l = &(*l)->next)
428 if((*l)->revert == c)
431 sel = sel->revert ? sel->revert : clients;
436 XSetErrorHandler(xerror);
451 if(sel == getnext(clients, tsel) && sel->next) {
452 if((c = getnext(sel->next, tsel)))