Repository navigation
fix(v3/windows): resync WebView2 rasterization scale after minimise/restore - #5572
Conversation
…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
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAdds 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. ChangesMixed-DPI Rasterization Scale Fix
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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-appliesPutRasterizationScale(dpi/96)when needed. - Invoke the resync on restore-from-minimize (
SIZE_RESTOREDwhile minimizing) and onWM_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.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
v3/pkg/application/webview_window_windows.go (1)
1878-1903: Fix float equality style inresyncWebviewRasterizationScale(controller method is available)
- Guard clauses and DPI→scale computation are solid.
controller.GetICoreWebView2Controller3()is valid:GetController()returns*ICoreWebView2Controller, and that type definesGetICoreWebView2Controller3().- 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
📒 Files selected for processing (2)
v3/UNRELEASED_CHANGELOG.mdv3/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.
|
Round 2 from reporter verification on real 200%/125% hardware: the rasterization-scale resync worked (dpr recovers), but a |
…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
|
Round 3 from reporter verification: (1) the un-minimise resync now also covers windows returning to the maximised state ( |
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.
…og and windows.go conflicts
…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.
Description
On mixed-DPI Windows systems, a frameless window's
window.devicePixelRatioadopts 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 withDisableFramelessWindowDecorations: 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 callsPutRasterizationScaleafter controller creation. A minimised window is parked at (-32000,-32000), which can re-associate it with another monitor's DPI; on restore, noWM_DPICHANGEDcorrects 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()— readsGetDpiForWindow-based DPI and re-assertscontroller3.PutRasterizationScale(dpi/96). Invoked:SIZE_RESTOREDwhileisMinimizing) — the reported case with no corrective event;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
pkg/applicationsuite pass on Windows (go1.26.2);go vetoutput byte-identical to master (pre-existing Win32 interop warnings only).Fixes #5544
Type of change
Checklist:
v3/UNRELEASED_CHANGELOG.mdSummary by CodeRabbit