Skip to main content

Module text_input_hook

Module text_input_hook 

Source
Expand description

The platform’s text input system, past what winit forwards.

winit hands an application two kinds of text: what a key press produced, and the end of an IME composition the user typed. The text input system sends more than that, and winit 0.30 drops the rest:

  • macOS. Emoji & Symbols, Dictation, AutoFill and Writing Tools all write through NSTextInputClient on winit’s view, outside any key press. winit commits an insertText: only while it holds marked text, so the string is discarded. The same view answers every question about the document (selectedRange, attributedSubstringForProposedRange:) with “nothing”, so nothing that reads or corrects text can work.
  • Windows. winit reads the input system through IMM32 alone. The emoji panel and voice typing reach it as IMM results, so they arrive as compositions: nothing tells voice typing apart without a TSF text store, and winit cannot end a composition the field has already kept.

This module attaches to each window’s native surface once it exists and detaches when it closes. Text the input system inserts outside a key press is posted to the application as an ImeCommitPayload, which teksilo-app delivers to the window’s focused widget as a WidgetEvent::ImeCommit. Which part of the input system the text came from is decided by one rule shared by the platforms, classify.

The native surface also answers the input system’s questions about the document (where the selection is, what the text of a range is, where a range is drawn, which character is under a point) from the document of the window’s focused text widget, which its tree’s TextSurfaces reach; answers holds the part of that which needs no platform.

A key press the input method takes for itself, without typing or composing anything, must not type its text either; one it answers with a commit of its own is the input method’s, as the key that ends a composition is; and one it types as another character (a full-width space) types that character: key_taken_by_input_method tells the application, while it handles the key, which it was.

Where it stands, measured on macOS 27: Emoji & Symbols, the press-and-hold accent popup, Dictation and Writing Tools (in its panel) insert into the focused field. Dictation is told apart from a composition through private AppKit methods (see the macOS backend). A composition its input method leaves marked when the user switches to another input source is kept as committed where it is, and the input method’s later delivery of it is dropped. On Windows the hook has the input method complete a composition the field ends, and tells the field what it committed (finish_composition); answers the input method’s requests about the document (where a character is drawn, the text around the composition); and when asked, it traces.

With TEKSILO_TEXT_INPUT_TRACE=1 set the hooks also log every call they see to stderr, which is how the per-OS behaviour they rely on was measured. TEKSILO_TEXT_INPUT_TRACE=stacks adds, on macOS, a short call stack to the input method’s calls inside a key press, and every respondsToSelector: asked of the view inside one.

Structs§

FinishedComposition
How the platform ended a window’s composition, as finish_composition reports it.
ImeCommitPayload
Text the platform’s input system committed into a window outside what winit reports, posted through the window’s AppEventPoster::post_external. teksilo-app delivers it to the window’s focused widget as a WidgetEvent::ImeCommit with the same fields; a payload for a window that has closed since is dropped.

Enums§

TakenKey
What the platform’s input method made of a key press, when it did not hand the key back as it was, as key_taken_by_input_method answers.

Functions§

attach
Attach to a window’s native surface. Main thread only, once the window exists. A no-op where the platform needs nothing.
detach
Forget a window. Safe to call for a window that was never attached.
finish_composition
End the window’s composition (a click elsewhere, a focus change), and say what the input method committed for it.
key_taken_by_input_method
What the platform’s input method took of the key press window_id is handling right now, if anything: see TakenKey.
take_marked_replacement
The range of the focused field’s text (its character offsets) that the macOS input method gave its latest setMarkedText: as the text the composition replaces, taken once.
trace_enabled
Whether TEKSILO_TEXT_INPUT_TRACE is set to anything but 0. Read once.