fix: reject off-desktop region offsets with a clear error (#41)#46
Merged
Conversation
A region: whose rectangle fell outside the virtual desktop (a negative offset before the leftmost monitor, or one past the right/bottom edge) was accepted by parseTarget and then failed in gdigrab with a cryptic libav error. resolveCaptureTarget now validates a raw region against the live virtual-desktop bounds (the bounding box of all monitors) before capture. Negative offsets stay valid when a monitor sits left of/above the primary, since the check uses the real desktop origin, not a blanket >= 0. virtualDesktopBounds and validateRegionOnDesktop are pure and unit-tested. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
89d2707 to
d49e443
Compare
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.
Summary
Fixes #41. A
region:target with a negative x/y (or one extending past the virtual desktop) was accepted byparseTarget(which allows negative offsets) but then failed in gdigrab with a cryptic ffmpeg error, e.g.screenshot { target: "region:-100,0,300,200" }.Changes
targets.ts:virtualDesktopBounds(monitors)(bounding box of all monitors) andvalidateRegionOnDesktop(region, monitors), which throws a clearScreencastErrornaming the region and the desktop bounds.resolveCaptureTargetvalidates a rawregion:against the live desktop bounds before capture. A window resolves to a region already clamped to the desktop, so only the raw-region path needs the check.>= 0. With no monitor geometry the check is skipped.Tests
virtualDesktopBoundsandvalidateRegionOnDesktopare pure and unit-tested: inside-desktop passes; negative-before-leftmost and past-right-edge are rejected; a legitimate negative offset with a left monitor passes; empty geometry skips.Verification
npm run build,npm run typecheck,npm testall pass (143 passed, 6 skipped).🤖 Generated with Claude Code