1
0
mirror of https://github.com/libretro/RetroArch synced 2025-02-20 15:40:44 +00:00

iOS: Better mouse grab ()

This commit is contained in:
Eric Warmenhoven 2024-08-27 04:53:18 -04:00 committed by GitHub
parent 391b46c3be
commit 4503b3989f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 33 additions and 2 deletions
input/drivers
ui/drivers

@ -511,7 +511,7 @@ static int16_t cocoa_input_state(
}
#ifdef IOS
#ifdef HAVE_IOS_TOUCHMOUSE
if (apple->window_pos_x > 0)
if (apple->window_pos_x > 0 || apple->mouse_grabbed)
{
val = apple->window_pos_x - apple->mouse_x_last;
apple->mouse_x_last = apple->window_pos_x;
@ -537,7 +537,7 @@ static int16_t cocoa_input_state(
}
#ifdef IOS
#ifdef HAVE_IOS_TOUCHMOUSE
if (apple->window_pos_y > 0)
if (apple->window_pos_y > 0 || apple->mouse_grabbed)
{
val = apple->window_pos_y - apple->mouse_y_last;
apple->mouse_y_last = apple->window_pos_y;
@ -773,6 +773,8 @@ static void cocoa_input_grab_mouse(void *data, bool state)
cocoa_input_data_t *apple = (cocoa_input_data_t*)data;
apple->mouse_grabbed = state;
[[CocoaView get] setNeedsUpdateOfPrefersPointerLocked];
}
#endif

@ -578,6 +578,14 @@ void cocoa_file_load_with_detect_core(const char *filename);
#ifdef HAVE_COCOATOUCH
-(BOOL) prefersPointerLocked API_AVAILABLE(ios(14.0))
{
cocoa_input_data_t *apple = (cocoa_input_data_t*) input_state_get_ptr()->current_data;
if (!apple)
return NO;
return apple->mouse_grabbed;
}
#pragma mark - UIViewController Lifecycle
-(void)loadView {

@ -47,6 +47,10 @@
#import <MetricKit/MetricKit.h>
#import <MetricKit/MXMetricManager.h>
#ifdef HAVE_MFI
#import <GameController/GCMouse.h>
#endif
#if defined(HAVE_COCOA_METAL) || defined(HAVE_COCOATOUCH)
#import "JITSupport.h"
id<ApplePlatform> apple_platform;
@ -670,6 +674,23 @@ enum
#ifdef HAVE_MFI
extern void *apple_gamecontroller_joypad_init(void *data);
apple_gamecontroller_joypad_init(NULL);
[[NSNotificationCenter defaultCenter] addObserverForName:GCMouseDidConnectNotification
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note)
{
GCMouse *mouse = note.object;
mouse.mouseInput.mouseMovedHandler = ^(GCMouseInput * _Nonnull mouse, float delta_x, float delta_y)
{
cocoa_input_data_t *apple = (cocoa_input_data_t*) input_state_get_ptr()->current_data;
if (!apple || !apple->mouse_grabbed)
return;
apple->mouse_rel_x += (int16_t)delta_x;
apple->mouse_rel_y -= (int16_t)delta_y;
apple->window_pos_x += (int16_t)delta_x;
apple->window_pos_y -= (int16_t)delta_y;
};
}];
#endif
}