Skip to content

fix(linux): restore the previous clipboard after a paste - #415

Merged
thdxr merged 1 commit into
devfrom
linux-clipboard-restore
Oct 29, 2026
Merged

thdxr merged 1 commit into
devfrom
linux-clipboard-restore

Conversation

@thdxr

@thdxr thdxr commented Oct 29, 2026

Copy link
Copy Markdown
Member

Fixes #391

Linux paste now restores the user's previous clipboard by default, as macOS does. Thanks to @shashankx86 for reporting it.

  • Before writing the transcript, linux_paste snapshots every format of the CLIPBOARD selection (32 MiB cap, 1 s deadline) through the new linux_clipboard module: wlr-data-control on Wayland (no helper per type), and Hex's own X11 selection owner with TARGETS and INCR (x11-clipboard serves only one target).
  • 500 ms after the paste shortcut (the macOS delay), a generation-checked thread restores it only if no later paste or copy happened and the clipboard still holds the paste (same bytes on Wayland, the paste's owner on X11). Back-to-back pastes keep the first original.
  • Empty before → cleared again. Over the cap or unreadable → not restored, logged. A paste that only reached the clipboard ("press Ctrl+V") keeps the transcript. Capture copies are never restored over.
  • Paste Last, Voice Action, terminal paste, and the RemoteDesktop portal path are unchanged; transcripts stay on stdin.

Verified on apollo in nested headless Sway: scripts/test-wayland-paste.sh now checks a two-format restore and an empty clipboard staying empty (passes); a full dictation from a file-fed ALSA mic pasted into a GTK target, then Ctrl+V pasted the original; an Xwayland round trip restored a 3 MB image through INCR. Dax's session clipboard was not touched.

— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

Linux paste now snapshots every format of the clipboard before writing the
transcript and restores it 500 ms after the paste shortcut, as macOS does,
unless a later paste, copy, or another client replaced it. Wayland reads and
serves through wlr-data-control; X11 through Hex's own selection owner with
INCR. Empty clipboards stay empty; clipboards over 32 MiB are left, with a log
line. Thanks to @shashankx86 for the report.

Fixes #391
@thdxr
thdxr merged commit 83e0825 into dev Oct 29, 2026
4 of 6 checks passed
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.

Add an option to insert dictation without adding it to clipboard

1 participant