Repository navigation
feat(viewer): paste on Wayland compositors without data-control - #446
Merged
Merged
Conversation
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.
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.
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_keyboardon 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-clientwith thedlopenfeature is the only new dependency, and the release binary still links no libwayland. CI'srustjob now installs weston and wl-clipboard and setsPICKFORGE_REQUIRE_WESTON, so the live tests cannot skip there.Traceability
wl_data_devicewithout data-controlpaste_weston::paste_reads_the_selection_through_the_window_data_deviceon 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 outputapp.rs~/.pickforge/investigations/426/failing-before-paste_weston.txt,fix4/viewer-tests.txt,fix4/paste-weston-5x.txt~/.pickforge/investigations/426/sway/clipboard::a_read_waiting_when_the_paste_stops_reads_no_byteanda_stop_waits_for_the_step_under_way_and_refuses_the_next~/.pickforge/investigations/426/fix1/fix1-stop-read-before.txt,fix4/viewer-tests.txtpaste_weston::paste_refuses_a_click_that_completes_after_focus_moved_awaywl-copyfocus bounce before each paste keeps the fresh selection~/.pickforge/investigations/426/fix1/fix2-focus-before.txt,fix4/paste-weston-5x.txtpaste_weston::a_data_device_that_cannot_be_set_up_names_the_stepon headless weston without a seat~/.pickforge/investigations/426/fix1/fix4-setup-line-before.txt,fix4/viewer-tests.txtdata_deviceunit tests andread_pipe_reads_only_while_the_paste_is_wanted~/.pickforge/investigations/426/fix4/viewer-tests.txtlddon the release binary~/.pickforge/investigations/426/fix1/ldd.txtrustjob installs weston and wl-clipboard,PICKFORGE_REQUIRE_WESTON=1on ubuntu-latestrust (ubuntu-latest)checkqa.shon headless weston with the desktop shell~/.pickforge/investigations/426/qa/0304.png,0506-session.png,06-after-paste-viewer.pngfull-suite.shat 3f3a04c~/.pickforge/investigations/426/full5/pickcheck check --base origin/main --fail-on new,worsened,unmatched; gitleaks on the branch commits~/.pickforge/investigations/426/fix4/pickcheck.jsonReal 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.
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_keyboardbelow 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.