JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
implemented ungrabkeys() which is called in cleanup()
[dwm.git] / event.c
diff --git a/event.c b/event.c
index bc7d42c..4357eae 100644 (file)
--- a/event.c
+++ b/event.c
@@ -58,6 +58,7 @@ static void
 resizemouse(Client *c)
 {
        int ocx, ocy;
+       int nw, nh;
        Corner sticky;
        XEvent ev;
 
@@ -76,8 +77,10 @@ resizemouse(Client *c)
                        break;
                case MotionNotify:
                        XSync(dpy, False);
-                       c->w = abs(ocx - ev.xmotion.x);
-                       c->h = abs(ocy - ev.xmotion.y);
+                       if((nw = abs(ocx - ev.xmotion.x)))
+                               c->w = abs(ocx - ev.xmotion.x);
+                       if((nh = abs(ocy - ev.xmotion.y)))
+                               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)
@@ -115,21 +118,24 @@ buttonpress(XEvent *e)
                }
        }
        else if((c = getclient(ev->window))) {
-               higher(c);
                focus(c);
                switch(ev->button) {
                default:
                        break;
                case Button1:
-                       if(!c->ismax && (arrange == dofloat || c->isfloat))
+                       if(!c->ismax && (arrange == dofloat || c->isfloat)) {
+                               restack(c);
                                movemouse(c);
+                       }
                        break;
                case Button2:
                        zoom(NULL);
                        break;
                case Button3:
-                       if(!c->ismax && (arrange == dofloat || c->isfloat))
+                       if(!c->ismax && (arrange == dofloat || c->isfloat)) {
+                               restack(c);
                                resizemouse(c);
+                       }
                        break;
                }
        }
@@ -364,3 +370,19 @@ grabkeys()
                                GrabModeAsync, GrabModeAsync);
        }
 }
+
+void
+ungrabkeys()
+{
+       static unsigned int len = sizeof(key) / sizeof(key[0]);
+       unsigned int i;
+       KeyCode code;
+
+       for(i = 0; i < len; i++) {
+               code = XKeysymToKeycode(dpy, key[i].keysym);
+               XUngrabKey(dpy, code, key[i].mod, root);
+               XUngrabKey(dpy, code, key[i].mod | LockMask, root);
+               XUngrabKey(dpy, code, key[i].mod | NUMLOCKMASK, root);
+               XUngrabKey(dpy, code, key[i].mod | NUMLOCKMASK | LockMask, root);
+       }
+}