Skip to content

feat: add Win32 API foreground check as alternative to a11y-based detection#114

Merged
abrichr merged 2 commits intomainfrom
feat/win32-foreground-check
Mar 6, 2026
Merged

feat: add Win32 API foreground check as alternative to a11y-based detection#114
abrichr merged 2 commits intomainfrom
feat/win32-foreground-check

Conversation

@abrichr
Copy link
Member

@abrichr abrichr commented Mar 6, 2026

Summary

  • Add _check_foreground_win32() method using GetForegroundWindow() + GetWindowText() via PowerShell P/Invoke
  • Add focus_check_method config field (win32 default, a11y, or both) to WAALiveConfig
  • Add --focus-check-method CLI flag to run and live subcommands
  • Detect known-bad foreground states (Document Recovery, LibreOffice Start Center, empty title)
  • Add _check_foreground_dispatch() that routes to the configured method

The existing a11y-based check is slow and unreliable when LibreOffice is loading. The Win32 API approach reuses the pattern from _capture_focus_diagnostics() in minimal form.

Test plan

  • Run with --focus-check-method win32 against a live WAA VM
  • Run with --focus-check-method a11y to confirm existing behavior
  • Run with --focus-check-method both to verify fallback chain
  • Test with LibreOffice task for Document Recovery / Start Center detection

abrichr and others added 2 commits March 6, 2026 16:12
…ection

Add _check_foreground_win32() method that uses GetForegroundWindow() +
GetWindowText() via PowerShell P/Invoke for fast, reliable foreground
window title checking. This replaces the slow a11y-based check as the
default, while keeping a11y available via the focus_check_method config.

- New config field: focus_check_method (win32, a11y, or both)
- New CLI flag: --focus-check-method for run and live subcommands
- Detection of known-bad foreground states (Document Recovery, Start Center)
- Dispatch method routes to win32, a11y, or both (win32 first, a11y fallback)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The focus check default changed from a11y to win32, so tests need to
mock run_powershell instead of requests.get for the /accessibility
endpoint.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@abrichr abrichr merged commit 81f89b0 into main Mar 6, 2026
1 check 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