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)
31 c->tw = textw(c->name);
34 c->tx = c->x + c->w - c->tw + 2;
37 XMoveResizeWindow(dpy, c->twin, c->tx, c->ty, c->tw, c->th);
39 XMoveResizeWindow(dpy, c->twin, c->tx + 2 * sw, c->ty, c->tw, c->th);
44 ungrabbutton(Client *c, unsigned int button, unsigned int modifier)
46 XUngrabButton(dpy, button, modifier, c->win);
47 XUngrabButton(dpy, button, modifier | LockMask, c->win);
48 XUngrabButton(dpy, button, modifier | numlockmask, c->win);
49 XUngrabButton(dpy, button, modifier | numlockmask | LockMask, c->win);
53 xerrordummy(Display *dsply, XErrorEvent *ee)
58 /* extern functions */
63 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
64 XMoveWindow(dpy, c->twin, c->tx + 2 * sw, c->ty);
80 grabbutton(old, AnyButton, 0);
83 ungrabbutton(c, AnyButton, 0);
85 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
93 for(c = clients; c; c = c->next)
104 for(c = clients; c; c = c->next)
111 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 if(sel->proto & PROTODELWIN)
171 sendevent(sel->win, wmatom[WMProtocols], wmatom[WMDelete]);
173 XKillClient(dpy, sel->win);
177 manage(Window w, XWindowAttributes *wa)
182 XSetWindowAttributes twa;
184 c = emallocz(sizeof(Client));
185 c->tags = emallocz(ntags * sizeof(Bool));
187 c->x = c->tx = wa->x;
188 c->y = c->ty = wa->y;
189 c->w = c->tw = wa->width;
196 if(c->x + c->w + 2 > sw)
197 c->x = sw - c->w - 2;
200 if(c->y + c->h + 2 > sh)
201 c->y = sh - c->h - 2;
202 if(c->h != sh && c->y < bh)
205 c->proto = getproto(c->win);
206 XSelectInput(dpy, c->win,
207 StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
208 XGetTransientForHint(dpy, c->win, &trans);
209 twa.override_redirect = 1;
210 twa.background_pixmap = ParentRelative;
211 twa.event_mask = ExposureMask | EnterWindowMask;
213 c->twin = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
214 0, DefaultDepth(dpy, screen), CopyFromParent,
215 DefaultVisual(dpy, screen),
216 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
223 grabbutton(c, Button1, MODKEY);
224 grabbutton(c, Button2, MODKEY);
225 grabbutton(c, Button3, MODKEY);
227 if((tc = getclient(trans))) /* inherit tags */
228 for(i = 0; i < ntags; i++)
229 c->tags[i] = tc->tags[i];
234 || (c->maxw && c->minw &&
235 c->maxw == c->minw && c->maxh == c->minh);
240 XMapWindow(dpy, c->win);
241 XMapWindow(dpy, c->twin);
247 resize(Client *c, Bool sizehints, Corner sticky)
249 int bottom = c->y + c->h;
250 int right = c->x + c->w;
255 c->w -= (c->w - c->basew) % c->incw;
257 c->h -= (c->h - c->baseh) % c->inch;
258 if(c->minw && c->w < c->minw)
260 if(c->minh && c->h < c->minh)
262 if(c->maxw && c->w > c->maxw)
264 if(c->maxh && c->h > c->maxh)
267 if(sticky == TopRight || sticky == BotRight)
269 if(sticky == BotLeft || sticky == BotRight)
270 c->y = bottom - c->h;
277 if(c->w == sw && c->h == sh)
281 XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
291 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
293 c->flags = size.flags;
294 if(c->flags & PBaseSize) {
295 c->basew = size.base_width;
296 c->baseh = size.base_height;
299 c->basew = c->baseh = 0;
300 if(c->flags & PResizeInc) {
301 c->incw = size.width_inc;
302 c->inch = size.height_inc;
305 c->incw = c->inch = 0;
306 if(c->flags & PMaxSize) {
307 c->maxw = size.max_width;
308 c->maxh = size.max_height;
311 c->maxw = c->maxh = 0;
312 if(c->flags & PMinSize) {
313 c->minw = size.min_width;
314 c->minh = size.min_height;
317 c->minw = c->minh = 0;
318 if(c->flags & PWinGravity)
319 c->grav = size.win_gravity;
321 c->grav = NorthWestGravity;
333 XGetTextProperty(dpy, c->win, &name, netatom[NetWMName]);
335 XGetWMName(dpy, c->win, &name);
338 if(name.encoding == XA_STRING)
339 strncpy(c->name, (char *)name.value, sizeof(c->name));
341 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
344 strncpy(c->name, *list, sizeof(c->name));
345 XFreeStringList(list);
361 if((sel->ismax = !sel->ismax)) {
369 sel->h = sh - 2 - bh;
372 resize(sel, arrange == dofloat, TopLeft);
380 resize(sel, False, TopLeft);
381 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
388 XSetErrorHandler(xerrordummy);
390 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
391 XDestroyWindow(dpy, c->twin);
394 c->prev->next = c->next;
396 c->next->prev = c->prev;
400 sel = getnext(clients);
405 XSetErrorHandler(xerror);