mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-05-08 07:08:05 +03:00
The kernel disables a session-level CGEventTap when its callback runs longer than ~1 s on a single event — typical causes are heavy load, scheduler contention, or the process being briefly suspended (App Nap on a long idle, debugger pause). It is not a fatal condition: Apple's documented recovery is to call CGEventTapEnable and resume processing. Before this change the tap stayed dead until the user manually clicked Re-enable from the menubar. Stash the tap's mach port pointer in an Arc<OnceLock<usize>> set immediately after CGEventTap::new returns, and on TapDisabledByTimeout call CGEventTapEnable from the callback to revive the tap while preserving capture state — the user doesn't see the cursor pop back to the local screen mid-session for a transient slow callback. TapDisabledByUserInput keeps the existing teardown path: those causes (TCC Accessibility revoked mid-session, secure-input mode, explicit kill) are not safely recoverable from inside the callback, and the existing fallthrough-fix from59d9e45/d1e963estill applies there. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>