window_clipboard

Cross-platform clipboard access for Rust GUI apps built on raw-window-handle

Library
Cargo
v0.5.1
25stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
23/100Needs Attention
Development Activity0
Maintenance0
Community20
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
73/100Good
Architecture78
Code Quality68
Innovation62
Learning Curve85

window_clipboard is a small Rust library that gives GUI applications clipboard read and write access derived from a raw-window-handle. Rather than tying you to a specific windowing toolkit, it accepts any window that implements HasDisplayHandle and dispatches to the correct native clipboard backend for the current platform.

It powers clipboard support in the iced GUI toolkit and other winit-based applications, abstracting the very different clipboard APIs of Windows, macOS, X11, and Wayland behind a single Clipboard type with simple read/write methods, plus optional primary-selection support on X11 and Wayland.

What You Get

  • A single Clipboard type that works across Windows, macOS, Linux X11, and Wayland
  • Integration with any window exposing a raw-window-handle HasDisplayHandle
  • Optional primary-selection (middle-click paste) support on X11 and Wayland
  • Feature flags to opt in or out of the X11 and Wayland backends
  • A small, dependency-light API surface that is easy to embed in a GUI toolkit

Common Use Cases

  • Adding copy/paste support to a winit- or iced-based desktop application
  • Reading text a user has copied so it can be pasted into a text input widget
  • Writing generated or selected text back to the system clipboard
  • Supporting X11/Wayland primary selection for middle-click paste on Linux

Under The Hood

Architecture - The crate’s src/lib.rs defines a public Clipboard struct wrapping a boxed dyn ClipboardProvider trait object, and uses #[cfg]/#[path] attributes to compile exactly one platform module (platform/linux.rs, windows.rs, macos.rs, ios.rs, android.rs, or a dummy.rs fallback) per target. Each platform module implements connect and returns a provider that satisfies the read/write/read_primary/write_primary contract, so the same public surface maps onto very different OS clipboard APIs.

Tech Stack - Written in pure Rust (2021 edition) with raw-window-handle 0.6 for window/display handles and thiserror for error types. Platform backends come from workspace sibling crates and dependencies: clipboard-win on Windows, clipboard_macos on macOS, and the local clipboard_x11 / clipboard_wayland members on Linux, gated behind x11 and wayland Cargo features.

Code Quality - The core is compact and readable, leaning on Rust’s cfg machinery to keep platform code isolated. Clipboard connection is an unsafe fn because the display handle must stay valid for the clipboard’s lifetime, and that invariant is documented at the call site. The repository is self-described as experimental and carries example programs rather than an extensive automated test suite.

API Design - The public API is deliberately tiny: connect once, then read and write strings, with Option-returning primary-selection variants that gracefully signal unsupported platforms. This minimal, toolkit-agnostic surface makes it easy to embed, at the cost of only supporting plain-text transfer.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search