Skip to content

Make copy actually copy on Wayland (main-process clipboard + OSC 52)#55

Open
ymajoros wants to merge 1 commit into
doctly:mainfrom
ymajoros:fix/clipboard-copy-wayland
Open

Make copy actually copy on Wayland (main-process clipboard + OSC 52)#55
ymajoros wants to merge 1 commit into
doctly:mainfrom
ymajoros:fix/clipboard-copy-wayland

Conversation

@ymajoros

Copy link
Copy Markdown

Fixes #54.

Copy was a black hole on Linux/Wayland — paste fine, copy gone. Two reasons, both about the renderer's rocky relationship with the clipboard:

1. Ctrl+C went through the renderer. navigator.clipboard.writeText(...).catch(() => {}) rejects on Ozone/Wayland (Chromium wants window focus + a user gesture) and the empty .catch swallowed it whole. Textbook silent failure.

2. OSC 52 wasn't handled at all. That's the sequence Claude Code uses to copy. xterm doesn't register a handler for it on its own, so those copies went nowhere.

What this does

Adds a small clipboard-write-text IPC that calls the main-process clipboard.writeText. The main process has none of the renderer's focus/gesture hangups, so it just writes on Wayland. Then:

  • Ctrl+C (with a selection) uses it instead of navigator.clipboard
  • registered an OSC 52 handler that base64-decodes the payload and routes it through the same IPC (and ignores the ? read-back query, which we don't answer)

Paste was never broken, so it's untouched.

The diff (3 files, ~30 lines)

  • main.js — import clipboard, add the IPC handler
  • preload.js — expose writeClipboard
  • public/terminal-manager.js — use it for Ctrl+C, add the OSC 52 handler

terminal.parser.registerOscHandler is stable xterm API and allowProposedApi: true is already set, so nothing new is required capability-wise.

Testing

Ubuntu / GNOME 49 / Wayland, native Ozone.

  • Before: Claude Code copy, Ctrl+C, and right-click Copy all dead, no error.
  • After: Claude Code's copy and Ctrl+C-with-selection both land in the system clipboard and paste cleanly into other apps.

I only have the Linux box, so I'd love a second pair of eyes confirming macOS/Windows still behave — though main-process clipboard is the boring-and-reliable option on every platform, so I'd be surprised if it regressed anything.

Copying out of the terminal did nothing on Linux/Wayland. Two separate holes:

- Ctrl+C copy used navigator.clipboard.writeText in the renderer. Chromium
  gates that on window focus + a user gesture, and it's effectively dead under
  Ozone/Wayland. The trailing .catch(() => {}) ate the rejection, so it failed
  in total silence.
- OSC 52 (how Claude Code itself copies) wasn't wired up at all — xterm doesn't
  do it for you, so those copies just evaporated.

Both now go through the main-process clipboard over IPC, which doesn't care about
focus or gestures. Paste was never affected, so it's left alone.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@ymajoros

Copy link
Copy Markdown
Author

Confirmed working. Built this branch and ran it on Ubuntu / GNOME Shell 49 / native Wayland (Ozone), Electron 41.0.3 — the same box where stock 0.0.30 copies nothing.

Both paths now land in the system clipboard and paste cleanly into other apps:

  • OSC 52 (Claude Code's copy) — tested with printf '\e]52;c;%s\a' "$(printf hi | base64)"
  • Ctrl+C with a selection

Paste was unaffected throughout. No regressions spotted in normal terminal use.

JeanBaptisteRenard added a commit to JeanBaptisteRenard/switchboard that referenced this pull request May 30, 2026
…18)

navigator.clipboard.writeText is gated on focus/user-activation and
silently fails on Linux/Wayland (Ozone). Replace with a main-process
clipboard.writeText via a new clipboard-write-text IPC.

Also register an xterm OSC 52 handler so programs inside the terminal
(notably Claude Code's copy-to-clipboard) can set the system clipboard;
xterm doesn't wire OSC 52 itself.

Port of upstream PR doctly#55 (ymajoros). Closes upstream
issue #54 from our fork's perspective; the upstream PR will close it
fully when merged.
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.

Copy to clipboard silently does nothing on Linux/Wayland (paste works fine)

1 participant