Skip to content

fix(screenshot): copy a saved screenshot as a file, not only image bytes - #3667

Merged
purian23 merged 2 commits into
duxlabs-dev:masterfrom
Conava:screenshot-clipboard-file
Oct 7, 2026
Merged

purian23 merged 2 commits into
duxlabs-dev:masterfrom
Conava:screenshot-clipboard-file

Conversation

@Conava

@Conava Conava commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR makes dms screenshot copy a saved screenshot as a file, so it can be pasted into terminals.

dms screenshot puts only image/png on the clipboard. Terminals can only paste text, so pasting a screenshot into a terminal app does nothing, for example into a CLI that attaches an image from a pasted path. A file copied through the server's clipboard.copyFile (which plugins use) pastes its path there and still pastes the image into image-aware apps.

  • When the screenshot is saved, it's copied the same way as clipboard.copyFile: x-special/gnome-copied-files, text/uri-list, the path as text/plain, and the image bytes. The server is asked first so the copy lands in history. Without a server, the CLI serves the same offers itself
  • clipboard.FileOffers builds the offer list for both, so Manager.CopyFile and the CLI can't drift apart. Manager.CopyFile's offers, order and history entry are unchanged
  • copyMultiFork waits for the child to take the selection, like copyForkCached, so a failed local copy is reported instead of lost
  • --no-file and --format ppm keep the image-only copy (there's no file to point to, and PPM isn't decodable as a clipboard image)

No new strings.

A few things worth flagging:

  • Pasting a saved screenshot into a plain text field now gives its path, the same as for any file copied through clipboard.copyFile.
  • dms cl copy --download shares copyFileToClipboard, so when the server is down or rejects the file (over MaxEntrySize), it now copies locally instead of exiting with an error. That copy gets no history entry.
  • The server's default MaxEntrySize is 5 MiB, so large PNGs (4K, several monitors) take the local fallback. Their history behavior is the same as before.
  • file:// URIs aren't percent-encoded, so paths with spaces give invalid URIs. Manager.CopyFile already does this; screenshots in such a directory now reach it too.

Validation

  • Tested by hand on Hyprland: a region screenshot pastes into a terminal as its path, which a CLI attached as an image
  • New TestFileOffers pins the full offer list in order, for an image and for non-image data
  • go test ./... (everything except internal/screenshot's TestWaylandOutputBoundsScaled, which also fails on upstream/master on this machine), make fmt, go vet on the changed packages, GOOS=freebsd go build ./..., prek run on the changed files. Skipped the qml-tests hook (needs niri) and the go-test hook (the screenshot test above)

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that changes existing behavior)
  • Refactor / internal cleanup
  • Documentation
  • Other

Related issues

Screenshots / video

Checklist

  • My code follows the conventions in CONTRIBUTING.md
  • I have tested my changes locally
  • New user-facing strings are wrapped in I18n.tr() with translator context, reusing existing terms where possible
  • Go changes: ran make fmt, added/updated tests, make test passes, and go mod tidy is clean
  • QML changes: ran make lint-qml with no new warnings
  • I have opened a corresponding pull request in dlx-docs to document any new behaviors: docs(screenshot): note that a saved screenshot is copied as a file dux-docs#156

dms screenshot put only image/png on the clipboard. Terminals can only
paste text, so pasting a screenshot into a terminal app (e.g. a CLI
that attaches images from a pasted path) did nothing, while a file
copied through the server's clipboard.copyFile pastes its path.

When the screenshot is saved to a file, copy it the same way:
gnome-copied-files, text/uri-list, the path as text/plain, and the
image bytes. The server is asked first so the copy lands in history;
without it, the same offers are served locally. The offer list is
shared with Manager.CopyFile through clipboard.FileOffers.

copyMultiFork now waits for the child to take the selection, like
copyForkCached, so a failed local copy is reported instead of lost.
dms cl copy --download shares this path and now falls back to a local
copy when the server is down or rejects the file. --no-file and PPM
keep the image-only copy.
@purian23

purian23 commented Oct 5, 2026

Copy link
Copy Markdown
Member

/claude review

@claude

claude Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Claude review

No issues found.
Checked: screenshot clipboard routing (saved file vs --no-file/PPM, relative output dirs), copyFileToClipboard server-first with local fallback, FileOffers parity with the old Manager.CopyFile offers, and the new _DMS_CLIPBOARD_READY handshake in copyMultiFork/signalReady (child reaches serveOffers → signalReady; a failed child gives EOF, which is reported). Model: claude-opus-5-5.

@purian23

purian23 commented Oct 5, 2026

Copy link
Copy Markdown
Member

Thanks for the PR, small merge conflict to resolve and we should be good to go!

Resolve the CopyFile conflict by keeping the shared FileOffers and moving
upstream's percent-encoding of file URIs into it, so both the server and
the CLI fallback offer encoded URIs.
@purian23

purian23 commented Oct 7, 2026

Copy link
Copy Markdown
Member

/claude review

@claude

claude Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Claude review

No issues found.
Checked: post-merge PR diff (Go only, no translation catalogs touched); screenshot clipboard routing (saved file vs --no-file/PPM), copyFileToClipboard server-first with local fallback and abs path, FileOffers parity with the old Manager.CopyFile offers and PNG/JPEG decoder registration for the image offer, _DMS_CLIPBOARD_READY handshake in copyMultiFork/signalReady. Model: claude-opus-5-5.

@purian23
purian23 merged commit 7c6e9ed into duxlabs-dev:master Oct 7, 2026
3 checks passed
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