Skip to content

fix: re-enable disabled macOS event taps - #1420

Open
shyam-king wants to merge 1 commit into
glzr-io:mainfrom
shyam-king:fix/1419-macos-event-tap-reenable
Open

fix: re-enable disabled macOS event taps#1420
shyam-king wants to merge 1 commit into
glzr-io:mainfrom
shyam-king:fix/1419-macos-event-tap-reenable

Conversation

@shyam-king

Copy link
Copy Markdown

Summary

Fixes #1419. On macOS, CGEventTap is disabled by the system when its callback is too slow to respond (kCGEventTapDisabledByTimeout) or on certain user-input conditions (kCGEventTapDisabledByUserInput), most commonly around sleep/wake. Neither the keyboard hook nor the mouse listener handled these notifications, so once a tap was disabled it stayed disabled for the rest of the process lifetime — keybindings (and mouse events) would silently stop working until GlazeWM was restarted.

This adds a shared EventTapHandle (wm-platform/src/platform_impl/macos/event_tap.rs) that:

  • Holds a thread-bound reference to the tap's CFMachPort, set up before the run loop source is registered.
  • On receiving a TapDisabledByTimeout/TapDisabledByUserInput event in either callback, calls CGEventTap::tap_enable(tap_port, true) to re-enable the tap and logs a warn! with the reason, short-circuiting normal event processing for that callback invocation.
  • Logs an error! if the tap handle can't be accessed, so failures aren't silent.

Wired into both keyboard_hook.rs and mouse_listener.rs, which share the same tap lifecycle pattern.

Testing

  • Ran the built binary continuously for ~2 days across multiple sleep/wake and lock/unlock cycles.
  • Confirmed via debug logs that the tap was disabled and successfully re-enabled 9 times (reason="callback timeout"), with no keybinding freeze observed — previously this reproduced within ~1.5 days of uptime.
  • Added unit tests in event_tap.rs covering disable-notification detection vs. normal event pass-through.
  • cargo test -p wm-platform passes.

Test plan

  • Reproduce original issue (keybindings freeze after sleep/wake) prior to fix
  • Confirm event tap re-enable log fires across multiple sleep/wake cycles
  • Confirm no keybinding freeze over multi-day uptime with the fix applied
  • Unit tests for tap-disabled event detection

@github-project-automation github-project-automation Bot moved this to 📬 Needs triage in glazewm Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 📬 Needs triage

Development

Successfully merging this pull request may close these issues.

[Bug] macOS: keybindings permanently stop working after sleep/wake — event tap is never re-enabled after kCGEventTapDisabledByTimeout

1 participant