fix(clipboard): copied templates vanish on Wayland - #23
Open
LashaKamadadze wants to merge 1 commit into
Open
Conversation
copypasta always uses the X11 clipboard backend on Linux, even though it also compiles in Wayland support - selecting that path requires the caller to hand it a raw Wayland display handle, which copypasta never does on its own. On Wayland compositors this means gitnr's clipboard copy silently writes to an ephemeral, headless X11 selection that the native Wayland clipboard never sees, so pasted content is just gone. Switch to arboard, which detects WAYLAND_DISPLAY at runtime and uses the wlr-data-control protocol (the same one wl-copy/cliphist use). That protocol works headless with no window surface, which fits a TUI app, and arboard falls back to X11 automatically when Wayland isn't available. The wayland-data-control feature has to be enabled explicitly - it's not part of arboard's defaults.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Wayland compositors (I tested on Hyprland), the clipboard actions in
search(Shift+C, Shift+X) print "copied to clipboard," but nothingends up there.
wl-pastecomes back empty and no Wayland app canpaste it.
Root cause
copypasta always picks its X11 backend on Linux. From
src/lib.rs:No runtime check for
WAYLAND_DISPLAY, no fallback. If thex11feature is on (it is by default, alongside
wayland),ClipboardContextis the X11 type, full stop. Reaching copypasta's Wayland backend means
calling
wayland_clipboard::create_clipboards_from_external(display_ptr)yourself with a raw Wayland display handle. gitnr never does that.
This isn't a gap copypasta is unaware of. The maintainer has said as
much directly:
to do this automatically. You require a display handle from your
window to access the clipboard on Wayland."
maintainer telling users "this crate requires a running window...
If you don't show any window and want a clipboard manager, use
wl-clipboard-rs."
gitnr is exactly that second case, a TUI with no window at all. So on
Wayland it opens XWayland and sets clipboard ownership on a headless,
invisible X11 window. The call succeeds, hence "Success," but the X11
selection only lives as long as the owning process answers paste
requests, and compositor XWayland-to-Wayland clipboard bridging is
generally keyed to visible or focused Xwayland surfaces. A headless
clipboard-only window often gets skipped by that bridge. The copy is
gone the moment gitnr exits, sometimes sooner.
Fix
Switched to arboard. On Linux it checks
WAYLAND_DISPLAYat runtimeand, when set, uses the wlr-data-control protocol, the same one
wl-copy and cliphist use (and, notably, the same wl-clipboard-rs the
copypasta maintainer pointed people to). That protocol works with no
window, which is what a TUI needs. It falls back to X11 automatically
when Wayland isn't there.
I also had to turn on the
wayland-data-controlfeature by hand.arboard's default feature is
image-data, not Wayland support. Iturned
image-dataoff too, since gitnr only ever copies text. Thatdrops the
imagecrate and its PNG decoding stack from the dependencytree.
Testing
cargo test: 21 passedcargo clippy --all-targets: no new warningscargo build --release: cleansearch, copiedwith Shift+C, checked
wl-pasteand pasted into another app.Previously produced nothing.