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)))
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, BUTTONMASK,
248 GrabModeAsync, GrabModeSync, None, None);
249 XGrabButton(dpy, Button2, MODKEY, c->win, False, BUTTONMASK,
250 GrabModeAsync, GrabModeSync, None, None);
251 XGrabButton(dpy, Button3, MODKEY, c->win, False, BUTTONMASK,
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 */
263 XMapRaised(dpy, c->win);
264 XMapRaised(dpy, c->title);
270 resize(Client *c, Bool sizehints, Corner sticky)
272 int bottom = c->y + c->h;
273 int right = c->x + c->w;
278 c->w -= (c->w - c->basew) % c->incw;
280 c->h -= (c->h - c->baseh) % c->inch;
281 if(c->minw && c->w < c->minw)
283 if(c->minh && c->h < c->minh)
285 if(c->maxw && c->w > c->maxw)
287 if(c->maxh && c->h > c->maxh)
290 if(c->x > sw) /* might happen on restart */
294 if(sticky == TopRight || sticky == BotRight)
296 if(sticky == BotLeft || sticky == BotRight)
297 c->y = bottom - c->h;
300 XSetWindowBorderWidth(dpy, c->win, 1);
301 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
303 e.type = ConfigureNotify;
310 e.border_width = c->border;
312 e.override_redirect = False;
313 XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
323 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
325 c->flags = size.flags;
326 if(c->flags & PBaseSize) {
327 c->basew = size.base_width;
328 c->baseh = size.base_height;
331 c->basew = c->baseh = 0;
332 if(c->flags & PResizeInc) {
333 c->incw = size.width_inc;
334 c->inch = size.height_inc;
337 c->incw = c->inch = 0;
338 if(c->flags & PMaxSize) {
339 c->maxw = size.max_width;
340 c->maxh = size.max_height;
343 c->maxw = c->maxh = 0;
344 if(c->flags & PMinSize) {
345 c->minw = size.min_width;
346 c->minh = size.min_height;
349 c->minw = c->minh = 0;
350 if(c->flags & PWinGravity)
351 c->grav = size.win_gravity;
353 c->grav = NorthWestGravity;
365 XGetTextProperty(dpy, c->win, &name, netatom[NetWMName]);
367 XGetWMName(dpy, c->win, &name);
370 if(name.encoding == XA_STRING)
371 strncpy(c->name, (char *)name.value, sizeof(c->name));
373 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
376 strncpy(c->name, *list, sizeof(c->name));
377 XFreeStringList(list);
393 if((sel->ismax = !sel->ismax)) {
400 sel->w = sw - 2 * sel->border;
401 sel->h = sh - 2 * sel->border - bh;
404 resize(sel, False, TopLeft);
412 resize(sel, False, TopLeft);
413 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
420 XSetErrorHandler(xerrordummy);
422 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
423 XDestroyWindow(dpy, c->title);
426 c->prev->next = c->next;
428 c->next->prev = c->prev;
432 sel = getnext(c->next);
434 sel = getprev(c->prev);
441 XSetErrorHandler(xerror);
456 if(sel == getnext(clients) && sel->next) {
457 if((c = getnext(sel->next)))
463 sel->prev->next = sel->next;
465 sel->next->prev = sel->prev;