screenshot: add screenshot-to-clipboard command
Successor to #13837, post-#15355 and #15564.
Currently implemented only on macOS.
Download the artifacts for this pull request:
Rebased with suggestions applied; split the function up to the extent that was possible without adding substantial duplication or major restructuring.
I think there is no need for this to be a command. I designed the clipboard API with the ability for format conversion in mind: when the data formats in clipboard_access_params and clipboard_data are different, the backend can perform automatic format conversion if possible. This makes it possible to use the operating system's built-in data format conversion abilities.
In this specific case, it is possible to make the clipboard/image property writable, and a client can just set the clipboard content by writing a special token of MPV_FORMAT_STRING type like @screenshot window to the property.
Alternatively, writing a MPV_FORMAT_NODE nodemap containing information of the raw image data to that property should write that image to the clipboard, so a client can also use screenshot-raw command to acquire the image data and write the data to clipboard.
These approaches allow for more flexibility of setting image clipboard contents while not introducing a new command.
I think supporting setting an MPV_FORMAT_NODE makes sense in the long term, but designing an API for it that's actually useful across a variety of pixel formats, colorspaces, etc. is going to be tricky, so I'd prefer to leave it out of this PR for now (see also the screenshot-raw command, which returns a node, but in a single hardcoded pixel format with no colorspace information).
I wouldn't object to having this be set clipboard/image "@screenshot window" or the like, though I do think the symmetry the current approach has with screenshot-to-file is probably a bit more intuitive for users?
Also, it probably makes most sense for any magic-string @screenshot support to happen up at the command/property level, rather than within each individual backend.
tested the the mac parts and works as expected in programs that can handle those pastes. besides that one open point i am fine with he swift parts of the code.
would be nice if we could resolve the rest of the open points in a timely manner:
- the user facing API
- implementation on the mpv core side
Rebased this a couple days ago; where are we on this now? Do we want to do set clipboard/image "@screenshot"?