SDL: cocoa: Run the CFRunLoop for 20ms during SDL_Quit().

From 4f477c807c088b2eacb5bacd81a28047668ca808 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Thu, 27 Aug 2026 00:23:20 -0400
Subject: [PATCH] cocoa: Run the CFRunLoop for 20ms during SDL_Quit().

This lets the OS remove windows that were destroyed in cases where we aren't
terminating the process right after calling SDL_Quit(). Otherwise, they'll
stay on the screen, unresponsive.

Apparently there is some animation state that needs to complete, and that is
handled via the runloop.

Fixes #10081.
---
 src/video/cocoa/SDL_cocoavideo.m | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/video/cocoa/SDL_cocoavideo.m b/src/video/cocoa/SDL_cocoavideo.m
index b0a8b6945d175..c87a48cd6fca5 100644
--- a/src/video/cocoa/SDL_cocoavideo.m
+++ b/src/video/cocoa/SDL_cocoavideo.m
@@ -235,6 +235,14 @@ void Cocoa_VideoQuit(SDL_VideoDevice *_this)
 {
     @autoreleasepool {
         SDL_CocoaVideoData *data = (__bridge SDL_CocoaVideoData *)_this->internal;
+
+        // Run the CFRunLoop a little, so last-minute window animations can run, etc, but we hopefully don't change any significant state.
+        // This needs to run multiple times over a time period, it's not enough to give it a longer timeout and use "false" for returnAfterSourceHandled.
+        const Uint64 start = SDL_GetTicks();
+        do {
+            CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.0, false);
+        } while ((SDL_GetTicks() - start) <= 20);
+
         Cocoa_QuitModes(_this);
         Cocoa_QuitKeyboard(_this);
         Cocoa_QuitGCMouse();