early-access version 2281
This commit is contained in:
+37
-26
@@ -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;
|
||||
}
|
||||
|
||||
@@ -234,7 +235,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 );
|
||||
@@ -243,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))
|
||||
@@ -260,7 +263,7 @@ static void OnGCMouseDisconnected(GCMouse *mouse) API_AVAILABLE(macos(11.0), ios
|
||||
button.pressedChangedHandler = nil;
|
||||
}
|
||||
|
||||
UpdateMouseGrab();
|
||||
UpdatePointerLock();
|
||||
}
|
||||
|
||||
void SDL_InitGCMouse(void)
|
||||
@@ -268,29 +271,37 @@ void SDL_InitGCMouse(void)
|
||||
@autoreleasepool {
|
||||
/* There is a bug where mouse accumulates duplicate deltas over time in iOS 14.0 */
|
||||
if (@available(iOS 14.1, tvOS 14.1, *)) {
|
||||
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
|
||||
/* iOS will not send the new pointer touch events if you don't have this key,
|
||||
* and we need them to differentiate between mouse events and real touch events.
|
||||
*/
|
||||
BOOL indirect_input_available = [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"UIApplicationSupportsIndirectInputEvents"] boolValue];
|
||||
if (indirect_input_available) {
|
||||
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
|
||||
|
||||
mouse_connect_observer = [center addObserverForName:GCMouseDidConnectNotification
|
||||
object:nil
|
||||
queue:nil
|
||||
usingBlock:^(NSNotification *note) {
|
||||
GCMouse *mouse = note.object;
|
||||
OnGCMouseConnected(mouse);
|
||||
}];
|
||||
mouse_connect_observer = [center addObserverForName:GCMouseDidConnectNotification
|
||||
object:nil
|
||||
queue:nil
|
||||
usingBlock:^(NSNotification *note) {
|
||||
GCMouse *mouse = note.object;
|
||||
OnGCMouseConnected(mouse);
|
||||
}];
|
||||
|
||||
mouse_disconnect_observer = [center addObserverForName:GCMouseDidDisconnectNotification
|
||||
object:nil
|
||||
queue:nil
|
||||
usingBlock:^(NSNotification *note) {
|
||||
GCMouse *mouse = note.object;
|
||||
OnGCMouseDisconnected(mouse);
|
||||
}];
|
||||
mouse_disconnect_observer = [center addObserverForName:GCMouseDidDisconnectNotification
|
||||
object:nil
|
||||
queue:nil
|
||||
usingBlock:^(NSNotification *note) {
|
||||
GCMouse *mouse = note.object;
|
||||
OnGCMouseDisconnected(mouse);
|
||||
}];
|
||||
|
||||
for (GCMouse *mouse in [GCMouse mice]) {
|
||||
OnGCMouseConnected(mouse);
|
||||
for (GCMouse *mouse in [GCMouse mice]) {
|
||||
OnGCMouseConnected(mouse);
|
||||
}
|
||||
|
||||
SDL_GetMouse()->SetRelativeMouseMode = SetGCMouseRelativeMode;
|
||||
} else {
|
||||
NSLog(@"You need UIApplicationSupportsIndirectInputEvents in your Info.plist for mouse support");
|
||||
}
|
||||
|
||||
SDL_GetMouse()->SetRelativeMouseMode = SetGCMouseRelativeMode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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()) {
|
||||
if (request != nil && !SDL_GCMouseRelativeMode()) {
|
||||
CGPoint origin = self.bounds.origin;
|
||||
CGPoint point = request.location;
|
||||
|
||||
|
||||
+1
-8
@@ -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 */
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -322,8 +322,15 @@ 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 {
|
||||
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
|
||||
SDL_uikitviewcontroller *viewcontroller = data.viewcontroller;
|
||||
@@ -331,6 +338,7 @@ UIKit_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
|
||||
[viewcontroller setNeedsUpdateOfPrefersPointerLocked];
|
||||
}
|
||||
}
|
||||
#endif /* defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0 */
|
||||
#endif /* !TARGET_OS_TV */
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user