Skip to content

android: request a redraw on GameTextInput commits - #4673

Open
mudbungie wants to merge 1 commit into
rust-windowing:masterfrom
mudbungie:android-text-event-redraw
Open

android: request a redraw on GameTextInput commits#4673
mudbungie wants to merge 1 commit into
rust-windowing:masterfrom
mudbungie:android-text-event-redraw

Conversation

@mudbungie

Copy link
Copy Markdown

The problem

With the game-activity backend, everything the IME's InputConnection
commits lands in the GameTextInput buffer and reaches winit as
InputEvent::TextEvent (and enter-key actions as
InputEvent::TextAction). The android event loop currently drops both in
its catch-all _ => arm — without requesting a redraw — even though the
looper was already woken for them (native_app_glue's onTextInputEvent
calls notifyInput).

The consequence: an application that reads
AndroidApp::text_input_state() per frame (the only way to consume IME
text today, since these events are not translated into Ime events) can
only notice a commit by polling on a timer, and that poll cadence is felt
directly as typing latency.

The change

Set the redraw flag for both events. single_iteration reads the flag
later in the same loop iteration, so an IME commit produces a frame on its
own edge and the buffer poll disappears.

Measured on device (current-generation Pixel, SDK 35, Gboard, egui app):
with this arm and a 1 s heartbeat as the only timer, injected-tap to
glyph-adopted is ~72–87 ms — nearly all of it the injection harness's JVM
startup plus IME processing — where previously text appeared only at the
poll interval.

What this is not

Not IME support: fully translating TextEvent into Ime events is blocked
on semantics (the Ime vocabulary cannot express
deleteSurroundingText; related: #2305). This change only stops
discarding a wake that has already happened, so buffer-reading
applications become event-driven.

android-activity's game-activity backend delivers InputEvent::TextEvent
and InputEvent::TextAction when the IME's InputConnection edits the
GameTextInput buffer, and the looper is already woken for them
(native_app_glue's onTextInputEvent calls notifyInput). The android event
loop dropped both in its catch-all arm without producing a frame, so an
application reading AndroidApp::text_input_state() could only notice an
IME commit by polling on a timer — poll cadence becomes typing latency.

Set the redraw flag for both events. The flag is read later in the same
loop iteration, so a commit produces a frame on its own edge. Translating
these events into winit Ime events remains open (the Ime vocabulary
cannot express deleteSurroundingText); this only stops discarding the
wake that already happened.
@mudbungie
mudbungie requested a review from MarijnS95 as a code owner August 24, 2026 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant