-
Notifications
You must be signed in to change notification settings - Fork 566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi-format copy and paste #330
Conversation
This was a slog, and there are problems, but it will get runebender moving forward. [mac] First cut of custom clipboard paste types This checkpoint attempts to generalize the idea of pasting custom types on macOS in a way that I *hope* is fairly flexible. I don't expect this to last, because I would like to have a common mechanism for reading and writing of custom types to the clipboard, but I'd like to check this in before I make too much of a mess. Impl most of a new clipboard API This is the bones of a more flexible system for copy/paste. The most basic idea is that when the user wants to copy or paste custom types, they define some marker struct and implement the `ClipboardRead` and or `ClipboardWrite` traits. Methods on these traits can be implemented per-platform, to return platform specific information about how to serialize and deserialize a given type. If impls are omitted for a platform, the type is ignored on that platform. The intent with this API is to be maxmimally accomodating to the fact that copy/paste APIs are very different on different platforms; instead of trying to come up with a lowest common feature set, we instead try to be as general as possible, without sacrificing ergonomics. TODOs: - I would like to prove this out on at least one additional platform - I would like to make copy/cut easier to use with this API; in particular I would like to support copying multiple data-types. [mac] Support multiple format cut/copy [win] Get basic cut/copy working with new API [win] Preliminary copy/paste of custom formats and multi-format [shell] Redo clipboard code Ultimately I'm not entirely happy with this API, but eventually you have to move on and live your life.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just skimmed the logic, didn't go deep into the details of any platform concerns, but looks good enough to me, willing to deal with problems as they come up.
druid-shell/src/clipboard.rs
Outdated
} | ||
|
||
impl ClipboardFormat { | ||
/// Create a new `ClipboardFormat` with the given `FormatId` and byes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bytes
/bloat |
🗜 Bloat check ⚖️Comparing 17dfe68 against 35d0052
|
This was very frustrating! I spent a lot of time trying to come up with a more "just works" API, but it ended up getting hairy and ultimately I ripped it out and tried to just do the simplest API I could.
In any case, this is working on mac, windows and gtk. The only bug I'm aware of is on GTK; if you put multiple formats on the clipboard, and one of them is text, the clipboard doesn't seem able to retrieve the text. I'm not totally sure what's going on there, but I'm not going to fight it right now, it's a pretty marginal case all in all.
Anyway: this covers the common case (text) and the special case required by runebender (multi-format vector data) comfortably. There may be future limitations; in particular I think doing copy/paste for images is going to be a headache and a half, but we can worry about that at some future date.