+ if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
+ size.flags = PSize;
+ c->flags = size.flags;
+ if(c->flags & PBaseSize) {
+ c->basew = size.base_width;
+ c->baseh = size.base_height;
+ }
+ else
+ c->basew = c->baseh = 0;
+ if(c->flags & PResizeInc) {
+ c->incw = size.width_inc;
+ c->inch = size.height_inc;
+ }
+ else
+ c->incw = c->inch = 0;
+ if(c->flags & PMaxSize) {
+ c->maxw = size.max_width;
+ c->maxh = size.max_height;
+ }
+ else
+ c->maxw = c->maxh = 0;
+ if(c->flags & PMinSize) {
+ c->minw = size.min_width;
+ c->minh = size.min_height;
+ }
+ else
+ c->minw = c->minh = 0;
+ if(c->flags & PWinGravity)
+ c->grav = size.win_gravity;
+ else
+ c->grav = NorthWestGravity;
+}
+
+void
+craise(Client *c)
+{
+ XRaiseWindow(dpy, c->win);
+ XRaiseWindow(dpy, c->title);
+}
+
+void
+lower(Client *c)
+{
+ XLowerWindow(dpy, c->title);
+ XLowerWindow(dpy, c->win);
+}
+
+void
+focus(Client *c)
+{
+ if(sel && sel != c) {
+ XSetWindowBorder(dpy, sel->win, dc.bg);
+ XMapWindow(dpy, sel->title);
+ draw_client(sel);
+ }
+ sel = c;
+ XUnmapWindow(dpy, c->title);
+ XSetWindowBorder(dpy, c->win, dc.fg);
+ draw_client(c);
+ XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
+ XFlush(dpy);
+ discard_events(EnterWindowMask);
+}
+
+static void
+init_tags(Client *c)
+{
+ XClassHint ch;
+ static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0;
+ unsigned int i, j;
+ Bool matched = False;
+
+ if(!len) {
+ c->tags[tsel] = tags[tsel];
+ return;
+ }
+
+ if(XGetClassHint(dpy, c->win, &ch)) {
+ if(ch.res_class && ch.res_name) {
+ fprintf(stderr, "%s:%s\n", ch.res_class, ch.res_name);
+ for(i = 0; i < len; i++)
+ if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class))
+ && !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance)))
+ {
+ fprintf(stderr, "->>>%s:%s\n", ch.res_class, ch.res_name);
+ for(j = 0; j < TLast; j++)
+ c->tags[j] = rule[i].tags[j];
+ matched = True;
+ break;
+ }
+ }
+ if(ch.res_class)
+ XFree(ch.res_class);
+ if(ch.res_name)
+ XFree(ch.res_name);
+ }
+
+ if(!matched)
+ c->tags[tsel] = tags[tsel];
+}
+
+void
+manage(Window w, XWindowAttributes *wa)
+{
+ Client *c, **l;
+ XSetWindowAttributes twa;