Skip to content

[Bug] Main-thread multi-second hangs with Window Snapping enabled when interacting with busy Electron apps #288

Done

Description

@poife

Summary

With Window Snapping enabled in Multitouch (Snap windows by dragging / windowSnapping = 1), clicking or dragging windows while an Electron/Chromium app (for example, an IDE actively streaming output) is momentarily unresponsive to Accessibility IPC causes multi-second main-thread hangs (~9s observed in sample). Disabling Snap windows by dragging immediately eliminates the hangs.

Environment

  • macOS: 26.7.3 (25G342)
  • Hardware: MacBookPro16,2 (Intel)
  • Multitouch: 2.1.2 (236)
  • Settings: windowSnapping = 1, macOS native edge tiling disabled

Root Cause (sample analysis)

Sampling Multitouch during a hang showed ~9.2s spent blocked synchronously on the main thread across three consecutive unbounded Accessibility IPC calls (using the default ~3–6s AXUIElement messaging timeout each):

  1. AXUIElementCopyAttributeValue for .role (~3.03s)
  2. AXUIElementCopyAttributeValue for .windows (~3.05s)
  3. _AXUIElementCopyElementAtPositionIncludeIgnored (~3.07s)

Reproducing and sampling against the open-source rxhanson/Rectangle codebase confirmed two unbounded cascading AX paths on the main thread in SnappingManager:

  1. getWindowElementUnderCursor: cascades .windows -> systemWide.getElementAtPosition -> frontmost, and leftMouseDragged retries up to 20 times on failure, compounding stalls.
  2. checkFullScreen() -> getFrontWindowElement(): cascades .focusedWindow -> .windows -> systemWide.focusedUIElement, and AccessibilityElement(pid) also performs an extra .role IPC call inside applicationElement.

Proposed Fixes

Approach 1: Minimal synchronous fix (PR submitted to Rectangle)

Submitted in rxhanson/Rectangle#1988:

  • Bound SnappingManager's AX lookups (getWindowElementUnderCursor and checkFullScreen()) to Rectangle's existing 0.25s messaging timeout convention (already used in OverlapOffsetGeometry, StackBadgeManager, StackCycleManager, and NewWindowActionManager).
  • Short-circuit cascading fallbacks and leftMouseDragged retries immediately when an AX lookup times out or hits the app's own interactive window.
  • Skip the redundant .role IPC lookup when an AccessibilityElement is already created from a PID.
  • Short-circuit checkFullScreen() via NSApp.windows when the frontmost app is the app itself.
  • Local sample verification on Rectangle confirmed multi-second stalls dropped to a single bounded timeout with no cascading fallbacks or drag retries, and all unit tests pass (796 passed, 0 failed, 11 skipped).

Approach 2: Architectural option (background serial queue)

If you prefer to eliminate even the bounded 0.25s synchronous wait on the main thread during app/space/display transitions, checkFullScreen() (and/or AX window queries) could be moved to a dedicated background serial DispatchQueue with a generation counter (similar to TitleBarManager / StackCycleManager), applying the result back on the main thread only if the generation still matches. We kept PR #1988 synchronous to preserve SnappingManager's existing contract and unit tests, but wanted to flag this option in case you prefer it for Multitouch / Rectangle Pro.

Activity

  1. rxhanson commented on Nov 29, 2026

    @rxhanson
    Owner

    Thanks! I'll prioritize this so it makes it into a MT/RP release within the next few days. I'll dive deeper and see if approach 2 is my desired approach as well.

  2. rxhanson commented on Dec 4, 2026

    @rxhanson
    Owner

    This was rolled into Multitouch (2.2) & Rectangle Pro (3.104) releases this week, so I'll close this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions