Subject: Re: bug#24091: Problem caused by the fix for this bug

From: Ken Brown <[email-masked]>
Date: Fri, 27 Oct 2017 10:11:19 -0400

On 10/26/2017 4:40 PM, Noam Postavsky wrote:
> On Thu, Oct 26, 2017 at 2:12 PM, Ken Brown <[email-masked]> wrote:
> 
>> The commit I cited was the first bad one (as determined by git bisect). The
>> problem still exists in the current HEAD of the emacs-26 branch.
> 
> Okay. I removed the code because my understanding of the comment was
> that it was needed to prevent a hang during the busy wait for
> visibility. Therefore, when I removed that busy wait, I thought that
> poll_for_input_1 was no longer needed either.
> 
> However, from what you say, it sounds like it's rather needed after
> creating a frame, unrelated to the waiting per se. I don't really
> understand what the code does, but I guess you could try putting the
> poll_for_input_1 stuff back in either before, inside, or after the
> x_wait_for_event at the end of x_make_frame_visible and see what
> helps?

Putting it before the x_wait_for_event fixes the problem.  Patch attached.

Eli, is it OK to push this to the release branch?

Ken
From 9160ce9d56222deb17a5c3922b66a0e8b214f751 Mon Sep 17 00:00:00 2001
From: Ken Brown <[email-masked]>
Date: Fri, 27 Oct 2017 10:04:30 -0400
Subject: [PATCH] Fix startup display on Cygwin

* src/xterm.c (x_make_frame_visible): Restore code that forces
input to be read if input polling is used.  This is needed on
Cygwin.  (Bug#24091)
---
 src/xterm.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/xterm.c b/src/xterm.c
index d90654b101..92066e9229 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -11504,6 +11504,23 @@ x_make_frame_visible (struct frame *f)
 
     /* Try to wait for a MapNotify event (that is what tells us when a
        frame becomes visible).  */
+
+    /* This hack is still in use at least for Cygwin.  See
+       http://lists.gnu.org/archive/html/emacs-devel/2013-12/msg00351.html
+       and https://debbugs.gnu.org/cgi/bugreport.cgi?bug=24091#131.
+       Fake an alarm signal to let the handler know that there's
+       something to be read.  */
+    if (input_polling_used ())
+      {
+	/* It could be confusing if a real alarm arrives while
+	   processing the fake one.  Turn it off and let the
+	   handler reset it.  */
+	int old_poll_suppress_count = poll_suppress_count;
+	poll_suppress_count = 1;
+	poll_for_input_1 ();
+	poll_suppress_count = old_poll_suppress_count;
+      }
+
     x_wait_for_event (f, MapNotify);
   }
 }
-- 
2.14.2