JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
added mouse-based resizals
[dwm.git] / client.c
index 8aca2e2..e05fdd7 100644 (file)
--- a/client.c
+++ b/client.c
 #include "util.h"
 #include "wm.h"
 
-static void
-update_client_name(Client *c)
+#define CLIENT_MASK            (StructureNotifyMask | PropertyChangeMask | EnterWindowMask)
+
+void
+update_name(Client *c)
 {
        XTextProperty name;
        int n;
@@ -35,6 +37,24 @@ update_client_name(Client *c)
                }
        }
        XFree(name.value);
+       if(c == stack)
+               draw_bar();
+       else
+               draw_client(c);
+}
+
+void
+focus(Client *c)
+{
+       Client **l;
+       for(l=&stack; *l && *l != c; l=&(*l)->snext);
+       eassert(*l == c);
+       *l = c->snext;
+       c->snext = stack;
+       stack = c;
+       XRaiseWindow(dpy, c->win);
+       XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
+       XFlush(dpy);
 }
 
 void
@@ -52,6 +72,7 @@ manage(Window w, XWindowAttributes *wa)
        c->r[RFloat].height = wa->height;
        c->border = wa->border_width;
        XSetWindowBorderWidth(dpy, c->win, 0);
+       XSelectInput(dpy, c->win, CLIENT_MASK);
        XGetTransientForHint(dpy, c->win, &c->trans);
        if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags)
                c->size.flags = PSize;
@@ -59,7 +80,7 @@ manage(Window w, XWindowAttributes *wa)
                (c->size.flags & PMinSize && c->size.flags & PMaxSize
                 && c->size.min_width == c->size.max_width
                 && c->size.min_height == c->size.max_height);
-       update_client_name(c);
+       update_name(c);
        twa.override_redirect = 1;
        twa.background_pixmap = ParentRelative;
        twa.event_mask = ExposureMask;
@@ -73,8 +94,34 @@ manage(Window w, XWindowAttributes *wa)
        for(l=&clients; *l; l=&(*l)->next);
        c->next = *l; /* *l == nil */
        *l = c;
-       XMapRaised(dpy, c->win);
-       XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
+       c->snext = stack;
+       stack = c;
+       XMapWindow(dpy, c->win);
+       XGrabButton(dpy, AnyButton, Mod1Mask, c->win, False, ButtonPressMask,
+                       GrabModeAsync, GrabModeSync, None, None);
+       focus(c);
+}
+
+void
+resize(Client *c)
+{
+       XConfigureEvent e;
+
+       XMoveResizeWindow(dpy, c->win, c->r[RFloat].x, c->r[RFloat].y,
+                       c->r[RFloat].width, c->r[RFloat].height);
+       e.type = ConfigureNotify;
+       e.event = c->win;
+       e.window = c->win;
+       e.x = c->r[RFloat].x;
+       e.y = c->r[RFloat].y;
+       e.width = c->r[RFloat].width;
+       e.height = c->r[RFloat].height;
+       e.border_width = c->border;
+       e.above = None;
+       e.override_redirect = False;
+       XSelectInput(dpy, c->win, CLIENT_MASK & ~StructureNotifyMask);
+       XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
+       XSelectInput(dpy, c->win, CLIENT_MASK);
        XFlush(dpy);
 }
 
@@ -92,18 +139,24 @@ unmanage(Client *c)
        XGrabServer(dpy);
        XSetErrorHandler(dummy_error_handler);
 
+       XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
        XUnmapWindow(dpy, c->win);
        XDestroyWindow(dpy, c->title);
 
        for(l=&clients; *l && *l != c; l=&(*l)->next);
        eassert(*l == c);
        *l = c->next;
+       for(l=&stack; *l && *l != c; l=&(*l)->snext);
+       eassert(*l == c);
+       *l = c->snext;
        free(c);
 
        XFlush(dpy);
        XSetErrorHandler(error_handler);
        XUngrabServer(dpy);
-       /*flush_masked_events(EnterWindowMask); ? */
+       discard_events(EnterWindowMask);
+       if(stack)
+               focus(stack);
 }
 
 
@@ -116,3 +169,11 @@ getclient(Window w)
                        return c;
        return NULL;
 }
+
+void
+draw_client(Client *c)
+{
+       
+
+
+}