fix(linux): persistent clipboard ownership on Wayland — Ctrl+V works after transcription#221
Open
injaamam wants to merge 2 commits intoOpenWhispr:mainfrom
Open
fix(linux): persistent clipboard ownership on Wayland — Ctrl+V works after transcription#221injaamam wants to merge 2 commits intoOpenWhispr:mainfrom
injaamam wants to merge 2 commits intoOpenWhispr:mainfrom
Conversation
Author
|
Built and tested on [Kubuntu 25.04] Wayland. Ctrl+V works after transcription; clipboard behavior is correct. |
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
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:Changes
src/helpers/clipboard.jswriteClipboardInRenderer(webContents, text)(safeJSON.stringifyfor injection).pasteText(text, options): acceptsoptions.webContents; on Linux + Wayland + valid webContents, writes via renderer instead of main process; passes options topasteLinuxfor 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.lastOwnedClipboardTextand clear onapp.on('will-quit').src/helpers/ipcHandlers.jspaste-text: passesevent.senderaswebContentsin options.write-clipboard: passesevent.senderas second argument.Platform impact
Testing