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));
76 if(!(c = getnext(sel->next, tsel)))
77 c = getnext(clients, tsel);
95 if(!(c = getprev(sel->prev))) {
96 for(c = clients; c && c->next; c = c->next);
110 for(c = clients; c; c = c->next)
121 for(c = clients; c; c = c->next)
128 gravitate(Client *c, Bool invert)
136 case NorthWestGravity:
138 case NorthEastGravity:
144 dy = -(c->h / 2) + c->border;
146 case SouthEastGravity:
148 case SouthWestGravity:
157 case NorthWestGravity:
159 case SouthWestGravity:
165 dx = -(c->w / 2) + c->border;
167 case NorthEastGravity:
169 case SouthEastGravity:
170 dx = -(c->w + c->border);
185 XRaiseWindow(dpy, c->win);
186 XRaiseWindow(dpy, c->title);
194 if(sel->proto & WM_PROTOCOL_DELWIN)
195 sendevent(sel->win, wmatom[WMProtocols], wmatom[WMDelete]);
197 XKillClient(dpy, sel->win);
203 XLowerWindow(dpy, c->title);
204 XLowerWindow(dpy, c->win);
208 manage(Window w, XWindowAttributes *wa)
212 XSetWindowAttributes twa;
214 c = emallocz(sizeof(Client));
216 c->x = c->tx = wa->x;
217 c->y = c->ty = wa->y;
218 c->w = c->tw = wa->width;
226 c->proto = getproto(c->win);
228 XSelectInput(dpy, c->win,
229 StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
230 XGetTransientForHint(dpy, c->win, &trans);
231 twa.override_redirect = 1;
232 twa.background_pixmap = ParentRelative;
233 twa.event_mask = ExposureMask;
235 c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
236 0, DefaultDepth(dpy, screen), CopyFromParent,
237 DefaultVisual(dpy, screen),
238 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
247 XGrabButton(dpy, Button1, MODKEY, c->win, False, ButtonPressMask,
248 GrabModeAsync, GrabModeSync, None, None);
249 XGrabButton(dpy, Button2, MODKEY, c->win, False, ButtonPressMask,
250 GrabModeAsync, GrabModeSync, None, None);
251 XGrabButton(dpy, Button3, MODKEY, c->win, False, ButtonPressMask,
252 GrabModeAsync, GrabModeSync, None, None);
255 c->isfloat = trans || (c->maxw && c->minw &&
256 (c->maxw == c->minw) && (c->maxh == c->minh));
262 /* mapping the window now prevents flicker */
264 XMapRaised(dpy, c->win);
265 XMapRaised(dpy, c->title);
269 XMapRaised(dpy, c->win);
270 XMapRaised(dpy, c->title);
280 for(l = &clients; *l && *l != c; l = &(*l)->next);
282 c->prev->next = c->next;
284 c->next->prev = c->prev;
296 resize(Client *c, Bool sizehints, Corner sticky)
298 int bottom = c->y + c->h;
299 int right = c->x + c->w;
304 c->w -= (c->w - c->basew) % c->incw;
306 c->h -= (c->h - c->baseh) % c->inch;
307 if(c->minw && c->w < c->minw)
309 if(c->minh && c->h < c->minh)
311 if(c->maxw && c->w > c->maxw)
313 if(c->maxh && c->h > c->maxh)
316 if(c->x > sw) /* might happen on restart */
320 if(sticky == TopRight || sticky == BotRight)
322 if(sticky == BotLeft || sticky == BotRight)
323 c->y = bottom - c->h;
326 XSetWindowBorderWidth(dpy, c->win, 1);
327 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
329 e.type = ConfigureNotify;
336 e.border_width = c->border;
338 e.override_redirect = False;
339 XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
349 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
351 c->flags = size.flags;
352 if(c->flags & PBaseSize) {
353 c->basew = size.base_width;
354 c->baseh = size.base_height;
357 c->basew = c->baseh = 0;
358 if(c->flags & PResizeInc) {
359 c->incw = size.width_inc;
360 c->inch = size.height_inc;
363 c->incw = c->inch = 0;
364 if(c->flags & PMaxSize) {
365 c->maxw = size.max_width;
366 c->maxh = size.max_height;
369 c->maxw = c->maxh = 0;
370 if(c->flags & PMinSize) {
371 c->minw = size.min_width;
372 c->minh = size.min_height;
375 c->minw = c->minh = 0;
376 if(c->flags & PWinGravity)
377 c->grav = size.win_gravity;
379 c->grav = NorthWestGravity;
391 XGetTextProperty(dpy, c->win, &name, netatom[NetWMName]);
393 XGetWMName(dpy, c->win, &name);
396 if(name.encoding == XA_STRING)
397 strncpy(c->name, (char *)name.value, sizeof(c->name));
399 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
402 strncpy(c->name, *list, sizeof(c->name));
403 XFreeStringList(list);
419 if((sel->ismax = !sel->ismax)) {
426 sel->w = sw - 2 * sel->border;
427 sel->h = sh - 2 * sel->border - bh;
430 resize(sel, False, TopLeft);
438 resize(sel, False, TopLeft);
439 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
448 XSetErrorHandler(xerrordummy);
450 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
451 XDestroyWindow(dpy, c->title);
453 for(l = &clients; *l && *l != c; l = &(*l)->next);
455 c->prev->next = c->next;
457 c->next->prev = c->prev;
460 sel = getnext(c->next, tsel);
462 sel = getprev(c->prev);
469 XSetErrorHandler(xerror);
484 if(sel == getnext(clients, tsel) && sel->next) {
485 if((c = getnext(sel->next, tsel)))
490 for(l = &clients; *l && *l != sel; l = &(*l)->next);
492 sel->prev->next = sel->next;
494 sel->next->prev = sel->prev;