Mapping: Do not translate keys with xkb

When checking keys for matching mappings, previously we did two checks:

1. Keysyms translated by xkb.
2. Raw keysyms

This commit removes the first check, so only the second is checked.

We're doing this because of strange behavior that xkb shows for some
layouts and keys. When pressing `Shift Space` on some layouts (Swedish
among others), xkb reports `Shift` as consumed. This leads to the case
that we cannot distinguish between `Space` and `Shift Space` presses
when doing a correct translation with xkb.
This commit is contained in:
Peter Kaplan 2022-05-15 17:45:59 +02:00 committed by Isaac Freund
parent d47be3b592
commit 47c02ebcbc

View File

@ -69,7 +69,7 @@ pub fn deinit(self: Self) void {
pub fn match( pub fn match(
self: Self, self: Self,
keycode: xkb.Keycode, keycode: xkb.Keycode,
modifiers_raw: wlr.Keyboard.ModifierMask, modifiers: wlr.Keyboard.ModifierMask,
released: bool, released: bool,
xkb_state: *xkb.State, xkb_state: *xkb.State,
) bool { ) bool {
@ -82,43 +82,28 @@ pub fn match(
// will fall back to the active layout if so. // will fall back to the active layout if so.
const layout_index = self.layout_index orelse xkb_state.keyGetLayout(keycode); const layout_index = self.layout_index orelse xkb_state.keyGetLayout(keycode);
// Raw keysyms and modifiers as if modifiers didn't change keysyms. // Get keysyms from the base layer, as if modifiers didn't change keysyms.
// E.g. pressing `Super+Shift 1` does not translate to `Super Exclam`. // E.g. pressing `Super+Shift 1` does not translate to `Super Exclam`.
const keysyms_raw = keymap.keyGetSymsByLevel( const keysyms = keymap.keyGetSymsByLevel(
keycode, keycode,
layout_index, layout_index,
0, 0,
); );
if (std.meta.eql(modifiers_raw, self.modifiers)) { if (std.meta.eql(modifiers, self.modifiers)) {
for (keysyms_raw) |sym| { for (keysyms) |sym| {
if (sym == self.keysym) { if (sym == self.keysym) {
return true; return true;
} }
} }
} }
// Keysyms and modifiers as translated by xkb. // We deliberately choose not to translate keysyms and modifiers with xkb,
// Modifiers used to translate the key are consumed. // because of strange behavior that xkb shows for some layouts and keys.
// E.g. pressing `Super+Shift 1` translates to `Super Exclam`. // When pressing `Shift Space` on some layouts (Swedish among others),
const keysyms_translated = keymap.keyGetSymsByLevel( // xkb reports `Shift` as consumed. This leads to the case that we cannot
keycode, // distinguish between `Space` and `Shift Space` presses when doing a
layout_index, // correct translation with xkb.
xkb_state.keyGetLevel(keycode, layout_index),
);
const consumed = xkb_state.keyGetConsumedMods2(keycode, xkb.ConsumedMode.xkb);
const modifiers_translated = @bitCast(
wlr.Keyboard.ModifierMask,
@bitCast(u32, modifiers_raw) & ~consumed,
);
if (std.meta.eql(modifiers_translated, self.modifiers)) {
for (keysyms_translated) |sym| {
if (sym == self.keysym) {
return true;
}
}
}
return false; return false;
} }