From 13ca693b1e615e04c526c19156eb2091a9f5f21a Mon Sep 17 00:00:00 2001 From: cyfung1031 <44498510+cyfung1031@users.noreply.github.com> Date: Mon, 12 Oct 2026 10:30:03 +0900 Subject: [PATCH] W2: Wayland: destroy the seat text input only when the seat is removed Port of rust-windowing/winit#4747 (merged on master). Originally "M15.1: preserve Wayland winit text input" in storytold/wordcraft#787 (same change as storytold/pdfcraft vendor/winit). --- src/platform_impl/linux/wayland/seat/mod.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/platform_impl/linux/wayland/seat/mod.rs b/src/platform_impl/linux/wayland/seat/mod.rs index eaecd93b..a9f9b62b 100644 --- a/src/platform_impl/linux/wayland/seat/mod.rs +++ b/src/platform_impl/linux/wayland/seat/mod.rs @@ -158,10 +158,11 @@ impl SeatHandler for WinitState { }, }; - if let Some(text_input) = seat_state.text_input.take() { - text_input.destroy(); - } - + // WordCraft patch: the text input belongs to the seat, not to a capability, so it is + // destroyed in `remove_seat` instead (rust-windowing/winit#4747). Destroying it here + // whenever any capability went away (a touch screen or tablet unplugged, a remote-desktop + // session ending) left the window without IME until restart: `new_capability` only + // recreates it when a capability is added. match capability { SeatCapability::Touch => { if let Some(touch) = seat_state.touch.take() { @@ -214,7 +215,11 @@ impl SeatHandler for WinitState { _queue_handle: &QueueHandle, seat: WlSeat, ) { - let _ = self.seats.remove(&seat.id()); + if let Some(mut seat_state) = self.seats.remove(&seat.id()) { + if let Some(text_input) = seat_state.text_input.take() { + text_input.destroy(); + } + } self.on_keyboard_destroy(&seat.id()); } }