state: special case effective group in layout_is_active 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>
diff --git a/src/state.c b/src/state.c
index 3da01a1..41a719d 100644
--- a/src/state.c
+++ b/src/state.c
@@ -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)