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;
277 for(l = &clients; *l && *l != c; l = &(*l)->next);
280 c->next = clients; /* pop */
286 resize(Client *c, Bool inc)
292 *c->w -= (*c->w - c->basew) % c->incw;
294 *c->h -= (*c->h - c->baseh) % c->inch;
296 if(*c->x > sw) /* might happen on restart */
300 if(c->minw && *c->w < c->minw)
302 if(c->minh && *c->h < c->minh)
304 if(c->maxw && *c->w > c->maxw)
306 if(c->maxh && *c->h > c->maxh)
309 XSetWindowBorderWidth(dpy, c->win, 1);
310 XMoveResizeWindow(dpy, c->win, *c->x, *c->y, *c->w, *c->h);
311 e.type = ConfigureNotify;
318 e.border_width = c->border;
320 e.override_redirect = False;
321 XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
328 if((arrange == dotile) && !c->isfloat) {
347 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
349 c->flags = size.flags;
350 if(c->flags & PBaseSize) {
351 c->basew = size.base_width;
352 c->baseh = size.base_height;
355 c->basew = c->baseh = 0;
356 if(c->flags & PResizeInc) {
357 c->incw = size.width_inc;
358 c->inch = size.height_inc;
361 c->incw = c->inch = 0;
362 if(c->flags & PMaxSize) {
363 c->maxw = size.max_width;
364 c->maxh = size.max_height;
367 c->maxw = c->maxh = 0;
368 if(c->flags & PMinSize) {
369 c->minw = size.min_width;
370 c->minh = size.min_height;
373 c->minw = c->minh = 0;
374 if(c->flags & PWinGravity)
375 c->grav = size.win_gravity;
377 c->grav = NorthWestGravity;
389 XGetTextProperty(dpy, c->win, &name, netatom[NetWMName]);
391 XGetWMName(dpy, c->win, &name);
394 if(name.encoding == XA_STRING)
395 strncpy(c->name, (char *)name.value, sizeof(c->name));
397 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
400 strncpy(c->name, *list, sizeof(c->name));
401 XFreeStringList(list);
414 XSetErrorHandler(xerrordummy);
416 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
417 XDestroyWindow(dpy, c->title);
419 for(l = &clients; *l && *l != c; l = &(*l)->next);
421 for(l = &clients; *l; l = &(*l)->next)
422 if((*l)->revert == c)
425 sel = sel->revert ? sel->revert : clients;
430 XSetErrorHandler(xerror);
445 if(sel == getnext(clients, tsel) && sel->next) {
446 if((c = getnext(sel->next, tsel)))