Smithay / smithay-clipboard

Provides access to the wayland clipboard for client applications
MIT License
28 stars 11 forks source link

Basic store/loop use case doesn't work #11

Closed ghost closed 4 years ago

ghost commented 4 years ago

I'm running this simple code

use sctk::reexports::client::{Display};

fn main() {
    let (display, _) = Display::connect_to_env().expect("Failed to connect to the wayland server.");
    let mut clipboard = smithay_clipboard::WaylandClipboard::new(&display);

    clipboard.store(None, "store");
    println!("loaded {}", clipboard.load(None));

    clipboard.store_primary(None, "store_primary".to_string());
    println!("loaded {}", clipboard.load_primary(None));
}

and getting this

> env WAYLAND_DISPLAY=/run/user/1000/wayland-0 cargo run --example clipboard
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `target/debug/examples/clipboard`
loaded 
loaded 

while I'm expecting something like this

loaded store
loaded store_primary

Any clue?

Btw, without the WAYLAND_DISPLAY=/run/user/1000/wayland-0 env variable set I'm getting

> cargo run --example clipboard
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s
     Running `target/debug/examples/clipboard`
thread 'main' panicked at 'Failed to connect to the wayland server.: NoCompositorListening', src/libcore/result.rs:1165:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
kchibisov commented 4 years ago

You need surface around to handle KbdEnter etc and actually draw in it. Without it it won't work. If your use case is CLI usage, this crate isn't for you and you should look at https://github.com/YaLTeR/wl-clipboard-rs .

Btw, without the WAYLAND_DISPLAY=/run/user/1000/wayland-0 env variable set I'm getting

Your wayland compositor should set WAYLAND_DIPLAY, so check env | grep WAYLAND_DISPLAY.

Update: So, I'd recommend you to start from https://github.com/Smithay/client-toolkit/tree/master/examples . once you drawn your surface and start handling events, etc. you can use clipboard from here.(smithay-clipboard should start working after KbdEnter event IIRC).

ghost commented 4 years ago

@kchibisov, I think you're right and https://github.com/YaLTeR/wl-clipboard-rs should be sufficient for me.

Thanks for satisfying answer, I'm closing it.