Skip to content

refactor(clipboard): replace clipboard-rs with native macOS and Windows backends - #465

Merged
lexoliu merged 5 commits into
mainfrom
refactor/remove-clipboard-rs
Nov 29, 2026
Merged

lexoliu merged 5 commits into
mainfrom
refactor/remove-clipboard-rs

Conversation

@lexoliu

@lexoliu lexoliu commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Replaces clipboard-rs in waterkit-clipboard with native macOS and Windows implementations and removes clipboard-rs from the workspace dependency tree.

  • macOS (platform/clipboard/src/sys/apple/macos.rs): Direct NSPasteboard implementation through objc2 / objc2-app-kit / objc2-foundation / objc2-uniform-type-identifiers / objc2-core-graphics. Maps custom MIME types to UTIs via UTType::typeWithMIMEType, resolves file-reference URLs (file:///.file/id=...) via NSURL::filePathURL, reads PNG/TIFF losslessly (falling back to NSImage/CGImage with unpremultiplication to straight RGBA), and watches changes by polling NSPasteboard.changeCount. Shares file_url with iOS (src/sys/apple/ios.rs).
  • Windows (platform/clipboard/src/sys/windows/): Direct Win32 clipboard implementation through the workspace windows crate: CF_UNICODETEXT, CF_HTML header encode/decode with optional plain-text fallback, CF_HDROP (DROPFILES), PNG + CF_DIBV5 / CF_DIB <-> straight-alpha RGBA8 conversion, registered MIME formats (RegisterClipboardFormatW), a hidden message-only window (HWND_MESSAGE) watcher using AddClipboardFormatListener / WM_CLIPBOARDUPDATE, and delayed rendering (WM_RENDERFORMAT / WM_RENDERALLFORMATS / WM_DESTROYCLIPBOARD) for set_file_promise.
  • Dependencies & docs: Drops clipboard-rs from Cargo.toml, platform/clipboard/Cargo.toml, and Cargo.lock, scopes tracing to the targets that use it, deletes sys/desktop.rs, and updates platform notes in lib.rs and README.md.

Fixes #462

Verification

  • macOS: cargo clippy -p waterkit-clipboard --all-targets --all-features -- -D warnings, cargo nextest run -p waterkit-clipboard --all-features (12 passed, including desktop_clipboard_round_trip covering text/pbpaste, HTML, files, RGBA image, custom/large binary, set_file_promise, watcher, and clear), and cargo test --doc -p waterkit-clipboard --all-features.
  • Windows: cargo clippy -p waterkit-clipboard --all-targets --all-features -- -D warnings, cargo test -p waterkit-clipboard --all-features (DIB/HTML unit tests, desktop_clipboard_round_trip including lazy delayed-rendered set_file_promise and WM_CLIPBOARDUPDATE watcher, plus direct CF_DIBV5 and CF_DIB clipboard decode), and doctests.
  • Linux: cargo clippy -p waterkit-clipboard --all-targets --all-features -- -D warnings, 24 unit tests, doctests, and Xvfb integration tests (clipboard_round_trip, primary_selection_round_trip, display_gone).

@lexoliu
lexoliu merged commit 2410270 into main Nov 29, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

clipboard: replace clipboard-rs with native macOS and Windows backends

1 participant