feat(wayland): add Window::lastInputTime, the compositor's time of a pointer or touch event
The pointer and touch handlers received wl_pointer's and wl_touch's `time` and dropped it, so a consumer could date an event only by its own clock at dispatch. Events queued while the consumer's loop is busy are dispatched together when it comes back, so by that clock a swipe's backlog is a burst, and a press and its release that both waited out a stall happen at one time. Window::lastInputTime is the compositor's time of the pointer, touch or scroll event a listener is being invoked for — milliseconds from an undefined base, wrapping at 2^32 — set before the event fires: the button events, a motion's onMouseMove, onMouseScroll, onTouchDown, onTouchMove and onTouchUp, and the pointer events the first finger stands in for. An event the compositor sends without a time keeps the last one's: an enter's onMouseEnter and the move that follows it, onMouseLeave, and a touch_cancel's release and onTouchCancel. A listener that dispatches Wayland events itself (it makes a Window, or calls Clipboard::GetText) runs the handlers of what is queued behind its event, and they set the time too: for that listener from there on, and for the listeners of its event that come after it. The click, move and release the first finger stands in for fire after the touch event's listeners, so the touch handlers set the time again before them. The member is the Wayland backend's alone: the Win32 and DOM handlers set no such time, and design rule 1 keeps the library from "inventing a shared signature that is a no-op on one side". Those builds have no such member, and the consumer notes say so. Tests: InputTime drives the wl_pointer and wl_touch handlers directly, as MouseScroll and PointerEnterLeave do, and reads lastInputTime in every listener: 0 before the first event; each event's own time for a motion, the four button events, a scroll and a touch's down, motion and up; the touch's time for the first finger's click, move and release, also when a listener of the touch event has run another handler in between, as a dispatch from inside it would; the last event's time for an enter and its move, a leave, and a cancel's release and onTouchCancel; a time past 2^31 and the one after the wrap as they came.
This commit is contained in:
parent
005b04b183
commit
364d2101c9
6 changed files with 268 additions and 6 deletions
|
|
@ -128,7 +128,7 @@ Heap-only: check `Device::rayTracingSupported`, or expect `std::runtime_error` f
|
|||
|
||||
### Input
|
||||
|
||||
- `Window` events, `Event<void>` unless noted: `onMouseMove` (then `currentMousePos`, `lastMousePos`, `mouseDelta`), `onMouseEnter` and `onMouseLeave` with `mouseInside` (native only: the DOM build declares the two events but never fires them, and has no `mouseInside`), `onMouseLeftClick`, `onMouseLeftHold`, `onMouseLeftRelease` and the right-button trio (`mouseLeftHeld`, `mouseRightHeld`), `onMouseScroll` (`Event<std::uint32_t>`: whole detents, reinterpret the payload as `int32`, positive is wheel down, every backend normalised to one per notch), `onRawKeyDown`, `onRawKeyHold`, `onRawKeyUp` (`Event<KeyCode>`, raw platform codes; `heldKeys`), `onTextInput` (`Event<const std::string_view>`, UTF-8; repeats are synthesised on Wayland), `onPreedit` and `onTextInputDelete` (input methods), `onTouchDown`, `onTouchMove`, `onTouchUp` (`Event<TouchPoint>`; the first finger also drives the pointer events), `onClose`, `onResize`, `onBeforeUpdate`, `onUpdate` (`Event<FrameTime>`: `now`, `delta`).
|
||||
- `Window` events, `Event<void>` unless noted: `onMouseMove` (then `currentMousePos`, `lastMousePos`, `mouseDelta`), `onMouseEnter` and `onMouseLeave` with `mouseInside` (native only: the DOM build declares the two events but never fires them, and has no `mouseInside`), `onMouseLeftClick`, `onMouseLeftHold`, `onMouseLeftRelease` and the right-button trio (`mouseLeftHeld`, `mouseRightHeld`), `onMouseScroll` (`Event<std::uint32_t>`: whole detents, reinterpret the payload as `int32`, positive is wheel down, every backend normalised to one per notch), `onRawKeyDown`, `onRawKeyHold`, `onRawKeyUp` (`Event<KeyCode>`, raw platform codes; `heldKeys`), `onTextInput` (`Event<const std::string_view>`, UTF-8; repeats are synthesised on Wayland), `onPreedit` and `onTextInputDelete` (input methods), `onTouchDown`, `onTouchMove`, `onTouchUp` (`Event<TouchPoint>`; the first finger also drives the pointer events), `onClose`, `onResize`, `onBeforeUpdate`, `onUpdate` (`Event<FrameTime>`: `now`, `delta`). On Wayland `lastInputTime` is the compositor's `time` of the pointer, touch or scroll event a listener is being invoked for (milliseconds from an undefined base, wrapping at 2^32, set before the event fires; an event the compositor sends without a time — an enter and the move that follows it, a leave, a touch cancel and its release — keeps the last one's): a consumer that dates gestures — a fling's velocity, a tap against a long press — reads it instead of its own clock at dispatch, since events queued while the loop was busy keep the times they happened at. A listener that dispatches Wayland events itself (it makes a `Window`, or calls `Clipboard::GetText`) has them set it too, for itself from there on and for the listeners of its event that come after it. The other backends have no such member.
|
||||
- Keys: `Key(CrafterKeys::Space)` is `consteval` and folds to the platform's raw code (a Win32 scancode, a Linux keycode), so bindings stay portable in source and compare against `onRawKeyDown`'s `KeyCode` at runtime. Bindings serialised with `Input::BindingToString` are platform-specific.
|
||||
- `Input::Map`: `auto& jump = map.AddAction("Jump", Input::ActionType::Button);` (`Button`, `Axis1D`, `Vector2`), `jump.bindings = { Input::KeyBind{Key(CrafterKeys::Space)}, Input::GamepadButtonBind{id, Gamepad::Button::South} };` (also `MouseButtonBind`, `MouseScrollBind`, `MouseDeltaBind{scale}`, `GamepadAxisBind`, `GamepadStickBind{id, Gamepad::Stick::Left}`, `WASDBind{up, down, left, right}`), `map.Attach(window);`, and `map.Tick();` once per frame, after `Gamepad::Tick()`, which the loop runs before `onBeforeUpdate`. Every `Tick` recomputes the mouse delta and drains the scroll accumulator, and on Wayland `onBeforeUpdate` fires on every loop wake, so either tick from `onUpdate`, or tick in `onBeforeUpdate` and consume the delta and scroll actions in that same listener, as the Sponza example does. Read `action.pressed`, `value` or `vector2`, or subscribe to `onPerformed`, `onCanceled`, `onValueChanged`, `onVector2Changed`. `StartRebind(action, CaptureMask, callback)` captures the next input.
|
||||
- `Gamepad::connected`, `onConnected`, `onDisconnected`, per-device `buttons[]`, `axes[]` and events, `Rumble(dev, low, high, duration)`, `FindById(id)`; buttons are named by position (`South`, `East`, `West`, `North`). `Clipboard::SetText(text)` and `GetText()` (`std::optional<std::string>`).
|
||||
|
|
|
|||
Loading…
Reference in a new issue