Skip to main content

ClipboardBackend

Trait ClipboardBackend 

pub trait ClipboardBackend: Send + Sync {
    // Required methods
    fn set_text(&self, target: ClipboardTarget, text: &str) -> bool;
    fn text(&self, target: ClipboardTarget) -> Option<String>;
    fn name(&self) -> &'static str;

    // Provided methods
    fn request_text(&self, target: ClipboardTarget) -> Receiver<Option<String>> { ... }
    fn rich_text(&self) -> Option<RichTextOffer> { ... }
    fn set_image(&self, width: usize, height: usize, rgba: &[u8]) -> bool { ... }
    fn image(&self) -> Option<ClipboardImage> { ... }
    fn set_shared_text(&self, target: ClipboardTarget, text: &str) -> bool { ... }
}
Expand description

A source of clipboard content for this process.

Implementors must be cheap to call and must never block on the compositor’s event loop from a widget’s event handler — a host backend reads a mirror in memory, and the Wayland backend does its protocol work on its own thread.

Required Methods§

fn set_text(&self, target: ClipboardTarget, text: &str) -> bool

Take ownership of target and offer text on it. Returns false if the backend could not.

fn text(&self, target: ClipboardTarget) -> Option<String>

Read target as UTF-8. None when it is empty, unavailable, or holds something that is not text.

fn name(&self) -> &'static str

Short name for diagnostics, e.g. "compositor-mirror".

Provided Methods§

fn request_text(&self, target: ClipboardTarget) -> Receiver<Option<String>>

Request text for an explicit paste. A native transfer may finish after this call returns; the backend must wake its owner when it answers. No answer may substitute text from an older selection or focus owner.

fn rich_text(&self) -> Option<RichTextOffer>

Read HTML and its plain fallback from one Ctrl+V clipboard offer. Optional: unsupported backends return None without reading plain text. A successful read consumes event-scoped offers; use the captured plain fallback if decoding refuses the HTML. Never reread to recover a stale selection, a permission refusal, or an active composition.

fn set_image(&self, width: usize, height: usize, rgba: &[u8]) -> bool

Offer an RGBA8 image on the clipboard. Optional: the default refuses, which is appropriate for backends that only carry text.

fn image(&self) -> Option<ClipboardImage>

The image on the Ctrl+V clipboard, when it holds one: a screenshot, an image copied in a viewer or a browser. Optional: the default reads none, which is right for backends that only carry text.

fn set_shared_text(&self, target: ClipboardTarget, text: &str) -> bool

Offer text only where other processes can read it. Returns false rather than keeping it in a buffer private to this process, so a secret is never reported as copied when it was not. The default is set_text, right for a backend that only reaches a shared clipboard.

Implementors§