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);
226 for(l = &clients; *l; l = &(*l)->next);
227 c->next = *l; /* *l == nil */
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));
242 /* mapping the window now prevents flicker */
244 XMapRaised(dpy, c->win);
245 XMapRaised(dpy, c->title);
250 XMapRaised(dpy, c->win);
251 XMapRaised(dpy, c->title);
262 sel->w = sw - 2 * sel->border;
263 sel->h = sh - 2 * sel->border - bh;
269 resize(Client *c, Bool inc)
275 c->w -= (c->w - c->basew) % c->incw;
277 c->h -= (c->h - c->baseh) % c->inch;
279 if(c->x > sw) /* might happen on restart */
282 c->ty = c->y = sh - c->h;
283 if(c->minw && c->w < c->minw)
285 if(c->minh && c->h < c->minh)
287 if(c->maxw && c->w > c->maxw)
289 if(c->maxh && c->h > c->maxh)
292 XSetWindowBorderWidth(dpy, c->win, 1);
293 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
294 e.type = ConfigureNotify;
301 e.border_width = c->border;
303 e.override_redirect = False;
304 XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
313 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
315 c->flags = size.flags;
316 if(c->flags & PBaseSize) {
317 c->basew = size.base_width;
318 c->baseh = size.base_height;
321 c->basew = c->baseh = 0;
322 if(c->flags & PResizeInc) {
323 c->incw = size.width_inc;
324 c->inch = size.height_inc;
327 c->incw = c->inch = 0;
328 if(c->flags & PMaxSize) {
329 c->maxw = size.max_width;
330 c->maxh = size.max_height;
333 c->maxw = c->maxh = 0;
334 if(c->flags & PMinSize) {
335 c->minw = size.min_width;
336 c->minh = size.min_height;
339 c->minw = c->minh = 0;
340 if(c->flags & PWinGravity)
341 c->grav = size.win_gravity;
343 c->grav = NorthWestGravity;
355 XGetTextProperty(dpy, c->win, &name, netatom[NetWMName]);
357 XGetWMName(dpy, c->win, &name);
360 if(name.encoding == XA_STRING)
361 strncpy(c->name, (char *)name.value, sizeof(c->name));
363 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
366 strncpy(c->name, *list, sizeof(c->name));
367 XFreeStringList(list);
380 XSetErrorHandler(xerrordummy);
382 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
383 XDestroyWindow(dpy, c->title);
385 for(l = &clients; *l && *l != c; l = &(*l)->next);
387 for(l = &clients; *l; l = &(*l)->next)
388 if((*l)->revert == c)
391 sel = sel->revert ? sel->revert : clients;
396 XSetErrorHandler(xerror);
411 if(sel == getnext(clients) && sel->next) {
412 if((c = getnext(sel->next)))
416 for(l = &clients; *l && *l != sel; l = &(*l)->next);
419 sel->next = clients; /* pop */