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

win32: Fix edge-case bug with DPI scaling #16143

Merged
merged 2 commits into from
Jun 27, 2024

Conversation

grokys
Copy link
Member

@grokys grokys commented Jun 26, 2024

What does the pull request do?

Fixes an issue reported to us by @danipen that can be reproduced by https://github.com/danipen/AvaloniaDpiIssue:

  • Have two monitors, the primary monitor with 125% scaling the secondary with 100% scaling
  • Run the repro
  • Move the window to the secondary monitor
  • Show the dialog
  • See that the dialog is cropped

This appears to be caused by a win32 bug. Not sure I can describe it any better than the in-code comment:

// I can't find mention of this *anywhere* online, but it seems that setting
// GWL_HWNDPARENT to a window which is on the non-primary monitor can cause two
// WM_DPICHANGED messages to be sent: the first changing the DPI to the parent's DPI,
// then another changing the DPI back. This then causes Windows to provide an incorrect
// suggested new rectangle to the WM_DPICHANGED message if the window is immediately
// moved to the parent window's monitor (e.g. when using
// WindowStartupLocation.CenterOwner) causing the window to be shown with an incorrect
// size.
//
// Just ignore any WM_DPICHANGED while we're setting the parent as this shouldn't
// change the DPI anyway.

The solution seems to be to simply ignore DPI changes while GWL_HWNDPARENT is being set.

Not sure I can describe it any better than the in-code comment.
Copy link
Member

@maxkatz6 maxkatz6 left a comment

Choose a reason for hiding this comment

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

Looks weird, but let's see if it regresses on master with anything

@maxkatz6 maxkatz6 merged commit ef014fc into master Jun 27, 2024
2 of 10 checks passed
@maxkatz6 maxkatz6 deleted the fixes/win32-dpi-scaling-issue branch June 27, 2024 21:14
maxkatz6 added a commit that referenced this pull request Jun 28, 2024
Not sure I can describe it any better than the in-code comment.

Co-authored-by: Max Katz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants