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

[Problem/Bug]: Screen details are incorrect and change unexpectedly in PerMonitorV2 DPI awareness mode #4826

Open
awolbach opened this issue Sep 20, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@awolbach
Copy link

What happened?

In our WinForms WebView2 application, when we enable the PerMonitorV2 DPI awareness mode (via ApplicationHighDpiMode) and then test on a workstation with multiple monitors set to different scaling percentages, the screen details returned by a call to await getScreenDetails(); are incorrect and also change depending on which monitor the application is showing on.

For example, I have two 1920x1080 monitors oriented horizontally, with my primary display on the left. When I set the scale of the primary monitor to 150% and launch my application on that display, the web application sees two 1280x720 screens with the same 1.5 devicePixelRatio, with one offset -360 pixels vertically from the other:

image

If I then move the application to my second, unscaled monitor, the devicePixelRatio changes to 1, and now the web application sees two 1920x1080 monitors, the right one still vertically offset but now horizontally overlapping the first display with a left value of 1280:

image

Edge does not have this problem. Regardless of which monitor the browser is on, it reports the primary screen as 1280x720 with a devicePixelRatio of 1.5, and the secondary screen as 1920x1080 with a devicePixelRatio of 1 (the negative offset remains; I am assuming Chromium chooses to bottom-align screens in this layout):

image

So the available layout seen by the web application is all over the place. If it wants to launch a second window with a size or position relative to the screen, like for example right-aligning the window on the primary display, it's going to send over values that will depend on where the web application is at that moment. Because this looks like a bug I am hesitant to write .NET code to interpret size and position based on the location of the WebView2 control requesting the new window, which might later change with a update.

Here's a simple sample app to repro the problem:
WebView2PerMonitorV2.zip

Importance

Important. My app's user experience is significantly compromised.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

128.0.2739.79

SDK Version

1.0.2739.15

Framework

Winforms

Operating System

Windows 11

OS Version

22631.4169

Repro steps

You'll need a workstation with two or more monitors to test this out.

  1. In Control Panel -> Display Settings, set the Scale value for your primary display to 150%
  2. Launch the application on the primary, scaled display
  3. Open Task Manager to the Details tab, add the DPI Awareness column, and confirm the application is running in "Per-Monitor (v2)" DPI awareness mode
  4. Put focus in the MSN website and press F12 to bring up the DevTools
  5. In the Console, execute: await window.getScreenDetails();
  6. Expand the ScreenDetailed objects and see they incorrectly have the same 1.5 devicePixelRatio and dimensions, and one display is vertically offset from the other
  7. Move the application to the unscaled display
  8. Back in the DevTools Console, execute: await window.getScreenDetails();
  9. Expand the ScreenDetailed objects again and see the devicePixelRatio has changed to 1, the dimensions of both screens have grown to their device size, they're still vertically offset, and they now horizontally overlap

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

Don't know

Last working version (if regression)

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants