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. |
Add
ActiveEventLoop::clipboardandActiveEventLoop::set_clipboardforinteracting with the system clipboard through the data transfer API, implemented on Wayland and macOS.
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.
Tested by
clipboardexample: press C to copy, V to paste, logs the advertised types.Cross-checked against a browser on hyprland ,niri and kwin.
Also tested in Graphite's desktop app.
Other changes:
winit-waylanddndmodule is renamed todata_transfer, andDndStatetoDataTransferState(wayland: rename dnd module to data_transfer)dispatched_events(wayland: mark dispatched events when a data transfer fetch completes)