From dca277f8b7ff873f037f0a8f87dd038afab0e0ed Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Sat, 30 Jun 2018 23:10:01 +0300 Subject: [PATCH] updated SDLMain.m copies in Xcode project templates to match the one in src (Applied changesets: 1496aa09e41e, d78e4e0bf553, cfec3f86fba7, 0c1a8b0429a9, and 67f391c74aee .) --- .../SDL Application/SDLMain.m | 61 ++++++++----------- .../SDL Cocoa Application/SDLMain.m | 61 ++++++++----------- .../SDL OpenGL Application/SDLMain.m | 61 ++++++++----------- .../SDL Application/SDLMain.m | 61 ++++++++----------- .../SDL Cocoa Application/SDLMain.m | 61 ++++++++----------- .../SDL OpenGL Application/SDLMain.m | 61 ++++++++----------- .../SDL Application/SDLMain.m | 61 ++++++++----------- .../SDL Cocoa Application/SDLMain.m | 61 ++++++++----------- .../SDL OpenGL Application/SDLMain.m | 61 ++++++++----------- 9 files changed, 234 insertions(+), 315 deletions(-) diff --git a/Xcode/TemplatesForXcodeLeopard/SDL Application/SDLMain.m b/Xcode/TemplatesForXcodeLeopard/SDL Application/SDLMain.m index b065a2009..6948979df 100644 --- a/Xcode/TemplatesForXcodeLeopard/SDL Application/SDLMain.m +++ b/Xcode/TemplatesForXcodeLeopard/SDL Application/SDLMain.m @@ -20,22 +20,6 @@ - (void)setAppleMenu:(NSMenu *)menu; /* 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 -#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; static BOOL gFinderLaunch; @@ -64,10 +48,10 @@ - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString; @end #endif -@interface SDLApplication : NSApplication +@interface NSApplication (SDLApplication) @end -@implementation SDLApplication +@implementation NSApplication (SDLApplication) /* Invoked from the Quit menu item */ - (void)terminate:(id)sender { @@ -119,7 +103,6 @@ - (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName if ([menuItem hasSubmenu]) [self fixMenu:[menuItem submenu] withAppName:appName]; } - [ aMenu sizeToFit ]; } #else @@ -202,18 +185,7 @@ static void CustomApplicationMain (int argc, char **argv) SDLMain *sdlMain; /* Ensure the application object is initialised */ - [SDLApplication 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)) - [SDLApplication sharedApplication]; - } -#endif /* SDL_USE_CPS */ + [[NSApplication sharedApplication] activateIgnoringOtherApps: YES]; /* Set up the menubar */ [NSApp setMainMenu:[[NSMenu alloc] init]]; @@ -346,18 +318,38 @@ - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString @end - #ifdef main # undef main #endif +static int IsRootCwd() +{ + char buf[MAXPATHLEN]; + char *cwd = getcwd(buf, sizeof (buf)); + return (cwd && (strcmp(cwd, "/") == 0)); +} + +static int IsFinderLaunch(const int argc, char **argv) +{ + /* -psn_XXX is passed if we are launched from Finder, SOMETIMES */ + if ( (argc >= 2) && (strncmp(argv[1], "-psn", 4) == 0) ) { + return 1; + } else if ((argc == 1) && IsRootCwd()) { + /* we might still be launched from the Finder; on 10.9+, you might not + get the -psn command line anymore. If there's no + command line, and if our current working directory is "/", it + might as well be a Finder launch. */ + return 1; + } + return 0; /* not a Finder launch. */ +} + /* Main entry point to executable - should *not* be SDL_main! */ int main (int argc, char **argv) { /* Copy the arguments into a global variable */ - /* This is passed if we are launched by double-clicking */ - if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) { + if (IsFinderLaunch(argc, argv)) { gArgv = (char **) SDL_malloc(sizeof (char *) * 2); gArgv[0] = argv[0]; gArgv[1] = NULL; @@ -373,7 +365,6 @@ int main (int argc, char **argv) } #if SDL_USE_NIB_FILE - [SDLApplication poseAsClass:[NSApplication class]]; NSApplicationMain (argc, argv); #else CustomApplicationMain (argc, argv); diff --git a/Xcode/TemplatesForXcodeLeopard/SDL Cocoa Application/SDLMain.m b/Xcode/TemplatesForXcodeLeopard/SDL Cocoa Application/SDLMain.m index b065a2009..6948979df 100644 --- a/Xcode/TemplatesForXcodeLeopard/SDL Cocoa Application/SDLMain.m +++ b/Xcode/TemplatesForXcodeLeopard/SDL Cocoa Application/SDLMain.m @@ -20,22 +20,6 @@ - (void)setAppleMenu:(NSMenu *)menu; /* 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 -#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; static BOOL gFinderLaunch; @@ -64,10 +48,10 @@ - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString; @end #endif -@interface SDLApplication : NSApplication +@interface NSApplication (SDLApplication) @end -@implementation SDLApplication +@implementation NSApplication (SDLApplication) /* Invoked from the Quit menu item */ - (void)terminate:(id)sender { @@ -119,7 +103,6 @@ - (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName if ([menuItem hasSubmenu]) [self fixMenu:[menuItem submenu] withAppName:appName]; } - [ aMenu sizeToFit ]; } #else @@ -202,18 +185,7 @@ static void CustomApplicationMain (int argc, char **argv) SDLMain *sdlMain; /* Ensure the application object is initialised */ - [SDLApplication 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)) - [SDLApplication sharedApplication]; - } -#endif /* SDL_USE_CPS */ + [[NSApplication sharedApplication] activateIgnoringOtherApps: YES]; /* Set up the menubar */ [NSApp setMainMenu:[[NSMenu alloc] init]]; @@ -346,18 +318,38 @@ - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString @end - #ifdef main # undef main #endif +static int IsRootCwd() +{ + char buf[MAXPATHLEN]; + char *cwd = getcwd(buf, sizeof (buf)); + return (cwd && (strcmp(cwd, "/") == 0)); +} + +static int IsFinderLaunch(const int argc, char **argv) +{ + /* -psn_XXX is passed if we are launched from Finder, SOMETIMES */ + if ( (argc >= 2) && (strncmp(argv[1], "-psn", 4) == 0) ) { + return 1; + } else if ((argc == 1) && IsRootCwd()) { + /* we might still be launched from the Finder; on 10.9+, you might not + get the -psn command line anymore. If there's no + command line, and if our current working directory is "/", it + might as well be a Finder launch. */ + return 1; + } + return 0; /* not a Finder launch. */ +} + /* Main entry point to executable - should *not* be SDL_main! */ int main (int argc, char **argv) { /* Copy the arguments into a global variable */ - /* This is passed if we are launched by double-clicking */ - if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) { + if (IsFinderLaunch(argc, argv)) { gArgv = (char **) SDL_malloc(sizeof (char *) * 2); gArgv[0] = argv[0]; gArgv[1] = NULL; @@ -373,7 +365,6 @@ int main (int argc, char **argv) } #if SDL_USE_NIB_FILE - [SDLApplication poseAsClass:[NSApplication class]]; NSApplicationMain (argc, argv); #else CustomApplicationMain (argc, argv); diff --git a/Xcode/TemplatesForXcodeLeopard/SDL OpenGL Application/SDLMain.m b/Xcode/TemplatesForXcodeLeopard/SDL OpenGL Application/SDLMain.m index b065a2009..6948979df 100644 --- a/Xcode/TemplatesForXcodeLeopard/SDL OpenGL Application/SDLMain.m +++ b/Xcode/TemplatesForXcodeLeopard/SDL OpenGL Application/SDLMain.m @@ -20,22 +20,6 @@ - (void)setAppleMenu:(NSMenu *)menu; /* 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 -#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; static BOOL gFinderLaunch; @@ -64,10 +48,10 @@ - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString; @end #endif -@interface SDLApplication : NSApplication +@interface NSApplication (SDLApplication) @end -@implementation SDLApplication +@implementation NSApplication (SDLApplication) /* Invoked from the Quit menu item */ - (void)terminate:(id)sender { @@ -119,7 +103,6 @@ - (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName if ([menuItem hasSubmenu]) [self fixMenu:[menuItem submenu] withAppName:appName]; } - [ aMenu sizeToFit ]; } #else @@ -202,18 +185,7 @@ static void CustomApplicationMain (int argc, char **argv) SDLMain *sdlMain; /* Ensure the application object is initialised */ - [SDLApplication 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)) - [SDLApplication sharedApplication]; - } -#endif /* SDL_USE_CPS */ + [[NSApplication sharedApplication] activateIgnoringOtherApps: YES]; /* Set up the menubar */ [NSApp setMainMenu:[[NSMenu alloc] init]]; @@ -346,18 +318,38 @@ - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString @end - #ifdef main # undef main #endif +static int IsRootCwd() +{ + char buf[MAXPATHLEN]; + char *cwd = getcwd(buf, sizeof (buf)); + return (cwd && (strcmp(cwd, "/") == 0)); +} + +static int IsFinderLaunch(const int argc, char **argv) +{ + /* -psn_XXX is passed if we are launched from Finder, SOMETIMES */ + if ( (argc >= 2) && (strncmp(argv[1], "-psn", 4) == 0) ) { + return 1; + } else if ((argc == 1) && IsRootCwd()) { + /* we might still be launched from the Finder; on 10.9+, you might not + get the -psn command line anymore. If there's no + command line, and if our current working directory is "/", it + might as well be a Finder launch. */ + return 1; + } + return 0; /* not a Finder launch. */ +} + /* Main entry point to executable - should *not* be SDL_main! */ int main (int argc, char **argv) { /* Copy the arguments into a global variable */ - /* This is passed if we are launched by double-clicking */ - if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) { + if (IsFinderLaunch(argc, argv)) { gArgv = (char **) SDL_malloc(sizeof (char *) * 2); gArgv[0] = argv[0]; gArgv[1] = NULL; @@ -373,7 +365,6 @@ int main (int argc, char **argv) } #if SDL_USE_NIB_FILE - [SDLApplication poseAsClass:[NSApplication class]]; NSApplicationMain (argc, argv); #else CustomApplicationMain (argc, argv); diff --git a/Xcode/TemplatesForXcodeSnowLeopard/SDL Application/SDLMain.m b/Xcode/TemplatesForXcodeSnowLeopard/SDL Application/SDLMain.m index b065a2009..6948979df 100644 --- a/Xcode/TemplatesForXcodeSnowLeopard/SDL Application/SDLMain.m +++ b/Xcode/TemplatesForXcodeSnowLeopard/SDL Application/SDLMain.m @@ -20,22 +20,6 @@ - (void)setAppleMenu:(NSMenu *)menu; /* 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 -#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; static BOOL gFinderLaunch; @@ -64,10 +48,10 @@ - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString; @end #endif -@interface SDLApplication : NSApplication +@interface NSApplication (SDLApplication) @end -@implementation SDLApplication +@implementation NSApplication (SDLApplication) /* Invoked from the Quit menu item */ - (void)terminate:(id)sender { @@ -119,7 +103,6 @@ - (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName if ([menuItem hasSubmenu]) [self fixMenu:[menuItem submenu] withAppName:appName]; } - [ aMenu sizeToFit ]; } #else @@ -202,18 +185,7 @@ static void CustomApplicationMain (int argc, char **argv) SDLMain *sdlMain; /* Ensure the application object is initialised */ - [SDLApplication 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)) - [SDLApplication sharedApplication]; - } -#endif /* SDL_USE_CPS */ + [[NSApplication sharedApplication] activateIgnoringOtherApps: YES]; /* Set up the menubar */ [NSApp setMainMenu:[[NSMenu alloc] init]]; @@ -346,18 +318,38 @@ - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString @end - #ifdef main # undef main #endif +static int IsRootCwd() +{ + char buf[MAXPATHLEN]; + char *cwd = getcwd(buf, sizeof (buf)); + return (cwd && (strcmp(cwd, "/") == 0)); +} + +static int IsFinderLaunch(const int argc, char **argv) +{ + /* -psn_XXX is passed if we are launched from Finder, SOMETIMES */ + if ( (argc >= 2) && (strncmp(argv[1], "-psn", 4) == 0) ) { + return 1; + } else if ((argc == 1) && IsRootCwd()) { + /* we might still be launched from the Finder; on 10.9+, you might not + get the -psn command line anymore. If there's no + command line, and if our current working directory is "/", it + might as well be a Finder launch. */ + return 1; + } + return 0; /* not a Finder launch. */ +} + /* Main entry point to executable - should *not* be SDL_main! */ int main (int argc, char **argv) { /* Copy the arguments into a global variable */ - /* This is passed if we are launched by double-clicking */ - if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) { + if (IsFinderLaunch(argc, argv)) { gArgv = (char **) SDL_malloc(sizeof (char *) * 2); gArgv[0] = argv[0]; gArgv[1] = NULL; @@ -373,7 +365,6 @@ int main (int argc, char **argv) } #if SDL_USE_NIB_FILE - [SDLApplication poseAsClass:[NSApplication class]]; NSApplicationMain (argc, argv); #else CustomApplicationMain (argc, argv); diff --git a/Xcode/TemplatesForXcodeSnowLeopard/SDL Cocoa Application/SDLMain.m b/Xcode/TemplatesForXcodeSnowLeopard/SDL Cocoa Application/SDLMain.m index b065a2009..6948979df 100644 --- a/Xcode/TemplatesForXcodeSnowLeopard/SDL Cocoa Application/SDLMain.m +++ b/Xcode/TemplatesForXcodeSnowLeopard/SDL Cocoa Application/SDLMain.m @@ -20,22 +20,6 @@ - (void)setAppleMenu:(NSMenu *)menu; /* 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 -#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; static BOOL gFinderLaunch; @@ -64,10 +48,10 @@ - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString; @end #endif -@interface SDLApplication : NSApplication +@interface NSApplication (SDLApplication) @end -@implementation SDLApplication +@implementation NSApplication (SDLApplication) /* Invoked from the Quit menu item */ - (void)terminate:(id)sender { @@ -119,7 +103,6 @@ - (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName if ([menuItem hasSubmenu]) [self fixMenu:[menuItem submenu] withAppName:appName]; } - [ aMenu sizeToFit ]; } #else @@ -202,18 +185,7 @@ static void CustomApplicationMain (int argc, char **argv) SDLMain *sdlMain; /* Ensure the application object is initialised */ - [SDLApplication 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)) - [SDLApplication sharedApplication]; - } -#endif /* SDL_USE_CPS */ + [[NSApplication sharedApplication] activateIgnoringOtherApps: YES]; /* Set up the menubar */ [NSApp setMainMenu:[[NSMenu alloc] init]]; @@ -346,18 +318,38 @@ - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString @end - #ifdef main # undef main #endif +static int IsRootCwd() +{ + char buf[MAXPATHLEN]; + char *cwd = getcwd(buf, sizeof (buf)); + return (cwd && (strcmp(cwd, "/") == 0)); +} + +static int IsFinderLaunch(const int argc, char **argv) +{ + /* -psn_XXX is passed if we are launched from Finder, SOMETIMES */ + if ( (argc >= 2) && (strncmp(argv[1], "-psn", 4) == 0) ) { + return 1; + } else if ((argc == 1) && IsRootCwd()) { + /* we might still be launched from the Finder; on 10.9+, you might not + get the -psn command line anymore. If there's no + command line, and if our current working directory is "/", it + might as well be a Finder launch. */ + return 1; + } + return 0; /* not a Finder launch. */ +} + /* Main entry point to executable - should *not* be SDL_main! */ int main (int argc, char **argv) { /* Copy the arguments into a global variable */ - /* This is passed if we are launched by double-clicking */ - if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) { + if (IsFinderLaunch(argc, argv)) { gArgv = (char **) SDL_malloc(sizeof (char *) * 2); gArgv[0] = argv[0]; gArgv[1] = NULL; @@ -373,7 +365,6 @@ int main (int argc, char **argv) } #if SDL_USE_NIB_FILE - [SDLApplication poseAsClass:[NSApplication class]]; NSApplicationMain (argc, argv); #else CustomApplicationMain (argc, argv); diff --git a/Xcode/TemplatesForXcodeSnowLeopard/SDL OpenGL Application/SDLMain.m b/Xcode/TemplatesForXcodeSnowLeopard/SDL OpenGL Application/SDLMain.m index b065a2009..6948979df 100644 --- a/Xcode/TemplatesForXcodeSnowLeopard/SDL OpenGL Application/SDLMain.m +++ b/Xcode/TemplatesForXcodeSnowLeopard/SDL OpenGL Application/SDLMain.m @@ -20,22 +20,6 @@ - (void)setAppleMenu:(NSMenu *)menu; /* 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 -#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; static BOOL gFinderLaunch; @@ -64,10 +48,10 @@ - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString; @end #endif -@interface SDLApplication : NSApplication +@interface NSApplication (SDLApplication) @end -@implementation SDLApplication +@implementation NSApplication (SDLApplication) /* Invoked from the Quit menu item */ - (void)terminate:(id)sender { @@ -119,7 +103,6 @@ - (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName if ([menuItem hasSubmenu]) [self fixMenu:[menuItem submenu] withAppName:appName]; } - [ aMenu sizeToFit ]; } #else @@ -202,18 +185,7 @@ static void CustomApplicationMain (int argc, char **argv) SDLMain *sdlMain; /* Ensure the application object is initialised */ - [SDLApplication 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)) - [SDLApplication sharedApplication]; - } -#endif /* SDL_USE_CPS */ + [[NSApplication sharedApplication] activateIgnoringOtherApps: YES]; /* Set up the menubar */ [NSApp setMainMenu:[[NSMenu alloc] init]]; @@ -346,18 +318,38 @@ - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString @end - #ifdef main # undef main #endif +static int IsRootCwd() +{ + char buf[MAXPATHLEN]; + char *cwd = getcwd(buf, sizeof (buf)); + return (cwd && (strcmp(cwd, "/") == 0)); +} + +static int IsFinderLaunch(const int argc, char **argv) +{ + /* -psn_XXX is passed if we are launched from Finder, SOMETIMES */ + if ( (argc >= 2) && (strncmp(argv[1], "-psn", 4) == 0) ) { + return 1; + } else if ((argc == 1) && IsRootCwd()) { + /* we might still be launched from the Finder; on 10.9+, you might not + get the -psn command line anymore. If there's no + command line, and if our current working directory is "/", it + might as well be a Finder launch. */ + return 1; + } + return 0; /* not a Finder launch. */ +} + /* Main entry point to executable - should *not* be SDL_main! */ int main (int argc, char **argv) { /* Copy the arguments into a global variable */ - /* This is passed if we are launched by double-clicking */ - if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) { + if (IsFinderLaunch(argc, argv)) { gArgv = (char **) SDL_malloc(sizeof (char *) * 2); gArgv[0] = argv[0]; gArgv[1] = NULL; @@ -373,7 +365,6 @@ int main (int argc, char **argv) } #if SDL_USE_NIB_FILE - [SDLApplication poseAsClass:[NSApplication class]]; NSApplicationMain (argc, argv); #else CustomApplicationMain (argc, argv); diff --git a/Xcode/TemplatesForXcodeTiger/SDL Application/SDLMain.m b/Xcode/TemplatesForXcodeTiger/SDL Application/SDLMain.m index b065a2009..6948979df 100644 --- a/Xcode/TemplatesForXcodeTiger/SDL Application/SDLMain.m +++ b/Xcode/TemplatesForXcodeTiger/SDL Application/SDLMain.m @@ -20,22 +20,6 @@ - (void)setAppleMenu:(NSMenu *)menu; /* 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 -#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; static BOOL gFinderLaunch; @@ -64,10 +48,10 @@ - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString; @end #endif -@interface SDLApplication : NSApplication +@interface NSApplication (SDLApplication) @end -@implementation SDLApplication +@implementation NSApplication (SDLApplication) /* Invoked from the Quit menu item */ - (void)terminate:(id)sender { @@ -119,7 +103,6 @@ - (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName if ([menuItem hasSubmenu]) [self fixMenu:[menuItem submenu] withAppName:appName]; } - [ aMenu sizeToFit ]; } #else @@ -202,18 +185,7 @@ static void CustomApplicationMain (int argc, char **argv) SDLMain *sdlMain; /* Ensure the application object is initialised */ - [SDLApplication 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)) - [SDLApplication sharedApplication]; - } -#endif /* SDL_USE_CPS */ + [[NSApplication sharedApplication] activateIgnoringOtherApps: YES]; /* Set up the menubar */ [NSApp setMainMenu:[[NSMenu alloc] init]]; @@ -346,18 +318,38 @@ - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString @end - #ifdef main # undef main #endif +static int IsRootCwd() +{ + char buf[MAXPATHLEN]; + char *cwd = getcwd(buf, sizeof (buf)); + return (cwd && (strcmp(cwd, "/") == 0)); +} + +static int IsFinderLaunch(const int argc, char **argv) +{ + /* -psn_XXX is passed if we are launched from Finder, SOMETIMES */ + if ( (argc >= 2) && (strncmp(argv[1], "-psn", 4) == 0) ) { + return 1; + } else if ((argc == 1) && IsRootCwd()) { + /* we might still be launched from the Finder; on 10.9+, you might not + get the -psn command line anymore. If there's no + command line, and if our current working directory is "/", it + might as well be a Finder launch. */ + return 1; + } + return 0; /* not a Finder launch. */ +} + /* Main entry point to executable - should *not* be SDL_main! */ int main (int argc, char **argv) { /* Copy the arguments into a global variable */ - /* This is passed if we are launched by double-clicking */ - if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) { + if (IsFinderLaunch(argc, argv)) { gArgv = (char **) SDL_malloc(sizeof (char *) * 2); gArgv[0] = argv[0]; gArgv[1] = NULL; @@ -373,7 +365,6 @@ int main (int argc, char **argv) } #if SDL_USE_NIB_FILE - [SDLApplication poseAsClass:[NSApplication class]]; NSApplicationMain (argc, argv); #else CustomApplicationMain (argc, argv); diff --git a/Xcode/TemplatesForXcodeTiger/SDL Cocoa Application/SDLMain.m b/Xcode/TemplatesForXcodeTiger/SDL Cocoa Application/SDLMain.m index b065a2009..6948979df 100644 --- a/Xcode/TemplatesForXcodeTiger/SDL Cocoa Application/SDLMain.m +++ b/Xcode/TemplatesForXcodeTiger/SDL Cocoa Application/SDLMain.m @@ -20,22 +20,6 @@ - (void)setAppleMenu:(NSMenu *)menu; /* 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 -#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; static BOOL gFinderLaunch; @@ -64,10 +48,10 @@ - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString; @end #endif -@interface SDLApplication : NSApplication +@interface NSApplication (SDLApplication) @end -@implementation SDLApplication +@implementation NSApplication (SDLApplication) /* Invoked from the Quit menu item */ - (void)terminate:(id)sender { @@ -119,7 +103,6 @@ - (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName if ([menuItem hasSubmenu]) [self fixMenu:[menuItem submenu] withAppName:appName]; } - [ aMenu sizeToFit ]; } #else @@ -202,18 +185,7 @@ static void CustomApplicationMain (int argc, char **argv) SDLMain *sdlMain; /* Ensure the application object is initialised */ - [SDLApplication 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)) - [SDLApplication sharedApplication]; - } -#endif /* SDL_USE_CPS */ + [[NSApplication sharedApplication] activateIgnoringOtherApps: YES]; /* Set up the menubar */ [NSApp setMainMenu:[[NSMenu alloc] init]]; @@ -346,18 +318,38 @@ - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString @end - #ifdef main # undef main #endif +static int IsRootCwd() +{ + char buf[MAXPATHLEN]; + char *cwd = getcwd(buf, sizeof (buf)); + return (cwd && (strcmp(cwd, "/") == 0)); +} + +static int IsFinderLaunch(const int argc, char **argv) +{ + /* -psn_XXX is passed if we are launched from Finder, SOMETIMES */ + if ( (argc >= 2) && (strncmp(argv[1], "-psn", 4) == 0) ) { + return 1; + } else if ((argc == 1) && IsRootCwd()) { + /* we might still be launched from the Finder; on 10.9+, you might not + get the -psn command line anymore. If there's no + command line, and if our current working directory is "/", it + might as well be a Finder launch. */ + return 1; + } + return 0; /* not a Finder launch. */ +} + /* Main entry point to executable - should *not* be SDL_main! */ int main (int argc, char **argv) { /* Copy the arguments into a global variable */ - /* This is passed if we are launched by double-clicking */ - if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) { + if (IsFinderLaunch(argc, argv)) { gArgv = (char **) SDL_malloc(sizeof (char *) * 2); gArgv[0] = argv[0]; gArgv[1] = NULL; @@ -373,7 +365,6 @@ int main (int argc, char **argv) } #if SDL_USE_NIB_FILE - [SDLApplication poseAsClass:[NSApplication class]]; NSApplicationMain (argc, argv); #else CustomApplicationMain (argc, argv); diff --git a/Xcode/TemplatesForXcodeTiger/SDL OpenGL Application/SDLMain.m b/Xcode/TemplatesForXcodeTiger/SDL OpenGL Application/SDLMain.m index b065a2009..6948979df 100644 --- a/Xcode/TemplatesForXcodeTiger/SDL OpenGL Application/SDLMain.m +++ b/Xcode/TemplatesForXcodeTiger/SDL OpenGL Application/SDLMain.m @@ -20,22 +20,6 @@ - (void)setAppleMenu:(NSMenu *)menu; /* 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 -#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; static BOOL gFinderLaunch; @@ -64,10 +48,10 @@ - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString; @end #endif -@interface SDLApplication : NSApplication +@interface NSApplication (SDLApplication) @end -@implementation SDLApplication +@implementation NSApplication (SDLApplication) /* Invoked from the Quit menu item */ - (void)terminate:(id)sender { @@ -119,7 +103,6 @@ - (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName if ([menuItem hasSubmenu]) [self fixMenu:[menuItem submenu] withAppName:appName]; } - [ aMenu sizeToFit ]; } #else @@ -202,18 +185,7 @@ static void CustomApplicationMain (int argc, char **argv) SDLMain *sdlMain; /* Ensure the application object is initialised */ - [SDLApplication 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)) - [SDLApplication sharedApplication]; - } -#endif /* SDL_USE_CPS */ + [[NSApplication sharedApplication] activateIgnoringOtherApps: YES]; /* Set up the menubar */ [NSApp setMainMenu:[[NSMenu alloc] init]]; @@ -346,18 +318,38 @@ - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString @end - #ifdef main # undef main #endif +static int IsRootCwd() +{ + char buf[MAXPATHLEN]; + char *cwd = getcwd(buf, sizeof (buf)); + return (cwd && (strcmp(cwd, "/") == 0)); +} + +static int IsFinderLaunch(const int argc, char **argv) +{ + /* -psn_XXX is passed if we are launched from Finder, SOMETIMES */ + if ( (argc >= 2) && (strncmp(argv[1], "-psn", 4) == 0) ) { + return 1; + } else if ((argc == 1) && IsRootCwd()) { + /* we might still be launched from the Finder; on 10.9+, you might not + get the -psn command line anymore. If there's no + command line, and if our current working directory is "/", it + might as well be a Finder launch. */ + return 1; + } + return 0; /* not a Finder launch. */ +} + /* Main entry point to executable - should *not* be SDL_main! */ int main (int argc, char **argv) { /* Copy the arguments into a global variable */ - /* This is passed if we are launched by double-clicking */ - if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) { + if (IsFinderLaunch(argc, argv)) { gArgv = (char **) SDL_malloc(sizeof (char *) * 2); gArgv[0] = argv[0]; gArgv[1] = NULL; @@ -373,7 +365,6 @@ int main (int argc, char **argv) } #if SDL_USE_NIB_FILE - [SDLApplication poseAsClass:[NSApplication class]]; NSApplicationMain (argc, argv); #else CustomApplicationMain (argc, argv);