SDL: cocoa: Run pending events to completion (4e305)

From 4e3058ce827f3dee4f37fd569af6efe3828670a6 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Wed, 12 Feb 2025 13:57:14 -0500
Subject: [PATCH] cocoa: Run pending events to completion

Fullscreen spaces and miniaturization will always give us some notification that they succeeded or failed, so the timeout isn't required. This prevents errant timeouts when live-resize is active.

(cherry picked from commit 078d737a27e30f91544499d999609898b8f8e435)
---
 src/video/cocoa/SDL_cocoawindow.m | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)

diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m
index 8ed3bcc9c99bc..52943e8f567f6 100644
--- a/src/video/cocoa/SDL_cocoawindow.m
+++ b/src/video/cocoa/SDL_cocoawindow.m
@@ -915,7 +915,8 @@ - (BOOL)windowOperationIsPending:(PendingWindowOperation)operation
 
 - (BOOL)hasPendingWindowOperation
 {
-    return pendingWindowOperation != PENDING_OPERATION_NONE ||
+    // A pending zoom may be deferred until leaving fullscreen, so don't block on it.
+    return (pendingWindowOperation & ~PENDING_OPERATION_ZOOM) != PENDING_OPERATION_NONE ||
            isMiniaturizing || inFullscreenTransition;
 }
 
@@ -3263,24 +3264,11 @@ bool Cocoa_SyncWindow(SDL_VideoDevice *_this, SDL_Window *window)
     bool result = true;
 
     @autoreleasepool {
-        /* The timeout needs to be high enough that animated fullscreen
-         * spaces transitions won't cause it to time out.
-         */
-        Uint64 timeout = SDL_GetTicksNS() + SDL_MS_TO_NS(2000);
         SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->internal;
-        while (true) {
-            SDL_PumpEvents();
-
-            if (SDL_GetTicksNS() >= timeout) {
-                result = false;
-                break;
-            }
-            if (![data.listener hasPendingWindowOperation]) {
-                break;
-            }
 
-            SDL_Delay(10);
-        }
+        do {
+            SDL_PumpEvents();
+        } while ([data.listener hasPendingWindowOperation]);
     }
 
     return result;