unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: j@mremus.net
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 44973@debbugs.gnu.org
Subject: bug#44973: Add a macOS global hotkey function
Date: Sun, 20 Dec 2020 16:40:37 -0800	[thread overview]
Message-ID: <CAAgndd5jbXk+s7aY=X05wOaJ87T-GAza2EXZKxkVgUc1FRrOxQ@mail.gmail.com> (raw)
In-Reply-To: <874kkw9gmq.fsf@gnus.org>

[-- Attachment #1: Type: text/plain, Size: 2026 bytes --]

Hi Lars,

I'm pretty close to having a patch ready, but I'm stuck in one key spot. I
don't know if anyone on the list could help?

After the user registers a hotkey, and when they press the hotkey, MacOS
will run the code below. On the line "RUN_SOME_ELISP_FUNCTION", I would
expect some elisp function to be run (e.g. 'emacs-version').

But no matter what I do, it always crashes the program. I think my first
problem is not knowing how to call elisp (run_hooks, safe_call, etc?)
correctly, but second, I suspect if this is crashing due to a threading
issue.

    handler = [NSEvent
addGlobalMonitorForEventsMatchingMask:(NSEventMaskKeyDown)
handler:^(NSEvent *event){
        if (event.modifierFlags & modifier)
          if([event.charactersIgnoringModifiers characterAtIndex:0] ==
vkey) {
           RUN_SOME_ELISP_FUNCTION
            [[NSApp mainWindow] makeKeyAndOrderFront:NSApp];
          }
        }
      }];

Is there anyone who might know how to fill in this piece?

Thanks

On Tue, Dec 8, 2020 at 12:39 PM Lars Ingebrigtsen <larsi@gnus.org> wrote:

> j@mremus.net writes:
>
> > MacOS makes it very difficult to assign global hotkeys to focus
> > Emacs. For example, if I'm in another program, and I want to
> > launch/focus Emacs with "Alt-SPC", it can't just be set in the system
> > preferences; I'd need to use a 3rd-party program like skhd.
> >
> > Would it be possible to add a function or hook to Emacs which registers
> one or
> > more global hotkeys (using addGlobalMonitorForEventsMatchingMask), and
> then
> > when the hotkey is pressed, run an elisp function?
>
> [...]
>
> > Even if it's rare for Emacs to implement an OS-specific feature, there
> > is some precedent on Windows. If you look at w32-register-hot-keys,
> > it's similar to, but different from my request.
>
> Sure, I think that makes sense.  Would it be possible for you to work up
> a patch that adds this functionality?
>
> --
> (domestic pets only, the antidote for overdose, milk.)
>    bloggy blog: http://lars.ingebrigtsen.no
>

[-- Attachment #2: Type: text/html, Size: 3322 bytes --]

  reply	other threads:[~2020-12-21  0:40 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-30 21:01 bug#44973: Add a macOS global hotkey function j
2020-12-08 20:39 ` Lars Ingebrigtsen
2020-12-21  0:40   ` j [this message]
2020-12-21  4:34     ` Lars Ingebrigtsen
2020-12-30  4:10       ` j
2020-12-30 11:01         ` Alan Third
2020-12-30 17:08         ` Eli Zaretskii
2021-01-04  5:13           ` j
2021-01-04 17:09             ` Eli Zaretskii
2021-01-05  8:25               ` Lars Ingebrigtsen
2021-01-05  8:26                 ` Lars Ingebrigtsen
2021-01-05 15:04                   ` Eli Zaretskii
2021-01-05 15:04                 ` Eli Zaretskii
2021-01-06  5:15                 ` Richard Stallman
2021-01-06  5:02               ` Richard Stallman
2020-12-21  8:12     ` Alan Third
2020-12-21 16:18       ` Eli Zaretskii
2020-12-21 16:34         ` Alan Third
2020-12-22  5:20           ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAAgndd5jbXk+s7aY=X05wOaJ87T-GAza2EXZKxkVgUc1FRrOxQ@mail.gmail.com' \
    --to=j@mremus.net \
    --cc=44973@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).