macOS: Further restrict the live resize callback to only be used when live resize is actually in progress

This commit is contained in:
Kovid Goyal
2025-10-07 18:23:08 +05:30
parent a76f32df2d
commit 2babfa7ebf
2 changed files with 8 additions and 4 deletions

View File

@@ -138,6 +138,7 @@ typedef struct _GLFWwindowNS
int fbWidth, fbHeight; int fbWidth, fbHeight;
float xscale, yscale; float xscale, yscale;
int blur_radius; int blur_radius;
bool live_resize_in_progress;
// The total sum of the distances the cursor has been warped // The total sum of the distances the cursor has been warped
// since the last cursor motion event was processed // since the last cursor motion event was processed

View File

@@ -537,6 +537,7 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
if (self != nil) { if (self != nil) {
window = initWindow; window = initWindow;
_lastScreenStates = [self captureScreenStates]; _lastScreenStates = [self captureScreenStates];
window->ns.live_resize_in_progress = false;
} }
return self; return self;
} }
@@ -566,13 +567,12 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
(void)notification; (void)notification;
NSArray<NSDictionary *> *currentScreenStates = [self captureScreenStates]; NSArray<NSDictionary *> *currentScreenStates = [self captureScreenStates];
const bool is_screen_change = ![_lastScreenStates isEqualToArray:currentScreenStates]; const bool is_screen_change = ![_lastScreenStates isEqualToArray:currentScreenStates];
const bool is_main_thread = [NSThread isMainThread];
NSWindowStyleMask sm = [window->ns.object styleMask]; NSWindowStyleMask sm = [window->ns.object styleMask];
const bool is_fullscreen = (sm & NSWindowStyleMaskFullScreen) != 0; const bool is_fullscreen = (sm & NSWindowStyleMaskFullScreen) != 0;
NSRect frame = [window->ns.object frame]; NSRect frame = [window->ns.object frame];
debug_rendering( debug_rendering(
"windowDidResize() called, is_screen_change: %d is_main_thread: %d is_fullscreen: %d frame: %.1fx%.1f@(%.1f, %.1f)\n", "windowDidResize() called, is_screen_change: %d is_fullscreen: %d live_resize_in_progress: %d frame: %.1fx%.1f@(%.1f, %.1f)\n",
is_screen_change, is_main_thread, is_fullscreen, frame.size.width, frame.size.height, frame.origin.x, frame.origin.y); is_screen_change, is_fullscreen, window->ns.live_resize_in_progress, frame.size.width, frame.size.height, frame.origin.x, frame.origin.y);
if (is_screen_change) { if (is_screen_change) {
// This resize likely happened because a screen was added, removed, or changed resolution. // This resize likely happened because a screen was added, removed, or changed resolution.
[_lastScreenStates release]; [_lastScreenStates release];
@@ -614,7 +614,8 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
// Because of a bug in macOS Tahoe we cannot redraw the window in response // Because of a bug in macOS Tahoe we cannot redraw the window in response
// to a resize event that was caused by a screen change as the OpenGL // to a resize event that was caused by a screen change as the OpenGL
// context is not ready yet. See: https://github.com/kovidgoyal/kitty/issues/8983 // context is not ready yet. See: https://github.com/kovidgoyal/kitty/issues/8983
if (window->ns.resizeCallback && !is_screen_change && !is_fullscreen && is_main_thread) window->ns.resizeCallback((GLFWwindow*)window); if (window->ns.resizeCallback && !is_screen_change && !is_fullscreen && window->ns.live_resize_in_progress)
window->ns.resizeCallback((GLFWwindow*)window);
} }
- (void)windowDidMove:(NSNotification *)notification - (void)windowDidMove:(NSNotification *)notification
@@ -830,12 +831,14 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
- (void) viewWillStartLiveResize - (void) viewWillStartLiveResize
{ {
if (!window) return; if (!window) return;
window->ns.live_resize_in_progress = true;
_glfwInputLiveResize(window, true); _glfwInputLiveResize(window, true);
} }
- (void)viewDidEndLiveResize - (void)viewDidEndLiveResize
{ {
if (!window) return; if (!window) return;
window->ns.live_resize_in_progress = false;
_glfwInputLiveResize(window, false); _glfwInputLiveResize(window, false);
} }