2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
11 /* static functions */
14 grabbutton(Client *c, unsigned int button, unsigned int modifier)
16 XGrabButton(dpy, button, modifier, c->win, False, BUTTONMASK,
17 GrabModeAsync, GrabModeSync, None, None);
18 XGrabButton(dpy, button, modifier | LockMask, c->win, False, BUTTONMASK,
19 GrabModeAsync, GrabModeSync, None, None);
20 XGrabButton(dpy, button, modifier | numlockmask, c->win, False, BUTTONMASK,
21 GrabModeAsync, GrabModeSync, None, None);
22 XGrabButton(dpy, button, modifier | numlockmask | LockMask, c->win, False, BUTTONMASK,
23 GrabModeAsync, GrabModeSync, None, None);
27 resizetitle(Client *c)
32 for(i = 0; i < ntags; i++)
34 c->tw += textw(tags[i]);
35 c->tw += textw(c->name);
38 c->tx = c->x + c->w - c->tw + 2;
41 XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
43 XMoveResizeWindow(dpy, c->title, c->tx + 2 * sw, c->ty, c->tw, c->th);
48 ungrabbutton(Client *c, unsigned int button, unsigned int modifier)
50 XUngrabButton(dpy, button, modifier, c->win);
51 XUngrabButton(dpy, button, modifier | LockMask, c->win);
52 XUngrabButton(dpy, button, modifier | numlockmask, c->win);
53 XUngrabButton(dpy, button, modifier | numlockmask | LockMask, c->win);
57 xerrordummy(Display *dsply, XErrorEvent *ee)
62 /* extern functions */
67 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
68 XMoveWindow(dpy, c->title, c->tx + 2 * sw, c->ty);
84 grabbutton(old, AnyButton, 0);
87 ungrabbutton(c, AnyButton, 0);
89 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
100 if(!(c = getnext(sel->next)))
101 c = getnext(clients);
116 if(!(c = getprev(sel->prev))) {
117 for(c = clients; c && c->next; c = c->next);
131 for(c = clients; c; c = c->next)
142 for(c = clients; c; c = c->next)
149 gravitate(Client *c, Bool invert)
157 case NorthWestGravity:
159 case NorthEastGravity:
165 dy = -(c->h / 2) + c->border;
167 case SouthEastGravity:
169 case SouthWestGravity:
178 case NorthWestGravity:
180 case SouthWestGravity:
186 dx = -(c->w / 2) + c->border;
188 case NorthEastGravity:
190 case SouthEastGravity:
191 dx = -(c->w + c->border);
208 if(sel->proto & PROTODELWIN)
209 sendevent(sel->win, wmatom[WMProtocols], wmatom[WMDelete]);
211 XKillClient(dpy, sel->win);
215 manage(Window w, XWindowAttributes *wa)
220 XSetWindowAttributes twa;
222 c = emallocz(sizeof(Client));
223 c->tags = emallocz(ntags * sizeof(Bool));
225 c->x = c->tx = wa->x;
226 c->y = c->ty = wa->y;
227 c->w = c->tw = wa->width;
234 if(c->x + c->w + 2 > sw)
235 c->x = sw - c->w - 2;
238 if(c->y + c->h + 2 > sh)
239 c->y = sh - c->h - 2;
240 if(c->h != sh && c->y < bh)
243 c->proto = getproto(c->win);
244 XSelectInput(dpy, c->win,
245 StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
246 XGetTransientForHint(dpy, c->win, &trans);
247 twa.override_redirect = 1;
248 twa.background_pixmap = ParentRelative;
249 twa.event_mask = ExposureMask | EnterWindowMask;
251 c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
252 0, DefaultDepth(dpy, screen), CopyFromParent,
253 DefaultVisual(dpy, screen),
254 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
261 grabbutton(c, Button1, MODKEY);
262 grabbutton(c, Button2, MODKEY);
263 grabbutton(c, Button3, MODKEY);
265 if((tc = getclient(trans))) /* inherit tags */
266 for(i = 0; i < ntags; i++)
267 c->tags[i] = tc->tags[i];
272 || (c->maxw && c->minw &&
273 c->maxw == c->minw && c->maxh == c->minh);
278 XMapWindow(dpy, c->win);
279 XMapWindow(dpy, c->title);
285 resize(Client *c, Bool sizehints, Corner sticky)
287 int bottom = c->y + c->h;
288 int right = c->x + c->w;
293 c->w -= (c->w - c->basew) % c->incw;
295 c->h -= (c->h - c->baseh) % c->inch;
296 if(c->minw && c->w < c->minw)
298 if(c->minh && c->h < c->minh)
300 if(c->maxw && c->w > c->maxw)
302 if(c->maxh && c->h > c->maxh)
305 if(sticky == TopRight || sticky == BotRight)
307 if(sticky == BotLeft || sticky == BotRight)
308 c->y = bottom - c->h;
315 if(c->w == sw && c->h == sh)
319 XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
329 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
331 c->flags = size.flags;
332 if(c->flags & PBaseSize) {
333 c->basew = size.base_width;
334 c->baseh = size.base_height;
337 c->basew = c->baseh = 0;
338 if(c->flags & PResizeInc) {
339 c->incw = size.width_inc;
340 c->inch = size.height_inc;
343 c->incw = c->inch = 0;
344 if(c->flags & PMaxSize) {
345 c->maxw = size.max_width;
346 c->maxh = size.max_height;
349 c->maxw = c->maxh = 0;
350 if(c->flags & PMinSize) {
351 c->minw = size.min_width;
352 c->minh = size.min_height;
355 c->minw = c->minh = 0;
356 if(c->flags & PWinGravity)
357 c->grav = size.win_gravity;
359 c->grav = NorthWestGravity;
371 XGetTextProperty(dpy, c->win, &name, netatom[NetWMName]);
373 XGetWMName(dpy, c->win, &name);
376 if(name.encoding == XA_STRING)
377 strncpy(c->name, (char *)name.value, sizeof(c->name));
379 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
382 strncpy(c->name, *list, sizeof(c->name));
383 XFreeStringList(list);
399 if((sel->ismax = !sel->ismax)) {
407 sel->h = sh - 2 - bh;
410 resize(sel, arrange == dofloat, TopLeft);
418 resize(sel, False, TopLeft);
419 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
426 XSetErrorHandler(xerrordummy);
428 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
429 XDestroyWindow(dpy, c->title);
432 c->prev->next = c->next;
434 c->next->prev = c->prev;
438 sel = getnext(clients);
443 XSetErrorHandler(xerror);
455 if(!sel || (arrange != dotile) || sel->isfloat || sel->ismax)
458 if(sel == getnext(clients)) {
459 if((c = getnext(sel->next)))
466 sel->prev->next = sel->next;
468 sel->next->prev = sel->prev;