Skip to content

Commit eea4227

Browse files
committed
Merge pull request #108205 from syntaxerror247/immersive-regression
Android: Don't exclude display cutout in immersive mode
2 parents 89809f2 + 4f695e1 commit eea4227

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

platform/android/java/lib/src/org/godotengine/godot/Godot.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ class Godot private constructor(val context: Context) {
342342
*/
343343
@JvmOverloads
344344
fun enableEdgeToEdge(enabled: Boolean, override: Boolean = false) {
345+
// Note: If modifying edge-to-edge or immersive mode logic, ensure to test with GodotIO.getDisplaySafeArea()
346+
// to confirm there are no regressions in safe area calculation.
345347
val window = getActivity()?.window ?: return
346348

347349
if (!isEdgeToEdge.compareAndSet(!enabled, enabled) && !override) {
@@ -354,27 +356,36 @@ class Godot private constructor(val context: Context) {
354356
ViewCompat.setOnApplyWindowInsetsListener(rootView, null)
355357
rootView.setPadding(0, 0, 0, 0)
356358
} else {
357-
val insetType = WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout()
358359
if (rootView.rootWindowInsets != null) {
359360
val windowInsets = WindowInsetsCompat.toWindowInsetsCompat(rootView.rootWindowInsets)
360-
val insets = windowInsets.getInsets(insetType)
361+
val insets = windowInsets.getInsets(getInsetType())
361362
rootView.setPadding(insets.left, insets.top, insets.right, insets.bottom)
362363
}
363364

364365
ViewCompat.setOnApplyWindowInsetsListener(rootView) { v: View, insets: WindowInsetsCompat ->
365-
val windowInsets = insets.getInsets(insetType)
366+
val windowInsets = insets.getInsets(getInsetType())
366367
v.setPadding(windowInsets.left, windowInsets.top, windowInsets.right, windowInsets.bottom)
367368
WindowInsetsCompat.CONSUMED
368369
}
369370
}
370371
}
371372

373+
private fun getInsetType(): Int {
374+
return if (!useImmersive.get() || isEditorBuild()) {
375+
WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout()
376+
} else {
377+
WindowInsetsCompat.Type.systemBars()
378+
}
379+
}
380+
372381
/**
373382
* Toggle immersive mode.
374383
* Must be called from the UI thread.
375384
*/
376385
@JvmOverloads
377386
fun enableImmersiveMode(enabled: Boolean, override: Boolean = false) {
387+
// Note: If modifying edge-to-edge or immersive mode logic, ensure to test with GodotIO.getDisplaySafeArea()
388+
// to confirm there are no regressions in safe area calculation.
378389
val activity = getActivity() ?: return
379390
val window = activity.window ?: return
380391

platform/android/java/lib/src/org/godotengine/godot/GodotIO.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,11 @@ public int[] getDisplaySafeArea() {
231231
WindowInsetsCompat insetsCompat = WindowInsetsCompat.toWindowInsetsCompat(topView.getRootWindowInsets(), topView);
232232
Insets insets = insetsCompat.getInsets(insetTypes);
233233

234-
if (godot.isInEdgeToEdgeMode()) {
234+
if (godot.isInEdgeToEdgeMode() || godot.isInImmersiveMode()) {
235235
result[0] = insets.left;
236236
result[1] = insets.top;
237237
} else {
238-
// If edge-to-edge mode is disabled, then top and left padding (if required) is already applied.
238+
// The top and left padding (if required) is already applied.
239239
result[0] = 0;
240240
result[1] = 0;
241241
}

0 commit comments

Comments
 (0)