Skip to content

feat(viewer): paste on Wayland compositors without data-control - #446

Merged
ElbertePlinio merged 8 commits into
mainfrom
feat/426-paste-wl-data-device
Oct 29, 2026
Merged

ElbertePlinio merged 8 commits into
mainfrom
feat/426-paste-wl-data-device

Conversation

@ElbertePlinio

@ElbertePlinio ElbertePlinio commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Closes #426

On a Wayland compositor without data-control, such as GNOME's Mutter, Paste in the native viewer now reads the clipboard through the viewer window's own wl_data_device. Before this change it showed "Paste unavailable" there. Where data-control exists (Hyprland, Sway, KDE, river), the viewer creates no data device and the existing reader runs unchanged.

The device runs on winit's connection on its own event queue. Until a click it only notes the best text type of each selection offer, and it never receives an offer before the click. After the click, under a live lease and only while the window has keyboard focus, it asks the source to write to a pipe. The pipe is read with the existing rules: UTF-8 text only, 16 KiB and one second at most, zeroed buffers, and nothing logged.

The device has its own wl_keyboard on the same queue, so keyboard enter and leave reach it in order with the selection. A leave drops the selection it ended, a fresh selection that comes with the next enter is kept, and a click that completes without focus shows "Paste unavailable". The keyboard's key events are ignored. When the seat loses its keyboard, the device releases it and asks for a new one when the seat has a keyboard again.

A paste stop now takes priority over the read worker. A stop waits for at most the one step under way: one pipe read, or one X11 GetProperty round trip. No step starts after the stop returns, on all three paths. When the device cannot be set up, the viewer writes one stderr line that names the step and holds no clipboard content.

wayland-client with the dlopen feature is the only new dependency, and the release binary still links no libwayland. CI's rust job now installs weston and wl-clipboard and sets PICKFORGE_REQUIRE_WESTON, so the live tests cannot skip there.

Traceability

Requirement Verification Scenario and edge cases Result Evidence
Read through the window's wl_data_device without data-control paste_weston::paste_reads_the_selection_through_the_window_data_device on weston nested in a private Xvfb, with no data-control global "Olá ß €\t<marker>\n" typed in the session; empty clipboard, image only and 4097 characters type nothing; no key held; the marker never appears in viewer output Pass; types nothing on the old app.rs ~/.pickforge/investigations/426/failing-before-paste_weston.txt, fix4/viewer-tests.txt, fix4/paste-weston-5x.txt
Data-control stays first Private headless sway with both data-control globals No data device created, existing reader used Pass ~/.pickforge/investigations/426/sway/
No read after the paste stops clipboard::a_read_waiting_when_the_paste_stops_reads_no_byte and a_stop_waits_for_the_step_under_way_and_refuses_the_next Read already waiting, stop set, then the source writes: bytes stay unread. A stop during a step waits for it, and the next step is refused even if the worker takes the lock first Pass; the first returned the text on the old code ~/.pickforge/investigations/426/fix1/fix1-stop-read-before.txt, fix4/viewer-tests.txt
No stale offer after focus loss paste_weston::paste_refuses_a_click_that_completes_after_focus_moved_away Press on Paste, another client takes focus, release: nothing typed; focus returns and a new paste works; the wl-copy focus bounce before each paste keeps the fresh selection Pass; the old code typed the marker ~/.pickforge/investigations/426/fix1/fix2-focus-before.txt, fix4/paste-weston-5x.txt
A failed setup is diagnosable paste_weston::a_data_device_that_cannot_be_set_up_names_the_step on headless weston without a seat One stderr line names the failed bind, without content Pass; no line on the old code ~/.pickforge/investigations/426/fix1/fix4-setup-line-before.txt, fix4/viewer-tests.txt
Offer and refusal choices data_device unit tests and read_pipe_reads_only_while_the_paste_is_wanted MIME order, offer without text, data-control globals, stop before read, too long, not UTF-8 Pass ~/.pickforge/investigations/426/fix4/viewer-tests.txt
No new C runtime library ldd on the release binary libgcc_s, libm and libc only Pass ~/.pickforge/investigations/426/fix1/ldd.txt
CI runs the live tests rust job installs weston and wl-clipboard, PICKFORGE_REQUIRE_WESTON=1 on ubuntu-latest Weston 13 on Ubuntu 24.04 Pass: the three weston tests ran and passed this PR's rust (ubuntu-latest) check
QA on a compositor without data-control qa.sh on headless weston with the desktop shell Empty clipboard and image only show "Nothing to paste"; 4097 characters show "Too long to paste"; text pasted into the session xterm Pass ~/.pickforge/investigations/426/qa/0304.png, 0506-session.png, 06-after-paste-viewer.png
PROTOCOL.md and SECURITY.md Updated for the second path, the focus rule, the device keyboard and the stop Done this diff
Full suite full-suite.sh at 3f3a04c build, lint, typecheck, viewer build, vitest, cargo 3502 passed, 4 skipped; cargo 351 passed. After merging main (#445): build, typecheck, lint and 3 native viewer files, 55 tests, pass ~/.pickforge/investigations/426/full5/
PickCheck and secret scan pickcheck check --base origin/main --fail-on new,worsened,unmatched; gitleaks on the branch commits 105 files checked 0 violations; no leaks ~/.pickforge/investigations/426/fix4/pickcheck.json

Real GNOME was not tested. Mutter sends the selection to each client's data device and keyboard focus to each wl_keyboard, as weston does. No test drives a seat keyboard being removed and added again; that path rests on code review against the Mutter and wlroots seat sources.

Review

Council, three seats per round.

Round Revision Sol Fable Kimi
1 fbbe588 6 8.5 not run (usage limit)
2 d2ba104 5 9 not run
3 aacf3df 5 8 not run
4 9b2a2b1 7 8 not run
5 3f3a04c 8 9 not run

The Kimi seat failed with a usage limit in round 1 and was not run after that.

Round 1 found that a delayed write could still be read after a stop, that an offer could be used after focus loss, and that CI skipped the live test. Rounds 2 and 3 found the gap between the stop check and the read, the stop's lack of priority, the X11 property fetch outside the stop, and focus changes that winit's reads could hide. Round 4 found that a keyboard removed from the seat was never replaced. All are fixed.

Accepted without change: the X11 round trip under the stop has no timeout of its own, and the viewer window depends on the same X server. A wl_keyboard below version 3 cannot be released. On a keyboard re-add, a selection can arrive before the new keyboard's enter. It is refused until that enter brings a fresh one. The focus test cannot see the "Paste unavailable" note, because notes send no event; the code path was checked by review.

When the compositor offers no data-control protocol, such as GNOME, Paste
now reads the selection through the viewer window's own wl_data_device on
winit's connection. The device notes the text types of each selection
offer and asks the source for the text only after the click; the pipe is
read with the same size, time, UTF-8 and stop rules. Data-control stays
the first choice where it exists.

The live test runs weston nested in a private Xvfb with a private socket
and runtime directory, and skips without weston unless
PICKFORGE_REQUIRE_WESTON=1.
A clipboard read now checks the stop flag after each wait and before each
read, so a source that writes only after the paste stopped leaves its
bytes unread. Both Wayland readers share the check.
A wl_data_device selection offer is valid only while the window has
keyboard focus. The app now tracks focus and refuses a click that ends
without it with Paste unavailable. The device drops its selection when
the window has no focus after a dispatch, so an offer from before a focus
loss never reaches a later click, while the selection sent before the
next keyboard enter is kept.

When the device cannot be set up, stderr names the failed step. The line
holds no clipboard content.

The live tests take focus away between press and release with a client
that has no data device, and run on headless weston, which has no seat.
Install weston and wl-clipboard and set PICKFORGE_REQUIRE_WESTON on
ubuntu-latest, so the paste tests run instead of skipping.
The stop flag was checked before each read call, so a paste that stopped
between the check and the read could still take bytes. A lock now covers
the check and the read call, and stopping takes the same lock, so no byte
is read after the stop returns.
…ce queue

A stop now asks first and then waits for the step under way, so the read
worker cannot take the lock again before it. The X11 property request and
its reply run as one step under the stop.

The data device now has its own wl_keyboard on its queue. Enter and leave
reach it in order with the selection, so a leave drops the selection it
ended and a fresh selection that comes with the next enter is kept,
however winit's reads split the stream. Key events are ignored.
When the seat loses its keyboard, the old wl_keyboard gets no more focus
events, so the device releases it, drops the selection and asks for a new
keyboard when the seat has one again. The device now waits for the seat's
capabilities before it asks for the data device, so the keyboard exists
before the first selection arrives.
@ElbertePlinio
ElbertePlinio merged commit 86219a1 into main Oct 29, 2026
10 checks passed
@ElbertePlinio
ElbertePlinio deleted the feat/426-paste-wl-data-device branch October 29, 2026 17:09
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.

viewer: paste on Wayland compositors without data-control, such as GNOME

1 participant