Skip to content

android: report GameTextInput edits as IME events - #4736

Open
SergioRibera wants to merge 1 commit into
rust-windowing:masterfrom
SergioRibera:android-ime-events-pr
Open

SergioRibera wants to merge 1 commit into
rust-windowing:masterfrom
SergioRibera:android-ime-events-pr

Conversation

@SergioRibera

@SergioRibera SergioRibera commented Oct 5, 2026 •

Copy link
Copy Markdown

With the game-activity backend, text typed on the soft keyboard reaches winit as InputEvent::TextEvent, a snapshot of the whole GameTextInput buffer (text, selection and composing region). The backend currently drops it with Unknown android_activity input event, so typing only works for the few keys an IME sends as key events. On top of that the keyboard never learns what the field contains, so it can't capitalize or suggest from it.

This turns those snapshots into the Ime events other backends send:

  • GameTextInput reports its whole buffer, winit reports edits relative to the selection, so the new ime.rs keeps the field as the application has been told about it and diffs every snapshot against it. The changed span between the common prefix and suffix is widened to the selection, then reported as Ime::DeleteSurrounding + Ime::Commit (the commit replaces the selection, like on Wayland).
  • The composing region is reported as Ime::Preedit, with the caret inside it when the selection is in it. Keyboards that re-compose the word behind the caret (Gboard does it when you backspace into a word) show up as a deletion followed by a preedit, which is what the application needs to keep the same text on screen.
  • Ime::Enabled / Ime::Disabled are reported when the IME is enabled or disabled.
  • ImeSurroundingText from ImeRequest::Enable / Update is loaded into GameTextInput. GameTextInput restarts the input connection every time its buffer is replaced, and the keyboard then forgets the word it is composing, its shift state, etc. So nothing is loaded when the buffer already holds that text, which is the common case of an application echoing back an edit the keyboard just made. When something is loaded while composing, the preedit is kept in the buffer as the composing region.
  • The buffer is emptied on ImeRequest::Disable, so the next field doesn't start with the text of the previous one.

Known limitations, all on the GameTextInput side:

  • requestCursorUpdates isn't implemented there, so there's no CursorAnchorInfo and set_ime_cursor_area stays a no-op.
  • Moving the caret from the application still has to replace the buffer (restarting the connection) instead of calling InputMethodManager.updateSelection.

Caret moves made by the keyboard itself (space bar drag) aren't reported yet, that needs a new event and is a separate PR.

Probably closes #4067

Before After
screenrecorder-20261005-151422.mp4
screenrecorder-20261005-154155.mp4
  • Tested on all platforms changed
  • Added an entry to the changelog module if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality

@SergioRibera
SergioRibera force-pushed the android-ime-events-pr branch from 1feb8d2 to 32af5e4 Compare October 26, 2026 19:53
@SergioRibera SergioRibera changed the title feat(android): forward GameTextInput TextEvent as WindowEvent::Ime android: report GameTextInput edits as IME events Oct 26, 2026

This branch has not been deployed

No deployments
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.

Asking for more KeyAction events when using android keyboard.

1 participant