GNU bug report logs -
#44973
Add a macOS global hotkey function
Previous Next
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Hi Eli, Alan,
Here's a new patch incorporating all of Alan's feedback, with two notes:
1. This implementation is unable to differentiate between left and right
modifier keys, because it depends upon NSEventModifierFlags, which
doesn't
differentiate between left and right.
2. hotkey_ids is a global variable, so it should not be released.
To address Eli's feedback, this patch is inspired by
https://www.mattduck.com/emacs-fuzzy-launcher.html , where Matt uses emacs
to
create a launcher like Spotlight or Alfred. Since he's using GNU/Linux and
i3 wm, he
simply assigned a global hotkey in his window manager config to run
emacsclient
and run the launcher. I believe this is also easy to do in Windows.
In macOS this is much more difficult, because assigning a global hotkey can
only
be done in code. So a user would have to rely on a utility like skhd or
Hammerspoon.
My proposal is to add this patch to emacs, so that a user can assign a
global
hotkey in emacs without relying on a 3rd-party program.
I used w32-register-hot-key as an example of another instance where emacs
added
an OS-specific feature in order to provide a consistent user experience
across
platforms. Also, even though the behavior is totally different, the actual
implementation of that routine and mine are very similar.
Thanks for all of your time and feedback.
On Wed, Dec 30, 2020 at 9:08 AM Eli Zaretskii <eliz <at> gnu.org> wrote:
> > From: j <at> mremus.net
> > Date: Tue, 29 Dec 2020 20:10:00 -0800
> > Cc: 44973 <at> debbugs.gnu.org
> >
> > 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.
>
> Hmm... w32-register-hot-key is not for binding Emacs commands to
> platform-specific keys, it is so that the OS doesn't catch some key
> combinations ahead of Emacs. That is, by using w32-register-hot-key
> you make the key combination available for binding to a command using
> global-set-key and the likes.
>
> By contrast, it sounds like your patch is for letting users bind
> platform-specific key sequences to Emacs commands, which is something
> quite different. What is the rationale for adding this functionality
> to Emacs?
>
[Message part 2 (text/html, inline)]
[ns_bind_global_hotkey.diff (application/octet-stream, attachment)]
This bug report was last modified 4 years and 163 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.