Repository navigation
Conversation
The macOS adapter captured only the main display and read every frame against it, so a window on another display gave an empty step (awlevin#38). Capture the display under the frontmost window's center, and read the window, the focused field, and the accessibility frames in that display's points; a click adds the display's origin back. A capture whose shape is not that display's falls back to the main display. Fixes awlevin#38
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.
Fixes #38.
What was wrong
The macOS adapter assumed the main display everywhere:
screenshot()ranscreencapture -D 1.display_scale()divided by the main display's width.frontmost_window_bounds,focused_fieldand the AX frames came back in global points, andax_walkpruned everything outside(0, 0, w, h).A window on any other display (including one left of or above the main display, with negative coordinates) produced a capture that didn't show it, plus an empty AX walk.
What changed (
macos.pyonly; theDesktopsurface is unchanged)screenshot()picks the display under the topmost on-screen app window's center. Displays come fromCGGetActiveDisplayList, whose first entry is the main display, which is alsoscreencapture's-Dorder. It captures that display with-D nand remembers its number and bounds for the reads that follow.-D 1, which is the current behaviour.display_scaleuses that display's width.frontmost_window_bounds,focused_fieldand the frames fed towalk_actionableare shifted by its origin, so they're in that display's points with its top-left corner at0, 0, the same way a main-display capture always worked.click_atadds the origin back.scrollalready parks the pointer at the window's global center, so it doesn't change.CGWindowListCopyWindowInfoonly, so it adds no AppleScript round trip to the capture.docs/known-limits.md: "Only the main display is captured" now describes the remaining limit. One display is read per step: the one under the window's center on macOS, and the primary monitor on Windows. A window straddling two displays is read only on that one.I kept this inside the adapter rather than swapping adapters with
platform_adapter.using(), which the issue also suggested. Every read for a step already starts withdesktop.screenshot(), so the adapter can choose the display at that point. That avoids a newDesktopmethod thatwindows.pyand the OSWorld adapter would also need. I can restructure it as ausing()wrapper if you'd prefer that shape.Tests
I don't have a multi-display Mac, so
tests/test_displays.pyruns the realmacosfunctions with Quartz, AX andscreencapturereplaced by mocked platform data. The setup is a 1440×900 main display at the origin and a 1512×982 built-in display at(-1512, 200)captured at 2×, with the frontmost window on the built-in display. The tests check:-D 2, the scale is 2.0, and the window bounds are relative to the built-in display;-D 1.On
main, four of these fail and the main-display one passes:With the change, all five pass. Run locally on Linux (Python 3.12,
uv sync --frozen --extra rapidocr, the Linux CI job's setup):uv run ruff check .: all checks passeduv run ruff format --check .: 90 files already formatteduv run pytest -q: 736 passed, 1 skipped, 1 xfailedNot verified: a real run on macOS with two displays. In particular, I haven't confirmed on hardware that
screencapture -Dnumbers displays inCGGetActiveDisplayListorder. The aspect-ratio fallback is there in case it doesn't. I have no run folder to replay either, so I can't include a before/after replay note. A check on a real two-display setup like the one in the issue would be welcome.