fix(windows): enforce min size constraints after window restore#5194
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
WalkthroughThis pull request fixes a Windows-specific bug where minimum window width and height constraints are not enforced after window unmaximize. It introduces a constraint-clamping helper with test coverage and integrates the enforcement into the window restore flow. ChangesWindows Window Minimum Size Enforcement
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
When a maximized window is restored via ToggleMaximise, Windows uses the saved window placement which may violate the current minimum size constraints. Add enforceMinSizeConstraints() call after SW_RESTORE to ensure the restored window respects MinWidth/MinHeight options. Fixes #4593
9fe65b1 to
97120a3
Compare
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Fixes Windows behavior where minimum size constraints weren’t applied after a window is restored/unmaximized.
Changes:
- Enforce
MinWidth/MinHeightafterrestore()on Windows. - Add a new unit test file intended to validate min-size enforcement behavior.
- Document the fix in the unreleased changelog.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| v3/pkg/application/webview_window_windows.go | Adds min-size enforcement after restoring a window on Windows. |
| v3/pkg/application/minsize_constraints_test.go | Introduces tests for min-size enforcement logic (currently via a test-local helper). |
| v3/UNRELEASED_CHANGELOG.md | Adds a changelog entry for the Windows min-size enforcement fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| for _, tc := range testCases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| newW, newH, changed := enforceMinSize(tc.width, tc.height, tc.minWidth, tc.minHeight) |
| func enforceMinSize(currentW, currentH, minWidth, minHeight int) (int, int, bool) { | ||
| changed := false | ||
| if minWidth > 0 && currentW < minWidth { | ||
| currentW = minWidth | ||
| changed = true | ||
| } | ||
| if minHeight > 0 && currentH < minHeight { | ||
| currentH = minHeight | ||
| changed = true | ||
| } | ||
| return currentW, currentH, changed | ||
| } |
|
|
||
| ## Fixed | ||
| <!-- Bug fixes --> | ||
| - Fix minimum width/height constraints not enforced after window unmaximise on Windows (#4593) |
Summary
enforceMinSizeConstraints()to therestore()method inwebview_window_windows.goso that afterSW_RESTORE(triggered byToggleMaximise→UnMaximise), the window is resized to respectMinWidth/MinHeightconstraints if the restored placement is smaller than the minimum.The root cause is that
SW_RESTORErestores the window to its pre-maximize placement without validating againstWM_GETMINMAXINFOconstraints. This means a restored window can be smaller thanMinWidth/MinHeight.Fixes #4593
Test plan
TestEnforceMinSizeConstraintsBelowMinimum— verifies enforcement logic for all edge cases (both below, width below, height below, both above, exactly at min, no constraints)GOOS=windows go build ./pkg/application/— compiles cleanlySummary by CodeRabbit
Release Notes
Bug Fixes
Tests