Subject: Re: bug#30699: 26.0.91; buffer contents flicker on macOS frames when frames are resized

From: Alan Third <[email-masked]>
Date: Sun, 4 Mar 2018 21:34:04 +0000

On Sun, Mar 04, 2018 at 08:27:36PM +0000, Alan Third wrote:
> On Sun, Mar 04, 2018 at 09:38:27AM -0800, Aaron Jensen wrote:
> > It appears that (on macOS, at least) when a frame is resized, there is
> > an unsightly flicker. It does not matter if the frame is undecorated or
> > not.
> 
> Simpler repro:
> 
> (dotimes (n 10)
>   (set-frame-parameter nil 'width (+ 80 n))
>   (sit-for 0.1))
> 

It’s the call to SET_FRAME_GARBAGED in EmacsView::updateFrameSize. I
don’t know if it’s needed in this circumstance, but without it it
stops the frame being blanked when resizing with the mouse, which is
unpleasant.

The attached patch appears to fix it without breaking mouse resizing,
but it looks like this comment in windowDidResize also counts for macOS:

   /* In GNUstep, at least currently, it's possible to get a didResize
      without getting a willResize.. therefore we need to act as if we got
      the willResize now */

I honestly don’t see that it makes any difference though.

The root problem is actually that we’re unable to execute redisplay
while the frame is being resized by a mouse. The NS event loop goes
into some ‘modal’ state which we can’t break out of, thus preventing
us from doing anything until it’s done. If that didn’t happen we
wouldn’t need to blank the screen at all.
-- 
Alan Third
>From 98c34098dca670b0613c84af347f4fa7046ae942 Mon Sep 17 00:00:00 2001
From: Alan Third <[email-masked]>
Date: Sun, 4 Mar 2018 21:29:21 +0000
Subject: [PATCH] Fix flicker when resizing frame on macOS (bug#30699)

* src/nsterm.m (EmacsView::updateFrameSize): Remove SET_FRAME_GARBAGED
call.
(EmacsView::windoWillResize): Call SET_FRAME_GARBAGED here instead.
---
 src/nsterm.m | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/nsterm.m b/src/nsterm.m
index 1919c6defa..719db4d552 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -6998,7 +6998,6 @@ - (void) updateFrameSize: (BOOL) delay
                          FRAME_PIXEL_TO_TEXT_WIDTH (emacsframe, neww),
                          FRAME_PIXEL_TO_TEXT_HEIGHT (emacsframe, newh),
                          0, delay, 0, 1);
-      SET_FRAME_GARBAGED (emacsframe);
       cancel_mouse_face (emacsframe);
 
       /* The next two lines set the frame to the same size as we've
@@ -7119,6 +7118,12 @@ - (NSSize)windowWillResize: (NSWindow *)sender toSize: (NSSize)frameSize
         }
     }
 
+  /* When the frame is being resized with the mouse we need to blank
+     it out or else we end up with old stuff being displayed.
+
+     FIXME: This may not be the place to put this (bug#30699).  */
+  SET_FRAME_GARBAGED (emacsframe);
+
   NSTRACE_RETURN_SIZE (frameSize);
 
   return frameSize;
-- 
2.16.1