sdl12-compat: macos: Remove deprecated SDL_USE_CPS code.

From 459bfc1d4cee2b2f4ca35fae9af82347c1eb4f5d Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Sat, 11 Dec 2021 16:58:07 -0500
Subject: [PATCH] macos: Remove deprecated SDL_USE_CPS code.

This pulls in a more modern idea from SDL2, but hasn't been tested.

(just using the buildbot to make sure it compiles in this commit).

Reference issue #106.
---
 src/SDLmain/macosx/SDLMain.h |  3 ---
 src/SDLmain/macosx/SDLMain.m | 37 +++++++++++-------------------------
 2 files changed, 11 insertions(+), 29 deletions(-)

diff --git a/src/SDLmain/macosx/SDLMain.h b/src/SDLmain/macosx/SDLMain.h
index 4acb2ad..f6ea978 100644
--- a/src/SDLmain/macosx/SDLMain.h
+++ b/src/SDLmain/macosx/SDLMain.h
@@ -16,9 +16,6 @@
 /* Use this flag to determine whether we use SDLMain.nib or not */
 #define		SDL_USE_NIB_FILE	0
 
-/* Use this flag to determine whether we use CPS (docking) or not */
-#define		SDL_USE_CPS		1
-
 @interface SDLMain : NSObject<NSApplicationDelegate>
 - (NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication *)sender;
 - (void) setupWorkingDirectory:(BOOL)shouldChdir;
diff --git a/src/SDLmain/macosx/SDLMain.m b/src/SDLmain/macosx/SDLMain.m
index 7b48995..4c9f720 100644
--- a/src/SDLmain/macosx/SDLMain.m
+++ b/src/SDLmain/macosx/SDLMain.m
@@ -22,19 +22,6 @@ - (void)setAppleMenu:(NSMenu *)menu;
 /* Same deal with the NSCommandKeyMask... */
 #define EventModifierFlagCommand (1 << 20)
 
-#ifdef SDL_USE_CPS
-/* Portions of CPS.h */
-typedef struct CPSProcessSerNum
-{
-	UInt32		lo;
-	UInt32		hi;
-} CPSProcessSerNum;
-
-extern OSErr	CPSGetCurrentProcess( CPSProcessSerNum *psn);
-extern OSErr 	CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
-extern OSErr	CPSSetFrontProcess( CPSProcessSerNum *psn);
-
-#endif /* SDL_USE_CPS */
 
 static int    gArgc;
 static char  **gArgv;
@@ -195,19 +182,9 @@ static void CustomApplicationMain (int argc, char **argv)
     NSAutoreleasePool	*pool = [[NSAutoreleasePool alloc] init];
     SDLMain				*sdlMain;
 
-    /* Ensure the application object is initialised */
-    [NSApplication sharedApplication];
-    
-#ifdef SDL_USE_CPS
-    {
-        CPSProcessSerNum PSN;
-        /* Tell the dock about us */
-        if (!CPSGetCurrentProcess(&PSN))
-            if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
-                if (!CPSSetFrontProcess(&PSN))
-                    [NSApplication sharedApplication];
-    }
-#endif /* SDL_USE_CPS */
+    /* Ensure the application object is initialised and converted to a GUI app if necessary. */
+    ProcessSerialNumber psn = { 0, kCurrentProcess};
+    TransformProcessType(&psn, kProcessTransformToForegroundApplication);
 
     /* Set up the menubar */
     [NSApp setMainMenu:[[NSMenu alloc] init]];
@@ -282,6 +259,14 @@ - (void) applicationDidFinishLaunching: (NSNotification *) note
 {
     int status;
 
+    /* Get more aggressive about activation for Catalina and later: activate the Dock first so we definitely reset all activation state. */
+    for (NSRunningApplication *i in [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.apple.dock"]) {
+        [i activateWithOptions:NSApplicationActivateIgnoringOtherApps];
+        break;
+    }
+    SDL_Delay(300);  /* !!! FIXME: this isn't right. */
+    [NSApp activateIgnoringOtherApps:YES];
+
     /* Set the working directory to the .app's parent directory */
     [self setupWorkingDirectory:gFinderLaunch];