SDL: Allow reading background events for MFi controllers

From 6a787619e6ffbf79d9c549d03633ef80ea9aab1c Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 8 Mar 2022 18:42:13 -0800
Subject: [PATCH] Allow reading background events for MFi controllers

---
 src/joystick/iphoneos/SDL_mfijoystick.m | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/joystick/iphoneos/SDL_mfijoystick.m b/src/joystick/iphoneos/SDL_mfijoystick.m
index 0f8148029c6..c75fbbae2c5 100644
--- a/src/joystick/iphoneos/SDL_mfijoystick.m
+++ b/src/joystick/iphoneos/SDL_mfijoystick.m
@@ -69,6 +69,9 @@ + (BOOL)supportsHIDDevice:(IOHIDDeviceRef)device;
 #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))
@@ -572,6 +575,10 @@ static int is_macos11(void)
             return 0;
         }
 
+        if (@available(macOS 11.3, iOS 14.5, tvOS 14.5, *)) {
+            GCController.shouldMonitorBackgroundEvents = YES;
+        }
+
         /* For whatever reason, this always returns an empty array on
          macOS 11.0.1 */
         for (GCController *controller in [GCController controllers]) {