Skip to content

Commit

Permalink
Ensure breaking a latch is always all-or-nothing
Browse files Browse the repository at this point in the history
Signed-off-by: Jules Bertholet <[email protected]>
  • Loading branch information
Jules-Bertholet committed Jan 6, 2025
1 parent 2b3a0f4 commit 6670fe3
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,24 +609,20 @@ xkb_filter_mod_latch_func(struct xkb_state *state,
actions->type == ACTION_TYPE_MOD_LATCH) {
/* We break latches only for mods that are part of the type's mod mask,
and are not preserved. */

xkb_layout_index_t group = xkb_state_xkb_key_get_layout(state, key);
const struct xkb_key_type *type = key->groups[group].type;
xkb_mod_mask_t type_mod_mask = type->mods.mask;

const struct xkb_key_type_entry *entry = get_entry_for_mods(type, state->components.mods & type_mod_mask);
if (entry) {
type_mod_mask &= ~entry->preserve.mask;
}

xkb_mod_mask_t filter_mod_mask = filter->action.mods.mods.mask;
xkb_mod_mask_t mods_to_unlatch_mask = filter_mod_mask & type_mod_mask;
xkb_mod_mask_t mods_to_keep_mask = filter_mod_mask & ~type_mod_mask;

state->components.latched_mods &= ~mods_to_unlatch_mask;
if (mods_to_keep_mask == 0) {
if (filter_mod_mask & type_mod_mask) {
state->components.latched_mods &= ~filter_mod_mask;
filter->func = NULL;
} else {
filter->action.mods.mods.mask = mods_to_keep_mask;
}

return XKB_FILTER_CONTINUE;
Expand Down

0 comments on commit 6670fe3

Please sign in to comment.