ios: screen orientation lock through display server
This commit is contained in:
parent
fbd05aa185
commit
afc32f02dc
|
@ -176,6 +176,53 @@ static void *apple_display_server_get_resolution_list(
|
||||||
return conf;
|
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 = {
|
const video_display_server_t dispserv_apple = {
|
||||||
NULL, /* init */
|
NULL, /* init */
|
||||||
NULL, /* destroy */
|
NULL, /* destroy */
|
||||||
|
@ -191,8 +238,13 @@ const video_display_server_t dispserv_apple = {
|
||||||
apple_display_server_set_resolution,
|
apple_display_server_set_resolution,
|
||||||
apple_display_server_get_resolution_list,
|
apple_display_server_get_resolution_list,
|
||||||
NULL, /* get_output_options */
|
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, /* set_screen_orientation */
|
||||||
NULL, /* get_screen_orientation */
|
NULL, /* get_screen_orientation */
|
||||||
|
#endif
|
||||||
NULL, /* get_flags */
|
NULL, /* get_flags */
|
||||||
"apple"
|
"apple"
|
||||||
};
|
};
|
||||||
|
|
|
@ -101,7 +101,6 @@ UINavigationControllerDelegate> {
|
||||||
- (void)showGameView;
|
- (void)showGameView;
|
||||||
- (void)supportOtherAudioSessions;
|
- (void)supportOtherAudioSessions;
|
||||||
|
|
||||||
- (void)refreshSystemConfig;
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -97,14 +97,6 @@ void get_ios_version(int *major, int *minor);
|
||||||
@end
|
@end
|
||||||
#endif
|
#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 BOXSTRING(x) [NSString stringWithUTF8String:x]
|
||||||
#define BOXINT(x) [NSNumber numberWithInt:x]
|
#define BOXINT(x) [NSNumber numberWithInt:x]
|
||||||
#define BOXUINT(x) [NSNumber numberWithUnsignedInt:x]
|
#define BOXUINT(x) [NSNumber numberWithUnsignedInt:x]
|
||||||
|
|
|
@ -584,9 +584,9 @@ void cocoa_file_load_with_detect_core(const char *filename);
|
||||||
{
|
{
|
||||||
if (self.shouldLockCurrentInterfaceOrientation)
|
if (self.shouldLockCurrentInterfaceOrientation)
|
||||||
return 1 << self.lockInterfaceOrientation;
|
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+ */
|
/* 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+. */
|
/* NOTE: This version runs on iOS2-iOS5, but not iOS6+. */
|
||||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
|
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
|
||||||
{
|
{
|
||||||
unsigned orientation_flags = apple_frontend_settings.orientation_flags;
|
return YES;
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -191,8 +191,6 @@ void rarch_stop_draw_observer(void)
|
||||||
iterate_observer = NULL;
|
iterate_observer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
apple_frontend_settings_t apple_frontend_settings;
|
|
||||||
|
|
||||||
void get_ios_version(int *major, int *minor)
|
void get_ios_version(int *major, int *minor)
|
||||||
{
|
{
|
||||||
static int savedMajor, savedMinor;
|
static int savedMajor, savedMinor;
|
||||||
|
@ -713,7 +711,6 @@ enum
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleAudioSessionInterruption:) name:AVAudioSessionInterruptionNotification object:[AVAudioSession sharedInstance]];
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleAudioSessionInterruption:) name:AVAudioSessionInterruptionNotification object:[AVAudioSession sharedInstance]];
|
||||||
|
|
||||||
[self refreshSystemConfig];
|
|
||||||
[self showGameView];
|
[self showGameView];
|
||||||
|
|
||||||
rarch_main(argc, argv, NULL);
|
rarch_main(argc, argv, NULL);
|
||||||
|
@ -913,7 +910,6 @@ enum
|
||||||
#if TARGET_OS_IOS
|
#if TARGET_OS_IOS
|
||||||
[self setToolbarHidden:![[viewController toolbarItems] count] animated:YES];
|
[self setToolbarHidden:![[viewController toolbarItems] count] animated:YES];
|
||||||
#endif
|
#endif
|
||||||
[self refreshSystemConfig];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)showGameView
|
- (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 { }
|
- (void)supportOtherAudioSessions { }
|
||||||
|
|
||||||
#if TARGET_OS_IOS
|
#if TARGET_OS_IOS
|
||||||
|
|
Loading…
Reference in New Issue