Subject: bug#48162: 28.0.50; Resizing using set-frame-width doesn't expand mode-line

From: Alan Third <[email-masked]>
Date: Sun, 2 May 2021 22:49:40 +0100

On Sun, May 02, 2021 at 09:19:20PM +0200, martin rudalics wrote:
> > Perhaps it just needs to look like this?
> >
> >    if ((oldh == newh && oldw == neww)
> >        || (newh == emacsframe->new_height
> >            && neww == emacsframe->new_width))
> >
> > This is hard, because I can't replicate either of the reported bugs
> > and I suspect my reasoning is very off here.
> 
> I think I understand now: When Emacs is busy it cannot set oldh and oldw
> immediately so oldh == newh && oldw == neww will continue to fail and we
> cannot return.  How about something like the below?

I think the attached works. I finally managed to reproduce the bug and
realised that the offscreen buffer's size doesn't really have anything
to do with what Emacs thinks the frame size is, so I've separated its
resizing code out.

Your suggested code for dealing with the Emacs frame size appears to
work right without any crashes on GNUstep too, so I've included it.

Now I just need to work out why using the menus causes GNUstep builds
to crash and we might have a semi-usable port again. ;)
-- 
Alan Third
>From c4048b3cd6841a7f2ccdfb3f6c880c9ee176390a Mon Sep 17 00:00:00 2001
From: Alan Third <[email-masked]>
Date: Sun, 2 May 2021 22:38:13 +0100
Subject: [PATCH] Fix incorrect resizing behaviour on macOS (bug#48157,
 bug#48162)

* src/nsterm.m ([EmacsView viewDidResize:]): The drawing buffer can be
resized independently of Emacs's idea of the frame size.

Co-authored-by: martin rudalics <[email-masked]>
---
 src/nsterm.m | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/src/nsterm.m b/src/nsterm.m
index 6e7ab1266b..bb20886ab1 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -7303,16 +7303,34 @@ - (void)viewDidResize:(NSNotification *)notification
 
   NSTRACE ("[EmacsView viewDidResize]");
 
+#ifdef NS_DRAW_TO_BUFFER
+  /* If the buffer size doesn't match the view's backing size, destroy
+     the buffer and let it be recreated at the correct size later.  */
+  if ([self wantsUpdateLayer] && surface)
+    {
+      NSRect surfaceRect = {{0, 0}, [surface getSize]};
+      NSRect frameRect = [[self window] convertRectToBacking:frame];
+
+      if (!NSEqualRects (frameRect, surfaceRect))
+        {
+          [surface release];
+          surface = nil;
+
+          [self setNeedsDisplay:YES];
+        }
+    }
+#endif
+
   neww = (int)NSWidth (frame);
   newh = (int)NSHeight (frame);
   oldw = FRAME_PIXEL_WIDTH (emacsframe);
   oldh = FRAME_PIXEL_HEIGHT (emacsframe);
 
   /* Don't want to do anything when the view size hasn't changed. */
-  if ((oldh == newh && oldw == neww)
-      || (emacsframe->new_size_p
-          && newh == emacsframe->new_height
-          && neww == emacsframe->new_width))
+  if (emacsframe->new_size_p
+      ? (newh == emacsframe->new_height
+         && neww == emacsframe->new_width)
+      : (oldh == newh && oldw == neww))
     {
       NSTRACE_MSG ("No change");
       return;
@@ -7321,16 +7339,6 @@ - (void)viewDidResize:(NSNotification *)notification
   NSTRACE_SIZE ("New size", NSMakeSize (neww, newh));
   NSTRACE_SIZE ("Original size", NSMakeSize (oldw, oldh));
 
-#ifdef NS_DRAW_TO_BUFFER
-  if ([self wantsUpdateLayer])
-    {
-      [surface release];
-      surface = nil;
-
-      [self setNeedsDisplay:YES];
-    }
-#endif
-
   change_frame_size (emacsframe, neww, newh, false, YES, false);
 
   SET_FRAME_GARBAGED (emacsframe);
-- 
2.30.2