Skip to content

Commit

Permalink
Update SDLmain.m to latest SDL
Browse files Browse the repository at this point in the history
  • Loading branch information
SupSuper committed Aug 9, 2018
1 parent 26eb201 commit b1b880f
Showing 1 changed file with 25 additions and 32 deletions.
57 changes: 25 additions & 32 deletions src/apple/SDLMain.m
Expand Up @@ -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;
Expand All @@ -47,7 +31,7 @@ - (void)setAppleMenu:(NSMenu *)menu;
NSString *appName = 0;

/* Determine the application name */
dict = (const NSDictionary *)CFBridgingRelease(CFBundleGetInfoDictionary(CFBundleGetMainBundle()));
dict = (const NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
if (dict)
appName = [dict objectForKey: @"CFBundleName"];

Expand Down Expand Up @@ -203,18 +187,7 @@ static void CustomApplicationMain (int argc, char **argv)
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 */
[[NSApplication sharedApplication] activateIgnoringOtherApps: YES];

/* Set up the menubar */
[NSApp setMainMenu:[[NSMenu alloc] init]];
Expand Down Expand Up @@ -347,18 +320,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;
Expand Down

0 comments on commit b1b880f

Please sign in to comment.