Repository navigation
fence: a patrol, for a pointer that arrives without moving - #9
Conversation
6743dc0 to
6f1a35b
Compare
fdussert
left a comment
There was a problem hiding this comment.
Thanks — a pointer stranded under the kiosk is exactly the kind of thing nobody can diagnose. Reviewed merged onto current main with #7 and #8: scripts/test-helper.sh 89/89, the helper builds clean; removing the !driven guard in FenceMath.patrol fails testPatrolStandsBackWhileAGestureOwnsTheCursor. Standing back on poster.isDrivingCursor covers a gesture and its 0.25 s restore, both on the main thread, and running the patrol without Accessibility is a good call.
Two things I'd like fixed before merging:
- A race that now moves the pointer, not just shows it. In the restore block of
EventPoster.swift(around lines 180–195), a new touch can start on the driver thread betweenwarpCursor(to: saved)andshowCursorIfHidden(). That clearscursorHiddenwhile the new gesture runs, soisDrivingCursorreads false with the cursor on the Edge, and the patrol (MouseFence.swift:196-206) pushes it off mid-gesture. Taps and drags survive because each report re-warps, but a finger held still can lose it. Re-checking the gesture counter beforeshowCursorIfHidden()would close it. - The patrol can switch itself off for good. If
CGEvent(source: nil)returns nil at the first warp (EventPoster.swift:165),restoreCursorreturns early andcursorHiddenstays true forever — which keeps the cursor hidden (that half predates this PR) and now also disables the patrol permanently. Rare, but cheap to guard: clear the state on that early return.
Smaller:
- The tick reads the pointer before checking there is an Edge (
MouseFence.swift:199); checkingedgefirst makes it free with no Edge connected, and the timer could carry atolerance. isDrivingCursorlives in the helper and is untested; worth a test if it can move toFremkitCore.
Note for the rebase: #7 and #9 conflict in CHANGELOG.md and docs/troubleshooting.md (the "Fence: permission missing" row); both sides keep, nothing subtle.
6f1a35b to
f0fe663
Compare
fdussert
left a comment
There was a problem hiding this comment.
Thanks Mickael, nice catch, and a neat fit: putting the patrol inside MouseFence means it follows syncFences() with no extra wiring, and isDrivingCursor is the right guard. I checked the lock ordering against warp/restoreCursor and found no window where the patrol could fight a gesture. Built and tested locally (83/83, and 92/92 merged with #7). Two small things:
MouseFence.swift:35/:205:lastsurvives a display rearrangement, which is one of the cases this PR targets. If it now sits on no display,clampstill returns it, the warp can be clamped back onto the Edge, and the patrol repeats that every 200 ms. Could you resetlastwhenedgechanges (adidSet), or check that it is still on an active display?- Nit,
MouseFence.swift:183: atoleranceof 50–100 ms on the patrol timer would let macOS coalesce the wake-ups, since it runs for as long as the dashboard is shown. Also,CGEvent(source: nil)does allocate an event, so "nothing allocated" (comment at line 30 and the PR body) is slightly off. The cost is negligible either way.
Heads-up: #7 and #9 conflict only in CHANGELOG.md and docs/troubleshooting.md. Keeping both sides resolves it, and whichever lands second will need that small rebase.
The tap only ever sees movement, so the fence only ever acted on a pointer that moved. A cursor reaches the Edge in other ways: an application warping it there posts no event at all, a tap the system disables for a moment lets it cross unseen, and a display rearranged under a resting pointer leaves it stranded. Once there it stays, since nothing moves it, and the next click or scroll lands on the dashboard rather than on the window the user is looking at. It happened to me twice this week, and the way out is to find the mouse and swing it. So the fence now also looks, every 200 ms, at where the pointer really is, and pushes it back with the geometry the tap already used. The read is one `CGEvent(source: nil)`, no event and no round trip. The patrol runs even when the tap could not be created: warping the cursor needs no Accessibility grant, so a Mac that has granted nothing still keeps its pointer off the panel, and the message about the missing permission says what is left. It stands back while a touch gesture owns the cursor. The driver warps the pointer onto the panel for the length of a gesture and restores it afterwards; `EventPoster.isDrivingCursor` is that window, and pushing during it would fight the finger. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
f0fe663 to
783cbdb
Compare
|
Hi Mickael, the patrol is a great catch, thank you, and sorry for the silence since your rebase. We added the follow-ups on top of your commit, in the
Your commit is kept as is, and this PR will show as merged once |
… Edge mcouzinet's window fence (#7) and pointer patrol (#9), with the review's remaining points finished on top of his commits: Accessibility calls off the main thread, no move during a drag, attempts counted per episode, a stale last position dropped after a display rearrangement, an atomic cursor restore. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The mouse fence taps
mouseMovedand the drags, so it only ever acts on a pointer that moves. A cursor reaches the Edge in other ways:CGWarpMouseCursorPositionposts no event at all;tapDisabledByTimeout,tapDisabledByUserInput) and it crosses unseen;Once there it stays, because nothing moves it, and the next click or scroll goes to the dashboard rather than to the window the user is looking at. That is the part that hurts: the pointer is invisible under the kiosk, and the way out is to find the mouse and swing it across two displays. It caught me twice this week.
So the fence also looks at where the pointer really is, every 200 ms, and pushes it back with the geometry the tap already used. The read is one
CGEvent(source: nil): no event, no round trip, nothing allocated.Worth a look:
EventPoster.isDrivingCursoris exactly that window (hidden cursor or pending restore, both already tracked under its lock), and pushing during it would fight the finger.FenceMath.patrol, besideclamp, so the rules are testable with plain rectangles: four new cases inFenceMathTests, registered in the shim.scripts/test-helper.shgreen (80 tests),scripts/build-helper.shbuilds. Checked on my Edge with the helper installed: a cursor warped to the middle of the panel is back on the main display 50 ms later, at the first tick, and a touch gesture is not disturbed.🤖 Generated with Claude Code