Skip to content

Add four Freeform window positions - #1982

Open
gslava wants to merge 1 commit into
rxhanson:mainfrom
gslava:main
Open

gslava wants to merge 1 commit into
rxhanson:mainfrom
gslava:main

Conversation

@gslava

@gslava gslava commented Nov 21, 2026

Copy link
Copy Markdown
Rectangle.app.-.custom.form.windows.mp4

Adds four Freeform positions, Freeform 1 to Freeform 4, at the end of the Extra section of the Shortcuts settings. Each one moves the focused window to an area you choose by dragging on the screen, the way you select an area for a screenshot in macOS.

This is for layouts the fixed positions can't express, such as a window in a specific spot on an ultrawide display or next to a sidebar. It's the "custom window size/place" request from #1362 without needing Terminal commands.

What it does

  • Each Freeform row has a small Select button. Clicking it hides the settings window and dims every display. Drag over an area and release to save it.
  • The selection behaves like the screenshot selection: hold Space to move it, Option to resize it around the starting point, Shift to resize along one axis, and press Esc to cancel. A click without a drag selects nothing, so you can try again. The preset's current area is outlined, and the new area's size is shown beside the pointer.
  • Once a preset has an area, its row gets an icon showing where the area is, drawn like the other position icons: a 30×20 template image with the display outline and the area filled in. A preset with no area has no icon and its shortcut does nothing.
  • Shortcuts can be set in the row as usual, or with defaults write (documented in TerminalCommands.md).

Behavior

  • Usable area: selections stay within the display's usable area (adjustedVisibleFrame, so the menu bar, the Dock, the Todo sidebar and screen edge gaps are excluded). They are stored relative to that area, so a preset keeps its proportions when the Dock moves or the resolution changes.
  • Display: a preset moves the window to the display its area was selected on, whatever display the window or the cursor is on. If that display isn't connected, the preset uses the same proportions on the window's display.
  • Repeats: repeating a preset doesn't cycle displays (ShortcutManager skips .cycleMonitor for these actions).
  • Gaps: the window gets exactly the selected area. Window gaps aren't applied, as with Center and the custom-size center command.
  • Menus: the actions are excluded from the menu bar menu and from drag-to-snap. They're listed in WindowAction.active (raw values 147–150), so they get shortcuts, rectangle://execute-action?name=freeform-one URLs and config export/import like other actions. The areas are saved in freeformOneRegion … freeformFourRegion.

Implementation notes

  • Settings window: while selecting, the settings window is made transparent and ignores the mouse, instead of being ordered out. Ordering it out makes the Shortcuts view controller disappear, which would end the selection as soon as it starts.
  • Shortcuts: global shortcuts are suspended while selecting, through the same ShortcutRecordingObserver path used while recording a shortcut.
  • Ending a selection: it ends cleanly if the app is deactivated, the displays change, the Space changes, or the settings window closes.
  • FreeformDrag: the selection geometry is a small value type with no AppKit dependency. It handles modifiers, clamping and snapping to whole points. It also snaps to the display edges the pointer can't reach: AppKit never reports the last column or the bottom pixel row.
  • FreeformRegion: the stored area, as a Codable value: the rect relative to the usable area, plus the display's UUID.
  • Localization: the new strings are in Localizable.xcstrings, with Ukrainian and Simplified Chinese translations.

Testing

70 new XCTest tests:

  • FreeformDragTests: selection geometry, modifiers, clamping and edge snapping
  • FreeformRegionTests: storage, scaling and invalid data
  • FreeformSelectionControllerTests: the overlay on two displays, driven by real NSEvents sent through the panels, covering dragging, Space, Option, Shift, Esc, interruptions and drawing
  • FreeformSettingsTests: clicking Select in a real ShortcutsViewController and dragging, for all four presets; also checks the icons, cancelling, and that shortcuts are suspended
  • FreeformPreviewTests: the icon matches the Left Half and Center icons pixel for pixel
  • FreeformCalculationTests, FreeformScreenSelectionTests: the calculation, and the display choice
  • ShortcutManagerSessionTests.testFreeformRepeatDoesNotCycleDisplays

The tests compare against localized strings, so they pass in any system language. The whole suite passes on GitHub Actions (xcode-27): https://github.com/gslava/Rectangle/actions/runs/44932907924

Also tested by hand: MacOS 15.8.3 (M1 Pro) with one display: all four presets, the modifiers, Esc, and the shortcuts

Freeform 1 to Freeform 4, at the end of Settings > Shortcuts > ⋯ > Extra,
move the focused window to an area chosen with the Select button beside
each of them.

Select covers every display with a screenshot-style overlay. Drag to
select an area; as in the macOS screenshot selection, hold Space to move
the selection, Option to resize it around its starting point and Shift
to resize it along one axis, and press Esc to cancel. The overlay shows
the preset's current area and the new area's size. Selections stay in
the display's usable area, snap to whole points and to the display
edges the pointer can't reach, and are stored relative to the usable
area of their display.

Once a preset has an area, its row shows an icon of where the area is
on the display, drawn in the style of the other window position icons.

While selecting, the settings window is made transparent rather than
ordered out, so the Shortcuts view stays on screen and the selection
isn't cancelled as it starts.

A preset moves the window to the display its area was selected on,
whichever display the window or the cursor is on, and uses the window's
display when that one isn't connected. Repeating it doesn't cycle
displays. The window gets exactly the selected area, without window
gaps; screen edge gaps are outside the area that can be selected.

The actions are excluded from the menu bar menu and drag-to-snap, and
TerminalCommands.md documents their keys.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant