Cross-platform clipboard watcher
- X11: Event-driven via the XFIXES extension (no polling)
- Mac: NSPasteboard polling, cgo
- Android/Termux:
termux-clipboard-getpolling, watch-only
cb, err := clipboard.Open(ctx)
for text := range cb.Changes() { ... } // changes made by other apps
cb.Set("hello") // take the clipboard overOpen picks a backend for the session. Under Termux an X server
(termux-x11) and the Android system clipboard are both live and are two
different clipboards, so name the one you want:
cb, err := clipboard.OpenBackend(ctx, "termux") // or "x11", "" for autoThe termux backend only watches; Set returns clipboard.ErrReadOnly.
Changes never reports values written with Set on the same Clipboard,
so mirroring a remote clipboard into Set cannot loop back into itself.
There is also clipboard.Watch(ctx) (<-chan string, error) if you only
need change notification.
Sync clipboard between machines over TCP. One side runs serve, the others sync:
- sync clipboard on mac / linux / android
- many peers can connect to one server; it relays between them, so A and C stay in sync through B without connecting to each other
server
clipsync serve :4444
client
clipsync sync 192.168.64.1:4444
Both accept -backend=name. On Android, -backend=termux feeds the Android
system clipboard into the mesh; it never writes back, so received values are
logged as dropped.