state: special case effective group in layout_is_active
authorRan Benita <ran234@gmail.com>
Fri, 21 Sep 2012 09:45:58 +0000 (12:45 +0300)
committerDaniel Stone <daniel@fooishbar.org>
Sun, 23 Sep 2012 23:08:53 +0000 (09:08 +1000)
Currently, xkb_state_layout_{index,name}_is_active may report multiple
groups as effective, because at looks at base,latched,locked separately.
But there can only be one effective group, which is computed from the
other three. So if XKB_STATE_EFFECTIVE is requested, just compare to the
effective group we have computed.

We also modify mod_{index,name}_is_active similarly, just for symmetry
(there the effective mask is just an OR of the other three so the
current test is correct).

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

index 3da01a1..41a719d 100644 (file)
@@ -794,6 +794,9 @@ 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)
+        return !!(state->mods & (1 << idx));
+
     if (type & XKB_STATE_DEPRESSED)
         ret |= (state->base_mods & (1 << idx));
     if (type & XKB_STATE_LATCHED)
@@ -926,6 +929,10 @@ xkb_state_layout_index_is_active(struct xkb_state *state,
     if (idx >= xkb_keymap_num_layouts(state->keymap))
         return -1;
 
+    /* Can only have one effective group. */
+    if (type & XKB_STATE_EFFECTIVE)
+        return state->group == idx;
+
     if (type & XKB_STATE_DEPRESSED)
         ret |= (state->base_group == idx);
     if (type & XKB_STATE_LATCHED)