Skip to content

fix: reject off-desktop region offsets with a clear error (#41)#46

Merged
TMHSDigital merged 1 commit into
mainfrom
fix/41-region-bounds
Jun 16, 2026
Merged

fix: reject off-desktop region offsets with a clear error (#41)#46
TMHSDigital merged 1 commit into
mainfrom
fix/41-region-bounds

Conversation

@TMHSDigital

Copy link
Copy Markdown
Owner

Summary

Fixes #41. A region: target with a negative x/y (or one extending past the virtual desktop) was accepted by parseTarget (which allows negative offsets) but then failed in gdigrab with a cryptic ffmpeg error, e.g. screenshot { target: "region:-100,0,300,200" }.

Changes

  • New pure helpers in targets.ts: virtualDesktopBounds(monitors) (bounding box of all monitors) and validateRegionOnDesktop(region, monitors), which throws a clear ScreencastError naming the region and the desktop bounds.
  • resolveCaptureTarget validates a raw region: 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.
  • Negative offsets stay valid when a monitor sits left of / above the primary: the check uses the real desktop origin, not a blanket >= 0. With no monitor geometry the check is skipped.

Tests

virtualDesktopBounds and validateRegionOnDesktop are 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 test all pass (143 passed, 6 skipped).

🤖 Generated with Claude Code

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>
@TMHSDigital TMHSDigital force-pushed the fix/41-region-bounds branch from 89d2707 to d49e443 Compare June 16, 2026 23:20
@TMHSDigital TMHSDigital merged commit 5e46963 into main Jun 16, 2026
@TMHSDigital TMHSDigital deleted the fix/41-region-bounds branch June 16, 2026 23:20
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.

Bug: negative / off-desktop region offsets are accepted but fail in ffmpeg with a cryptic error

1 participant