Preserve relative window position when moving to another display - #1809
Open
YuriNachos wants to merge 1 commit into
Open
Preserve relative window position when moving to another display#1809YuriNachos wants to merge 1 commit into
YuriNachos wants to merge 1 commit into
Conversation
When the hidden attemptMatchOnNextPrevDisplay opt-in is ON and a window is moved to the next/previous or a specific display with no Rectangle snap action to replay, map the window's rect proportionally from the source screen's adjustedVisibleFrame to the destination's, preserving its relative position and size, and clamp it inside the destination. Previously the window jumped to the center in this case. Applies identically to next/prev and specific-display moves. No change when the opt-in is off/unset.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
attemptMatchOnNextPrevDisplayopt-in enabled and no Rectangle snap action to replay.visibleFrames and clamped inside the destination.attemptMatchOnNextPrevDisplaysee no change.Root cause
NextPrevDisplayCalculation.calculate(andSpecificDisplayCalculation.calculate) only preserved position by replayinglastAction. With the opt-in ON but no replayable lastAction (a manually positioned window), execution fell through tocalculateRect, whose override returnscenterCalculation— so the window was centered regardless of the opt-in.Fix
In the fall-through case (opt-in ON, no replayable snap), map the window's current rect proportionally from the source screen's
adjustedVisibleFrameto the destination screen'sadjustedVisibleFrame, preserving its relative position and size as fractions of the source frame, then clamp inside the destination. Shared by both call sites via a singleNextPrevDisplayCalculation.relativePositionedRect(window:source:destination:)helper. Degenerate source frames return the window unchanged.Testing
xcodebuild test -project Rectangle.xcodeproj -scheme Rectangle -destination 'platform=macOS'NextPrevDisplayMappingTests: 4 pure-geometry tests covering right-third mapping, centered-quarter mapping, destination-overflow clamp, and identity. All pass.ActiveSideSplitRatiosCooperativeTests/HalfSplitCornerCalculationTests(unchanged baseline — these pre-date this PR, in-flight cooperative-resize / corner-calc work). No new failures.AI assistance
This PR was prepared with AI assistance; the approach, tests, and verification were reviewed by the contributor.
Closes #1723