Skip to main content

Crate lamco_data_control

Crate lamco_data_control 

Source
Expand description

A Wayland clipboard client built on the data-control protocols.

Data-control lets a client that has no window read and set the clipboard. This crate speaks both ext-data-control-v1 and wlr-data-control-unstable-v1 and picks whichever the compositor offers.

It has no async runtime and no dependency on any RDP, D-Bus or PipeWire stack. One thread owns the Wayland connection; DataControl is the handle you call from anywhere.

§Reading

use lamco_data_control::DataControl;

let clipboard = DataControl::connect()?;
if let Some(bytes) = clipboard.read("text/plain;charset=utf-8")? {
    println!("{}", String::from_utf8_lossy(&bytes));
}

§Owning the clipboard, with delayed rendering

use lamco_data_control::{Content, DataControl};

let clipboard = DataControl::connect()?;
clipboard.on_transfer(|request| {
    // Produce the data only now that something is pasting it.
    let _ = request.complete("rendered on demand");
});
clipboard.set_selection(Content::new().advertise("text/plain;charset=utf-8"))?;

§Platform

Linux and other systems with a Wayland compositor that offers a data-control protocol. GNOME’s Mutter does not.

Structs§

Content
What to offer as the clipboard selection.
DataControl
A connection to the Wayland compositor’s clipboard.
Options
Options for DataControl::connect_with.
TransferRequest
A paste waiting for data that was advertised without any.

Enums§

Error
Errors returned by DataControl.
Preference
Which protocol to prefer when the compositor offers both.
Protocol
The data-control protocol in use.

Functions§

find_mime_match
Find a MIME type match in available, tolerating charset differences.

Type Aliases§

Result
Result alias for this crate.