state: fix bad EFFECTIVE check in *_is_active()
authorRan Benita <ran234@gmail.com>
Wed, 3 Oct 2012 17:41:22 +0000 (19:41 +0200)
committerRan Benita <ran234@gmail.com>
Sat, 6 Oct 2012 19:41:58 +0000 (21:41 +0200)
This is a regression introduced in ed78fbcb30888cbfc6cd00.
XKB_STATE_EFFECTIVE is just a OR of the other states, so using & here is
completely wrong. So test/state shows for example:
    dumping state for LCtrl down:
            group English (US) (0): effective depressed latched locked
            mod Control (2): depressed latched locked
    dumping state for LCtrl + RAlt down:
            group English (US) (0): effective depressed latched locked
            mod Control (2): depressed latched locked
            mod Mod1 (3): depressed latched locked
    dumping state for RAlt down:
            group English (US) (0): effective depressed latched locked
            mod Mod1 (3): depressed latched locked
    dumping state for Caps Lock:
            group English (US) (0): effective depressed latched locked
            mod Lock (1): depressed latched locked
            led Caps Lock (0): active
    dumping state for Alt-Shift-+
            group English (US) (0): effective depressed latched locked
            mod Shift (0): depressed latched locked
            mod Mod1 (3): depressed latched locked
which is bogus.

Signed-off-by: Ran Benita <ran234@gmail.com>
src/state.c
test/state.c

index e186ece..1fad36f 100644 (file)
@@ -841,7 +841,7 @@ xkb_state_mod_index_is_active(struct xkb_state *state,
     if (idx >= xkb_keymap_num_mods(state->keymap))
         return -1;
 
-    if (type & XKB_STATE_EFFECTIVE)
+    if (type == XKB_STATE_EFFECTIVE)
         return !!(state->mods & (1 << idx));
 
     if (type & XKB_STATE_DEPRESSED)
@@ -978,7 +978,7 @@ xkb_state_layout_index_is_active(struct xkb_state *state,
         return -1;
 
     /* Can only have one effective group. */
-    if (type & XKB_STATE_EFFECTIVE)
+    if (type == XKB_STATE_EFFECTIVE)
         return state->group == idx;
 
     if (type & XKB_STATE_DEPRESSED)
index 3da4c99..8cd11e0 100644 (file)
@@ -149,6 +149,11 @@ test_update_key(struct xkb_keymap *keymap)
                                           XKB_MOD_NAME_CTRL,
                                           XKB_MOD_NAME_ALT,
                                           NULL) > 0);
+    assert(xkb_state_mod_names_are_active(state, XKB_STATE_LATCHED,
+                                          XKB_STATE_MATCH_ANY,
+                                          XKB_MOD_NAME_CTRL,
+                                          XKB_MOD_NAME_ALT,
+                                          NULL) == 0);
 
     /* none down */
     xkb_state_update_key(state, KEY_RIGHTALT + EVDEV_OFFSET, XKB_KEY_UP);
@@ -157,10 +162,14 @@ test_update_key(struct xkb_keymap *keymap)
 
     /* Caps locked */
     xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, XKB_KEY_DOWN);
+    assert(xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CAPS,
+                                        XKB_STATE_DEPRESSED) > 0);
     xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, XKB_KEY_UP);
     fprintf(stderr, "dumping state for Caps Lock:\n");
     print_state(state);
     assert(xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CAPS,
+                                        XKB_STATE_DEPRESSED) == 0);
+    assert(xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CAPS,
                                         XKB_STATE_LOCKED) > 0);
     assert(xkb_state_led_name_is_active(state, XKB_LED_NAME_CAPS) > 0);
     num_syms = xkb_state_key_get_syms(state, KEY_Q + EVDEV_OFFSET, &syms);