Skip to content

fix(windows): enforce min size constraints after window restore#5194

Merged
leaanthony merged 2 commits into
masterfrom
fix/4593-min-size-togglemaximise
May 31, 2026
Merged

fix(windows): enforce min size constraints after window restore#5194
leaanthony merged 2 commits into
masterfrom
fix/4593-min-size-togglemaximise

Conversation

@leaanthony

@leaanthony leaanthony commented Apr 20, 2026

Copy link
Copy Markdown
Member

Summary

  • Add enforceMinSizeConstraints() to the restore() method in webview_window_windows.go so that after SW_RESTORE (triggered by ToggleMaximiseUnMaximise), the window is resized to respect MinWidth/MinHeight constraints if the restored placement is smaller than the minimum.
  • Add unit tests for the min-size enforcement logic.

The root cause is that SW_RESTORE restores the window to its pre-maximize placement without validating against WM_GETMINMAXINFO constraints. This means a restored window can be smaller than MinWidth/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 cleanly
  • Manual testing: Set MinWidth/MinHeight, maximise, use ToggleMaximise to unmaximise, verify window is at least MinWidth x MinHeight

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Resolved an issue where configured minimum window dimensions were not being enforced after unmaximizing or restoring windows on Windows.
  • Tests

    • Added unit test coverage for minimum size constraint enforcement across various window dimension scenarios.

@coderabbitai

coderabbitai Bot commented Apr 20, 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: e660f141-456d-4d8c-a67a-2d365d4f3fbd

📥 Commits

Reviewing files that changed from the base of the PR and between ae5abd9 and 4d39a5e.

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

Walkthrough

This 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.

Changes

Windows Window Minimum Size Enforcement

Layer / File(s) Summary
Min size constraint helper and test
v3/pkg/application/minsize_constraints_test.go
The enforceMinSize helper clamps dimensions to configured minimums when they fall below constraints and returns a flag indicating whether adjustment occurred. A table-driven test validates both clamped dimensions and the changed flag across scenarios where dimensions are below, above, or equal to minimums, and when no constraints exist.
Windows restore integration
v3/pkg/application/webview_window_windows.go
The enforceMinSizeConstraints() method is added to the Windows WebView window class and called during restore() after refocusing. It reads MinWidth/MinHeight from options, compares against current bounds, and adjusts the window via setBounds when needed.
Changelog documentation
v3/UNRELEASED_CHANGELOG.md
A "Fixed" entry documents that minimum width/height constraints are now enforced after window unmaximize on Windows.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

Bug, Windows, v3, size:XS

🐰 A window unmaximized, constraints checked—
Dimensions clamped to minimums, now correct,
Tests verify the logic is sound and true,
Windows users rejoice—dimensions stay as they're set for you! 🪟✨

✨ 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/4593-min-size-togglemaximise

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 leaanthony added this to the v3.0.0-beta.1 milestone May 20, 2026
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
@leaanthony leaanthony force-pushed the fix/4593-min-size-togglemaximise branch from 9fe65b1 to 97120a3 Compare May 31, 2026 03:07
@leaanthony leaanthony marked this pull request as ready for review May 31, 2026 07:14
Copilot AI review requested due to automatic review settings May 31, 2026 07:14
@leaanthony leaanthony merged commit 38b087d into master May 31, 2026
14 of 16 checks passed
@leaanthony leaanthony deleted the fix/4593-min-size-togglemaximise branch May 31, 2026 07:14

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

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/MinHeight after restore() 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)
Comment on lines +41 to +52
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)
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.

wails v3 Unable to restrict the minimum width and height of the window.

2 participants