ios: screen orientation lock through display server

This commit is contained in:
Eric Warmenhoven 2025-04-08 15:36:02 -04:00
parent fbd05aa185
commit afc32f02dc
5 changed files with 55 additions and 54 deletions

View File

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

View File

@ -101,7 +101,6 @@ UINavigationControllerDelegate> {
- (void)showGameView;
- (void)supportOtherAudioSessions;
- (void)refreshSystemConfig;
@end
#else

View File

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

View File

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

View File

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