From f41897cfa49e043db2bac1279d2f34d6c429c2aa Mon Sep 17 00:00:00 2001 From: DorotaC <43449960+dcz-self@users.noreply.github.com> Date: Wed, 29 Oct 2025 05:40:30 +0100 Subject: [PATCH] examples/ime: fix crash on wayland When pressing Ctrl+Space, KeyEvent::text_with_all_modifiers would return \0. That would get included in the text-input text. When an input method gets activated, the invalid string returning \0 would get sent as surrounding text, resulting in a Wayland protocol error and crashing the application. --- winit-core/src/event.rs | 5 +++-- winit/examples/ime.rs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/winit-core/src/event.rs b/winit-core/src/event.rs index a787c1e2..4cbe41b7 100644 --- a/winit-core/src/event.rs +++ b/winit-core/src/event.rs @@ -788,9 +788,10 @@ pub struct KeyEvent { /// ``` pub repeat: bool, - /// Similar to [`text`][Self::text], except that this is affected by Ctrl. + /// Similar to [`text`][Self::text], except that this is affected by Ctrl and may + /// produce ASCII control characters. /// - /// For example, pressing Ctrl+a produces `Some("\x01")`. + /// For example, pressing Ctrl+space produces `Some("\x00")`. /// /// ## Platform-specific /// diff --git a/winit/examples/ime.rs b/winit/examples/ime.rs index 28e5c487..c2251fe9 100644 --- a/winit/examples/ime.rs +++ b/winit/examples/ime.rs @@ -200,7 +200,7 @@ impl App { self.print_input_state(); }, _ => { - if let Some(text) = event.text_with_all_modifiers { + if let Some(text) = event.text { self.input_state.append_text(&text); if self.input_state.ime_enabled { self.window()