Skip to content

fix(linux): persistent clipboard ownership on Wayland — Ctrl+V works after transcription#221

Open
injaamam wants to merge 2 commits intoOpenWhispr:mainfrom
injaamam:fix/wayland-clipboard
Open

fix(linux): persistent clipboard ownership on Wayland — Ctrl+V works after transcription#221
injaamam wants to merge 2 commits intoOpenWhispr:mainfrom
injaamam:fix/wayland-clipboard

Conversation

@injaamam
Copy link

@injaamam injaamam commented Feb 8, 2026

Problem

On Wayland, after speech recognition finishes, OpenWhispr cannot automatically paste text into the focused text box due to Wayland security restrictions, which prevent applications from injecting input into other clients. Therefore, OpenWhispr relies on the system clipboard.

However, after speech recognition finishes, OpenWhispr copies the transcription to the system clipboard but releases clipboard ownership immediately. On Wayland the compositor does not store clipboard content; it only holds a reference to the owning client's wl_data_source. Once the owner releases the source, the clipboard has no active owner.

Result: Ctrl+V fails in all applications. Clipboard history (e.g. Klipper) may show the text, but paste only works after manually re-selecting the item.

Root cause

Clipboard writes were done in the main process via Electron's clipboard.writeText(). After the copy function (and IPC handler) completed, the clipboard source was dropped. This matches how Wayland works: the owner must keep the source alive.

Solution

On Linux when running under Wayland, clipboard writes are now performed in the renderer (the visible window) via webContents.executeJavaScript('navigator.clipboard.writeText(...)'). The renderer's WebContents then owns the Wayland clipboard offer for the window's lifetime, so:

  • Ctrl+V works in all apps after transcription
  • Ownership is released only when a new transcription is copied, or the app exits
  • No reliance on clipboard history or external helpers

Changes

  • src/helpers/clipboard.js
    • Added writeClipboardInRenderer(webContents, text) (safe JSON.stringify for injection).
    • pasteText(text, options): accepts options.webContents; on Linux + Wayland + valid webContents, writes via renderer instead of main process; passes options to pasteLinux for restore.
    • pasteLinux(originalClipboard, options): after successful paste, restores previous clipboard via renderer on Wayland when webContents is provided.
    • writeClipboard(text, webContents): optional second argument; on Linux + Wayland + valid webContents, writes via renderer.
    • Optional: lastOwnedClipboardText and clear on app.on('will-quit').
  • src/helpers/ipcHandlers.js
    • paste-text: passes event.sender as webContents in options.
    • write-clipboard: passes event.sender as second argument.

Platform impact

Platform Effect
macOS No change (main process clipboard only).
Windows No change (main process clipboard only).
Linux (X11) No change (main process clipboard only).
Linux (Wayland) Fixed: renderer owns clipboard; Ctrl+V works.

Testing

  • Wayland: Run under a Wayland session (e.g. GNOME on Wayland). After a transcription, confirm the text is in the clipboard and Ctrl+V works in another app (browser, terminal, editor) without re-selecting in Klipper.
  • X11 / macOS / Windows: Confirm existing copy + paste simulation and clipboard restore still work as before.

@injaamam
Copy link
Author

injaamam commented Feb 8, 2026

Built and tested on [Kubuntu 25.04] Wayland. Ctrl+V works after transcription; clipboard behavior is correct.

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