lamco-clipboard-core
Protocol-agnostic clipboard utilities for Rust.
This crate provides core clipboard functionality that can be used with any clipboard backend (Portal, X11, headless, etc.):
ClipboardSinktrait - Abstract clipboard backend interface with 7 async methodsFormatConverter- MIME ↔ Windows clipboard format conversionLoopDetector- Prevent clipboard sync loops with SHA256 content hashingTransferEngine- Chunked transfer for large clipboard data with progress tracking
Installation
[]
= "0.1"
Feature Flags
[]
# Default - text conversion, loop detection, transfer engine
= "0.1"
# With image format conversion (PNG/JPEG/BMP ↔ DIB)
= { = "0.1", = ["image"] }
| Feature | Description |
|---|---|
image |
Image format conversion - PNG, JPEG, BMP, GIF to/from Windows DIB format. Required for clipboard image sync. |
Quick Start
use ;
use ;
// Convert MIME types to RDP clipboard formats
let formats = mime_to_rdp_formats;
println!;
// Convert RDP format back to MIME
let mime = rdp_format_to_mime;
assert_eq!;
// Prevent clipboard sync loops
let mut detector = new;
if !detector.would_cause_loop
Format Conversion
Convert between UTF-8 text and Windows Unicode format:
use FormatConverter;
let converter = new;
// UTF-8 → UTF-16LE (for CF_UNICODETEXT)
let unicode = converter.text_to_unicode.unwrap;
// UTF-16LE → UTF-8
let text = converter.unicode_to_text.unwrap;
assert_eq!;
Convert HTML to Windows CF_HTML format:
use FormatConverter;
let converter = new;
let html = "<b>Bold text</b>";
let cf_html = converter.html_to_cf_html.unwrap;
let recovered = converter.cf_html_to_html.unwrap;
assert_eq!;
Loop Detection
Prevent infinite clipboard sync loops between local and remote clipboards:
use ;
let mut detector = new;
// Record an operation from RDP
let formats = vec!;
detector.record_formats;
// Check if syncing back would cause a loop
if detector.would_cause_loop
// Content-based deduplication
let data = b"Clipboard content";
detector.record_content;
if detector.would_cause_content_loop
Chunked Transfers
Handle large clipboard data with progress tracking:
use TransferEngine;
let mut engine = new;
// Prepare data for chunked sending
let data = vec!; // 1MB
let chunks = engine.prepare_send.unwrap;
for in chunks.iter.enumerate
// Get hash for integrity verification
let hash = engine.compute_hash;
Receive chunked data:
use TransferEngine;
let mut engine = new;
// Start receiving
engine.start_receive.unwrap;
// Receive chunks
engine.receive_chunk.unwrap;
engine.receive_chunk.unwrap;
// Check progress
if let Some = engine.progress
// Finalize and verify integrity
let data = engine.finalize_receive.unwrap;
ClipboardSink Trait
Implement this trait to create a clipboard backend:
use ;
Image Conversion (requires image feature)
Convert between Windows DIB format and standard image formats:
use ;
// PNG → DIB (for sending to RDP client)
let png_data = read.unwrap;
let dib_data = png_to_dib.unwrap;
// DIB → PNG (for receiving from RDP client)
let png_result = dib_to_png.unwrap;
// Get dimensions without full decode
let = dib_dimensions.unwrap;
println!;
Supported formats: PNG, JPEG, BMP, GIF (read-only).
Supported Formats
| Windows Format | Format ID | MIME Type |
|---|---|---|
| CF_UNICODETEXT | 13 | text/plain;charset=utf-8 |
| CF_TEXT | 1 | text/plain |
| CF_DIB | 8 | image/png |
| CF_HDROP | 15 | text/uri-list |
| HTML Format | 0xD010 | text/html |
| PNG | 0xD011 | image/png |
| JFIF | 0xD012 | image/jpeg |
| GIF | 0xD013 | image/gif |
| Rich Text Format | 0xD014 | text/rtf |
About Lamco
Lamco is a collection of high-quality, production-ready Rust crates for building Remote Desktop Protocol (RDP) applications. Built on top of IronRDP, Lamco provides idiomatic Rust APIs with a focus on safety, performance, and ease of use.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Contributing
Contributions are welcome! Please see the main repository for contribution guidelines.