Switch icon indicating copy to clipboard operation
Switch copied to clipboard

Investigate using `RegisterEventHotKey` instead of Event taps.

Open numist opened this issue 12 years ago • 2 comments

This is a pretty low priority—it would only be useful for listing Switch in the App Store.

numist avatar Jul 22 '13 07:07 numist

@numist why closed? Did you find this to be impossible?

borismus avatar Nov 12 '13 22:11 borismus

Not at all, but there were other factors at play specific to Switch's purpose.

Two arguments in favour of Switch sticking with an event tap:

  • Switch doesn't want to be the active application; it makes application and window order more difficult to maintain, and the Accessibility IPC calls are inherently slow and, sadly, error-prone. At the same time, Switch does want to receive mouse events when it is in use. The event manager implemented in Switch forwards mouse events to the UI when it is being shown, solving both of these problems.
  • Ultimately I'd like to support custom keybindings. While this is totally possible with RegisterEventHotKey, it is not possible to override ⌘⇥ using anything other than an event tap.

Those two arguments are very application-specific, and there exist at least as many good general arguments against using an event tap:

  • Event taps slow down the entire system. It's critically important that the event handler be the fastest part of your application because it will be run for every single input event. Even if your handler is a return statement there is a significant cost—the time spent context switching adds up. With RegisterEventHotKey, you only get events when they are relevant to you.
  • Event taps do not work in sandboxed applications. I believe the sandbox to be generally a Good Thing™ for users, and a decent guardrail for developers. Unfortunately, it's already impossible to sandbox Switch due to the use of Accessibility and CGWindowListCreateImage.

numist avatar Nov 12 '13 22:11 numist