SDL: Send absolute mouse motion when in normal mouse mode and relative mouse motion when in relative mode on iOS

From 27ce91446327c796a3a2dc477d893880d58f4a99 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 9 Nov 2021 20:51:42 -0800
Subject: [PATCH] Send absolute mouse motion when in normal mouse mode and
 relative mouse motion when in relative mode on iOS

This keeps the SDL cursor in sync with the visible cursor when in normal mouse mode.
---
 src/video/uikit/SDL_uikitevents.m | 4 +++-
 src/video/uikit/SDL_uikitview.m   | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/video/uikit/SDL_uikitevents.m b/src/video/uikit/SDL_uikitevents.m
index 82fde8889e..4169c9b205 100644
--- a/src/video/uikit/SDL_uikitevents.m
+++ b/src/video/uikit/SDL_uikitevents.m
@@ -234,7 +234,9 @@ static void OnGCMouseConnected(GCMouse *mouse) API_AVAILABLE(macos(11.0), ios(14
 
     mouse.mouseInput.mouseMovedHandler = ^(GCMouseInput *mouse, float deltaX, float deltaY)
     {
-        SDL_SendMouseMotion(SDL_GetMouseFocus(), mouseID, SDL_TRUE, (int)deltaX, -(int)deltaY);
+        if (SDL_GCMouseRelativeMode()) {
+            SDL_SendMouseMotion(SDL_GetMouseFocus(), mouseID, 1, (int)deltaX, -(int)deltaY);
+        }
     };
 
     dispatch_queue_t queue = dispatch_queue_create( "org.libsdl.input.mouse", DISPATCH_QUEUE_SERIAL );
diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m
index 58815a4d05..0bc5676d13 100644
--- a/src/video/uikit/SDL_uikitview.m
+++ b/src/video/uikit/SDL_uikitview.m
@@ -160,7 +160,7 @@ - (void)setSDLWindow:(SDL_Window *)window
 
 #if !TARGET_OS_TV && defined(__IPHONE_13_4)
 - (UIPointerRegion *)pointerInteraction:(UIPointerInteraction *)interaction regionForRequest:(UIPointerRegionRequest *)request defaultRegion:(UIPointerRegion *)defaultRegion API_AVAILABLE(ios(13.4)){
-    if (request != nil && !SDL_HasGCMouse()) {
+    if (request != nil && (!SDL_HasGCMouse() || !SDL_GCMouseRelativeMode())) {
         CGPoint origin = self.bounds.origin;
         CGPoint point = request.location;