From e799b4ba108a31ba04d66c9d7eeacd65a5d8dfc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 26 May 2024 09:55:50 +0200 Subject: [PATCH] iOS: Pass through touches near the task switcher only in-game. Makes the UI better behaved. --- Common/System/System.h | 1 + ios/ViewController.mm | 17 ++++++++++++++++- ios/ViewControllerCommon.h | 2 ++ ios/ViewControllerMetal.mm | 17 ++++++++++++++++- ios/main.mm | 10 +++++++++- 5 files changed, 44 insertions(+), 3 deletions(-) diff --git a/Common/System/System.h b/Common/System/System.h index a5d87e479668..7c7b3c4c1b30 100644 --- a/Common/System/System.h +++ b/Common/System/System.h @@ -229,6 +229,7 @@ enum class SystemNotification { TEST_JAVA_EXCEPTION, KEEP_SCREEN_AWAKE, ACTIVITY, + UI_STATE_CHANGED, }; // I guess it's not super great architecturally to centralize this, since it's not general - but same with a lot of diff --git a/ios/ViewController.mm b/ios/ViewController.mm index 48afd931e3c2..224b22cc6559 100644 --- a/ios/ViewController.mm +++ b/ios/ViewController.mm @@ -392,7 +392,22 @@ - (void)controllerDidDisconnect:(NSNotification *)note // Enables tapping for edge area. -(UIRectEdge)preferredScreenEdgesDeferringSystemGestures { - return UIRectEdgeAll; + if (GetUIState() == UISTATE_INGAME) { + // In-game, we need all the control we can get. Though, we could possibly + // allow the top edge? + INFO_LOG(SYSTEM, "Defer system gestures on all edges"); + return UIRectEdgeAll; + } else { + INFO_LOG(SYSTEM, "Allow system gestures on the bottom"); + // Allow task switching gestures to take precedence, without causing + // scroll events in the UI. + return UIRectEdgeTop | UIRectEdgeLeft | UIRectEdgeRight; + } +} + +- (void)uiStateChanged +{ + [self setNeedsUpdateOfScreenEdgesDeferringSystemGestures]; } - (UIView *)getView { diff --git a/ios/ViewControllerCommon.h b/ios/ViewControllerCommon.h index cfbe5e7daf99..1e955b66ce39 100644 --- a/ios/ViewControllerCommon.h +++ b/ios/ViewControllerCommon.h @@ -20,6 +20,8 @@ - (void)didBecomeActive; - (void)willResignActive; +- (void)uiStateChanged; + @end extern id sharedViewController; diff --git a/ios/ViewControllerMetal.mm b/ios/ViewControllerMetal.mm index 1fd177a8f36c..43038c8e6191 100644 --- a/ios/ViewControllerMetal.mm +++ b/ios/ViewControllerMetal.mm @@ -477,7 +477,22 @@ - (void)viewSafeAreaInsetsDidChange { // Enables tapping for edge area. -(UIRectEdge)preferredScreenEdgesDeferringSystemGestures { - return UIRectEdgeAll; + if (GetUIState() == UISTATE_INGAME) { + // In-game, we need all the control we can get. Though, we could possibly + // allow the top edge? + INFO_LOG(SYSTEM, "Defer system gestures on all edges"); + return UIRectEdgeAll; + } else { + INFO_LOG(SYSTEM, "Allow system gestures on the bottom"); + // Allow task switching gestures to take precedence, without causing + // scroll events in the UI. + return UIRectEdgeTop | UIRectEdgeLeft | UIRectEdgeRight; + } +} + +- (void)uiStateChanged +{ + [self setNeedsUpdateOfScreenEdgesDeferringSystemGestures]; } - (void)bindDefaultFBO diff --git a/ios/main.mm b/ios/main.mm index 48690865b21d..f0de32c9960e 100644 --- a/ios/main.mm +++ b/ios/main.mm @@ -386,7 +386,15 @@ bool System_GetPropertyBool(SystemProperty prop) { void System_Notify(SystemNotification notification) { switch (notification) { - default: break; + case SystemNotification::UI_STATE_CHANGED: + dispatch_async(dispatch_get_main_queue(), ^{ + if (sharedViewController) { + [sharedViewController uiStateChanged]; + } + }); + break; + default: + break; } }