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

Copy to clipboard not working on Ubuntu #16

Open
alexanderkjall opened this issue Feb 10, 2023 · 3 comments
Open

Copy to clipboard not working on Ubuntu #16

alexanderkjall opened this issue Feb 10, 2023 · 3 comments

Comments

@alexanderkjall
Copy link

Hi

On my ubuntu machine the cli_clipboard::set_contents function doesn't copy anything to the copy buffer.

I'm running Ubuntu 22.10 with xfce as my window manager.

This small program reproduces the problem:

use std::{thread, time};
use cli_clipboard;

fn main() {
   let the_string = "Hello, world!";
   cli_clipboard::set_contents(the_string.to_owned()).unwrap();

   let ten_millis = time::Duration::from_millis(100000);
   thread::sleep(ten_millis);
}

A similar program using the clipboard crate doesn't show the same problem:

use std::{thread, time};
use clipboard::ClipboardProvider;
use clipboard::ClipboardContext;

fn main() {
    let mut ctx: ClipboardContext = ClipboardProvider::new().unwrap();

    let the_string = "Hello, world!";

    ctx.set_contents(the_string.to_owned()).unwrap();

    let ten_millis = time::Duration::from_millis(100000);

    thread::sleep(ten_millis);
}
@alexanderkjall
Copy link
Author

alexanderkjall commented Feb 17, 2023

I did a bisect, and the error was introduced by this commit: 15e39bf

And I guess that it's the upgrade of the x11-clipboard crate that have caused this:

- x11-clipboard = "0.3"
+ x11-clipboard = "0.5.1"

I guess that I have to bisect the x11-clipboard crate now T_T

@alexanderkjall
Copy link
Author

Did a bisect and opened a bug in x11-clipboard: quininer/x11-clipboard#32

@allie-wake-up
Copy link
Owner

allie-wake-up commented Feb 25, 2023

For both this and #17 the issue seems to lie with x11-clipboard. Using it directly does not resolve the problem. I looked into it quite a bit tonight and it seems like the options are downgrade x11-clipboard to 0.6.1, wait for or make a fix to x11-clipboard, find a different x11 clipboard dependency (which it doesn't seem like there is), or handle the x11 clipboard directly with x11rb (possible but looks like a greater undertaking than I currently have time for).

My immediate suggestion would be to use cli-clipboard v0.3.0 which from what I can tell works correctly (it uses x11-clipboard 0.6.1) or switching to https://github.com/1Password/arboard. It seems to work on X11 correctly and is the only cross-platform clipboard library I could find that did not rely on x11-clipboard. I did not test it on windows, macOS, or wayland but it seems to be very actively maintained so is likely your current best bet.

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

No branches or pull requests

2 participants