Skip to content

Move window to the display under the cursor - #1913

Open
Kiizon wants to merge 1 commit into
rxhanson:mainfrom
Kiizon:cursor-display-targeting
Open

Kiizon wants to merge 1 commit into
rxhanson:mainfrom
Kiizon:cursor-display-targeting

Conversation

@Kiizon

@Kiizon Kiizon commented Oct 13, 2026 •

Copy link
Copy Markdown

Closes #1908.

What it does

  • Shows the existing cursor screen detection setting in Settings as "Move window to display where cursor is" under Across Display Settings. Previously it only appeared once the hidden default was already on.
  • When it's on, a command moves the focused window to its target position on the display under the cursor.
  • Fixes the repeat problem from the issue: if the cursor has moved to another display since the window's last command, the next command is treated as a first press on that display, not a repeat. Before, Left, then moving the cursor, then Left again landed on the right half of the old display.
  • Pressing the same shortcut again with the cursor on the same display repeats exactly as it does with the setting off, including repeats that cycle the window to another display. Any other shortcut starts fresh on the cursor's display, even if repeats have moved the window elsewhere.
  • With "Move cursor along with window across displays" on, the cursor stays where it is when the window moves to the display it's already on. It still follows the window to a different display, e.g. when cycling. When Rectangle moves the cursor itself, that doesn't count as pointing at a new display, so repeats keep cycling.
  • Next/Previous Display always count from the window's display.

How

WindowHistory keeps, for each window's last command, the frame of the display that was under the cursor and the shortcut that was pressed (which can differ from the action it resulted in, e.g. Left becoming the right half when crossing displays). WindowManager and ShortcutManager compare the display with the one under the cursor now. If the cursor hasn't changed displays and the same shortcut was pressed, the command works from the window's display, the same as with the setting off. Otherwise it starts on the cursor's display. This doesn't depend on the last recorded action, which Rectangle forgets whenever an app adjusts the frame it was given (common when moving across displays).

When Rectangle moves the cursor, it records the destination display, so its own cursor moves don't end a repeat. Cursor moves go through warpCursor(to:) so tests can stub them.

Tests

  • New tests cover: moving to the cursor's display, a cursor display change ending a repeat (for both the cross-display and cycle-sizes modes), repeats still working while the cursor stays put, a repeated walk across displays matching the setting-off behavior even when the app adjusts the window's frame, a different shortcut after cycling going to the cursor's display, the cursor staying put when the window comes to its display, a cursor moved along with the window not ending a repeat, Next Display counting from the window's display, and the setting being off.
  • withExecutionSettings now pins useCursorScreenDetection, so the existing display-cycle test doesn't pick up the machine's own setting.
  • Tested manually on two displays with halves and thirds: commands follow the cursor to the other display, and repeating Left with the cursor still walks the window through both halves of both displays, the same as with the setting off. Also retested the three scenarios from @porg's review: switching shortcuts after cycling, the cursor staying put, and repeated presses with the cursor moved along.

All 581 tests pass. Note: I built and tested with Xcode 26.0.1, using local-only changes (old app icon, macOS 14 deployment target, no macOS 27 menu API) that aren't part of this PR. It hasn't been built with Xcode 27.

@Kiizon Kiizon changed the title Move window to the display under the cursor (#1908) Move window to the display under the cursor Oct 13, 2026
@Kiizon
Kiizon force-pushed the cursor-display-targeting branch from 9dcb43a to 06f0fa6 Compare October 13, 2026 20:48
@rxhanson

rxhanson commented Oct 16, 2026 •

Copy link
Copy Markdown
Owner

Thanks for working on this! The WindowManager has to be refactored before this goes in, unfortunately. I'll post back when it's ready, and I don't foresee it being difficult to accommodate the change.

Some quick background: There are a few files in Rectangle where all logic flows through, and they are the easiest places for changes to accumulate. The WindowManager is the most central, and it simply needs a better architecture to handle many of the changes that have recently gone in and will continue to come in.

@porg

porg commented Oct 16, 2026

Copy link
Copy Markdown

@Kiizon I added my testing feedback to the issue.

Show the cursor screen detection toggle as "Move window to display
where cursor is" under Across Display Settings, instead of only when
the hidden default is already on.

Test helpers now pin the cursor screen detection setting, so the
display cycle tests no longer depend on the machine's own preferences.
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.

Move window to display where cursor

3 participants