SDL: macOS: Don't raise the parent top-level window when raising a child window, only raise the child window to the top of the parent

From a7eea9997d81c54b25d1aaee38842835b8c87f42 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 30 Aug 2023 20:29:57 -0700
Subject: [PATCH] macOS: Don't raise the parent top-level window when raising a
 child window, only raise the child window to the top of the parent

---
 src/video/cocoa/SDL_cocoawindow.m | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m
index 3dcff6bb203d..ce110528c73b 100644
--- a/src/video/cocoa/SDL_cocoawindow.m
+++ b/src/video/cocoa/SDL_cocoawindow.m
@@ -2170,16 +2170,17 @@ void Cocoa_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window)
             if (SDL_WINDOW_IS_POPUP(window)) {
                 NSWindow *nsparent = ((__bridge SDL_CocoaWindowData *)window->parent->driverdata).nswindow;
                 [nsparent addChildWindow:nswindow ordered:NSWindowAbove];
-            }
-            if (bActivate) {
-                [nswindow makeKeyAndOrderFront:nil];
             } else {
-                /* Order this window below the key window if we're not activating it */
-                if ([NSApp keyWindow]) {
-                    [nswindow orderWindow:NSWindowBelow relativeTo:[[NSApp keyWindow] windowNumber]];
+                if (bActivate) {
+                    [nswindow makeKeyAndOrderFront:nil];
+                } else {
+                    /* Order this window below the key window if we're not activating it */
+                    if ([NSApp keyWindow]) {
+                        [nswindow orderWindow:NSWindowBelow relativeTo:[[NSApp keyWindow] windowNumber]];
+                    }
                 }
-                [nswindow setIsVisible:YES];
             }
+            [nswindow setIsVisible:YES];
             [windowData.listener resumeVisibleObservation];
         }
     }
@@ -2234,13 +2235,13 @@ void Cocoa_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window)
             if (SDL_WINDOW_IS_POPUP(window)) {
                 NSWindow *nsparent = ((__bridge SDL_CocoaWindowData *)window->parent->driverdata).nswindow;
                 [nsparent addChildWindow:nswindow ordered:NSWindowAbove];
-            }
-
-            if (bActivate) {
-                [NSApp activateIgnoringOtherApps:YES];
-                [nswindow makeKeyAndOrderFront:nil];
             } else {
-                [nswindow orderFront:nil];
+                if (bActivate) {
+                    [NSApp activateIgnoringOtherApps:YES];
+                    [nswindow makeKeyAndOrderFront:nil];
+                } else {
+                    [nswindow orderFront:nil];
+                }
             }
         }
         [windowData.listener resumeVisibleObservation];