iOS: Better handling of physical mice/magic keyboard trackpad (#16911)

This commit is contained in:
Eric Warmenhoven 2024-08-22 15:11:16 -04:00 committed by GitHub
parent 47397f07a1
commit 800be5530f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 43 additions and 45 deletions

View File

@ -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 */

View File

@ -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

View File

@ -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
}
}

View File

@ -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

View File

@ -481,8 +481,7 @@ enum
@end
#if TARGET_OS_IOS
@interface RetroArch_iOS () <MXMetricManagerSubscriber>
@interface RetroArch_iOS () <MXMetricManagerSubscriber, UIPointerInteractionDelegate>
@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<MXDiagnosticPayload *> *)payloads
- (void)didReceiveDiagnosticPayloads:(NSArray<MXDiagnosticPayload *> *)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