From 6afc35507c557e90cb47df1c35cf6e14bedf699f Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 7 Jan 2022 23:53:23 -0700 Subject: [PATCH] window: macos: fix lalt-` in default config w/ US layout lalt-` is technically a dead key combo, so we entered dead key processing, then realized that `send_composed_key_when_left_alt_is_pressed == false` and that we should ignore the dead-key-ness of the combo, but returned a composed result, which had the modifiers discarded. The correct way to handle this is to signal that it wasn't dead after all and to allow the main flow to build the KeyEvent as normal. --- window/src/os/macos/window.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/window/src/os/macos/window.rs b/window/src/os/macos/window.rs index 3de8bccc9..d90248d7f 100644 --- a/window/src/os/macos/window.rs +++ b/window/src/os/macos/window.rs @@ -1032,6 +1032,7 @@ fn decoration_to_mask(decorations: WindowDecorations) -> NSWindowStyleMask { } } +#[derive(Debug)] struct DeadKeyState { /// The private dead key state preserved from UCKeyTranslate dead_state: u32, @@ -1126,9 +1127,11 @@ extern "C" { fn LMGetKbdType() -> u8; } +#[derive(Debug)] enum TranslateStatus { Composing(String), Composed(String), + NotDead, } impl Inner { @@ -1232,6 +1235,8 @@ impl Inner { std::slice::from_raw_parts(unicode_buffer.as_mut_ptr(), length as _) })?; return Ok(TranslateStatus::Composing(composing)); + } else { + return Ok(TranslateStatus::NotDead); } length = 0; unsafe { @@ -1975,6 +1980,13 @@ impl WindowView { inner.events.dispatch(WindowEvent::KeyEvent(event)); return; } + Ok(TranslateStatus::NotDead) => { + // Turned out that while it would have been a dead + // key combo, our send_composed_key_when_XXX settings + // said otherwise. Let's continue as if it was not + // a dead key. + unmod + } Err(e) => { log::error!("Failed to translate dead key: {}", e); return;