Skip to content

Fix false positive overlap detection for half/third actions - #1766

Merged
rxhanson merged 1 commit into
rxhanson:mainfrom
MyronKoch:fix/overlap-false-positive
May 26, 2026
Merged

rxhanson merged 1 commit into
rxhanson:mainfrom
MyronKoch:fix/overlap-false-positive

Conversation

@MyronKoch

Copy link
Copy Markdown
Contributor

Summary

Fixes the post-merge bug from #1762 where executing a left or right half would add an offset even when there is no underlying window at that position.

Root cause

The overlap detection used origin-only matching (within 4px tolerance). When snapping to left-half at origin (0, 0), any other window on screen with its origin near (0, 0) - such as a maximized window - triggered a false positive.

Fix

Now requires that the other window fits within the candidate's dimensions: origins must match AND the other window must be the same size or smaller. This prevents a maximized window (1920x1080) from triggering the offset on a left-half (960x1080), while still detecting an eighth (480x540) behind a quarter (960x1080) at the same grid position.

Test cases

  • Two left-halves at same position - offset triggers (correct)
  • Eighth behind quarter at same origin - offset triggers (correct)
  • Maximized window behind left-half - NO offset (fixed)
  • Right-half vs left-half - NO offset (correct, different origins)

@MyronKoch
MyronKoch marked this pull request as draft May 25, 2026 16:13
Origin-only matching caused false positives when a larger window
(e.g. maximized or near-fullscreen) shared the same origin as the
target position. Now excludes windows that cover more than 90% of
the screen on both axes from overlap detection, while preserving
offset behavior for mixed-size grid windows at the same position
(e.g. an eighth behind a quarter).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@MyronKoch
MyronKoch force-pushed the fix/overlap-false-positive branch from ec1d023 to 38eca47 Compare May 25, 2026 17:14
@MyronKoch
MyronKoch marked this pull request as ready for review May 25, 2026 17:14
@rxhanson
rxhanson merged commit 6aa825f into rxhanson:main May 26, 2026
1 check passed
@rxhanson

Copy link
Copy Markdown
Owner

Thanks for the incredibly quick fix! Looks good.

MyronKoch added a commit to MyronKoch/Rectangle that referenced this pull request Aug 22, 2026
The badge briefly excluded screen-covering windows from forming a stack.
That exclusion belongs to the overlap offset, where a maximized window
shares its origin with every placement and would otherwise shift them
all (rxhanson#1766). The badge moves nothing, so it never needed the rule, and
with it a maximized window sitting on a half-screen window showed no
badge at all - which is the one case where the covered window cannot be
seen any other way and the badge is the only thing that would reveal it.

The offset keeps its own copy of the check, so rxhanson#1766 is unaffected.
MyronKoch added a commit to MyronKoch/Rectangle that referenced this pull request Aug 27, 2026
The badge briefly excluded screen-covering windows from forming a stack.
That exclusion belongs to the overlap offset, where a maximized window
shares its origin with every placement and would otherwise shift them
all (rxhanson#1766). The badge moves nothing, so it never needed the rule, and
with it a maximized window sitting on a half-screen window showed no
badge at all - which is the one case where the covered window cannot be
seen any other way and the badge is the only thing that would reveal it.

The offset keeps its own copy of the check, so rxhanson#1766 is unaffected.
rxhanson pushed a commit that referenced this pull request Aug 31, 2026
* Add keyboard navigation and a toggle shortcut to the stacked-window list

Arrow keys move the highlight, Return raises the selected window and
leaves the list up so the stack can be walked, Escape closes. Rectangle
is an accessory app, so its panels can never become key and ordinary
focus cannot deliver these keys - the list uses a consuming event tap
instead, scoped as tightly as it can be. Only bare navigation keys are
claimed: any held modifier goes to the app underneath, the tap is not
installed at all while VoiceOver is running, since Quick Nav owns the
arrow keys, and an untouched list expires after five seconds so it can
never sit holding them.

macOS reports every arrow keystroke as carrying .function and
.numericPad. Those are properties of the key rather than modifiers being
held, so only the four keys a user can actually hold are treated as a
reason to pass a keystroke through.

The badge also stops counting stacks that are not there: a window
covering the screen joins a stack the tiled windows already form, but
never forms one on its own. Rows that would fall off the bottom of the
screen are not built, since arrow keys could otherwise select - and
Return raise - a window with no visible row.

The toggle shortcut follows the app's existing shortcut conventions, and
the view code moves into StackBadgeWindow, StackBadgeListPanel and
StackBadgeRowView, one view per file.

* Take the list's keys through the panel instead of an event tap

The list is a non-activating panel, so it can become key and receive
arrow keys directly once canBecomeKey allows it - the earlier attempt
failed because a borderless window refuses key status by default and the
panel was only ordered front, never made key. That removes the consuming
CGEvent tap and everything that existed to make a global key grab safe:
the claim state, the VoiceOver guard, and the five-second expiry. Any key
that is not navigation now dismisses the list rather than being eaten.

Raising a window activates its app, which takes key status away, so the
panel takes it back afterwards. Without that the list stayed on screen
while the arrow keys drove the window that had just come forward.

The badge and the list are also no longer shown together. A dwell shows
the badge; the list opens when the cursor reaches it. Passing over a
stack on the way somewhere else now costs a small pill rather than a
popup, and since opening the list means taking the keyboard, that only
happens once someone has aimed at the badge on purpose.

* Line the badge toggle recorder up with the other shortcut rows

It was the only row in the popover not sharing the shortcut column, so
its recorder sat out to the right of every other one.

* List tiled windows hidden under a stack of maximized ones

A stack formed by screen-covering windows dropped any tiled window at
the same corner, so two maximized terminals over a half-width browser
listed the terminals and silently omitted the browser. That is the worst
window to lose: the covering windows are precisely what makes it
invisible, and the badge still showed a plausible count, so there was
nothing to suggest a window was missing.

* Keep the keyboard on the list after a window is raised

Activating an app is asynchronous, so taking key status back immediately
after the call raced the activation and lost. The tick reclaims it
whenever the list is visible without it, which does not depend on
knowing when activation finishes.

* Measure the offset window forward from the one it covers

A tiled window under a stack of maximized ones was still being dropped.
The maximized windows carry the overlap offset, so they sit a cascade
step forward of the tiled window they hide, and proximity was being
measured from the offset window back to the tiled one - a direction the
test deliberately barely allows, since it exists to follow a cascade
forward.

The earlier test for this placed every window on one origin, where the
direction cannot matter, so it passed against code that could not work
on any layout where the offset had actually moved something.

* Count every window at the corner, whatever its size

The badge briefly excluded screen-covering windows from forming a stack.
That exclusion belongs to the overlap offset, where a maximized window
shares its origin with every placement and would otherwise shift them
all (#1766). The badge moves nothing, so it never needed the rule, and
with it a maximized window sitting on a half-screen window showed no
badge at all - which is the one case where the covered window cannot be
seen any other way and the badge is the only thing that would reveal it.

The offset keeps its own copy of the check, so #1766 is unaffected.

* Open the window list on hover instead of a count badge

The badge was a holdover from before the list existed, when a count was
all this feature offered. Once the list arrived the badge was labelling
something you were about to read anyway, and making it a first stage put
a step between wanting the list and getting it. The overlap offset
already signals that a stack is there - the covered windows peek out
from under the top one - so nothing is lost by removing the pill.

Opening the list means taking key status, which is how it receives the
arrow keys, so the list appears on dwell but does not take the keyboard
until the cursor is on it. Resting near a stack corner while typing
therefore costs nothing. Once a window has been raised from the list the
keyboard is taken back without that test, since raising activates the
window's app and walking a stack lets the pointer drift off the rows -
but only then, so switching apps by any other means is left alone.

The corridor between the dwell point and the list follows the cursor
rather than the geometric corner, since a gap puts the stack down and
right of it and the first move toward the list would otherwise read as
leaving.
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.

2 participants