diff --git a/gfx/display_servers/dispserv_apple.m b/gfx/display_servers/dispserv_apple.m index 64314cd0d4..f521ee237b 100644 --- a/gfx/display_servers/dispserv_apple.m +++ b/gfx/display_servers/dispserv_apple.m @@ -176,6 +176,53 @@ static void *apple_display_server_get_resolution_list( return conf; } +#if TARGET_OS_IOS +static void apple_display_server_set_screen_orientation(void *data, enum rotation rotation) +{ + switch (rotation) + { + case ORIENTATION_VERTICAL: + [[CocoaView get] setShouldLockCurrentInterfaceOrientation:YES]; + [[CocoaView get] setLockInterfaceOrientation:UIInterfaceOrientationLandscapeRight]; + break; + case ORIENTATION_FLIPPED: + [[CocoaView get] setShouldLockCurrentInterfaceOrientation:YES]; + [[CocoaView get] setLockInterfaceOrientation:UIInterfaceOrientationPortraitUpsideDown]; + break; + case ORIENTATION_FLIPPED_ROTATED: + [[CocoaView get] setShouldLockCurrentInterfaceOrientation:YES]; + [[CocoaView get] setLockInterfaceOrientation:UIInterfaceOrientationLandscapeLeft]; + break; + case ORIENTATION_NORMAL: + default: + [[CocoaView get] setShouldLockCurrentInterfaceOrientation:NO]; + break; + } + if (@available(iOS 16.0, *)) + { + [[CocoaView get] setNeedsUpdateOfSupportedInterfaceOrientations]; + } +} + +static enum rotation apple_display_server_get_screen_orientation(void *data) +{ + if (![[CocoaView get] shouldLockCurrentInterfaceOrientation]) + return ORIENTATION_NORMAL; + UIInterfaceOrientation orientation = [[CocoaView get] lockInterfaceOrientation]; + switch (orientation) + { + case UIInterfaceOrientationLandscapeRight: + return ORIENTATION_VERTICAL; + case UIInterfaceOrientationPortraitUpsideDown: + return ORIENTATION_FLIPPED; + case UIInterfaceOrientationLandscapeLeft: + return ORIENTATION_FLIPPED_ROTATED; + default: + return ORIENTATION_NORMAL; + } +} +#endif + const video_display_server_t dispserv_apple = { NULL, /* init */ NULL, /* destroy */ @@ -191,8 +238,13 @@ const video_display_server_t dispserv_apple = { apple_display_server_set_resolution, apple_display_server_get_resolution_list, NULL, /* get_output_options */ +#if TARGET_OS_IOS + apple_display_server_set_screen_orientation, + apple_display_server_get_screen_orientation, +#else NULL, /* set_screen_orientation */ NULL, /* get_screen_orientation */ +#endif NULL, /* get_flags */ "apple" }; diff --git a/ui/drivers/cocoa/apple_platform.h b/ui/drivers/cocoa/apple_platform.h index 9bd15b1539..ae1386ef7a 100644 --- a/ui/drivers/cocoa/apple_platform.h +++ b/ui/drivers/cocoa/apple_platform.h @@ -101,7 +101,6 @@ UINavigationControllerDelegate> { - (void)showGameView; - (void)supportOtherAudioSessions; -- (void)refreshSystemConfig; @end #else diff --git a/ui/drivers/cocoa/cocoa_common.h b/ui/drivers/cocoa/cocoa_common.h index 15d88430b1..50cc1a75d4 100644 --- a/ui/drivers/cocoa/cocoa_common.h +++ b/ui/drivers/cocoa/cocoa_common.h @@ -97,14 +97,6 @@ void get_ios_version(int *major, int *minor); @end #endif -typedef struct -{ - char orientations[32]; - unsigned orientation_flags; - char bluetooth_mode[64]; -} apple_frontend_settings_t; -extern apple_frontend_settings_t apple_frontend_settings; - #define BOXSTRING(x) [NSString stringWithUTF8String:x] #define BOXINT(x) [NSNumber numberWithInt:x] #define BOXUINT(x) [NSNumber numberWithUnsignedInt:x] diff --git a/ui/drivers/cocoa/cocoa_common.m b/ui/drivers/cocoa/cocoa_common.m index 7656c90ea0..875e2992ea 100644 --- a/ui/drivers/cocoa/cocoa_common.m +++ b/ui/drivers/cocoa/cocoa_common.m @@ -584,9 +584,9 @@ void cocoa_file_load_with_detect_core(const char *filename); { if (self.shouldLockCurrentInterfaceOrientation) return 1 << self.lockInterfaceOrientation; - return (UIInterfaceOrientationMask)apple_frontend_settings.orientation_flags; + return UIInterfaceOrientationMaskAll; } - return (UIInterfaceOrientationMask)apple_frontend_settings.orientation_flags; + return UIInterfaceOrientationMaskAll; } /* NOTE: This does not run on iOS 16+ */ @@ -600,29 +600,7 @@ void cocoa_file_load_with_detect_core(const char *filename); /* NOTE: This version runs on iOS2-iOS5, but not iOS6+. */ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { - unsigned orientation_flags = apple_frontend_settings.orientation_flags; - - switch (interfaceOrientation) - { - case UIInterfaceOrientationPortrait: - return (orientation_flags - & UIInterfaceOrientationMaskPortrait); - case UIInterfaceOrientationPortraitUpsideDown: - return (orientation_flags - & UIInterfaceOrientationMaskPortraitUpsideDown); - case UIInterfaceOrientationLandscapeLeft: - return (orientation_flags - & UIInterfaceOrientationMaskLandscapeLeft); - case UIInterfaceOrientationLandscapeRight: - return (orientation_flags - & UIInterfaceOrientationMaskLandscapeRight); - - default: - break; - } - - return (orientation_flags - & UIInterfaceOrientationMaskAll); + return YES; } #endif diff --git a/ui/drivers/ui_cocoatouch.m b/ui/drivers/ui_cocoatouch.m index f7a8fcd4ca..e7e71a219a 100644 --- a/ui/drivers/ui_cocoatouch.m +++ b/ui/drivers/ui_cocoatouch.m @@ -191,8 +191,6 @@ void rarch_stop_draw_observer(void) iterate_observer = NULL; } -apple_frontend_settings_t apple_frontend_settings; - void get_ios_version(int *major, int *minor) { static int savedMajor, savedMinor; @@ -713,7 +711,6 @@ enum [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleAudioSessionInterruption:) name:AVAudioSessionInterruptionNotification object:[AVAudioSession sharedInstance]]; - [self refreshSystemConfig]; [self showGameView]; rarch_main(argc, argv, NULL); @@ -913,7 +910,6 @@ enum #if TARGET_OS_IOS [self setToolbarHidden:![[viewController toolbarItems] count] animated:YES]; #endif - [self refreshSystemConfig]; } - (void)showGameView @@ -933,22 +929,6 @@ enum }); } -- (void)refreshSystemConfig -{ -#if TARGET_OS_IOS - /* Get enabled orientations */ - apple_frontend_settings.orientation_flags = UIInterfaceOrientationMaskAll; - - if (string_is_equal(apple_frontend_settings.orientations, "landscape")) - apple_frontend_settings.orientation_flags = - UIInterfaceOrientationMaskLandscape; - else if (string_is_equal(apple_frontend_settings.orientations, "portrait")) - apple_frontend_settings.orientation_flags = - UIInterfaceOrientationMaskPortrait - | UIInterfaceOrientationMaskPortraitUpsideDown; -#endif -} - - (void)supportOtherAudioSessions { } #if TARGET_OS_IOS