Repository navigation
On Linux, a paste also sets the primary selection - #5
Open
adamshiervani wants to merge 1 commit into
Open
adamshiervani wants to merge 1 commit into
adamshiervani wants to merge 1 commit into
Conversation
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
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
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.setnow writes the text to the primary selection and to the clipboard (writeinsrc/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
flagsinclipboard.capabilities(ClipboardCapabilities::primary, encoded insrc/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": trueinsession.config(SessionSettings::clipboard_primary, kept inControlLink). This is the pattern ofdisplay_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_supportedinsrc/services/clipboard/linux.rs). On X11 there is always one. macOS and Windows never set the bit.PROTOCOL.mddocumentsclipboard_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.configwithoutclipboard_primaryreads as false, and a registration with read, write and primary encodesflagsas 7. The container build ran the lint and the tests before the rebase onmain.On an Intel N100 with Ubuntu 26.04 (GNOME 50 on Wayland), with a JetKVM that runs the KVM side:
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": trueinsession.config, the sender sets bit 2 inclipboard.capabilitiesand, 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
SessionSettingsgainclipboard_primary/ClipboardCapabilities::primary; session startup passes the KVM policy intoclipboard::capabilities()and registration.Reviewed by Cursor Bugbot for commit 8547c50. Bugbot is set up for automated code reviews on this repo. Configure here.