Repository navigation
web: an Apple Pencil is the mouse, not a finger - #600
Merged
Merged
Conversation
iPad Safari sends a pencil as a TouchEvent whose touch has touchType "stylus", and web.js made every touch a dvui touch button, so dvui.pointerKind() said .touch while drawing with a pencil. A stylus touch now goes in as mouse motion plus a left press or release, so it reads .mouse as a native pen does (#563). touchcancel now ends a touch like touchend, so a cancelled touch or pencil no longer stays held. Fixes #568 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
foxnne
marked this pull request as ready for review
October 18, 2026 23:41
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #568
What changes
On the web, an Apple Pencil is now the mouse, not a finger. iPad Safari sends a pencil as a
TouchEventwhose touch hastouchType === "stylus", andweb/web.jsturned every touch intoa dvui touch button, so
dvui.pointerKind()said.touchwhile drawing with a pencil: nothingstayed hovered after a lift, and canvases panned as they do for a finger. Now a stylus touch goes
in as mouse motion to its position (in drawing-buffer pixels, as
mousemovedoes) followed by aleft-button press or release, with the event's modifiers. It takes no touch slot. dvui then
reports
.mouse, the same answer native gives once SDL's pen touches are excluded(#563,
backend/src/touch_slots.zig). Fingers, and touches with notouchType(browsersother than Safari), are unchanged.
touchcancelnow ends a touch the waytouchenddoes. It had no handler, so a touch the systemtook (a gesture, an alert) left its button held. A pencil's held mouse button would be worse,
because it keeps dragging until the next press.
The change is in fizzy's own web backend, not dvui-dev: fizzy builds dvui in
custommode andlinks
web/web.js+src/backend/WebBackend.zig(docs/DEPENDENCIES.md), so no dvui commit andno repin are needed.
Considered and dropped: moving to Pointer Events and
pointerType("pen"/"touch"/"mouse"). That would also cover Android styluses and pencil hover, but it replaces all of themouse and touch input paths (capture, the compatibility mouse events, the on-screen-keyboard
oskCheckthat iOS only allows inside a touch handler) for a pencil fix. Worth doing as its ownchange if Android stylus support is wanted.
SDK impact
Verified
web/web.js, runsDvui.runwith a stub canvas and wasm exports, and fires fake touch events at the handlers.A stylus start/move/end sends mouse motion at pixel coordinates, then a left press or release
with the modifiers; a stylus takes no touch slot; a cancelled stylus releases the button.
Finger and no-
touchTypetouches still send touch press/motion/release at normalisedcoordinates; a cancelled finger releases its touch button. On
main'sweb.jsthe styluscases fail (they send touch events).
zig build,zig build test,zig build test-integration,zig build check-web,zig build test-sdk-version,zig build check-tests-reachedon macOS, andscripts/check-examples.shwithEXAMPLES_DIR(example-appzig-0.17, example-pluginmain:example-plugin has no
zig-0.17branch any more, so the script's default clone fails onmain).scripts/check-fmt.shflags onlybackend/src/platform/win32_titlebar.zig, which isunformatted on
maintoo (main's Format job fails since windows: a dragged view is carried outside its window #463); this PR touches no Zig.(
zig build web,scripts/serve-web.sh, the Mac's address on :8765). Tap a tab or tree rowwith the pencil and lift: it stays lit (it went dark before). In a pixi canvas, a pencil stroke
draws rather than pans. A finger tap on a tab still leaves it unlit.
Follow-ups
pointerType) for Android styluses and pencil hover, if wanted.🤖 Generated with Claude Code