Skip to content

fix: ocr_region not read everything above a window far from the menu bar - #59

Open
bluzername wants to merge 1 commit into
awlevin:mainfrom
bluzername:fix-ocr-region-above-window
Open

bluzername wants to merge 1 commit into
awlevin:mainfrom
bluzername:fix-ocr-region-above-window

Conversation

@bluzername

Copy link
Copy Markdown

Fixes #35.

ocr_region joined the window rect with a box that start at y=0, so a window
low on the screen pull in all the text above it in its own columns too. On a
5K display with a Finder window at y=609 pt over a full-screen terminal, this
make one OCR step take 46s and read mostly the terminal text, not Finder.

The fix is simple: read the window rect with its margin, clamped to the
display, nothing else. The menu bar text still reach the model through the
accessibility tree as AXMenuBarItem controls (as the issue says), so this
lose nothing.

Root cause: min(window[1], 0.0) always resolve to 0.0 since a window top is
almost never negative, so the top of the region was always the top of the
display, not the menu bar strip the comment describe.

Test approach (TDD): added test_region_does_not_reach_above_a_window_low_on_the_display
in tests/test_ocr_cache.py, confirmed RED against current main (region[1] was 0.0
instead of the window top), then fixed ocr_region and confirmed GREEN. Also
updated the two older tests that asserted the old, buggy join behavior
(test_region_reaches_the_menu_bar_even_for_a_window_low_on_the_display and
test_region_is_at_least_the_menu_bar_strip_for_a_window_above_it) to match
the corrected behavior.

Verification: uv run ruff check . && uv run ruff format . clean, uv run pytest -q
730 passed, 2 skipped, 1 xfailed (same totals as main, just two tests renamed
to match the fix).

🤖 Generated with Claude Code

ocr_region joined the window rect with a box that always start at y=0,
so a window low on the screen pull in all the text above it in its
columns too. On a 5K display with Finder at y=609 over a full terminal,
this make one OCR step take 46s and mostly return the terminal's text.

Now ocr_region just read the window rect with its margin, clamped to
the display. The menu bar text still reach the model through the
accessibility tree as AXMenuBarItem controls, so nothing is lost.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.

OCR region reads everything between the menu bar and a window that starts low on the screen

1 participant