]> git.sur5r.net Git - i3/i3lock/commitdiff
Bugfix: Handle numpad keys correctly (Thanks Pascal)
authorMichael Stapelberg <michael@stapelberg.de>
Mon, 8 Nov 2010 13:39:53 +0000 (14:39 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Mon, 8 Nov 2010 13:43:07 +0000 (14:43 +0100)
i3lock.c
keysym2ucs.c

index 2d2cc89c13df791a615226158b646a4496a0154e..198d334e43f2fc52d622e1d4be56620462046446 100644 (file)
--- a/i3lock.c
+++ b/i3lock.c
@@ -120,17 +120,15 @@ static void handle_key_release(xcb_key_release_event_t *event) {
 static void handle_key_press(xcb_key_press_event_t *event) {
     //printf("keypress %d, state raw = %d\n", event->detail, event->state);
 
-    /* fix state */
-    if (modeswitch_active)
-            event->state |= modeswitchmask;
-
-    /* Apparantly, after activating numlock once, the numlock modifier
-     * stays turned on (use xev(1) to verify). So, to resolve useful
-     * keysyms, we remove the numlock flag from the event state */
-    event->state &= ~numlockmask;
-
-    xcb_keysym_t sym = xcb_key_press_lookup_keysym(symbols, event, event->state);
-    switch (sym) {
+    xcb_keysym_t sym0, sym1, sym;
+    if (modeswitch_active) {
+        sym0 = xcb_key_press_lookup_keysym(symbols, event, 4);
+        sym1 = xcb_key_press_lookup_keysym(symbols, event, 5);
+    } else {
+        sym0 = xcb_key_press_lookup_keysym(symbols, event, 0);
+        sym1 = xcb_key_press_lookup_keysym(symbols, event, 1);
+    }
+    switch (sym0) {
     case XK_Mode_switch:
         //printf("Mode switch enabled\n");
         modeswitch_active = true;
@@ -157,6 +155,17 @@ static void handle_key_press(xcb_key_press_event_t *event) {
     if ((input_position + 8) >= sizeof(password))
         return;
 
+    if ((event->state & numlockmask) && xcb_is_keypad_key(sym1)) {
+        /* this key was a keypad key */
+        if ((event->state & XCB_MOD_MASK_SHIFT))
+            sym = sym0;
+        else sym = sym1;
+    } else {
+        if ((event->state & XCB_MOD_MASK_SHIFT))
+            sym = sym1;
+        else sym = sym0;
+    }
+
 #if 0
     /* FIXME: handle all of these? */
     printf("is_keypad_key = %d\n", xcb_is_keypad_key(sym));
index 3da51edd3b2a229788ee9060b172b29c35dec297..9eecf6bfc072fa91cb3f67e17a1c2c8ab8012ebc 100644 (file)
@@ -825,6 +825,10 @@ long keysym2ucs(xcb_keysym_t keysym)
         (keysym >= 0x00a0 && keysym <= 0x00ff))
         return keysym;
 
+    /* check for numpad keys (direct mapping) */
+    if ((keysym >= 0xff80 && keysym <= 0xffb9))
+        return keysym & 0x7F;
+
     /* also check for directly encoded 24-bit UCS characters */
     if ((keysym & 0xff000000) == 0x01000000)
        return keysym & 0x00ffffff;