From 5b9f4ee76e2acdd56fa6a36d5a6a29d27287c427 Mon Sep 17 00:00:00 2001 From: "Dr.Sc.KAWAMOTO,Takuji" Date: Sat, 2 Aug 2025 13:15:06 +0900 Subject: [PATCH] Fix NS frame position update after resize/move Fixes bug#74074, bug#79164. * src/nsterm.m ([EmacsView windowDidEndLiveResize:]): ([EmacsView updateFramePosition]): New functions. ([EmacsView windowDidMove:]): Move contents of this function into updateFramePosition and call it. Copyright-paperwork-exempt: yes --- src/nsterm.m | 63 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/src/nsterm.m b/src/nsterm.m index b006b4d5dd0..5127739e2d9 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -6818,6 +6818,11 @@ ns_create_font_panel_buttons (id target, SEL select, SEL cancel_action) @implementation EmacsView +- (void)windowDidEndLiveResize:(NSNotification *)notification +{ + [self updateFramePosition]; +} + /* Needed to inform when window closed from lisp. */ - (void) setWindowClosing: (BOOL)closing { @@ -7970,6 +7975,37 @@ ns_in_echo_area (void) } +- (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. */ { @@ -8304,34 +8340,9 @@ ns_in_echo_area (void) - (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]; }