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);
78 if(sel && sel->ismax && sel != c)
82 grabbutton(old, AnyButton, 0);
85 ungrabbutton(c, AnyButton, 0);
87 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
98 if(!(c = getnext(sel->next)))
114 if(!(c = getprev(sel->prev))) {
115 for(c = clients; c && c->next; c = c->next);
129 for(c = clients; c; c = c->next)
140 for(c = clients; c; c = c->next)
147 gravitate(Client *c, Bool invert)
155 case NorthWestGravity:
157 case NorthEastGravity:
163 dy = -(c->h / 2) + c->border;
165 case SouthEastGravity:
167 case SouthWestGravity:
176 case NorthWestGravity:
178 case SouthWestGravity:
184 dx = -(c->w / 2) + c->border;
186 case NorthEastGravity:
188 case SouthEastGravity:
189 dx = -(c->w + c->border);
206 if(sel->proto & PROTODELWIN)
207 sendevent(sel->win, wmatom[WMProtocols], wmatom[WMDelete]);
209 XKillClient(dpy, sel->win);
213 manage(Window w, XWindowAttributes *wa)
217 XSetWindowAttributes twa;
219 c = emallocz(sizeof(Client));
220 c->tags = emallocz(ntags * sizeof(Bool));
222 c->x = c->tx = wa->x;
223 c->y = c->ty = wa->y;
224 c->w = c->tw = wa->width;
231 if(c->x + c->w + 2 > sw)
232 c->x = sw - c->w - 2;
235 if(c->y + c->h + 2 > sh)
236 c->y = sh - c->h - 2;
237 if(c->h != sh && c->y < bh)
240 c->proto = getproto(c->win);
241 XSelectInput(dpy, c->win,
242 StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
243 XGetTransientForHint(dpy, c->win, &trans);
244 twa.override_redirect = 1;
245 twa.background_pixmap = ParentRelative;
246 twa.event_mask = ExposureMask | EnterWindowMask;
248 c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
249 0, DefaultDepth(dpy, screen), CopyFromParent,
250 DefaultVisual(dpy, screen),
251 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
258 grabbutton(c, Button1, MODKEY);
259 grabbutton(c, Button2, MODKEY);
260 grabbutton(c, Button3, MODKEY);
265 || (c->maxw && c->minw &&
266 c->maxw == c->minw && c->maxh == c->minh);
271 XMapWindow(dpy, c->win);
272 XMapWindow(dpy, c->title);
278 resize(Client *c, Bool sizehints, Corner sticky)
280 int bottom = c->y + c->h;
281 int right = c->x + c->w;
286 c->w -= (c->w - c->basew) % c->incw;
288 c->h -= (c->h - c->baseh) % c->inch;
289 if(c->minw && c->w < c->minw)
291 if(c->minh && c->h < c->minh)
293 if(c->maxw && c->w > c->maxw)
295 if(c->maxh && c->h > c->maxh)
298 if(sticky == TopRight || sticky == BotRight)
300 if(sticky == BotLeft || sticky == BotRight)
301 c->y = bottom - c->h;
308 if(c->w == sw && c->h == sh)
312 XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
322 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
324 c->flags = size.flags;
325 if(c->flags & PBaseSize) {
326 c->basew = size.base_width;
327 c->baseh = size.base_height;
330 c->basew = c->baseh = 0;
331 if(c->flags & PResizeInc) {
332 c->incw = size.width_inc;
333 c->inch = size.height_inc;
336 c->incw = c->inch = 0;
337 if(c->flags & PMaxSize) {
338 c->maxw = size.max_width;
339 c->maxh = size.max_height;
342 c->maxw = c->maxh = 0;
343 if(c->flags & PMinSize) {
344 c->minw = size.min_width;
345 c->minh = size.min_height;
348 c->minw = c->minh = 0;
349 if(c->flags & PWinGravity)
350 c->grav = size.win_gravity;
352 c->grav = NorthWestGravity;
364 XGetTextProperty(dpy, c->win, &name, netatom[NetWMName]);
366 XGetWMName(dpy, c->win, &name);
369 if(name.encoding == XA_STRING)
370 strncpy(c->name, (char *)name.value, sizeof(c->name));
372 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
375 strncpy(c->name, *list, sizeof(c->name));
376 XFreeStringList(list);
392 if((sel->ismax = !sel->ismax)) {
400 sel->h = sh - 2 - bh;
403 resize(sel, arrange == dofloat, TopLeft);
411 resize(sel, False, TopLeft);
412 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
419 XSetErrorHandler(xerrordummy);
421 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
422 XDestroyWindow(dpy, c->title);
425 c->prev->next = c->next;
427 c->next->prev = c->prev;
431 sel = getnext(clients);
436 XSetErrorHandler(xerror);
448 if(!sel || (arrange != dotile) || sel->isfloat || sel->ismax)
451 if(sel == getnext(clients)) {
452 if((c = getnext(sel->next)))
459 sel->prev->next = sel->next;
461 sel->next->prev = sel->prev;