Repository navigation
Preserve relative window position when moving to another display - #1809
Merged
Merged
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.
Contributor
Author
|
One practical note on this PR: the Build workflow is still marked 'waiting for approval to run', so the checks haven't actually executed on this branch yet. Whenever you're working through the queue, approving that run would let it build — and if anything else would save you time, whether that's a specific display setup to test the relative-position behavior on or further changes to the diff, I'm glad to handle that part. No rush from my side; I just don't want it sitting invisible. |
Owner
|
Great, thanks! Good point on the workflow approval, and thanks for your patience :) |
anandghegde
added a commit
to anandghegde/Rectangle
that referenced
this pull request
Sep 24, 2026
A window against three screen edges - spanning one axis and against one edge of the other, like a left half or a top half - was stretched along the whole of the spanning axis when it moved between a landscape and a portrait display, turning a left half into a tall sliver. It now keeps its size and is centered along the middle one of its three edges. Picking a corner instead would mean guessing from how the displays are arranged; centering makes no assumption. Keeping a window's position is now a setting, "Keep window position when moving across displays" in the Behavior tab, backed by keepWindowPositionOnDisplayChange. It is on by default. Turned off, display moves behave as they did before this branch: the window is centered, or with attemptMatchOnNextPrevDisplay on and no action to replay, mapped proportionally as in rxhanson#1809. relativePositionedRect and its tests are restored for that path, and the centerOnDisplayChange terminal command is gone, since the setting replaces it.
rxhanson
pushed a commit
that referenced
this pull request
Sep 24, 2026
* Keep a window's position when moving it to another display Moving a window to the next, previous or a specific display centered it on the destination, which loses the spot the user had put it in. DisplayTransfer works out each axis on its own from whether the window was against a screen edge: against both edges it follows both and spans the destination, against one it keeps its size and stays against that edge, against neither it keeps its size and its center keeps the same relative spot. The distance from an edge is carried over rather than flattened, so a window snapped with gaps arrives with the same gaps. This is now the default for next/previous and specific display moves. The old centering is available as centerOnDisplayChange, and attemptMatchOnNextPrevDisplay still replays the last Rectangle action where there is one. Closes #1666 * RectangleTests: match the current setFrame signature The test double overrides setFrame(_:adjustSizeFirst:), but AccessibilityElement.setFrame gained an adjustPosition parameter in "Add optional snapping animations and a blurred snap preview" (#1849), so the override no longer matches and the test target does not compile: RectangleTests.swift:6153:23: error: method does not override any method from its superclass This is not related to the rest of the branch - it reproduces on a clean checkout - but the test target has to build before any of the tests can run. * Center three-edge windows along the middle edge across orientations A window against three screen edges - spanning one axis and against one edge of the other, like a left half or a top half - was stretched along the whole of the spanning axis when it moved between a landscape and a portrait display, turning a left half into a tall sliver. It now keeps its size and is centered along the middle one of its three edges. Picking a corner instead would mean guessing from how the displays are arranged; centering makes no assumption. Keeping a window's position is now a setting, "Keep window position when moving across displays" in the Behavior tab, backed by keepWindowPositionOnDisplayChange. It is on by default. Turned off, display moves behave as they did before this branch: the window is centered, or with attemptMatchOnNextPrevDisplay on and no action to replay, mapped proportionally as in #1809. relativePositionedRect and its tests are restored for that path, and the centerOnDisplayChange terminal command is gone, since the setting replaces it.
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