From 4f695e1713e7acaaf27c2c2f7bdce968756f1451 Mon Sep 17 00:00:00 2001 From: Anish Mishra Date: Wed, 2 Jul 2025 21:07:35 +0530 Subject: [PATCH] Android: Don't exclude display cutout in immersive mode --- .../java/lib/src/org/godotengine/godot/Godot.kt | 17 ++++++++++++++--- .../lib/src/org/godotengine/godot/GodotIO.java | 4 ++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt index 051f2323a7a..5cc75c017ea 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt +++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt @@ -342,6 +342,8 @@ class Godot private constructor(val context: Context) { */ @JvmOverloads fun enableEdgeToEdge(enabled: Boolean, override: Boolean = false) { + // Note: If modifying edge-to-edge or immersive mode logic, ensure to test with GodotIO.getDisplaySafeArea() + // to confirm there are no regressions in safe area calculation. val window = getActivity()?.window ?: return if (!isEdgeToEdge.compareAndSet(!enabled, enabled) && !override) { @@ -354,27 +356,36 @@ class Godot private constructor(val context: Context) { ViewCompat.setOnApplyWindowInsetsListener(rootView, null) rootView.setPadding(0, 0, 0, 0) } else { - val insetType = WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout() if (rootView.rootWindowInsets != null) { val windowInsets = WindowInsetsCompat.toWindowInsetsCompat(rootView.rootWindowInsets) - val insets = windowInsets.getInsets(insetType) + val insets = windowInsets.getInsets(getInsetType()) rootView.setPadding(insets.left, insets.top, insets.right, insets.bottom) } ViewCompat.setOnApplyWindowInsetsListener(rootView) { v: View, insets: WindowInsetsCompat -> - val windowInsets = insets.getInsets(insetType) + val windowInsets = insets.getInsets(getInsetType()) v.setPadding(windowInsets.left, windowInsets.top, windowInsets.right, windowInsets.bottom) WindowInsetsCompat.CONSUMED } } } + private fun getInsetType(): Int { + return if (!useImmersive.get() || isEditorBuild()) { + WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout() + } else { + WindowInsetsCompat.Type.systemBars() + } + } + /** * Toggle immersive mode. * Must be called from the UI thread. */ @JvmOverloads fun enableImmersiveMode(enabled: Boolean, override: Boolean = false) { + // Note: If modifying edge-to-edge or immersive mode logic, ensure to test with GodotIO.getDisplaySafeArea() + // to confirm there are no regressions in safe area calculation. val activity = getActivity() ?: return val window = activity.window ?: return diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java b/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java index d35a9a19ecf..c947652e94e 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java @@ -231,11 +231,11 @@ public class GodotIO { WindowInsetsCompat insetsCompat = WindowInsetsCompat.toWindowInsetsCompat(topView.getRootWindowInsets(), topView); Insets insets = insetsCompat.getInsets(insetTypes); - if (godot.isInEdgeToEdgeMode()) { + if (godot.isInEdgeToEdgeMode() || godot.isInImmersiveMode()) { result[0] = insets.left; result[1] = insets.top; } else { - // If edge-to-edge mode is disabled, then top and left padding (if required) is already applied. + // The top and left padding (if required) is already applied. result[0] = 0; result[1] = 0; }