diff --git a/input/drivers/cocoa_input.m b/input/drivers/cocoa_input.m index 4154e18298..15cf75249e 100644 --- a/input/drivers/cocoa_input.m +++ b/input/drivers/cocoa_input.m @@ -570,10 +570,6 @@ static int16_t cocoa_input_state( case RETRO_DEVICE_POINTER: case RARCH_DEVICE_POINTER_SCREEN: { -#ifdef IOS - if (!apple->touch_count) - return 0; -#endif // with a physical mouse that is hovering, the touch_count will be 0 // and apple->touches[0] will have the hover position if ((idx == 0 || idx < apple->touch_count) && (idx < MAX_TOUCHES)) @@ -771,6 +767,13 @@ static void cocoa_input_grab_mouse(void *data, bool state) cocoa_show_mouse(nil, !state); apple->mouse_grabbed = state; } +#elif TARGET_OS_IOS +static void cocoa_input_grab_mouse(void *data, bool state) +{ + cocoa_input_data_t *apple = (cocoa_input_data_t*)data; + + apple->mouse_grabbed = state; +} #endif input_driver_t input_cocoa = { @@ -782,7 +785,7 @@ input_driver_t input_cocoa = { cocoa_input_get_sensor_input, cocoa_input_get_capabilities, "cocoa", -#ifdef OSX +#if defined(OSX) || TARGET_OS_IOS cocoa_input_grab_mouse, #else NULL, /* grab_mouse */ diff --git a/menu/menu_driver.c b/menu/menu_driver.c index b86445a6d5..beda6b11ca 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -5272,13 +5272,6 @@ unsigned menu_event( menu_input_pointer_hw_state_t touchscreen_hw_state = {0}; /* Read mouse */ -#ifdef HAVE_IOS_TOUCHMOUSE - if (menu_mouse_enable) - { - settings->bools.menu_pointer_enable = true; - menu_pointer_enable = true; - } -#else if (menu_mouse_enable) menu_input_get_mouse_hw_state( p_disp, @@ -5292,7 +5285,7 @@ unsigned menu_event( input_overlay_enable, overlay_active, &mouse_hw_state); -#endif + /* Read touchscreen * Note: Could forgo this if mouse is currently active, * but this is 'cleaner' code... (if performance is a diff --git a/pkg/apple/MouseEmulation/EmulatorTouchMouse.swift b/pkg/apple/MouseEmulation/EmulatorTouchMouse.swift index de482dc810..a687a4153a 100644 --- a/pkg/apple/MouseEmulation/EmulatorTouchMouse.swift +++ b/pkg/apple/MouseEmulation/EmulatorTouchMouse.swift @@ -22,7 +22,6 @@ import UIKit @objc public protocol EmulatorTouchMouseHandlerDelegate: AnyObject { func handleMouseClick(isLeftClick: Bool, isPressed: Bool) func handleMouseMove(x: CGFloat, y: CGFloat) - func handlePointerMove(x: CGFloat, y: CGFloat) } @objcMembers public class EmulatorTouchMouseHandler: NSObject, UIPointerInteractionDelegate { @@ -74,12 +73,6 @@ import UIKit self?.pendingMouseEvents.append(value) self?.processMouseEvents() }) - if #available(iOS 13.4, *) { - // get pointer interactions - let pointerInteraction = UIPointerInteraction(delegate: self) - self.view.addInteraction(pointerInteraction) - self.view.isUserInteractionEnabled=true - } } private func processMouseEvents() { @@ -203,16 +196,4 @@ import UIKit let dy = pointA.y - pointB.y return sqrt(dx*dx*dy*dy) } - - @available(iOS 13.4, *) - public func pointerInteraction( - _ interaction: UIPointerInteraction, - regionFor request: UIPointerRegionRequest, - defaultRegion: UIPointerRegion - ) -> UIPointerRegion? { - guard !enabled else { return defaultRegion } - let location = request.location; - delegate?.handlePointerMove(x: location.x, y: location.y) - return defaultRegion - } } diff --git a/ui/drivers/cocoa/cocoa_common.m b/ui/drivers/cocoa/cocoa_common.m index 8a5cf0c4ae..f86039a1ab 100644 --- a/ui/drivers/cocoa/cocoa_common.m +++ b/ui/drivers/cocoa/cocoa_common.m @@ -688,16 +688,6 @@ void cocoa_file_load_with_detect_core(const char *filename); } } --(void)handlePointerMoveWithX:(CGFloat)x y:(CGFloat)y -{ - cocoa_input_data_t *apple = (cocoa_input_data_t*) - input_state_get_ptr()->current_data; - if (!apple) - return; - apple->window_pos_x = (int16_t)x; - apple->window_pos_y = (int16_t)y; -} - #endif #pragma mark GCDWebServerDelegate diff --git a/ui/drivers/ui_cocoatouch.m b/ui/drivers/ui_cocoatouch.m index d2eaf69772..74c7399766 100644 --- a/ui/drivers/ui_cocoatouch.m +++ b/ui/drivers/ui_cocoatouch.m @@ -481,8 +481,7 @@ enum @end #if TARGET_OS_IOS -@interface RetroArch_iOS () - +@interface RetroArch_iOS () @end #endif @@ -535,6 +534,13 @@ enum _renderView.translatesAutoresizingMaskIntoConstraints = NO; UIView *rootView = [CocoaView get].view; [rootView addSubview:_renderView]; +#if TARGET_OS_IOS + if (@available(iOS 13.4, *)) + { + [_renderView addInteraction:[[UIPointerInteraction alloc] initWithDelegate:self]]; + _renderView.userInteractionEnabled = YES; + } +#endif [[_renderView.topAnchor constraintEqualToAnchor:rootView.topAnchor] setActive:YES]; [[_renderView.bottomAnchor constraintEqualToAnchor:rootView.bottomAnchor] setActive:YES]; [[_renderView.leadingAnchor constraintEqualToAnchor:rootView.leadingAnchor] setActive:YES]; @@ -824,7 +830,7 @@ enum } } -- (void)didReceiveDiagnosticPayloads:(NSArray *)payloads +- (void)didReceiveDiagnosticPayloads:(NSArray *)payloads API_AVAILABLE(ios(14.0)) { for (MXDiagnosticPayload *payload in payloads) { @@ -832,6 +838,31 @@ enum RARCH_LOG("Got Diagnostic Payload:\n%s\n", [json cStringUsingEncoding:kCFStringEncodingUTF8]); } } + +- (UIPointerStyle *)pointerInteraction:(UIPointerInteraction *)interaction styleForRegion:(UIPointerRegion *)region API_AVAILABLE(ios(13.4)) +{ + cocoa_input_data_t *apple = (cocoa_input_data_t*) input_state_get_ptr()->current_data; + if (!apple) + return nil; + if (apple->mouse_grabbed) + return [UIPointerStyle hiddenPointerStyle]; + return nil; +} + +- (UIPointerRegion *)pointerInteraction:(UIPointerInteraction *)interaction + regionForRequest:(UIPointerRegionRequest *)request + defaultRegion:(UIPointerRegion *)defaultRegion API_AVAILABLE(ios(13.4)) +{ + cocoa_input_data_t *apple = (cocoa_input_data_t*) input_state_get_ptr()->current_data; + if (!apple) + return nil; + CGPoint location = [apple_platform.renderView convertPoint:[request location] fromView:nil]; + apple->touches[0].screen_x = (int16_t)(location.x * [[UIScreen mainScreen] scale]); + apple->touches[0].screen_y = (int16_t)(location.y * [[UIScreen mainScreen] scale]); + apple->window_pos_x = (int16_t)(location.x * [[UIScreen mainScreen] scale]); + apple->window_pos_y = (int16_t)(location.y * [[UIScreen mainScreen] scale]); + return [UIPointerRegion regionWithRect:[apple_platform.renderView bounds] identifier:@"game view"]; +} #endif @end