feat(wayland): SetTextInput takes text-input-v3's purposes and its version 1 hints, and enables anew for a field of another kind
Window::SetTextInput knew two purposes, Normal and Phone, and
Device::ApplyTextInput chose the content hints from them: none for
Phone, and completion, spellcheck and auto_capitalization for Normal.
Nothing could send another purpose, or hidden_text or sensitive_data:
a password field was Normal, with those three hints, or Phone.
Types: TextInputPurpose has the fourteen content purposes of the
bundled text-input-v3 protocol, in its order, so that the enumerators
have the protocol's values; Phone was 1 and is 4. kTextInputHintNone
and the ten kTextInputHint* bits are the content hints of version 1
of the protocol, the version Device binds the text input's manager
at, with the protocol's values, and kTextInputHintMask is the ten
together. TextInputDefaultHints(purpose) is what a field gets when
the caller names no hints: the three Normal had, hidden_text and
sensitive_data for Password and Pin, none for the other eleven. For
Normal and Phone without hints that is the content type they had
before.
Window: SetTextInput takes the hints as a last, defaulted
std::optional<std::uint32_t>, which tells kTextInputHintNone (no
hints) from no argument (the purpose's defaults). It keeps only the
bits of kTextInputHintMask: version 2's hints are not in version 1's
enum. On Win32 and in the browser the call still does nothing.
Device, ApplyTextInput: it sends the window's purpose and hints as
they are. For a window whose field is enabled it compares them with
the ones the enable in force went out with, which the window now
keeps, and when either differs it sends an enable before the content
type, where it sent the content type without one. The protocol, as
bundled in lib/text-input-unstable-v3-client-protocol.h, says of
set_content_type's values that "Subsequent attempts to update them
may have no effect" and that they "remain valid until the next
committed enable or disable request", and of enable that it "must be
issued every time the focused text input changes to a new one,
including within the current surface". The same text has an enable
reset "the state associated with preedit_string, commit_string, and
delete_surrounding_text events", so such an enable clears the pending
flags and the record of the composing text the window was last told,
as the disable path does (6f471ca), and fires no onPreedit. A call
with the purpose and hints of the enable in force sends no enable, as
before, also when it is for another field: the window does not know
one field from another of the same purpose and hints, and a caller
marks that move with SetTextInput(false) first.
Device, text_input_done: a listener of onTextInputDelete, onTextInput
or onPreedit may call SetTextInput, and the disable path's clearing
then ran in the middle of a done that was still reading the pending
flags and strings it clears: a disable from a listener of onPreedit
cleared the string the listeners' string_view points into, and one
from a listener of onTextInputDelete reset the flag the commit of the
same done waited on, so that commit never reached onTextInput. The
enable for a field of another kind clears the same values. A listener
may also dispatch the display, as Clipboard::GetText and Window's
constructor do, and the next done then ran inside the first, on
pending values the first had not yet reset. The handler now moves a
done out of the pending values as it arrives, onto a queue, and
delivers from there: the deletion, then the commit, then the
composing text. A done that arrives while another is being delivered
waits on the queue for it, so the window hears the dones in the order
they came. Only the dones wait: a key, pointer or touch event that
the same dispatch brings still fires where it arrives, ahead of a
done that waits, which the consumer notes now say. The commit goes
out whatever a listener of the deletion called SetTextInput with. The
composing text is reported only when nothing has overtaken it since
its done arrived: textInputEpoch, a counter in Device.cpp, moves at a
disable, at an enable for a field of another kind, at a leave and at
every done, and the handler compares the value a done arrived with
against the one after its commit's listeners. A listener may also
destroy the window: ~Window calls Device::ForgetTextInputDones, which
takes the window out of the queue's entries, the one being delivered
among them, and the handler fires nothing more of those. A look-up of
the address in Device::windows would take a window opened at that
address in the meantime for the one destroyed.
Tests: TextInputContent (new) makes the text input a proxy on a
wl_display over a socketpair, as TitleWayland makes its proxies,
reads the requests off the other end and calls the text input's
listener callbacks itself. It checks the purposes and the hint
constants against the bundled protocol header's values, the mask,
and the default hints of the fourteen purposes; then, on the wire:
nothing from a window the text input has not entered; an enable, the
content type, the caret and a commit at the enter; no enable for a
caret that moves; an enable with its own content type for the other
thirteen purposes in turn, after which a composing text equal to the
one before them reaches onPreedit again; named hints in place of the
defaults; an enable for other hints under the same purpose; a
version 2 hint (no_emoji) neither sent nor taken for a change;
kTextInputHintNone sent as 0; the caret in surface coordinates at a
scale of 2; one disable for a field losing the focus; no enable for
a call for another field of the same purpose and hints, and one when
a disable comes before it; and after a leave, nothing until the
enter, which enables the field the window has by then. For the done,
with two listeners on onTextInput and on onPreedit: a first listener
of onPreedit that changes the purpose, or disables the field, and the
listener after it are given the composing text as the input method
sent it; after a listener of onTextInputDelete that changes the
hints, or disables the field, the commit of the same done reaches
both listeners of onTextInput and that done fires no onPreedit; a
done fed from inside a listener of
onTextInputDelete is delivered after the one that listener was called
for, whose commit reaches the listeners of onTextInput before the fed
one's; a done fed from inside a listener of onTextInput is delivered
after that listener's done, whose own composing text is not reported;
a leave fed from inside a listener of onTextInput is followed by no
onPreedit for that done's composing text; and when a listener of
onTextInputDelete feeds a done, destroys the window and puts another
at its address, listed in Device::windows, neither onTextInput nor
onPreedit fires on the new one.
Docs: the consumer notes list the purposes and the hints, the default
hints, what a call that changes either does to a composition under
way, the SetTextInput(false) that marks a move to another field of
the same purpose and hints, and the order the input method's dones
are delivered in. AGENTS.template.md names TextInputContent among
the tests that need no GPU.
This commit is contained in:
parent
89111e0d65
commit
a9ce1a02e8
9 changed files with 707 additions and 24 deletions
|
|
@ -227,8 +227,19 @@ export namespace Crafter {
|
|||
// Tells the compositor's input method that a text field has focus
|
||||
// (an on-screen keyboard opens) and where its caret is, in physical
|
||||
// pixels, or that none has. Remembered: it is applied again whenever
|
||||
// the keyboard focus comes back to this window.
|
||||
void SetTextInput(bool active, std::int32_t x = 0, std::int32_t y = 0, std::int32_t width = 0, std::int32_t height = 0, TextInputPurpose purpose = TextInputPurpose::Normal);
|
||||
// the keyboard focus comes back to this window. `purpose` says what
|
||||
// the field holds and `hints` how the input method treats it
|
||||
// (kTextInputHint*, or-ed together); without hints the field gets
|
||||
// its purpose's usual ones, TextInputDefaultHints(purpose). The input
|
||||
// method takes a field's purpose and hints when the field is
|
||||
// enabled, and a field of another kind is another field to it: a
|
||||
// call that changes either while a field has focus enables anew,
|
||||
// which ends the composition under way, as a disable does. A caret
|
||||
// that moves within one field sends its rectangle alone, and so
|
||||
// does a move to another field of the same purpose and hints, which
|
||||
// the window cannot tell from it: mark that move with
|
||||
// SetTextInput(false) before the new field's call.
|
||||
void SetTextInput(bool active, std::int32_t x = 0, std::int32_t y = 0, std::int32_t width = 0, std::int32_t height = 0, TextInputPurpose purpose = TextInputPurpose::Normal, std::optional<std::uint32_t> hints = std::nullopt);
|
||||
// Like SetPresentMode, a resize asked for while a frame is being
|
||||
// recorded takes effect once that frame has been presented, width and
|
||||
// height included, which the rest of the frame still draws at. On
|
||||
|
|
@ -464,6 +475,11 @@ export namespace Crafter {
|
|||
bool textInputEnabled_ = false; // enable sent and not taken back since
|
||||
std::int32_t textInputRect_[4] = { 0, 0, 0, 0 };
|
||||
TextInputPurpose textInputPurpose_ = TextInputPurpose::Normal;
|
||||
std::uint32_t textInputHints_ = TextInputDefaultHints(TextInputPurpose::Normal);
|
||||
// The purpose and hints the enable in force went out with: a field
|
||||
// of another kind is enabled anew (see SetTextInput).
|
||||
TextInputPurpose textInputEnabledPurpose_ = TextInputPurpose::Normal;
|
||||
std::uint32_t textInputEnabledHints_ = kTextInputHintNone;
|
||||
|
||||
static void xdg_surface_handle_preferred_scale(void* data, wp_fractional_scale_v1*, std::uint32_t scale);
|
||||
static void wl_surface_frame_done(void *data, wl_callback *cb, uint32_t time);
|
||||
|
|
|
|||
Loading…
Reference in a new issue