aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Kaplan <peter@pkap.de>2022-05-15 17:45:59 +0200
committerIsaac Freund <mail@isaacfreund.com>2022-05-15 23:08:34 +0200
commit47c02ebcbc484e44db728a84e446e3a159474e71 (patch)
tree0707835b2775fac74e4aefae7d0aa1e3008836e0
parentd47be3b5920cc0a9bed06a885bbf5785a06e8161 (diff)
downloadriver-47c02ebcbc484e44db728a84e446e3a159474e71.tar.gz
river-47c02ebcbc484e44db728a84e446e3a159474e71.tar.xz
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.
-rw-r--r--river/Mapping.zig37
1 files changed, 11 insertions, 26 deletions
diff --git a/river/Mapping.zig b/river/Mapping.zig
index 21b32fe..94ea2a4 100644
--- a/river/Mapping.zig
+++ b/river/Mapping.zig
@@ -69,7 +69,7 @@ pub fn deinit(self: Self) void {
pub fn match(
self: Self,
keycode: xkb.Keycode,
- modifiers_raw: wlr.Keyboard.ModifierMask,
+ modifiers: wlr.Keyboard.ModifierMask,
released: bool,
xkb_state: *xkb.State,
) bool {
@@ -82,43 +82,28 @@ pub fn match(
// will fall back to the active layout if so.
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`.
- const keysyms_raw = keymap.keyGetSymsByLevel(
+ const keysyms = keymap.keyGetSymsByLevel(
keycode,
layout_index,
0,
);
- if (std.meta.eql(modifiers_raw, self.modifiers)) {
- for (keysyms_raw) |sym| {
+ if (std.meta.eql(modifiers, self.modifiers)) {
+ for (keysyms) |sym| {
if (sym == self.keysym) {
return true;
}
}
}
- // Keysyms and modifiers as translated by xkb.
- // Modifiers used to translate the key are consumed.
- // E.g. pressing `Super+Shift 1` translates to `Super Exclam`.
- const keysyms_translated = keymap.keyGetSymsByLevel(
- keycode,
- layout_index,
- 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,
- );
+ // We deliberately choose not to translate keysyms and modifiers with xkb,
+ // 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.
- if (std.meta.eql(modifiers_translated, self.modifiers)) {
- for (keysyms_translated) |sym| {
- if (sym == self.keysym) {
- return true;
- }
- }
- }
return false;
}