Subject: Re: bug#31371: 26.1; Menu-bar stops working after search

From: Nick <[email-masked]>
Date: Mon, 14 Oct 2019 14:50:04 +1300

Stefan Kangas <[email-masked]> writes:

> I've tried your patch on macOS 10.13, and it fixes the issues with the
> help menu for me.  The code looks okay to me, but I don't know much
> about Objective-C or macOS development, so it would be good if someone
> else could review it too.
>
> Nick, could you please provide a ChangeLog entry for these changes and
> send them using "git format-patch -1"?  Details on how to do that well
> are in the CONTRIBUTE file.  Thanks in advance.

Thanks for testing. Updated patch attached.

Nick

>From 9ec201c229fdb8f9fbed1050961730daaf9db718 Mon Sep 17 00:00:00 2001
From: Nick Helm <[email-masked]>
Date: Mon, 14 Oct 2019 14:11:25 +1300
Subject: [PATCH] Fix unresponsive Help menu in macOS

* src/nsterm.m (ns_check_menu_open): Don't postpone mouse drag and
non-user-generated mouse down events (Bug#31371).
---
 src/nsterm.m | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/src/nsterm.m b/src/nsterm.m
index bbd2c84..cc21ec3 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -4292,14 +4292,22 @@ in certain situations (rapid incoming events).
           NSEvent *theEvent = [NSApp currentEvent];
           struct frame *emacsframe = SELECTED_FRAME ();
 
-          [menu cancelTracking];
-          menu_will_open_state = MENU_PENDING;
-          emacs_event->kind = MENU_BAR_ACTIVATE_EVENT;
-          EV_TRAILER (theEvent);
-
-          CGEventRef ourEvent = CGEventCreate (NULL);
-          menu_mouse_point = CGEventGetLocation (ourEvent);
-          CFRelease (ourEvent);
+          /* On macOS, the following can cause an event loop when the
+             Spotlight for Help search field is populated.  Avoid this by
+             not postponing mouse drag and non-user-generated mouse down
+             events (Bug#31371).  */
+          if (([theEvent type] == NSEventTypeLeftMouseDown)
+              && [theEvent eventNumber])
+            {
+              [menu cancelTracking];
+              menu_will_open_state = MENU_PENDING;
+              emacs_event->kind = MENU_BAR_ACTIVATE_EVENT;
+              EV_TRAILER (theEvent);
+
+              CGEventRef ourEvent = CGEventCreate (NULL);
+              menu_mouse_point = CGEventGetLocation (ourEvent);
+              CFRelease (ourEvent);
+            }
         }
       else if (menu_will_open_state == MENU_OPENING)
         {
-- 
2.20.1 (Apple Git-117)