JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
removed finished message
[dwm.git] / event.c
diff --git a/event.c b/event.c
index c5e5f40..85205d9 100644 (file)
--- a/event.c
+++ b/event.c
@@ -4,7 +4,6 @@
  */
 #include "dwm.h"
 #include <stdlib.h>
-#include <unistd.h>
 #include <X11/keysym.h>
 #include <X11/Xatom.h>
 
@@ -278,6 +277,16 @@ leavenotify(XEvent *e)
 }
 
 static void
+mappingnotify(XEvent *e)
+{
+       XMappingEvent *ev = &e->xmapping;
+
+       XRefreshKeyboardMapping(ev);
+       if(ev->request == MappingKeyboard)
+               grabkeys();
+}
+
+static void
 maprequest(XEvent *e)
 {
        static XWindowAttributes wa;
@@ -349,6 +358,7 @@ void (*handler[LASTEvent]) (XEvent *) = {
        [LeaveNotify] = leavenotify,
        [Expose] = expose,
        [KeyPress] = keypress,
+       [MappingNotify] = mappingnotify,
        [MapRequest] = maprequest,
        [PropertyNotify] = propertynotify,
        [UnmapNotify] = unmapnotify
@@ -361,11 +371,7 @@ grabkeys()
        unsigned int i;
        KeyCode code;
 
-       while(XGrabKeyboard(dpy, root, True, GrabModeAsync,
-                        GrabModeAsync, CurrentTime) != GrabSuccess)
-               usleep(1000);
-       XUngrabKeyboard(dpy, CurrentTime);
-
+       XUngrabKey(dpy, AnyKey, AnyModifier, root);
        for(i = 0; i < len; i++) {
                code = XKeysymToKeycode(dpy, key[i].keysym);
                XGrabKey(dpy, code, key[i].mod, root, True,
@@ -376,5 +382,6 @@ grabkeys()
                                GrabModeAsync, GrabModeAsync);
                XGrabKey(dpy, code, key[i].mod | NUMLOCKMASK | LockMask, root, True,
                                GrabModeAsync, GrabModeAsync);
+               XSync(dpy, False);
        }
 }