Skip to content

Enable per-monitor DPI for Win10 #8786

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

Merged
merged 1 commit into from
Apr 12, 2017
Merged

Conversation

zcbenz
Copy link
Contributor

@zcbenz zcbenz commented Feb 27, 2017

Close #5429.

@groundwater
Copy link
Contributor

I will test this with my Surface Pro 4 and non-high-DPI external monitor.

@kevinsawicki
Copy link
Contributor

I will test this with my Surface Pro 4 and non-high-DPI external monitor.

@groundwater have you had a chance to test this out yet?

Copy link
Contributor

@miniak miniak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider keeping the manifest entry instead of adding back the code.

@@ -32,7 +32,6 @@

<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think setting this via manifest is preferrable. You can also combine the <dpiAware> element with the new <dpiAwareness> element for Windows 10 build 1607 and higher to enable additional per-monitor DPI features.
https://msdn.microsoft.com/en-us/library/windows/desktop/aa374191.aspx

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may also want to look at what we added in Windows 10 Creators update which is detailed here: https://blogs.windows.com/buildingapps/2017/04/04/high-dpi-scaling-improvements-desktop-applications-windows-10-creators-update/#HBK3Qfrm4qbzWAEV.97

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-client area scaling is available via the following:

  1. PerMonitor tag + a call to EnableNonClinetDpiScaling() on 1607
  2. PerMonitorV2 on 1703 (no need for that additional API call)

You can also use a combination of tags that will be consumed differently on different versions of Windows:
true/pm (this will give you per-monitor (version 1) on >= 8.1 and system awareness on Vista to 8)
PerMonitorV2, PerMonitor will result in PerMonitorV2 on 1703 (Creators Update) and PerMonitor (version 1) on 1607 (Anniversary Update). When running on versions of Windows that consume this tag the tag will be ignored.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can probably work on this and I also have a combination of High/Low DPI screens running.
I think EnableNonClientDpiScaling is really important (or permonitorv2), i wouldn't go for true/pm only

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use True/PM instead of adding back the code

I didn't know this, it is much better!

PerMonitor tag + a call to EnableNonClinetDpiScaling() on 1607
PerMonitorV2 on 1703 (no need for that additional API call)

I agree it is important to have these, but I'm not sure whether they work well with Chromium's own UI framework. Can someone who has Windows running on multiple monitors test it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually plan to have a look at this. Leave it to me then, I'll make it work across all the different scenarios.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@alespergl alespergl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep using the manifest and adjust the value to true/pm

@poiru
Copy link
Contributor

poiru commented Apr 12, 2017

What do we think of merging this? I agree that we should ideally also have

<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">permonitorv2, permonitor</dpiAwareness>

... but it would be nice to have at least <dpiAware>true/pm</dpiAware> until we can confirm that permonitorv2 works properly.

@kevinsawicki kevinsawicki merged commit 1c44bcf into master Apr 12, 2017
@kevinsawicki kevinsawicki deleted the per-monitor-dpi-aware branch April 12, 2017 19:27
@kevinsawicki
Copy link
Contributor

What do we think of merging this? I agree that we should ideally also have

Yeah, sounds good 🚢

We can follow this up with more changes as well as pulling in anything via the Chrome 58 upgrade.

@alespergl
Copy link
Contributor

When is Chrome 58 coming in? The change @poiru mentioned would likely need to be backported if it's delayed.

@kevinsawicki
Copy link
Contributor

When is Chrome 58 coming in?

I believe @zcbenz is working through some offscreen window compilation issues right now that are being updated in #9116, no definite timeline at this time.

The change @poiru mentioned would likely need to be backported if it's delayed.

Understood, maybe we wait until the end of next week to see where Chrome 58 is then?

@alespergl
Copy link
Contributor

@kevinsawicki I created a PR for the backport, just in case.

@poiru
Copy link
Contributor

poiru commented Apr 17, 2017

On Win10 version 1607, this patch made the titlebar, scrollbars, etc. huge:

titlebar

Maybe EnableNonClinetDpiScaling() will fix this, but that's not available on all Windows 10 versions. Should we revert this patch? cc @alespergl

@peterfelts
Copy link

So it looks like before this change the process ran as system aware <dpiAware>true</dpiAware> and the change made it run under the original per-monitor mode <dpiAware>true/pm</dpiAware>. This would result in what @poiru is seeing: non-client area won't DPI scale on a DPI change. Getting the non-client area to scale (if Windows is drawing the non-client area, that is) wasn't supported until 1607 (via a call to EnableNonClinetDpiSacling(HWND)). What I would recommend is:

<dpiAware>true</dpiAware>
<dpiAwareness>PerMonitor</dpiAwareness>

  • call EnableNonClientDpiScaling()

This will result in the following behavior:

  1. Vista -> 1607 -> System Awareness (what I think was used before this change)
  2. >= 1607 -> per-monitor awareness and the non-client area will scale

Again, the non-client area will only scale if Windows is drawing it. I don't know how Electron draws its non-client area though. If its custom drawn, then Windows won't DPI scale it automatically.

@alespergl
Copy link
Contributor

alespergl commented Apr 17, 2017

@poiru Yes, EnableNonClientDpiScaling fixes it. There's no way to make this work universally, unless custom non-client drawing is implemented, or we don't do per-monitor DPI pre Win10 1607. That would result in blurred client area. Other per-monitor apps work the same. I think it's reasonable to expect most users upgrading their Win10 systems to the latest version, so I wouldn't optimize too much for earlier versions.
Btw dpiAwareness makes no difference here, it's simply a shortcoming of Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants