Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/clipboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,16 @@ pub use x::XBackend;

#[cfg(target_os = "linux")]
pub fn create_backend() -> Result<Box<dyn ClipBackend>> {
// Try Wayland first, but only if the required protocol is available
if std::env::var("WAYLAND_DISPLAY").is_ok() {
return Ok(Box::new(WaylandBackend {}));
} else if std::env::var("DISPLAY").is_ok() {
if wayland::test_protocol_available() {
return Ok(Box::new(WaylandBackend {}));
}
log::debug!("Wayland wlr_data_control protocol not available, trying X11 fallback");
}

// Fall back to X11
if std::env::var("DISPLAY").is_ok() {
return Ok(Box::new(XBackend {}));
}

Expand Down
10 changes: 8 additions & 2 deletions src/clipboard/wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ use wayrs_protocols::wlr_data_control_unstable_v1::{

pub struct WaylandBackend {}

pub fn test_protocol_available() -> bool {
create_wayland_client::<()>().is_ok()
}

struct WaylandClient<T> {
conn: Connection<T>,
seat: WlSeat,
Expand Down Expand Up @@ -62,8 +66,10 @@ fn create_wayland_client<T>() -> Result<WaylandClient<T>> {
conn.blocking_roundtrip()
.context("Failed to call 'blocking_roundtrip'")?;

let seat: WlSeat = conn.bind_singleton(2..=4).context("")?;
let data_ctl_mgr: ZwlrDataControlManagerV1 = conn.bind_singleton(..=2).context("")?;
let seat: WlSeat = conn
.bind_singleton(2..=4)
.context("Failed to bind Wayland seat")?;
let data_ctl_mgr: ZwlrDataControlManagerV1 = conn.bind_singleton(..=2).context("Failed to bind data control manager (wlr_data_control_unstable_v1 protocol may not be available)")?;

Ok(WaylandClient::<T> {
conn,
Expand Down
Loading