Support code for macOS binaries that statically linked against 1.2's SDLmain.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 14 Feb 2019 14:28:40 -0500
changeset 62a26906f18e84
parent 61 832594ced260
child 63 5f62918d2819
Support code for macOS binaries that statically linked against 1.2's SDLmain.
src/SDL12_compat.c
src/SDL12_compat_objc.m
     1.1 --- a/src/SDL12_compat.c	Wed Feb 13 20:56:19 2019 -0500
     1.2 +++ b/src/SDL12_compat.c	Thu Feb 14 14:28:40 2019 -0500
     1.3 @@ -719,6 +719,11 @@
     1.4      if (!LoadSDL20())
     1.5          return -1;
     1.6  
     1.7 +#ifdef __MACOSX__
     1.8 +    extern void sdl12_compat_macos_init(void);
     1.9 +    sdl12_compat_macos_init();
    1.10 +#endif
    1.11 +
    1.12      #define SETFLAG(flag) if (sdl12flags & SDL12_INIT_##flag) sdl20flags |= SDL_INIT_##flag
    1.13      SETFLAG(TIMER);
    1.14      SETFLAG(AUDIO);
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/SDL12_compat_objc.m	Thu Feb 14 14:28:40 2019 -0500
     2.3 @@ -0,0 +1,41 @@
     2.4 +/*
     2.5 +  Simple DirectMedia Layer
     2.6 +  Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
     2.7 +
     2.8 +  This software is provided 'as-is', without any express or implied
     2.9 +  warranty.  In no event will the authors be held liable for any damages
    2.10 +  arising from the use of this software.
    2.11 +
    2.12 +  Permission is granted to anyone to use this software for any purpose,
    2.13 +  including commercial applications, and to alter it and redistribute it
    2.14 +  freely, subject to the following restrictions:
    2.15 +
    2.16 +  1. The origin of this software must not be misrepresented; you must not
    2.17 +     claim that you wrote the original software. If you use this software
    2.18 +     in a product, an acknowledgment in the product documentation would be
    2.19 +     appreciated but is not required.
    2.20 +  2. Altered source versions must be plainly marked as such, and must not be
    2.21 +     misrepresented as being the original software.
    2.22 +  3. This notice may not be removed or altered from any source distribution.
    2.23 +*/
    2.24 +
    2.25 +/* This file contains some macOS-specific support code */
    2.26 +
    2.27 +#include "SDL.h"
    2.28 +
    2.29 +#ifdef __MACOSX__
    2.30 +#include <Cocoa/Cocoa.h>
    2.31 +
    2.32 +/* This has to be in a separate, Objective-C source file because it calls
    2.33 +   into Cocoa. The issue is that SDL 1.2 apps on macOS are statically linked
    2.34 +   with SDLmain, which does something mac-specific that conflicts with SDL2
    2.35 +   before the app's main() is even called, and we have to counteract that. */
    2.36 +
    2.37 +void sdl12_compat_macos_init(void)
    2.38 +{
    2.39 +    [[NSApp sharedApplication] setActivationPolicy:NSApplicationActivationPolicyRegular];
    2.40 +}
    2.41 +#endif
    2.42 +
    2.43 +/* vi: set ts=4 sw=4 expandtab: */
    2.44 +