JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
made code more readable
[dwm.git] / client.c
index caa523c..b1b1417 100644 (file)
--- a/client.c
+++ b/client.c
@@ -10,6 +10,8 @@
 #include "util.h"
 #include "wm.h"
 
+#define CLIENT_MASK            (StructureNotifyMask | PropertyChangeMask | EnterWindowMask)
+
 void
 update_name(Client *c)
 {
@@ -35,6 +37,28 @@ update_name(Client *c)
                }
        }
        XFree(name.value);
+       if(c == stack)
+               draw_bar();
+       else
+               draw_client(c);
+}
+
+void
+update_size(Client *c)
+{
+       XSizeHints size;
+       long msize;
+       if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
+               size.flags = PSize;
+       c->flags = size.flags;
+       c->basew = size.base_width;
+       c->baseh = size.base_height;
+       c->incw = size.width_inc;
+       c->inch = size.height_inc;
+       c->maxw = size.max_width;
+       c->maxh = size.max_height;
+       c->minw = size.min_width;
+       c->minh = size.min_height;
 }
 
 void
@@ -56,31 +80,24 @@ manage(Window w, XWindowAttributes *wa)
 {
        Client *c, **l;
        XSetWindowAttributes twa;
-       long msize;
 
        c = emallocz(sizeof(Client));
        c->win = w;
-       c->r[RFloat].x = wa->x;
-       c->r[RFloat].y = wa->y;
-       c->r[RFloat].width = wa->width;
-       c->r[RFloat].height = wa->height;
-       c->border = wa->border_width;
-       XSetWindowBorderWidth(dpy, c->win, 0);
+       c->x = wa->x;
+       c->y = wa->y;
+       c->w = wa->width;
+       c->h = wa->height;
+       update_size(c);
+       XSetWindowBorderWidth(dpy, c->win, 1);
+       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;
-       c->fixedsize =
-               (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_name(c);
        twa.override_redirect = 1;
        twa.background_pixmap = ParentRelative;
        twa.event_mask = ExposureMask;
 
-       c->title = XCreateWindow(dpy, root, c->r[RFloat].x, c->r[RFloat].y,
-                       c->r[RFloat].width, barrect.height, 0,
-                       DefaultDepth(dpy, screen), CopyFromParent,
+       c->title = XCreateWindow(dpy, root, c->x, c->y, c->w, barrect.height,
+                       0, DefaultDepth(dpy, screen), CopyFromParent,
                        DefaultVisual(dpy, screen),
                        CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
 
@@ -90,9 +107,37 @@ manage(Window w, XWindowAttributes *wa)
        c->snext = stack;
        stack = c;
        XMapWindow(dpy, c->win);
+       XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
+                       GrabModeAsync, GrabModeSync, None, None);
+       XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask,
+                       GrabModeAsync, GrabModeSync, None, None);
+       XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask,
+                       GrabModeAsync, GrabModeSync, None, None);
        focus(c);
 }
 
+void
+resize(Client *c)
+{
+       XConfigureEvent e;
+
+       XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
+       e.type = ConfigureNotify;
+       e.event = c->win;
+       e.window = c->win;
+       e.x = c->x;
+       e.y = c->y;
+       e.width = c->w;
+       e.height = c->h;
+       e.border_width = 0;
+       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);
+}
+
 static int
 dummy_error_handler(Display *dpy, XErrorEvent *error)
 {
@@ -107,6 +152,7 @@ unmanage(Client *c)
        XGrabServer(dpy);
        XSetErrorHandler(dummy_error_handler);
 
+       XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
        XUnmapWindow(dpy, c->win);
        XDestroyWindow(dpy, c->title);
 
@@ -121,7 +167,9 @@ unmanage(Client *c)
        XFlush(dpy);
        XSetErrorHandler(error_handler);
        XUngrabServer(dpy);
-       flush_events(EnterWindowMask);
+       discard_events(EnterWindowMask);
+       if(stack)
+               focus(stack);
 }
 
 
@@ -135,3 +183,10 @@ getclient(Window w)
        return NULL;
 }
 
+void
+draw_client(Client *c)
+{
+       
+
+
+}