Skip to content

Commit

Permalink
fix #1795
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightczx committed Jul 6, 2024
1 parent 1cd6aad commit e230d7a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void Unload()
}
}

public RectInt32 InitializePosition(RectInt32 parentRect)
public RectInt32 InitializePosition(RectInt32 parentRect, double parentDpi)
{
// Parent Window can never be so small
// if (parentRect.Width < 96 || parentRect.Height < 96)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal interface IWebView2ContentProvider

ValueTask InitializeAsync(IServiceProvider serviceProvider, CancellationToken token);

RectInt32 InitializePosition(RectInt32 parentRect);
RectInt32 InitializePosition(RectInt32 parentRect, double parentDpi);

void Unload();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.

using Microsoft.Graphics.Display;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
Expand Down Expand Up @@ -70,11 +71,11 @@ public void Unload()
jsBridge?.Detach();
}

public RectInt32 InitializePosition(RectInt32 parentRect)
public RectInt32 InitializePosition(RectInt32 parentRect, double parentDpi)
{
PointInt32 center = parentRect.GetPointInt32(PointInt32Kind.Center);
RectInt32 target = new(center.X - 240, center.Y - 400, 450, 800);

SizeInt32 size = new SizeInt32(480, 800).Scale(parentDpi);
RectInt32 target = RectInt32Convert.RectInt32(new(center.X - (size.Width / 2), center.Y - (size.Height / 2)), size);
RectInt32 workArea = DisplayArea.GetFromRect(parentRect, DisplayAreaFallback.None).WorkArea;
RectInt32 workAreaShrink = new(workArea.X + 48, workArea.Y + 48, workArea.Width - 96, workArea.Height - 96);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public WebView2Window(WindowId parentWindowId, IWebView2ContentProvider contentP
EnableWindow(parentHWND, false);
base.Activate();

AppWindow.MoveThenResize(contentProvider.InitializePosition(parentAppWindow.GetRect()));
double dpi = Math.Round(GetDpiForWindow(parentHWND) / 96D, 2, MidpointRounding.AwayFromZero);
AppWindow.MoveThenResize(contentProvider.InitializePosition(parentAppWindow.GetRect(), dpi));
}

public void OnWindowClosed()
Expand Down

0 comments on commit e230d7a

Please sign in to comment.