Skip to content

fix: clamp zoom to minimum 1.0 on Windows and macOS - #5205

Merged
leaanthony merged 2 commits into
masterfrom
fix/4590-zoom-minimum-clamp
May 31, 2026
Merged

leaanthony merged 2 commits into
masterfrom
fix/4590-zoom-minimum-clamp

Conversation

@leaanthony

@leaanthony leaanthony commented Apr 21, 2026 •

Copy link
Copy Markdown
Member

Summary

  • SetZoom(0.5) causes the rendered content to shrink but the window's hit-testing area is not adjusted, making invisible regions draggable/resizable
  • Linux already clamps zoom to minimum 1.0; Windows and macOS did not
  • Apply the same guard on Windows and macOS for consistency

Test plan

  • TestZoomClamp verifies the clamping logic for values below, at, and above 1.0
  • Manual: call window.SetZoom(0.5) and verify the call is clamped to 1.0

Fixes #4590

Summary by CodeRabbit

  • Bug Fixes
    • Fixed zoom functionality on macOS and Windows to enforce a minimum zoom level of 1.0, preventing invalid zoom values from being applied.

When SetZoom is called with a value less than 1.0, the rendered web
content shrinks but the window's hit-testing area is not adjusted. This
causes the invisible region outside the content to still be draggable
and resizable. Linux already clamps to 1.0 minimum.

Apply the same guard on Windows and macOS for consistency and to
prevent the drag/resize area mismatch bug.

Fixes #4590
@coderabbitai

coderabbitai Bot commented Apr 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c7c72e33-0f15-4ffb-8b44-21599b474357

📥 Commits

Reviewing files that changed from the base of the PR and between 38b087d and d35ddca.

📒 Files selected for processing (3)
  • v3/pkg/application/webview_window_darwin.go
  • v3/pkg/application/webview_window_windows.go
  • v3/pkg/application/zoom_test.go

Walkthrough

This PR prevents zoom levels below 1.0 from being applied to webview windows on macOS and Windows, addressing UI scaling and window edge dragging issues. The implementation adds zoom value clamping in both platform-specific setZoom methods, with comprehensive table-driven test coverage.

Changes

Zoom Level Clamping

Layer / File(s) Summary
Platform zoom clamping implementations
v3/pkg/application/webview_window_darwin.go, v3/pkg/application/webview_window_windows.go
Both macOS and Windows setZoom methods enforce a minimum zoom value of 1.0 before passing the value to platform APIs, preventing sub-1.0 zoom factors from being set.
Zoom clamping tests
v3/pkg/application/zoom_test.go
Table-driven test TestZoomClamp validates that zoom values below 1.0 are clamped to 1.0 and values ≥ 1.0 remain unchanged across multiple test cases.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

Bug, go, Windows, MacOS, v3, size:M

Poem

🐰 Zoom zoom, but not too small!
With clamping guards, we prevent the fall,
No dragging woes at ratios low,
The windows stay steady—they've got some flow! ✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/4590-zoom-minimum-clamp

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


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.

@leaanthony
leaanthony changed the base branch from v3-alpha to master April 29, 2026 13:07
@leaanthony

Copy link
Copy Markdown
Member Author

Tested on Windows 11 Pro 24H2 (Build 26100) — verdict: ✓ pass

  • Commit: e934c21f75
  • Build: 16s successful (pkg/application with CGo/WebView2, including webview_window_windows.go)
  • Unit tests: 7/7 passing (TestZoomClamp)
  • Visual smoke: badge example launched (PID confirmed, WebView2 147.0.3912.98 at startup); vcs.revision=e934c21f75... confirmed in binary

Test results (TestZoomClamp):

  • zero_clamped_to_1.0 — PASS
  • negative_clamped_to_1.0 — PASS
  • 0.5_clamped_to_1.0 — PASS
  • 0.99_clamped_to_1.0 — PASS
  • 1.0_stays_1.0 — PASS
  • 1.5_stays_1.5 — PASS
  • 2.0_stays_2.0 — PASS

The three-line guard in windowsWebviewWindow.setZoom (if zoom < 1.0 { zoom = 1.0 }) is present and the Windows path compiles cleanly.


PR test pass on Windows (go1.26.2 / WebView2 147.0.3912.98 / amd64)

@leaanthony

Copy link
Copy Markdown
Member Author

Simple but important fix! Zoom values below 1.0 causing invisible draggable/resizable regions is a UX issue that should be caught early. The clamp brings Windows and macOS in line with Linux.

I've dispatched cross-platform test sub-issues:

  • WAI-231 - macOS testing (includes this PR)
  • WAI-232 - Linux testing (includes this PR)
  • WAI-233 - Windows testing (includes this PR)

Once all platforms report back with successful test results, I'll apply the reviewed ✅ label.

CC @leaanthony

@leaanthony

Copy link
Copy Markdown
Member Author

Investigating on Windows 11 Pro (24H2, Build 26100).

Test environment: Go 1.26.2 · WebView2 147.0.3912.86

Unit tests (go test ./pkg/application/... -run TestZoomClamp -v):

=== RUN   TestZoomClamp
    --- PASS: TestZoomClamp/zero_clamped_to_1.0
    --- PASS: TestZoomClamp/negative_clamped_to_1.0
    --- PASS: TestZoomClamp/0.5_clamped_to_1.0
    --- PASS: TestZoomClamp/0.99_clamped_to_1.0
    --- PASS: TestZoomClamp/1.0_stays_1.0
    --- PASS: TestZoomClamp/1.5_stays_1.5
    --- PASS: TestZoomClamp/2.0_stays_2.0
--- PASS: TestZoomClamp (0.00s)
PASS
ok  	github.com/wailsapp/wails/v3/pkg/application	1.408s

All 7 clamp-logic subtests pass on Windows. The 3-line guard in setZoom on webview_window_windows.go is correct.

CC @leaanthony

@leaanthony leaanthony added this to the v3.0.0-beta.1 milestone May 20, 2026
@leaanthony
leaanthony marked this pull request as ready for review May 31, 2026 07:15
Copilot AI review requested due to automatic review settings May 31, 2026 07:15
@leaanthony
leaanthony merged commit d8ad33c into master May 31, 2026
14 of 17 checks passed
@leaanthony
leaanthony deleted the fix/4590-zoom-minimum-clamp branch May 31, 2026 07:15

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

APshenkin added a commit to APshenkin/wails that referenced this pull request Sep 24, 2026
Every backend raised a factor below 1.0 to 1.0 in setZoom, so
Window.SetZoom(0.8) silently applied 100%. The floor came from wailsapp#5205,
which closed wailsapp#4590 (SetZoom(0.5) leaves drag and resize regions where
the content used to be) by clamping the input instead of adjusting those
regions, citing the Linux clamp as precedent. None of the backends needs
it: WebView2 only rejects factors <= 0 and normalises values outside its
own range itself; WKWebView's magnification and WebKitGTK's zoom level
accept any positive value. The window option WebviewWindowOptions.Zoom
never had the floor either: on Windows it is passed straight to
PutZoomFactor at creation, so a window could start at 80% but never be
set to 80% afterwards.

setZoom now goes through zoomFactor, which
- rejects non-positive, NaN and Inf factors (WebView2 returns an error
  for them, WKWebView raises NSInvalidArgumentException, fatal from cgo)
  instead of raising them to 1.0,
- keeps the 1.0 floor for frameless windows only, whose drag and resize
  regions are what wailsapp#4590 is about; framed windows leave resizing to the
  OS and get the requested factor.

TestZoomClamp reimplemented the clamp inside the test body and never
called production code; TestZoomFactor exercises the helper instead.
ZoomIn, ZoomOut and ZoomReset are untouched.
APshenkin added a commit to APshenkin/wails that referenced this pull request Sep 24, 2026
Every backend raised a factor below 1.0 to 1.0 in setZoom, so
Window.SetZoom(0.8) silently applied 100%. The floor came from wailsapp#5205,
which closed wailsapp#4590 (SetZoom(0.5) leaves drag and resize regions where
the content used to be) by clamping the input instead of adjusting those
regions, citing the Linux clamp as precedent. None of the backends needs
it: WebView2 only rejects factors <= 0 and normalises values outside its
own range itself; WKWebView's magnification and WebKitGTK's zoom level
accept any positive value. The window option WebviewWindowOptions.Zoom
never had the floor either: on Windows it is passed straight to
PutZoomFactor at creation, so a window could start at 80% but never be
set to 80% afterwards.

setZoom now goes through zoomFactor, which
- rejects non-positive, NaN and Inf factors (WebView2 returns an error
  for them, WKWebView raises NSInvalidArgumentException, fatal from cgo)
  instead of raising them to 1.0,
- keeps the 1.0 floor for frameless windows only, whose drag and resize
  regions are what wailsapp#4590 is about; framed windows leave resizing to the
  OS and get the requested factor.

TestZoomClamp reimplemented the clamp inside the test body and never
called production code; TestZoomFactor exercises the helper instead.
ZoomIn, ZoomOut and ZoomReset are untouched.
leaanthony added a commit that referenced this pull request Oct 27, 2026
fix(v3): let Window.SetZoom go below 1.0 on framed windows

Every backend raised a factor below 1.0 to 1.0 in setZoom, so
Window.SetZoom(0.8) silently applied 100%. The floor came from #5205,
which closed #4590 (SetZoom(0.5) leaves drag and resize regions where
the content used to be) by clamping the input instead of adjusting those
regions, citing the Linux clamp as precedent. None of the backends needs
it: WebView2 only rejects factors <= 0 and normalises values outside its
own range itself; WKWebView's magnification and WebKitGTK's zoom level
accept any positive value. The window option WebviewWindowOptions.Zoom
never had the floor either: on Windows it is passed straight to
PutZoomFactor at creation, so a window could start at 80% but never be
set to 80% afterwards.

setZoom now goes through zoomFactor, which
- rejects non-positive, NaN and Inf factors (WebView2 returns an error
  for them, WKWebView raises NSInvalidArgumentException, fatal from cgo)
  instead of raising them to 1.0,
- keeps the 1.0 floor for frameless windows only, whose drag and resize
  regions are what #4590 is about; framed windows leave resizing to the
  OS and get the requested factor.

TestZoomClamp reimplemented the clamp inside the test body and never
called production code; TestZoomFactor exercises the helper instead.
ZoomIn, ZoomOut and ZoomReset are untouched.

Co-authored-by: Lea Anthony <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

[V3] SetZoom(0.5) , scaling ratio is less than 1

2 participants