Skip to content

fix: don't realign a window that is within a point of filling its zone - #1853

Merged
rxhanson merged 1 commit into
rxhanson:mainfrom
anandghegde:fix/1852-skip-realignment-within-a-point
Sep 12, 2026
Merged

rxhanson merged 1 commit into
rxhanson:mainfrom
anandghegde:fix/1852-skip-realignment-within-a-point

Conversation

@anandghegde

Copy link
Copy Markdown
Contributor

Fixes #1852.

Problem

With the Dock on the right, Maximize leaves the window 1pt narrower than the screen and shifted 1pt right (x=1 instead of x=0). From the log in the issue, on a 1679pt-wide visible frame:

AX sizing proposed: (1679.0, 1079.0), result: (1678.0, 1079.0)
AX position proposed: (1.0, 38.0), result: (1.0, 38.0)
maximize, calculatedRect: (0.0, 38.0, 1679.0, 1079.0), resultRect: (1.0, 38.0, 1678.0, 1079.0)

Two things combine, as diagnosed by @nyg in the issue:

  1. macOS shortens an AX size change that grows a window's right edge onto the Dock edge, so a requested width of 1679 comes back as 1678. A position change to the same edge is not clamped, which is why Left Half → Last Two Thirds (resized at x=0, then moved) is exact while Right Half → Last Two Thirds is not.
  2. ClampedWindowAligner reads that 1pt shortfall as a clamped window. Maximize shares both left and right screen edges, so the window gets centered: round((1679 - 1678) / 2) = 1.

The net effect is that the 1pt gap moves off the Dock edge, where it was invisible, onto the opposite edge, where it is not.

Fix

Skip realignment on an axis when the shortfall there is within a point. I took the first of the two options suggested in the issue — the alternative, applying the size to the left of the target and then moving the window, would change AccessibilityElement.setFrame behavior for every action to address a 1pt cosmetic issue.

The check is per axis, so a window that is a point narrow but genuinely short still gets aligned vertically. Real clamps — a window holding a fixed aspect ratio, for example — are unaffected, since those miss the zone by far more than a point.

Tests

Five cases added to ClampedWindowAlignerTests, using the measurements from the issue:

  • testMaximizeOnePointNarrowStaysPut — the reported case (zone 1679 wide, window 1678, all four edges shared)
  • testRightHalfOnePointNarrowStaysPut — the right-half variant from the issue's measurement table
  • testOnePointShortHeightStaysPut — same tolerance on the vertical axis
  • testOnePointNarrowLeavesOtherAxisAlignmentIntact — a point narrow and genuinely short: width is left alone, height still centers
  • testShortfallJustOverToleranceStillAligns — pins the boundary so the tolerance can't be widened later without a test failing

The first four fail on main and pass with this change. The boundary test passes both ways by design. Full suite: 338 tests, 0 failures.

macOS shortens an AX size change that grows a window onto the Dock edge
by a point, so a Maximize with the Dock on the right comes back 1pt
narrow. ClampedWindowAligner read that as a clamped window and centered
it, moving the 1pt gap off the Dock edge (where it was invisible) to the
opposite edge (where it is not) and leaving the window at x=1.

Skip realignment per axis when the shortfall is within a point. Genuine
clamps, such as a window holding a fixed aspect ratio, are unaffected.

Fixes rxhanson#1852
@rxhanson

Copy link
Copy Markdown
Owner

Thanks for the prompt fix!

@rxhanson
rxhanson merged commit 222dd1a into rxhanson:main Sep 12, 2026
1 check passed
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.

Maximize leaves window at x=1 and 1pt narrow when Dock is on the right

2 participants