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 · 3 comments
Assignees
Labels
bug Something isn't working tracked We are tracking this work internally.

Comments

@awolbach
Copy link

awolbach commented Sep 20, 2024

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

AB#54587017

@johna-ms
Copy link
Contributor

Thanks for reporting this @awolbach. Looks like this is the same issue as #4551 which you have already found. I will close this issue for tracking purposes.

@johna-ms johna-ms closed this as not planned Won't fix, can't repro, duplicate, stale Oct 18, 2024
@awolbach
Copy link
Author

I see #4551 as specifically describing an issue with the types of the left and top window feature arguments. What I'm describing here is that the virtual screen arrangement presented by WebView2 to the website seems incorrect when the primary display is scaled. Edge reports different screen details for the same configuration which seems like a clear bug.

After I posted this though, I noticed https://www.w3.org/TR/window-management/ is only a working draft, so you tell me if WebView2 is not intended to conform to it yet.

@johna-ms
Copy link
Contributor

I'll reopen this as distinct. You're right @awolbach this is an issue about the reported screen position and the other issue is about the window position. That's my mistake.

WebView2 behavior should align with Edge's. So even if the standard is a working draft, if the browser appears to implement it properly WebView2 should too. I'll put this on our backlog.

@johna-ms johna-ms reopened this Oct 21, 2024
@johna-ms johna-ms added the tracked We are tracking this work internally. label Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

2 participants