Subject: Re: bug#34213: 27.0.50; Menu bar requires 2 clicks, is unresponsive, or has delays on macOS Mojave

From: David Hart <[email-masked]>
Date: Mon, 6 Apr 2020 03:19:25 -0700

The mechanism used in the ns port of emacs to cancel menu tracking, and to
post a CGEvent to resume it after menus have been updated via lisp no
longer works on recent macOS versions.

The cause of this bug is due to Apple tightening security in macOS, and no
longer allowing apps to post arbitrary CGEvents to the system.

You can observe a console message on macOS Catalina when the first click
fails: "Sender is prohibited from synthesizing events".

A proposed fix is included inline below, using a newer API
'CGEventPostToPid' instead of CGEventPost. The newer API accepts a pid
specifying the recipient, and when the recipient is the same pid as the
sending process, the event gets posted successfully.

Note: the newer API is only available in macOS versions 10.11 and greater.

David

Fix more menu bar requires 2 clicks (bug#34213)

diff --git a/src/nsterm.m b/src/nsterm.m
index 3ce2233..4dbe1c2 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -4523,7 +4523,7 @@ in certain situations (rapid incoming events).
                                                   menu_mouse_point,
                                                   kCGMouseButtonLeft);
       CGEventSetType (event, kCGEventLeftMouseDown);
-      CGEventPost (kCGHIDEventTap, event);
+      CGEventPostToPid([NSProcessInfo processInfo].processIdentifier,
event);
       CFRelease (event);
       CFRelease (source);