Skip to content

Support Per-Monitor (V2): Fix Markdown preview misalignment after DPI change - #1988

Open
walterlv wants to merge 1 commit into
QL-Win:masterfrom
walterlv:t/walterlv/per-monitor-v2
Open

Support Per-Monitor (V2): Fix Markdown preview misalignment after DPI change#1988
walterlv wants to merge 1 commit into
QL-Win:masterfrom
walterlv:t/walterlv/per-monitor-v2

Conversation

@walterlv

@walterlv walterlv commented Aug 21, 2026

Copy link
Copy Markdown

PR Checklist

  • Functionality has been tested, no obvious bugs
  • Code style follows project conventions
  • Documentation/comments updated (if applicable)

Brief Description of Changes

Please briefly describe the main changes in this PR:

  • Before: Per-Monitor (V1) support, which has bugs with child windows (such as the Markdown Preview child window)
  • After: Per-Monitor (V2) support, which now behaves correctly for the Windows non-client area and child windows.

I've written a blog post describing how to support Per-Monitor V2 correctly, especially on .NET Framework 4.6.2.

Previous related issues:

This PR is the correct fix for the issue, replacing the incorrect commit 97f8232.

Related Issue (if any)

Please provide related issue numbers: No related issues.

Additional Notes

Add any extra notes here:

Before:

图片

▲ DPI 150% -> 100%

图片

▲ DPI 100% -> 150%

After:

图片

Summary by Sourcery

Enable Per-Monitor V2 DPI awareness to keep QuickLook windows correctly aligned and scaled across monitor DPI changes.

Bug Fixes:

  • Fix Markdown preview and other child-window alignment when moving between monitors with different DPI settings.

Enhancements:

  • Adopt Windows Per-Monitor V2 DPI awareness for correct non-client area and child-window scaling behavior.
  • Consolidate DPI awareness configuration in the application manifest and remove the previous runtime DPI-awareness setup.

Chores:

  • Remove obsolete DPI-awareness interop code and related assembly configuration.

@sourcery-ai

sourcery-ai Bot commented Aug 21, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Switches DPI handling from explicit Per-Monitor V1 setup in code to proper Per-Monitor V2 configuration via application manifest, cleaning up obsolete DPI-awareness code and comments related to older .NET behavior.

Sequence diagram for DPI awareness initialization change to Per-Monitor V2

sequenceDiagram
    participant Windows_OS
    participant QuickLook_App
    participant SHCore

    rect rgb(230,230,230)
    Windows_OS->>QuickLook_App: Load process (startup)
    end

    alt Before_PR_PerMonitor_V1
        QuickLook_App->>QuickLook_App: static App constructor
        QuickLook_App->>SHCore: SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE)
        SHCore-->>QuickLook_App: result
        QuickLook_App->>QuickLook_App: RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly
    else After_PR_PerMonitor_V2
        Windows_OS->>Windows_OS: Read app.manifest (PerMonitorV2)
        Windows_OS->>QuickLook_App: Initialize with Per-Monitor V2 DPI
        QuickLook_App->>QuickLook_App: static App constructor
        QuickLook_App->>QuickLook_App: RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly
    end
Loading

File-Level Changes

Change Details Files
Remove explicit runtime DPI awareness configuration in favor of manifest-based Per-Monitor V2 handling.
  • Delete the SHCore P/Invoke helper used to call SetProcessDpiAwareness.
  • Remove the static App constructor code that invoked SetProcessDpiAwareness and logged the result.
  • Drop the unnecessary Debug using now that no debug logging is performed there.
QuickLook/App.xaml.cs
QuickLook/NativeMethods/SHCore.cs
Align assembly and manifest DPI settings with Per-Monitor V2 guidance for the target .NET Framework version.
  • Clean up outdated comment about using DisableDpiAwareness for .NET versions above 4.6.2, which is no longer applicable with the new DPI approach.
  • Adjust application manifest DPI-awareness entries to rely on OS-level Per-Monitor V2 instead of legacy configuration.
  • Update App.config and manifest metadata as needed to match the new DPI-awareness model.
QuickLook/Properties/AssemblyInfo.cs
QuickLook/app.manifest
QuickLook/App.config

Possibly linked issues

  • #(not specified): Yes. PR’s Per-Monitor V2 DPI fix specifically addresses Markdown preview misalignment after screen scaling changes described in issue.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@walterlv

walterlv commented Aug 21, 2026

Copy link
Copy Markdown
Author

Previous fixes only swapped one Per-Monitor V1 setup for another. The real fix is to drop the buggy V1 path and use V2.


I have verified this PR on my machine.

Testing tip: The most reliable way to verify this fix is to preview a Markdown or HTML file. The important difference between Per-Monitor V1 and V2 is child-window DPI awareness; hosted WebView/browser HWNDs only pick up the correct scale under V2. WPF-only viewers can look fine on both, so they are easy to misread.

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.

1 participant