Repository navigation
clipboard data transfer api - #4658
Conversation
ogoffart
left a comment
There was a problem hiding this comment.
Thanks a lot for working on this.
One problem with the API is that this doesn't support multiple clipboard like the middle-click paste vs ctrl+c/v.
I'm thinking the clipboard and set_clipboard functions should take an enum telling what keyboard we want.
Thank for the review. Isn't the primary selection just a Linux thing? If it should be part of the general API I would also suggest taking an enum with Clipboard::Selection and Clipboard::Primary. |
|
Yes, I meant clipboard. |
An you would prefer that being part of the cross platform api (would be easier to implement I guess)? If it should be a cross platform thing what should platforms that don't have the primary selection do? Return unsupported? |
1deca6f to
3d17417
Compare
|
I think one other point is that this API should be brought to every platform that is supported by other clipboard crates, so x11/wayland/windows/macOS at least, so users who rely on special crates for clipboard can just replace them with winit clipboard... And yeah, on linux we'd need an extra trait for |
|
I'm working on/thinking about the mac implementation, and I could also work on x11 (my testing would be limited to Xwayland) but not sure when I would be able to work on Windows, likely better if someone else with more Windows knowledge works on that. Personally I would prefer every platform being in it's own (stacked) PR but if maintainers prefer this being one giant PR sure. And I will add a trait for primary selection, definitely the shape I prefer. |
3d17417 to
a880dd6
Compare
a880dd6 to
eabee20
Compare
|
appkit implementation is now in shape I'm happy with, less complicated than initially anticipated. I'm not making good progress with x11 though and haven't looked much into the windows side. |
01fea5a to
8d61b17
Compare
|
Hi, I'm collaborating with Timon into adding the X11 backend. I have a mostly working implementation at timon-schelling#1. X11 requires an event to get the possible To avoid XFixes, it would be possible to poll to see where the selection changes. Alternatively the API could be adjusted so that users do not know the available types when issuing the paste request (although this would likely be annoying). I have not currently added support for the Also when the program ends and it owned the clipboard, it is not possible to paste. I think it is possible to send the data to a clipboard manager when closing. Is support for this desired? Unfortunately the X11 implementation is already quite long and complex. A lot of this is due to support for the |
Isn't this is the same as Wayland here? But besides, I think xfixes is available in a lot of places so maybe fine. |
I don't think so? The code in this PR does something like: let offer = seat.data_device()?.data().selection_offer()?;
offer.with_mime_types(|types| {
types.iter().map(|mime| MimeType::parse(mime.clone())).collect()
});Which appears inspects the mime types synchronously.
Sounds good; thanks for the input @kchibisov. |
741cf27 to
d4763cb
Compare
1226add to
7250240
Compare
79479bf to
c596b3c
Compare
|
Tested the Windows implementation locally on Windows 11. The clipboard example and existing tests pass, but I ran into a few edge cases around OLE flushing, payload caching and child window focus. Left inline comments with details on how I hit each one |
2a00d7f to
9734536
Compare
9734536 to
80205b6
Compare
80205b6 to
e911d10
Compare
e911d10 to
2789058
Compare
|
I checked it on Windows/Mac again and it looks fine (beside that small issue on Mac). |
2789058 to
7868eea
Compare
Hyprland and KWin deliver the clipboard selection only to the first wl_data_device a client creates. Winit owns that device but exposes no clipboard read, so smithay-clipboard's second device received nothing and paste failed with "selection is empty". Read through Winit's clipboard API instead (rust-windowing/winit#4658), using the same device as drag-and-drop. Fixes skyline69#1
Hyprland and KWin deliver the clipboard selection only to the first wl_data_device a client creates. Winit owns that device but exposes no clipboard read, so smithay-clipboard's second device received nothing and paste failed with "selection is empty". Read through Winit's clipboard API instead (rust-windowing/winit#4658), using the same device as drag-and-drop. Fixes #1
Add
ActiveEventLoop::clipboardandActiveEventLoop::set_clipboardforinteracting with the system clipboard through the data transfer API, implemented on Wayland, X11, macOS and Windows.
changelogmodule if knowledge of this change could be valuable to usersFollow-up of #4571
Addition to public API consists of two new methods on
ActiveEventLoop, both defaulting toNotSupported:Works like the DnD API.
clipboard()gives you aDataTransferId, orNoneifthe clipboard is empty. Pass it to
data_transfer()for the types andfetch_data_transfer()for the data, which arrives asDataTransferReceived.set_clipboard()takes aDataTransferSend, encoded lazily when another appasks for a type, and dropped when someone else takes over the clipboard.
Matching API for the primary selection is available on Wayland and X11 through
ActiveEventLoop::primary_selection_ext.Tested with new
clipboardexample: press C to copy, V to paste, logs the advertised types etc.Tested with plaintext and images on Wayland (hyprland, niri and kwin), Xwayland, macOS 16 and Windows 11.
Also tested in Graphite's desktop app (Integration PR).
Primary selection was tested with the same example slightly modified (I think that code should be left out of the example to keep it simple).
Changes to be aware of that are not strictly required for the feature but I think desirable:
dndmodules renamed todata_transfer, andDndStatetoDataTransferState.dispatched_events.fetch_data_transfer()failed when called on DragDroped (only fetching on DragEntered was guaranteed, witch is inconsistent with other platforms).Should be done in followup (intentionally not included here):
Implement Linux extension trait that allows for access to the(included now)Primaryclipboard.Thanks to @0HyperCube for implementing the X11 backend!