Skip to content

Conversation

Copy link

Copilot AI commented Oct 6, 2025

Problem

Users experience display glitches in the PDF viewer when switching between monitors with different resolutions or DPI settings (e.g., switching between a laptop's high-DPI display at 2880x1800 and an external monitor). The glitches persist until QuickLook is restarted, significantly impacting the user experience for those working with multiple displays.

Display glitch example

Root Cause

The WebView2 control used to render PDFs was not properly responding to DPI changes when Windows notifies applications of display setting changes. Without explicit handling, the WebView2 rendering becomes corrupted when DPI scaling factors change.

Solution

This PR implements DPI-aware rendering by:

  1. Subscribing to DPI change events: The WebpagePanel now listens for the Window.DpiChanged event when loaded
  2. Forcing WebView2 refresh: When a DPI change is detected, the code forces the WebView2 control to re-render by calling InvalidateVisual() and UpdateLayout()
  3. Proper cleanup: Event handlers are properly unsubscribed in the Dispose() method to prevent memory leaks

The implementation uses asynchronous dispatching at render priority to ensure smooth UI updates without blocking the main thread.

Changes

  • Added OnLoaded, OnUnloaded, and OnDpiChanged event handlers to WebpagePanel
  • Implemented UpdateRasterizationScale method to refresh WebView2 rendering
  • Enhanced Dispose method to properly clean up all event subscriptions
  • Fixed code quality issue with Color type ambiguity by using DrawingColor alias

Testing

The solution builds successfully with no errors. Manual testing is recommended on Windows with multiple monitors at different DPI settings to verify the fix resolves the reported glitches without requiring an application restart.

Original prompt

This section details on the original issue you should resolve

<issue_title>Display glitches when screen resolution changes</issue_title>
<issue_description>My laptop has a 2880*1800 screen. Whenever I plug my laptop into an external monitor (and use it instead) with a different resolution, the pdf viewer shows display glitches that can only be resolved by restarting quicklook. An example is shown in the screenshot.

Image</issue_description>

Comments on the Issue (you are @copilot in this section)

@emako Can you provide detailed screen information, such as the primary screen resolution and DPI, the second screen resolution and DPI, so that I can reproduce the problem
Fixes #5

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 5 commits October 6, 2025 05:25
Co-authored-by: emako <24737061+emako@users.noreply.github.com>
Co-authored-by: emako <24737061+emako@users.noreply.github.com>
Co-authored-by: emako <24737061+emako@users.noreply.github.com>
Co-authored-by: emako <24737061+emako@users.noreply.github.com>
Co-authored-by: emako <24737061+emako@users.noreply.github.com>
Copilot AI changed the title [WIP] Display glitches when screen resolution changes Fix display glitches when switching between monitors with different DPI settings Oct 6, 2025
Copilot finished work on behalf of emako October 6, 2025 05:34
Copilot AI requested a review from emako October 6, 2025 05:34
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.

Display glitches when screen resolution changes

2 participants