2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
11 /* static functions */
14 resizetitle(Client *c)
19 for(i = 0; i < ntags; i++)
21 c->tw += textw(tags[i]);
22 c->tw += textw(c->name);
25 c->tx = c->x + c->w - c->tw + 2;
28 XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
30 XMoveResizeWindow(dpy, c->title, c->tx + 2 * sw, c->ty, c->tw, c->th);
35 xerrordummy(Display *dsply, XErrorEvent *ee)
40 /* extern functions */
45 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
46 XMoveWindow(dpy, c->title, c->tx + 2 * sw, c->ty);
59 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
61 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
75 if(!(c = getnext(sel->next)))
94 if(!(c = getprev(sel->prev))) {
95 for(c = clients; c && c->next; c = c->next);
109 for(c = clients; c; c = c->next)
120 for(c = clients; c; c = c->next)
127 gravitate(Client *c, Bool invert)
135 case NorthWestGravity:
137 case NorthEastGravity:
143 dy = -(c->h / 2) + c->border;
145 case SouthEastGravity:
147 case SouthWestGravity:
156 case NorthWestGravity:
158 case SouthWestGravity:
164 dx = -(c->w / 2) + c->border;
166 case NorthEastGravity:
168 case SouthEastGravity:
169 dx = -(c->w + c->border);
184 XRaiseWindow(dpy, c->win);
185 XRaiseWindow(dpy, c->title);
193 if(sel->proto & PROTODELWIN)
194 sendevent(sel->win, wmatom[WMProtocols], wmatom[WMDelete]);
196 XKillClient(dpy, sel->win);
202 XLowerWindow(dpy, c->title);
203 XLowerWindow(dpy, c->win);
207 manage(Window w, XWindowAttributes *wa)
211 XSetWindowAttributes twa;
213 c = emallocz(sizeof(Client));
214 c->tags = emallocz(ntags * sizeof(Bool));
216 c->x = c->tx = wa->x;
217 c->y = c->ty = wa->y;
218 c->w = c->tw = wa->width;
225 if(c->h != sh && c->y < bh)
228 c->proto = getproto(c->win);
229 XSelectInput(dpy, c->win,
230 StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
231 XGetTransientForHint(dpy, c->win, &trans);
232 twa.override_redirect = 1;
233 twa.background_pixmap = ParentRelative;
234 twa.event_mask = ExposureMask | EnterWindowMask;
236 c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
237 0, DefaultDepth(dpy, screen), CopyFromParent,
238 DefaultVisual(dpy, screen),
239 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
246 XGrabButton(dpy, Button1, MODKEY, c->win, False, BUTTONMASK,
247 GrabModeAsync, GrabModeSync, None, None);
248 XGrabButton(dpy, Button2, MODKEY, c->win, False, BUTTONMASK,
249 GrabModeAsync, GrabModeSync, None, None);
250 XGrabButton(dpy, Button3, MODKEY, c->win, False, BUTTONMASK,
251 GrabModeAsync, GrabModeSync, None, None);
256 || (c->maxw && c->minw &&
257 c->maxw == c->minw && c->maxh == c->minh);
261 /* mapping the window now prevents flicker */
262 XMapRaised(dpy, c->win);
263 XMapRaised(dpy, c->title);
269 resize(Client *c, Bool sizehints, Corner sticky)
271 int bottom = c->y + c->h;
272 int right = c->x + c->w;
273 /*XConfigureEvent e;*/
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 > right) /* might happen on restart */
293 c->y = bottom - c->h;
294 if(sticky == TopRight || sticky == BotRight)
296 if(sticky == BotLeft || sticky == BotRight)
297 c->y = bottom - c->h;
304 if(c->w == sw && c->h == sh)
308 XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
318 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
320 c->flags = size.flags;
321 if(c->flags & PBaseSize) {
322 c->basew = size.base_width;
323 c->baseh = size.base_height;
326 c->basew = c->baseh = 0;
327 if(c->flags & PResizeInc) {
328 c->incw = size.width_inc;
329 c->inch = size.height_inc;
332 c->incw = c->inch = 0;
333 if(c->flags & PMaxSize) {
334 c->maxw = size.max_width;
335 c->maxh = size.max_height;
338 c->maxw = c->maxh = 0;
339 if(c->flags & PMinSize) {
340 c->minw = size.min_width;
341 c->minh = size.min_height;
344 c->minw = c->minh = 0;
345 if(c->flags & PWinGravity)
346 c->grav = size.win_gravity;
348 c->grav = NorthWestGravity;
360 XGetTextProperty(dpy, c->win, &name, netatom[NetWMName]);
362 XGetWMName(dpy, c->win, &name);
365 if(name.encoding == XA_STRING)
366 strncpy(c->name, (char *)name.value, sizeof(c->name));
368 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
371 strncpy(c->name, *list, sizeof(c->name));
372 XFreeStringList(list);
388 if((sel->ismax = !sel->ismax)) {
396 sel->h = sh - 2 - bh;
399 resize(sel, False, TopLeft);
407 resize(sel, False, TopLeft);
408 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
415 XSetErrorHandler(xerrordummy);
417 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
418 XDestroyWindow(dpy, c->title);
421 c->prev->next = c->next;
423 c->next->prev = c->prev;
427 sel = getnext(c->next);
429 sel = getprev(c->prev);
437 XSetErrorHandler(xerror);
452 if(sel == getnext(clients) && sel->next) {
453 if((c = getnext(sel->next)))
459 sel->prev->next = sel->next;
461 sel->next->prev = sel->prev;