Skip to content

feat(screenshot): add --geometry flag to selection coordinates - #3274

Merged
bbedward merged 4 commits into
duxlabs-dev:masterfrom
hthienloc:feat/screenshot-geometry-flag
Sep 3, 2026
Merged

bbedward merged 4 commits into
duxlabs-dev:masterfrom
hthienloc:feat/screenshot-geometry-flag

Conversation

@hthienloc

Copy link
Copy Markdown
Member

Adds a -g, --geometry flag to dms screenshot to output selected geometry (X,Y WxH) directly to stdout without capturing an image buffer, saving files, or copying to clipboard.

I am planning to add screen recording to Quick Capture, but currently I have to use slurp for geometry capture. So this PR should help make DMS more self-contained. It would also be nice since dms screenshot has better region selection than the alternatives.

- Add -g/--geometry persistent flag to print region geometry (X,Y WxH) to stdout.
- Skip image buffer allocation, cropping, and file/clipboard/notification actions when in geometry mode.
- Support standard Enter/Space confirmation or mouse release via --no-confirm.
- Exit with code 1 when selection is cancelled, matching slurp behavior for script integrations.
- Support printing geometry across last, window, output, full, and all modes.
- Add unit tests in region_geometry_test.go.
…sult helpers

- Add bounds() method on WaylandOutput to deduplicate Hyprland geometry lookup across output capture and search.
- Add geometryResult() helper in screenshot package to eliminate redundant CaptureResult literals.
- Add GeometryString() method on Region to unify geometry formatting.
- Refactor selectedLogicalGeometry() to return Region directly.
- Clean up flag validation in runScreenshot.
@hthienloc

Copy link
Copy Markdown
Member Author

/claude review

Comment thread core/internal/screenshot/region.go Resolved
Comment thread core/cmd/dms/commands_screenshot.go Resolved
Comment thread core/internal/screenshot/screenshot.go Resolved
@claude

claude Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Claude review

Feature works end to end, but the reported geometry does not match what DMS itself captures — three correctness issues, all in the new geometry paths.

  • Region geometry is 1px smaller than the selection every other path uses (inclusive edges), core/internal/screenshot/region.go:286
  • x/y use omitempty, so an origin at 0 vanishes from --geometry --json output, core/cmd/dms/commands_screenshot.go:41
  • bounds() returns logical origin with device-pixel size, so full/output/all/last disagree with region mode on scaled outputs, core/internal/screenshot/screenshot.go:339

Checked: flag wiring and mode/stdout guards, selection math against selectionExtent/selectionRenderBounds, shift-square and cancel handling, the bounds() refactor in findOutputForRegion, buffer lifetime on the nil-buffer path, and the new test table. Model: claude-opus-5.

…utput

- Derive selectedLogicalGeometry from selectionExtent and ext.logical to keep geometry in sync with inclusive selection bounds.
- Use pointer int for X and Y in screenshotMetadata so (0,0) origins are preserved in JSON output.
- Divide output dimensions by effectiveScale in bounds() for non-Hyprland compositors and handle transform rotation.
- Convert stored device coordinates to logical units in captureLastRegion geometry mode.
- Update and expand unit tests for inclusive bounds, preselection, and scaled outputs.
@hthienloc

Copy link
Copy Markdown
Member Author

/claude review

Comment thread core/internal/screenshot/region.go Resolved
Comment thread core/internal/screenshot/screenshot.go Resolved
@claude

claude Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Claude review

Previous three findings are fixed; two new correctness issues remain in the geometry paths.

  • Region -g writes logical-unit coords into the last-region store (device-px convention), breaking screenshot last on scaled outputs, core/internal/screenshot/region.go:242
  • window -g on niri returns before the geometry check, printing 0,0 0x0 and still capturing the image, core/internal/screenshot/screenshot.go:230

Checked: re-verified the three earlier findings (inclusive edges now match selectionExtent/selectionRenderBounds, x/y are *int, bounds() divides by effectiveScale()), the new test table against the extent math, flag/shorthand registration and the stdout/scroll guards, cancel and no-confirm paths through finishSelection, buffer lifetime on the nil-buffer branch, and each per-mode geometry short-circuit for unit consistency. Model: claude-opus-5.

…nd handle niri window geometry

- Guard SaveLastRegion in captureRegion with !s.config.Geometry to prevent overwriting saved region with logical coordinates.
- Return explicit error when attempting window -g on niri instead of printing bogus 0,0 0x0 rect.
- Populate Region dimensions in captureNiriWindow.
@hthienloc

Copy link
Copy Markdown
Member Author

/claude review

@claude

claude Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Claude review

No issues found. Both findings from the last round are fixed and I could not confirm anything new.

Checked: captureRegion now guards SaveLastRegion with !s.config.Geometry, so a -g query no longer writes logical-unit coords into the device-px last-region store; captureWindow rejects window -g on niri before reaching captureNiriWindow, so no bogus 0,0 0x0. Re-verified the earlier three: selectedLogicalGeometry derives from selectionExtent()/logical() and matches the inclusive edges used by selectionRenderBounds (hand-checked each test case), x/y are *int so a 0 origin still serializes, and bounds() divides by effectiveScale(). Also checked unit consistency across every -g short-circuit (last divides by scale to match the device-px store convention, window gets logical rects from hyprctl/mmsg, full/output/all go through bounds()), the findOutputForRegion switch to logical-sized hit boxes (a fix for scaled multi-monitor, and findOutputByName now runs first for last), the shift-square and cross-output extent math, cancel/--no-confirm paths through finishSelection, exit codes and --json output on abort and error, -g shorthand collisions, and the new test table against the extent math. Model: claude-opus-5.

@bbedward
bbedward merged commit 0fc4aac into duxlabs-dev:master Sep 3, 2026
3 checks passed
@hthienloc
hthienloc deleted the feat/screenshot-geometry-flag branch September 3, 2026 12:49
@hthienloc
hthienloc restored the feat/screenshot-geometry-flag branch September 4, 2026 09:02
@hthienloc
hthienloc deleted the feat/screenshot-geometry-flag branch November 15, 2026 15:38
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.

2 participants