Skip to content

Gate per-monitor DPI on GetDpiForMonitor availability - #22299

Merged
MrJul merged 1 commit into
AvaloniaUI:mainfrom
Davide244:Davide244/Fix22204
Oct 8, 2026
Merged

MrJul merged 1 commit into
AvaloniaUI:mainfrom
Davide244:Davide244/Fix22204

Conversation

@Davide244

@Davide244 Davide244 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

What does the pull request do?

Makes the Win32 backend check whether GetDpiForMonitor exists before using per-monitor DPI, instead of checking the reported Windows version.

What is the current behavior?

WindowImpl, FramebufferManager and TrayIconImpl only use GetDpiForMonitor when Win32Platform.WindowsVersion >= 8.1. Under an app compatibility shim, RtlGetVersion can report an older version (e.g. 6.0.6000) on Windows 11. The check then fails, RenderScaling stays at 1, and the window is too small at scales above 100%. Screens already reports the correct scaling because WinScreen checks with GetProcAddress.

What is the updated/expected behavior with this PR?

RenderScaling matches the monitor DPI even when the reported Windows version is spoofed.

How was the solution implemented (if it's not obvious)?

UnmanagedMethods.ShCoreAvailable is replaced by a cached GetDpiForMonitorAvailable, which uses the same GetProcAddress check WinScreen already had. All four call sites now use it.

Checklist

  • Added unit tests (if possible)?

No test: Win32Platform.WindowsVersion is read-only and set once from RtlGetVersion, so a spoofed version can't be simulated in a unit test.

Fixed issues

Fixes #22204

@github-actions

Copy link
Copy Markdown

NuGet packages

The packages for this pull request have been published (workflow run):

@MrJul MrJul added enhancement os-windows backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Sep 25, 2026

@MrJul MrJul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

WinScreen.cs already had this check, it makes sense to generalize it.
LGTM!

@MrJul

MrJul commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

The CLA needs to be accepted, but our bot is having trouble triggering the required comment.
Edit: it's below.

@cla-avalonia

cla-avalonia commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator
  • All contributors have signed the CLA.

@Davide244

Copy link
Copy Markdown
Contributor Author

@cla-avalonia agree

@MrJul
MrJul added this pull request to the merge queue Oct 8, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 8, 2026
@MrJul
MrJul added this pull request to the merge queue Oct 8, 2026
Merged via the queue into AvaloniaUI:main with commit 8f4b944 Oct 8, 2026
12 checks passed
@MrJul MrJul added backported-12.1.x and removed backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Oct 9, 2026
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.

Per-monitor DPI is ignored when RtlGetVersion is shimmed

3 participants