Skip to content

On Linux, a paste also sets the primary selection - #5

Open
adamshiervani wants to merge 1 commit into
mainfrom
linux-paste-primary-selection
Open

adamshiervani wants to merge 1 commit into
mainfrom
linux-paste-primary-selection

Conversation

@adamshiervani

@adamshiervani adamshiervani commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A paste from the KVM web UI does nothing in a Linux terminal. The same paste works in other applications, such as GNOME Text Editor. A user who works in a terminal on the target cannot paste.

Cause

A paste has two steps: the sender writes the text to the target's clipboard, and the KVM then types a paste shortcut as a USB keyboard. For Linux the KVM types Ctrl+V. A terminal takes Ctrl+V as a control character and prints ^V, so the text never arrives.

Shift+Insert pastes in a terminal and in other applications, but they read different buffers. A terminal pastes the primary selection, which holds the text that the user highlighted last, and other applications paste the clipboard. The sender wrote only the clipboard, so Shift+Insert in a terminal would paste old highlighted text.

Fix

On Linux, clipboard.set now writes the text to the primary selection and to the clipboard (write in src/services/clipboard.rs). The primary selection goes first, so a failure there leaves both buffers as they were. The sender does the same for each paste and does not look at the focused application.

The KVM must know that the sender wrote both buffers before it types Shift+Insert, because a sender of before writes only the clipboard. The sender says so with bit 2 of flags in clipboard.capabilities (ClipboardCapabilities::primary, encoded in src/protocol/codec.rs).

A KVM of before rejects a flag bit that it does not know. The sender therefore sets bit 2 only for a KVM that sends "clipboard_primary": true in session.config (SessionSettings::clipboard_primary, kept in ControlLink). This is the pattern of display_mode_by_sender, and the protocol version does not change, so each pair of old and new versions keeps its behavior of before.

On Wayland the sender sets bit 2 only when the compositor has a primary selection (primary_supported in src/services/clipboard/linux.rs). On X11 there is always one. macOS and Windows never set the bit.

PROTOCOL.md documents clipboard_primary, bit 2 and the shortcuts.

The KVM side is jetkvm/kvm (the pull request "Linux copy and paste use the Insert shortcuts").

Testing

Two unit tests cover the wire format: session.config without clipboard_primary reads as false, and a registration with read, write and primary encodes flags as 7. The container build ran the lint and the tests before the rebase on main.

On an Intel N100 with Ubuntu 26.04 (GNOME 50 on Wayland), with a JetKVM that runs the KVM side:

KVM firmware Sender Paste in GNOME Terminal Paste in Text Editor
before 0.4.5 prints nothing text arrives
with the KVM side this change text arrives text arrives

Not in this PR

An X11 session and desktops other than GNOME are not tested.


Note

Medium Risk
Touches clipboard write paths and protocol capability bits; mis-sync with KVM firmware could break paste, but old KVMs reject unknown bits and behavior stays unchanged without clipboard_primary.

Overview
Adds optional primary-selection paste so KVM-driven paste works in Linux terminals (which ignore Ctrl+V). When the KVM advertises "clipboard_primary": true in session.config, the sender sets bit 2 in clipboard.capabilities and, on paste (clipboard.set), writes text to the primary selection first, then the regular clipboard—on Wayland only when the compositor supports it.

Protocol docs describe the new session flag, capability bit, and that a supporting KVM types Shift+Insert on Linux instead of relying on Ctrl+V alone. Wire encoding and SessionSettings gain clipboard_primary / ClipboardCapabilities::primary; session startup passes the KVM policy into clipboard::capabilities() and registration.

Reviewed by Cursor Bugbot for commit 8547c50. Bugbot is set up for automated code reviews on this repo. Configure here.

A paste from the KVM did nothing in a Linux terminal. The service wrote
the text to the clipboard, and the KVM typed Ctrl+V, which a terminal
takes as a control character and prints as ^V.

Shift+Insert pastes in a terminal and in other applications, but a
terminal pastes the primary selection and other applications paste the
clipboard. A write now sets both, the primary selection first, so that
a KVM can type Shift+Insert.

The KVM must know that the service wrote both: with a service that
writes only the clipboard, Shift+Insert in a terminal pastes the text
that the user highlighted last. The service says so with bit 2 of the
flags in clipboard.capabilities. A KVM of before rejects a flag bit it
does not know, so the service sets the bit only for a KVM that sends
"clipboard_primary": true in session.config. The protocol version does
not change.

On Wayland the service sets the bit only when the compositor has a
primary selection. On X11 there is always one.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant