Skip to main content

lamco_data_control/
lib.rs

1//! A Wayland clipboard client built on the data-control protocols.
2//!
3//! Data-control lets a client that has no window read and set the clipboard.
4//! This crate speaks both `ext-data-control-v1` and
5//! `wlr-data-control-unstable-v1` and picks whichever the compositor offers.
6//!
7//! It has no async runtime and no dependency on any RDP, `D-Bus` or `PipeWire`
8//! stack. One thread owns the Wayland connection; [`DataControl`] is the
9//! handle you call from anywhere.
10//!
11//! # Reading
12//!
13//! ```no_run
14//! use lamco_data_control::DataControl;
15//!
16//! # fn main() -> lamco_data_control::Result<()> {
17//! let clipboard = DataControl::connect()?;
18//! if let Some(bytes) = clipboard.read("text/plain;charset=utf-8")? {
19//!     println!("{}", String::from_utf8_lossy(&bytes));
20//! }
21//! # Ok(())
22//! # }
23//! ```
24//!
25//! # Owning the clipboard, with delayed rendering
26//!
27//! ```no_run
28//! use lamco_data_control::{Content, DataControl};
29//!
30//! # fn main() -> lamco_data_control::Result<()> {
31//! let clipboard = DataControl::connect()?;
32//! clipboard.on_transfer(|request| {
33//!     // Produce the data only now that something is pasting it.
34//!     let _ = request.complete("rendered on demand");
35//! });
36//! clipboard.set_selection(Content::new().advertise("text/plain;charset=utf-8"))?;
37//! # Ok(())
38//! # }
39//! ```
40//!
41//! # Platform
42//!
43//! Linux and other systems with a Wayland compositor that offers a
44//! data-control protocol. GNOME's Mutter does not.
45
46#![cfg_attr(docsrs, feature(doc_cfg))]
47#![deny(missing_docs)]
48#![cfg_attr(test, allow(clippy::unwrap_used, clippy::expect_used))]
49
50mod client;
51mod dispatch;
52mod error;
53mod mime;
54mod options;
55mod state;
56mod worker;
57
58pub use client::{Content, DataControl, TransferRequest};
59pub use error::{Error, Result};
60pub use mime::find_mime_match;
61pub use options::{Options, Preference, Protocol};