diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs index 6f250f0d7..0f4d0b214 100644 --- a/wezterm-gui/src/termwindow/mod.rs +++ b/wezterm-gui/src/termwindow/mod.rs @@ -947,7 +947,11 @@ impl TermWindow { Ok(true) } WindowEvent::AdviseDeadKeyStatus(status) => { - log::trace!("DeadKeyStatus now: {:?}", status); + if self.config.debug_key_events { + log::info!("DeadKeyStatus now: {:?}", status); + } else { + log::trace!("DeadKeyStatus now: {:?}", status); + } self.dead_key_status = status; self.update_title(); // Ensure that we repaint so that any composing diff --git a/window/src/os/x11/keyboard.rs b/window/src/os/x11/keyboard.rs index 0715ecd5f..bad5b3245 100644 --- a/window/src/os/x11/keyboard.rs +++ b/window/src/os/x11/keyboard.rs @@ -38,7 +38,7 @@ struct Compose { enum FeedResult { Composing(String), Composed(String, xkb::Keysym), - Nothing(String, xkb::Keysym), + Nothing(String, xkb::Keysym, bool), Cancelled, } @@ -54,6 +54,8 @@ impl Compose { xsym: xkb::Keysym, key_state: &RefCell, ) -> FeedResult { + let had_composition = !self.composition.is_empty(); + if matches!( self.state.status(), ComposeStatus::Nothing | ComposeStatus::Cancelled | ComposeStatus::Composed @@ -62,7 +64,8 @@ impl Compose { } let previously_composing = !self.composition.is_empty(); - self.state.feed(xsym); + let feed_result = self.state.feed(xsym); + log::trace!("feed {xsym} -> result {feed_result:?}"); match self.state.status() { ComposeStatus::Composing => { @@ -112,7 +115,9 @@ impl Compose { } ComposeStatus::Nothing => { let utf8 = key_state.borrow().key_get_utf8(xcode); - FeedResult::Nothing(utf8, xsym) + let clear_dead_key_state = had_composition; + self.composition.clear(); + FeedResult::Nothing(utf8, xsym, clear_dead_key_state) } ComposeStatus::Cancelled => { self.state.reset(); @@ -292,7 +297,7 @@ impl KeyboardWithFallback { events.dispatch(WindowEvent::AdviseDeadKeyStatus(DeadKeyStatus::None)); sym } - FeedResult::Nothing(utf8, sym) => { + FeedResult::Nothing(utf8, sym, clear_dead_key_state) => { // Composition had no special expansion. // Xkb will return a textual representation of the key even when // it is not generally useful; for example, when CTRL, ALT or SUPER @@ -315,9 +320,20 @@ impl KeyboardWithFallback { log::trace!( "process_key_event: RawKeyEvent FeedResult::Nothing: \ - {utf8:?}, {sym:?}. kc -> {kc:?} fallback_feed={fallback_feed:?}" + {utf8:?}, {sym:?}. kc -> {kc:?} fallback_feed={fallback_feed:?} \ + clear_dead_key_state={clear_dead_key_state}" ); + if clear_dead_key_state { + // Some setups don't guarantee to trigger a state transition + // that will clear out the composition state, so we will + // synthesize it for ourselves here: since the + // FeedResult::Nothing case will emit a key to the GUI + // layer we take that as a signal that composition is + // complete and emit an event to clear it + events.dispatch(WindowEvent::AdviseDeadKeyStatus(DeadKeyStatus::None)); + } + // If we have a modified key, and its expansion is non-ascii, such as cyrillic // "Es" (which appears visually similar to "c" in latin texts), then consider // this key expansion against the default latin layout. @@ -333,7 +349,11 @@ impl KeyboardWithFallback { // Consider shortcuts like CTRL-C against the default // latin layout match fallback_feed { - FeedResult::Nothing(_fb_utf8, fb_sym) => { + FeedResult::Nothing( + _fb_utf8, + fb_sym, + _clear_dead_key_state, + ) => { log::trace!( "process_key_event: RawKeyEvent using fallback \ sym {fb_sym} because layout would expand to \