next version is 2.9
[dmenu.git] / main.c
diff --git a/main.c b/main.c
index 0f07773..9fab328 100644 (file)
--- a/main.c
+++ b/main.c
@@ -108,11 +108,17 @@ drawmenu(void) {
        XFlush(dpy);
 }
 
-static void
+static Bool
 grabkeyboard(void) {
-       while(XGrabKeyboard(dpy, root, True, GrabModeAsync,
-                        GrabModeAsync, CurrentTime) != GrabSuccess)
+       unsigned int len;
+
+       for(len = 1000; len; len--) {
+               if(XGrabKeyboard(dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime)
+                       == GrabSuccess)
+                       break;
                usleep(1000);
+       }
+       return len > 0;
 }
 
 static unsigned long
@@ -210,6 +216,13 @@ kpress(XKeyEvent * e) {
        len = strlen(text);
        buf[0] = 0;
        num = XLookupString(e, buf, sizeof buf, &ksym, 0);
+       if(IsKeypadKey(ksym)) { 
+               if(ksym == XK_KP_Enter) {
+                       ksym = XK_Return;
+               } else if(ksym >= XK_KP_0 && ksym <= XK_KP_9) {
+                       ksym = (ksym - XK_KP_0) + XK_0;
+               }
+       }
        if(IsFunctionKey(ksym) || IsKeypadKey(ksym)
                        || IsMiscFunctionKey(ksym) || IsPFKey(ksym)
                        || IsPrivateKeypadKey(ksym))
@@ -456,10 +469,10 @@ main(int argc, char *argv[]) {
        root = RootWindow(dpy, screen);
        if(isatty(STDIN_FILENO)) {
                maxname = readstdin();
-               grabkeyboard();
+               running = grabkeyboard();
        }
        else { /* prevent keypress loss */
-               grabkeyboard();
+               running = grabkeyboard();
                maxname = readstdin();
        }
        /* init modifier map */