Xcode/TemplatesForXcodeSnowLeopard/SDL OpenGL Application/SDLMain.m
branchSDL-1.2
changeset 12048 eb70ab731d29
parent 5895 402eac854030
child 13239 f5a0937d2b04
     1.1 --- a/Xcode/TemplatesForXcodeSnowLeopard/SDL OpenGL Application/SDLMain.m	Sat Jun 30 22:55:05 2018 +0300
     1.2 +++ b/Xcode/TemplatesForXcodeSnowLeopard/SDL OpenGL 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);