1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Android: Don't exclude display cutout in immersive mode

This commit is contained in:
Anish Mishra
2025-07-02 21:07:35 +05:30
parent efb40c1524
commit 4f695e1713
2 changed files with 16 additions and 5 deletions

View File

@@ -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

View File

@@ -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;
}