diff options
author | Ran Benita <ran234@gmail.com> | 2016-02-27 22:31:16 +0200 |
---|---|---|
committer | Ran Benita <ran234@gmail.com> | 2016-10-31 12:52:28 +0200 |
commit | babc9e0c30918d3e12dea9e2e47b6c1c9c6cc1fb (patch) | |
tree | bb531bfd739d6f0d0f0c7f1ec263c95b682a5dbb /src/state.c | |
parent | a0a41332cc3811370b4f9d46528b7a590846e289 (diff) | |
download | xorg-lib-libxkbcommon-babc9e0c30918d3e12dea9e2e47b6c1c9c6cc1fb.tar.gz |
state: add GTK consumed modifiers mode
This is more or less what is implemented here:
https://git.gnome.org/browse/gtk+/tree/gdk/x11/gdkkeys-x11.c?h=3.19.10#n1131
The implementation here is more technically correct but should provide
the same results.
Try it out with ./test/interactive-evdev -g (modifiers prefixed with "-"
are consumed).
https://bugzilla.gnome.org/show_bug.cgi?id=754110
https://github.com/xkbcommon/libxkbcommon/issues/17
Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'src/state.c')
-rw-r--r-- | src/state.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/state.c b/src/state.c index 6611d33..039115a 100644 --- a/src/state.c +++ b/src/state.c @@ -1340,6 +1340,30 @@ key_get_consumed(struct xkb_state *state, const struct xkb_key *key, case XKB_CONSUMED_MODE_XKB: consumed = type->mods.mask; break; + + case XKB_CONSUMED_MODE_GTK: { + const struct xkb_key_type_entry *no_mods_entry; + xkb_level_index_t no_mods_leveli; + const struct xkb_level *no_mods_level, *level; + + no_mods_entry = get_entry_for_mods(type, 0); + no_mods_leveli = no_mods_entry ? no_mods_entry->level : 0; + no_mods_level = &key->groups[group].levels[no_mods_leveli]; + + for (unsigned i = 0; i < type->num_entries; i++) { + const struct xkb_key_type_entry *entry = &type->entries[i]; + if (!entry_is_active(entry)) + continue; + + level = &key->groups[group].levels[entry->level]; + if (XkbLevelsSameSyms(level, no_mods_level)) + continue; + + if (entry == matching_entry || popcount(entry->mods.mask) == 1) + consumed |= entry->mods.mask & ~entry->preserve.mask; + } + break; + } } return consumed & ~preserve; @@ -1386,6 +1410,7 @@ xkb_state_key_get_consumed_mods2(struct xkb_state *state, xkb_keycode_t kc, switch (mode) { case XKB_CONSUMED_MODE_XKB: + case XKB_CONSUMED_MODE_GTK: break; default: log_err_func(state->keymap->ctx, |