SDL: Merge commit '413500ab69d9ac288a73946073d4414376ca17d2' into main

From 413500ab69d9ac288a73946073d4414376ca17d2 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 22 Oct 2022 09:37:34 -0700
Subject: [PATCH] Replaced mouseWheelGesture with GCMouse support on iOS
 (thanks @russelltg!)

Fixes https://github.com/libsdl-org/SDL/issues/6411
---
 src/video/uikit/SDL_uikitevents.m |  5 ++++
 src/video/uikit/SDL_uikitview.m   | 44 -------------------------------
 2 files changed, 5 insertions(+), 44 deletions(-)

diff --git a/src/video/uikit/SDL_uikitevents.m b/src/video/uikit/SDL_uikitevents.m
index 61c57b2539c3..e1bc5a29e67b 100644
--- a/src/video/uikit/SDL_uikitevents.m
+++ b/src/video/uikit/SDL_uikitevents.m
@@ -315,6 +315,11 @@ static void OnGCMouseConnected(GCMouse *mouse) API_AVAILABLE(macos(11.0), ios(14
         }
     };
 
+    mouse.mouseInput.scroll.valueChangedHandler = ^(GCControllerDirectionPad *dpad, float xValue, float yValue)
+    {
+        SDL_SendMouseWheel(SDL_GetMouseFocus(), 0, xValue, yValue, SDL_MOUSEWHEEL_NORMAL);
+    };
+
     dispatch_queue_t queue = dispatch_queue_create( "org.libsdl.input.mouse", DISPATCH_QUEUE_SERIAL );
     dispatch_set_target_queue( queue, dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_HIGH, 0 ) );
     mouse.handlerQueue = queue;
diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m
index fea10ff21355..8c48cfa503b9 100644
--- a/src/video/uikit/SDL_uikitview.m
+++ b/src/video/uikit/SDL_uikitview.m
@@ -69,16 +69,6 @@ - (instancetype)initWithFrame:(CGRect)frame
         UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
         swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
         [self addGestureRecognizer:swipeRight];
-#elif defined(__IPHONE_13_4)
-        if (@available(iOS 13.4, *)) {
-            UIPanGestureRecognizer *mouseWheelRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(mouseWheelGesture:)];
-            mouseWheelRecognizer.allowedScrollTypesMask = UIScrollTypeMaskDiscrete;
-            mouseWheelRecognizer.allowedTouchTypes = @[ @(UITouchTypeIndirectPointer) ];
-            mouseWheelRecognizer.cancelsTouchesInView = NO;
-            mouseWheelRecognizer.delaysTouchesBegan = NO;
-            mouseWheelRecognizer.delaysTouchesEnded = NO;
-            [self addGestureRecognizer:mouseWheelRecognizer];
-        }
 #endif
 
         self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
@@ -455,40 +445,6 @@ - (void)pressesChanged:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)e
 
 #endif /* TARGET_OS_TV || defined(__IPHONE_9_1) */
 
-static CGPoint translation_old = (CGPoint){ 0.0, 0.0 };
-
--(void)mouseWheelGesture:(UIPanGestureRecognizer *)gesture
-{
-    if (gesture.state == UIGestureRecognizerStateBegan ||
-        gesture.state == UIGestureRecognizerStateChanged) {
-
-        CGPoint translation = [gesture translationInView:self];
-        CGPoint mouse_wheel = translation;
-
-        if (gesture.state == UIGestureRecognizerStateChanged) {
-            mouse_wheel.x -= translation_old.x;
-            mouse_wheel.y -= translation_old.y;
-        }
-
-        translation_old = translation;
-
-        if (mouse_wheel.x > 0.0f) {
-            mouse_wheel.x = 1.0;
-        } else if (mouse_wheel.x < 0.0f) {
-            mouse_wheel.x = -1.0f;
-        }
-        if (mouse_wheel.y > 0.0f) {
-            mouse_wheel.y = 1.0;
-        } else if (mouse_wheel.y < 0.0f) {
-            mouse_wheel.y = -1.0f;
-        }
-
-        if (mouse_wheel.x != 0.0f || mouse_wheel.y != 0.0f) {
-            SDL_SendMouseWheel(sdlwindow, 0, mouse_wheel.x, mouse_wheel.y, SDL_MOUSEWHEEL_NORMAL);
-        }
-    }
-}
-
 #if TARGET_OS_TV
 -(void)swipeGesture:(UISwipeGestureRecognizer *)gesture
 {