Subject: bug#79164: [PATCH] Fix macOS frame position update after resize/move in nsterm.m

From: 川本 琢二 (Dr.Sc.KAWAMOTO,Takuji) <[email-masked]>
Date: Tue, 5 Aug 2025 20:15:11 +0900

Hi,

Thank you for the feedback.

I’m resending the patch as an attachment to avoid line wrapping issues.
This patch is generated from the latest master branch of Emacs as of 
2025-07-20.

     commit e6c1ec71b72  [Define setfunction for 
bibtex-generate-url-list (bug#78798)]

Best regards,
TDr.Sc.KAWAMOTO, Takuji

On 2025/08/05 0:45, Alan Third wrote:
>>> Date: Sun, 3 Aug 2025 15:45:25 +0900
>>> From: 川本 琢二
>>>   (Dr.Sc.KAWAMOTO, Takuji)<[email-masked]>
>>>
>>> This patch addresses a bug in the macOS build of Emacs, where frame
>>> position was not correctly updated after resizing from the left edge.
>>>
>>> In particular, it fixes the issue reported in bug#74074, where
>>> the move-frame-functions hook does not reliably reflect the final
>>> frame location after resizing. This patch introduces the
>>> updateFramePosition method, which is called from windowDidMove
>>> and windowDidEndLiveResize to ensure the frame geometry stays
>>> in sync with the actual macOS window position.
>>>
>>> Tested on macOS 15.5.
>> Thanks, I hope the macOS experts (CC'ed) will be able to review and
>> test the patch.
> This all looks good to me. The patch looks good and the explanation
> and testing too.
>
> Unfortunately I can't apply the patch, I think it's had long-lines
> wrapped by the email client. Can you please resend it?
>
> Thanks!

From 5995f19782d414a392bd769d8bb712e8964e2a16 Mon Sep 17 00:00:00 2001
From: "Dr.Sc.KAWAMOTO,Takuji" <[email-masked]>
Date: Sat, 2 Aug 2025 13:15:06 +0900
Subject: [PATCH] Fix macOS frame position update after resize/move in nsterm.m

---
 src/nsterm.m | 63 ++++++++++++++++++++++++++++++----------------------
 1 file changed, 37 insertions(+), 26 deletions(-)

diff --git a/src/nsterm.m b/src/nsterm.m
index 003aadb9782..3db002d9678 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -6736,6 +6736,11 @@ - (BOOL)fulfillService: (NSString *)name withArg: (NSString *)arg
 
 @implementation EmacsView
 
+- (void)windowDidEndLiveResize:(NSNotification *)notification
+{
+  [self updateFramePosition];
+}
+
 /* Needed to inform when window closed from lisp.  */
 - (void) setWindowClosing: (BOOL)closing
 {
@@ -7871,6 +7876,37 @@ - (BOOL)windowShouldClose: (id)sender
 }

+- (void)updateFramePosition
+{
+  NSWindow *win = [self window];
+  NSRect r = [win frame];
+  NSArray *screens = [NSScreen screens];
+  NSScreen *screen = [screens objectAtIndex: 0];
+
+  if (!emacsframe->output_data.ns)
+    return;
+
+  if (screen != nil)
+    {
+      emacsframe->left_pos = (NSMinX (r)
+                              - NS_PARENT_WINDOW_LEFT_POS (emacsframe));
+      emacsframe->top_pos = (NS_PARENT_WINDOW_TOP_POS (emacsframe)
+                             - NSMaxY (r));
+
+      if (emacs_event)
+        {
+          struct input_event ie;
+          EVENT_INIT (ie);
+          ie.kind = MOVE_FRAME_EVENT;
+          XSETFRAME (ie.frame_or_window, emacsframe);
+          XSETINT (ie.x, emacsframe->left_pos);
+          XSETINT (ie.y, emacsframe->top_pos);
+          kbd_buffer_store_event (&ie);
+        }
+    }
+}
+
+
 - (NSSize)windowWillResize: (NSWindow *)sender toSize: (NSSize)frameSize
 /* Normalize frame to gridded text size.  */
 {
@@ -8205,34 +8241,9 @@ - (instancetype) initFrameFromEmacs: (struct frame *)f
 
 - (void)windowDidMove: sender
 {
-  NSWindow *win = [self window];
-  NSRect r = [win frame];
-  NSArray *screens = [NSScreen screens];
-  NSScreen *screen = [screens objectAtIndex: 0];
-
   NSTRACE ("[EmacsView windowDidMove:]");
 
-  if (!emacsframe->output_data.ns)
-    return;
-
-  if (screen != nil)
-    {
-      emacsframe->left_pos = (NSMinX (r)
-			      - NS_PARENT_WINDOW_LEFT_POS (emacsframe));
-      emacsframe->top_pos = (NS_PARENT_WINDOW_TOP_POS (emacsframe)
-			     - NSMaxY (r));
-
-      if (emacs_event)
-	{
-	  struct input_event ie;
-	  EVENT_INIT (ie);
-	  ie.kind = MOVE_FRAME_EVENT;
-	  XSETFRAME (ie.frame_or_window, emacsframe);
-	  XSETINT (ie.x, emacsframe->left_pos);
-	  XSETINT (ie.y, emacsframe->top_pos);
-	  kbd_buffer_store_event (&ie);
-	}
-    }
+  [self updateFramePosition];
 }

-- 
2.49.0