copypasta is a rust-clipboard fork, adding support for the Wayland clipboard

copypasta

copypasta is a rust-clipboard fork, adding support for the Wayland clipboard.

rust-clipboard is a cross-platform library for getting and setting the contents of the OS-level clipboard.

Example

extern crate copypasta;

use copypasta::{ClipboardContext, ClipboardProvider};

fn main() {
    let mut ctx = ClipboardContext::new().unwrap();
    println!("{:?}", ctx.get_contents());
    ctx.set_contents("some string".to_owned()).unwrap();
}

API

The ClipboardProvider trait has the following functions:

fn get_contents(&mut self) -> Result<String, Box<Error>>;
fn set_contents(&mut self, String) -> Result<(), Box<Error>>;

ClipboardContext is a type alias for one of {WindowsClipboardContext, OSXClipboardContext, X11ClipboardContext, NopClipboardContext}, all of which implement ClipboardProvider. Which concrete type is chosen for ClipboardContext depends on the OS (via conditional compilation).

License

rust-clipboard is dual-licensed under MIT and Apache2.

Issues

Collection of the latest Issues

liquidev

liquidev

enhancement
3

Some data that goes through the clipboard is not necessarily text, one example is images. Currently copypasta uses Strings to transfer all clipboard data, which all guarantee that the data inside is valid UTF-8, and panic if it's not. This prevents users from transferring non-text data through the clipboard.

delight-aug

delight-aug

enhancement
6

Hi! I see two possible uses of this library on Android:

  • By some JVM apps, through their own rust library (e.g. game engines)
  • By cross-platform term apps, through Termux (e.g. jmacdonald/amp)

The latter probably can be done by simply running process . About the first case — there is an easy way in SDK to use the clipboard, however, it needs to be used through JNI. This crate is used by Servo among others, so I think it'll be fine to use.

Things to think about:

  • Can the Termux case be covered by the JNI thing?
  • How to handle different Android SDKs?
  • How to test?
jayache80

jayache80

5

I use Alacritty on Wayland, specifically with the Sway window manager. Alacritty uses this underlying library to handle text copying and pasting. When pasting text from the clipboard with Alacritty (using default Ctrl+Shift+V key binding) the pasted text will actually be older, previously copied text. Pasting again will eventually paste the most recently copied text, however it may take several repetitions before it "bubbles" up.

This only seems to occur on a very long running Alacritty instance. For example, I have several Alacritty instances open, and the recently started processes do not exhibit this issue, but a very old instance does exhibit this behavior and continues to do so.

Steps to reproduce:

  1. Start Alacritty and use the same instance over the course of many days.
  2. Copy text to clipboard using any means (other applications that have access to Wayland clipboard or Alacritty itself)
  3. Paste text using Alacritty. The pasted text will incorrectly be previously copied text. Subsequent pastes will eventually paste the most recently copied text.

Example:

  • Copy "foo" from text using some application.
  • In Alacritty at a shell, execute a Paste hot key (Ctrl+Shift+V by default)
  • "foo" should be output to the screen. If it isn't, it may be "queued up". Keep retrying the Paste operation until "foo" is outputted.
  • Copy "bar" from text using some application.
  • Repeat Paste hot key an arbitrary amount of times. Alacritty will output "foo" each time until eventually "bar" is output

Note: In the above, "some application" can be anything that is able to copy text to the Wayland clipboard. The above example occurs for both copying using Alacritty's highlighting and Ctrl+Shift+C, or copying text in Firefox.

Here is a Youtube video I created which demonstrates the issue: Youtube video

sagacity

sagacity

bug
6

I'm seeing crashes on MacOS Catalina (10.15.3) with Rust 1.43.1. This happens in the original clipboard crate as well, but since that seems unmaintained I'm reporting it here.

You can reproduce the crash by running cargo test in my fork.

You may need to run it a few times, but you will get different errors such as:

Or:

I'm unfortunately no MacOS developer so I have no idea what causes this, but it only seems to occur when I'm accessing the clipboard from both my test code and my regular (under test) code, like in some_other_fn in the code below. Moving the ClipboardContext to a shared static using something like lazy_static! does not help.

The test is fairly simple:

Versions

Find the latest versions by id

Information - Updated May 03, 2022

Stars: 150
Forks: 21
Issues: 5

A cross-platform GUI library for Rust focused on simplicity and type-safety

Cross-platform support (Windows, macOS, Linux, and text inputs, Debug overlay with performance metrics

A cross-platform GUI library for Rust focused on simplicity and type-safety
Misc

248

A CLI tool to easily get a new project up and running by using pre-made...

A rust cross platform rust boilerplate template to get up and running quickly

A CLI tool to easily get a new project up and running by using pre-made...

HAL : Hyper Adaptive Learning

Rust based Cross-GPU Machine Learning

HAL : Hyper Adaptive Learning

A crossplatform Rust bindings for the soloud audio engine library

Supported formats: wav, mp3, ogg, flac

A crossplatform Rust bindings for the soloud audio engine library

Safe wrapper around SPIR-V Cross

Safe wrapper around SPIRV-Cross for use with Rust

Safe wrapper around SPIR-V Cross

🐏 rpmalloc-rs

Cross-platform Rust global memory allocator using rpmalloc README for a detailed description of how the allocator works, peforms, and compares with other allocators

🐏 rpmalloc-rs

Rust crate providing cross-platform information about the notebook batteries

battery provides a cross-platform unified API to a notebook batteries state

Rust crate providing cross-platform information about the notebook batteries

rust-clipboard is a cross-platform library for getting and setting the contents of the OS-level clipboard

It has been tested on Windows, Mac OSX, GNU/Linux, and FreeBSD

rust-clipboard is a cross-platform library for getting and setting the contents of the OS-level clipboard

A cross-platform GUI library for Rust focused on simplicity and type-safety

Cross-platform support (Windows, macOS, Linux, and text inputs, Debug overlay with performance metrics

A cross-platform GUI library for Rust focused on simplicity and type-safety

A cross platform Rust library for efficiently walking a directory recursively

Comes with support for following symbolic links, controlling the number of

A cross platform Rust library for efficiently walking a directory recursively

debug-here: a cross platform rust debugger hook

Debuggers are a great way to examine the state of a program

debug-here: a cross platform rust debugger hook
Facebook Instagram Twitter GitHub Dribbble
Privacy