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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
diff --git a/src/video/uikit/SDL_uikitevents.m b/src/video/uikit/SDL_uikitevents.m
index 4169c9b..e5615fa 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 <Foundation/Foundation.h>
@@ -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 0bc5676..bd54ad6 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 c51d1ae..b2db403 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 23beea7..6f86a5d 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 c71314b..d2713ed 100644
--- a/src/video/uikit/SDL_uikitwindow.m
+++ b/src/video/uikit/SDL_uikitwindow.m
@@ -323,6 +323,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
@autoreleasepool {