From 51986bce262ed24de947e5b5aea4ae0a0277de9f Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Mon, 10 Oct 2022 00:13:37 +0300 Subject: [PATCH] On X11, fix IME crashing during reload During reload we were picking old styles, but the styles could change during reload leading to errors during IME building. Fixes #2510. --- CHANGELOG.md | 1 + src/platform_impl/linux/x11/ime/callbacks.rs | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c050ebdf02..2e6f90a004 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ And please only add new entries to the top of this list, right below the `# Unre - On Windows, emit `ReceivedCharacter` events on system keybindings. - On Windows, fixed focus event emission on minimize. +- On X11, fixed IME crashing during reload. # 0.27.3 (2022-9-10) diff --git a/src/platform_impl/linux/x11/ime/callbacks.rs b/src/platform_impl/linux/x11/ime/callbacks.rs index 1f6bc23b1b..5fa6077058 100644 --- a/src/platform_impl/linux/x11/ime/callbacks.rs +++ b/src/platform_impl/linux/x11/ime/callbacks.rs @@ -108,10 +108,21 @@ unsafe fn replace_im(inner: *mut ImeInner) -> Result<(), ReplaceImError> { let mut new_contexts = HashMap::new(); for (window, old_context) in (*inner).contexts.iter() { let spot = old_context.as_ref().map(|old_context| old_context.ic_spot); - let style = old_context + + // Check if the IME was allowed on that context. + let is_allowed = old_context .as_ref() - .map(|old_context| old_context.style) + .map(|old_context| old_context.is_allowed()) .unwrap_or_default(); + + // We can't use the style from the old context here, since it may change on reload, so + // pick style from the new XIM based on the old state. + let style = if is_allowed { + new_im.preedit_style + } else { + new_im.none_style + }; + let new_context = { let result = ImeContext::new( xconn,