Skip to content

Fit a new snap into the space beside a recently snapped window - #1903

Open
kiteretsu903 wants to merge 16 commits into
rxhanson:mainfrom
kiteretsu903:fix/review-fit-remaining-space
Open

kiteretsu903 wants to merge 16 commits into
rxhanson:mainfrom
kiteretsu903:fix/review-fit-remaining-space

Conversation

@kiteretsu903

@kiteretsu903 kiteretsu903 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Adds opt-in Fit remaining space under Adjacent Windows, off by default. When window A snaps left and ends up 60% wide, snapping window B to the right half fills the remaining 40%. It works along both axes, honors configured gaps, and shows a matching drag-to-snap preview while keeping explicit sizing, cycling, and cooperative resize rules intact.

A valid, unchanged reference window A remains eligible until the next window command consumes that opportunity. If A has been closed, minimized, hidden, moved, or resized before that command, B falls back to an ordinary snap with a matching preview.

Behavior

Scenario Behavior
Adjacent snap beside an oversized neighbor Window A takes 60% on the left and Window B's next right-half snap fills the remaining 40% while Window A remains valid and unchanged
Vertical splits and configured gaps Applies remaining-space fitting along either axis while honoring configured gaps
Reference closed, minimized, hidden, moved, or resized Falls back to an ordinary snap with a matching drag-to-snap preview
No room left beside the neighbor Declines the snap with a beep before committing Restore, cursor, action, or calculation history, keeping Window B's saved Restore frame intact
Next window command Consumes the pending Fit opportunity; a fitted snap completes that opportunity, while an eligible ordinary snap can establish the next reference
Explicit sizing, cycling, or setting disabled Runs standard calculation, cycling, and cooperative resize behavior

Why WindowManager and hooks change

Fit computation, preview adjustment, and session tracking stay inside the Fit module. SnappedWindowFitProvider registers in AppDelegate as an ordered peer WindowManagerDelegateProvider ahead of cooperative resize and records actual reference frames from achieved-frame completion notifications.

These three internal extension points in WindowMoveHooks are integrated into WindowManager's execution flow: history commits wait for placement admission, and placement notifications report actual settled coordinates. Because the contracts are lifecycle-level rather than Fit-specific, other internal Rectangle features can reuse the same boundaries:

Extension point Current use Reuse value
WindowManagerDelegate.acceptsPlacement (default true) Checked right after target calculation and before WindowManager commits Restore, cursor, action, or calculation-history state or supersedes pending work (place runs too late to prevent history updates and is skipped for animated placements and cross-display retries). Fit declines no-room snaps so Window B's saved Restore frame stays intact. Other internal move delegates with placement conditions can reject a calculated target at the same admission boundary, preserving history.
WindowActionCompletion(result, achievedFrame, identity) on windowActionCompleted Posted with actual AX coordinates after display retries settle, including already-achieved moves (moveDidSettle only runs on same-display moves). Fit records window A's actual settled size across displays; the dependent #1907 also consumes it for pair discovery. Other internal observers can subscribe when they need achieved placement geometry. This describes placement outcomes and excludes Restore, which follows its own path.
WindowActionIdentity on ExecutionParameters, WindowMoveRequest, and WindowActionCompletion Keeps Fit's reference associated with the command that consumed it through planning and deferred execution. Completion ordering lets a late accepted snap establish a reference after a later rejected or no-op command without overriding a newer recorded reference or crossing a Restore/reset boundary, and once a fitted target is admitted, Fit executes it even if window A changes afterward. Other deferred or retried internal operations can associate their state with the original command and distinguish it from newer commands.

Feedback on whether these boundaries sit in the right places in the WindowManager pipeline is very welcome.

Verification

  • Unit tests: 847 tests, 2 skipped, zero failures.
  • Native E2E: Passed horizontal and vertical Fit splits, reference retention until the next window command, minimized and closed reference preview fallback, cross-display anchor placement, no-room rejection followed by Restore, and reference dragged during animation with a replacement command.

Review order

Review the Fit changes on top of #1904. Merge in order: #1904 → #1903 → #1907. If #1904 is squash-merged, replay this layer on the resulting main before merging it.

Demo

06-fit-remaining-space.mp4

@rxhanson

Copy link
Copy Markdown
Owner

There's a flaw in my design of WindowManager, where it becomes a place that needs to be modified in most changes to Rectangle functionality. Ideally, this change wouldn't have to modify the WindowManager, but would leverage a hook instead (which also goes for ShortcutManager). I'm debating whether this work should be done prior to merging this change. The different architecture would look a little more like a pipeline with hooks at each of the different stages of before/after calculations, adjusting calculations, and before/after applying the window placement. On this note, placeBesideSnappedWindow should be moved outside of WindowManager, and I think it would make more sense to have things like this live in files that hook into the pipeline as opposed to being directly inserted as part of it. I realize that these PRs have been in limbo for a while, but want to make sure that it's easy to build something stable. I'll give it a little more thought and post back when I decide on a direction.

@kiteretsu903

Copy link
Copy Markdown
Contributor Author

There's a flaw in my design of WindowManager, where it becomes a place that needs to be modified in most changes to Rectangle functionality. Ideally, this change wouldn't have to modify the WindowManager, but would leverage a hook instead (which also goes for ShortcutManager). I'm debating whether this work should be done prior to merging this change. The different architecture would look a little more like a pipeline with hooks at each of the different stages of before/after calculations, adjusting calculations, and before/after applying the window placement. On this note, placeBesideSnappedWindow should be moved outside of WindowManager, and I think it would make more sense to have things like this live in files that hook into the pipeline as opposed to being directly inserted as part of it. I realize that these PRs have been in limbo for a while, but want to make sure that it's easy to build something stable. I'll give it a little more thought and post back when I decide on a direction.

That makes sense to me. Let me know how I could help with the refactoring!

@rxhanson

Copy link
Copy Markdown
Owner

Thanks for your understanding! I'm getting ready to wrap up some other app work and will rearchitect the WindowManager soon.

@rxhanson

Copy link
Copy Markdown
Owner

Ok, at long last, I have updated the WindowManager and am ready to resume PR review. Let me know if/when you get a chance to revisit this. Thanks!

@kiteretsu903

Copy link
Copy Markdown
Contributor Author

@rxhanson that's awesome! congrats on great work. Will update these PRs later this week

@kiteretsu903
kiteretsu903 force-pushed the fix/review-fit-remaining-space branch from 17ea393 to 97430a3 Compare November 22, 2026 06:27
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.

2 participants