From 92754e6c4560fc71c2d1f2aec6a125a2258debff Mon Sep 17 00:00:00 2001 From: Florin9doi Date: Tue, 31 Mar 2020 19:45:39 +0300 Subject: [PATCH] [iOS] Notch support --- .travis.yml | 4 ++-- ios/ViewController.mm | 24 ++++++++++++++++++------ ios/main.mm | 21 +++++++++++++++++++++ 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 64aff24a1744..da4efe94a409 100644 --- a/.travis.yml +++ b/.travis.yml @@ -86,11 +86,11 @@ matrix: env: PPSSPP_BUILD_TYPE=Linux LIBRETRO=TRUE - os: osx - osx_image: xcode8.3 + osx_image: xcode9 compiler: "clang" env: PPSSPP_BUILD_TYPE=macOS - os: osx - osx_image: xcode8.3 + osx_image: xcode9 compiler: "clang" env: PPSSPP_BUILD_TYPE=iOS - os: windows diff --git a/ios/ViewController.mm b/ios/ViewController.mm index 276076fdc10f..81c1960aee2b 100644 --- a/ios/ViewController.mm +++ b/ios/ViewController.mm @@ -148,11 +148,23 @@ - (void)subtleVolume:(SubtleVolume *)volumeView willChange:(CGFloat)value { - (void)subtleVolume:(SubtleVolume *)volumeView didChange:(CGFloat)value { } +- (void)viewSafeAreaInsetsDidChange { + if (@available(iOS 11.0, *)) { + [super viewSafeAreaInsetsDidChange]; + char safeArea[100]; + // we use 0.0f instead of safeAreaInsets.bottom because the bottom overlay isn't disturbing (for now) + snprintf(safeArea, sizeof(safeArea), "%f:%f:%f:%f", + self.view.safeAreaInsets.left, self.view.safeAreaInsets.right, + self.view.safeAreaInsets.top, 0.0f); + System_SendMessage("safe_insets", safeArea); + } +} + - (void)viewDidLoad { [super viewDidLoad]; [[DisplayManager shared] setupDisplayListener]; - UIScreen* screen = [(AppDelegate*)[UIApplication sharedApplication].delegate screen]; + UIScreen* screen = [(AppDelegate*)[UIApplication sharedApplication].delegate screen]; self.view.frame = [screen bounds]; self.view.multipleTouchEnabled = YES; self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]; @@ -687,23 +699,23 @@ void startVideo() { } void stopVideo() { - [cameraHelper stopVideo]; + [cameraHelper stopVideo]; } -(void) PushCameraImageIOS:(long long)len buffer:(unsigned char*)data { - Camera::pushCameraImage(len, data); + Camera::pushCameraImage(len, data); } void startLocation() { - [locationHelper startLocationUpdates]; + [locationHelper startLocationUpdates]; } void stopLocation() { - [locationHelper stopLocationUpdates]; + [locationHelper stopLocationUpdates]; } -(void) SetGpsDataIOS:(CLLocation *)newLocation { - GPS::setGpsData((long long)newLocation.timestamp.timeIntervalSince1970, + GPS::setGpsData((long long)newLocation.timestamp.timeIntervalSince1970, newLocation.horizontalAccuracy/5.0, newLocation.coordinate.latitude, newLocation.coordinate.longitude, newLocation.altitude, diff --git a/ios/main.mm b/ios/main.mm index ff23140b4391..7d755013bd58 100644 --- a/ios/main.mm +++ b/ios/main.mm @@ -46,6 +46,11 @@ kern_return_t catch_exception_raise(mach_port_t exception_port, return NULL; } +static float g_safeInsetLeft = 0.0; +static float g_safeInsetRight = 0.0; +static float g_safeInsetTop = 0.0; +static float g_safeInsetBottom = 0.0; + std::string System_GetProperty(SystemProperty prop) { switch (prop) { @@ -73,6 +78,14 @@ float System_GetPropertyFloat(SystemProperty prop) { switch (prop) { case SYSPROP_DISPLAY_REFRESH_RATE: return 60.f; + case SYSPROP_DISPLAY_SAFE_INSET_LEFT: + return g_safeInsetLeft; + case SYSPROP_DISPLAY_SAFE_INSET_RIGHT: + return g_safeInsetRight; + case SYSPROP_DISPLAY_SAFE_INSET_TOP: + return g_safeInsetTop; + case SYSPROP_DISPLAY_SAFE_INSET_BOTTOM: + return g_safeInsetBottom; default: return -1; } @@ -116,6 +129,14 @@ void System_SendMessage(const char *command, const char *parameter) { } else if (!strcmp(parameter, "close")) { stopLocation(); } + } else if (!strcmp(command, "safe_insets")) { + float left, right, top, bottom; + if (4 == sscanf(parameter, "%f:%f:%f:%f", &left, &right, &top, &bottom)) { + g_safeInsetLeft = left; + g_safeInsetRight = right; + g_safeInsetTop = top; + g_safeInsetBottom = bottom; + } } }