From cbf29c2e53811717c82ab6bf2e7a2cd1592e4943 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 25 Dec 2020 10:29:30 -0800 Subject: [PATCH] window: x11: remove SHIFT state from KeyCode::Char(_) When we decode a key event from X11 into a `KeyCode::Char(_)` variant, that result has already factored in the result of the SHIFT modifier state. That makes SHIFT largely useless for unicode keys; we do want to preserve the SHIFT modifier for keys such as the arrow keys. This commit removes SHIFT from the `KeyEvent::modifiers` for `KeyCode::Char(_)` variants so that those modifiers don't get in the way of keymap lookups. refs: https://github.com/wez/wezterm/issues/394 --- window/src/os/x11/keyboard.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/window/src/os/x11/keyboard.rs b/window/src/os/x11/keyboard.rs index 3c32fa441..245229945 100644 --- a/window/src/os/x11/keyboard.rs +++ b/window/src/os/x11/keyboard.rs @@ -133,13 +133,22 @@ impl Keyboard { }; let kc = keysym_to_keycode(ksym).or_else(|| keysym_to_keycode(xsym))?; - let modifiers = self.get_key_modifiers(); + let raw_modifiers = self.get_key_modifiers(); + // X11 keysyms that map to KeyCode::Char already factor in the SHIFT + // modifier state. eg: SHIFT-c in an US layout produces `Char('C')`. + // So, if we have `Char`, remove SHIFT from the processed modifier + // state. Not doing so can produce frustration such as that in + // https://github.com/wez/wezterm/issues/394 + let modifiers = match (&kc, raw_modifiers) { + (crate::KeyCode::Char(_), mods) => mods - Modifiers::SHIFT, + (_, mods) => mods, + }; Some(KeyEvent { key: kc, modifiers, raw_key: None, - raw_modifiers: modifiers, + raw_modifiers, raw_code: Some(xcode), repeat_count: 1, key_is_down: pressed,