You've already forked godot
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:
@@ -342,6 +342,8 @@ class Godot private constructor(val context: Context) {
|
|||||||
*/
|
*/
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun enableEdgeToEdge(enabled: Boolean, override: Boolean = false) {
|
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
|
val window = getActivity()?.window ?: return
|
||||||
|
|
||||||
if (!isEdgeToEdge.compareAndSet(!enabled, enabled) && !override) {
|
if (!isEdgeToEdge.compareAndSet(!enabled, enabled) && !override) {
|
||||||
@@ -354,27 +356,36 @@ class Godot private constructor(val context: Context) {
|
|||||||
ViewCompat.setOnApplyWindowInsetsListener(rootView, null)
|
ViewCompat.setOnApplyWindowInsetsListener(rootView, null)
|
||||||
rootView.setPadding(0, 0, 0, 0)
|
rootView.setPadding(0, 0, 0, 0)
|
||||||
} else {
|
} else {
|
||||||
val insetType = WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout()
|
|
||||||
if (rootView.rootWindowInsets != null) {
|
if (rootView.rootWindowInsets != null) {
|
||||||
val windowInsets = WindowInsetsCompat.toWindowInsetsCompat(rootView.rootWindowInsets)
|
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)
|
rootView.setPadding(insets.left, insets.top, insets.right, insets.bottom)
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewCompat.setOnApplyWindowInsetsListener(rootView) { v: View, insets: WindowInsetsCompat ->
|
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)
|
v.setPadding(windowInsets.left, windowInsets.top, windowInsets.right, windowInsets.bottom)
|
||||||
WindowInsetsCompat.CONSUMED
|
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.
|
* Toggle immersive mode.
|
||||||
* Must be called from the UI thread.
|
* Must be called from the UI thread.
|
||||||
*/
|
*/
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun enableImmersiveMode(enabled: Boolean, override: Boolean = false) {
|
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 activity = getActivity() ?: return
|
||||||
val window = activity.window ?: return
|
val window = activity.window ?: return
|
||||||
|
|
||||||
|
|||||||
@@ -231,11 +231,11 @@ public class GodotIO {
|
|||||||
WindowInsetsCompat insetsCompat = WindowInsetsCompat.toWindowInsetsCompat(topView.getRootWindowInsets(), topView);
|
WindowInsetsCompat insetsCompat = WindowInsetsCompat.toWindowInsetsCompat(topView.getRootWindowInsets(), topView);
|
||||||
Insets insets = insetsCompat.getInsets(insetTypes);
|
Insets insets = insetsCompat.getInsets(insetTypes);
|
||||||
|
|
||||||
if (godot.isInEdgeToEdgeMode()) {
|
if (godot.isInEdgeToEdgeMode() || godot.isInImmersiveMode()) {
|
||||||
result[0] = insets.left;
|
result[0] = insets.left;
|
||||||
result[1] = insets.top;
|
result[1] = insets.top;
|
||||||
} else {
|
} 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[0] = 0;
|
||||||
result[1] = 0;
|
result[1] = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user