SDL - add a new SDL_HINT_MAC_BACKGROUND_APP hint, when set or set to 1 don't force the app to be foreground
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index 3da3ec3..5484687 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -526,6 +526,14 @@ extern "C" {
#define SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES "SDL_VIDEO_MAC_FULLSCREEN_SPACES"
/**
+* \brief When set don't force the SDL app to become a foreground process
+*
+* This hint only applies to Mac OS X.
+*
+*/
+#define SDL_HINT_MAC_BACKGROUND_APP "SDL_MAC_BACKGROUND_APP"
+
+/**
* \brief Android APK expansion main file version. Should be a string number like "1", "2" etc.
*/
#define SDL_HINT_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION "SDL_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION"
diff --git a/src/video/cocoa/SDL_cocoaevents.m b/src/video/cocoa/SDL_cocoaevents.m
index 6305629..bf15e2a 100644
--- a/src/video/cocoa/SDL_cocoaevents.m
+++ b/src/video/cocoa/SDL_cocoaevents.m
@@ -26,6 +26,7 @@
#include "SDL_cocoavideo.h"
#include "../../events/SDL_events_c.h"
#include "SDL_assert.h"
+#include "SDL_hints.h"
/* This define was added in the 10.9 SDK. */
#ifndef kIOPMAssertPreventUserIdleDisplaySleep
@@ -318,19 +319,21 @@ Cocoa_RegisterApp(void)
[SDLApplication sharedApplication];
SDL_assert(NSApp != nil);
+ const char *hint = SDL_GetHint(SDL_HINT_MAC_BACKGROUND_APP);
+ if (!hint && *hint != '0') {
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6
- if ([NSApp respondsToSelector:@selector(setActivationPolicy:)]) {
+ if ([NSApp respondsToSelector:@selector(setActivationPolicy:)]) {
#endif
- [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
+ [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6
- } else {
- ProcessSerialNumber psn = {0, kCurrentProcess};
- TransformProcessType(&psn, kProcessTransformToForegroundApplication);
- }
+ } else {
+ ProcessSerialNumber psn = {0, kCurrentProcess};
+ TransformProcessType(&psn, kProcessTransformToForegroundApplication);
+ }
#endif
-
- [NSApp activateIgnoringOtherApps:YES];
-
+ [NSApp activateIgnoringOtherApps:YES];
+ }
+
if ([NSApp mainMenu] == nil) {
CreateApplicationMenus();
}