From c4970b7fc8f2eae994b80e95154f5fee0e3c7771 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 21 Jan 2024 13:11:36 -0700 Subject: [PATCH] xkbd: don't merge in modifiers, use only when missing I think it will be safer to only take the flags from the event in the case that the state reports zero modifiers. refs: https://github.com/wez/wezterm/issues/4776 closes: https://github.com/wez/wezterm/pull/4781 --- window/src/os/x11/keyboard.rs | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/window/src/os/x11/keyboard.rs b/window/src/os/x11/keyboard.rs index b33fe04bb..7d8be7113 100644 --- a/window/src/os/x11/keyboard.rs +++ b/window/src/os/x11/keyboard.rs @@ -169,15 +169,8 @@ impl KeyboardWithFallback { self.process_key_event_impl(code + 8, Modifiers::default(), pressed, events, want_repeat) } - /// When XKB doesn't have modifiers in its state but there are modifiers given in the X - /// event, use these as fallback. - /// - /// This can happen (FIXME: WHY) for example when Espanso (a text expander/injector) - /// simulate inputs. - /// - /// This also happens intermittently for wez on an Ubuntu system where - /// the XServer clears the mask state seemingly at the wrong time via - /// a call into process_xkb_event that zeroes out all the modifier states. + /// Compute the Modifier mask equivalent from the button mask + /// provided in an XCB keyboard event fn modifiers_from_btn_mask(mask: xcb::x::KeyButMask) -> Modifiers { let mut res = Modifiers::default(); if mask.contains(xcb::x::KeyButMask::SHIFT) { @@ -228,13 +221,29 @@ impl KeyboardWithFallback { fn process_key_event_impl( &self, xcode: xkb::Keycode, - additional_x_raw_modifiers: Modifiers, + modifiers_from_event: Modifiers, pressed: bool, events: &mut WindowEventSender, want_repeat: bool, ) -> Option { let phys_code = self.selected.phys_code_map.borrow().get(&xcode).copied(); - let raw_modifiers = self.get_key_modifiers() | additional_x_raw_modifiers; + + let modifiers_from_state = self.get_key_modifiers(); + // When XKB doesn't have modifiers in its state but there are modifiers + // given in the X event, use the values from the X event. + // + // This can happen (FIXME: WHY) for example when Espanso + // (a text expander/injector) simulate inputs. + // + // This also happens intermittently for wez on an Ubuntu system where + // the XServer clears the mask state seemingly at the wrong time via + // a call into process_xkb_event that zeroes out all the modifier states. + let raw_modifiers = if modifiers_from_state.is_empty() { + modifiers_from_event + } else { + modifiers_from_state + }; + let leds = self.get_led_status(); let xsym = self.selected.state.borrow().key_get_one_sym(xcode);