2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
10 #include <X11/Xutil.h>
14 static Rule rule[] = {
15 /* class instance tags floating */
16 { "Firefox-bin", "Gecko", { [Twww] = "www" }, False },
22 for(; c && !c->tags[tsel]; c = c->next);
29 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
30 XMoveWindow(dpy, c->title, c->tx + 2 * sw, c->ty);
34 resize_title(Client *c)
39 for(i = 0; i < TLast; i++)
41 c->tw += textw(c->tags[i]);
42 c->tw += textw(c->name);
45 c->tx = c->x + c->w - c->tw + 2;
47 XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
59 XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]);
61 XGetWMName(dpy, c->win, &name);
64 if(name.encoding == XA_STRING)
65 strncpy(c->name, (char *)name.value, sizeof(c->name));
67 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
70 strncpy(c->name, *list, sizeof(c->name));
71 XFreeStringList(list);
83 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
85 c->flags = size.flags;
86 if(c->flags & PBaseSize) {
87 c->basew = size.base_width;
88 c->baseh = size.base_height;
91 c->basew = c->baseh = 0;
92 if(c->flags & PResizeInc) {
93 c->incw = size.width_inc;
94 c->inch = size.height_inc;
97 c->incw = c->inch = 0;
98 if(c->flags & PMaxSize) {
99 c->maxw = size.max_width;
100 c->maxh = size.max_height;
103 c->maxw = c->maxh = 0;
104 if(c->flags & PMinSize) {
105 c->minw = size.min_width;
106 c->minh = size.min_height;
109 c->minw = c->minh = 0;
110 if(c->flags & PWinGravity)
111 c->grav = size.win_gravity;
113 c->grav = NorthWestGravity;
119 XRaiseWindow(dpy, c->win);
120 XRaiseWindow(dpy, c->title);
126 XLowerWindow(dpy, c->title);
127 XLowerWindow(dpy, c->win);
141 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
143 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
150 static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0;
152 Bool matched = False;
155 c->tags[tsel] = tags[tsel];
159 if(XGetClassHint(dpy, c->win, &ch)) {
160 if(ch.res_class && ch.res_name) {
161 for(i = 0; i < len; i++)
162 if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class))
163 && !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance)))
165 for(j = 0; j < TLast; j++)
166 c->tags[j] = rule[i].tags[j];
167 c->floating = rule[i].floating;
179 c->tags[tsel] = tags[tsel];
183 manage(Window w, XWindowAttributes *wa)
186 XSetWindowAttributes twa;
189 c = emallocz(sizeof(Client));
191 c->tx = c->x = wa->x;
192 c->ty = c->y = wa->y;
195 c->tw = c->w = wa->width;
199 c->proto = proto(c->win);
201 XSelectInput(dpy, c->win,
202 StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
203 XGetTransientForHint(dpy, c->win, &trans);
204 twa.override_redirect = 1;
205 twa.background_pixmap = ParentRelative;
206 twa.event_mask = ExposureMask;
208 c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
209 0, DefaultDepth(dpy, screen), CopyFromParent,
210 DefaultVisual(dpy, screen),
211 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
216 for(l = &clients; *l; l = &(*l)->next);
217 c->next = *l; /* *l == nil */
220 XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
221 GrabModeAsync, GrabModeSync, None, None);
222 XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask,
223 GrabModeAsync, GrabModeSync, None, None);
224 XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask,
225 GrabModeAsync, GrabModeSync, None, None);
229 || ((c->maxw == c->minw) && (c->maxh == c->minh));
232 /* mapping the window now prevents flicker */
234 XMapRaised(dpy, c->win);
235 XMapRaised(dpy, c->title);
240 XMapRaised(dpy, c->win);
241 XMapRaised(dpy, c->title);
246 gravitate(Client *c, Bool invert)
252 case NorthWestGravity:
254 case NorthEastGravity:
260 dy = -(c->h / 2) + c->border;
262 case SouthEastGravity:
264 case SouthWestGravity:
273 case NorthWestGravity:
275 case SouthWestGravity:
281 dx = -(c->w / 2) + c->border;
283 case NorthEastGravity:
285 case SouthEastGravity:
286 dx = -(c->w + c->border);
302 resize(Client *c, Bool inc)
308 c->w -= (c->w - c->basew) % c->incw;
310 c->h -= (c->h - c->baseh) % c->inch;
312 if(c->x > sw) /* might happen on restart */
315 c->ty = c->y = sh - c->h;
316 if(c->minw && c->w < c->minw)
318 if(c->minh && c->h < c->minh)
320 if(c->maxw && c->w > c->maxw)
322 if(c->maxh && c->h > c->maxh)
325 XSetWindowBorderWidth(dpy, c->win, 1);
326 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
327 e.type = ConfigureNotify;
334 e.border_width = c->border;
336 e.override_redirect = False;
337 XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
342 dummy_xerror(Display *dsply, XErrorEvent *err)
353 XSetErrorHandler(dummy_xerror);
355 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
356 XDestroyWindow(dpy, c->title);
358 for(l = &clients; *l && *l != c; l = &(*l)->next);
360 for(l = &clients; *l; l = &(*l)->next)
361 if((*l)->revert == c)
364 sel = sel->revert ? sel->revert : clients;
369 XSetErrorHandler(xerror);
380 for(c = clients; c; c = c->next)
390 for(c = clients; c; c = c->next)