Skip to content

fix(v3/windows): resync WebView2 rasterization scale after minimise/restore - #5572

Merged
leaanthony merged 7 commits into
masterfrom
fix/dpi-restore-resync-5544
Jun 13, 2026
Merged

leaanthony merged 7 commits into
masterfrom
fix/dpi-restore-resync-5544

Conversation

@leaanthony

@leaanthony leaanthony commented Jun 11, 2026 •

Copy link
Copy Markdown
Member

Description

On mixed-DPI Windows systems, a frameless window's window.devicePixelRatio adopts the wrong monitor's scale after maximize → minimize → restore (e.g. stuck at 1.25 on a 200% display) until a manual resize fixes it. Confirmed by the reporter with detailed diagnostics on a 200%/125% dual-monitor setup — including with DisableFramelessWindowDecorations: true, ruling out the DWM decorations path.

Root cause

Wails runs WebView2 in raw-pixels bounds mode and explicitly disables ShouldDetectMonitorScaleChanges — which makes the rasterization scale the app's responsibility — but nothing in the codebase ever calls PutRasterizationScale after controller creation. A minimised window is parked at (-32000,-32000), which can re-associate it with another monitor's DPI; on restore, no WM_DPICHANGED corrects the webview, so the stale scale persists. A manual drag-resize happens to trigger the missing resync, which is exactly the reporter's observed workaround.

Fix

New resyncWebviewRasterizationScale() — reads GetDpiForWindow-based DPI and re-asserts controller3.PutRasterizationScale(dpi/96). Invoked:

  1. on restore-from-minimise (SIZE_RESTORED while isMinimizing) — the reported case with no corrective event;
  2. in WM_DPICHANGED — the natural owner of scale updates given auto-detection is off, covering ordinary monitor crossings.

No-op when the controller is unavailable or the scale already matches, so single-DPI setups see zero behaviour change.

Verification

Fixes #5544

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the general coding style of this project
  • I have updated v3/UNRELEASED_CHANGELOG.md

Summary by CodeRabbit

  • Bug Fixes
    • Fixed incorrect window scaling on Windows with mixed-DPI displays so visuals render at the correct size after restoring from minimized.
    • Made devicePixelRatio and rendering/rasterization scale update more reliably on restore and when display DPI changes, reducing blurry or mis-scaled content after minimize/restore or monitor switches.

…estore

Wails runs WebView2 in raw-pixels bounds mode with
ShouldDetectMonitorScaleChanges disabled, which makes the rasterization
scale the application's responsibility — but nothing ever set it after
controller creation. While a window is minimised it is parked at
(-32000,-32000), which on mixed-DPI systems can re-associate it with a
different monitor's DPI; on restore nothing corrected the scale, so
window.devicePixelRatio kept the wrong monitor's value (e.g. 1.25 on a
200% display) and content rendered at the wrong size until a manual
resize forced a resync. Reproduced consistently by the reporter on a
200%/125% dual-monitor setup, including with
DisableFramelessWindowDecorations enabled.

Add resyncWebviewRasterizationScale(), invoked on restore-from-minimise
and in the WM_DPICHANGED handler (the natural owner of scale updates
now that auto-detection is off). It is a no-op when the controller is
unavailable or the scale already matches, so single-DPI setups are
unaffected.

Verified: build and pkg/application suite pass on Windows; vet output
identical to master. Mixed-DPI behaviour needs a physical multi-monitor
setup — reporter verification requested on the issue.

Fixes #5544
Copilot AI review requested due to automatic review settings June 11, 2026 00:40
@coderabbitai

coderabbitai Bot commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds helpers to re-sync WebView2 rasterization scale from the window DPI and invokes them on restore-from-minimise and on WM_DPICHANGED; updates changelog documenting the mixed‑DPI minimise/restore devicePixelRatio fix.

Changes

Mixed-DPI Rasterization Scale Fix

Layer / File(s) Summary
Rasterization scale resync helper
v3/pkg/application/webview_window_windows.go
New resyncWebviewRasterizationScale() and resyncWebviewDPIAfterMinimise() compute target rasterization scale from window DPI (dpi/96), compare with the controller's current rasterization scale, call PutRasterizationScale when different, no-op when controller/DPI unavailable, and trigger chromium.Resize() after minimise-resume when an update occurred.
Integration on restore and DPI changes
v3/pkg/application/webview_window_windows.go
WM_SIZE handlers now call the DPI/rasterization resync helper when leaving minimized state for maximized and restored windows. WM_DPICHANGED guards suggested-rect restore bookkeeping while minimized (unless enabled) and calls resyncWebviewRasterizationScale() after the layered hit-test refresh.
Changelog documentation
v3/UNRELEASED_CHANGELOG.md
Adds a "Fixed" changelog entry describing that window.devicePixelRatio now updates correctly after minimise/restore on mixed‑DPI Windows and references #5544.

Sequence Diagram

sequenceDiagram
  participant WndProc as Window WndProc
  participant Layered as LayeredHitTestRefresh
  participant WebviewController as ICoreWebView2Controller3
  participant Chromium as ChromiumResize

  WndProc->>WebviewController: resyncWebviewRasterizationScale() (compute targetScale from DPI, compare)
  WndProc->>Layered: refresh layered hit-test (WM_DPICHANGED path)
  Layered->>WebviewController: resyncWebviewRasterizationScale() (post-refresh)
  WebviewController-->>WndProc: PutRasterizationScale(targetScale) / success or error
  alt rasterization changed after minimise
    WndProc->>Chromium: chromium.Resize()
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • wailsapp/wails#4478: Also adjusts WM_SIZE handling for minimize/restore transitions in webview_window_windows.go.
  • wailsapp/wails#5371: Touches WM_DPICHANGED layered hit-test refresh logic in the same file and code path.
  • wailsapp/wails#5382: Modifies WM_SIZE handling around minimize/maximize/restore transitions in the same source file.

Suggested labels

Bug, Windows, v3, size:M, Documentation, lgtm

Poem

🐰
A pixel hopped from screen to screen,
Lost its DPI, not what it seemed.
We nudged the webview back in place,
Restored the scale, restored its grace.
Frameless windows now wear a steady face.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(v3/windows): resync WebView2 rasterization scale after minimise/restore' is concise, clear, and directly describes the main fix being implemented.
Description check ✅ Passed The PR description provides detailed context, root cause analysis, the fix, verification details, issue reference, type of change checkbox, and checklist confirmation. It follows the template requirements.
Linked Issues check ✅ Passed The PR implements the core objective from #5544: resync WebView2 rasterization scale on restore and WM_DPICHANGED to fix incorrect devicePixelRatio on mixed-DPI systems. The changes directly address the frameless window viewport synchronization issue.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the mixed-DPI viewport issue: rasterization scale resync logic, WM_SIZE/WM_DPICHANGED handling, and changelog update. No unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/dpi-restore-resync-5544

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a Windows mixed-DPI issue where a frameless WebView2 window can keep a stale window.devicePixelRatio after minimize/restore by explicitly resynchronizing WebView2’s rasterization scale with the window DPI.

Changes:

  • Add a resyncWebviewRasterizationScale() helper that reads window DPI and re-applies PutRasterizationScale(dpi/96) when needed.
  • Invoke the resync on restore-from-minimize (SIZE_RESTORED while minimizing) and on WM_DPICHANGED.
  • Document the fix in v3/UNRELEASED_CHANGELOG.md.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
v3/pkg/application/webview_window_windows.go Adds rasterization scale resync helper and hooks it into minimize/restore + DPI-change message handling.
v3/UNRELEASED_CHANGELOG.md Adds a changelog entry describing the Windows mixed-DPI minimize/restore fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
v3/pkg/application/webview_window_windows.go (1)

1878-1903: Fix float equality style in resyncWebviewRasterizationScale (controller method is available)

  • Guard clauses and DPI→scale computation are solid.
  • controller.GetICoreWebView2Controller3() is valid: GetController() returns *ICoreWebView2Controller, and that type defines GetICoreWebView2Controller3().
  • Minor: the exact float equality check current == scale (line ~1897) is likely fine for common DPI values, but a small tolerance (or skipping the equality optimization) would be more robust.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@v3/pkg/application/webview_window_windows.go` around lines 1878 - 1903,
resyncWebviewRasterizationScale currently uses exact float equality between
controller3.GetRasterizationScale() and computed scale which can be brittle;
update the check in windowsWebviewWindow.resyncWebviewRasterizationScale to
compare with a small epsilon (e.g. math.Abs(current-scale) < epsilon) or simply
always call controller3.PutRasterizationScale when DPI changed, referencing
GetRasterizationScale and PutRasterizationScale to determine/assign the new
rasterization scale; keep existing guards (controller :=
w.chromium.GetController(), controller3 :=
controller.GetICoreWebView2Controller3(), dpiX := w.DPI()) and preserve the
globalApplication.error call for PutRasterizationScale failures.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@v3/pkg/application/webview_window_windows.go`:
- Around line 1878-1903: resyncWebviewRasterizationScale currently uses exact
float equality between controller3.GetRasterizationScale() and computed scale
which can be brittle; update the check in
windowsWebviewWindow.resyncWebviewRasterizationScale to compare with a small
epsilon (e.g. math.Abs(current-scale) < epsilon) or simply always call
controller3.PutRasterizationScale when DPI changed, referencing
GetRasterizationScale and PutRasterizationScale to determine/assign the new
rasterization scale; keep existing guards (controller :=
w.chromium.GetController(), controller3 :=
controller.GetICoreWebView2Controller3(), dpiX := w.DPI()) and preserve the
globalApplication.error call for PutRasterizationScale failures.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: be8124f5-6ab0-4e0f-954d-6c8d7495928c

📥 Commits

Reviewing files that changed from the base of the PR and between 2633f81 and e3236b5.

📒 Files selected for processing (2)
  • v3/UNRELEASED_CHANGELOG.md
  • v3/pkg/application/webview_window_windows.go

Verification on a 200%/125% mixed-DPI setup showed the rasterization
scale now recovers on restore, but the window bounds did not: a
WM_DPICHANGED delivered while the window is parked at (-32000,-32000)
carries a suggested rect scaled for the wrong monitor, and applying it
rewrites the window's restore bookkeeping (a maximised 1920x1080 window
came back as 3072x1728). Skip the suggested-rect resize while
minimised; the scale resync still runs, and a fresh WM_DPICHANGED with
a correct rect arrives if the DPI genuinely differs on restore.
@leaanthony

Copy link
Copy Markdown
Member Author

Round 2 from reporter verification on real 200%/125% hardware: the rasterization-scale resync worked (dpr recovers), but a WM_DPICHANGED delivered while minimised was applying a wrong-monitor suggested rect, corrupting the restore bounds (maximised 1920×1080 → restored 3072×1728). New commit skips the suggested-rect resize while isMinimizing. Companion fix for the Eval crash their testing exposed is on #5568. Reporter re-verification requested.

…s re-put

Reporter verification round 2 (200%/125% hardware) showed two gaps:

1. Their window is maximised, so leaving the minimised state delivers
   WM_SIZE with SIZE_MAXIMIZED, not SIZE_RESTORED — the resync hook
   never ran on that path. Both transitions now share
   resyncWebviewDPIAfterMinimise.

2. Re-putting the rasterization scale alone does not make WebView2
   re-lay out content whose bounds are unchanged: dpr recovered but the
   page kept sizes computed with the stale scale (3072x1728 instead of
   1920x1080) until a manual resize re-asserted bounds. When the resync
   actually corrects a drifted scale, the current bounds are now
   re-put via chromium.Resize() to force the re-layout.

Refs #5544
@leaanthony

Copy link
Copy Markdown
Member Author

Round 3 from reporter verification: (1) the un-minimise resync now also covers windows returning to the maximised state (SIZE_MAXIMIZED while isMinimizing — the reporter's actual path; round 2 only hooked SIZE_RESTORED), and (2) when the resync corrects a drifted scale it now re-puts the current bounds via chromium.Resize(), since a scale change alone doesn't make WebView2 re-lay out unchanged bounds (the root of the lingering 3072×1728). Build + suite green on win-node1; reporter re-verification in progress.

Review follow-up (#5544): GetRasterizationScale returns a float that may
not be bit-identical to dpi/96 for non-25% DPI steps, so an exact ==
could re-Put the scale on every resync. Use a small tolerance.
@leaanthony
leaanthony merged commit 52b3529 into master Jun 13, 2026
21 of 25 checks passed
@leaanthony
leaanthony deleted the fix/dpi-restore-resync-5544 branch June 13, 2026 23:01
sinspired added a commit to sinspired/wails that referenced this pull request Jun 20, 2026
…ailsapp#5572

On Windows, 52b3529 (wailsapp#5572) unconditionally resynced WebView2 rasterization scale in the minimize/restore path.
That caused even normal same-DPI minimize/restore cycles to enter the WebView2 reconfiguration path and race with
ResizeWithBounds() during restore, which could leave the content area blank and, in some cases, crash the app.

This change records the DPI before minimizing and only resyncs WebView2 rasterization scale when the DPI after restore
actually differs from the pre-minimize DPI. It keeps the cross-monitor DPI fix needed for wailsapp#5544 while avoiding unnecessary
Controller3 updates during ordinary minimize/restore cycles.
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.

[Windows] Frameless window reports incorrect innerWidth/innerHeight after minimize and restore on high-DPI displays

2 participants