GNU bug report logs -
#79164
[PATCH] Fix macOS frame position update after resize/move in nsterm.m
Previous Next
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Your bug report
#79164: [PATCH] Fix macOS frame position update after resize/move in nsterm.m
which was filed against the emacs package, has been closed.
The explanation is attached below, along with your original report.
If you require more details, please reply to 79164 <at> debbugs.gnu.org.
--
79164: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=79164
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
I've pushed this change to master.
Thank you!
On Thu, Aug 07, 2025 at 08:40:10PM +0900, 川本 琢二 (Dr.Sc.KAWAMOTO,Takuji) wrote:
> I am attaching the final commit message corresponding to the patch I
> submitted earlier.
> It includes the requested Copyright-paperwork-exempt line.
>
> On 2025/08/06 11:31, Eli Zaretskii wrote:
> > > Date: Tue, 5 Aug 2025 21:03:59 +0100
> > > From: Alan Third <alan <at> idiocy.org>
> > > Cc: Gerd Möllmann <gerd.moellmann <at> gmail.com>,
> > > Eli Zaretskii <eliz <at> gnu.org>, 79164 <at> debbugs.gnu.org
> > >
> > > On Tue, Aug 05, 2025 at 08:20:16PM +0900, 川本 琢二 (Dr.Sc.KAWAMOTO,Takuji) wrote:
> > > > Thank you for the reference.
> > > >
> > > > Yes, I also noticed that Yamamoto-san’s `emacs-mac` port uses similar
> > > > approaches
> > > > to track window movement and resizing accurately on macOS.
> > > > That gave me more confidence that this patch’s use of `windowDidMove` and
> > > > `windowDidEndLiveResize` to update frame geometry is consistent with
> > > > well-tested practice.
> > > >
> > > > My patch aims to integrate such behavior into upstream Emacs so that even
> > > > the standard
> > > > Cocoa build reports accurate frame positions during edge-resize
> > > > operations—especially
> > > > for use cases relying on `move-frame-functions`.
> > > I think I redid the resizing code a few years ago, and I'm guessing
> > > this got missed. Thank you for the patch.
> > >
> > > Eli, does this require copyright assignment? I'm guessing not as most
> > > of the code is not new, just moved from A to B.
> > Yes, we can accept this without an assignment. Just please remember
> > indicating that in the commit log message, with
> > Copyright-paperwork-exempt.
> >
> > Thanks.
> macOS: Ensure frame position is correctly updated after resizing from left edge
>
> This patch fixes a bug where frame position is not accurately updated
> when resizing an Emacs frame from the left edge in the macOS (Cocoa)
> build. The issue affected consumers of `move-frame-functions`, which
> would receive outdated frame positions.
>
> To resolve this, the patch applies the same frame-position update
> logic in `windowDidEndLiveResize` that is already present in
> `windowDidMove`. Since the logic is shared, a new helper method
> `updateFramePosition` is introduced.
>
> Both `windowDidMove` and `windowDidEndLiveResize` are macOS Cocoa
> framework methods defined by the NSWindowDelegate protocol. They are
> now both calling `updateFramePosition` to ensure that the internal
> Emacs frame geometry reflects the actual macOS window state during
> and after edge-resize operations.
>
> Tested on macOS 15.5 (Sonoma) with native compilation enabled.
> Based on commit e6c1ec71b72 (2025-07-20, master).
>
> * src/nsterm.m (windowDidEndLiveResize): Implement NSWindowDelegate method.
> (updateFramePosition): Extract common logic from windowDidMove and windowDidEndLiveResize.
>
> Bug: #74074
> Copyright-paperwork-exempt: yes
--
Alan Third
[Message part 3 (message/rfc822, inline)]
Hello,
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.
Best regards,
Dr.Sc.KAWAMOTO, Takuji
---
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
This bug report was last modified 2 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.