Hi Lars,
Here is the patch to bind a global hotkey in mac. As long as Emacs is set as
"trusted" in macOS preferences, the user can bind a two-key hotkey of the
form [modifier-key] or a single-key modifier [function key], for example
(mac-bind-global-hotkey [f1] 'tetris). Binding a three-key
combo is left to a future patch.
The code is copied from w32-register-hot-key as much as possible.
The routine intentionally does not focus the window after the hotkey is hit; the
user must call a function like (x-focus-frame nil) to focus the frame.
I also wanted to mention that after discovering x-focus-frame, and testing my
patch and shkd more, I realized that my patch is in fact very similar to shkd in
functionality. The main differences are that my patch allows hotkeys to be
declared directly in emacs (which I like), and that this patch acts directly on
an open window (e.g. making it easier to make a hotkey to yank into an
already-open buffer). On the other hand skhd would call emacsclient, which
interacts with the server, even if no frame is open, offering its own
advantages.
Anyways, I'll leave this patch for your consideration as to whether it's the right
thing to include in emacs!
P.S. I looked into what other code in emacs might be using blocks. I believe
nsxwidget.m also has a block in nsxwidget_webkit_execute_script. I'm guessing
it's working in our cases because we're ultimately building with the Xcode C
compiler.
Thanks