Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Window Scaling Issues with Mixed DPI Screens #17834

Open
boydpatterson opened this issue Dec 26, 2024 · 0 comments
Open

Window Scaling Issues with Mixed DPI Screens #17834

boydpatterson opened this issue Dec 26, 2024 · 0 comments
Labels
bug customer-priority Issue reported by a customer with a support agreement. os-windows

Comments

@boydpatterson
Copy link
Contributor

Describe the bug

We have noticed some issues opening owned windows in mixed DPI environments on Windows OS. When a window is shown without an owner, the DPI and size of the window are scaled appropriately no matter which screen the window is opened on. When a window is shown as a child to another window, however, the DPI or size may be incorrect.

Environment Configuration

The following environment was used for testing:

  • Windows 11 23H2 (OS Build 22635.4655)
  • Avalonia 11.2.3 (testing with 11.0.x and 11.1.x also noted with each issue)
  • Primary monitor is 100% DPI
  • Secondary monitor is 150% DPI

Unfortunately, I have not been able to test on other platforms to know if this is unique to Windows.

Avalonia Problems

❌ Window of Unspecified Size Has Incorrect Scale When Shown On Different Monitor than Owner

If the owning application is positioned on the secondary (high DPI) monitor and it opens a window on the primary (100% DPI) monitor, the content of the window is scaled correctly, but the title bar is rendered too large (high DPI scale, same as owner). This issue was present on Avalonia 11.0.x to 11.2.x (tested 11.0.0, 11.0.13, 11.2.0, 11.1.5, 11.2.0, and 11.2.3).

// With owner on secondary monitor
var owner = (Window)TopLevel.GetTopLevel(this);
var child = new Window() {
    // Position window on primary monitor
    Position = owner.Screens.Primary.Bounds.Position
};
child.Show(owner);

Similarly, if the owning application is positioned on the primary (100% DPI) monitor and it opens a window on the secondary (high DPI) monitor, the content of the window is scaled correctly, but the title bar is rendered too small (100% scale, same as owner). Note this issue appears to have been introduced with Avalonia 11.2.0 as it was not present with Avalonia 11.0 (tested 11.0.0 and 11.0.13) or 11.1 (tested 11.1.0 and 11.1.5).

// With owner on primary monitor
var owner = (Window)TopLevel.GetTopLevel(this);
var child = new Window() {
    // Position window on secondary monitor
    Position = GetSecondaryScreen().Bounds.Position
};
child.Show(owner);
...
Screen GetSecondaryScreen()
  => TopLevel.GetTopLevel(this).Screens.All.First(x => x.Scaling > 1.0);

In both scenarios, attempting to drag/move or drag/resize the window will result in the title bar updating to the correct scale.

❌ Window of Specific Size Displayed At Extra Large Size When Shown On High DPI Monitor with Owner on 100% DPI Monitor

If the owning application is positioned on the primary (100% DPI) monitor and it opens a child window to be located on the secondary (high DPI) monitor, the Width and Height of that window are adjusted multiple times resulting in the window display at a size close to if the window had been upscaled twice.

// With owner on primary monitor
var owner = (Window)TopLevel.GetTopLevel(this);
var child = new Window() {
    // Position 300x300 window on secondary monitor
    Width = 300,
    Height = 300,
    Position = GetSecondaryScreen().Bounds.Position
};
child.Show(owner);
...
Screen GetSecondaryScreen()
  => TopLevel.GetTopLevel(this).Screens.All.First(x => x.Scaling > 1.0);

Attempting to display this 300x300 window in my environment with a 150% DPI secondary monitor has varying results in recent Avalonia versions:

  • Avalonia 11.2 (tested 11.2.0 and 11.2.3) results in a window whose width is 735.33 and height is 712.66.
  • Avalonia 11.1 (tested 11.1.0 and 11.1.5) works "close enough" with width of 300.67 and height of 300, although it should be noted that opening a window without an owner results in a perfect 300x300 window.
  • Avalonia 11.0 (tested 11.0.0 and 11.0.13) essentially ignores the 300x300 size and displays at 1905x986 (which is the same size of a window opened on this monitor when no explicit size is given).

❌ Window of Specific Size Displayed At Slightly Incorrect Size When Shown On 100% DPI Monitor with Owner on High DPI Monitor

If the owning application is positioned on the secondary (high DPI) monitor and it opens a child window to be located on the primary (100% DPI) monitor, the Width and Height of that window are slightly off.

// With owner on secondary monitor
var owner = (Window)TopLevel.GetTopLevel(this);
var child = new Window() {
    // Position 300x300 window on primary monitor
    Width = 300,
    Height = 300,
    Position = owner.Screens.Primary.Bounds.Position
};
child.Show(owner);

Attempting to display this 300x300 window in my environment with a 150% DPI secondary monitor has varying results i recent Avalonia versions:

  • Avalonia 11.2 (tested 11.2.0 and 11.2.3) results in a window whose width is 317 and height is 294.
  • Avalonia 11.1 (tested 11.1.0 and 11.2.5) works as expected with 300x300 window.
  • Avalonia 11.0 (tested 11.0.0 and 11.0.13) works as expected with 300x300 window.

To Reproduce

See sample code above

Expected behavior

No response

Avalonia version

11.2.3

OS

Windows

Additional context

No response

@MikeCodesDotNET MikeCodesDotNET added the customer-priority Issue reported by a customer with a support agreement. label Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug customer-priority Issue reported by a customer with a support agreement. os-windows
Projects
None yet
Development

No branches or pull requests

3 participants