Skip to content

feat(wayland): add zwp_primary_selection_v1 support and keyboard primary-selection writes (#1859) - #2640

Merged
Hona merged 1 commit into
devfrom
feat/wayland-primary-selection
Nov 27, 2026
Merged

Hona merged 1 commit into
devfrom
feat/wayland-primary-selection

Conversation

@Hona

@Hona Hona commented Nov 27, 2026

Copy link
Copy Markdown
Member

Summary

Implements native Wayland zwp_primary_selection_v1 primary-selection support (Part 2 of #1859) and extends Linux primary-selection writes to keyboard selections (Shift+Arrows, Ctrl+A) alongside pointer releases.

  • Native Wayland zwp_primary_selection_v1 backend (crates/rune/src/platform/wayland/primary_selection/):
    • Lazily binds zwp_primary_selection_device_manager_v1 (v1) once per wl_display after frame 1 (Host::run_on_ready and after an overlay's first frame); falls back to arboard's rune-primary worker only when the compositor lacks the global (and keeps X11 unchanged).
    • Reuses the shared unwatched per-seat serial tracker (platform/wayland/serial.rs), shared bounded pipe reader promoted from drop/pipe.rs into platform/wayland/pipe.rs, and shared non-blocking bounded pipe writer (platform/wayland/pipe_write.rs).
    • Plugs into window::wayland_wake strictly while our own zwp_primary_selection_source_v1 is owned (zero background WaylandWatch threads, zero idle wakeups on plain windows).
    • Pure state machine (machine.rs) handles Mutter's selection(None) -> selection(Some(new)) replacement, Hyprland pointer-enter offers, zero-syscall self-paste fast path while owning the source, RFC 2045 case-insensitive MIME priority (text/plain;charset=utf-8 > UTF8_STRING > text/plain > TEXT > STRING with Latin-1 decode), MAX_PENDING_OFFERS = 16 eviction, latest-wins Attempt read cancellation (4 MiB / 2 s cap), MAX_CONCURRENT_WRITERS = 8 (5 s timeout, Arc<[u8]> sharing), retired sources ignoring stale Cancelled, and strict teardown before wl_display closes.
  • Keyboard primary-selection writes (runtime/input/primary_selection.rs, keys.rs, caret_browse, select_all.rs):
    • Shift+Arrows and Ctrl+A in editable/read-only text_input, caret browsing, and selectable text publish to primary selection coalesced once per frame, with secure fields still excluded and collapse/blur leaving primary selection intact.
    • RuntimeCore::primary_selection_lost() clears the dedup hash when the active source receives Cancelled, so re-selecting identical text after another app overwrote primary selection publishes again.

Verification

  • Verified locally on Windows + wasm32-unknown-unknown:
    • cargo test -p rune --lib platform::wayland:: (78 passed, including 8 new primary_selection::machine tests and extended serial tests)
    • cargo test -p rune --lib runtime::input::primary_selection (8 passed, including keyboard Shift+Arrow, Ctrl+A, coalescing, primary_selection_lost, secure fields, caret browsing, and selectable text)
    • cargo test -p rune --lib wayland_wake (5 passed)
    • cargo check -p rune --target wasm32-unknown-unknown (passed)
    • scripts/file-size.sh (0 errors, 0 folder-shape violations)
  • Not run locally: Linux Wayland wire compilation, Unix pipe(2) tests, opt-in headless sway E2E test (sway_e2e_tests.rs), and live desktop Wayland compositors (GNOME/Mutter, Flatpak, KDE Plasma, Hyprland) — relying on Linux CI for Linux/Unix build + tests and asking the reporter to confirm on live compositors.

Fixes #1859

@Hona
Hona force-pushed the feat/wayland-primary-selection branch from 6f6481e to 0aebebd Compare November 27, 2026 15:22
@Hona
Hona merged commit 6c95557 into dev Nov 27, 2026
1 of 2 checks passed
@Hona
Hona deleted the feat/wayland-primary-selection branch November 27, 2026 15:23
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.

Linux primary selection: middle-clicking a role("textbox") wrapper misses paste and leaks to ancestors, and Wayland lacks zwp_primary_selection_v1

1 participant