-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Naive clipboard support #19106
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
base: main
Are you sure you want to change the base?
Naive clipboard support #19106
Conversation
Enabled with the `bevy_clipboard` feature. Supports setting and getting text to and from the clipboard. Only supports desktop targets.
Enabled with the `bevy_clipboard` feature. Supports setting and getting text to and from the clipboard. Only supports desktop targets.
Marked as X-Controversial due to a new crate, but I strongly think we need this as part of the engine in some form. Both for games and the editor! |
I don't like the crate for that which is pretty much just a resource wrapping arboard... And not sure I like the fake resource that can't work on not supported platforms |
crates/bevy_clipboard/src/dummy.rs
Outdated
/// | ||
/// Returns error if clipboard is empty or contents are not UTF-8 text. | ||
pub fn get_text(&mut self) -> Result<String, arboard::Error> { | ||
Err(arboard::Error::ClipboardNotSupported) |
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.
Question: why can't Clipboard
store the string itself? Then use arboard
in addition when it is supported?
I guess that only works when setting directly through the resource. But might be an okay tradeoff
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.
I thought about this but felt like it might be confusing for users if copy and paste is only working internally.
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.
What platforms are unsupported? It might be an okay tradeoff to still allow some amount of clipboard behavior
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.
arboard
seems to support Linux, Mac and Windows. So there's at least Web that is unsupported, and many no_std targets.
I also feel like ultra basic support is still better than no support at all ? Maybe with a warning emitted if the plugin is enabled on an unsupported platform ?
crates/bevy_clipboard/src/desktop.rs
Outdated
&mut self, | ||
text: T, | ||
) -> Result<(), arboard::Error> { | ||
arboard::Clipboard::new().and_then(|mut clipboard| clipboard.set_text(text)) |
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.
I think dropping the Clipboard
may not work on Linux ?
See arboard's documentation about platform-specific behaviors (and also issue #88 and PR #89 for more info)
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.
Yeah seems like drop-after-use is only needed on windows.
This PR is really trivial, but image and android and wasm support will add a lot more complexity. I'm being lazy here, I've got way too many things I working on atm so I was thinking if I just get desktop text clipboard support going someone else will pick this up and fill out the rest of the implementation. I'm not sure it's an important enough feature to deserve its own crate, but I'm not sure if it belongs in any of the exisiting crates either. Maybe
The idea is that you can only use the clipboard with a |
Co-authored-by: Gilles Henaux <[email protected]>
* On unix targets an instance of `arboard::Clipboard` is stored in the `Clipboard` resource. * Removed the desktop and dummy modules. * Made `arboard` dependency conditional.
For crates candidates, I've had a look and did not find much either. Doesn't fit in There's a potential savior in |
Objective
Add a platform-agnostic interface for interacting with the clipboard.
Solution
New crate
bevy_clipboard
that has aClipboardPlugin
. The clipboard is accessed using methods on theClipboard
resource. It only has two methodsget_text
andset_text
which returnResult
s, with errors if the clipboard is unavailable.On windows the
Clipboard
resource is a unit struct and a new arboard clipboard instance is created and dropped for each clipboard access. On unix targets theClipboard
resource holds a clipboard instance it reuses each time.Doesn't support images or android and wasm targets. Almost everything is done by the
arboard
crate.I'm not sure that clipboard support needs its own crate but I wasn't sure where to put it if not.
Testing
Add this system to an app:
If working should output: