-
Notifications
You must be signed in to change notification settings - Fork 965
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
DPI scaling for Windows 10 and later #982
Conversation
Observations on Windows 11 when changing DPI from 100% to 200% while the app is running:
|
There's a problem with trusting the suggested window bounds we get when handling |
477b94b
to
42041e3
Compare
The latest code calculates the new scaled window size inside |
The work with scaling with DPI changes wasn't as easy as I imagined it would be. @sdicker8 If you find the time to check whether this PR is satisfactory for you then it would be of great help. I'll do more testing later as well as I've only tested the new code on Windows 10. Do you see any room for optimization here? Aside for whether it works properly, I'm particularly interested in your opinion about the calculations in |
It does look like you had to touch the code in several different places. I probably would have had a difficult time with some of that. Unfortunately, this version doesn't work on my win 11 laptop. If i'm at 100% and start the app it looks fine. If i then scale up, it scales the window too much. Also, if i start the app at a scale that is greater than 100%, it's too small - just like the original problem. As a slight aside, regarding the apparent difference between windows 10 & 11, there was a windows 10 version number associated with some of the api - i was wondering if your version was less than that. As for the set_size function you have to know that i tend to have a very minimalistic coding style. I would personally stay away from floating point math here - i just see no need for it (but i do like your epsilon check). I would probably just use a simple 'get_window_dpi' function, use the result from that in any required logic, and completely avoid scale and the scale type. If and when you need to scale the width and height you could just make sure to divide by the default_dpi last and you will have a correct integer result. Having to do that 'undo' stuff seemed unfortunate - i'm wondering if that would still be there once the problems that i'm seeing on win11 are ironed out. Sorry - i wish i could have given you a better win11 report and sorry that the complexity turned out to be so much. I'll be happy to test again - |
Also got rid of floating point arithmetic.
Oh, my bad. I was focusing on the changing DPI and didn't realize that it wasn't scaling properly on startup anymore. I've looked into that also got rid of the floating point arithmetic. The complexity is still greater than I would like but first of all we need to get it to work reliably. This now appears to work properly on my Windows 10 system but there's a problem on Windows 11. On Windows 11, at the time we receive It would have been easy if we could just skip our own calculations on Windows 11 but the new dimensions of the window after the automatic scaling done by Windows 11 are really unexpected. On my system it goes from 480x320 at 100% to something greater than the expected 960x640. This result is similar to when we just use the suggested dimensions provided by |
|
The library uses per monitor awareness (v1, not v2).
Source: https://learn.microsoft.com/en-us/windows/win32/hidpi/dpi-awareness-context To me the statement that "processes are not automatically scaled by the system" just doesn't seem to be true on Windows 11 during a DPI change. |
If we just enable DPI awareness through a manifest file without also actually adding the logic to make it DPI-aware then it looks like this: Here the button isn't scaled in either example, The top-level window scales automatically on Windows 11 (weird) but not on Windows 10. |
there is also this on that site: |
On Windows 10, the size we get when handling On Windows 11, what we receive when handling It's hard to believe that this is functioning as intended. |
bd782bc
to
77748b9
Compare
Still looks good on my machine. And, for what i understand, i like your changes. Wish i had more experience with the win api so that i could help with understanding the weirdness -- seems to me like you are really getting there though - |
aafea46
to
f0642fa
Compare
|
I believe this is finally good to go. |
Still looking good on my machine. I get a couple of minor warnings with /W4 Great work with significant impact! thank you - |
Thank you! I'll take a look at the warnings. Do you see any new warnings other than |
these are what i see: webview.h(1525): warning C4456: declaration of 'fn' hides previous local declaration |
I've sorted out the new |
I've submitted #995 for the C4100 warnings. |
Scales when the DPI setting changes on the window's display:
change_dpi.webm
Scales when moving window to display with different DPI:
move_between_displays.webm
Test cases
*set_size()
.Result for 5defd8c (
master
)Result for b7a05b5