Skip to content

Add standalone clipboard change watchers - #242

Open
aymanbagabas wants to merge 3 commits into
1Password:masterfrom
aymanbagabas:aymanbagabas/clipboard-watchers
Open

aymanbagabas wants to merge 3 commits into
1Password:masterfrom
aymanbagabas:aymanbagabas/clipboard-watchers

Conversation

@aymanbagabas

Copy link
Copy Markdown

Add a standalone ClipboardWatcher with an initial event, coalesced changes, blocking/timed waits, terminal error reporting, and joined stop/drop. The watcher does not read clipboard payloads or acquire the existing clipboard backend locks.

Backends use Windows/macOS native change counters, XFixes on X11, and ext/wlr data-control selection events on Wayland. Missing required extensions return explicit unsupported errors. Document the 50-ms checks, coalescing, first-seat Wayland scope, and ownership-notification limits.

Include a runnable example, native integration checks, protocol fixtures, and Linux validation tools.

Validation: macOS unit/doctests and native watcher test with external pbcopy passed. Linux Xvfb and headless Sway tests passed, including external changes, clear, stop, examples, and disconnection. Protocol fixtures cover ext/wlr identical-MIME changes, empty selections, revocation, and seat removal. Rust 1.71 checks/tests, Linux/Windows cross-checks, formatting, and platform Clippy passed.

Native Windows execution and an actual ext-data-control compositor remain to validate; Sway covered wlr and fixtures covered ext. This is an independent API proposal against master.

Observe native selection events on X11 and Wayland, and poll native
change counters on macOS and Windows. Keep notifications coalesced
and separate from clipboard payload transfers.

Expose blocking and timed waits with explicit stop and joined Drop
lifecycles. Document unsupported protocols and add native examples,
protocol fixtures, and Linux validation tooling.

Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
Run the ignored native watcher test explicitly in the existing test
matrix. This checks native counter changes, external clipboard writes,
clear, stop, and drop on both hosted platforms.

Document the CI coverage alongside the native test command.

Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
@aymanbagabas
aymanbagabas marked this pull request as ready for review October 16, 2026 20:39
Copilot AI balanced review requested due to automatic review settings October 16, 2026 20:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A shutdown race allows a late poll error after the terminal Stopped event.

1 open finding
What changed in this PR

Adds standalone clipboard change notifications without reading payloads or acquiring existing clipboard backend locks.

Changes:

  • Introduces coalesced events, blocking/timed waits, and joined shutdown.
  • Adds Windows, macOS, X11, and Wayland backends.
  • Includes documentation, examples, tests, and native validation tools.
File Description
tools/​test_watchers_linux.sh Validates isolated X11 and Wayland behavior.
tests/​watcher.rs Tests native changes and external writers.
src/​watcher/​x11.rs Watches XFixes selection notifications.
src/​watcher/​windows.rs Checks clipboard sequence numbers.
src/​watcher/​wayland.rs Watches data-control events; adds protocol fixtures.
src/​watcher/​macos.rs Checks pasteboard change counts.
src/​watcher/​linux.rs Selects the Linux watcher backend.
src/​watcher.rs Defines watcher API, lifecycle, and unit tests.
src/​lib.rs Exports watcher types.
README.md Documents usage and platform limitations.
examples/​watch.rs Demonstrates watching and self-testing.
Cargo.toml Enables required protocol dependencies.
Cargo.lock Records direct Wayland dependencies.
.github/​workflows/​test.yml Runs native watcher integration tests.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/watcher.rs Outdated
Only the first stopped transition can record an error. Preserve any
pending error, but discard failures from a poll that finishes after an
explicit stop has already won the transition.

Add a regression that blocks a poll, observes Stopped, then releases
the poll with an error. Subsequent waits must still return Stopped.

Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
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.

2 participants