updated SDLMain.m copies in Xcode project templates to match the one in src SDL-1.2
authorOzkan Sezer <sezeroz@gmail.com>
Sat, 30 Jun 2018 23:10:01 +0300
branchSDL-1.2
changeset 12048eb70ab731d29
parent 12047 160a0e63e641
child 12049 69d8281bdd66
updated SDLMain.m copies in Xcode project templates to match the one in src

(Applied changesets: 1496aa09e41e, d78e4e0bf553, cfec3f86fba7, 0c1a8b0429a9,
and 67f391c74aee .)
Xcode/TemplatesForXcodeLeopard/SDL Application/SDLMain.m
Xcode/TemplatesForXcodeLeopard/SDL Cocoa Application/SDLMain.m
Xcode/TemplatesForXcodeLeopard/SDL OpenGL Application/SDLMain.m
Xcode/TemplatesForXcodeSnowLeopard/SDL Application/SDLMain.m
Xcode/TemplatesForXcodeSnowLeopard/SDL Cocoa Application/SDLMain.m
Xcode/TemplatesForXcodeSnowLeopard/SDL OpenGL Application/SDLMain.m
Xcode/TemplatesForXcodeTiger/SDL Application/SDLMain.m
Xcode/TemplatesForXcodeTiger/SDL Cocoa Application/SDLMain.m
Xcode/TemplatesForXcodeTiger/SDL OpenGL Application/SDLMain.m
     1.1 --- a/Xcode/TemplatesForXcodeLeopard/SDL Application/SDLMain.m	Sat Jun 30 22:55:05 2018 +0300
     1.2 +++ b/Xcode/TemplatesForXcodeLeopard/SDL Application/SDLMain.m	Sat Jun 30 23:10:01 2018 +0300
     1.3 @@ -20,22 +20,6 @@
     1.4  /* Use this flag to determine whether we use SDLMain.nib or not */
     1.5  #define		SDL_USE_NIB_FILE	0
     1.6  
     1.7 -/* Use this flag to determine whether we use CPS (docking) or not */
     1.8 -#define		SDL_USE_CPS		1
     1.9 -#ifdef SDL_USE_CPS
    1.10 -/* Portions of CPS.h */
    1.11 -typedef struct CPSProcessSerNum
    1.12 -{
    1.13 -	UInt32		lo;
    1.14 -	UInt32		hi;
    1.15 -} CPSProcessSerNum;
    1.16 -
    1.17 -extern OSErr	CPSGetCurrentProcess( CPSProcessSerNum *psn);
    1.18 -extern OSErr 	CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
    1.19 -extern OSErr	CPSSetFrontProcess( CPSProcessSerNum *psn);
    1.20 -
    1.21 -#endif /* SDL_USE_CPS */
    1.22 -
    1.23  static int    gArgc;
    1.24  static char  **gArgv;
    1.25  static BOOL   gFinderLaunch;
    1.26 @@ -64,10 +48,10 @@
    1.27  @end
    1.28  #endif
    1.29  
    1.30 -@interface SDLApplication : NSApplication
    1.31 +@interface NSApplication (SDLApplication)
    1.32  @end
    1.33  
    1.34 -@implementation SDLApplication
    1.35 +@implementation NSApplication (SDLApplication)
    1.36  /* Invoked from the Quit menu item */
    1.37  - (void)terminate:(id)sender
    1.38  {
    1.39 @@ -119,7 +103,6 @@
    1.40          if ([menuItem hasSubmenu])
    1.41              [self fixMenu:[menuItem submenu] withAppName:appName];
    1.42      }
    1.43 -    [ aMenu sizeToFit ];
    1.44  }
    1.45  
    1.46  #else
    1.47 @@ -202,18 +185,7 @@
    1.48      SDLMain				*sdlMain;
    1.49  
    1.50      /* Ensure the application object is initialised */
    1.51 -    [SDLApplication sharedApplication];
    1.52 -    
    1.53 -#ifdef SDL_USE_CPS
    1.54 -    {
    1.55 -        CPSProcessSerNum PSN;
    1.56 -        /* Tell the dock about us */
    1.57 -        if (!CPSGetCurrentProcess(&PSN))
    1.58 -            if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
    1.59 -                if (!CPSSetFrontProcess(&PSN))
    1.60 -                    [SDLApplication sharedApplication];
    1.61 -    }
    1.62 -#endif /* SDL_USE_CPS */
    1.63 +    [[NSApplication sharedApplication] activateIgnoringOtherApps: YES];
    1.64  
    1.65      /* Set up the menubar */
    1.66      [NSApp setMainMenu:[[NSMenu alloc] init]];
    1.67 @@ -346,18 +318,38 @@
    1.68  @end
    1.69  
    1.70  
    1.71 -
    1.72  #ifdef main
    1.73  #  undef main
    1.74  #endif
    1.75  
    1.76  
    1.77 +static int IsRootCwd()
    1.78 +{
    1.79 +    char buf[MAXPATHLEN];
    1.80 +    char *cwd = getcwd(buf, sizeof (buf));
    1.81 +    return (cwd && (strcmp(cwd, "/") == 0));
    1.82 +}
    1.83 +
    1.84 +static int IsFinderLaunch(const int argc, char **argv)
    1.85 +{
    1.86 +    /* -psn_XXX is passed if we are launched from Finder, SOMETIMES */
    1.87 +    if ( (argc >= 2) && (strncmp(argv[1], "-psn", 4) == 0) ) {
    1.88 +        return 1;
    1.89 +    } else if ((argc == 1) && IsRootCwd()) {
    1.90 +        /* we might still be launched from the Finder; on 10.9+, you might not
    1.91 +        get the -psn command line anymore. If there's no
    1.92 +        command line, and if our current working directory is "/", it
    1.93 +        might as well be a Finder launch. */
    1.94 +        return 1;
    1.95 +    }
    1.96 +    return 0;  /* not a Finder launch. */
    1.97 +}
    1.98 +
    1.99  /* Main entry point to executable - should *not* be SDL_main! */
   1.100  int main (int argc, char **argv)
   1.101  {
   1.102      /* Copy the arguments into a global variable */
   1.103 -    /* This is passed if we are launched by double-clicking */
   1.104 -    if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
   1.105 +    if (IsFinderLaunch(argc, argv)) {
   1.106          gArgv = (char **) SDL_malloc(sizeof (char *) * 2);
   1.107          gArgv[0] = argv[0];
   1.108          gArgv[1] = NULL;
   1.109 @@ -373,7 +365,6 @@
   1.110      }
   1.111  
   1.112  #if SDL_USE_NIB_FILE
   1.113 -    [SDLApplication poseAsClass:[NSApplication class]];
   1.114      NSApplicationMain (argc, argv);
   1.115  #else
   1.116      CustomApplicationMain (argc, argv);
     2.1 --- a/Xcode/TemplatesForXcodeLeopard/SDL Cocoa Application/SDLMain.m	Sat Jun 30 22:55:05 2018 +0300
     2.2 +++ b/Xcode/TemplatesForXcodeLeopard/SDL Cocoa Application/SDLMain.m	Sat Jun 30 23:10:01 2018 +0300
     2.3 @@ -20,22 +20,6 @@
     2.4  /* Use this flag to determine whether we use SDLMain.nib or not */
     2.5  #define		SDL_USE_NIB_FILE	0
     2.6  
     2.7 -/* Use this flag to determine whether we use CPS (docking) or not */
     2.8 -#define		SDL_USE_CPS		1
     2.9 -#ifdef SDL_USE_CPS
    2.10 -/* Portions of CPS.h */
    2.11 -typedef struct CPSProcessSerNum
    2.12 -{
    2.13 -	UInt32		lo;
    2.14 -	UInt32		hi;
    2.15 -} CPSProcessSerNum;
    2.16 -
    2.17 -extern OSErr	CPSGetCurrentProcess( CPSProcessSerNum *psn);
    2.18 -extern OSErr 	CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
    2.19 -extern OSErr	CPSSetFrontProcess( CPSProcessSerNum *psn);
    2.20 -
    2.21 -#endif /* SDL_USE_CPS */
    2.22 -
    2.23  static int    gArgc;
    2.24  static char  **gArgv;
    2.25  static BOOL   gFinderLaunch;
    2.26 @@ -64,10 +48,10 @@
    2.27  @end
    2.28  #endif
    2.29  
    2.30 -@interface SDLApplication : NSApplication
    2.31 +@interface NSApplication (SDLApplication)
    2.32  @end
    2.33  
    2.34 -@implementation SDLApplication
    2.35 +@implementation NSApplication (SDLApplication)
    2.36  /* Invoked from the Quit menu item */
    2.37  - (void)terminate:(id)sender
    2.38  {
    2.39 @@ -119,7 +103,6 @@
    2.40          if ([menuItem hasSubmenu])
    2.41              [self fixMenu:[menuItem submenu] withAppName:appName];
    2.42      }
    2.43 -    [ aMenu sizeToFit ];
    2.44  }
    2.45  
    2.46  #else
    2.47 @@ -202,18 +185,7 @@
    2.48      SDLMain				*sdlMain;
    2.49  
    2.50      /* Ensure the application object is initialised */
    2.51 -    [SDLApplication sharedApplication];
    2.52 -    
    2.53 -#ifdef SDL_USE_CPS
    2.54 -    {
    2.55 -        CPSProcessSerNum PSN;
    2.56 -        /* Tell the dock about us */
    2.57 -        if (!CPSGetCurrentProcess(&PSN))
    2.58 -            if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
    2.59 -                if (!CPSSetFrontProcess(&PSN))
    2.60 -                    [SDLApplication sharedApplication];
    2.61 -    }
    2.62 -#endif /* SDL_USE_CPS */
    2.63 +    [[NSApplication sharedApplication] activateIgnoringOtherApps: YES];
    2.64  
    2.65      /* Set up the menubar */
    2.66      [NSApp setMainMenu:[[NSMenu alloc] init]];
    2.67 @@ -346,18 +318,38 @@
    2.68  @end
    2.69  
    2.70  
    2.71 -
    2.72  #ifdef main
    2.73  #  undef main
    2.74  #endif
    2.75  
    2.76  
    2.77 +static int IsRootCwd()
    2.78 +{
    2.79 +    char buf[MAXPATHLEN];
    2.80 +    char *cwd = getcwd(buf, sizeof (buf));
    2.81 +    return (cwd && (strcmp(cwd, "/") == 0));
    2.82 +}
    2.83 +
    2.84 +static int IsFinderLaunch(const int argc, char **argv)
    2.85 +{
    2.86 +    /* -psn_XXX is passed if we are launched from Finder, SOMETIMES */
    2.87 +    if ( (argc >= 2) && (strncmp(argv[1], "-psn", 4) == 0) ) {
    2.88 +        return 1;
    2.89 +    } else if ((argc == 1) && IsRootCwd()) {
    2.90 +        /* we might still be launched from the Finder; on 10.9+, you might not
    2.91 +        get the -psn command line anymore. If there's no
    2.92 +        command line, and if our current working directory is "/", it
    2.93 +        might as well be a Finder launch. */
    2.94 +        return 1;
    2.95 +    }
    2.96 +    return 0;  /* not a Finder launch. */
    2.97 +}
    2.98 +
    2.99  /* Main entry point to executable - should *not* be SDL_main! */
   2.100  int main (int argc, char **argv)
   2.101  {
   2.102      /* Copy the arguments into a global variable */
   2.103 -    /* This is passed if we are launched by double-clicking */
   2.104 -    if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
   2.105 +    if (IsFinderLaunch(argc, argv)) {
   2.106          gArgv = (char **) SDL_malloc(sizeof (char *) * 2);
   2.107          gArgv[0] = argv[0];
   2.108          gArgv[1] = NULL;
   2.109 @@ -373,7 +365,6 @@
   2.110      }
   2.111  
   2.112  #if SDL_USE_NIB_FILE
   2.113 -    [SDLApplication poseAsClass:[NSApplication class]];
   2.114      NSApplicationMain (argc, argv);
   2.115  #else
   2.116      CustomApplicationMain (argc, argv);
     3.1 --- a/Xcode/TemplatesForXcodeLeopard/SDL OpenGL Application/SDLMain.m	Sat Jun 30 22:55:05 2018 +0300
     3.2 +++ b/Xcode/TemplatesForXcodeLeopard/SDL OpenGL Application/SDLMain.m	Sat Jun 30 23:10:01 2018 +0300
     3.3 @@ -20,22 +20,6 @@
     3.4  /* Use this flag to determine whether we use SDLMain.nib or not */
     3.5  #define		SDL_USE_NIB_FILE	0
     3.6  
     3.7 -/* Use this flag to determine whether we use CPS (docking) or not */
     3.8 -#define		SDL_USE_CPS		1
     3.9 -#ifdef SDL_USE_CPS
    3.10 -/* Portions of CPS.h */
    3.11 -typedef struct CPSProcessSerNum
    3.12 -{
    3.13 -	UInt32		lo;
    3.14 -	UInt32		hi;
    3.15 -} CPSProcessSerNum;
    3.16 -
    3.17 -extern OSErr	CPSGetCurrentProcess( CPSProcessSerNum *psn);
    3.18 -extern OSErr 	CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
    3.19 -extern OSErr	CPSSetFrontProcess( CPSProcessSerNum *psn);
    3.20 -
    3.21 -#endif /* SDL_USE_CPS */
    3.22 -
    3.23  static int    gArgc;
    3.24  static char  **gArgv;
    3.25  static BOOL   gFinderLaunch;
    3.26 @@ -64,10 +48,10 @@
    3.27  @end
    3.28  #endif
    3.29  
    3.30 -@interface SDLApplication : NSApplication
    3.31 +@interface NSApplication (SDLApplication)
    3.32  @end
    3.33  
    3.34 -@implementation SDLApplication
    3.35 +@implementation NSApplication (SDLApplication)
    3.36  /* Invoked from the Quit menu item */
    3.37  - (void)terminate:(id)sender
    3.38  {
    3.39 @@ -119,7 +103,6 @@
    3.40          if ([menuItem hasSubmenu])
    3.41              [self fixMenu:[menuItem submenu] withAppName:appName];
    3.42      }
    3.43 -    [ aMenu sizeToFit ];
    3.44  }
    3.45  
    3.46  #else
    3.47 @@ -202,18 +185,7 @@
    3.48      SDLMain				*sdlMain;
    3.49  
    3.50      /* Ensure the application object is initialised */
    3.51 -    [SDLApplication sharedApplication];
    3.52 -    
    3.53 -#ifdef SDL_USE_CPS
    3.54 -    {
    3.55 -        CPSProcessSerNum PSN;
    3.56 -        /* Tell the dock about us */
    3.57 -        if (!CPSGetCurrentProcess(&PSN))
    3.58 -            if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
    3.59 -                if (!CPSSetFrontProcess(&PSN))
    3.60 -                    [SDLApplication sharedApplication];
    3.61 -    }
    3.62 -#endif /* SDL_USE_CPS */
    3.63 +    [[NSApplication sharedApplication] activateIgnoringOtherApps: YES];
    3.64  
    3.65      /* Set up the menubar */
    3.66      [NSApp setMainMenu:[[NSMenu alloc] init]];
    3.67 @@ -346,18 +318,38 @@
    3.68  @end
    3.69  
    3.70  
    3.71 -
    3.72  #ifdef main
    3.73  #  undef main
    3.74  #endif
    3.75  
    3.76  
    3.77 +static int IsRootCwd()
    3.78 +{
    3.79 +    char buf[MAXPATHLEN];
    3.80 +    char *cwd = getcwd(buf, sizeof (buf));
    3.81 +    return (cwd && (strcmp(cwd, "/") == 0));
    3.82 +}
    3.83 +
    3.84 +static int IsFinderLaunch(const int argc, char **argv)
    3.85 +{
    3.86 +    /* -psn_XXX is passed if we are launched from Finder, SOMETIMES */
    3.87 +    if ( (argc >= 2) && (strncmp(argv[1], "-psn", 4) == 0) ) {
    3.88 +        return 1;
    3.89 +    } else if ((argc == 1) && IsRootCwd()) {
    3.90 +        /* we might still be launched from the Finder; on 10.9+, you might not
    3.91 +        get the -psn command line anymore. If there's no
    3.92 +        command line, and if our current working directory is "/", it
    3.93 +        might as well be a Finder launch. */
    3.94 +        return 1;
    3.95 +    }
    3.96 +    return 0;  /* not a Finder launch. */
    3.97 +}
    3.98 +
    3.99  /* Main entry point to executable - should *not* be SDL_main! */
   3.100  int main (int argc, char **argv)
   3.101  {
   3.102      /* Copy the arguments into a global variable */
   3.103 -    /* This is passed if we are launched by double-clicking */
   3.104 -    if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
   3.105 +    if (IsFinderLaunch(argc, argv)) {
   3.106          gArgv = (char **) SDL_malloc(sizeof (char *) * 2);
   3.107          gArgv[0] = argv[0];
   3.108          gArgv[1] = NULL;
   3.109 @@ -373,7 +365,6 @@
   3.110      }
   3.111  
   3.112  #if SDL_USE_NIB_FILE
   3.113 -    [SDLApplication poseAsClass:[NSApplication class]];
   3.114      NSApplicationMain (argc, argv);
   3.115  #else
   3.116      CustomApplicationMain (argc, argv);
     4.1 --- a/Xcode/TemplatesForXcodeSnowLeopard/SDL Application/SDLMain.m	Sat Jun 30 22:55:05 2018 +0300
     4.2 +++ b/Xcode/TemplatesForXcodeSnowLeopard/SDL Application/SDLMain.m	Sat Jun 30 23:10:01 2018 +0300
     4.3 @@ -20,22 +20,6 @@
     4.4  /* Use this flag to determine whether we use SDLMain.nib or not */
     4.5  #define		SDL_USE_NIB_FILE	0
     4.6  
     4.7 -/* Use this flag to determine whether we use CPS (docking) or not */
     4.8 -#define		SDL_USE_CPS		1
     4.9 -#ifdef SDL_USE_CPS
    4.10 -/* Portions of CPS.h */
    4.11 -typedef struct CPSProcessSerNum
    4.12 -{
    4.13 -	UInt32		lo;
    4.14 -	UInt32		hi;
    4.15 -} CPSProcessSerNum;
    4.16 -
    4.17 -extern OSErr	CPSGetCurrentProcess( CPSProcessSerNum *psn);
    4.18 -extern OSErr 	CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
    4.19 -extern OSErr	CPSSetFrontProcess( CPSProcessSerNum *psn);
    4.20 -
    4.21 -#endif /* SDL_USE_CPS */
    4.22 -
    4.23  static int    gArgc;
    4.24  static char  **gArgv;
    4.25  static BOOL   gFinderLaunch;
    4.26 @@ -64,10 +48,10 @@
    4.27  @end
    4.28  #endif
    4.29  
    4.30 -@interface SDLApplication : NSApplication
    4.31 +@interface NSApplication (SDLApplication)
    4.32  @end
    4.33  
    4.34 -@implementation SDLApplication
    4.35 +@implementation NSApplication (SDLApplication)
    4.36  /* Invoked from the Quit menu item */
    4.37  - (void)terminate:(id)sender
    4.38  {
    4.39 @@ -119,7 +103,6 @@
    4.40          if ([menuItem hasSubmenu])
    4.41              [self fixMenu:[menuItem submenu] withAppName:appName];
    4.42      }
    4.43 -    [ aMenu sizeToFit ];
    4.44  }
    4.45  
    4.46  #else
    4.47 @@ -202,18 +185,7 @@
    4.48      SDLMain				*sdlMain;
    4.49  
    4.50      /* Ensure the application object is initialised */
    4.51 -    [SDLApplication sharedApplication];
    4.52 -    
    4.53 -#ifdef SDL_USE_CPS
    4.54 -    {
    4.55 -        CPSProcessSerNum PSN;
    4.56 -        /* Tell the dock about us */
    4.57 -        if (!CPSGetCurrentProcess(&PSN))
    4.58 -            if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
    4.59 -                if (!CPSSetFrontProcess(&PSN))
    4.60 -                    [SDLApplication sharedApplication];
    4.61 -    }
    4.62 -#endif /* SDL_USE_CPS */
    4.63 +    [[NSApplication sharedApplication] activateIgnoringOtherApps: YES];
    4.64  
    4.65      /* Set up the menubar */
    4.66      [NSApp setMainMenu:[[NSMenu alloc] init]];
    4.67 @@ -346,18 +318,38 @@
    4.68  @end
    4.69  
    4.70  
    4.71 -
    4.72  #ifdef main
    4.73  #  undef main
    4.74  #endif
    4.75  
    4.76  
    4.77 +static int IsRootCwd()
    4.78 +{
    4.79 +    char buf[MAXPATHLEN];
    4.80 +    char *cwd = getcwd(buf, sizeof (buf));
    4.81 +    return (cwd && (strcmp(cwd, "/") == 0));
    4.82 +}
    4.83 +
    4.84 +static int IsFinderLaunch(const int argc, char **argv)
    4.85 +{
    4.86 +    /* -psn_XXX is passed if we are launched from Finder, SOMETIMES */
    4.87 +    if ( (argc >= 2) && (strncmp(argv[1], "-psn", 4) == 0) ) {
    4.88 +        return 1;
    4.89 +    } else if ((argc == 1) && IsRootCwd()) {
    4.90 +        /* we might still be launched from the Finder; on 10.9+, you might not
    4.91 +        get the -psn command line anymore. If there's no
    4.92 +        command line, and if our current working directory is "/", it
    4.93 +        might as well be a Finder launch. */
    4.94 +        return 1;
    4.95 +    }
    4.96 +    return 0;  /* not a Finder launch. */
    4.97 +}
    4.98 +
    4.99  /* Main entry point to executable - should *not* be SDL_main! */
   4.100  int main (int argc, char **argv)
   4.101  {
   4.102      /* Copy the arguments into a global variable */
   4.103 -    /* This is passed if we are launched by double-clicking */
   4.104 -    if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
   4.105 +    if (IsFinderLaunch(argc, argv)) {
   4.106          gArgv = (char **) SDL_malloc(sizeof (char *) * 2);
   4.107          gArgv[0] = argv[0];
   4.108          gArgv[1] = NULL;
   4.109 @@ -373,7 +365,6 @@
   4.110      }
   4.111  
   4.112  #if SDL_USE_NIB_FILE
   4.113 -    [SDLApplication poseAsClass:[NSApplication class]];
   4.114      NSApplicationMain (argc, argv);
   4.115  #else
   4.116      CustomApplicationMain (argc, argv);
     5.1 --- a/Xcode/TemplatesForXcodeSnowLeopard/SDL Cocoa Application/SDLMain.m	Sat Jun 30 22:55:05 2018 +0300
     5.2 +++ b/Xcode/TemplatesForXcodeSnowLeopard/SDL Cocoa Application/SDLMain.m	Sat Jun 30 23:10:01 2018 +0300
     5.3 @@ -20,22 +20,6 @@
     5.4  /* Use this flag to determine whether we use SDLMain.nib or not */
     5.5  #define		SDL_USE_NIB_FILE	0
     5.6  
     5.7 -/* Use this flag to determine whether we use CPS (docking) or not */
     5.8 -#define		SDL_USE_CPS		1
     5.9 -#ifdef SDL_USE_CPS
    5.10 -/* Portions of CPS.h */
    5.11 -typedef struct CPSProcessSerNum
    5.12 -{
    5.13 -	UInt32		lo;
    5.14 -	UInt32		hi;
    5.15 -} CPSProcessSerNum;
    5.16 -
    5.17 -extern OSErr	CPSGetCurrentProcess( CPSProcessSerNum *psn);
    5.18 -extern OSErr 	CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
    5.19 -extern OSErr	CPSSetFrontProcess( CPSProcessSerNum *psn);
    5.20 -
    5.21 -#endif /* SDL_USE_CPS */
    5.22 -
    5.23  static int    gArgc;
    5.24  static char  **gArgv;
    5.25  static BOOL   gFinderLaunch;
    5.26 @@ -64,10 +48,10 @@
    5.27  @end
    5.28  #endif
    5.29  
    5.30 -@interface SDLApplication : NSApplication
    5.31 +@interface NSApplication (SDLApplication)
    5.32  @end
    5.33  
    5.34 -@implementation SDLApplication
    5.35 +@implementation NSApplication (SDLApplication)
    5.36  /* Invoked from the Quit menu item */
    5.37  - (void)terminate:(id)sender
    5.38  {
    5.39 @@ -119,7 +103,6 @@
    5.40          if ([menuItem hasSubmenu])
    5.41              [self fixMenu:[menuItem submenu] withAppName:appName];
    5.42      }
    5.43 -    [ aMenu sizeToFit ];
    5.44  }
    5.45  
    5.46  #else
    5.47 @@ -202,18 +185,7 @@
    5.48      SDLMain				*sdlMain;
    5.49  
    5.50      /* Ensure the application object is initialised */
    5.51 -    [SDLApplication sharedApplication];
    5.52 -    
    5.53 -#ifdef SDL_USE_CPS
    5.54 -    {
    5.55 -        CPSProcessSerNum PSN;
    5.56 -        /* Tell the dock about us */
    5.57 -        if (!CPSGetCurrentProcess(&PSN))
    5.58 -            if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
    5.59 -                if (!CPSSetFrontProcess(&PSN))
    5.60 -                    [SDLApplication sharedApplication];
    5.61 -    }
    5.62 -#endif /* SDL_USE_CPS */
    5.63 +    [[NSApplication sharedApplication] activateIgnoringOtherApps: YES];
    5.64  
    5.65      /* Set up the menubar */
    5.66      [NSApp setMainMenu:[[NSMenu alloc] init]];
    5.67 @@ -346,18 +318,38 @@
    5.68  @end
    5.69  
    5.70  
    5.71 -
    5.72  #ifdef main
    5.73  #  undef main
    5.74  #endif
    5.75  
    5.76  
    5.77 +static int IsRootCwd()
    5.78 +{
    5.79 +    char buf[MAXPATHLEN];
    5.80 +    char *cwd = getcwd(buf, sizeof (buf));
    5.81 +    return (cwd && (strcmp(cwd, "/") == 0));
    5.82 +}
    5.83 +
    5.84 +static int IsFinderLaunch(const int argc, char **argv)
    5.85 +{
    5.86 +    /* -psn_XXX is passed if we are launched from Finder, SOMETIMES */
    5.87 +    if ( (argc >= 2) && (strncmp(argv[1], "-psn", 4) == 0) ) {
    5.88 +        return 1;
    5.89 +    } else if ((argc == 1) && IsRootCwd()) {
    5.90 +        /* we might still be launched from the Finder; on 10.9+, you might not
    5.91 +        get the -psn command line anymore. If there's no
    5.92 +        command line, and if our current working directory is "/", it
    5.93 +        might as well be a Finder launch. */
    5.94 +        return 1;
    5.95 +    }
    5.96 +    return 0;  /* not a Finder launch. */
    5.97 +}
    5.98 +
    5.99  /* Main entry point to executable - should *not* be SDL_main! */
   5.100  int main (int argc, char **argv)
   5.101  {
   5.102      /* Copy the arguments into a global variable */
   5.103 -    /* This is passed if we are launched by double-clicking */
   5.104 -    if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
   5.105 +    if (IsFinderLaunch(argc, argv)) {
   5.106          gArgv = (char **) SDL_malloc(sizeof (char *) * 2);
   5.107          gArgv[0] = argv[0];
   5.108          gArgv[1] = NULL;
   5.109 @@ -373,7 +365,6 @@
   5.110      }
   5.111  
   5.112  #if SDL_USE_NIB_FILE
   5.113 -    [SDLApplication poseAsClass:[NSApplication class]];
   5.114      NSApplicationMain (argc, argv);
   5.115  #else
   5.116      CustomApplicationMain (argc, argv);
     6.1 --- a/Xcode/TemplatesForXcodeSnowLeopard/SDL OpenGL Application/SDLMain.m	Sat Jun 30 22:55:05 2018 +0300
     6.2 +++ b/Xcode/TemplatesForXcodeSnowLeopard/SDL OpenGL Application/SDLMain.m	Sat Jun 30 23:10:01 2018 +0300
     6.3 @@ -20,22 +20,6 @@
     6.4  /* Use this flag to determine whether we use SDLMain.nib or not */
     6.5  #define		SDL_USE_NIB_FILE	0
     6.6  
     6.7 -/* Use this flag to determine whether we use CPS (docking) or not */
     6.8 -#define		SDL_USE_CPS		1
     6.9 -#ifdef SDL_USE_CPS
    6.10 -/* Portions of CPS.h */
    6.11 -typedef struct CPSProcessSerNum
    6.12 -{
    6.13 -	UInt32		lo;
    6.14 -	UInt32		hi;
    6.15 -} CPSProcessSerNum;
    6.16 -
    6.17 -extern OSErr	CPSGetCurrentProcess( CPSProcessSerNum *psn);
    6.18 -extern OSErr 	CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
    6.19 -extern OSErr	CPSSetFrontProcess( CPSProcessSerNum *psn);
    6.20 -
    6.21 -#endif /* SDL_USE_CPS */
    6.22 -
    6.23  static int    gArgc;
    6.24  static char  **gArgv;
    6.25  static BOOL   gFinderLaunch;
    6.26 @@ -64,10 +48,10 @@
    6.27  @end
    6.28  #endif
    6.29  
    6.30 -@interface SDLApplication : NSApplication
    6.31 +@interface NSApplication (SDLApplication)
    6.32  @end
    6.33  
    6.34 -@implementation SDLApplication
    6.35 +@implementation NSApplication (SDLApplication)
    6.36  /* Invoked from the Quit menu item */
    6.37  - (void)terminate:(id)sender
    6.38  {
    6.39 @@ -119,7 +103,6 @@
    6.40          if ([menuItem hasSubmenu])
    6.41              [self fixMenu:[menuItem submenu] withAppName:appName];
    6.42      }
    6.43 -    [ aMenu sizeToFit ];
    6.44  }
    6.45  
    6.46  #else
    6.47 @@ -202,18 +185,7 @@
    6.48      SDLMain				*sdlMain;
    6.49  
    6.50      /* Ensure the application object is initialised */
    6.51 -    [SDLApplication sharedApplication];
    6.52 -    
    6.53 -#ifdef SDL_USE_CPS
    6.54 -    {
    6.55 -        CPSProcessSerNum PSN;
    6.56 -        /* Tell the dock about us */
    6.57 -        if (!CPSGetCurrentProcess(&PSN))
    6.58 -            if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
    6.59 -                if (!CPSSetFrontProcess(&PSN))
    6.60 -                    [SDLApplication sharedApplication];
    6.61 -    }
    6.62 -#endif /* SDL_USE_CPS */
    6.63 +    [[NSApplication sharedApplication] activateIgnoringOtherApps: YES];
    6.64  
    6.65      /* Set up the menubar */
    6.66      [NSApp setMainMenu:[[NSMenu alloc] init]];
    6.67 @@ -346,18 +318,38 @@
    6.68  @end
    6.69  
    6.70  
    6.71 -
    6.72  #ifdef main
    6.73  #  undef main
    6.74  #endif
    6.75  
    6.76  
    6.77 +static int IsRootCwd()
    6.78 +{
    6.79 +    char buf[MAXPATHLEN];
    6.80 +    char *cwd = getcwd(buf, sizeof (buf));
    6.81 +    return (cwd && (strcmp(cwd, "/") == 0));
    6.82 +}
    6.83 +
    6.84 +static int IsFinderLaunch(const int argc, char **argv)
    6.85 +{
    6.86 +    /* -psn_XXX is passed if we are launched from Finder, SOMETIMES */
    6.87 +    if ( (argc >= 2) && (strncmp(argv[1], "-psn", 4) == 0) ) {
    6.88 +        return 1;
    6.89 +    } else if ((argc == 1) && IsRootCwd()) {
    6.90 +        /* we might still be launched from the Finder; on 10.9+, you might not
    6.91 +        get the -psn command line anymore. If there's no
    6.92 +        command line, and if our current working directory is "/", it
    6.93 +        might as well be a Finder launch. */
    6.94 +        return 1;
    6.95 +    }
    6.96 +    return 0;  /* not a Finder launch. */
    6.97 +}
    6.98 +
    6.99  /* Main entry point to executable - should *not* be SDL_main! */
   6.100  int main (int argc, char **argv)
   6.101  {
   6.102      /* Copy the arguments into a global variable */
   6.103 -    /* This is passed if we are launched by double-clicking */
   6.104 -    if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
   6.105 +    if (IsFinderLaunch(argc, argv)) {
   6.106          gArgv = (char **) SDL_malloc(sizeof (char *) * 2);
   6.107          gArgv[0] = argv[0];
   6.108          gArgv[1] = NULL;
   6.109 @@ -373,7 +365,6 @@
   6.110      }
   6.111  
   6.112  #if SDL_USE_NIB_FILE
   6.113 -    [SDLApplication poseAsClass:[NSApplication class]];
   6.114      NSApplicationMain (argc, argv);
   6.115  #else
   6.116      CustomApplicationMain (argc, argv);
     7.1 --- a/Xcode/TemplatesForXcodeTiger/SDL Application/SDLMain.m	Sat Jun 30 22:55:05 2018 +0300
     7.2 +++ b/Xcode/TemplatesForXcodeTiger/SDL Application/SDLMain.m	Sat Jun 30 23:10:01 2018 +0300
     7.3 @@ -20,22 +20,6 @@
     7.4  /* Use this flag to determine whether we use SDLMain.nib or not */
     7.5  #define		SDL_USE_NIB_FILE	0
     7.6  
     7.7 -/* Use this flag to determine whether we use CPS (docking) or not */
     7.8 -#define		SDL_USE_CPS		1
     7.9 -#ifdef SDL_USE_CPS
    7.10 -/* Portions of CPS.h */
    7.11 -typedef struct CPSProcessSerNum
    7.12 -{
    7.13 -	UInt32		lo;
    7.14 -	UInt32		hi;
    7.15 -} CPSProcessSerNum;
    7.16 -
    7.17 -extern OSErr	CPSGetCurrentProcess( CPSProcessSerNum *psn);
    7.18 -extern OSErr 	CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
    7.19 -extern OSErr	CPSSetFrontProcess( CPSProcessSerNum *psn);
    7.20 -
    7.21 -#endif /* SDL_USE_CPS */
    7.22 -
    7.23  static int    gArgc;
    7.24  static char  **gArgv;
    7.25  static BOOL   gFinderLaunch;
    7.26 @@ -64,10 +48,10 @@
    7.27  @end
    7.28  #endif
    7.29  
    7.30 -@interface SDLApplication : NSApplication
    7.31 +@interface NSApplication (SDLApplication)
    7.32  @end
    7.33  
    7.34 -@implementation SDLApplication
    7.35 +@implementation NSApplication (SDLApplication)
    7.36  /* Invoked from the Quit menu item */
    7.37  - (void)terminate:(id)sender
    7.38  {
    7.39 @@ -119,7 +103,6 @@
    7.40          if ([menuItem hasSubmenu])
    7.41              [self fixMenu:[menuItem submenu] withAppName:appName];
    7.42      }
    7.43 -    [ aMenu sizeToFit ];
    7.44  }
    7.45  
    7.46  #else
    7.47 @@ -202,18 +185,7 @@
    7.48      SDLMain				*sdlMain;
    7.49  
    7.50      /* Ensure the application object is initialised */
    7.51 -    [SDLApplication sharedApplication];
    7.52 -    
    7.53 -#ifdef SDL_USE_CPS
    7.54 -    {
    7.55 -        CPSProcessSerNum PSN;
    7.56 -        /* Tell the dock about us */
    7.57 -        if (!CPSGetCurrentProcess(&PSN))
    7.58 -            if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
    7.59 -                if (!CPSSetFrontProcess(&PSN))
    7.60 -                    [SDLApplication sharedApplication];
    7.61 -    }
    7.62 -#endif /* SDL_USE_CPS */
    7.63 +    [[NSApplication sharedApplication] activateIgnoringOtherApps: YES];
    7.64  
    7.65      /* Set up the menubar */
    7.66      [NSApp setMainMenu:[[NSMenu alloc] init]];
    7.67 @@ -346,18 +318,38 @@
    7.68  @end
    7.69  
    7.70  
    7.71 -
    7.72  #ifdef main
    7.73  #  undef main
    7.74  #endif
    7.75  
    7.76  
    7.77 +static int IsRootCwd()
    7.78 +{
    7.79 +    char buf[MAXPATHLEN];
    7.80 +    char *cwd = getcwd(buf, sizeof (buf));
    7.81 +    return (cwd && (strcmp(cwd, "/") == 0));
    7.82 +}
    7.83 +
    7.84 +static int IsFinderLaunch(const int argc, char **argv)
    7.85 +{
    7.86 +    /* -psn_XXX is passed if we are launched from Finder, SOMETIMES */
    7.87 +    if ( (argc >= 2) && (strncmp(argv[1], "-psn", 4) == 0) ) {
    7.88 +        return 1;
    7.89 +    } else if ((argc == 1) && IsRootCwd()) {
    7.90 +        /* we might still be launched from the Finder; on 10.9+, you might not
    7.91 +        get the -psn command line anymore. If there's no
    7.92 +        command line, and if our current working directory is "/", it
    7.93 +        might as well be a Finder launch. */
    7.94 +        return 1;
    7.95 +    }
    7.96 +    return 0;  /* not a Finder launch. */
    7.97 +}
    7.98 +
    7.99  /* Main entry point to executable - should *not* be SDL_main! */
   7.100  int main (int argc, char **argv)
   7.101  {
   7.102      /* Copy the arguments into a global variable */
   7.103 -    /* This is passed if we are launched by double-clicking */
   7.104 -    if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
   7.105 +    if (IsFinderLaunch(argc, argv)) {
   7.106          gArgv = (char **) SDL_malloc(sizeof (char *) * 2);
   7.107          gArgv[0] = argv[0];
   7.108          gArgv[1] = NULL;
   7.109 @@ -373,7 +365,6 @@
   7.110      }
   7.111  
   7.112  #if SDL_USE_NIB_FILE
   7.113 -    [SDLApplication poseAsClass:[NSApplication class]];
   7.114      NSApplicationMain (argc, argv);
   7.115  #else
   7.116      CustomApplicationMain (argc, argv);
     8.1 --- a/Xcode/TemplatesForXcodeTiger/SDL Cocoa Application/SDLMain.m	Sat Jun 30 22:55:05 2018 +0300
     8.2 +++ b/Xcode/TemplatesForXcodeTiger/SDL Cocoa Application/SDLMain.m	Sat Jun 30 23:10:01 2018 +0300
     8.3 @@ -20,22 +20,6 @@
     8.4  /* Use this flag to determine whether we use SDLMain.nib or not */
     8.5  #define		SDL_USE_NIB_FILE	0
     8.6  
     8.7 -/* Use this flag to determine whether we use CPS (docking) or not */
     8.8 -#define		SDL_USE_CPS		1
     8.9 -#ifdef SDL_USE_CPS
    8.10 -/* Portions of CPS.h */
    8.11 -typedef struct CPSProcessSerNum
    8.12 -{
    8.13 -	UInt32		lo;
    8.14 -	UInt32		hi;
    8.15 -} CPSProcessSerNum;
    8.16 -
    8.17 -extern OSErr	CPSGetCurrentProcess( CPSProcessSerNum *psn);
    8.18 -extern OSErr 	CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
    8.19 -extern OSErr	CPSSetFrontProcess( CPSProcessSerNum *psn);
    8.20 -
    8.21 -#endif /* SDL_USE_CPS */
    8.22 -
    8.23  static int    gArgc;
    8.24  static char  **gArgv;
    8.25  static BOOL   gFinderLaunch;
    8.26 @@ -64,10 +48,10 @@
    8.27  @end
    8.28  #endif
    8.29  
    8.30 -@interface SDLApplication : NSApplication
    8.31 +@interface NSApplication (SDLApplication)
    8.32  @end
    8.33  
    8.34 -@implementation SDLApplication
    8.35 +@implementation NSApplication (SDLApplication)
    8.36  /* Invoked from the Quit menu item */
    8.37  - (void)terminate:(id)sender
    8.38  {
    8.39 @@ -119,7 +103,6 @@
    8.40          if ([menuItem hasSubmenu])
    8.41              [self fixMenu:[menuItem submenu] withAppName:appName];
    8.42      }
    8.43 -    [ aMenu sizeToFit ];
    8.44  }
    8.45  
    8.46  #else
    8.47 @@ -202,18 +185,7 @@
    8.48      SDLMain				*sdlMain;
    8.49  
    8.50      /* Ensure the application object is initialised */
    8.51 -    [SDLApplication sharedApplication];
    8.52 -    
    8.53 -#ifdef SDL_USE_CPS
    8.54 -    {
    8.55 -        CPSProcessSerNum PSN;
    8.56 -        /* Tell the dock about us */
    8.57 -        if (!CPSGetCurrentProcess(&PSN))
    8.58 -            if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
    8.59 -                if (!CPSSetFrontProcess(&PSN))
    8.60 -                    [SDLApplication sharedApplication];
    8.61 -    }
    8.62 -#endif /* SDL_USE_CPS */
    8.63 +    [[NSApplication sharedApplication] activateIgnoringOtherApps: YES];
    8.64  
    8.65      /* Set up the menubar */
    8.66      [NSApp setMainMenu:[[NSMenu alloc] init]];
    8.67 @@ -346,18 +318,38 @@
    8.68  @end
    8.69  
    8.70  
    8.71 -
    8.72  #ifdef main
    8.73  #  undef main
    8.74  #endif
    8.75  
    8.76  
    8.77 +static int IsRootCwd()
    8.78 +{
    8.79 +    char buf[MAXPATHLEN];
    8.80 +    char *cwd = getcwd(buf, sizeof (buf));
    8.81 +    return (cwd && (strcmp(cwd, "/") == 0));
    8.82 +}
    8.83 +
    8.84 +static int IsFinderLaunch(const int argc, char **argv)
    8.85 +{
    8.86 +    /* -psn_XXX is passed if we are launched from Finder, SOMETIMES */
    8.87 +    if ( (argc >= 2) && (strncmp(argv[1], "-psn", 4) == 0) ) {
    8.88 +        return 1;
    8.89 +    } else if ((argc == 1) && IsRootCwd()) {
    8.90 +        /* we might still be launched from the Finder; on 10.9+, you might not
    8.91 +        get the -psn command line anymore. If there's no
    8.92 +        command line, and if our current working directory is "/", it
    8.93 +        might as well be a Finder launch. */
    8.94 +        return 1;
    8.95 +    }
    8.96 +    return 0;  /* not a Finder launch. */
    8.97 +}
    8.98 +
    8.99  /* Main entry point to executable - should *not* be SDL_main! */
   8.100  int main (int argc, char **argv)
   8.101  {
   8.102      /* Copy the arguments into a global variable */
   8.103 -    /* This is passed if we are launched by double-clicking */
   8.104 -    if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
   8.105 +    if (IsFinderLaunch(argc, argv)) {
   8.106          gArgv = (char **) SDL_malloc(sizeof (char *) * 2);
   8.107          gArgv[0] = argv[0];
   8.108          gArgv[1] = NULL;
   8.109 @@ -373,7 +365,6 @@
   8.110      }
   8.111  
   8.112  #if SDL_USE_NIB_FILE
   8.113 -    [SDLApplication poseAsClass:[NSApplication class]];
   8.114      NSApplicationMain (argc, argv);
   8.115  #else
   8.116      CustomApplicationMain (argc, argv);
     9.1 --- a/Xcode/TemplatesForXcodeTiger/SDL OpenGL Application/SDLMain.m	Sat Jun 30 22:55:05 2018 +0300
     9.2 +++ b/Xcode/TemplatesForXcodeTiger/SDL OpenGL Application/SDLMain.m	Sat Jun 30 23:10:01 2018 +0300
     9.3 @@ -20,22 +20,6 @@
     9.4  /* Use this flag to determine whether we use SDLMain.nib or not */
     9.5  #define		SDL_USE_NIB_FILE	0
     9.6  
     9.7 -/* Use this flag to determine whether we use CPS (docking) or not */
     9.8 -#define		SDL_USE_CPS		1
     9.9 -#ifdef SDL_USE_CPS
    9.10 -/* Portions of CPS.h */
    9.11 -typedef struct CPSProcessSerNum
    9.12 -{
    9.13 -	UInt32		lo;
    9.14 -	UInt32		hi;
    9.15 -} CPSProcessSerNum;
    9.16 -
    9.17 -extern OSErr	CPSGetCurrentProcess( CPSProcessSerNum *psn);
    9.18 -extern OSErr 	CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
    9.19 -extern OSErr	CPSSetFrontProcess( CPSProcessSerNum *psn);
    9.20 -
    9.21 -#endif /* SDL_USE_CPS */
    9.22 -
    9.23  static int    gArgc;
    9.24  static char  **gArgv;
    9.25  static BOOL   gFinderLaunch;
    9.26 @@ -64,10 +48,10 @@
    9.27  @end
    9.28  #endif
    9.29  
    9.30 -@interface SDLApplication : NSApplication
    9.31 +@interface NSApplication (SDLApplication)
    9.32  @end
    9.33  
    9.34 -@implementation SDLApplication
    9.35 +@implementation NSApplication (SDLApplication)
    9.36  /* Invoked from the Quit menu item */
    9.37  - (void)terminate:(id)sender
    9.38  {
    9.39 @@ -119,7 +103,6 @@
    9.40          if ([menuItem hasSubmenu])
    9.41              [self fixMenu:[menuItem submenu] withAppName:appName];
    9.42      }
    9.43 -    [ aMenu sizeToFit ];
    9.44  }
    9.45  
    9.46  #else
    9.47 @@ -202,18 +185,7 @@
    9.48      SDLMain				*sdlMain;
    9.49  
    9.50      /* Ensure the application object is initialised */
    9.51 -    [SDLApplication sharedApplication];
    9.52 -    
    9.53 -#ifdef SDL_USE_CPS
    9.54 -    {
    9.55 -        CPSProcessSerNum PSN;
    9.56 -        /* Tell the dock about us */
    9.57 -        if (!CPSGetCurrentProcess(&PSN))
    9.58 -            if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
    9.59 -                if (!CPSSetFrontProcess(&PSN))
    9.60 -                    [SDLApplication sharedApplication];
    9.61 -    }
    9.62 -#endif /* SDL_USE_CPS */
    9.63 +    [[NSApplication sharedApplication] activateIgnoringOtherApps: YES];
    9.64  
    9.65      /* Set up the menubar */
    9.66      [NSApp setMainMenu:[[NSMenu alloc] init]];
    9.67 @@ -346,18 +318,38 @@
    9.68  @end
    9.69  
    9.70  
    9.71 -
    9.72  #ifdef main
    9.73  #  undef main
    9.74  #endif
    9.75  
    9.76  
    9.77 +static int IsRootCwd()
    9.78 +{
    9.79 +    char buf[MAXPATHLEN];
    9.80 +    char *cwd = getcwd(buf, sizeof (buf));
    9.81 +    return (cwd && (strcmp(cwd, "/") == 0));
    9.82 +}
    9.83 +
    9.84 +static int IsFinderLaunch(const int argc, char **argv)
    9.85 +{
    9.86 +    /* -psn_XXX is passed if we are launched from Finder, SOMETIMES */
    9.87 +    if ( (argc >= 2) && (strncmp(argv[1], "-psn", 4) == 0) ) {
    9.88 +        return 1;
    9.89 +    } else if ((argc == 1) && IsRootCwd()) {
    9.90 +        /* we might still be launched from the Finder; on 10.9+, you might not
    9.91 +        get the -psn command line anymore. If there's no
    9.92 +        command line, and if our current working directory is "/", it
    9.93 +        might as well be a Finder launch. */
    9.94 +        return 1;
    9.95 +    }
    9.96 +    return 0;  /* not a Finder launch. */
    9.97 +}
    9.98 +
    9.99  /* Main entry point to executable - should *not* be SDL_main! */
   9.100  int main (int argc, char **argv)
   9.101  {
   9.102      /* Copy the arguments into a global variable */
   9.103 -    /* This is passed if we are launched by double-clicking */
   9.104 -    if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
   9.105 +    if (IsFinderLaunch(argc, argv)) {
   9.106          gArgv = (char **) SDL_malloc(sizeof (char *) * 2);
   9.107          gArgv[0] = argv[0];
   9.108          gArgv[1] = NULL;
   9.109 @@ -373,7 +365,6 @@
   9.110      }
   9.111  
   9.112  #if SDL_USE_NIB_FILE
   9.113 -    [SDLApplication poseAsClass:[NSApplication class]];
   9.114      NSApplicationMain (argc, argv);
   9.115  #else
   9.116      CustomApplicationMain (argc, argv);