Repository navigation
fix(macos): list windows raised above the normal window layer - #594
Closed
MateuszJuszczyk wants to merge 2 commits into
Closed
MateuszJuszczyk wants to merge 2 commits into
MateuszJuszczyk wants to merge 2 commits into
Conversation
Window managers such as Sunlight, yabai and Aerospace raise the window the user is working in above kCGNormalWindowLevel. The CoreGraphics inventory dropped every window whose layer was not 0, so a real application window on layer 2 never reached the window list. With no record left for the frontmost window, the global inventory could not join the accessibility focused window and every attempt retried until the deadline, so `list-windows` failed with TIMEOUT while `list-windows --app <name>` returned an empty list. Keep the layer on each CoreGraphics record and decide admission on the accessibility side: a raised window is kept only when its owning process publishes its exact window number as an AXStandardWindow. Menus, panels, status items and the Dock stay excluded because they are never standard windows of their owner, and layer-0 windows keep their existing behavior. The scoped inventory already reads each owner's accessibility window state, so it admits raised windows from that read. The global inventory probes only the owners that actually have a raised window, which keeps the existing rule that background owners are not probed.
Contributor
|
@MateuszJuszczyk is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
A hung background app owning a raised window could spend the whole global inventory deadline in its accessibility admission probe, so list-windows timed out even with a healthy foreground app. The frontmost owner is now probed first with the full deadline; background owners get 250 ms each from a shared 1 s budget, and a probe that runs out only drops that owner's raised windows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
wojciechsacewicz
approved these changes
Nov 12, 2026
Collaborator
|
closing as superseded by #702 on main ( |
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.
Problem
macOS window inventory commands miss real application windows when a window manager moves them off the normal window layer. With Sunlight 0.2.3 running, the active Zen window sits on
kCGWindowLayer2 (window-server data:owner Zen, number 13458, layer 2, alpha 1, onscreen true, bounds 0,33 1512x949), while accessibility reports the same window normally (AXWindow/AXStandardWindow, 0,33 1512x949).agent-desktop list-windows --app zenreturns{"ok":true,"data":[]}.agent-desktop list-windowsfails withTIMEOUT,detail.kind: global_window_inventory_unstable,last_code: APP_UNRESPONSIVE,last_kind: frontmost_window_join.Root cause
records_from_dictionariesreadkCGWindowLayeratcrates/macos/src/system/window/cg_window.rs:129and dropped every window whose layer was not 0 atcrates/macos/src/system/window/cg_window.rs:130, before the accessibility side was consulted. A raised window therefore never became a candidate.list_windows_untilcaptures through the same function (crates/macos/src/system/window/window_inventory.rs:51), so--app <name>filters the only real window out and returns an empty list beforenarrow_to_real_windows(window_inventory.rs:160).assemble_global_windowsreads the frontmost application'sAXFocusedWindow(crates/macos/src/system/window/window_inventory_global.rs:133) and requires that window number to join exactly one CoreGraphics record.matching_focus_windows(window_inventory_global.rs:283) finds none, andwindow_inventory_global.rs:144reportsfrontmost_window_join, whichstabilize_global_withretries until the deadline. That is the observed 74/120 attempts and the timeout.The layer filter was there to keep menus, panels, status items and the Dock out of the list, but the layer alone cannot tell a raised application window from system chrome.
Fix
kCGWindowLayerand no longer filter on it (crates/macos/src/system/window/cg_window.rs).crates/macos/src/system/window/window_admission.rsdecides admission from accessibility: a raised window is kept only when its owning process publishes that exact window number as anAXStandardWindow. Menus, panels, status items and the Dock stay excluded because they are never standard windows of their owner.crates/macos/src/system/window/window_ax_state.rscollects each owner's standard window ids from the sameAXWindowspass the scoped inventory already performs, so admitting a raised window costs no extra round trip there. The global inventory probes only owners that actually have a raised window, which keeps the existing rule that background owners are not probed.Tests
window_admission_tests.rs: a layer-2 window matching an AX standard window is kept; a layer-101 overlay of the same owner is excluded; layer-0 windows need no probe; a failed probe drops only that owner's raised windows; each owner is probed once.window_inventory_admission_tests.rs: a layer-2 window is listed and joins the AX focus number; a layer-101 window without the standard subrole is excluded; normal-layer windows are unchanged.cg_window_tests.rs: raised layers survive CoreGraphics parsing and reach admission.window_ax_state.rs: subrole gate test.cargo fmt --all -- --check,cargo clippy -p agent-desktop-core -p agent-desktop-macos -p agent-desktop -p agent-desktop-ffi --all-targets -- -D warnings,cargo testfor those packages, and the source-rule scripts all pass.Manual verification
macOS 27.0.1, Sunlight 0.2.3, Zen window on layer 2, read-only commands only. "Before" is upstream
main(b43ac4f) built from source, so both binaries differ only by this branch.list-windows --app zen{"ok":true,"data":[]}w-13458,1512x949at0,33, focused when Zen is frontmostlist-windowsTIMEOUTafter 8 s,last_kind: frontmost_window_join, 120 attemptsok:true, 150 windows, ~1.4 ssnapshot --app zencomplete:true, 73 refsIn the global list, the only window on a non-zero layer is the layer-2 Zen window. A Zen notification window on layer 101 and an unrelated window on layer 1000 are still excluded.
list-windows --app Claudeandsnapshot --app Claudeare unchanged (Claude's windows are on layer 0). Latency on layer-0 apps is unchanged within noise (list-windows --app Finder186 ms → 185 ms,snapshot --app Claude298 ms → 307 ms, median of 10).Out of scope
The reported
snapshot --app Claudetimeout did not reproduce here: Claude's windows are on layer 0 and the snapshot completes in about 0.3 s, so it is unrelated to this filter. Separately, the macOS app inventory lists browser helper processes as extra instances ofZen/Claude, which makes windowless--applookups ambiguous; that is also unrelated to this change.🤖 Generated with Claude Code