Skip to content

Commit f41897c

Browse files
authored
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.
1 parent bd6fef1 commit f41897c

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

winit-core/src/event.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,9 +788,10 @@ pub struct KeyEvent {
788788
/// ```
789789
pub repeat: bool,
790790

791-
/// Similar to [`text`][Self::text], except that this is affected by <kbd>Ctrl</kbd>.
791+
/// Similar to [`text`][Self::text], except that this is affected by <kbd>Ctrl</kbd> and may
792+
/// produce ASCII control characters.
792793
///
793-
/// For example, pressing <kbd>Ctrl</kbd>+<kbd>a</kbd> produces `Some("\x01")`.
794+
/// For example, pressing <kbd>Ctrl</kbd>+<kbd>space</kbd> produces `Some("\x00")`.
794795
///
795796
/// ## Platform-specific
796797
///

winit/examples/ime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl App {
200200
self.print_input_state();
201201
},
202202
_ => {
203-
if let Some(text) = event.text_with_all_modifiers {
203+
if let Some(text) = event.text {
204204
self.input_state.append_text(&text);
205205
if self.input_state.ime_enabled {
206206
self.window()

0 commit comments

Comments
 (0)