Skip to content

Linux copy and paste use the Insert shortcuts - #37

Open
adamshiervani wants to merge 1 commit into
mainfrom
linux-copy-paste-shortcuts
Open

adamshiervani wants to merge 1 commit into
mainfrom
linux-copy-paste-shortcuts

Conversation

@adamshiervani

@adamshiervani adamshiervani commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem

With OS Services on a Linux target, a paste from the web UI does nothing in a terminal, and a copy stops the program that runs in the terminal. Both work in other applications, such as GNOME Text Editor.

Cause

For a paste, the sender writes the text to the target's clipboard, and the Mini then types Ctrl+V. For a copy, the Mini types Ctrl+C, and then asks the sender for the clipboard. A Linux terminal takes Ctrl+V and Ctrl+C as control characters: it prints ^V for the first and sends an interrupt for the second.

Fix

This is the Mini side of jetkvm/kvm#1801 ("fix(os-services): Linux copy and paste use the Insert shortcuts"), with the same behavior.

Paste. Shift+Insert pastes in a terminal and in other applications, but a terminal pastes the primary selection (the text that the user highlighted last), and other applications paste the clipboard. A sender with jetkvm/os-services#5 ("On Linux, a paste also sets the primary selection") writes both, and says so with bit 2 of flags in clipboard.capabilities.

  • OSVC_CLIPBOARD_FLAG_PRIMARY in os_services_wire.h is the new bit. handle_clipboard in os_services_session.c accepts it, and faults the clipboard service when it comes without the write bit, because clipboard.set does the write.
  • send_session_config sends "clipboard_primary": true. A sender sets the bit only for a KVM that sends this, because firmware of before rejects unknown bits.
  • jetkvm_os_services.c passes the bit to the UI as primary in guestClipboard, and GuestClipboardState in stores.ts has the field.
  • pasteShortcut in useGuestClipboard.ts returns Shift+Insert when primary is set, Cmd+V for macOS, and Ctrl+V otherwise.

With a sender of before the bit is not set, and the Mini types Ctrl+V as before. Shift+Insert without the bit would paste old highlighted text in a terminal.

Copy. copyShortcut in useGuestClipboard.ts returns Ctrl+Insert for a Linux target, which copies in a terminal and in other applications. The sender reads the clipboard as before, so the copy needs no flag.

The two UI files have the same change as in jetkvm/kvm#1801. macOS and Windows targets do not change.

Testing

components/jetkvm_os_services/tests/run_host_tests.sh passes. The new test test_clipboard_primary_flag checks that read, write and primary together are accepted, that read with primary faults the clipboard service, and that an unknown bit still faults it. The two session.config tests expect clipboard_primary. The UI lint and the type check pass.

Not in this PR

This change is not tested on a Mini. The same behavior is tested on a JetKVM with jetkvm/kvm#1801 and an Intel N100 with Ubuntu 26.04 (GNOME 50 on Wayland): a paste arrives in GNOME Terminal and in Text Editor, and a copy from GNOME Terminal sets the target's clipboard without an interrupt.


Note

Medium Risk
Touches clipboard protocol negotiation and injected keystrokes; backward compatible when senders omit the primary bit, but wrong shortcut choice could paste stale primary selection if mis-negotiated.

Overview
Adds primary-selection support to OS Services clipboard so Linux guest paste/copy works in terminals (Ctrl+V/C are control characters there).

Protocol & firmware: New OSVC_CLIPBOARD_FLAG_PRIMARY; session.config advertises clipboard_primary: true; clipboard.capabilities rejects primary without write; guestClipboard JSON includes optional primary.

UI: GuestClipboardState.primary drives pasteShortcut (Shift+Insert when primary is set, else macOS/Windows behavior) and `copyShortcut** (Ctrl+Insert on Linux). Paste/copy macros use these instead of fixed Ctrl+V/C.

Tests: Session config and clipboard capability tests updated; test_clipboard_primary_flag added.

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

Summary by CodeRabbit

  • New Features
    • Guest clipboard writes can now update the Linux primary selection when supported.
    • Paste shortcuts adapt to the guest: Shift+Insert when primary selection is enabled, Ctrl+V otherwise, and Meta+V on macOS. Copy uses Ctrl+Insert on Linux, Ctrl+C on other non-macOS guests, and Meta+C on macOS.
    • Older KVMs that do not report primary-selection support continue to use the standard paste shortcut.

A paste did nothing in a Linux terminal, and a copy stopped the program
that ran in it. The Mini typed Ctrl+V and Ctrl+C after the OS Services
clipboard request, and a terminal takes both as control characters.

Paste: a Linux sender that also writes the primary selection says so
with bit 2 of the flags in clipboard.capabilities. The Mini then types
Shift+Insert: a terminal pastes the primary selection, and other
applications paste the clipboard. The Mini sends "clipboard_primary":
true in session.config, because a sender sets the bit only for a KVM
that accepts it. Without the bit the Mini types Ctrl+V as before.

Copy: for a Linux target the Mini types Ctrl+Insert, which copies in a
terminal and in other applications. The sender reads the clipboard as
before, so this needs no flag.

macOS and Windows targets do not change.

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

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Primary-Selection Clipboard

Layer / File(s) Summary
Advertise and validate clipboard capability
components/jetkvm_os_services/include/os_services_wire.h, components/jetkvm_os_services/os_services_session.c, components/jetkvm_os_services/tests/test_os_services_protocol.py, components/jetkvm_os_services/tests/test_os_services_session.c
The session configuration advertises clipboard_primary. Clipboard validation accepts the primary flag only with the write flag. Tests check the configuration and capability validation.
Expose primary-selection state
components/jetkvm_os_services/jetkvm_os_services.c, frontend/jetkvm-ui/src/hooks/stores.ts
The guestClipboard JSON object includes the primary state. GuestClipboardState adds an optional primary property.
Select guest clipboard key chords
frontend/jetkvm-ui/src/hooks/useGuestClipboard.ts
New helpers select paste and copy chords by guest OS and primary-selection state. Guest paste and copy use these helpers.

Change: Bug fix

Merge Risk: Minimal · up to 658f0

This change makes Linux guest copy and paste use the Insert shortcuts when primary-selection support is advertised. Older KVMs keep the existing Ctrl+V paste behavior. No merge-blocking risk was identified.

Security architecture risk: Low · up to 658f0

The change is limited to clipboard actions on the connected computer. If clipboard support changes during a paste, the new shortcut can insert an earlier selection instead of the text the user just sent.

Retained concerns

  • Low · security · inferred: The paste action chooses Shift+Insert from a previously reported capability, not from the completed write. Firmware can accept a capability update that removes primary support while retaining write access without invalidating the pending request. If the successful write updated only the ordinary clipboard, the browser can still press Shift+Insert and insert an earlier primary selection into the focused guest application. The base did not select the primary buffer through this shortcut.
Security review details

Security Blast Radius

  • inferred — The changed paste path can select a different buffer in the focused application on the connected guest. It still requires an enabled clipboard write path and a browser paste gesture; the primary bit does not create an independent keyboard trigger or clipboard read grant.

Trust Boundaries and Controls

  • observed — The sender supplies both the capability advertisement and the write acknowledgement. Firmware checks capability shape and matches the acknowledgement to a pending set request, but the acknowledgement carries status rather than a statement of which clipboard buffers were written.

Resilience and Maintainability Implications

  • observed — Session teardown fails pending clipboard requests and forgets registrations. The browser drops overlapping transfers within the page, releases its guard on completion or error, and skips the paste shortcut on an unsuccessful write.

Hardening Proposals

  • proposed — Choose Shift+Insert only when the completed write confirms that it set the primary selection and still belongs to the active guest session. If the session or capability changed, stop the gesture rather than guessing which buffer is current.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

  • Mode: Continue automatically
  • Reviewed files: 7
  • Waived: $1.75 (charged $0.00)
  • View usage details

Note

This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1a8d3579-e9fd-4407-b09a-d3a390cc7ce6
Commits

Reviewing files that changed from the base of the PR and between 28bf553 and 658f070.

Files selected for processing: 7

  • components/jetkvm_os_services/include/os_services_wire.h
  • components/jetkvm_os_services/jetkvm_os_services.c
  • components/jetkvm_os_services/os_services_session.c
  • components/jetkvm_os_services/tests/test_os_services_protocol.py
  • components/jetkvm_os_services/tests/test_os_services_session.c
  • frontend/jetkvm-ui/src/hooks/stores.ts
  • frontend/jetkvm-ui/src/hooks/useGuestClipboard.ts

Limit details: You’ve used all 10 included reviews currently available.

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