From c3612a9466a6bb7fbb7315a6cf8c97f5adeb4ad3 Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Thu, 31 Oct 2024 14:14:59 +0100 Subject: [PATCH 1/4] fix: Ensure WPF adheres to physical Position and Size on AppWindow (cherry picked from commit 5c16cd000a1da54a770c1bd30d596f32e25c49ce) --- .../UI/Controls/WpfWindowWrapper.cs | 14 +++++++------- .../Xaml/Window/Native/NativeWindowWrapperBase.cs | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Uno.UI.Runtime.Skia.Wpf/UI/Controls/WpfWindowWrapper.cs b/src/Uno.UI.Runtime.Skia.Wpf/UI/Controls/WpfWindowWrapper.cs index 646af200d362..ffdccb761073 100644 --- a/src/Uno.UI.Runtime.Skia.Wpf/UI/Controls/WpfWindowWrapper.cs +++ b/src/Uno.UI.Runtime.Skia.Wpf/UI/Controls/WpfWindowWrapper.cs @@ -45,18 +45,18 @@ private void UpdateSizeFromNative() { if (!_wasShown) { - Size = new() { Width = (int)_wpfWindow.Width, Height = (int)_wpfWindow.Height }; + Size = new() { Width = (int)(_wpfWindow.Width * RasterizationScale), Height = (int)(_wpfWindow.Height * RasterizationScale)}; } else { - Size = new() { Width = (int)_wpfWindow.ActualWidth, Height = (int)_wpfWindow.ActualHeight }; + Size = new() { Width = (int)(_wpfWindow.ActualWidth * RasterizationScale), Height = (int)(_wpfWindow.ActualHeight * RasterizationScale)}; } } private void OnNativeLocationChanged(object? sender, EventArgs e) => UpdatePositionFromNative(); private void UpdatePositionFromNative() => - Position = new() { X = (int)_wpfWindow.Left, Y = (int)_wpfWindow.Top }; + Position = new() { X = (int)(_wpfWindow.Left * RasterizationScale), Y = (int)(_wpfWindow.Top * RasterizationScale)}; private void OnNativeStateChanged(object? sender, EventArgs e) => UpdateIsVisible(); @@ -165,8 +165,8 @@ protected override IDisposable ApplyOverlappedPresenter(OverlappedPresenter pres public override void Move(PointInt32 position) { - _wpfWindow.Left = position.X; - _wpfWindow.Top = position.Y; + _wpfWindow.Left = position.X / RasterizationScale; + _wpfWindow.Top = position.Y / RasterizationScale; if (!_wasShown) { @@ -177,8 +177,8 @@ public override void Move(PointInt32 position) public override void Resize(SizeInt32 size) { - _wpfWindow.Width = size.Width; - _wpfWindow.Height = size.Height; + _wpfWindow.Width = size.Width / RasterizationScale; + _wpfWindow.Height = size.Height / RasterizationScale; if (!_wasShown) { diff --git a/src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapperBase.cs b/src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapperBase.cs index 090475d9a39e..9e568ceaa1ff 100644 --- a/src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapperBase.cs +++ b/src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapperBase.cs @@ -33,7 +33,7 @@ internal abstract class NativeWindowWrapperBase : INativeWindowWrapper private CoreWindowActivationState _activationState; private XamlRoot? _xamlRoot; private Window? _window; - private float _rasterizationScale; + private float _rasterizationScale = 1f; private readonly SerialDisposable _presenterSubscription = new SerialDisposable(); protected NativeWindowWrapperBase(Window window, XamlRoot xamlRoot) : this() From b6af3240b36801b0cf5827d02d10ebad557dae99 Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Fri, 1 Nov 2024 13:41:39 +0100 Subject: [PATCH 2/4] chore: Formatting (cherry picked from commit df4937803dd0a2f86d16a7c053e7e43895afb093) --- src/Uno.UI.Runtime.Skia.Wpf/UI/Controls/WpfWindowWrapper.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Uno.UI.Runtime.Skia.Wpf/UI/Controls/WpfWindowWrapper.cs b/src/Uno.UI.Runtime.Skia.Wpf/UI/Controls/WpfWindowWrapper.cs index ffdccb761073..fb7a304d5771 100644 --- a/src/Uno.UI.Runtime.Skia.Wpf/UI/Controls/WpfWindowWrapper.cs +++ b/src/Uno.UI.Runtime.Skia.Wpf/UI/Controls/WpfWindowWrapper.cs @@ -45,18 +45,18 @@ private void UpdateSizeFromNative() { if (!_wasShown) { - Size = new() { Width = (int)(_wpfWindow.Width * RasterizationScale), Height = (int)(_wpfWindow.Height * RasterizationScale)}; + Size = new() { Width = (int)(_wpfWindow.Width * RasterizationScale), Height = (int)(_wpfWindow.Height * RasterizationScale) }; } else { - Size = new() { Width = (int)(_wpfWindow.ActualWidth * RasterizationScale), Height = (int)(_wpfWindow.ActualHeight * RasterizationScale)}; + Size = new() { Width = (int)(_wpfWindow.ActualWidth * RasterizationScale), Height = (int)(_wpfWindow.ActualHeight * RasterizationScale) }; } } private void OnNativeLocationChanged(object? sender, EventArgs e) => UpdatePositionFromNative(); private void UpdatePositionFromNative() => - Position = new() { X = (int)(_wpfWindow.Left * RasterizationScale), Y = (int)(_wpfWindow.Top * RasterizationScale)}; + Position = new() { X = (int)(_wpfWindow.Left * RasterizationScale), Y = (int)(_wpfWindow.Top * RasterizationScale) }; private void OnNativeStateChanged(object? sender, EventArgs e) => UpdateIsVisible(); From 1741188cca46f8a7b531c70bbbfd30b78e2af9ad Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Fri, 1 Nov 2024 14:35:57 +0100 Subject: [PATCH 3/4] chore: Undo invalid change (cherry picked from commit 700a60c81f47b760af52ce27449f08082ff3592f) --- src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapperBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapperBase.cs b/src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapperBase.cs index 9e568ceaa1ff..090475d9a39e 100644 --- a/src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapperBase.cs +++ b/src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapperBase.cs @@ -33,7 +33,7 @@ internal abstract class NativeWindowWrapperBase : INativeWindowWrapper private CoreWindowActivationState _activationState; private XamlRoot? _xamlRoot; private Window? _window; - private float _rasterizationScale = 1f; + private float _rasterizationScale; private readonly SerialDisposable _presenterSubscription = new SerialDisposable(); protected NativeWindowWrapperBase(Window window, XamlRoot xamlRoot) : this() From 9d8c5df22913bba7d0b0e27a50e50cd003210d7e Mon Sep 17 00:00:00 2001 From: Ramez Ragaa Date: Mon, 4 Nov 2024 12:26:16 +0200 Subject: [PATCH 4/4] chore: fix When__Before_Activate (cherry picked from commit df0796cc84224ce2103f05ebf6eb63402a183487) --- src/Uno.UI.Runtime.Skia.Wpf/UI/Controls/WpfWindowWrapper.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Uno.UI.Runtime.Skia.Wpf/UI/Controls/WpfWindowWrapper.cs b/src/Uno.UI.Runtime.Skia.Wpf/UI/Controls/WpfWindowWrapper.cs index fb7a304d5771..e8d51e8536b3 100644 --- a/src/Uno.UI.Runtime.Skia.Wpf/UI/Controls/WpfWindowWrapper.cs +++ b/src/Uno.UI.Runtime.Skia.Wpf/UI/Controls/WpfWindowWrapper.cs @@ -32,9 +32,12 @@ public WpfWindowWrapper(UnoWpfWindow wpfWindow, WinUIWindow window, XamlRoot xam _wpfWindow.DpiChanged += OnNativeDpiChanged; _wpfWindow.StateChanged += OnNativeStateChanged; _wpfWindow.Host.SizeChanged += (_, e) => OnHostSizeChanged(e.NewSize); - OnHostSizeChanged(new Size(_wpfWindow.Width, _wpfWindow.Height)); _wpfWindow.LocationChanged += OnNativeLocationChanged; _wpfWindow.SizeChanged += OnNativeSizeChanged; + + RasterizationScale = (float)VisualTreeHelper.GetDpi(_wpfWindow.Host).DpiScaleX; + + OnHostSizeChanged(new Size(_wpfWindow.Width, _wpfWindow.Height)); UpdateSizeFromNative(); UpdatePositionFromNative(); } @@ -72,7 +75,6 @@ public override string Title protected override void ShowCore() { - RasterizationScale = (float)VisualTreeHelper.GetDpi(_wpfWindow.Host).DpiScaleX; _wpfWindow.Show(); _wasShown = true; UpdatePositionFromNative();