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

Android: Fix DisplayServer.get_display_safe_area() issues

This commit is contained in:
Anish Mishra
2025-06-29 12:56:14 +05:30
parent e1b4101e34
commit 1338e29bf5

View File

@@ -53,6 +53,8 @@ import android.view.WindowInsets;
import android.view.WindowManager; import android.view.WindowManager;
import androidx.core.content.FileProvider; import androidx.core.content.FileProvider;
import androidx.core.graphics.Insets;
import androidx.core.view.WindowInsetsCompat;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
@@ -223,25 +225,25 @@ public class GodotIO {
} }
if (topView != null) { if (topView != null) {
topView.getWindowVisibleDisplayFrame(rect); int insetTypes = WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout();
result[0] = rect.left;
result[1] = rect.top;
result[2] = rect.right;
result[3] = rect.bottom;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { if (topView.getRootWindowInsets() != null) {
WindowInsets insets = topView.getRootWindowInsets(); WindowInsetsCompat insetsCompat = WindowInsetsCompat.toWindowInsetsCompat(topView.getRootWindowInsets(), topView);
DisplayCutout cutout = insets.getDisplayCutout(); Insets insets = insetsCompat.getInsets(insetTypes);
if (cutout != null) {
int insetLeft = cutout.getSafeInsetLeft(); if (godot.isInEdgeToEdgeMode()) {
int insetTop = cutout.getSafeInsetTop(); result[0] = insets.left;
result[0] = insetLeft; result[1] = insets.top;
result[1] = insetTop; } else {
result[2] -= insetLeft + cutout.getSafeInsetRight(); // If edge-to-edge mode is disabled, then top and left padding (if required) is already applied.
result[3] -= insetTop + cutout.getSafeInsetBottom(); result[0] = 0;
result[1] = 0;
} }
result[2] = topView.getWidth() - insets.right - insets.left;
result[3] = topView.getHeight() - insets.bottom - insets.top;
} }
} }
return result; return result;
} }