From 11ae43ca167476070225d493a642fe6e5bbb96da Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 11 Nov 2021 07:49:38 -0800 Subject: [PATCH] Only lock the pointer for mouse relative mode, there isn't really a concept of grab and confinement on iOS Locking the pointer prevents the on-screen cursor from moving, which isn't what we want with a grab behavior. Fixes https://github.com/libsdl-org/SDL/issues/4941 --- src/video/uikit/SDL_uikitevents.m | 13 +++++++------ src/video/uikit/SDL_uikitview.m | 2 +- src/video/uikit/SDL_uikitviewcontroller.m | 9 +-------- src/video/uikit/SDL_uikitwindow.h | 1 + src/video/uikit/SDL_uikitwindow.m | 6 ++++++ 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/video/uikit/SDL_uikitevents.m b/src/video/uikit/SDL_uikitevents.m index 4169c9b20..e5615fa32 100644 --- a/src/video/uikit/SDL_uikitevents.m +++ b/src/video/uikit/SDL_uikitevents.m @@ -24,9 +24,10 @@ #include "../../events/SDL_events_c.h" -#include "SDL_uikitvideo.h" #include "SDL_uikitevents.h" #include "SDL_uikitopengles.h" +#include "SDL_uikitvideo.h" +#include "SDL_uikitwindow.h" #import @@ -184,20 +185,20 @@ static id mouse_connect_observer = nil; static id mouse_disconnect_observer = nil; static bool mouse_relative_mode = SDL_FALSE; -static void UpdateMouseGrab() +static void UpdatePointerLock() { SDL_VideoDevice *_this = SDL_GetVideoDevice(); SDL_Window *window; for (window = _this->windows; window != NULL; window = window->next) { - SDL_UpdateWindowGrab(window); + UIKit_UpdatePointerLock(_this, window); } } static int SetGCMouseRelativeMode(SDL_bool enabled) { mouse_relative_mode = enabled; - UpdateMouseGrab(); + UpdatePointerLock(); return 0; } @@ -245,7 +246,7 @@ static void OnGCMouseConnected(GCMouse *mouse) API_AVAILABLE(macos(11.0), ios(14 ++mice_connected; - UpdateMouseGrab(); + UpdatePointerLock(); } static void OnGCMouseDisconnected(GCMouse *mouse) API_AVAILABLE(macos(11.0), ios(14.0), tvos(14.0)) @@ -262,7 +263,7 @@ static void OnGCMouseDisconnected(GCMouse *mouse) API_AVAILABLE(macos(11.0), ios button.pressedChangedHandler = nil; } - UpdateMouseGrab(); + UpdatePointerLock(); } void SDL_InitGCMouse(void) diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m index 0bc5676d1..bd54ad6d0 100644 --- a/src/video/uikit/SDL_uikitview.m +++ b/src/video/uikit/SDL_uikitview.m @@ -160,7 +160,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick; #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() || !SDL_GCMouseRelativeMode())) { + if (request != nil && !SDL_GCMouseRelativeMode()) { CGPoint origin = self.bounds.origin; CGPoint point = request.location; diff --git a/src/video/uikit/SDL_uikitviewcontroller.m b/src/video/uikit/SDL_uikitviewcontroller.m index c51d1aed2..b2db4037d 100644 --- a/src/video/uikit/SDL_uikitviewcontroller.m +++ b/src/video/uikit/SDL_uikitviewcontroller.m @@ -250,14 +250,7 @@ SDL_HideHomeIndicatorHintChanged(void *userdata, const char *name, const char *o - (BOOL)prefersPointerLocked { - SDL_VideoDevice *_this = SDL_GetVideoDevice(); - - if (SDL_HasGCMouse() && - (SDL_GCMouseRelativeMode() || _this->grabbed_window == window)) { - return YES; - } else { - return NO; - } + return SDL_GCMouseRelativeMode() ? YES : NO; } #endif /* !TARGET_OS_TV */ diff --git a/src/video/uikit/SDL_uikitwindow.h b/src/video/uikit/SDL_uikitwindow.h index 23beea776..6f86a5d41 100644 --- a/src/video/uikit/SDL_uikitwindow.h +++ b/src/video/uikit/SDL_uikitwindow.h @@ -34,6 +34,7 @@ extern void UIKit_RaiseWindow(_THIS, SDL_Window * window); extern void UIKit_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered); extern void UIKit_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen); extern void UIKit_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed); +extern void UIKit_UpdatePointerLock(_THIS, SDL_Window * window); extern void UIKit_DestroyWindow(_THIS, SDL_Window * window); extern SDL_bool UIKit_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo * info); diff --git a/src/video/uikit/SDL_uikitwindow.m b/src/video/uikit/SDL_uikitwindow.m index c71314b7b..d2713ed0f 100644 --- a/src/video/uikit/SDL_uikitwindow.m +++ b/src/video/uikit/SDL_uikitwindow.m @@ -322,6 +322,12 @@ UIKit_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display void UIKit_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed) +{ + /* There really isn't a concept of window grab or cursor confinement on iOS */ +} + +void +UIKit_UpdatePointerLock(_THIS, SDL_Window * window) { #if !TARGET_OS_TV #if defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0