Skip to content

Commit

Permalink
Pass in the window insets
Browse files Browse the repository at this point in the history
  • Loading branch information
Susko3 committed Feb 5, 2024
1 parent 116d899 commit 7c15b4a
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions osu.Framework.Android/AndroidGameView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ protected override void OnLoad(EventArgs e)

public override WindowInsets? OnApplyWindowInsets(WindowInsets? insets)
{
updateSafeArea();
updateSafeArea(insets);
return base.OnApplyWindowInsets(insets);
}

Expand Down Expand Up @@ -218,26 +218,26 @@ private bool handleException(Exception ex)
/// <summary>
/// Updates the <see cref="IWindow.SafeAreaPadding"/>, taking into account screen insets that may be obstructing this <see cref="AndroidGameView"/>.
/// </summary>
private void updateSafeArea()
private void updateSafeArea(WindowInsets? windowInsets)
{
var metrics = WindowMetricsCalculator.Companion.OrCreate.ComputeCurrentWindowMetrics(Activity);
var windowArea = metrics.Bounds.ToRectangleI();
var usableWindowArea = windowArea;

if (OperatingSystem.IsAndroidVersionAtLeast(28))
{
var cutout = RootWindowInsets?.DisplayCutout;
var cutout = windowInsets?.DisplayCutout;

if (cutout != null)
usableWindowArea = usableWindowArea.Shrink(cutout.SafeInsetLeft, cutout.SafeInsetRight, cutout.SafeInsetTop, cutout.SafeInsetBottom);
}

if (OperatingSystem.IsAndroidVersionAtLeast(31) && RootWindowInsets != null)
if (OperatingSystem.IsAndroidVersionAtLeast(31) && windowInsets != null)
{
var topLeftCorner = RootWindowInsets.GetRoundedCorner((int)RoundedCornerPosition.TopLeft);
var topRightCorner = RootWindowInsets.GetRoundedCorner((int)RoundedCornerPosition.TopRight);
var bottomLeftCorner = RootWindowInsets.GetRoundedCorner((int)RoundedCornerPosition.BottomLeft);
var bottomRightCorner = RootWindowInsets.GetRoundedCorner((int)RoundedCornerPosition.BottomRight);
var topLeftCorner = windowInsets.GetRoundedCorner((int)RoundedCornerPosition.TopLeft);
var topRightCorner = windowInsets.GetRoundedCorner((int)RoundedCornerPosition.TopRight);
var bottomLeftCorner = windowInsets.GetRoundedCorner((int)RoundedCornerPosition.BottomLeft);
var bottomRightCorner = windowInsets.GetRoundedCorner((int)RoundedCornerPosition.BottomRight);

int cornerInsetLeft = Math.Max(topLeftCorner?.Radius ?? 0, bottomLeftCorner?.Radius ?? 0);
int cornerInsetRight = Math.Max(topRightCorner?.Radius ?? 0, bottomRightCorner?.Radius ?? 0);
Expand All @@ -251,11 +251,11 @@ private void updateSafeArea()
usableWindowArea = usableWindowArea.Intersect(radiusInsetArea);
}

if (OperatingSystem.IsAndroidVersionAtLeast(24) && Activity.IsInMultiWindowMode && RootWindowInsets != null)
if (OperatingSystem.IsAndroidVersionAtLeast(24) && Activity.IsInMultiWindowMode && windowInsets != null)
{
// if we are in multi-window mode, the status bar is always visible (even if we request to hide it) and could be obstructing our view.
// if multi-window mode is not active, we can assume the status bar is hidden so we shouldn't consider it for safe area calculations.
var insetsCompat = WindowInsetsCompat.ToWindowInsetsCompat(RootWindowInsets, this);
var insetsCompat = WindowInsetsCompat.ToWindowInsetsCompat(windowInsets, this);
int statusBarHeight = insetsCompat.GetInsets(WindowInsetsCompat.Type.StatusBars()).Top;
usableWindowArea = usableWindowArea.Intersect(windowArea.Shrink(0, 0, statusBarHeight, 0));
}
Expand Down

0 comments on commit 7c15b4a

Please sign in to comment.