SDL: uikit: Patched to compile, added to Xcode project.

From f6143da617ad7c8e31c4de9e855a605b5890c0e0 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Fri, 27 Dec 2024 15:12:28 -0500
Subject: [PATCH] uikit: Patched to compile, added to Xcode project.

---
 Xcode/SDL/SDL.xcodeproj/project.pbxproj |  7 +++
 src/video/uikit/SDL_uikitview.h         |  6 +--
 src/video/uikit/SDL_uikitview.m         | 62 +++++++++++++------------
 3 files changed, 43 insertions(+), 32 deletions(-)

diff --git a/Xcode/SDL/SDL.xcodeproj/project.pbxproj b/Xcode/SDL/SDL.xcodeproj/project.pbxproj
index 93f7e26d00667..7dcccde39c922 100644
--- a/Xcode/SDL/SDL.xcodeproj/project.pbxproj
+++ b/Xcode/SDL/SDL.xcodeproj/project.pbxproj
@@ -530,6 +530,8 @@
 		F3FD042E2C9B755700824C4C /* SDL_hidapi_nintendo.h in Headers */ = {isa = PBXBuildFile; fileRef = F3FD042C2C9B755700824C4C /* SDL_hidapi_nintendo.h */; };
 		F3FD042F2C9B755700824C4C /* SDL_hidapi_steam_hori.c in Sources */ = {isa = PBXBuildFile; fileRef = F3FD042D2C9B755700824C4C /* SDL_hidapi_steam_hori.c */; };
 		FA73671D19A540EF004122E4 /* CoreVideo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA73671C19A540EF004122E4 /* CoreVideo.framework */; platformFilters = (ios, maccatalyst, macos, tvos, watchos, ); };
+		000012E88BE7D71B274A0000 /* SDL_uikitpen.h in Headers */ = {isa = PBXBuildFile; fileRef = 000063D3D80F97ADC7770000 /* SDL_uikitpen.h */; };
+		0000A877C7DB9FA935FC0000 /* SDL_uikitpen.m in Sources */ = {isa = PBXBuildFile; fileRef = 000053D344416737F6050000 /* SDL_uikitpen.m */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
@@ -1092,6 +1094,8 @@
 		F59C710600D5CB5801000001 /* SDL.info */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = SDL.info; sourceTree = "<group>"; };
 		F5A2EF3900C6A39A01000001 /* BUGS.txt */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; name = BUGS.txt; path = ../../BUGS.txt; sourceTree = SOURCE_ROOT; };
 		FA73671C19A540EF004122E4 /* CoreVideo.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreVideo.framework; path = System/Library/Frameworks/CoreVideo.framework; sourceTree = SDKROOT; };
+		000063D3D80F97ADC7770000 /* SDL_uikitpen.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_uikitpen.h; path = SDL_uikitpen.h; sourceTree = "<group>"; };
+		000053D344416737F6050000 /* SDL_uikitpen.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDL_uikitpen.m; path = SDL_uikitpen.m; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -1682,6 +1686,8 @@
 				A7D8A62523E2513D00DCD162 /* SDL_uikitvulkan.m */,
 				A7D8A62723E2513D00DCD162 /* SDL_uikitwindow.h */,
 				A7D8A61A23E2513D00DCD162 /* SDL_uikitwindow.m */,
+				000063D3D80F97ADC7770000 /* SDL_uikitpen.h */,
+				000053D344416737F6050000 /* SDL_uikitpen.m */,
 			);
 			path = uikit;
 			sourceTree = "<group>";
@@ -3020,6 +3026,7 @@
 				0000AEB9AE90228CA2D60000 /* SDL_asyncio.c in Sources */,
 				00004D0B73767647AD550000 /* SDL_asyncio_generic.c in Sources */,
 				0000A03C0F32C43816F40000 /* SDL_asyncio_windows_ioring.c in Sources */,
+				0000A877C7DB9FA935FC0000 /* SDL_uikitpen.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
diff --git a/src/video/uikit/SDL_uikitview.h b/src/video/uikit/SDL_uikitview.h
index 5d2121428712c..2b8ed9dad255b 100644
--- a/src/video/uikit/SDL_uikitview.h
+++ b/src/video/uikit/SDL_uikitview.h
@@ -34,16 +34,16 @@
 - (void)setSDLWindow:(SDL_Window *)window;
 - (SDL_Window *)getSDLWindow;
 
+#if !defined(SDL_PLATFORM_TVOS)
 #if defined(__IPHONE_13_0)
 - (void)pencilHovering:(UIHoverGestureRecognizer *)recognizer API_AVAILABLE(ios(13.0));
 #endif
 
-#if !defined(SDL_PLATFORM_TVOS) && defined(__IPHONE_13_4)
+#if defined(__IPHONE_13_4)
 - (UIPointerRegion *)pointerInteraction:(UIPointerInteraction *)interaction regionForRequest:(UIPointerRegionRequest *)request defaultRegion:(UIPointerRegion *)defaultRegion API_AVAILABLE(ios(13.4));
 - (UIPointerStyle *)pointerInteraction:(UIPointerInteraction *)interaction styleForRegion:(UIPointerRegion *)region API_AVAILABLE(ios(13.4));
 - (void)indirectPointerHovering:(UIHoverGestureRecognizer *)recognizer API_AVAILABLE(ios(13.4));
-- (void)updateIndirectPointerFromTouch:(UITouch *)touch;
-- (void)updateIndirectPointerButtonState:(UITouch *)touch fromEvent:(UIEvent *)event;
+#endif
 #endif
 
 - (CGPoint)touchLocation:(UITouch *)touch shouldNormalize:(BOOL)normalize;
diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m
index 99ebc774d63f0..b5629517ea711 100644
--- a/src/video/uikit/SDL_uikitview.m
+++ b/src/video/uikit/SDL_uikitview.m
@@ -49,7 +49,7 @@ @implementation SDL_uikitview
     SDL_TouchID directTouchId;
     SDL_TouchID indirectTouchId;
 
-#if defined(__IPHONE_13_4)
+#if !defined(SDL_PLATFORM_TVOS) && defined(__IPHONE_13_4)
     UIPointerInteraction *indirectPointerInteraction API_AVAILABLE(ios(13.4));
 #endif
 }
@@ -85,8 +85,7 @@ - (instancetype)initWithFrame:(CGRect)frame
 #ifndef SDL_PLATFORM_TVOS
         self.multipleTouchEnabled = YES;
         SDL_AddTouch(directTouchId, SDL_TOUCH_DEVICE_DIRECT, "");
-#endif
-        
+
 #if defined(__IPHONE_13_0)
         if (@available(iOS 13.0, *)) {
             UIHoverGestureRecognizer *pencilRecognizer = [[UIHoverGestureRecognizer alloc] initWithTarget:self action:@selector(pencilHovering:)];
@@ -95,7 +94,7 @@ - (instancetype)initWithFrame:(CGRect)frame
         }
 #endif
 
-#if !defined(SDL_PLATFORM_TVOS) && defined(__IPHONE_13_4)
+#if defined(__IPHONE_13_4)
         if (@available(iOS 13.4, *)) {
             indirectPointerInteraction = [[UIPointerInteraction alloc] initWithDelegate:self];
             [self addInteraction:indirectPointerInteraction];
@@ -105,6 +104,7 @@ - (instancetype)initWithFrame:(CGRect)frame
             [self addGestureRecognizer:indirectPointerRecognizer];
         }
 #endif
+#endif // !defined(SDL_PLATFORM_TVOS)
     }
 
     return self;
@@ -171,7 +171,9 @@ - (SDL_Window *)getSDLWindow
     return sdlwindow;
 }
 
-#if !defined(SDL_PLATFORM_TVOS) && defined(__IPHONE_13_4)
+#if !defined(SDL_PLATFORM_TVOS)
+
+#if defined(__IPHONE_13_4)
 - (UIPointerRegion *)pointerInteraction:(UIPointerInteraction *)interaction regionForRequest:(UIPointerRegionRequest *)request defaultRegion:(UIPointerRegion *)defaultRegion API_AVAILABLE(ios(13.4))
 {
     return [UIPointerRegion regionWithRect:self.bounds identifier:nil];
@@ -251,7 +253,7 @@ - (void)indirectPointerReleased:(UITouch *)touch fromEvent:(UIEvent *)event API_
     }
 }
 
-#endif // !defined(SDL_PLATFORM_TVOS) && __IPHONE_13_4
+#endif // __IPHONE_13_4
 
 #if defined(__IPHONE_13_0)
 
@@ -293,6 +295,7 @@ - (void)pencilReleased:(UITouch *)touch
 }
 
 #endif // defined(__IPHONE_13_0)
+#endif // !defined(SDL_PLATFORM_TVOS)
 
 - (SDL_TouchDeviceType)touchTypeForTouch:(UITouch *)touch
 {
@@ -345,8 +348,7 @@ - (float)pressureForTouch:(UITouch *)touch
 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
 {
     for (UITouch *touch in touches) {
-        BOOL handled = NO;
-
+#if !defined(SDL_PLATFORM_TVOS)
 #if defined(__IPHONE_13_0)
         if (@available(iOS 13.0, *)) {
             if (touch.type == UITouchTypePencil) {
@@ -356,38 +358,37 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
         }
 #endif
         
-#if !defined(SDL_PLATFORM_TVOS) && defined(__IPHONE_13_4)
+#if defined(__IPHONE_13_4)
         if (@available(iOS 13.4, *)) {
             if (touch.type == UITouchTypeIndirectPointer) {
                 [self indirectPointerPressed:touch fromEvent:event];
-                handled = YES;
+                continue;
             }
         }
 #endif
-        if (!handled) {
-            SDL_TouchDeviceType touchType = [self touchTypeForTouch:touch];
-            SDL_TouchID touchId = [self touchIdForType:touchType];
-            float pressure = [self pressureForTouch:touch];
+#endif // !defined(SDL_PLATFORM_TVOS)
 
-            if (SDL_AddTouch(touchId, touchType, "") < 0) {
-                continue;
-            }
-
-            // FIXME, need to send: int clicks = (int) touch.tapCount; ?
+        SDL_TouchDeviceType touchType = [self touchTypeForTouch:touch];
+        SDL_TouchID touchId = [self touchIdForType:touchType];
+        float pressure = [self pressureForTouch:touch];
 
-            CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
-            SDL_SendTouch(UIKit_GetEventTimestamp([event timestamp]),
-                          touchId, (SDL_FingerID)(uintptr_t)touch, sdlwindow,
-                          true, locationInView.x, locationInView.y, pressure);
+        if (SDL_AddTouch(touchId, touchType, "") < 0) {
+            continue;
         }
+
+        // FIXME, need to send: int clicks = (int) touch.tapCount; ?
+
+        CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
+        SDL_SendTouch(UIKit_GetEventTimestamp([event timestamp]),
+                      touchId, (SDL_FingerID)(uintptr_t)touch, sdlwindow,
+                      true, locationInView.x, locationInView.y, pressure);
     }
 }
 
 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
 {
     for (UITouch *touch in touches) {
-        BOOL handled = NO;
-        
+#if !defined(SDL_PLATFORM_TVOS)
 #if defined(__IPHONE_13_0)
         if (@available(iOS 13.0, *)) {
             if (touch.type == UITouchTypePencil) {
@@ -397,7 +398,7 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
         }
 #endif
         
-#if !defined(SDL_PLATFORM_TVOS) && defined(__IPHONE_13_4)
+#if defined(__IPHONE_13_4)
         if (@available(iOS 13.4, *)) {
             if (touch.type == UITouchTypeIndirectPointer) {
                 [self indirectPointerReleased:touch fromEvent:event];
@@ -405,6 +406,8 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
             }
         }
 #endif
+#endif // !defined(SDL_PLATFORM_TVOS)
+
         SDL_TouchDeviceType touchType = [self touchTypeForTouch:touch];
         SDL_TouchID touchId = [self touchIdForType:touchType];
         float pressure = [self pressureForTouch:touch];
@@ -430,8 +433,7 @@ - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
 {
     for (UITouch *touch in touches) {
-        BOOL handled = NO;
-        
+#if !defined(SDL_PLATFORM_TVOS)
 #if defined(__IPHONE_13_0)
         if (@available(iOS 13.0, *)) {
             if (touch.type == UITouchTypePencil) {
@@ -441,7 +443,7 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
         }
 #endif
 
-#if !defined(SDL_PLATFORM_TVOS) && defined(__IPHONE_13_4)
+#if defined(__IPHONE_13_4)
         if (@available(iOS 13.4, *)) {
             if (touch.type == UITouchTypeIndirectPointer) {
                 [self indirectPointerMoving:touch];
@@ -449,6 +451,8 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
             }
         }
 #endif
+#endif  // !defined(SDL_PLATFORM_TVOS)
+
         SDL_TouchDeviceType touchType = [self touchTypeForTouch:touch];
         SDL_TouchID touchId = [self touchIdForType:touchType];
         float pressure = [self pressureForTouch:touch];