Skip to content

feat: clipboard sync on X11 sessions and through XWayland - #337

Merged
zackb merged 2 commits into
zackb:mainfrom
fernando2393:pr/x11-clipboard-backend
Nov 23, 2026
Merged

zackb merged 2 commits into
zackb:mainfrom
fernando2393:pr/x11-clipboard-backend

Conversation

@fernando2393

Copy link
Copy Markdown
Contributor

Refs #65 (Wayland requirement).

What

An X11 ClipboardManager backend, so clipboard sync works without a Wayland data-control protocol:

  • X11 sessions (XFCE, GNOME on Xorg, ...): the daemon used to report "off, no Wayland session".
  • GNOME on Wayland: Mutter offers neither zwlr_data_control_manager_v1 nor ext_data_control_manager_v1, so sync was unavailable. XWayland bridges the Wayland clipboard to X11, so the same backend sees (and sets) GNOME's selection.

Wayland data-control stays the first choice; X11 is used when there is no compositor, or when the compositor has no data-control manager.

How

  • XFixes selection-owner notifications, no polling; a 1×1 unmapped window owns/reads the selection.
  • Reads: TARGETS first, then pick_clipboard_mime; INCR for large payloads; STRING converted from Latin-1.
  • Writes: own CLIPBOARD, serve TARGETS, TIMESTAMP, UTF-8/text types, STRING (Latin-1), image/png; INCR when a payload exceeds one request.
  • Our own copy() is not reported back as a desktop change (no echo to the phone).
  • X errors from vanished requestors are logged, not fatal; a lost X connection tears the backend down and the daemon retries.
  • Optional at build time (TETHER_X11, on by default when x11 and xfixes are found); package dependencies updated.

Testing

  • 9 new tests: pure helpers (chunk size, INCR chunking, display discovery) and live tests against a throwaway X server (TETHER_TEST_X11_DISPLAY=:N with Xvfb/Xephyr; skipped when unset): UTF-8/Latin-1/PNG paste, a 3 MB INCR transfer, desktop copies reported once.
  • Whole suite passes on this branch alone: 647 tests (638 existing + 9 new).
  • Used by hand with a real iPhone on Ubuntu 24.04 (GNOME 46, Xorg) and Ubuntu 26.04 (GNOME 50, Wayland, through XWayland): copying in a native Wayland app reaches the phone, and text sent from the phone pastes into native apps.
  • Not tested: KDE/other compositors (they keep using data-control), non-GNOME X11 desktops.

Notes for review

  • The fallback is in WaylandContext::setup(); setup_x11() is also reached from init() when there is no compositor.
  • I left docs/PROTOCOL.md wording alone; README requirements and build deps are updated.

🤖 Generated with Claude Code

Clipboard sync needed a Wayland data-control protocol, so it was off on X11
desktops (XFCE, GNOME on Xorg, issue zackb#65) and on GNOME Wayland, whose Mutter
offers neither wlr nor ext data-control.

Add an X11 ClipboardManager backend: XFixes reports CLIPBOARD ownership changes
without polling, reads use selection conversions (TARGETS first, INCR for large
payloads), and writes take ownership and serve TARGETS/TIMESTAMP/text/PNG
requests, with INCR for payloads that do not fit one request.

WaylandContext uses it when there is no Wayland compositor, and as a fallback
when the compositor has no data-control manager: XWayland bridges the Wayland
clipboard to X11, so GNOME's own selection is still seen. Wayland data-control
stays the first choice. The backend is optional at build time (TETHER_X11) and
needs libx11 and libxfixes.

Tested with helper unit tests plus live tests against a throwaway X server
(TETHER_TEST_X11_DISPLAY, skipped when unset): text and PNG paste, STRING
Latin-1, a 3 MB INCR transfer, and desktop copies reported once with no echo
of our own selection.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@zackb

zackb commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Thanks, this is nicely done. I think this is the best way tether could support X11. I pushed one small commit on top so X11 is not a hard dependency for tether, which I'm not willing to do. BUT, I checked that gtk3 already pulls them in and it builds and runs correctly on all the different permutations of system configurations (Wayland only, X11+Wayland, etc). I made the link \PRIVATE to core. x11>=1.7 is required so older libX11 disables the X11 backend instead of breaking the build. Also had claude fix the translations. Thanks for the contribution!

@zackb
zackb merged commit b404679 into zackb:main Nov 23, 2026
@zackb zackb mentioned this pull request Nov 23, 2026
@fernando2393

Copy link
Copy Markdown
Contributor Author

Thank you for your time and merging this request. Happy to contribute!

@fernando2393
fernando2393 deleted the pr/x11-clipboard-backend branch November 23, 2026 21:52
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