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;
28 XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
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->tx + 2 * sw, c->ty);
56 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
58 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
69 if(!(c = getnext(sel->next)))
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->tx = c->x = wa->x;
202 c->ty = c->y = wa->y;
205 c->tw = c->w = wa->width;
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->tx, c->ty, c->tw, c->th,
219 0, DefaultDepth(dpy, screen), CopyFromParent,
220 DefaultVisual(dpy, screen),
221 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
229 XGrabButton(dpy, Button1, ControlMask, c->win, False, ButtonPressMask,
230 GrabModeAsync, GrabModeSync, None, None);
231 XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
232 GrabModeAsync, GrabModeSync, None, None);
233 XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask,
234 GrabModeAsync, GrabModeSync, None, None);
235 XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask,
236 GrabModeAsync, GrabModeSync, None, None);
240 || ((c->maxw == c->minw) && (c->maxh == c->minh));
243 /* mapping the window now prevents flicker */
245 XMapRaised(dpy, c->win);
246 XMapRaised(dpy, c->title);
251 XMapRaised(dpy, c->win);
252 XMapRaised(dpy, c->title);
263 sel->w = sw - 2 * sel->border;
264 sel->h = sh - 2 * sel->border - bh;
270 resize(Client *c, Bool inc)
276 c->w -= (c->w - c->basew) % c->incw;
278 c->h -= (c->h - c->baseh) % c->inch;
280 if(c->x > sw) /* might happen on restart */
283 c->ty = c->y = sh - c->h;
284 if(c->minw && c->w < c->minw)
286 if(c->minh && c->h < c->minh)
288 if(c->maxw && c->w > c->maxw)
290 if(c->maxh && c->h > c->maxh)
293 XSetWindowBorderWidth(dpy, c->win, 1);
294 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
295 e.type = ConfigureNotify;
302 e.border_width = c->border;
304 e.override_redirect = False;
305 XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
314 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
316 c->flags = size.flags;
317 if(c->flags & PBaseSize) {
318 c->basew = size.base_width;
319 c->baseh = size.base_height;
322 c->basew = c->baseh = 0;
323 if(c->flags & PResizeInc) {
324 c->incw = size.width_inc;
325 c->inch = size.height_inc;
328 c->incw = c->inch = 0;
329 if(c->flags & PMaxSize) {
330 c->maxw = size.max_width;
331 c->maxh = size.max_height;
334 c->maxw = c->maxh = 0;
335 if(c->flags & PMinSize) {
336 c->minw = size.min_width;
337 c->minh = size.min_height;
340 c->minw = c->minh = 0;
341 if(c->flags & PWinGravity)
342 c->grav = size.win_gravity;
344 c->grav = NorthWestGravity;
356 XGetTextProperty(dpy, c->win, &name, netatom[NetWMName]);
358 XGetWMName(dpy, c->win, &name);
361 if(name.encoding == XA_STRING)
362 strncpy(c->name, (char *)name.value, sizeof(c->name));
364 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
367 strncpy(c->name, *list, sizeof(c->name));
368 XFreeStringList(list);
381 XSetErrorHandler(xerrordummy);
383 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
384 XDestroyWindow(dpy, c->title);
386 for(l = &clients; *l && *l != c; l = &(*l)->next);
388 for(l = &clients; *l; l = &(*l)->next)
389 if((*l)->revert == c)
392 sel = sel->revert ? sel->revert : clients;
397 XSetErrorHandler(xerror);
412 if(sel == getnext(clients) && sel->next) {
413 if((c = getnext(sel->next)))
417 for(l = &clients; *l && *l != sel; l = &(*l)->next);
420 sel->next = clients; /* pop */