wl-clipboard icon indicating copy to clipboard operation
wl-clipboard copied to clipboard

Copy "entire" file (not just file content)

Open ysooqe opened this issue 1 year ago • 14 comments

Hi there,

I have looked around this repo, but I haven't found a matching issue.

How can an "entire" file be copied to the clipboard so that it can be pasted into other applications like web-browsers or email-clients (e.g. as attachments)?

When I do something like $ wl-copy < my_document.pdf, it appearently only copies the file content, but not the entire file. I can not paste the copied file into another application with Ctrl+V.

What is the command to copy the entire file into the clipboard via wl-copy?

ysooqe avatar Nov 23 '24 10:11 ysooqe

Hi, please see https://github.com/bugaevc/wl-clipboard/issues/26

In particular, something like this is likely to do what you want:

$ wl-copy -t text/uri-list "file://$(realpath my_document.pdf)"

bugaevc avatar Nov 23 '24 12:11 bugaevc

Thanks for the quick reply! Unfortunately, this does not seem to work (and neither do the suggestions from the linked issue thread).

In Gnome, when I go to Nautilus and Ctrl+C on a file, $ wl-paste --list-types gives me

text/plain;charset=utf-8
text/uri-list
application/vnd.portal.files
application/vnd.portal.filetransfer
x-special/gnome-copied-files

and $ wl-paste returns

/home/user/my_document.pdf

and I can easily paste this file into other applications using Ctrl+V.

Now I tried doing $ wl-paste | wl-copy -t <type> where <type> is any of the above, then I tried to paste this into another application with Ctrl+V to see what happens; but nothing happend for any of the types (and I made sure to re-copy the file from Nautilus between trying this command with different types).

So this kind of seems like there must be something else that Nautilus is copying into the clipboard compared to wl-copy?

ysooqe avatar Nov 23 '24 12:11 ysooqe

i came here cuz https://yazi-rs.github.io/docs/tips/#selected-files-to-clipboard wasn't working...

what i found was

wl-copy -t x-special/gnome-copied-files file:///home/vaisakh/Vide
os/getvid.mp4

now i can paste to thunar(maybe nautilus too?) file manager, but not to browser

wl-copy -t text/uri-list file:///home/vaisakh/Videos/getvid.mp4

now i can paste to browser (firefox)

can i specify both type at once?

Vaisakhkm2625 avatar Nov 30 '24 03:11 Vaisakhkm2625

wl-copy -t text/uri-list "file://$(realpath my_document.pdf)"

This especially does not work for portals as they use something different

septatrix avatar Dec 16 '24 10:12 septatrix

Hi, this is still relevant and I would love to be able to do this. My use case is a screenshot script that copies the screenshot file to the clipboard.

mattfbacon avatar Feb 06 '25 21:02 mattfbacon

I just created a pull request for this, https://github.com/bugaevc/wl-clipboard/pull/248

i am not that good at c, but i hope this will do..

Vaisakhkm2625 avatar Feb 07 '25 13:02 Vaisakhkm2625

Hi @Vaisakhkm2625 . Thanks for the effort and that is definitely better than nothing but there is still some necessary functionality missing because there are certain mime types, like application/vnd.portal.filetransfer that do special things behind the scenes -- for example for that mime type the "copied" data is just some numeric ID; I have not investigated how the ID is generated but it would require more advanced behaviour.

mattfbacon avatar Feb 07 '25 13:02 mattfbacon

So, application/vnd.portal.filetransfer and application/vnd.portal.files are based on a D-Bus protocol: https://github.com/flatpak/xdg-desktop-portal/blob/main/data/org.freedesktop.portal.FileTransfer.xml

wl-clipboard currently contains no dbus code. I think it would not be very good to add it just for this. The question is just, how many applications actually depend on that protocol?

mattfbacon avatar Feb 07 '25 13:02 mattfbacon

So, application/vnd.portal.filetransfer and application/vnd.portal.files are based on a D-Bus protocol: https://github.com/flatpak/xdg-desktop-portal/blob/main/data/org.freedesktop.portal.FileTransfer.xml

wl-clipboard currently contains no dbus code. I think it would not be very good to add it just for this. The question is just, how many applications actually depend on that protocol?

:( i am not sure, but i assume almost all application that packaged under flatpak right? biggest issue is, it feel like it's own sub project, as it's not only need to support things like checking for flatpak permissions but i hope it also need to check for various inconsistencies of the implementations between different DEs...

Vaisakhkm2625 avatar Feb 07 '25 14:02 Vaisakhkm2625

wl-clipboard currently contains no dbus code. I think it would not be very good to add it just for this. The question is just, how many applications actually depend on that protocol?

Anything running as a Flatpak which on my system is e.g. Telegram, Signal, Discord...

septatrix avatar Feb 07 '25 14:02 septatrix

OK, then I think we need the opinion of the maintainers. My instinct is to say that FlatPak should be responsible for that, i.e., bridging copied files into the flatpak sandbox. But I have no idea how that would work.

mattfbacon avatar Feb 07 '25 14:02 mattfbacon

My instinct is to say that FlatPak should be responsible for that, i.e., bridging copied files into the flatpak sandbox. But I have no idea how that would work.

It already handles most of it as long as it's not about files. For files, however, there needs to be special care as the apps cannot access the original location. Generally the toolkits which initiate the copying already take care of that (e.g. GTK for GNOME Files, QT for Dolphin) but as this project completely sidesteps those and does everything manually we will need to do the talking to D-Bus ourselves

septatrix avatar Feb 07 '25 19:02 septatrix

OK, then I think we need the opinion of the maintainers. My instinct is to say that FlatPak should be responsible for that, i.e., bridging copied files into the flatpak sandbox. But I have no idea how that would work.

but as this project completely sidesteps those and does everything manually we will need to do the talking to D-Bus ourselves

Indeed Flatpak/D-Bus has nothing to do with wl-clipboard. wl-clipboard interacts with the Wayland clipboard, not with clipboard implemented over other protocols like D-Bus or X11.

If you want to build an utility for copying files into clipboard in a Flatpak-aware way, you might use wl-clipboard as one of the components it builds on. Another other component might be busctl for example (which does D-Bus and not Wayland or X11). You'd call the D-Bus method to start a session and add the files to transfer, then copy the key into the Wayland clipboard using wl-clipboard.

bugaevc avatar Feb 08 '25 20:02 bugaevc

OK, so for wl-clipboard we just need support for multiple mime types.

In terms of interface I like the look of something like wl-clipboard -t text/plain hello -t application/json '{"message":"hello"}' -t text/html '<p>hello</p>' but this is not practical if the strings to be copied start with dashes or come from stdin. So I don't know.

mattfbacon avatar Feb 08 '25 22:02 mattfbacon