Skip to content

Bound the overlap-offset window scan so an unresponsive app can't freeze the UI - #1810

Open
MyronKoch wants to merge 1 commit into
rxhanson:mainfrom
MyronKoch:feat/offset-ax-timeout
Open

Bound the overlap-offset window scan so an unresponsive app can't freeze the UI#1810
MyronKoch wants to merge 1 commit into
rxhanson:mainfrom
MyronKoch:feat/offset-ax-timeout

Conversation

@MyronKoch

@MyronKoch MyronKoch commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

When cycling a window onto a grid position, the overlap-offset check (from #1762) enumerates every on-screen window over the Accessibility API to see whether one already sits at the target position — and that scan runs on the main thread before the placement.

Normally that's a few milliseconds. But an Accessibility query to an unresponsive app blocks until the default messaging timeout, which is several seconds. So if any app is hung or beachballing, moving a window can freeze Rectangle's UI for that whole duration, on every placement.

Fix: set a 0.25s AX messaging timeout on the system-wide element for the duration of the scan, and restore the default immediately after via defer. An app that doesn't answer within the cap is simply skipped (no offset applied for it), which is harmless. Under normal conditions nothing changes — responsive apps answer far faster than the cap.

Only affects the overlap-offset path (behind cyclingOverlapOffset).

The overlap-offset check enumerates every window over the accessibility
API on the main thread before each grid placement. A hung app - or, under
heavy system load, a merely sluggish one - can block that enumeration for
the full default AX timeout (seconds), freezing the UI on every window
move. Set a 0.25s messaging timeout on the system-wide element for the
duration of the scan and restore the default right after; an app that
can't answer in time is skipped (no offset), which is harmless.
@MyronKoch MyronKoch changed the title Cap the overlap-offset window scan so it can't stall the UI under load Bound the overlap-offset window scan so an unresponsive app can't freeze the UI Aug 8, 2026
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