Skip to content
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

Merged
merged 2 commits into from
Nov 22, 2019
Merged

Multi-format copy and paste #330

merged 2 commits into from
Nov 22, 2019

Conversation

cmyr
Copy link
Member

@cmyr cmyr commented Nov 22, 2019

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.

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.
Copy link
Contributor

@raphlinus raphlinus left a 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.

}

impl ClipboardFormat {
/// Create a new `ClipboardFormat` with the given `FormatId` and byes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bytes

@cmyr
Copy link
Member Author

cmyr commented Nov 22, 2019

/bloat

@github-actions
Copy link

🗜 Bloat check ⚖️

Comparing 17dfe68 against 35d0052

target old size new size difference
target/release/examples/calc 1 MB 1021.13 KB -6.96 KB (-0.68%)
target/release/examples/scroll_colors 998.99 KB 992.06 KB -6.93 KB (-0.69%)
target/release/examples/multiwin 1 MB 1020.21 KB -6.95 KB (-0.68%)
target/release/examples/textbox 1.03 MB 1.03 MB -5.92 KB (-0.56%)
target/release/examples/custom_widget 998.53 KB 991.64 KB -6.89 KB (-0.69%)

@cmyr cmyr merged commit 529756f into master Nov 22, 2019
@cmyr cmyr deleted the copy-glyphs branch November 22, 2019 17:38
@cmyr cmyr mentioned this pull request Dec 31, 2019
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants