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->tw += textw(c->tags[i]);
23 c->tw += textw(c->name);
26 c->tx = c->x + c->w - c->tw + 2;
29 XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
31 XMoveResizeWindow(dpy, c->title, c->tx + 2 * sw, c->ty, c->tw, c->th);
36 xerrordummy(Display *dsply, XErrorEvent *ee)
41 /* extern functions */
46 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
47 XMoveWindow(dpy, c->title, c->tx + 2 * sw, c->ty);
60 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
62 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
73 if(!(c = getnext(sel->next, tsel)))
74 c = getnext(clients, tsel);
90 if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) {
101 for(c = clients; c; c = c->next)
112 for(c = clients; c; c = c->next)
119 gravitate(Client *c, Bool invert)
125 case NorthWestGravity:
127 case NorthEastGravity:
133 dy = -(c->h / 2) + c->border;
135 case SouthEastGravity:
137 case SouthWestGravity:
146 case NorthWestGravity:
148 case SouthWestGravity:
154 dx = -(c->w / 2) + c->border;
156 case NorthEastGravity:
158 case SouthEastGravity:
159 dx = -(c->w + c->border);
176 XRaiseWindow(dpy, c->win);
177 XRaiseWindow(dpy, c->title);
185 if(sel->proto & WM_PROTOCOL_DELWIN)
186 sendevent(sel->win, wmatom[WMProtocols], wmatom[WMDelete]);
188 XKillClient(dpy, sel->win);
194 XLowerWindow(dpy, c->title);
195 XLowerWindow(dpy, c->win);
199 manage(Window w, XWindowAttributes *wa)
204 XSetWindowAttributes twa;
206 c = emallocz(sizeof(Client));
208 c->x = c->tx = wa->x;
209 c->y = c->ty = wa->y;
210 c->w = c->tw = wa->width;
218 c->proto = getproto(c->win);
220 XSelectInput(dpy, c->win,
221 StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
222 XGetTransientForHint(dpy, c->win, &trans);
223 twa.override_redirect = 1;
224 twa.background_pixmap = ParentRelative;
225 twa.event_mask = ExposureMask;
227 c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
228 0, DefaultDepth(dpy, screen), CopyFromParent,
229 DefaultVisual(dpy, screen),
230 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
237 XGrabButton(dpy, Button1, ControlMask, c->win, False, ButtonPressMask,
238 GrabModeAsync, GrabModeSync, None, None);
239 XGrabButton(dpy, Button1, MODKEY, c->win, False, ButtonPressMask,
240 GrabModeAsync, GrabModeSync, None, None);
241 XGrabButton(dpy, Button2, MODKEY, c->win, False, ButtonPressMask,
242 GrabModeAsync, GrabModeSync, None, None);
243 XGrabButton(dpy, Button3, MODKEY, c->win, False, ButtonPressMask,
244 GrabModeAsync, GrabModeSync, None, None);
247 c->isfloat = trans || (c->maxw && c->minw &&
248 (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);
261 XMapRaised(dpy, c->win);
262 XMapRaised(dpy, c->title);
273 sel->w = sw - 2 * sel->border;
274 sel->h = sh - 2 * sel->border - bh;
276 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)
295 int bottom = c->y + c->h;
296 int right = c->x + c->w;
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 == BotRight)
319 if(sticky == BotLeft || sticky == BotRight)
320 c->y = bottom - c->h;
323 XSetWindowBorderWidth(dpy, c->win, 1);
324 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
326 e.type = ConfigureNotify;
333 e.border_width = c->border;
335 e.override_redirect = False;
336 XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
346 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
348 c->flags = size.flags;
349 if(c->flags & PBaseSize) {
350 c->basew = size.base_width;
351 c->baseh = size.base_height;
354 c->basew = c->baseh = 0;
355 if(c->flags & PResizeInc) {
356 c->incw = size.width_inc;
357 c->inch = size.height_inc;
360 c->incw = c->inch = 0;
361 if(c->flags & PMaxSize) {
362 c->maxw = size.max_width;
363 c->maxh = size.max_height;
366 c->maxw = c->maxh = 0;
367 if(c->flags & PMinSize) {
368 c->minw = size.min_width;
369 c->minh = size.min_height;
372 c->minw = c->minh = 0;
373 if(c->flags & PWinGravity)
374 c->grav = size.win_gravity;
376 c->grav = NorthWestGravity;
388 XGetTextProperty(dpy, c->win, &name, netatom[NetWMName]);
390 XGetWMName(dpy, c->win, &name);
393 if(name.encoding == XA_STRING)
394 strncpy(c->name, (char *)name.value, sizeof(c->name));
396 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
399 strncpy(c->name, *list, sizeof(c->name));
400 XFreeStringList(list);
413 XSetErrorHandler(xerrordummy);
415 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
416 XDestroyWindow(dpy, c->title);
418 for(l = &clients; *l && *l != c; l = &(*l)->next);
420 for(l = &clients; *l; l = &(*l)->next)
421 if((*l)->revert == c)
424 sel = sel->revert ? sel->revert : clients;
429 XSetErrorHandler(xerror);
444 if(sel == getnext(clients, tsel) && sel->next) {
445 if((c = getnext(sel->next, tsel)))