$ show YaLTeR/wl-clipboard-rs
wl-clipboard-rs is a Rust library providing safe access to the Wayland clipboard through the ext-data-control and wlr-data-control protocols. It consists of a library crate (wl-clipboard-rs) that handles clipboard operations and a tools crate (wl-clipboard-rs-tools) providing terminal utilities: wl-copy (copy to clipboard), wl-paste (paste from clipboard), and wl-clip (xclip-like utility). The library abstracts over different Wayland clipboard protocol versions, manages connections to the compositor, handles MIME type negotiation, and serves clipboard requests. The architecture separates concerns into copy, paste, utils, common connection logic, data control abstraction, and seat data management modules.
The LLM identified 3 files worth highlighting for reuse:
Provides a clean abstraction over ext-data-control and wlr-data-control protocols using enum variants and macros to eliminate code duplication. Implements Manager, Device, Source, and Offer types that work with both protocol implementations through a unified interface. Demonstrates advanced Rust skills in creating zero-cost abstractions over similar but incompatible C APIs.
Contains the is_text() function that determines if a MIME type represents plain text content. Goes beyond simple 'text/' prefix checking to include common script and markup types (JSON, XML, YAML, CSV, INI) and special types like TEXT, STRING, UTF8_STRING. Based on reference implementation from wl-clipboard, showing careful consideration of real-world MIME type usage patterns.
Handles the shared Wayland connection logic including socket connection, global registry retrieval, seat binding, and initial setup. Encapsulates the boilerplate required to establish a Wayland client connection and prepare for protocol interactions. Cleanly separates connection concerns from protocol-specific clipboard logic, making it reusable across different Wayland client applications.