Design Idea: Support for copying multiple mime-types into the clipboard
wl-clipboard is an incredible tool, but is currently not exposing the two capabilities that I absolutely love about the wayland clipboard:
- Having support for multiple mime-types
- And computing the actual values lazily
To solve both of these problems at once I would suggest to add a command wl-copy --watch <command>-subcommand with the following execution pattern:
First accept a list of mime-types. Either over the command line as list of -t <mime-type>, or over stdin the of wl-copy as newline separated list.
Then advertise that list as available clipboard, and when a copy-request is made, that mime-type is written to the stdin of <command>, which then is expected to reply via stdout.
This design would make it incredibly easy to write for example shellscripte that compute file formats on-demand depending on what the client supports/requests.
I like this idea but I thought about it a bit and I think just allowing multiple (either comma separated or as multiple -t arguments) and picking the first compatible one would be enough for the majority of use cases, either way that behavior makes sense standalone and won't conflict with this. Imo --watch is unintuitive, I think most people would expect it to run a command to generate the data to copy on demand, that would be much more useful (e.g. you can implement pasting files into flatpak using the FileTransfer portal), or do you mean it should generate both the MIME type and data?
I like this idea but I thought about it a bit and I think just allowing multiple (either comma separated or as multiple
-targuments) and picking the first compatible one would be enough for the majority of use cases, either way that behavior makes sense standalone and won't conflict with this.
What do you mean with choosing the first compatible one?
Imo
--watchis unintuitive, I think most people would expect it to run a command to generate the data to copy on demand, that would be much more useful (e.g. you can implement pasting files into flatpak using theFileTransferportal),
I mean that is the goal of the idea. To first setup the list of mime-types that are supported and then, only when it is requested, to generate the data. (I could for example imagine converting SVGs to PNGs on request or even more creative use cases)
or do you mean it should generate both the MIME type and data?
- Setup the command with the list of mime-types you want to accept.
- Run the specified command when the data is requested.
Nevermind I got confused with how the clipboard works (the application pasting the clipboard controls the format from the ones advertised, multiple MIME types for static data is very rare and plain text having a lot of MIME types is handled transparently) and I thought you meant the stdin of the watch command not of wl-copy, I understand it now and it's really elegant.