From 052e21b90352dc15d0a2fb0bd69f5a73e859005d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 26 Oct 2025 14:03:37 +0100 Subject: [PATCH] Increase the safe inset margins slightly --- CMakeLists.txt | 1 + ios/Controls.mm | 12 ++++++------ ios/ViewControllerCommon.mm | 2 ++ ios/ViewControllerMetal.mm | 18 +++++++++++++++--- 4 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 ios/ViewControllerCommon.mm diff --git a/CMakeLists.txt b/CMakeLists.txt index bbe6042166..f478d8166b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1349,6 +1349,7 @@ elseif(IOS AND NOT LIBRETRO) ios/Controls.h ios/Controls.mm ios/ViewControllerCommon.h + ios/ViewControllerCommon.mm ios/ViewController.mm ios/ViewController.h ios/ViewControllerMetal.mm diff --git a/ios/Controls.mm b/ios/Controls.mm index 652a3bb9bb..e71215a870 100644 --- a/ios/Controls.mm +++ b/ios/Controls.mm @@ -108,13 +108,13 @@ bool InitController(GCController *controller) { }; } -#if defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0 - if ([extendedProfile respondsToSelector:@selector(buttonHome)] && extendedProfile.buttonHome != nil) { - extendedProfile.buttonHome.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) { - controllerButtonPressed(pressed, NKCODE_HOME); - }; + if (@available(iOS 14.0, *)) { + if ([extendedProfile respondsToSelector:@selector(buttonHome)] && extendedProfile.buttonHome != nil) { + extendedProfile.buttonHome.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) { + controllerButtonPressed(pressed, NKCODE_HOME); + }; + } } -#endif extendedProfile.leftThumbstick.xAxis.valueChangedHandler = ^(GCControllerAxisInput *axis, float value) { AxisInput axisInput; diff --git a/ios/ViewControllerCommon.mm b/ios/ViewControllerCommon.mm new file mode 100644 index 0000000000..ff611ab217 --- /dev/null +++ b/ios/ViewControllerCommon.mm @@ -0,0 +1,2 @@ +#import "ios/ViewControllerCommon.h" + diff --git a/ios/ViewControllerMetal.mm b/ios/ViewControllerMetal.mm index f7ce3c38ef..85877f75e6 100644 --- a/ios/ViewControllerMetal.mm +++ b/ios/ViewControllerMetal.mm @@ -491,13 +491,25 @@ extern float g_safeInsetRight; extern float g_safeInsetTop; extern float g_safeInsetBottom; +static float BoostInset(float inset) { + if (inset > 0.0f) { + // If there's some inset, add a few pixels extra. Really needed on iPhone 12, at least. + inset += 4.0f; + } + return inset; +} + - (void)viewSafeAreaInsetsDidChange { if (@available(iOS 11.0, *)) { [super viewSafeAreaInsetsDidChange]; // we use 0.0f instead of safeAreaInsets.bottom because the bottom overlay isn't disturbing (for now) - g_safeInsetLeft = self.view.safeAreaInsets.left; - g_safeInsetRight = self.view.safeAreaInsets.right; - g_safeInsetTop = self.view.safeAreaInsets.top; + g_safeInsetLeft = BoostInset(self.view.safeAreaInsets.left); + g_safeInsetRight = BoostInset(self.view.safeAreaInsets.right); + g_safeInsetTop = BoostInset(self.view.safeAreaInsets.top); + + // TODO: In portrait mode, should probably use safeAreaInsets.bottom. + // However, in landscape mode, it's not really needed. + // g_safeInsetBottom = BoostInset(self.view.safeAreaInsets.bottom); g_safeInsetBottom = 0.0f; } }