JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
implemented fallback for too many clients in stacked mode
[dwm.git] / event.c
diff --git a/event.c b/event.c
index 4b8c07b..9d69373 100644 (file)
--- a/event.c
+++ b/event.c
@@ -62,8 +62,8 @@ movemouse(Client *c)
        unsigned int dui;
        Window dummy;
 
-       ocx = c->x;
-       ocy = c->y;
+       ocx = *c->x;
+       ocy = *c->y;
        if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
                                None, cursor[CurMove], CurrentTime) != GrabSuccess)
                return;
@@ -77,9 +77,9 @@ movemouse(Client *c)
                        break;
                case MotionNotify:
                        XSync(dpy, False);
-                       c->x = ocx + (ev.xmotion.x - x1);
-                       c->y = ocy + (ev.xmotion.y - y1);
-                       resize(c, False);
+                       *c->x = ocx + (ev.xmotion.x - x1);
+                       *c->y = ocy + (ev.xmotion.y - y1);
+                       resize(c, False, TopLeft);
                        break;
                case ButtonRelease:
                        XUngrabPointer(dpy, CurrentTime);
@@ -93,13 +93,14 @@ resizemouse(Client *c)
 {
        XEvent ev;
        int ocx, ocy;
+       Corner sticky;
 
-       ocx = c->x;
-       ocy = c->y;
+       ocx = *c->x;
+       ocy = *c->y;
        if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
                                None, cursor[CurResize], CurrentTime) != GrabSuccess)
                return;
-       XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
+       XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, *c->w, *c->h);
        for(;;) {
                XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
                switch(ev.type) {
@@ -109,11 +110,22 @@ resizemouse(Client *c)
                        break;
                case MotionNotify:
                        XSync(dpy, False);
-                       c->w = abs(ocx - ev.xmotion.x);
-                       c->h = abs(ocy - ev.xmotion.y);
-                       c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
-                       c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
-                       resize(c, True);
+                       *c->w = abs(ocx - ev.xmotion.x);
+                       *c->h = abs(ocy - ev.xmotion.y);
+                       *c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - *c->w;
+                       *c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - *c->h;
+                       if(ocx <= ev.xmotion.x) {
+                               if(ocy <= ev.xmotion.y)
+                                       sticky = TopLeft;
+                               else
+                                       sticky = BottomLeft;
+                       } else {
+                               if(ocy <= ev.xmotion.y)
+                                       sticky = TopRight;
+                               else
+                                       sticky = BottomRight;
+                       }
+                       resize(c, True, sticky);
                        break;
                case ButtonRelease:
                        XUngrabPointer(dpy, CurrentTime);
@@ -153,24 +165,27 @@ buttonpress(XEvent *e)
                }
        }
        else if((c = getclient(ev->window))) {
-               if(arrange == dotile && !c->isfloat) {
-                       if((ev->state & ControlMask) && (ev->button == Button1))
-                               zoom(NULL);
-                       return;
-               }
-               /* floating windows */
-               higher(c);
                switch(ev->button) {
                default:
                        break;
                case Button1:
-                       movemouse(c);
+                       if(arrange == dotile && !c->isfloat) {
+                               if((ev->state & ControlMask) && (ev->button == Button1))
+                                       zoom(NULL);
+                       }
+                       else {
+                               higher(c);
+                               movemouse(c);
+                       }
                        break;
                case Button2:
                        lower(c);
                        break;
                case Button3:
-                       resizemouse(c);
+                       if(arrange == dofloat || c->isfloat) {
+                               higher(c);
+                               resizemouse(c);
+                       }
                        break;
                }
        }
@@ -187,17 +202,17 @@ configurerequest(XEvent *e)
        if((c = getclient(ev->window))) {
                gravitate(c, True);
                if(ev->value_mask & CWX)
-                       c->x = ev->x;
+                       *c->x = ev->x;
                if(ev->value_mask & CWY)
-                       c->y = ev->y;
+                       *c->y = ev->y;
                if(ev->value_mask & CWWidth)
-                       c->w = ev->width;
+                       *c->w = ev->width;
                if(ev->value_mask & CWHeight)
-                       c->h = ev->height;
+                       *c->h = ev->height;
                if(ev->value_mask & CWBorderWidth)
                        c->border = 1;
                gravitate(c, False);
-               resize(c, True);
+               resize(c, True, TopLeft);
        }
 
        wc.x = ev->x;