garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

cartopolis-agent · 2026-11-27T15:42:21Z

fix(android): no platform keyboard over the app's own

bevy_ui_widgets turns the window's IME on whenever a text input has
the focus, and winit on Android answers with show_soft_input: since
egui went, every library field brought up the system keyboard over
the app's own keys, and under NativeActivity nothing it types arrives
(android-build.md). Search and chat took no text. Where the app draws
its own keyboard, the IME is turned back off before winit reads the
window.
crates/cartopolis/src/systems/gui/onscreen_keyboard.rs | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/crates/cartopolis/src/systems/gui/onscreen_keyboard.rs b/crates/cartopolis/src/systems/gui/onscreen_keyboard.rs
index be2dd47f..b1d22ded 100644
--- a/crates/cartopolis/src/systems/gui/onscreen_keyboard.rs
+++ b/crates/cartopolis/src/systems/gui/onscreen_keyboard.rs
@@ -930,7 +930,7 @@ pub fn drive_onscreen_keyboard(
     time: Res<Time<Real>>,
     touches: Option<Res<Touches>>,
     mut mouse: MessageReader<MouseButtonInput>,
-    windows: Query<&Window, With<PrimaryWindow>>,
+    mut windows: Query<&mut Window, With<PrimaryWindow>>,
     inset: Option<ResMut<KeyboardInset>>,
     mut commands: Commands,
 ) {
@@ -939,6 +939,16 @@ pub fn drive_onscreen_keyboard(
         return;
     }
     kb.follow_focus(input.overlay_owns_keyboard());
+    // `bevy_ui_widgets` turns the window's IME on whenever a text input has
+    // the focus (`PreUpdate`), and on Android winit answers that with the
+    // platform's soft keyboard: it covers these keys, and under
+    // NativeActivity nothing it types arrives (`android-build.md`). Turned
+    // back off before `Last` hands the window to winit, it never asks.
+    for mut window in &mut windows {
+        if window.ime_enabled {
+            window.ime_enabled = false;
+        }
+    }
 
     let viewport = Rect::from_corners(Vec2::ZERO, metrics.viewport_pts());
     let min_key_h = min_key_height_pts(metrics.ui_scale(), metrics.display_scale());