Subject: bug#48406: 28.0.50; Emacs stuck in infinite loop in wait_reading_process_output when opening in fullscreen (NS)

From: Alan Third <[email-masked]>
Date: Fri, 14 May 2021 21:34:42 +0100

On Fri, May 14, 2021 at 10:32:56PM +0300, Andrii Kolomoiets wrote:
> Illia Ostapyshyn <[email-masked]> writes:
> 
> > Executing like this doesn't work for me:
> >
> >     emacs -Q --execute "(push '(fullscreen . fullboth) default-frame-alist)"
> >
> > I've tried recompiling emacs with you configure flags, same
> > result. Could it be the OS version? I doubt it, I recall having this
> > issue long time ago, but I bore with it instead of reporting.
> 
> Well, I'm on macOS 11.3.1 now, recompiled Emacs with `make bootstrap`
> still works fine.

Now I've dug out my Mac I can confirm I see this hang as well.

The problem is that we never reach the NS run loop and therefore
windowDidEnterFullScreen is never called.

It appears ns_select returns in this code:

  if (hold_event_q.nr > 0)
    {
      /* We already have events pending.  */
      raise (SIGIO);
      errno = EINTR;
      return -1;
    }

hmmmm.......

This fixes it for me, but whether it's a good idea or not I don't know:

modified   src/nsterm.m
@@ -7876,6 +7876,7 @@ - (void)windowDidEnterFullScreen:(NSNotification *)notification
   NSTRACE ("[EmacsView windowDidEnterFullScreen:]");
   [self windowDidEnterFullScreen];
   in_fullscreen_transition = NO;
+  ns_send_appdefined (-1);
 }
 
 - (void)windowDidEnterFullScreen /* provided for direct calls */
@@ -7935,6 +7936,7 @@ - (void)windowDidExitFullScreen:(NSNotification *)notification
   NSTRACE ("[EmacsView windowDidExitFullScreen:]");
   [self windowDidExitFullScreen];
   in_fullscreen_transition = NO;
+  ns_send_appdefined (-1);
 }
 
 - (void)windowDidExitFullScreen /* provided for direct calls */
@@ -7974,7 +7976,7 @@ - (void)waitFullScreenTransition
   while ([self inFullScreenTransition])
     {
       NSTRACE ("wait for fullscreen");
-      wait_reading_process_output (0, 300000000, 0, 1, Qnil, NULL, 0);
+      [NSApp run];
     }
 #endif
 }

-- 
Alan Third