SDL: Bumped deployment requirements for Apple platforms

From cdde6dd7bb182a430f82c5e059122b350df7f1dd Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 14 Jan 2025 09:19:39 -0800
Subject: [PATCH] Bumped deployment requirements for Apple platforms

We require at least Xcode 12.2 and macOS SDK 11 to build. We support deploying to macOS 10.13, iOS 11.0, and tvOS 11.0.

This cleans up the code significantly
---
 .github/workflows/create-test-plan.py     |   8 +-
 .github/workflows/release.yml             |  12 +-
 Xcode/SDL/SDL.xcodeproj/project.pbxproj   |  12 +-
 docs/README-ios.md                        |   9 +-
 docs/README-macos.md                      |   9 +-
 src/SDL_internal.h                        |  11 +
 src/audio/coreaudio/SDL_coreaudio.m       |  35 +-
 src/dialog/cocoa/SDL_cocoadialog.m        |   6 +-
 src/gpu/metal/SDL_gpu_metal.m             |  24 +-
 src/hidapi/ios/hid.m                      |  12 +-
 src/joystick/apple/SDL_mfijoystick.m      | 444 +++++++---------------
 src/misc/ios/SDL_sysurl.m                 |   8 +-
 src/render/metal/SDL_render_metal.m       |  98 ++---
 src/video/cocoa/SDL_cocoaclipboard.m      |   4 -
 src/video/cocoa/SDL_cocoaevents.m         |   4 -
 src/video/cocoa/SDL_cocoamodes.m          |   8 -
 src/video/cocoa/SDL_cocoavideo.h          |  58 ---
 src/video/cocoa/SDL_cocoavideo.m          |   4 +-
 src/video/cocoa/SDL_cocoawindow.m         |  40 +-
 src/video/uikit/SDL_uikitappdelegate.m    |  22 --
 src/video/uikit/SDL_uikitevents.m         |  39 --
 src/video/uikit/SDL_uikitmodes.m          |   7 +-
 src/video/uikit/SDL_uikitpen.h            |   2 +-
 src/video/uikit/SDL_uikitpen.m            |   2 +-
 src/video/uikit/SDL_uikitvideo.m          |   9 +-
 src/video/uikit/SDL_uikitview.h           |   6 +-
 src/video/uikit/SDL_uikitview.m           |  68 +---
 src/video/uikit/SDL_uikitviewcontroller.m |  38 +-
 src/video/uikit/SDL_uikitwindow.m         |   8 +-
 29 files changed, 266 insertions(+), 741 deletions(-)

diff --git a/.github/workflows/create-test-plan.py b/.github/workflows/create-test-plan.py
index 3ae5cabfec78e..860355dbc4882 100755
--- a/.github/workflows/create-test-plan.py
+++ b/.github/workflows/create-test-plan.py
@@ -469,7 +469,7 @@ def spec_to_job(spec: JobSpec, key: str, trackmem_symbol_names: bool) -> JobDeta
                     job.cmake_arguments.extend([
                         "-DCMAKE_SYSTEM_NAME=iOS",
                         "-DCMAKE_OSX_ARCHITECTURES=\"arm64\"",
-                        "-DCMAKE_OSX_DEPLOYMENT_TARGET=9.0",
+                        "-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0",
                     ])
                 case SdlPlatform.Tvos:
                     if spec.xcode:
@@ -477,7 +477,7 @@ def spec_to_job(spec: JobSpec, key: str, trackmem_symbol_names: bool) -> JobDeta
                     job.cmake_arguments.extend([
                         "-DCMAKE_SYSTEM_NAME=tvOS",
                         "-DCMAKE_OSX_ARCHITECTURES=\"arm64\"",
-                        "-DCMAKE_OSX_DEPLOYMENT_TARGET=9.0",
+                        "-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0",
                     ])
         case SdlPlatform.MacOS:
             if spec.apple_framework:
@@ -486,7 +486,7 @@ def spec_to_job(spec: JobSpec, key: str, trackmem_symbol_names: bool) -> JobDeta
                 job.test_pkg_config = False
                 job.cmake_arguments.extend((
                     "'-DCMAKE_OSX_ARCHITECTURES=x86_64;arm64'",
-                    "-DCMAKE_OSX_DEPLOYMENT_TARGET=10.11",
+                    "-DCMAKE_OSX_DEPLOYMENT_TARGET=10.13",
                     "-DSDL_FRAMEWORK=ON",
                 ))
                 job.shared_lib = SharedLibType.FRAMEWORK
@@ -494,7 +494,7 @@ def spec_to_job(spec: JobSpec, key: str, trackmem_symbol_names: bool) -> JobDeta
                 job.clang_tidy = True
                 job.cmake_arguments.extend((
                     "-DCMAKE_OSX_ARCHITECTURES=arm64",
-                    "-DCMAKE_OSX_DEPLOYMENT_TARGET=10.11",
+                    "-DCMAKE_OSX_DEPLOYMENT_TARGET=10.13",
                     "-DCLANG_TIDY_BINARY=$(brew --prefix llvm)/bin/clang-tidy",
                 ))
                 job.shared_lib = SharedLibType.DYLIB
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 7b541fa789104..64199c7c6237b 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -163,7 +163,7 @@ jobs:
               -DCMAKE_PREFIX_PATH="${{ steps.mount.outputs.mount_point }}"  \
               -DCMAKE_SYSTEM_NAME=Darwin                                    \
               -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"                      \
-              -DCMAKE_OSX_DEPLOYMENT_TARGET=10.11                           \
+              -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13                           \
               -Werror=dev                                                   \
               -B build_darwin
           cmake --build build_darwin --config Release --verbose
@@ -175,7 +175,7 @@ jobs:
               -DCMAKE_PREFIX_PATH="${{ steps.mount.outputs.mount_point }}/SDL3.xcframework/macos-arm64_x86_64"  \
               -DCMAKE_SYSTEM_NAME=Darwin                                                                        \
               -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"                                                          \
-              -DCMAKE_OSX_DEPLOYMENT_TARGET=10.11                                                               \
+              -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13                                                               \
               -Werror=dev                                                                                       \
               -B build_darwin_2
           cmake --build build_darwin --config Release --verbose
@@ -188,7 +188,7 @@ jobs:
               -DCMAKE_PREFIX_PATH="${{ steps.mount.outputs.mount_point }}"  \
               -DCMAKE_SYSTEM_NAME=iOS                                       \
               -DCMAKE_OSX_ARCHITECTURES="arm64"                             \
-              -DCMAKE_OSX_DEPLOYMENT_TARGET=9.0                             \
+              -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0                             \
               -Werror=dev                                                   \
               -B build_ios
           cmake --build build_ios --config Release --verbose
@@ -201,7 +201,7 @@ jobs:
               -DCMAKE_PREFIX_PATH="${{ steps.mount.outputs.mount_point }}"  \
               -DCMAKE_SYSTEM_NAME=tvOS                                      \
               -DCMAKE_OSX_ARCHITECTURES="arm64"                             \
-              -DCMAKE_OSX_DEPLOYMENT_TARGET=9.0                             \
+              -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0                             \
               -Werror=dev                                                   \
               -B build_tvos
           cmake --build build_tvos --config Release --verbose
@@ -217,7 +217,7 @@ jobs:
               -DCMAKE_SYSTEM_NAME=iOS                                       \
               -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"                      \
               -DCMAKE_OSX_SYSROOT="${sysroot}"                              \
-              -DCMAKE_OSX_DEPLOYMENT_TARGET=9.0                             \
+              -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0                            \
               -Werror=dev                                                   \
               -B build_ios_simulator
           cmake --build build_ios_simulator --config Release --verbose
@@ -233,7 +233,7 @@ jobs:
               -DCMAKE_SYSTEM_NAME=tvOS                                      \
               -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"                      \
               -DCMAKE_OSX_SYSROOT="${sysroot}"                              \
-              -DCMAKE_OSX_DEPLOYMENT_TARGET=9.0                             \
+              -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0                            \
               -Werror=dev                                                   \
               -B build_tvos_simulator
           cmake --build build_tvos_simulator --config Release --verbose
diff --git a/Xcode/SDL/SDL.xcodeproj/project.pbxproj b/Xcode/SDL/SDL.xcodeproj/project.pbxproj
index bc8b15e01b77e..cd52392b6b388 100644
--- a/Xcode/SDL/SDL.xcodeproj/project.pbxproj
+++ b/Xcode/SDL/SDL.xcodeproj/project.pbxproj
@@ -3073,7 +3073,7 @@
 					/usr/X11R6/include,
 				);
 				INFOPLIST_FILE = "Info-Framework.plist";
-				IPHONEOS_DEPLOYMENT_TARGET = 9.0;
+				IPHONEOS_DEPLOYMENT_TARGET = 11.0;
 				LD_RUNPATH_SEARCH_PATHS = (
 					"$(inherited)",
 					"@executable_path/Frameworks",
@@ -3083,7 +3083,7 @@
 					"@executable_path/../Frameworks",
 					"@loader_path/Frameworks",
 				);
-				MACOSX_DEPLOYMENT_TARGET = 10.11;
+				MACOSX_DEPLOYMENT_TARGET = 10.13;
 				MARKETING_VERSION = 3.1.9;
 				OTHER_LDFLAGS = "$(CONFIG_FRAMEWORK_LDFLAGS)";
 				PRODUCT_BUNDLE_IDENTIFIER = org.libsdl.SDL3;
@@ -3091,7 +3091,7 @@
 				STRIP_STYLE = "non-global";
 				SUPPORTED_PLATFORMS = "xrsimulator xros macosx iphonesimulator iphoneos appletvsimulator appletvos";
 				SUPPORTS_MACCATALYST = YES;
-				TVOS_DEPLOYMENT_TARGET = 9.0;
+				TVOS_DEPLOYMENT_TARGET = 11.0;
 				XROS_DEPLOYMENT_TARGET = 1.0;
 			};
 			name = Release;
@@ -3134,7 +3134,7 @@
 					/usr/X11R6/include,
 				);
 				INFOPLIST_FILE = "Info-Framework.plist";
-				IPHONEOS_DEPLOYMENT_TARGET = 9.0;
+				IPHONEOS_DEPLOYMENT_TARGET = 11.0;
 				LD_RUNPATH_SEARCH_PATHS = (
 					"$(inherited)",
 					"@executable_path/Frameworks",
@@ -3144,7 +3144,7 @@
 					"@executable_path/../Frameworks",
 					"@loader_path/Frameworks",
 				);
-				MACOSX_DEPLOYMENT_TARGET = 10.11;
+				MACOSX_DEPLOYMENT_TARGET = 10.13;
 				MARKETING_VERSION = 3.1.9;
 				ONLY_ACTIVE_ARCH = YES;
 				OTHER_LDFLAGS = "$(CONFIG_FRAMEWORK_LDFLAGS)";
@@ -3153,7 +3153,7 @@
 				STRIP_INSTALLED_PRODUCT = NO;
 				SUPPORTED_PLATFORMS = "xrsimulator xros macosx iphonesimulator iphoneos appletvsimulator appletvos";
 				SUPPORTS_MACCATALYST = YES;
-				TVOS_DEPLOYMENT_TARGET = 9.0;
+				TVOS_DEPLOYMENT_TARGET = 11.0;
 				XROS_DEPLOYMENT_TARGET = 1.0;
 			};
 			name = Debug;
diff --git a/docs/README-ios.md b/docs/README-ios.md
index 51e1d76c996a8..dbd70f5a702f4 100644
--- a/docs/README-ios.md
+++ b/docs/README-ios.md
@@ -1,10 +1,10 @@
 iOS
 ======
 
-Building the Simple DirectMedia Layer for iOS 9.0+
+Building the Simple DirectMedia Layer for iOS 11.0+
 ==============================================================================
 
-Requirements: macOS 10.9 or later and the iOS 9.0 or newer SDK.
+Please note that building SDL requires at least Xcode 12.2 and the iOS 14.2 SDK.
 
 Instructions:
 
@@ -185,9 +185,6 @@ Windows:
 Textures:
 	The optimal texture formats on iOS are SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_XBGR8888, and SDL_PIXELFORMAT_RGB24 pixel formats.
 
-Loading Shared Objects:
-	This is disabled by default since it seems to break the terms of the iOS SDK agreement for iOS versions prior to iOS 8. It can be re-enabled in SDL_config_ios.h.
-
 
 Notes -- CoreBluetooth.framework
 ==============================================================================
@@ -249,7 +246,7 @@ Note that if you are using main callbacks instead of a standard C main() functio
 Deploying to older versions of iOS
 ==============================================================================
 
-SDL supports deploying to older versions of iOS than are supported by the latest version of Xcode, all the way back to iOS 8.0
+SDL supports deploying to older versions of iOS than are supported by the latest version of Xcode, all the way back to iOS 11.0
 
 In order to do that you need to download an older version of Xcode:
 https://developer.apple.com/download/more/?name=Xcode
diff --git a/docs/README-macos.md b/docs/README-macos.md
index d2f22c7f47c62..fb0639b66eda5 100644
--- a/docs/README-macos.md
+++ b/docs/README-macos.md
@@ -13,7 +13,7 @@ To build SDL using the command line, use the CMake build script:
 ```bash
 mkdir build
 cd build
-cmake .. -DCMAKE_OSX_DEPLOYMENT_TARGET=10.11
+cmake .. -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13
 cmake --build .
 sudo cmake --install .

@@ -25,15 +25,12 @@ You can also build SDL as a Universal library (a single binary for both

mkdir build
cd build
-cmake .. "-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64" -DCMAKE_OSX_DEPLOYMENT_TARGET=10.11
+cmake .. "-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64" -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13
cmake --build .
sudo cmake --install .

-Please note that building SDL requires at least Xcode 12.2 and the 11.0 SDK.
-PowerPC support for macOS has been officially dropped as of SDL 2.0.2.
-32-bit Intel and macOS 10.8 runtime support has been officially dropped as
-of SDL 2.24.0.
+Please note that building SDL requires at least Xcode 12.2 and the macOS 11.0 SDK.

To use the library once it’s built, you essential have two possibilities:
use the traditional autoconf/automake/make method, or use Xcode.
diff --git a/src/SDL_internal.h b/src/SDL_internal.h
index e3910cf500000…ac018f9b28abb 100644
— a/src/SDL_internal.h
+++ b/src/SDL_internal.h
@@ -78,7 +78,18 @@
#ifndef _DARWIN_C_SOURCE
#define _DARWIN_C_SOURCE 1 // for memset_pattern4()
#endif
+#include <Availability.h>
+
+#ifndef __IPHONE_OS_VERSION_MAX_ALLOWED
+#define __IPHONE_OS_VERSION_MAX_ALLOWED 0
+#endif
+#ifndef __APPLETV_OS_VERSION_MAX_ALLOWED
+#define __APPLETV_OS_VERSION_MAX_ALLOWED 0
+#endif
+#ifndef __MAC_OS_X_VERSION_MAX_ALLOWED
+#define __MAC_OS_X_VERSION_MAX_ALLOWED 0
#endif
+#endif // SDL_PLATFORM_APPLE

#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
diff --git a/src/audio/coreaudio/SDL_coreaudio.m b/src/audio/coreaudio/SDL_coreaudio.m
index 6760fdbd06ae0…d518d883cdf26 100644
— a/src/audio/coreaudio/SDL_coreaudio.m
+++ b/src/audio/coreaudio/SDL_coreaudio.m
@@ -467,31 +467,16 @@ static bool UpdateAudioSession(SDL_AudioDevice *device, bool open, bool allow_pl
options |= AVAudioSessionCategoryOptionDuckOthers;
}

  •    if ([session respondsToSelector:@selector(setCategory:mode:options:error:)]) {
    
  •        if (![session.category isEqualToString:category] || session.categoryOptions != options) {
    
  •            // Stop the current session so we don't interrupt other application audio
    
  •            PauseAudioDevices();
    
  •            [session setActive:NO error:nil];
    
  •            session_active = false;
    
  •            if (![session setCategory:category mode:mode options:options error:&err]) {
    
  •                NSString *desc = err.description;
    
  •                SDL_SetError("Could not set Audio Session category: %s", desc.UTF8String);
    
  •                return false;
    
  •            }
    
  •        }
    
  •    } else {
    
  •        if (![session.category isEqualToString:category]) {
    
  •            // Stop the current session so we don't interrupt other application audio
    
  •            PauseAudioDevices();
    
  •            [session setActive:NO error:nil];
    
  •            session_active = false;
    
  •            if (![session setCategory:category error:&err]) {
    
  •                NSString *desc = err.description;
    
  •                SDL_SetError("Could not set Audio Session category: %s", desc.UTF8String);
    
  •                return false;
    
  •            }
    
  •    if (![session.category isEqualToString:category] || session.categoryOptions != options) {
    
  •        // Stop the current session so we don't interrupt other application audio
    
  •        PauseAudioDevices();
    
  •        [session setActive:NO error:nil];
    
  •        session_active = false;
    
  •        if (![session setCategory:category mode:mode options:options error:&err]) {
    
  •            NSString *desc = err.description;
    
  •            SDL_SetError("Could not set Audio Session category: %s", desc.UTF8String);
    
  •            return false;
           }
       }
    

diff --git a/src/dialog/cocoa/SDL_cocoadialog.m b/src/dialog/cocoa/SDL_cocoadialog.m
index aac7fd02fd337…fb9c5ad88f77b 100644
— a/src/dialog/cocoa/SDL_cocoadialog.m
+++ b/src/dialog/cocoa/SDL_cocoadialog.m
@@ -146,8 +146,7 @@ void SDL_SYS_ShowFileDialogWithProperties(SDL_FileDialogType type, SDL_DialogFil
if (w) {
// [dialog beginWithCompletionHandler:^(NSInteger result) {
[dialog beginSheetModalForWindow:w completionHandler:^(NSInteger result) {

  •        // NSModalResponseOK for >= 10.13
    
  •        if (result == NSFileHandlingPanelOKButton) {
    
  •        if (result == NSModalResponseOK) {
               if (dialog_as_open) {
                   NSArray* urls = [dialog_as_open URLs];
                   const char *files[[urls count] + 1];
    

@@ -166,8 +165,7 @@ void SDL_SYS_ShowFileDialogWithProperties(SDL_FileDialogType type, SDL_DialogFil
}
}];
} else {

  •    // NSModalResponseOK for >= 10.10
    
  •    if ([dialog runModal] == NSOKButton) {
    
  •    if ([dialog runModal] == NSModalResponseOK) {
           if (dialog_as_open) {
               NSArray* urls = [dialog_as_open URLs];
               const char *files[[urls count] + 1];
    

diff --git a/src/gpu/metal/SDL_gpu_metal.m b/src/gpu/metal/SDL_gpu_metal.m
index 411a29b29a941…ac712d52fa90b 100644
— a/src/gpu/metal/SDL_gpu_metal.m
+++ b/src/gpu/metal/SDL_gpu_metal.m
@@ -386,11 +386,7 @@ static MTLTextureType SDLToMetal_TextureType(SDL_GPUTextureType textureType, boo
case SDL_GPU_TEXTURETYPE_CUBE:
return MTLTextureTypeCube;
case SDL_GPU_TEXTURETYPE_CUBE_ARRAY:

  •    if (@available(iOS 11.0, tvOS 11.0, *)) {
    
  •        return MTLTextureTypeCubeArray;
    
  •    } else {
    
  •        return MTLTextureType2D; // FIXME: I guess...?
    
  •    }
    
  •    return MTLTextureTypeCubeArray;
    
    default:
    return MTLTextureType2D;
    }
    @@ -1289,10 +1285,8 @@ static void METAL_InsertDebugLabel(
    [metalCommandBuffer->computeEncoder insertDebugSignpost:label];
    } else {
    // Metal doesn’t have insertDebugSignpost for command buffers…
  •        if (@available(macOS 10.13, iOS 11.0, tvOS 11.0, *)) {
    
  •            [metalCommandBuffer->handle pushDebugGroup:label];
    
  •            [metalCommandBuffer->handle popDebugGroup];
    
  •        }
    
  •        [metalCommandBuffer->handle pushDebugGroup:label];
    
  •        [metalCommandBuffer->handle popDebugGroup];
       }
    
    }
    }
    @@ -1312,9 +1306,7 @@ static void METAL_PushDebugGroup(
    } else if (metalCommandBuffer->computeEncoder) {
    [metalCommandBuffer->computeEncoder pushDebugGroup:label];
    } else {
  •        if (@available(macOS 10.13, iOS 11.0, tvOS 11.0, *)) {
    
  •            [metalCommandBuffer->handle pushDebugGroup:label];
    
  •        }
    
  •        [metalCommandBuffer->handle pushDebugGroup:label];
       }
    
    }
    }
    @@ -1332,9 +1324,7 @@ static void METAL_PopDebugGroup(
    } else if (metalCommandBuffer->computeEncoder) {
    [metalCommandBuffer->computeEncoder popDebugGroup];
    } else {
  •        if (@available(macOS 10.13, iOS 11.0, tvOS 11.0, *)) {
    
  •            [metalCommandBuffer->handle popDebugGroup];
    
  •        }
    
  •        [metalCommandBuffer->handle popDebugGroup];
       }
    
    }
    }
    @@ -2418,9 +2408,7 @@ static void METAL_BindGraphicsPipeline(
    [metalCommandBuffer->renderEncoder setTriangleFillMode:SDLToMetal_PolygonMode[metalGraphicsPipeline->rasterizerState.fill_mode]];
    [metalCommandBuffer->renderEncoder setCullMode:SDLToMetal_CullMode[metalGraphicsPipeline->rasterizerState.cull_mode]];
    [metalCommandBuffer->renderEncoder setFrontFacingWinding:SDLToMetal_FrontFace[metalGraphicsPipeline->rasterizerState.front_face]];
  •    if (@available(iOS 11.0, tvOS 11.0, *)) {
    
  •        [metalCommandBuffer->renderEncoder setDepthClipMode:SDLToMetal_DepthClipMode(metalGraphicsPipeline->rasterizerState.enable_depth_clip)];
    
  •    }
    
  •    [metalCommandBuffer->renderEncoder setDepthClipMode:SDLToMetal_DepthClipMode(metalGraphicsPipeline->rasterizerState.enable_depth_clip)];
       [metalCommandBuffer->renderEncoder
           setDepthBias:((rast->enable_depth_bias) ? rast->depth_bias_constant_factor : 0)
             slopeScale:((rast->enable_depth_bias) ? rast->depth_bias_slope_factor : 0)
    

diff --git a/src/hidapi/ios/hid.m b/src/hidapi/ios/hid.m
index b6f8037304cb7…29e0782094cfb 100644
— a/src/hidapi/ios/hid.m
+++ b/src/hidapi/ios/hid.m
@@ -398,7 +398,7 @@ - (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
switch ( central.state )
{

  •   case CBCentralManagerStatePoweredOn:
    
  •   case CBManagerStatePoweredOn:
      {
      	NSLog( @"CoreBluetooth BLE hardware is powered on and ready" );
    

@@ -418,23 +418,23 @@ - (void)centralManagerDidUpdateState:(CBCentralManager *)central
break;
}

  •   case CBCentralManagerStatePoweredOff:
    
  •   case CBManagerStatePoweredOff:
      	NSLog( @"CoreBluetooth BLE hardware is powered off" );
      	break;
    
  •   case CBCentralManagerStateUnauthorized:
    
  •   case CBManagerStateUnauthorized:
      	NSLog( @"CoreBluetooth BLE state is unauthorized" );
      	break;
    
  •   case CBCentralManagerStateUnknown:
    
  •   case CBManagerStateUnknown:
      	NSLog( @"CoreBluetooth BLE state is unknown" );
      	break;
    
  •   case CBCentralManagerStateUnsupported:
    
  •   case CBManagerStateUnsupported:
      	NSLog( @"CoreBluetooth BLE hardware is unsupported on this platform" );
      	break;
    
  •   case CBCentralManagerStateResetting:
    
  •   case CBManagerStateResetting:
      	NSLog( @"CoreBluetooth BLE manager is resetting" );
      	break;
    
    }
    diff --git a/src/joystick/apple/SDL_mfijoystick.m b/src/joystick/apple/SDL_mfijoystick.m
    index c1863830cd981…c224bb2f4f5f6 100644
    — a/src/joystick/apple/SDL_mfijoystick.m
    +++ b/src/joystick/apple/SDL_mfijoystick.m
    @@ -48,66 +48,18 @@
    static id connectObserver = nil;
    static id disconnectObserver = nil;

-#include <Availability.h>
#include <objc/message.h>

-#ifndef __IPHONE_OS_VERSION_MAX_ALLOWED
-#define __IPHONE_OS_VERSION_MAX_ALLOWED 0
-#endif

-#ifndef __APPLETV_OS_VERSION_MAX_ALLOWED
-#define __APPLETV_OS_VERSION_MAX_ALLOWED 0
-#endif

-#ifndef __MAC_OS_VERSION_MAX_ALLOWED
-#define __MAC_OS_VERSION_MAX_ALLOWED 0
-#endif

/* remove compilation warnings for strict builds by defining these selectors, even though

  • they are only ever used indirectly through objc_msgSend
    */
    @interface GCController (SDL)
    -#if defined(SDL_PLATFORM_MACOS) && (__MAC_OS_X_VERSION_MAX_ALLOWED <= 101600)
    -+ (BOOL)supportsHIDDevice:(IOHIDDeviceRef)device;
    -#endif
    -#if !((__IPHONE_OS_VERSION_MAX_ALLOWED >= 130000) || (__APPLETV_OS_VERSION_MAX_ALLOWED >= 130000) || (__MAC_OS_VERSION_MAX_ALLOWED >= 1500000))
    -@property(nonatomic, readonly) NSString *productCategory;
    -#endif
    #if !((__IPHONE_OS_VERSION_MAX_ALLOWED >= 140500) || (__APPLETV_OS_VERSION_MAX_ALLOWED >= 140500) || (__MAC_OS_X_VERSION_MAX_ALLOWED >= 110300))
    @property(class, nonatomic, readwrite) BOOL shouldMonitorBackgroundEvents;
    #endif
    @end
    -@interface GCExtendedGamepad (SDL)
    -#if !((__IPHONE_OS_VERSION_MAX_ALLOWED >= 121000) || (__APPLETV_OS_VERSION_MAX_ALLOWED >= 121000) || (__MAC_OS_VERSION_MAX_ALLOWED >= 1401000))
    -@property(nonatomic, readonly, nullable) GCControllerButtonInput *leftThumbstickButton;
    -@property(nonatomic, readonly, nullable) GCControllerButtonInput *rightThumbstickButton;
    -#endif
    -#if !((__IPHONE_OS_VERSION_MAX_ALLOWED >= 130000) || (__APPLETV_OS_VERSION_MAX_ALLOWED >= 130000) || (__MAC_OS_VERSION_MAX_ALLOWED >= 1500000))
    -@property(nonatomic, readonly) GCControllerButtonInput *buttonMenu;
    -@property(nonatomic, readonly, nullable) GCControllerButtonInput *buttonOptions;
    -#endif
    -#if !((__IPHONE_OS_VERSION_MAX_ALLOWED >= 140000) || (__APPLETV_OS_VERSION_MAX_ALLOWED >= 140000) || (__MAC_OS_VERSION_MAX_ALLOWED > 1500000))
    -@property(nonatomic, readonly, nullable) GCControllerButtonInput *buttonHome;
    -#endif
    -@end
    -@interface GCMicroGamepad (SDL)
    -#if !((__IPHONE_OS_VERSION_MAX_ALLOWED >= 130000) || (__APPLETV_OS_VERSION_MAX_ALLOWED >= 130000) || (__MAC_OS_VERSION_MAX_ALLOWED >= 1500000))
    -@property(nonatomic, readonly) GCControllerButtonInput *buttonMenu;
    -#endif
    -@end

-#if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 140000) || (__APPLETV_OS_VERSION_MAX_ALLOWED >= 140000) || (__MAC_OS_VERSION_MAX_ALLOWED > 1500000) || (__MAC_OS_X_VERSION_MAX_ALLOWED > 101600)
-#define ENABLE_MFI_BATTERY
-#define ENABLE_MFI_RUMBLE
-#define ENABLE_MFI_LIGHT
-#define ENABLE_MFI_SENSORS
-#define ENABLE_MFI_SYSTEM_GESTURE_STATE
-#define ENABLE_PHYSICAL_INPUT_PROFILE
-#endif

-#ifdef ENABLE_MFI_RUMBLE
#import <CoreHaptics/CoreHaptics.h>
-#endif

#endif // SDL_JOYSTICK_MFI

@@ -234,7 +186,6 @@ static void CheckControllerSiriRemote(GCController *controller, int *is_siri_rem
*is_siri_remote = 0;
}

-#ifdef ENABLE_PHYSICAL_INPUT_PROFILE
static bool ElementAlreadyHandled(SDL_JoystickDeviceItem *device, NSString *element, NSDictionary<NSString *, GCControllerElement *> *elements)
{
if ([element isEqualToString:@“Left Thumbstick Left”] ||
@@ -333,7 +284,6 @@ static bool ElementAlreadyHandled(SDL_JoystickDeviceItem *device, NSString *elem
}
return false;
}
-#endif // ENABLE_PHYSICAL_INPUT_PROFILE

static bool IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCController *controller)
{
@@ -366,7 +316,6 @@ static bool IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
NSLog(@“Product name: %@\n”, controller.vendorName);
NSLog(@“Product category: %@\n”, controller.productCategory);
NSLog(@“Elements available:\n”);
-#ifdef ENABLE_PHYSICAL_INPUT_PROFILE
if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
NSDictionary<NSString *, GCControllerElement *> *elements = controller.physicalInputProfile.elements;
for (id key in controller.physicalInputProfile.buttons) {
@@ -379,8 +328,7 @@ static bool IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
NSLog(@“\tHat: %@\n”, key);
}
}
-#endif
-#endif
+#endif // DEBUG_CONTROLLER_PROFILE

 device->is_xbox = IsControllerXbox(controller);
 device->is_ps4 = IsControllerPS4(controller);

@@ -416,7 +364,6 @@ static bool IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
return false;
}

-#ifdef ENABLE_PHYSICAL_INPUT_PROFILE
if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
if (controller.physicalInputProfile.buttons[GCInputDualShockTouchpadButton] != nil) {
device->has_dualshock_touchpad = TRUE;
@@ -428,7 +375,6 @@ static bool IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
device->has_xbox_share_button = TRUE;
}
}
-#endif // ENABLE_PHYSICAL_INPUT_PROFILE

 if (device->is_backbone_one) {
     vendor = USB_VENDOR_BACKBONE;

@@ -473,20 +419,14 @@ static bool IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
} else if (device->is_switch_joyconR) {
vendor = USB_VENDOR_NINTENDO;
product = USB_PRODUCT_NINTENDO_SWITCH_JOYCON_RIGHT;
-#ifdef ENABLE_PHYSICAL_INPUT_PROFILE
} else if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
vendor = USB_VENDOR_APPLE;
product = 4;
subtype = 4;
-#endif
} else if (controller.extendedGamepad) {
vendor = USB_VENDOR_APPLE;
product = 1;
subtype = 1;

  • } else if (controller.gamepad) {
  •    vendor = USB_VENDOR_APPLE;
    
  •    product = 2;
    
  •    subtype = 2;
    

#ifdef SDL_PLATFORM_TVOS
} else if (controller.microGamepad) {
vendor = USB_VENDOR_APPLE;
@@ -502,7 +442,6 @@ static bool IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
return false;
}

-#ifdef ENABLE_PHYSICAL_INPUT_PROFILE
if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
NSDictionary<NSString *, GCControllerElement *> *elements = controller.physicalInputProfile.elements;

@@ -558,9 +497,7 @@ static bool IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
device->pause_button_index = (int)[device->buttons indexOfObject:GCInputButtonMenu];
}
#endif

  • } else
    -#endif
  • if (controller.extendedGamepad) {
  • } else if (controller.extendedGamepad) {
    GCExtendedGamepad *gamepad = controller.extendedGamepad;
    int nbuttons = 0;
    BOOL has_direct_menu = FALSE;
    @@ -612,24 +549,6 @@ static bool IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
    device->naxes = 6; // 2 thumbsticks and 2 triggers
    device->nhats = 1; // d-pad
    device->nbuttons = nbuttons;
  • } else if (controller.gamepad) {
  •    int nbuttons = 0;
    
  •    // These buttons are part of the original MFi spec
    
  •    device->button_mask |= (1 << SDL_GAMEPAD_BUTTON_SOUTH);
    
  •    device->button_mask |= (1 << SDL_GAMEPAD_BUTTON_EAST);
    
  •    device->button_mask |= (1 << SDL_GAMEPAD_BUTTON_WEST);
    
  •    device->button_mask |= (1 << SDL_GAMEPAD_BUTTON_NORTH);
    
  •    device->button_mask |= (1 << SDL_GAMEPAD_BUTTON_LEFT_SHOULDER);
    
  •    device->button_mask |= (1 << SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER);
    
  •    device->button_mask |= (1 << SDL_GAMEPAD_BUTTON_START);
    
  •    nbuttons += 7;
    
  •    device->pause_button_index = (nbuttons - 1);
    
  •    device->naxes = 0; // no traditional analog inputs
    
  •    device->nhats = 1; // d-pad
    
  •    device->nbuttons = nbuttons;
    
    }
    #ifdef SDL_PLATFORM_TVOS
    else if (controller.microGamepad) {
    @@ -677,7 +596,7 @@ static bool IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle
    }
    #endif // SDL_JOYSTICK_MFI

-#if defined(SDL_JOYSTICK_MFI)
+#ifdef SDL_JOYSTICK_MFI
static void IOS_AddJoystickDevice(GCController *controller)
{
SDL_JoystickDeviceItem *device = deviceList;
@@ -975,7 +894,6 @@ static bool IOS_JoystickOpen(SDL_Joystick *joystick, int device_index)
};
}

-#ifdef ENABLE_MFI_SENSORS
if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
GCController *controller = joystick->hwdata->controller;
GCMotion *motion = controller.motion;
@@ -986,9 +904,7 @@ static bool IOS_JoystickOpen(SDL_Joystick *joystick, int device_index)
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, 0.0f);
}
}
-#endif // ENABLE_MFI_SENSORS

-#ifdef ENABLE_MFI_SYSTEM_GESTURE_STATE
if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
GCController *controller = joystick->hwdata->controller;
for (id key in controller.physicalInputProfile.buttons) {
@@ -998,17 +914,13 @@ static bool IOS_JoystickOpen(SDL_Joystick *joystick, int device_index)
}
}
}
-#endif // ENABLE_MFI_SYSTEM_GESTURE_STATE

     if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) {
         GCController *controller = device->controller;

-#ifdef ENABLE_MFI_LIGHT
if (controller.light) {
SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN, true);
}
-#endif

-#ifdef ENABLE_MFI_RUMBLE
if (controller.haptics) {
for (GCHapticsLocality locality in controller.haptics.supportedLocalities) {
if ([locality isEqualToString:GCHapticsLocalityHandles]) {
@@ -1018,7 +930,6 @@ static bool IOS_JoystickOpen(SDL_Joystick *joystick, int device_index)
}
}
}
-#endif
}
#endif // SDL_JOYSTICK_MFI
}
@@ -1064,7 +975,

(Patch may be truncated, please check the link at the top of this post.)