Wayland touch: events a touch listener dispatches run before the stand-in pointer event, so a tap can be lost or the left button left held #193
Labels
No labels
claude:blocked
claude:done
claude:failed
claude:in-progress
claude:ready
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Catcrafts/Crafter.Graphics#193
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
For the first finger, each touch handler fires the touch event and then the pointer event the finger stands in for, and it updates the bookkeeping (
primaryTouchId,mouseLeftHeld) between the two. A listener of the touch event that dispatches Wayland events itself (it makes aWindow, or callsClipboard::GetText) runs the handlers of whatever is queued behind that event inside itself, against the half-updated state. A tap can leave the left button held, a second tap can lose its click, and the stand-in events arrive out of order with the events dispatched inside the listener. Line numbers refer toc006519.Details
touch_down(implementations/Crafter.Graphics-Device.cpp:734-745):onTouchDown.Invoke, and only thenprimaryTouchId = id,mouseLeftHeld = trueandonMouseLeftClick.Invoke.touch_up(:759-765):onTouchUp.Invoke, and only thenprimaryTouchId = -1,mouseLeftHeld = falseandonMouseLeftRelease.Invoke.Windowconstructor (implementations/Crafter.Graphics-Window.cpp:392,wl_display_dispatch) andClipboard::GetTextwhen the selection holds text (implementations/Crafter.Graphics-Clipboard.cpp:341,:368,wl_display_dispatch_pending). Both dispatch the default queue, which is wherewl_touch's events are. libwayland takes an event off the queue and releases its lock before it calls the handler, so a dispatch from inside a handler runs everything still queued (wayland 1.26.0,src/wayland-client.c,dispatch_eventanddispatch_queue).Concrete cases
touch_downfiresonTouchDown, and a listener dispatches. The nestedtouch_upfindsprimaryTouchId == -1, fires no release and clearstouchWindow. Back intouch_down:primaryTouchId = id,mouseLeftHeld = true,onMouseLeftClick. No up is left to release it.touch_up, anonTouchUplistener dispatches. The nestedtouch_downof the second finger findsprimaryTouchIdstill set and fires no click. The outertouch_upthen clearsprimaryTouchId, so the second finger is never the primary one: no click, no move and no release for it.364d210the stand-in event is given its own touch'slastInputTimeagain (:744,:764,:785), but it fires after the events dispatched inside the listener, which carry later times. A consumer that subtracts consecutive times asuint32gets a value near 2^32.AGENTS.consumer.mdsays what a dispatching listener does to the time for itself and for the listeners after it; it does not say this.Found by reading the code, in the pre-push review of 364d210..c006519. The order is older than that range. Not reproduced on a compositor.
tests/InputTimeshows how to stage it without one: a touch listener that calls the handler a nested dispatch would run.Suggested fix
Finish the state before any listener runs. In
touch_down, setprimaryTouchId,focusedWindow,currentMousePosandmouseLeftHeldbeforeonTouchDown.Invoke; intouch_up, clear them beforeonTouchUp.Invoke; keep in a local whether this finger was the primary one, so that a nested handler meets a consistent state and the stand-in event still fires for the right finger. That cures 1 and 2. For 3, either fire the stand-in event before the touch event, or say in the consumer notes that the two are not ordered against what a listener dispatches.