Skip to content

Fix activation source window selection - #57

Merged
Saber5656 merged 1 commit into
mainfrom
codex/fix-source-window-selection
Jul 19, 2026
Merged

Saber5656 merged 1 commit into
mainfrom
codex/fix-source-window-selection

Conversation

@Saber5656

@Saber5656 Saber5656 commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Summary

  • disambiguate same-process layer-0 windows with the Accessibility focused-window frame
  • preserve the missing-permission fallback while failing closed on trusted AX lookup failures or ambiguous frame matches
  • add regression coverage for transient helper windows, legitimate small windows, trust/query states, ambiguity, and frame tolerance

Why

A real TextEdit E2E exposed a transient 66×20 layer-0 helper window ahead of the document in the CG window list. Selecting the first layer-0 window bound the activation to that helper, while Accessibility correctly reported the document as focused, so GridSelect failed closed with Source changed.

The production fix does not filter by size, title, or area. It selects the unique CG candidate matching the AX focused window within the existing ±1pt tolerance.

Validation

  • direct Swift 6 production compile with warnings-as-errors: PASS
  • deterministic source-window selector harness: PASS
  • git diff --check: PASS
  • live TextEdit E2E: selected document window 16037, CG and AX preflight checks true
  • live rectangle: rows [0,5), columns [17,24)
  • clipboard: 39 bytes, SHA-256 0267f5dda6750d3d85dda92d356e8d91c2dec3cc83e1f06a2f5a729d5b4295fd, exact expected output

Local swift build / swift test remain blocked before repository compilation by the installed Command Line Tools compiler/SDK/PackageDescription mismatch. GitHub Actions is the required official SwiftPM validation.

No release or merge action is included.

Summary by CodeRabbit

  • Bug Fixes

    • Improved macOS window selection when multiple windows are visible.
    • More reliably identifies the focused document window.
    • Preserves a safe fallback order when accessibility permissions are unavailable.
    • Prevents activation when the focused window cannot be confidently identified.
    • Supports small windows and allows minor frame-position differences when matching windows.
  • Tests

    • Added coverage for focused-window selection, permission fallbacks, query failures, and frame matching.

Use the Accessibility focused window to disambiguate same-process
layer-zero windows so transient helpers cannot invalidate selections.
Preserve the permission fallback while failing closed on trusted lookup
ambiguity.
@Saber5656 Saber5656 self-assigned this Jul 19, 2026
@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5c71c641-f701-4ea3-b7ab-84493ce7d610

📥 Commits

Reviewing files that changed from the base of the PR and between 91ff625 and 0a75c33.

📒 Files selected for processing (3)
  • Sources/GridSelect/MacOSAccessibilityTextExtractor.swift
  • Sources/GridSelect/MacOSGlobalShortcut.swift
  • Tests/GridSelectCoreTests/MacOSActivationSourceCapturerTests.swift

📝 Walkthrough

Walkthrough

Adds a focused-window accessibility query and uses its resolution state to select among macOS on-screen window candidates, with fallback, failure, uniqueness, and frame-tolerance tests.

Changes

Focused window selection

Layer / File(s) Summary
Accessibility focused-window lookup
Sources/GridSelect/MacOSAccessibilityTextExtractor.swift
Adds a bounded AX query for a process’s focused window and returns a validated accessibility element handle.
Candidate resolution and validation
Sources/GridSelect/MacOSGlobalShortcut.swift, Tests/GridSelectCoreTests/MacOSActivationSourceCapturerTests.swift
Introduces window snapshots and focused-window resolution states, selects uniquely matching frames with one-point tolerance, preserves untrusted fallback order, and fails closed on trusted query failures. Tests cover these outcomes.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MacOSActivationSourceCapturer
  participant SystemMacOSAccessibilityClient
  participant WindowCandidates
  MacOSActivationSourceCapturer->>WindowCandidates: collect on-screen candidates
  MacOSActivationSourceCapturer->>SystemMacOSAccessibilityClient: resolve focused window
  SystemMacOSAccessibilityClient-->>MacOSActivationSourceCapturer: resolution state and frame
  MacOSActivationSourceCapturer->>WindowCandidates: select first or uniquely matching candidate
  WindowCandidates-->>MacOSActivationSourceCapturer: selected window or nil
Loading

Possibly related PRs

Suggested labels: enhancement, type:test, area:macos, area:accessibility

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change to activation source window selection.
Description check ✅ Passed The description covers summary, motivation, and validation, but omits linked issue, scope, security, and notes sections from the template.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-source-window-selection

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 0a75c339a3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Saber5656
Saber5656 merged commit 1fe3807 into main Jul 19, 2026
4 checks passed
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