mod data_control;
mod mime;
mod pipe;
pub(crate) mod portal;
mod served;
mod transfer;
use std::time::Duration;
use super::Clipboard;
const CHANNEL_CAPACITY: usize = 16;
const READ_TIMEOUT: Duration = Duration::from_secs(2);
const WRITE_TIMEOUT: Duration = Duration::from_secs(10);
const MAX_TRANSFERS: usize = 16;
#[derive(Debug, thiserror::Error)]
pub enum WaylandError {
#[error("cannot connect to the Wayland compositor: {0}")]
Connect(#[from] wayland_client::ConnectError),
#[error("cannot read the Wayland globals: {0}")]
Globals(#[from] wayland_client::globals::GlobalError),
#[error("the compositor has no seat for data control")]
NoSeat,
#[error("Wayland connection failed: {0}")]
Connection(String),
#[error(
"the compositor offers no data-control protocol and the clipboard portal was not granted"
)]
NoClipboardAccess,
#[error("cannot start a clipboard thread: {0}")]
Thread(std::io::Error),
}
pub(super) fn start() -> Result<Clipboard, WaylandError> {
match data_control::start() {
Err(data_control::StartError::Missing) => {}
Err(data_control::StartError::Failed(error)) => {
return portal::take().ok_or(error);
}
Ok(clipboard) => return Ok(clipboard),
}
portal::take().ok_or(WaylandError::NoClipboardAccess)
}