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 < TLast; i++)
21 c->tw += textw(c->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));
215 c->x = c->tx = wa->x;
216 c->y = c->ty = wa->y;
217 c->w = c->tw = wa->width;
224 if(c->h != sh && c->y < bh)
227 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 | EnterWindowMask;
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);
245 XGrabButton(dpy, Button1, MODKEY, c->win, False, BUTTONMASK,
246 GrabModeAsync, GrabModeSync, None, None);
247 XGrabButton(dpy, Button2, MODKEY, c->win, False, BUTTONMASK,
248 GrabModeAsync, GrabModeSync, None, None);
249 XGrabButton(dpy, Button3, MODKEY, c->win, False, BUTTONMASK,
250 GrabModeAsync, GrabModeSync, None, None);
255 || (c->maxw && c->minw &&
256 c->maxw == c->minw && c->maxh == c->minh);
260 /* mapping the window now prevents flicker */
261 XMapRaised(dpy, c->win);
262 XMapRaised(dpy, c->title);
268 resize(Client *c, Bool sizehints, Corner sticky)
270 int bottom = c->y + c->h;
271 int right = c->x + c->w;
272 /*XConfigureEvent e;*/
277 c->w -= (c->w - c->basew) % c->incw;
279 c->h -= (c->h - c->baseh) % c->inch;
280 if(c->minw && c->w < c->minw)
282 if(c->minh && c->h < c->minh)
284 if(c->maxw && c->w > c->maxw)
286 if(c->maxh && c->h > c->maxh)
289 if(c->x > right) /* might happen on restart */
292 c->y = bottom - c->h;
293 if(sticky == TopRight || sticky == BotRight)
295 if(sticky == BotLeft || sticky == BotRight)
296 c->y = bottom - c->h;
303 if(c->w == sw && c->h == sh)
307 XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
317 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
319 c->flags = size.flags;
320 if(c->flags & PBaseSize) {
321 c->basew = size.base_width;
322 c->baseh = size.base_height;
325 c->basew = c->baseh = 0;
326 if(c->flags & PResizeInc) {
327 c->incw = size.width_inc;
328 c->inch = size.height_inc;
331 c->incw = c->inch = 0;
332 if(c->flags & PMaxSize) {
333 c->maxw = size.max_width;
334 c->maxh = size.max_height;
337 c->maxw = c->maxh = 0;
338 if(c->flags & PMinSize) {
339 c->minw = size.min_width;
340 c->minh = size.min_height;
343 c->minw = c->minh = 0;
344 if(c->flags & PWinGravity)
345 c->grav = size.win_gravity;
347 c->grav = NorthWestGravity;
359 XGetTextProperty(dpy, c->win, &name, netatom[NetWMName]);
361 XGetWMName(dpy, c->win, &name);
364 if(name.encoding == XA_STRING)
365 strncpy(c->name, (char *)name.value, sizeof(c->name));
367 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
370 strncpy(c->name, *list, sizeof(c->name));
371 XFreeStringList(list);
387 if((sel->ismax = !sel->ismax)) {
395 sel->h = sh - 2 - bh;
398 resize(sel, False, TopLeft);
406 resize(sel, False, TopLeft);
407 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
414 XSetErrorHandler(xerrordummy);
416 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
417 XDestroyWindow(dpy, c->title);
420 c->prev->next = c->next;
422 c->next->prev = c->prev;
426 sel = getnext(c->next);
428 sel = getprev(c->prev);
435 XSetErrorHandler(xerror);
450 if(sel == getnext(clients) && sel->next) {
451 if((c = getnext(sel->next)))
457 sel->prev->next = sel->next;
459 sel->next->prev = sel->prev;