diff --git a/ui/drivers/cocoa/cocoa_common.m b/ui/drivers/cocoa/cocoa_common.m index 1a4e18a45a..fd90d0f310 100644 --- a/ui/drivers/cocoa/cocoa_common.m +++ b/ui/drivers/cocoa/cocoa_common.m @@ -244,7 +244,7 @@ void cocoa_file_load_with_detect_core(const char *filename); static NSDictionary*> *map; static dispatch_once_t once; dispatch_once(&once, ^{ - map = @{ + NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:@{ @(UIPressTypeUpArrow): @[ @(RETROK_UP), @( 0 ) ], @(UIPressTypeDownArrow): @[ @(RETROK_DOWN), @( 0 ) ], @(UIPressTypeLeftArrow): @[ @(RETROK_LEFT), @( 0 ) ], @@ -253,10 +253,16 @@ void cocoa_file_load_with_detect_core(const char *filename); @(UIPressTypeSelect): @[ @(RETROK_z), @('z') ], @(UIPressTypeMenu) : @[ @(RETROK_x), @('x') ], @(UIPressTypePlayPause): @[ @(RETROK_s), @('s') ], + }]; - @(UIPressTypePageUp): @[ @(RETROK_PAGEUP), @( 0 ) ], - @(UIPressTypePageDown): @[ @(RETROK_PAGEDOWN), @( 0 ) ], - }; + if (@available(tvOS 14.3, *)) + { + [dict addEntriesFromDictionary:@{ + @(UIPressTypePageUp): @[ @(RETROK_PAGEUP), @( 0 ) ], + @(UIPressTypePageDown): @[ @(RETROK_PAGEDOWN), @( 0 ) ], + }]; + } + map = dict; }); NSArray* keyvals = map[@(type)]; if (!keyvals) @@ -270,12 +276,15 @@ void cocoa_file_load_with_detect_core(const char *filename); { for (UIPress *press in presses) { + bool has_key = false; + if (@available(tvOS 14, *)) + has_key = !![press key]; /* If we're at the top it doesn't matter who pressed it, we want to leave */ if (press.type == UIPressTypeMenu && [self menuIsAtTop]) [super pressesBegan:presses withEvent:event]; - else if (!press.key && [self didMicroGamepadPress:press.type]) + else if (!has_key && [self didMicroGamepadPress:press.type]) [self sendKeyForPress:press.type down:true]; - else if (press.key) + else if (has_key) [super pressesBegan:[NSSet setWithObject:press] withEvent:event]; } } diff --git a/ui/drivers/ui_cocoatouch.m b/ui/drivers/ui_cocoatouch.m index 48a72db8e8..efcd254e2f 100644 --- a/ui/drivers/ui_cocoatouch.m +++ b/ui/drivers/ui_cocoatouch.m @@ -387,10 +387,15 @@ enum #else - (void)handleUIPress:(UIPress *)press withEvent:(UIPressesEvent *)event down:(BOOL)down { - NSString *ch = (NSString*)press.key.characters; + NSString *ch; uint32_t character = 0; uint32_t mod = 0; - NSUInteger mods = event.modifierFlags; + NSUInteger mods = 0; + if (@available(iOS 13.4, tvOS 13.4, *)) + { + ch = (NSString*)press.key.characters; + mods = event.modifierFlags; + } if (mods & UIKeyModifierAlphaShift) mod |= RETROKMOD_CAPSLOCK; @@ -420,9 +425,10 @@ enum RETRO_DEVICE_KEYBOARD); } - apple_input_keyboard_event(down, - (uint32_t)press.key.keyCode, character, mod, - RETRO_DEVICE_KEYBOARD); + if (@available(iOS 13.4, tvOS 13.4, *)) + apple_input_keyboard_event(down, + (uint32_t)press.key.keyCode, character, mod, + RETRO_DEVICE_KEYBOARD); } - (void)pressesBegan:(NSSet *)presses withEvent:(UIPressesEvent *)event @@ -674,23 +680,26 @@ 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; - }; - }]; + if (@available(macOS 11, iOS 14, tvOS 14, *)) + { + [[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 }