compile and run following script with RUST_BACKTRACE=1:
use x11_clipboard::Clipboard;
fn main() {
let clipboard = Clipboard::new().unwrap();
loop {
let val = clipboard
.load_wait(
clipboard.setter.atoms.clipboard,
clipboard.setter.atoms.utf8_string,
clipboard.setter.atoms.property
)
.unwrap();
println!("{}", val.len());
let val = String::from_utf8(val).unwrap();
println!("{}", val);
}
}
copy from chrome address bar
It crashes with following information:
23
https://www.google.com/
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: UnexpectedType(0)', src/main.rs:12:14
stack backtrace:
0: rust_begin_unwind
1: core::panicking::panic_fmt
2: core::result::unwrap_failed
3: core::result::Result<T,E>::unwrap
at /build/rustc-1.65.0-src/library/core/src/result.rs:1107:23
4: x11_test::main
at ./src/main.rs:6:19
5: core::ops::function::FnOnce::call_once
at /build/rustc-1.65.0-src/library/core/src/ops/function.rs:248:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Reproduce
compile and run following script with RUST_BACKTRACE=1:
Reason
Google chrome has a strange behavior: it send xcb_xfixes_selection_notify_event_t twice when coping from address bar. Therefore loop in
process_event
meet XfixesSelectionNotify (https://github.com/quininer/x11-clipboard/blob/6d850c069feb6aab0b3869e7ca1f76298f84546e/src/lib.rs#L182) twice at first and callconvert_selection
twice (https://github.com/quininer/x11-clipboard/blob/6d850c069feb6aab0b3869e7ca1f76298f84546e/src/lib.rs#L183) before recive SelectioniNotify (you can verify it by log), which makes reply.type_ become zero and UnexpectedType error raise.Fix
After get
XfixesSelectionNotify
, only wait forSelectionNotify
andPropertyNotify
.Maybe I can make a PR later.