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
|
|
@ -33,7 +33,7 @@ window.StartSync(); // the event loop
|
||||||
- `Update()` computes `mouseDelta` and calls `Render()`, which waits for the fence of its frame slot (three frames in flight, `Window::numFrames`; the slot is `window.currentFrame`), acquires a swapchain image (`window.currentImage`; the swapchain has as many images as its present mode needs, not necessarily three), writes it into this window's swapchain slots of the heap, reclaims deferred deletions, begins `drawCmdBuffers[currentFrame]`, binds the heap (or the descriptor set), fires `onUpdate(FrameTime)`, records every pass in `passes` in order with a barrier on the swapchain image between them, transitions the image to present, submits and presents. Per-frame GPU work of your own (a TLAS rebuild, a physics dispatch) is recorded from `onUpdate` into `window.drawCmdBuffers[window.currentFrame]`; the heaps are bound by then and the passes come after. A `Resize` or `SetPresentMode` from a listener of the frame (an input action ticked in `onUpdate`, say) takes effect after its present. `onResize` fires after a swapchain rebuild (a new size or present mode); the swapchain slots follow by themselves, and anything else that holds the old images or is sized after the window is made again there.
|
- `Update()` computes `mouseDelta` and calls `Render()`, which waits for the fence of its frame slot (three frames in flight, `Window::numFrames`; the slot is `window.currentFrame`), acquires a swapchain image (`window.currentImage`; the swapchain has as many images as its present mode needs, not necessarily three), writes it into this window's swapchain slots of the heap, reclaims deferred deletions, begins `drawCmdBuffers[currentFrame]`, binds the heap (or the descriptor set), fires `onUpdate(FrameTime)`, records every pass in `passes` in order with a barrier on the swapchain image between them, transitions the image to present, submits and presents. Per-frame GPU work of your own (a TLAS rebuild, a physics dispatch) is recorded from `onUpdate` into `window.drawCmdBuffers[window.currentFrame]`; the heaps are bound by then and the passes come after. A `Resize` or `SetPresentMode` from a listener of the frame (an input action ticked in `onUpdate`, say) takes effect after its present. `onResize` fires after a swapchain rebuild (a new size or present mode); the swapchain slots follow by themselves, and anything else that holds the old images or is sized after the window is made again there.
|
||||||
- On Wayland the compositor resizes a window with a configure (a maximize, a tile, a drag of its border, a phone's on-screen keyboard coming or going), and the window answers it with a frame, not in the configure's listener, which only keeps the size. The next `Render()` starts by making the swapchain again at it and firing `onResize`, before the frame's `onUpdate`, with the queue idle and no frame being recorded, as `Resize` fires it; and the frame it then presents brings, with the present's commit, the first buffer of the new size together with the surface's new size and the configure's acknowledgement. (A size configured while a frame is being recorded is taken at the end of that `Render()`, after its present, and the frame after it brings it.) So `onResize` for such a resize comes from inside `Render()`: for a consumer that calls `Update()` itself, a `try` around it covers the rebuild's Vulkan calls, while a window under `StartUpdate` draws where its frames always do: from its frame callback, inside the event dispatch, when it is on the compositor's clock, and from `StartSync`'s loop, after the dispatch, when it is on its own (`updateInterval`). Until that frame's present the window keeps its old size on screen, and then changes size with the buffer drawn for the new one, where it used to change at the configure and show the last frame scaled until the next. The exception is a present that fails: what the frame sent ahead of it stays pending for the surface's next commit. A window that updates from `StartUpdate` needs nothing: its next `Update()`, from the frame callback or from its clock, is that frame. On the compositor's clock that counts on the frame callbacks going on while a configure waits for its answer, as KWin's do. A window that draws on demand (it calls `Update()` itself when something changed) must ask for a frame when `onFrameOwed` fires, as it does from `onResize`: `onFrameOwed` (Wayland only, `Event<void>`) fires from the configure, after `onToplevelState`, whenever the configure leaves a frame owed, and nothing has been rebuilt by then. The listener marks the window as wanting a frame and lets its loop draw it; it does not call `Update()` itself, because the event fires wherever the events are dispatched, and that may be inside a frame being recorded (a listener of that frame made a `Window` or called `Clipboard::GetText`), which `onResize` never is. Without that frame the configure is never answered and the window never takes the new size. A window that has stopped updating (`StopUpdate`) is in the same position. `Resize` and `SetPresentMode` called outside a frame still rebuild at once and fire `onResize` from the call; the surface takes the new size with the next frame there too. A rebuild that throws is tried again by the next `Render()`. A Wayland window has two sizes: `width` and `height`, the pixels of its buffers, and `logicalWidth` and `logicalHeight`, the surface's size in surface-local units, which is what a configure gives and what the compositor lays the window out by; `scale` is the compositor's preferred scale (1 where it has no `wp_fractional_scale_v1` or no `wp_viewporter`), and the two sizes are worked out from one another with it only when a size is taken and when a swapchain is made, so between those moments `scale` may be newer than they are. A size the compositor configured is the surface's size unchanged, with `width` and `height` the pixels it came to then, rounded up (the size in the first configure, the one the constructor waits for, is the exception: it is not taken, #166); a size the application gave (the constructor's, `Resize`) is in pixels, and the surface's size is what they came to. Of a `Resize` and a configured size the one asked for last is taken. Where a configured size comes to the pixels the window has (an output's scale changed under a window that fills it), the frame brings the surface its new size, nothing is rebuilt and `onResize` does not fire; `onFrameOwed` does. A scale that changes by itself is not acted on until the next swapchain or configured size (#165).
|
- On Wayland the compositor resizes a window with a configure (a maximize, a tile, a drag of its border, a phone's on-screen keyboard coming or going), and the window answers it with a frame, not in the configure's listener, which only keeps the size. The next `Render()` starts by making the swapchain again at it and firing `onResize`, before the frame's `onUpdate`, with the queue idle and no frame being recorded, as `Resize` fires it; and the frame it then presents brings, with the present's commit, the first buffer of the new size together with the surface's new size and the configure's acknowledgement. (A size configured while a frame is being recorded is taken at the end of that `Render()`, after its present, and the frame after it brings it.) So `onResize` for such a resize comes from inside `Render()`: for a consumer that calls `Update()` itself, a `try` around it covers the rebuild's Vulkan calls, while a window under `StartUpdate` draws where its frames always do: from its frame callback, inside the event dispatch, when it is on the compositor's clock, and from `StartSync`'s loop, after the dispatch, when it is on its own (`updateInterval`). Until that frame's present the window keeps its old size on screen, and then changes size with the buffer drawn for the new one, where it used to change at the configure and show the last frame scaled until the next. The exception is a present that fails: what the frame sent ahead of it stays pending for the surface's next commit. A window that updates from `StartUpdate` needs nothing: its next `Update()`, from the frame callback or from its clock, is that frame. On the compositor's clock that counts on the frame callbacks going on while a configure waits for its answer, as KWin's do. A window that draws on demand (it calls `Update()` itself when something changed) must ask for a frame when `onFrameOwed` fires, as it does from `onResize`: `onFrameOwed` (Wayland only, `Event<void>`) fires from the configure, after `onToplevelState`, whenever the configure leaves a frame owed, and nothing has been rebuilt by then. The listener marks the window as wanting a frame and lets its loop draw it; it does not call `Update()` itself, because the event fires wherever the events are dispatched, and that may be inside a frame being recorded (a listener of that frame made a `Window` or called `Clipboard::GetText`), which `onResize` never is. Without that frame the configure is never answered and the window never takes the new size. A window that has stopped updating (`StopUpdate`) is in the same position. `Resize` and `SetPresentMode` called outside a frame still rebuild at once and fire `onResize` from the call; the surface takes the new size with the next frame there too. A rebuild that throws is tried again by the next `Render()`. A Wayland window has two sizes: `width` and `height`, the pixels of its buffers, and `logicalWidth` and `logicalHeight`, the surface's size in surface-local units, which is what a configure gives and what the compositor lays the window out by; `scale` is the compositor's preferred scale (1 where it has no `wp_fractional_scale_v1` or no `wp_viewporter`), and the two sizes are worked out from one another with it only when a size is taken and when a swapchain is made, so between those moments `scale` may be newer than they are. A size the compositor configured is the surface's size unchanged, with `width` and `height` the pixels it came to then, rounded up (the size in the first configure, the one the constructor waits for, is the exception: it is not taken, #166); a size the application gave (the constructor's, `Resize`) is in pixels, and the surface's size is what they came to. Of a `Resize` and a configured size the one asked for last is taken. Where a configured size comes to the pixels the window has (an output's scale changed under a window that fills it), the frame brings the surface its new size, nothing is rebuilt and `onResize` does not fire; `onFrameOwed` does. A scale that changes by itself is not acted on until the next swapchain or configured size (#165).
|
||||||
- A `RenderPass` is `Record(cmd, frameIdx, window)` plus `SwapchainStage()`, which must return the stage that touches the swapchain image (`COMPUTE_SHADER`, `RAY_TRACING_SHADER` or `TRANSFER`): the frame's barriers take their stage and access masks from it. `frameIdx` is the frame slot, `window.currentFrame`, not the image: the frame's image is `window.images[window.currentImage]`. The image stays in `VK_IMAGE_LAYOUT_GENERAL` through the whole pass list, with `STORAGE | TRANSFER_SRC` usage and `TRANSFER_DST` where the surface allows it (`window.swapchainUsage`). Nothing clears it: draw a background quad, or clear from a transfer pass where `TRANSFER_DST` is there.
|
- A `RenderPass` is `Record(cmd, frameIdx, window)` plus `SwapchainStage()`, which must return the stage that touches the swapchain image (`COMPUTE_SHADER`, `RAY_TRACING_SHADER` or `TRANSFER`): the frame's barriers take their stage and access masks from it. `frameIdx` is the frame slot, `window.currentFrame`, not the image: the frame's image is `window.images[window.currentImage]`. The image stays in `VK_IMAGE_LAYOUT_GENERAL` through the whole pass list, with `STORAGE | TRANSFER_SRC` usage and `TRANSFER_DST` where the surface allows it (`window.swapchainUsage`). Nothing clears it: draw a background quad, or clear from a transfer pass where `TRANSFER_DST` is there.
|
||||||
- `window.width` and `height` are physical pixels, as is `currentMousePos`. `CaptureNextFrame(path)` saves the next frame as a PNG. `SetTitle`, `SetAppId`, `SetCursorImage`, `SetDefaultCursor`; `SetTextInput(active, x, y, w, h, purpose)` tells the compositor's input method a text field has focus, which opens an on-screen keyboard on a phone.
|
- `window.width` and `height` are physical pixels, as is `currentMousePos`. `CaptureNextFrame(path)` saves the next frame as a PNG. `SetTitle`, `SetAppId`, `SetCursorImage`, `SetDefaultCursor`; `SetTextInput(active, x, y, w, h, purpose, hints)` tells the compositor's input method a text field has focus, which opens an on-screen keyboard on a phone. `purpose` is what the field holds (`TextInputPurpose::Normal`, `Alpha`, `Digits`, `Number`, `Phone`, `Url`, `Email`, `Name`, `Password`, `Pin`, `Date`, `Time`, `Datetime`, `Terminal`), by which the keyboard picks its layout, and `hints` how it treats what is typed (`kTextInputHintCompletion`, `Spellcheck`, `AutoCapitalization`, `Lowercase`, `Uppercase`, `Titlecase`, `HiddenText`, `SensitiveData`, `Latin`, `Multiline`, or-ed together). Without `hints` a field gets `TextInputDefaultHints(purpose)`: completion, spellcheck and capitals for `Normal`, hidden and not learnt for `Password` and `Pin`, none for the rest; `kTextInputHintNone` asks for none. Name the purpose of every field that is not prose. Call it again when the caret moves, with the same purpose and hints. A call that changes either while a field has focus tells the input method the focus moved to another field (it enables anew), which ends the composition under way without an `onPreedit`, as `SetTextInput(false)` does, so commit or drop your composing text first. A move to another field of the same purpose and hints looks to the window like a caret that moved and sends no enable: call `SetTextInput(false)` before the new field's `SetTextInput(true, ...)`. The input method's changes come in batches (text-input-v3's `done`), each fired as `onTextInputDelete`, `onTextInput` and `onPreedit` in that order, and the batches in the order they arrived: one that arrives while a listener of another is running (the listener made a `Window` or called `Clipboard::GetText`, which dispatch the events) waits until that one is through. Only these wait: a key, pointer or touch event the same dispatch brings fires at once, before a batch that waits.
|
||||||
- Several windows can exist (on Wayland `Device::windows` lists them; the other backends keep no list), and may share a heap, each writing only its own swapchain slots, but they share one frame clock: one rendering window is the assumption behind the deletion queue, the staging rings and the font atlas's evictions. Without a `Window`, nothing advances `Device::frameCounter`: a program that draws text without one steps it itself after each frame's work, or its full atlas never frees a cell and new glyphs stay blank.
|
- Several windows can exist (on Wayland `Device::windows` lists them; the other backends keep no list), and may share a heap, each writing only its own swapchain slots, but they share one frame clock: one rendering window is the assumption behind the deletion queue, the staging rings and the font atlas's evictions. Without a `Window`, nothing advances `Device::frameCounter`: a program that draws text without one steps it itself after each frame's work, or its full atlas never frees a cell and new glyphs stay blank.
|
||||||
|
|
||||||
### Device and features
|
### Device and features
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ Tests are declared in `project.cpp`, not discovered, through the `LibraryTest(na
|
||||||
|
|
||||||
A test is an `int main()`: exit 0 passes, nonzero fails, 77 skips (for a missing capability, never for a failed check). Each runs in its own process, in parallel, with a 60 s default timeout, and the output of a failed, crashed or timed-out test is in `build/test-logs/<name>.log`; a later pass does not delete the log, so check its timestamp. What the tests need, in three groups:
|
A test is an `int main()`: exit 0 passes, nonzero fails, 77 skips (for a missing capability, never for a failed check). Each runs in its own process, in parallel, with a 60 s default timeout, and the output of a failed, crashed or timed-out test is in `build/test-logs/<name>.log`; a later pass does not delete the log, so check its timestamp. What the tests need, in three groups:
|
||||||
|
|
||||||
- Pure logic, no GPU: they stage `Device`'s statics or feed synthetic data to the decision functions that were factored out for them (`Device::ResolveFeatures`, `ChooseDevice`, `CheckShaderCapabilities`, `GetMemoryType`, `PreferDirectDeviceWrite`, `PipelineCacheDataCompatible`, `AlignMappedFlushRange`, `BuildMipChainFinalBarriers`, `SwapchainStageUnion`, `BuildTlasWriteBarrier`, `UIRenderer::ClipFlags`, `Window::SwapchainMinImageCount`, `WorkaroundNvidiaAS::Patch`, `DescriptorHeapVulkan::ComputeLayout`, `FontAtlas::Packer`, the font and input-field helpers). `PushConstantRewrite` and `UIFusedShader` compile GLSL with glslang and check the SPIR-V with spirv-val at runtime, and `ExampleShaders` compiles every GLSL shader under `examples/` the way crafter-build would, the descriptor-set build included, so a shader contract change that breaks an example fails here without building the example; `FontAtlasDecode` reads `ui-shared.glsl` and `dom-webgpu.js` and holds their copies of the SDF encoding constants to `FontAtlas`'s; `MouseScroll`, `PointerEnterLeave` and `InputTime` drive the Wayland listener callbacks directly, `TitleWayland` reads the requests a window sends off a `wl_display` connected to a socketpair, and `ToplevelState` does both: it feeds the `xdg_toplevel` and `xdg_surface` configure callbacks of a window whose surfaces are proxies on such a display, and reads the version `xdg_wm_base` is bound at off the wire. `ConfigureResize` does the same for a configure's size: with a made-up swapchain handle it steps the two ends of a frame (`TakeDeferredSize` and `MatchSizesToScale`, `SendFrameSurfaceState`) and reads which commit gets the viewport's destination and the acknowledgement, and what the destination is when the scale changes in between.
|
- Pure logic, no GPU: they stage `Device`'s statics or feed synthetic data to the decision functions that were factored out for them (`Device::ResolveFeatures`, `ChooseDevice`, `CheckShaderCapabilities`, `GetMemoryType`, `PreferDirectDeviceWrite`, `PipelineCacheDataCompatible`, `AlignMappedFlushRange`, `BuildMipChainFinalBarriers`, `SwapchainStageUnion`, `BuildTlasWriteBarrier`, `UIRenderer::ClipFlags`, `Window::SwapchainMinImageCount`, `WorkaroundNvidiaAS::Patch`, `DescriptorHeapVulkan::ComputeLayout`, `FontAtlas::Packer`, the font and input-field helpers). `PushConstantRewrite` and `UIFusedShader` compile GLSL with glslang and check the SPIR-V with spirv-val at runtime, and `ExampleShaders` compiles every GLSL shader under `examples/` the way crafter-build would, the descriptor-set build included, so a shader contract change that breaks an example fails here without building the example; `FontAtlasDecode` reads `ui-shared.glsl` and `dom-webgpu.js` and holds their copies of the SDF encoding constants to `FontAtlas`'s; `MouseScroll`, `PointerEnterLeave` and `InputTime` drive the Wayland listener callbacks directly, `TitleWayland` reads the requests a window sends off a `wl_display` connected to a socketpair, `TextInputContent` reads the text input's the same way and feeds its callbacks, and `ToplevelState` does both: it feeds the `xdg_toplevel` and `xdg_surface` configure callbacks of a window whose surfaces are proxies on such a display, and reads the version `xdg_wm_base` is bound at off the wire. `ConfigureResize` does the same for a configure's size: with a made-up swapchain handle it steps the two ends of a frame (`TakeDeferredSize` and `MatchSizesToScale`, `SendFrameSurfaceState`) and reads which commit gets the viewport's destination and the acknowledgement, and what the destination is when the scale changes in between.
|
||||||
- A headless device: `Device::Initialize()` and no `Window` (`HeapSlotReuse`, `DeferredDeletion`, `MeshLifetime`, `ImageStagingRelease`, `BLASBuildOptions`, the `TLAS*` tests, ...). Headless still means a Wayland display on Linux. Most of the RT ones check `Device::rayTracingSupported` and return 77 without it; `BLASBuildOptions`, `TLASInstanceDirtyTracking` and `MeshDecompressStagingRelease` do not, and crash on a GPU without ray tracing (`Device::RequireRayTracing` throws out of `main`). `DeviceSelection` skips with one GPU.
|
- A headless device: `Device::Initialize()` and no `Window` (`HeapSlotReuse`, `DeferredDeletion`, `MeshLifetime`, `ImageStagingRelease`, `BLASBuildOptions`, the `TLAS*` tests, ...). Headless still means a Wayland display on Linux. Most of the RT ones check `Device::rayTracingSupported` and return 77 without it; `BLASBuildOptions`, `TLASInstanceDirtyTracking` and `MeshDecompressStagingRelease` do not, and crash on a GPU without ray tracing (`Device::RequireRayTracing` throws out of `main`). `DeviceSelection` skips with one GPU.
|
||||||
- A window and a live compositor: `FrameLoopSync`, `SetupCmdBufferReuse`, `UIFallbackParity`, `SwapchainTransferDst`, `WindowUpdateClock`, `HeapASRead`, `HeapDynamicIndexHit`, `RTPassPushData`, `WindowOptionalGlobals` (hides xdg-decoration, viewporter and fractional scale from the window in turn), `SwapchainImageCount` (every present mode, and swapchains with more images than frames in flight, in child processes on llvmpipe where the host's GPU never makes one), `TextAntialiasing` (text through `DispatchText` and `DispatchFused` against stb_truetype's own antialiased rasterizer, at 14 and 64 px and stretched, plus a glyph mirrored by its UVs and empty texels shrunk below 4 px), `ResizeViewport` (a `Resize` and a configured size, got by maximizing its window for a moment, against the connection itself: it runs with `WAYLAND_DEBUG` set and stderr in a file and replays the log, which has the driver's attach and commit too), and `FeatureRequests` for its retry case. `UIFallbackParity`, `SwapchainTransferDst`, `HeapASRead`, `HeapDynamicIndexHit`, `RTPassPushData` and `TextAntialiasing` read the frame back with `Window::CaptureNextFrame` (a PNG, decoded with a private `STB_IMAGE_STATIC` copy of stb_image), `SwapchainImageCount` with a transfer pass of its own, and check pixels. The others read no frame back: they check what the frame loop, the device and the window report (their counts and members, the validation layer's count, the connection's protocol errors), and `ResizeViewport` the connection's log.
|
- A window and a live compositor: `FrameLoopSync`, `SetupCmdBufferReuse`, `UIFallbackParity`, `SwapchainTransferDst`, `WindowUpdateClock`, `HeapASRead`, `HeapDynamicIndexHit`, `RTPassPushData`, `WindowOptionalGlobals` (hides xdg-decoration, viewporter and fractional scale from the window in turn), `SwapchainImageCount` (every present mode, and swapchains with more images than frames in flight, in child processes on llvmpipe where the host's GPU never makes one), `TextAntialiasing` (text through `DispatchText` and `DispatchFused` against stb_truetype's own antialiased rasterizer, at 14 and 64 px and stretched, plus a glyph mirrored by its UVs and empty texels shrunk below 4 px), `ResizeViewport` (a `Resize` and a configured size, got by maximizing its window for a moment, against the connection itself: it runs with `WAYLAND_DEBUG` set and stderr in a file and replays the log, which has the driver's attach and commit too), and `FeatureRequests` for its retry case. `UIFallbackParity`, `SwapchainTransferDst`, `HeapASRead`, `HeapDynamicIndexHit`, `RTPassPushData` and `TextAntialiasing` read the frame back with `Window::CaptureNextFrame` (a PNG, decoded with a private `STB_IMAGE_STATIC` copy of stb_image), `SwapchainImageCount` with a transfer pass of its own, and check pixels. The others read no frame back: they check what the frame loop, the device and the window report (their counts and members, the validation layer's count, the connection's protocol errors), and `ResizeViewport` the connection's log.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -387,6 +387,35 @@ namespace {
|
||||||
static TextInputStrings strings;
|
static TextInputStrings strings;
|
||||||
return strings;
|
return strings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Moves whenever the composing text of a done that is yet to be
|
||||||
|
// delivered stops being the current one: at a leave, a disable, an
|
||||||
|
// enable for a field of another kind, and at every done.
|
||||||
|
std::uint32_t textInputEpoch = 0;
|
||||||
|
|
||||||
|
// One done of the input method, taken out of the pending values when it
|
||||||
|
// arrived.
|
||||||
|
struct TextInputDone {
|
||||||
|
Window* window; // the one the text input followed then; null once it is destroyed
|
||||||
|
bool deletes;
|
||||||
|
TextDelete deletion;
|
||||||
|
std::string commit;
|
||||||
|
std::string preedit;
|
||||||
|
std::uint32_t epoch; // textInputEpoch as this done left it
|
||||||
|
};
|
||||||
|
|
||||||
|
// The dones yet to be delivered, in the order they arrived: the one
|
||||||
|
// whose listeners are running, then those a listener that dispatched the
|
||||||
|
// display brought meanwhile. Never destroyed: ~Window reads it
|
||||||
|
// (Device::ForgetTextInputDones), and a Window that is destroyed at exit
|
||||||
|
// may be so after this deque's own destructor would have run.
|
||||||
|
std::deque<TextInputDone>& TextDones() {
|
||||||
|
static std::deque<TextInputDone>& dones = *new std::deque<TextInputDone>();
|
||||||
|
return dones;
|
||||||
|
}
|
||||||
|
|
||||||
|
// True while text_input_done is delivering.
|
||||||
|
bool textInputDelivering = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::text_input_enter(void*, zwp_text_input_v3*, wl_surface* surface) {
|
void Device::text_input_enter(void*, zwp_text_input_v3*, wl_surface* surface) {
|
||||||
|
|
@ -404,6 +433,7 @@ void Device::text_input_leave(void*, zwp_text_input_v3*, wl_surface*) {
|
||||||
textInputWindow = nullptr;
|
textInputWindow = nullptr;
|
||||||
textInputHasPreedit = textInputHasCommit = textInputHasDelete = false;
|
textInputHasPreedit = textInputHasCommit = textInputHasDelete = false;
|
||||||
TextStrings().preedit.clear();
|
TextStrings().preedit.clear();
|
||||||
|
++textInputEpoch;
|
||||||
if (window != nullptr) {
|
if (window != nullptr) {
|
||||||
window->textInputEnabled_ = false;
|
window->textInputEnabled_ = false;
|
||||||
if (!TextStrings().shown.empty()) window->onPreedit.Invoke(std::string_view());
|
if (!TextStrings().shown.empty()) window->onPreedit.Invoke(std::string_view());
|
||||||
|
|
@ -431,33 +461,95 @@ void Device::text_input_delete(void*, zwp_text_input_v3*, std::uint32_t before,
|
||||||
// text at the cursor, then the composing text after it. The pending values
|
// text at the cursor, then the composing text after it. The pending values
|
||||||
// reset with every done, so a round that set no preedit means an empty one;
|
// reset with every done, so a round that set no preedit means an empty one;
|
||||||
// the window hears about it only when that differs from what it shows.
|
// the window hears about it only when that differs from what it shows.
|
||||||
|
//
|
||||||
|
// A listener may call SetTextInput, whose disable, or enable for a field of
|
||||||
|
// another kind, clears the pending values (ApplyTextInput), and it may
|
||||||
|
// dispatch the display, which can bring a leave or the next done. So a done
|
||||||
|
// is taken out of the pending values as it arrives and delivered from that
|
||||||
|
// copy, and one that arrives while another is being delivered waits its turn:
|
||||||
|
// the window hears the dones whole and in the order the input method sent
|
||||||
|
// them. Only the dones wait: a key, a pointer or touch event or a leave that
|
||||||
|
// the same dispatch brings is handled where it arrives, ahead of a done that
|
||||||
|
// waits, and putting those in order too would take a queue of every window
|
||||||
|
// event. The deletion and the commit are one edit: both go out whatever a
|
||||||
|
// listener does in between, short of destroying the window
|
||||||
|
// (ForgetTextInputDones). The composing text is reported only while it is the
|
||||||
|
// current one (textInputEpoch): after a leave, a disable or such an enable
|
||||||
|
// its composition is over, and after a later done the window gets that one's.
|
||||||
void Device::text_input_done(void*, zwp_text_input_v3*, std::uint32_t) {
|
void Device::text_input_done(void*, zwp_text_input_v3*, std::uint32_t) {
|
||||||
Window* window = textInputWindow;
|
|
||||||
TextInputStrings& strings = TextStrings();
|
TextInputStrings& strings = TextStrings();
|
||||||
if (!textInputHasPreedit) strings.preedit.clear();
|
std::deque<TextInputDone>& dones = TextDones();
|
||||||
if (window != nullptr) {
|
dones.push_back({
|
||||||
if (textInputHasDelete && (textInputDeleteBefore > 0 || textInputDeleteAfter > 0)) window->onTextInputDelete.Invoke({ textInputDeleteBefore, textInputDeleteAfter });
|
.window = textInputWindow,
|
||||||
if (textInputHasCommit && !strings.commit.empty()) window->onTextInput.Invoke(strings.commit);
|
.deletes = textInputHasDelete && (textInputDeleteBefore > 0 || textInputDeleteAfter > 0),
|
||||||
if (strings.preedit != strings.shown || (textInputHasCommit && !strings.commit.empty())) {
|
.deletion = { textInputDeleteBefore, textInputDeleteAfter },
|
||||||
strings.shown = strings.preedit;
|
.commit = textInputHasCommit ? std::move(strings.commit) : std::string(),
|
||||||
window->onPreedit.Invoke(strings.preedit);
|
.preedit = textInputHasPreedit ? std::move(strings.preedit) : std::string(),
|
||||||
|
.epoch = ++textInputEpoch,
|
||||||
|
});
|
||||||
|
textInputHasPreedit = textInputHasCommit = textInputHasDelete = false;
|
||||||
|
strings.preedit.clear();
|
||||||
|
strings.commit.clear();
|
||||||
|
if (textInputDelivering) return;
|
||||||
|
textInputDelivering = true;
|
||||||
|
struct Delivering {
|
||||||
|
~Delivering() { textInputDelivering = false; }
|
||||||
|
} delivering;
|
||||||
|
while (!dones.empty()) {
|
||||||
|
// The done stays at the front while its listeners run, where
|
||||||
|
// ForgetTextInputDones finds it, and goes when they are through,
|
||||||
|
// also when one of them throws.
|
||||||
|
struct Pop {
|
||||||
|
~Pop() { TextDones().pop_front(); }
|
||||||
|
} pop;
|
||||||
|
const TextInputDone& done = dones.front();
|
||||||
|
if (done.window != nullptr && done.deletes) done.window->onTextInputDelete.Invoke(done.deletion);
|
||||||
|
if (done.window != nullptr && !done.commit.empty()) done.window->onTextInput.Invoke(done.commit);
|
||||||
|
if (done.window != nullptr && done.epoch == textInputEpoch && (done.preedit != strings.shown || !done.commit.empty())) {
|
||||||
|
strings.shown = done.preedit;
|
||||||
|
done.window->onPreedit.Invoke(done.preedit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
textInputHasPreedit = textInputHasCommit = textInputHasDelete = false;
|
|
||||||
strings.commit.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// enable resets the input method's state, so it goes once per focus; a
|
void Device::ForgetTextInputDones(Window* window) {
|
||||||
// caret that moved sends its rectangle alone.
|
for (TextInputDone& done : TextDones()) {
|
||||||
|
if (done.window == window) done.window = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// enable resets the input method's state, so it goes only when the window's
|
||||||
|
// field goes from none to one (at the enter, or after a disable or a leave)
|
||||||
|
// and when the field that has the focus is of another purpose or other hints
|
||||||
|
// than the one enabled. For the second the content type alone would not do:
|
||||||
|
// it holds from the enable it was committed with, and "subsequent attempts
|
||||||
|
// to update [it] may have no effect". Every other call sends the content
|
||||||
|
// type and the caret's rectangle alone. The protocol asks for an enable
|
||||||
|
// "every time the focused text input changes to a new one, including within
|
||||||
|
// the current surface", and the window does not know one field from another
|
||||||
|
// of the same purpose and hints: a move between two such looks like a caret
|
||||||
|
// that moved, so the caller marks it with SetTextInput(false) first, whose
|
||||||
|
// disable ends the composition (below).
|
||||||
void Device::ApplyTextInput(Window* window) {
|
void Device::ApplyTextInput(Window* window) {
|
||||||
if (textInput == nullptr || window == nullptr || textInputWindow != window) return;
|
if (textInput == nullptr || window == nullptr || textInputWindow != window) return;
|
||||||
if (window->textInputActive_) {
|
if (window->textInputActive_) {
|
||||||
if (!window->textInputEnabled_) zwp_text_input_v3_enable(textInput);
|
const bool another = window->textInputEnabled_
|
||||||
|
&& (window->textInputEnabledPurpose_ != window->textInputPurpose_ || window->textInputEnabledHints_ != window->textInputHints_);
|
||||||
|
if (!window->textInputEnabled_ || another) zwp_text_input_v3_enable(textInput);
|
||||||
|
if (another) {
|
||||||
|
// This enable ends the composition as a disable does (below):
|
||||||
|
// what the window was last told goes with it.
|
||||||
|
textInputHasPreedit = textInputHasCommit = textInputHasDelete = false;
|
||||||
|
TextStrings().preedit.clear();
|
||||||
|
TextStrings().shown.clear();
|
||||||
|
++textInputEpoch;
|
||||||
|
}
|
||||||
window->textInputEnabled_ = true;
|
window->textInputEnabled_ = true;
|
||||||
const bool phone = window->textInputPurpose_ == TextInputPurpose::Phone;
|
window->textInputEnabledPurpose_ = window->textInputPurpose_;
|
||||||
zwp_text_input_v3_set_content_type(textInput,
|
window->textInputEnabledHints_ = window->textInputHints_;
|
||||||
phone ? ZWP_TEXT_INPUT_V3_CONTENT_HINT_NONE : (ZWP_TEXT_INPUT_V3_CONTENT_HINT_COMPLETION | ZWP_TEXT_INPUT_V3_CONTENT_HINT_SPELLCHECK | ZWP_TEXT_INPUT_V3_CONTENT_HINT_AUTO_CAPITALIZATION),
|
// TextInputPurpose and the kTextInputHint* constants have the
|
||||||
phone ? ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_PHONE : ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NORMAL);
|
// protocol's values (TextInputContent holds them to it).
|
||||||
|
zwp_text_input_v3_set_content_type(textInput, window->textInputHints_, static_cast<std::uint32_t>(window->textInputPurpose_));
|
||||||
const float s = window->scale > 0.0f ? window->scale : 1.0f;
|
const float s = window->scale > 0.0f ? window->scale : 1.0f;
|
||||||
zwp_text_input_v3_set_cursor_rectangle(textInput,
|
zwp_text_input_v3_set_cursor_rectangle(textInput,
|
||||||
static_cast<std::int32_t>(window->textInputRect_[0] / s), static_cast<std::int32_t>(window->textInputRect_[1] / s),
|
static_cast<std::int32_t>(window->textInputRect_[0] / s), static_cast<std::int32_t>(window->textInputRect_[1] / s),
|
||||||
|
|
@ -472,6 +564,7 @@ void Device::ApplyTextInput(Window* window) {
|
||||||
textInputHasPreedit = textInputHasCommit = textInputHasDelete = false;
|
textInputHasPreedit = textInputHasCommit = textInputHasDelete = false;
|
||||||
TextStrings().preedit.clear();
|
TextStrings().preedit.clear();
|
||||||
TextStrings().shown.clear();
|
TextStrings().shown.clear();
|
||||||
|
++textInputEpoch;
|
||||||
}
|
}
|
||||||
zwp_text_input_v3_commit(textInput);
|
zwp_text_input_v3_commit(textInput);
|
||||||
wl_display_flush(display);
|
wl_display_flush(display);
|
||||||
|
|
|
||||||
|
|
@ -703,6 +703,7 @@ Window::~Window() {
|
||||||
Device::ForgetTouches();
|
Device::ForgetTouches();
|
||||||
}
|
}
|
||||||
if (Device::textInputWindow == this) Device::textInputWindow = nullptr;
|
if (Device::textInputWindow == this) Device::textInputWindow = nullptr;
|
||||||
|
Device::ForgetTextInputDones(this);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CRAFTER_GRAPHICS_WINDOW_WIN32
|
#ifdef CRAFTER_GRAPHICS_WINDOW_WIN32
|
||||||
|
|
@ -932,7 +933,7 @@ void Window::SetAppId(const std::string_view id) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::SetTextInput(bool active, std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height, TextInputPurpose purpose) {
|
void Window::SetTextInput(bool active, std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height, TextInputPurpose purpose, std::optional<std::uint32_t> hints) {
|
||||||
#ifdef CRAFTER_GRAPHICS_WINDOW_WAYLAND
|
#ifdef CRAFTER_GRAPHICS_WINDOW_WAYLAND
|
||||||
textInputActive_ = active;
|
textInputActive_ = active;
|
||||||
textInputRect_[0] = x;
|
textInputRect_[0] = x;
|
||||||
|
|
@ -940,6 +941,9 @@ void Window::SetTextInput(bool active, std::int32_t x, std::int32_t y, std::int3
|
||||||
textInputRect_[2] = width;
|
textInputRect_[2] = width;
|
||||||
textInputRect_[3] = height;
|
textInputRect_[3] = height;
|
||||||
textInputPurpose_ = purpose;
|
textInputPurpose_ = purpose;
|
||||||
|
// Only version 1's hints: a later one's is not a value of the enum the
|
||||||
|
// bound object knows.
|
||||||
|
textInputHints_ = hints.value_or(TextInputDefaultHints(purpose)) & kTextInputHintMask;
|
||||||
Device::ApplyTextInput(this);
|
Device::ApplyTextInput(this);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
@ -2244,7 +2248,7 @@ void Window::SetTitle(const std::string_view title) {
|
||||||
|
|
||||||
void Window::SetAppId(const std::string_view) {}
|
void Window::SetAppId(const std::string_view) {}
|
||||||
|
|
||||||
void Window::SetTextInput(bool, std::int32_t, std::int32_t, std::int32_t, std::int32_t, TextInputPurpose) {}
|
void Window::SetTextInput(bool, std::int32_t, std::int32_t, std::int32_t, std::int32_t, TextInputPurpose, std::optional<std::uint32_t>) {}
|
||||||
|
|
||||||
void Window::Resize(std::uint32_t newWidth, std::uint32_t newHeight) {
|
void Window::Resize(std::uint32_t newWidth, std::uint32_t newHeight) {
|
||||||
if (newWidth == 0 || newHeight == 0) return;
|
if (newWidth == 0 || newHeight == 0) return;
|
||||||
|
|
|
||||||
|
|
@ -145,6 +145,10 @@ export namespace Crafter {
|
||||||
inline static bool textInputHasPreedit = false;
|
inline static bool textInputHasPreedit = false;
|
||||||
inline static bool textInputHasCommit = false;
|
inline static bool textInputHasCommit = false;
|
||||||
inline static bool textInputHasDelete = false;
|
inline static bool textInputHasDelete = false;
|
||||||
|
// ~Window: what text_input_done has yet to deliver to this window is
|
||||||
|
// dropped, so nothing more of a done fires on a window one of its
|
||||||
|
// listeners destroyed, whatever is built at that address afterwards.
|
||||||
|
static void ForgetTextInputDones(Window* window);
|
||||||
// Sends the window's wanted text-input state when it has the focus.
|
// Sends the window's wanted text-input state when it has the focus.
|
||||||
static void ApplyTextInput(Window* window);
|
static void ApplyTextInput(Window* window);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,58 @@ export namespace Crafter {
|
||||||
std::uint32_t afterBytes;
|
std::uint32_t afterBytes;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class TextInputPurpose : std::uint8_t { Normal, Phone };
|
// What a text field holds, which the input method picks its layout by (a
|
||||||
|
// number pad for Digits, an @ key for Email): text-input-v3's content
|
||||||
|
// purposes, with the protocol's values.
|
||||||
|
enum class TextInputPurpose : std::uint8_t {
|
||||||
|
Normal, // any text
|
||||||
|
Alpha, // letters only
|
||||||
|
Digits, // digits only
|
||||||
|
Number, // a number, with its sign and decimal separator
|
||||||
|
Phone,
|
||||||
|
Url,
|
||||||
|
Email,
|
||||||
|
Name, // a person's name
|
||||||
|
Password,
|
||||||
|
Pin, // a password of digits
|
||||||
|
Date,
|
||||||
|
Time,
|
||||||
|
Datetime,
|
||||||
|
Terminal,
|
||||||
|
};
|
||||||
|
|
||||||
|
// How the input method treats what is typed there: text-input-v3's
|
||||||
|
// content hints, or-ed together, with the protocol's values. These are
|
||||||
|
// the hints of version 1 of the protocol, the version the library binds;
|
||||||
|
// kTextInputHintMask is all of them.
|
||||||
|
inline constexpr std::uint32_t kTextInputHintNone = 0x0;
|
||||||
|
inline constexpr std::uint32_t kTextInputHintCompletion = 0x1; // suggest completions
|
||||||
|
inline constexpr std::uint32_t kTextInputHintSpellcheck = 0x2; // suggest corrections
|
||||||
|
inline constexpr std::uint32_t kTextInputHintAutoCapitalization = 0x4; // a capital at the start of a sentence
|
||||||
|
inline constexpr std::uint32_t kTextInputHintLowercase = 0x8; // prefer lowercase letters
|
||||||
|
inline constexpr std::uint32_t kTextInputHintUppercase = 0x10; // prefer capitals
|
||||||
|
inline constexpr std::uint32_t kTextInputHintTitlecase = 0x20; // a capital at the start of each word
|
||||||
|
inline constexpr std::uint32_t kTextInputHintHiddenText = 0x40; // the field shows no characters: show none either
|
||||||
|
inline constexpr std::uint32_t kTextInputHintSensitiveData = 0x80; // do not store or learn what is typed
|
||||||
|
inline constexpr std::uint32_t kTextInputHintLatin = 0x100; // prefer Latin characters
|
||||||
|
inline constexpr std::uint32_t kTextInputHintMultiline = 0x200; // the text may have line breaks
|
||||||
|
inline constexpr std::uint32_t kTextInputHintMask = 0x3FF;
|
||||||
|
|
||||||
|
// The hints Window::SetTextInput gives a field whose caller names none:
|
||||||
|
// prose is completed, checked and capitalised; a password or a PIN is
|
||||||
|
// neither shown nor remembered; everything else is taken as typed, since
|
||||||
|
// a phone number, an address or an account number is no word to correct.
|
||||||
|
constexpr std::uint32_t TextInputDefaultHints(TextInputPurpose purpose) {
|
||||||
|
switch (purpose) {
|
||||||
|
case TextInputPurpose::Normal:
|
||||||
|
return kTextInputHintCompletion | kTextInputHintSpellcheck | kTextInputHintAutoCapitalization;
|
||||||
|
case TextInputPurpose::Password:
|
||||||
|
case TextInputPurpose::Pin:
|
||||||
|
return kTextInputHintHiddenText | kTextInputHintSensitiveData;
|
||||||
|
default:
|
||||||
|
return kTextInputHintNone;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct ScaleData2D {
|
struct ScaleData2D {
|
||||||
Vector<std::int16_t, 2, 2> position;
|
Vector<std::int16_t, 2, 2> position;
|
||||||
|
|
|
||||||
|
|
@ -227,8 +227,19 @@ export namespace Crafter {
|
||||||
// Tells the compositor's input method that a text field has focus
|
// Tells the compositor's input method that a text field has focus
|
||||||
// (an on-screen keyboard opens) and where its caret is, in physical
|
// (an on-screen keyboard opens) and where its caret is, in physical
|
||||||
// pixels, or that none has. Remembered: it is applied again whenever
|
// pixels, or that none has. Remembered: it is applied again whenever
|
||||||
// the keyboard focus comes back to this window.
|
// the keyboard focus comes back to this window. `purpose` says what
|
||||||
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 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
|
// Like SetPresentMode, a resize asked for while a frame is being
|
||||||
// recorded takes effect once that frame has been presented, width and
|
// recorded takes effect once that frame has been presented, width and
|
||||||
// height included, which the rest of the frame still draws at. On
|
// 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
|
bool textInputEnabled_ = false; // enable sent and not taken back since
|
||||||
std::int32_t textInputRect_[4] = { 0, 0, 0, 0 };
|
std::int32_t textInputRect_[4] = { 0, 0, 0, 0 };
|
||||||
TextInputPurpose textInputPurpose_ = TextInputPurpose::Normal;
|
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 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);
|
static void wl_surface_frame_done(void *data, wl_callback *cb, uint32_t time);
|
||||||
|
|
|
||||||
10
project.cpp
10
project.cpp
|
|
@ -486,6 +486,16 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
|
||||||
// itself. No compositor, no GPU.
|
// itself. No compositor, no GPU.
|
||||||
cfg.tests.push_back(LibraryTest("ConfigureResize"));
|
cfg.tests.push_back(LibraryTest("ConfigureResize"));
|
||||||
|
|
||||||
|
// Window::SetTextInput's purpose and hints as text-input-v3's
|
||||||
|
// content type: the protocol's values, a purpose's usual hints,
|
||||||
|
// one enable per field, and a field of another purpose or other
|
||||||
|
// hints enabled anew, which ends the composition; and a done
|
||||||
|
// whose listeners call SetTextInput, bring a later done or a
|
||||||
|
// leave, or destroy the window: the dones are delivered whole
|
||||||
|
// and in order. Reads the requests off a socketpair display and
|
||||||
|
// feeds the text input's callbacks. No compositor.
|
||||||
|
cfg.tests.push_back(LibraryTest("TextInputContent"));
|
||||||
|
|
||||||
// Issue #40: multi-frame-in-flight frame pacing (per-frame fences
|
// Issue #40: multi-frame-in-flight frame pacing (per-frame fences
|
||||||
// and acquire semaphores, per-image render-finished semaphores, no
|
// and acquire semaphores, per-image render-finished semaphores, no
|
||||||
// steady-state wait-idle). Drives the
|
// steady-state wait-idle). Drives the
|
||||||
|
|
|
||||||
505
tests/TextInputContent/main.cpp
Normal file
505
tests/TextInputContent/main.cpp
Normal file
|
|
@ -0,0 +1,505 @@
|
||||||
|
//SPDX-License-Identifier: LGPL-3.0-only
|
||||||
|
//SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||||
|
|
||||||
|
// Window::SetTextInput's purpose and hints on the Wayland backend: what a
|
||||||
|
// text field holds and how the input method treats it, as text-input-v3's
|
||||||
|
// content type. The window knew two purposes, Normal and Phone, and chose
|
||||||
|
// the hints itself, so a password field was completed, spell-checked and
|
||||||
|
// learnt by the on-screen keyboard like prose, and an amount got letters
|
||||||
|
// where a number pad belongs. And a call that changed the purpose of a
|
||||||
|
// field that had the focus sent the new content type alone, which the
|
||||||
|
// protocol lets an input method ignore: the content type holds from the
|
||||||
|
// enable it was committed with, and a field of another kind is another text
|
||||||
|
// input, to be enabled anew.
|
||||||
|
//
|
||||||
|
// The text input is a proxy on a wl_display connected to one end of a
|
||||||
|
// socketpair, as in TitleWayland, and the test reads the requests off the
|
||||||
|
// other end and calls the listener callbacks itself, so no compositor is
|
||||||
|
// needed. Asserts:
|
||||||
|
//
|
||||||
|
// - TextInputPurpose and the kTextInputHint* constants have the protocol's
|
||||||
|
// values, which is what lets the window send them as they are
|
||||||
|
// - a purpose without hints gets its usual ones: prose is completed,
|
||||||
|
// checked and capitalised, a password and a PIN are hidden and not
|
||||||
|
// learnt, every other purpose is taken as typed
|
||||||
|
// - hints the caller names replace those, and a hint of a later version of
|
||||||
|
// the protocol than the one bound is not sent
|
||||||
|
// - a field getting the focus is one enable, its content type, its caret
|
||||||
|
// and a commit; a caret moving within it sends no second enable
|
||||||
|
// - a field of another purpose, or of other hints, is enabled anew, and
|
||||||
|
// the composition under way ends with it: the same composing text
|
||||||
|
// afterwards is new to the window
|
||||||
|
// - a field losing the focus is a disable, and the next one an enable
|
||||||
|
// - a call for another field of the same purpose and hints sends no enable
|
||||||
|
// by itself, as for a caret that moved, and a disable before it makes it
|
||||||
|
// one
|
||||||
|
// - a window the compositor has not given the text input sends nothing,
|
||||||
|
// and its field is enabled when the text input enters it
|
||||||
|
//
|
||||||
|
// A listener of the window's text events may call SetTextInput, and may
|
||||||
|
// dispatch the display, while the input method's done is being delivered;
|
||||||
|
// a change of purpose or hints from there, like a disable, clears the pending
|
||||||
|
// values that done is made of. Asserts:
|
||||||
|
//
|
||||||
|
// - a listener of onPreedit that changes the purpose, or disables the
|
||||||
|
// field: it and the listener after it still read the composing text
|
||||||
|
// - a listener of onTextInputDelete that changes the hints, or disables
|
||||||
|
// the field: the commit of the same done still arrives, and the done's
|
||||||
|
// composing text, of a composition the listener ended, is not reported
|
||||||
|
// - a later done that a listener of onTextInputDelete or onTextInput
|
||||||
|
// brings: it is delivered after the done that listener was called for,
|
||||||
|
// whose commit comes first and whose composing text is not reported
|
||||||
|
// - a leave that a listener of onTextInput brings: the done's composing
|
||||||
|
// text is not reported after it
|
||||||
|
// - a listener of onTextInputDelete that destroys the window and opens
|
||||||
|
// another at its address: nothing more of the done, and nothing of a
|
||||||
|
// done waiting behind it, fires through the handler's pointer
|
||||||
|
|
||||||
|
#include <wayland-client.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <cerrno>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
#include "../../lib/text-input-unstable-v3-client-protocol.h"
|
||||||
|
|
||||||
|
import Crafter.Graphics;
|
||||||
|
import Crafter.Event;
|
||||||
|
import std;
|
||||||
|
using namespace Crafter;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
int failures = 0;
|
||||||
|
|
||||||
|
void Check(bool ok, std::string_view what) {
|
||||||
|
std::println("{} {}", ok ? "PASS" : "FAIL", what);
|
||||||
|
if (!ok) ++failures;
|
||||||
|
}
|
||||||
|
|
||||||
|
// One request on the text input: its opcode and its arguments, which are
|
||||||
|
// all 32-bit words for the requests the window makes.
|
||||||
|
struct Request {
|
||||||
|
std::uint32_t opcode;
|
||||||
|
std::vector<std::uint32_t> arguments;
|
||||||
|
bool operator==(const Request&) const = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
Request Enable() { return { ZWP_TEXT_INPUT_V3_ENABLE, {} }; }
|
||||||
|
Request Disable() { return { ZWP_TEXT_INPUT_V3_DISABLE, {} }; }
|
||||||
|
Request Commit() { return { ZWP_TEXT_INPUT_V3_COMMIT, {} }; }
|
||||||
|
Request Content(std::uint32_t hints, std::uint32_t purpose) { return { ZWP_TEXT_INPUT_V3_SET_CONTENT_TYPE, { hints, purpose } }; }
|
||||||
|
Request Caret(std::uint32_t x, std::uint32_t y, std::uint32_t width, std::uint32_t height) {
|
||||||
|
return { ZWP_TEXT_INPUT_V3_SET_CURSOR_RECTANGLE, { x, y, width, height } };
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Describe(const std::vector<Request>& requests) {
|
||||||
|
std::string out;
|
||||||
|
for (const Request& request : requests) {
|
||||||
|
out += std::format("{}(", request.opcode);
|
||||||
|
for (std::size_t i = 0; i < request.arguments.size(); ++i) {
|
||||||
|
out += std::format("{}{:#x}", i == 0 ? "" : ", ", request.arguments[i]);
|
||||||
|
}
|
||||||
|
out += ") ";
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// What the display has written since the last call: the requests on
|
||||||
|
// `object`. A request is its object id, then its size and opcode in one
|
||||||
|
// word, then its arguments.
|
||||||
|
std::vector<Request> Sent(wl_display* display, int peer, std::uint32_t object) {
|
||||||
|
wl_display_flush(display);
|
||||||
|
std::vector<std::uint8_t> wire;
|
||||||
|
std::uint8_t chunk[4096];
|
||||||
|
for (ssize_t n; (n = recv(peer, chunk, sizeof(chunk), MSG_DONTWAIT)) > 0;) {
|
||||||
|
wire.insert(wire.end(), chunk, chunk + n);
|
||||||
|
}
|
||||||
|
std::vector<Request> requests;
|
||||||
|
for (std::size_t at = 0; at + 8 <= wire.size();) {
|
||||||
|
std::uint32_t header[2];
|
||||||
|
std::memcpy(header, wire.data() + at, sizeof(header));
|
||||||
|
const std::uint32_t size = header[1] >> 16;
|
||||||
|
if (size < 8 || at + size > wire.size()) break;
|
||||||
|
if (header[0] == object) {
|
||||||
|
Request request{ header[1] & 0xFFFF, {} };
|
||||||
|
for (std::size_t word = 8; word + 4 <= size; word += 4) {
|
||||||
|
std::uint32_t argument;
|
||||||
|
std::memcpy(&argument, wire.data() + at + word, sizeof(argument));
|
||||||
|
request.arguments.push_back(argument);
|
||||||
|
}
|
||||||
|
requests.push_back(std::move(request));
|
||||||
|
}
|
||||||
|
at += size;
|
||||||
|
}
|
||||||
|
return requests;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Expect(const std::vector<Request>& sent, const std::vector<Request>& expected, std::string_view what) {
|
||||||
|
Check(sent == expected, what);
|
||||||
|
if (sent != expected) {
|
||||||
|
std::println(" sent {}", Describe(sent));
|
||||||
|
std::println(" expected {}", Describe(expected));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr std::uint32_t kProse = kTextInputHintCompletion | kTextInputHintSpellcheck | kTextInputHintAutoCapitalization;
|
||||||
|
constexpr std::uint32_t kSecret = kTextInputHintHiddenText | kTextInputHintSensitiveData;
|
||||||
|
|
||||||
|
// The purposes, each with the protocol's value for it and the hints a field
|
||||||
|
// of it gets when the caller names none.
|
||||||
|
struct Purpose {
|
||||||
|
TextInputPurpose purpose;
|
||||||
|
std::uint32_t wire;
|
||||||
|
std::uint32_t hints;
|
||||||
|
std::string_view name;
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr Purpose kPurposes[] = {
|
||||||
|
{ TextInputPurpose::Normal, ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NORMAL, kProse, "Normal" },
|
||||||
|
{ TextInputPurpose::Alpha, ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_ALPHA, 0, "Alpha" },
|
||||||
|
{ TextInputPurpose::Digits, ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_DIGITS, 0, "Digits" },
|
||||||
|
{ TextInputPurpose::Number, ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NUMBER, 0, "Number" },
|
||||||
|
{ TextInputPurpose::Phone, ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_PHONE, 0, "Phone" },
|
||||||
|
{ TextInputPurpose::Url, ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_URL, 0, "Url" },
|
||||||
|
{ TextInputPurpose::Email, ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_EMAIL, 0, "Email" },
|
||||||
|
{ TextInputPurpose::Name, ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NAME, 0, "Name" },
|
||||||
|
{ TextInputPurpose::Password, ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_PASSWORD, kSecret, "Password" },
|
||||||
|
{ TextInputPurpose::Pin, ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_PIN, kSecret, "Pin" },
|
||||||
|
{ TextInputPurpose::Date, ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_DATE, 0, "Date" },
|
||||||
|
{ TextInputPurpose::Time, ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_TIME, 0, "Time" },
|
||||||
|
{ TextInputPurpose::Datetime, ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_DATETIME, 0, "Datetime" },
|
||||||
|
{ TextInputPurpose::Terminal, ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_TERMINAL, 0, "Terminal" },
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
Check(kTextInputHintNone == ZWP_TEXT_INPUT_V3_CONTENT_HINT_NONE
|
||||||
|
&& kTextInputHintCompletion == ZWP_TEXT_INPUT_V3_CONTENT_HINT_COMPLETION
|
||||||
|
&& kTextInputHintSpellcheck == ZWP_TEXT_INPUT_V3_CONTENT_HINT_SPELLCHECK
|
||||||
|
&& kTextInputHintAutoCapitalization == ZWP_TEXT_INPUT_V3_CONTENT_HINT_AUTO_CAPITALIZATION
|
||||||
|
&& kTextInputHintLowercase == ZWP_TEXT_INPUT_V3_CONTENT_HINT_LOWERCASE
|
||||||
|
&& kTextInputHintUppercase == ZWP_TEXT_INPUT_V3_CONTENT_HINT_UPPERCASE
|
||||||
|
&& kTextInputHintTitlecase == ZWP_TEXT_INPUT_V3_CONTENT_HINT_TITLECASE
|
||||||
|
&& kTextInputHintHiddenText == ZWP_TEXT_INPUT_V3_CONTENT_HINT_HIDDEN_TEXT
|
||||||
|
&& kTextInputHintSensitiveData == ZWP_TEXT_INPUT_V3_CONTENT_HINT_SENSITIVE_DATA
|
||||||
|
&& kTextInputHintLatin == ZWP_TEXT_INPUT_V3_CONTENT_HINT_LATIN
|
||||||
|
&& kTextInputHintMultiline == ZWP_TEXT_INPUT_V3_CONTENT_HINT_MULTILINE,
|
||||||
|
"the hint constants have the protocol's values");
|
||||||
|
Check(kTextInputHintMask == (kTextInputHintCompletion | kTextInputHintSpellcheck | kTextInputHintAutoCapitalization
|
||||||
|
| kTextInputHintLowercase | kTextInputHintUppercase | kTextInputHintTitlecase
|
||||||
|
| kTextInputHintHiddenText | kTextInputHintSensitiveData | kTextInputHintLatin | kTextInputHintMultiline),
|
||||||
|
"the mask is every hint of version 1, and no later one");
|
||||||
|
bool values = true;
|
||||||
|
bool defaults = true;
|
||||||
|
for (const Purpose& purpose : kPurposes) {
|
||||||
|
if (static_cast<std::uint32_t>(purpose.purpose) != purpose.wire) {
|
||||||
|
values = false;
|
||||||
|
std::println(" {} is {}, the protocol's is {}", purpose.name, static_cast<std::uint32_t>(purpose.purpose), purpose.wire);
|
||||||
|
}
|
||||||
|
if (TextInputDefaultHints(purpose.purpose) != purpose.hints) {
|
||||||
|
defaults = false;
|
||||||
|
std::println(" {} gets {:#x}, expected {:#x}", purpose.name, TextInputDefaultHints(purpose.purpose), purpose.hints);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Check(values, "the purposes have the protocol's values");
|
||||||
|
Check(defaults, "prose is completed, checked and capitalised; a password and a PIN hidden and not learnt; the rest taken as typed");
|
||||||
|
|
||||||
|
int fds[2];
|
||||||
|
if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, fds) != 0) {
|
||||||
|
std::println("FAIL socketpair: {}", std::strerror(errno));
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
// The display owns fds[0] from here.
|
||||||
|
wl_display* display = wl_display_connect_to_fd(fds[0]);
|
||||||
|
if (display == nullptr) {
|
||||||
|
std::println("FAIL wl_display_connect_to_fd: {}", std::strerror(errno));
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
// libwayland makes whatever proxy it is asked to bind; nothing answers.
|
||||||
|
// Version 1, as Device::handle_global binds the text input's manager.
|
||||||
|
wl_registry* registry = wl_display_get_registry(display);
|
||||||
|
auto* input = static_cast<zwp_text_input_v3*>(wl_registry_bind(registry, 1, &zwp_text_input_v3_interface, 1));
|
||||||
|
const std::uint32_t id = wl_proxy_get_id(reinterpret_cast<wl_proxy*>(input));
|
||||||
|
Device::display = display;
|
||||||
|
Device::textInput = input;
|
||||||
|
|
||||||
|
{
|
||||||
|
// Default-constructed windows, which ~Window can tear down without a
|
||||||
|
// device. The surface is what the text input's enter names.
|
||||||
|
Window window;
|
||||||
|
window.surface = static_cast<wl_surface*>(wl_registry_bind(registry, 2, &wl_surface_interface, 1));
|
||||||
|
Device::windows.push_back(&window);
|
||||||
|
Sent(display, fds[1], id);
|
||||||
|
|
||||||
|
std::vector<std::string> composed;
|
||||||
|
EventListener<const std::string_view> preedit(&window.onPreedit, [&](const std::string_view text) { composed.emplace_back(text); });
|
||||||
|
|
||||||
|
window.SetTextInput(true, 10, 20, 2, 30);
|
||||||
|
Expect(Sent(display, fds[1], id), {}, "a window the text input has not entered sends nothing");
|
||||||
|
|
||||||
|
Device::text_input_enter(nullptr, input, window.surface);
|
||||||
|
Expect(Sent(display, fds[1], id), { Enable(), Content(kProse, ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NORMAL), Caret(10, 20, 2, 30), Commit() },
|
||||||
|
"the text input entering it enables the field it asked for: one enable, the content type, the caret, a commit");
|
||||||
|
|
||||||
|
window.SetTextInput(true, 14, 20, 2, 30);
|
||||||
|
Expect(Sent(display, fds[1], id), { Content(kProse, ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NORMAL), Caret(14, 20, 2, 30), Commit() },
|
||||||
|
"a caret that moves within the field sends no second enable");
|
||||||
|
|
||||||
|
// The input method composes "ab"; the window shows it.
|
||||||
|
Device::text_input_preedit(nullptr, input, "ab", 2, 2);
|
||||||
|
Device::text_input_done(nullptr, input, 1);
|
||||||
|
Check(composed == std::vector<std::string>{ "ab" }, "a composing text reaches the window");
|
||||||
|
composed.clear();
|
||||||
|
|
||||||
|
// The focus moves to a field of another purpose, each in turn: an
|
||||||
|
// enable for every one, with its own content type.
|
||||||
|
bool each = true;
|
||||||
|
TextInputPurpose last = TextInputPurpose::Normal;
|
||||||
|
for (const Purpose& purpose : kPurposes) {
|
||||||
|
if (purpose.purpose == last) continue;
|
||||||
|
window.SetTextInput(true, 14, 20, 2, 30, purpose.purpose);
|
||||||
|
const std::vector<Request> sent = Sent(display, fds[1], id);
|
||||||
|
const std::vector<Request> expected = { Enable(), Content(purpose.hints, purpose.wire), Caret(14, 20, 2, 30), Commit() };
|
||||||
|
if (sent != expected) {
|
||||||
|
each = false;
|
||||||
|
std::println(" {}: sent {}", purpose.name, Describe(sent));
|
||||||
|
}
|
||||||
|
last = purpose.purpose;
|
||||||
|
}
|
||||||
|
Check(each, "a field of another purpose is enabled anew, with that purpose and its usual hints");
|
||||||
|
|
||||||
|
// The enable ended the composition: the same text again is a new
|
||||||
|
// composition, which the window must hear of.
|
||||||
|
Device::text_input_preedit(nullptr, input, "ab", 2, 2);
|
||||||
|
Device::text_input_done(nullptr, input, 2);
|
||||||
|
Check(composed == std::vector<std::string>{ "ab" }, "the composition ended with the enable: the same composing text afterwards is new");
|
||||||
|
composed.clear();
|
||||||
|
|
||||||
|
window.SetTextInput(true, 14, 20, 2, 30, TextInputPurpose::Email, kTextInputHintLowercase);
|
||||||
|
Expect(Sent(display, fds[1], id), { Enable(), Content(kTextInputHintLowercase, ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_EMAIL), Caret(14, 20, 2, 30), Commit() },
|
||||||
|
"hints the caller names replace the purpose's usual ones");
|
||||||
|
|
||||||
|
window.SetTextInput(true, 14, 20, 2, 30, TextInputPurpose::Email, kTextInputHintLowercase | kTextInputHintLatin);
|
||||||
|
Expect(Sent(display, fds[1], id), { Enable(), Content(kTextInputHintLowercase | kTextInputHintLatin, ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_EMAIL), Caret(14, 20, 2, 30), Commit() },
|
||||||
|
"other hints for the same purpose are another field too");
|
||||||
|
|
||||||
|
window.SetTextInput(true, 14, 20, 2, 30, TextInputPurpose::Email, kTextInputHintLowercase | kTextInputHintLatin | ZWP_TEXT_INPUT_V3_CONTENT_HINT_NO_EMOJI);
|
||||||
|
Expect(Sent(display, fds[1], id), { Content(kTextInputHintLowercase | kTextInputHintLatin, ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_EMAIL), Caret(14, 20, 2, 30), Commit() },
|
||||||
|
"a hint of a later version than the one bound is not sent, and makes no other field");
|
||||||
|
|
||||||
|
window.SetTextInput(true, 14, 20, 2, 30, TextInputPurpose::Password, kTextInputHintNone);
|
||||||
|
Expect(Sent(display, fds[1], id), { Enable(), Content(0, ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_PASSWORD), Caret(14, 20, 2, 30), Commit() },
|
||||||
|
"naming no hints at all is not asking for the usual ones");
|
||||||
|
|
||||||
|
// The caret is in physical pixels; the protocol wants the surface's.
|
||||||
|
window.scale = 2.0f;
|
||||||
|
window.SetTextInput(true, 20, 40, 4, 60, TextInputPurpose::Password, kTextInputHintNone);
|
||||||
|
Expect(Sent(display, fds[1], id), { Content(0, ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_PASSWORD), Caret(10, 20, 2, 30), Commit() },
|
||||||
|
"the caret is sent in surface coordinates");
|
||||||
|
window.scale = 1.0f;
|
||||||
|
|
||||||
|
window.SetTextInput(false);
|
||||||
|
Expect(Sent(display, fds[1], id), { Disable(), Commit() }, "a field losing the focus is a disable");
|
||||||
|
window.SetTextInput(false);
|
||||||
|
Expect(Sent(display, fds[1], id), {}, "which goes once");
|
||||||
|
|
||||||
|
window.SetTextInput(true, 14, 20, 2, 30, TextInputPurpose::Number);
|
||||||
|
Expect(Sent(display, fds[1], id), { Enable(), Content(0, ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NUMBER), Caret(14, 20, 2, 30), Commit() },
|
||||||
|
"the next field is enabled");
|
||||||
|
|
||||||
|
// The focus moves to another field of the same purpose and hints.
|
||||||
|
// The window cannot tell that from a caret that moved, so the caller
|
||||||
|
// marks it with a disable.
|
||||||
|
window.SetTextInput(true, 40, 20, 2, 30, TextInputPurpose::Number);
|
||||||
|
Expect(Sent(display, fds[1], id), { Content(0, ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NUMBER), Caret(40, 20, 2, 30), Commit() },
|
||||||
|
"a call for another field of the same purpose and hints sends no enable by itself");
|
||||||
|
window.SetTextInput(false);
|
||||||
|
window.SetTextInput(true, 40, 20, 2, 30, TextInputPurpose::Number);
|
||||||
|
Expect(Sent(display, fds[1], id), { Disable(), Commit(), Enable(), Content(0, ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NUMBER), Caret(40, 20, 2, 30), Commit() },
|
||||||
|
"a disable before it makes it one: a disable, then an enable with the content type and the caret");
|
||||||
|
|
||||||
|
// The keyboard focus leaves the window and comes back: the field it
|
||||||
|
// still has is enabled again, as what it is now.
|
||||||
|
Device::text_input_leave(nullptr, input, window.surface);
|
||||||
|
window.SetTextInput(true, 14, 20, 2, 30, TextInputPurpose::Pin);
|
||||||
|
Expect(Sent(display, fds[1], id), {}, "a window the text input has left sends nothing");
|
||||||
|
Device::text_input_enter(nullptr, input, window.surface);
|
||||||
|
Expect(Sent(display, fds[1], id), { Enable(), Content(kSecret, ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_PIN), Caret(14, 20, 2, 30), Commit() },
|
||||||
|
"and is enabled once, as the field it has by then, when the text input comes back");
|
||||||
|
|
||||||
|
// ~Window destroys the surface and takes the window off the device.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Listeners that call SetTextInput, or dispatch the display, while a done
|
||||||
|
// is being delivered. Each event has two listeners: the first does what
|
||||||
|
// the case asks and then tells what it was given, the second only tells.
|
||||||
|
{
|
||||||
|
Window window;
|
||||||
|
window.surface = static_cast<wl_surface*>(wl_registry_bind(registry, 3, &wl_surface_interface, 1));
|
||||||
|
Device::windows.push_back(&window);
|
||||||
|
window.SetTextInput(true, 14, 20, 2, 30);
|
||||||
|
Device::text_input_enter(nullptr, input, window.surface);
|
||||||
|
Sent(display, fds[1], id);
|
||||||
|
|
||||||
|
std::vector<std::string> heard;
|
||||||
|
std::function<void()> inDelete, inCommit, inPreedit;
|
||||||
|
EventListener<TextDelete> deleteActs(&window.onTextInputDelete, [&](TextDelete deletion) {
|
||||||
|
if (inDelete) inDelete();
|
||||||
|
heard.push_back(std::format("delete {} {}", deletion.beforeBytes, deletion.afterBytes));
|
||||||
|
});
|
||||||
|
EventListener<const std::string_view> commitActs(&window.onTextInput, [&](const std::string_view text) {
|
||||||
|
if (inCommit) inCommit();
|
||||||
|
heard.push_back(std::format("commit {}", text));
|
||||||
|
});
|
||||||
|
EventListener<const std::string_view> commitTells(&window.onTextInput, [&](const std::string_view text) { heard.push_back(std::format("commit {}", text)); });
|
||||||
|
EventListener<const std::string_view> preeditActs(&window.onPreedit, [&](const std::string_view text) {
|
||||||
|
if (inPreedit) inPreedit();
|
||||||
|
heard.push_back(std::format("preedit {}", text));
|
||||||
|
});
|
||||||
|
EventListener<const std::string_view> preeditTells(&window.onPreedit, [&](const std::string_view text) { heard.push_back(std::format("preedit {}", text)); });
|
||||||
|
|
||||||
|
// One done from the input method: a deletion before the cursor, a
|
||||||
|
// commit and a composing text, each when given.
|
||||||
|
std::uint32_t serial = 0;
|
||||||
|
auto done = [&](std::uint32_t before, const char* commit, const char* preedit) {
|
||||||
|
if (preedit != nullptr) Device::text_input_preedit(nullptr, input, preedit, 0, 0);
|
||||||
|
if (commit != nullptr) Device::text_input_commit(nullptr, input, commit);
|
||||||
|
if (before > 0) Device::text_input_delete(nullptr, input, before, 0);
|
||||||
|
Device::text_input_done(nullptr, input, ++serial);
|
||||||
|
};
|
||||||
|
auto expectHeard = [&](const std::vector<std::string>& expected, std::string_view what) {
|
||||||
|
Check(heard == expected, what);
|
||||||
|
if (heard != expected) {
|
||||||
|
std::println(" heard {}", heard);
|
||||||
|
std::println(" expected {}", expected);
|
||||||
|
}
|
||||||
|
heard.clear();
|
||||||
|
};
|
||||||
|
|
||||||
|
inPreedit = [&] { window.SetTextInput(true, 14, 20, 2, 30, TextInputPurpose::Email); };
|
||||||
|
done(0, nullptr, "a@");
|
||||||
|
expectHeard({ "preedit a@", "preedit a@" },
|
||||||
|
"a listener of onPreedit that changes the purpose: it and the listener after it still read the composing text");
|
||||||
|
Expect(Sent(display, fds[1], id), { Enable(), Content(0, ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_EMAIL), Caret(14, 20, 2, 30), Commit() },
|
||||||
|
"and the field is enabled anew from inside the listener");
|
||||||
|
done(0, nullptr, "a@");
|
||||||
|
expectHeard({ "preedit a@", "preedit a@" }, "that enable ended the composition: the same composing text again is new");
|
||||||
|
Sent(display, fds[1], id);
|
||||||
|
|
||||||
|
inPreedit = [&] { window.SetTextInput(false); };
|
||||||
|
done(0, nullptr, "bc");
|
||||||
|
expectHeard({ "preedit bc", "preedit bc" },
|
||||||
|
"a listener of onPreedit that disables the field: it and the listener after it still read the composing text");
|
||||||
|
Expect(Sent(display, fds[1], id), { Disable(), Commit() }, "and the field is disabled from inside the listener");
|
||||||
|
inPreedit = nullptr;
|
||||||
|
window.SetTextInput(true, 14, 20, 2, 30);
|
||||||
|
Sent(display, fds[1], id);
|
||||||
|
|
||||||
|
inDelete = [&] { window.SetTextInput(true, 14, 20, 2, 30, TextInputPurpose::Normal, kTextInputHintNone); };
|
||||||
|
done(3, "the ", "q");
|
||||||
|
expectHeard({ "delete 3 0", "commit the ", "commit the " },
|
||||||
|
"a listener of onTextInputDelete that changes the hints: the commit of the same done still arrives, its composing text does not");
|
||||||
|
Expect(Sent(display, fds[1], id), { Enable(), Content(0, ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NORMAL), Caret(14, 20, 2, 30), Commit() },
|
||||||
|
"and the field is enabled anew from inside the listener");
|
||||||
|
inDelete = nullptr;
|
||||||
|
done(0, nullptr, "q");
|
||||||
|
expectHeard({ "preedit q", "preedit q" }, "the composing text that was not reported is new when the input method sends it again");
|
||||||
|
|
||||||
|
inDelete = [&] { window.SetTextInput(false); };
|
||||||
|
done(1, "k", nullptr);
|
||||||
|
expectHeard({ "delete 1 0", "commit k", "commit k" },
|
||||||
|
"a listener of onTextInputDelete that disables the field: the commit of the same done still arrives, and no onPreedit after it");
|
||||||
|
Expect(Sent(display, fds[1], id), { Disable(), Commit() }, "and the field is disabled from inside the listener");
|
||||||
|
inDelete = nullptr;
|
||||||
|
window.SetTextInput(true, 14, 20, 2, 30);
|
||||||
|
Sent(display, fds[1], id);
|
||||||
|
|
||||||
|
// What a listener that dispatches the display can bring: the next
|
||||||
|
// done, once, and the compositor's leave. The next done waits for
|
||||||
|
// the one being delivered, so the window hears the two in the order
|
||||||
|
// the input method sent them.
|
||||||
|
bool fed = false;
|
||||||
|
inDelete = [&] {
|
||||||
|
if (fed) return;
|
||||||
|
fed = true;
|
||||||
|
done(0, "x", nullptr);
|
||||||
|
};
|
||||||
|
done(1, "e", nullptr);
|
||||||
|
expectHeard({ "delete 1 0", "commit e", "commit e", "commit x", "commit x", "preedit ", "preedit " },
|
||||||
|
"a later done from inside a listener of onTextInputDelete: its commit arrives after the commit of the done being delivered");
|
||||||
|
inDelete = nullptr;
|
||||||
|
|
||||||
|
fed = false;
|
||||||
|
inCommit = [&] {
|
||||||
|
if (fed) return;
|
||||||
|
fed = true;
|
||||||
|
done(0, nullptr, "new");
|
||||||
|
};
|
||||||
|
done(0, "c", "old");
|
||||||
|
expectHeard({ "commit c", "commit c", "preedit new", "preedit new" },
|
||||||
|
"a later done from inside a listener of onTextInput: it is delivered after that listener's done, whose composing text is not reported");
|
||||||
|
|
||||||
|
inCommit = [&] { Device::text_input_leave(nullptr, input, window.surface); };
|
||||||
|
done(0, "d", "old");
|
||||||
|
expectHeard({ "preedit ", "preedit ", "commit d", "commit d" },
|
||||||
|
"a leave from inside a listener of onTextInput: the window hears its composing text is gone, and the done's is not reported after it");
|
||||||
|
inCommit = nullptr;
|
||||||
|
Expect(Sent(display, fds[1], id), {}, "and nothing is sent for a window the text input has left");
|
||||||
|
}
|
||||||
|
|
||||||
|
// A listener of onTextInputDelete destroys the window: the done fires
|
||||||
|
// nothing more through its pointer. Another window is made in its place,
|
||||||
|
// at the same address, and listed on the device as Window's constructor
|
||||||
|
// lists every window it opens, so an event fired through the old pointer
|
||||||
|
// would show, and a handler that only looked the address up in
|
||||||
|
// Device::windows would take the new window for the old one.
|
||||||
|
{
|
||||||
|
std::optional<Window> holder;
|
||||||
|
holder.emplace();
|
||||||
|
holder->surface = static_cast<wl_surface*>(wl_registry_bind(registry, 4, &wl_surface_interface, 1));
|
||||||
|
Device::windows.push_back(&*holder);
|
||||||
|
Device::text_input_enter(nullptr, input, holder->surface);
|
||||||
|
|
||||||
|
int firedOnReplacement = 0;
|
||||||
|
std::optional<EventListener<const std::string_view>> commitSub, preeditSub;
|
||||||
|
EventListener<TextDelete> deleteSub(&holder->onTextInputDelete, [&](TextDelete) {
|
||||||
|
// A later done for the window, which waits its turn, and then
|
||||||
|
// the window goes.
|
||||||
|
Device::text_input_commit(nullptr, input, "z");
|
||||||
|
Device::text_input_done(nullptr, input, 2);
|
||||||
|
holder.reset();
|
||||||
|
Window& replacement = holder.emplace();
|
||||||
|
Device::windows.push_back(&replacement);
|
||||||
|
commitSub.emplace(&replacement.onTextInput, [&](const std::string_view) { ++firedOnReplacement; });
|
||||||
|
preeditSub.emplace(&replacement.onPreedit, [&](const std::string_view) { ++firedOnReplacement; });
|
||||||
|
});
|
||||||
|
Device::text_input_preedit(nullptr, input, "p", 0, 0);
|
||||||
|
Device::text_input_commit(nullptr, input, "c");
|
||||||
|
Device::text_input_delete(nullptr, input, 1, 0);
|
||||||
|
Device::text_input_done(nullptr, input, 1);
|
||||||
|
Check(std::ranges::contains(Device::windows, &*holder), "the window made in the destroyed one's place is listed at its address");
|
||||||
|
Check(firedOnReplacement == 0, "a window destroyed from onTextInputDelete: neither the rest of that done nor the done waiting behind it fires through the handler's pointer");
|
||||||
|
commitSub.reset();
|
||||||
|
preeditSub.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
const int error = wl_display_get_error(display);
|
||||||
|
Check(error == 0, "the display took every request");
|
||||||
|
if (error != 0) std::println(" the display failed: {}", std::strerror(error));
|
||||||
|
|
||||||
|
Device::textInput = nullptr;
|
||||||
|
Device::display = nullptr;
|
||||||
|
zwp_text_input_v3_destroy(input);
|
||||||
|
wl_registry_destroy(registry);
|
||||||
|
wl_display_disconnect(display);
|
||||||
|
close(fds[1]);
|
||||||
|
|
||||||
|
if (failures != 0) {
|
||||||
|
std::println("{} check(s) failed", failures);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
std::println("all checks passed");
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue