Bound the overlap-offset window scan so an unresponsive app can't freeze the UI - #1810
Open
MyronKoch wants to merge 1 commit into
Open
Bound the overlap-offset window scan so an unresponsive app can't freeze the UI#1810MyronKoch wants to merge 1 commit into
MyronKoch wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).