Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix(linux): paste through the KDE portal on non-Latin layouts and keep the user's clipboard (#2520)

void81e7056322f2
diff --git a/CLAUDE.md b/CLAUDE.md
index cf652ac1d..d501eab62 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -62,7 +62,7 @@ OpenWhispr is an Electron-based desktop dictation application that uses whisper.
- **clipboard.js**: Cross-platform clipboard operations
- macOS: AppleScript-based paste with accessibility permission check
- Windows: PowerShell SendKeys with nircmd.exe fallback
- - Linux: compositor-aware Wayland paste (Hyprland sendshortcut, wlroots wtype, GNOME/KDE portal keysyms) with native uinput/XTest and system-tool fallbacks
+ - Linux: compositor-aware Wayland paste (Hyprland sendshortcut, wlroots wtype, GNOME/KDE portal keysyms) with native uinput/XTest and system-tool fallbacks. KDE's portal paste sends Shift+Insert to every window but Warp, which binds paste to Ctrl+Shift+V only: KWin resolves keysyms in the active layout only, so a Ctrl+V on a non-Latin layout arrives as Ctrl alone (#2055). The app runs on XWayland, which the compositor won't let read a native Wayland app's clipboard while a Wayland window is focused, so `_saveClipboard` falls back to `wl-paste --type text` when Electron reads nothing; otherwise the restore would wipe the user's clipboard
- Linux COSMIC: paste reads the focused app from cosmic-comp's `zcosmic_toplevel_info_v1` (`cosmicToplevel.js`, a minimal Wayland wire client, bound at version 1, which still sends app_id and state), never from xdotool, whose XWayland answer goes stale while a native Wayland window has focus. A known terminal is pasted through wtype (Ctrl+Shift+V; Shift+Insert for Konsole); everything else keeps uinput Shift+Insert, since COSMIC gives no PID to spot Electron apps hosting TUIs. Short terminal names (`st`) match whole words only, or every `com.system76.*` app id would read as a terminal
- Linux: before any paste or selection-copy chord, `linux-fast-paste --capabilities --await-modifier-release <ms>` waits for physically held modifiers to be released (XKB state on X11, `EVIOCGKEY` on Wayland; `unknown` without `/dev/input` access pastes as before). A chord injected into held keys arrives as a different shortcut, and a virtual device cannot release another device's key (#2113). Still held after 1.5 s → not pasted, `reason: "modifiers-held"`, and the renderer shows the dictation-error pill with the transcript on the clipboard; a selection edit blocked the same way reports `code: "modifiers_held"` and gets the same pill (the assistant caret paste reports the same code, for logs only). `ydotoold`'s virtual keyboard is ignored, since an interrupted chord can leave its modifier down, and an unreadable key state is logged once per session. The wait runs before `pasteLinux` detects the target window, and a selection copy that had to wait looks the target up again, since focus can move while a key is held: a fresh capture then runs the command on its own (`focus_moved`), and a revalidated session declines as `target_changed`. Retry on a modifiers-held pill pastes the kept transcript again rather than recording again (the macOS/Windows push force-stop pill keeps its record-again Retry, since neither platform waits for held keys), ignores clicks while its paste is pending, and never dismisses a newer pill. `useAudioRecording` keeps the pill in processing until the paste attempt settles (the audio manager settles before the paste starts), but never reports that to main, which drops dictation hotkeys while processing; a paste held back after the next dictation started leaves the transcript on the clipboard without a pill. The helper measures its wait on `CLOCK_MONOTONIC`, since the JS watchdog kills it at timeout + 1 s
- **database.js**: SQLite operations for transcription history
@@ -883,7 +883,7 @@ UI icons come from `src/components/icons/` (vendored Nucleo core outline compone
- Hyprland Wayland: wtype → sendshortcut → uinput/ydotool
- Sway/wlroots Wayland: wtype → uinput/ydotool
- COSMIC Wayland: wtype for a detected terminal → uinput/ydotool
- - GNOME/KDE Wayland: portal keysyms → uinput/ydotool
+ - GNOME/KDE Wayland: portal keysyms (Shift+Insert on KDE, except Warp) → uinput/ydotool
- Physical Wayland fallbacks use Shift+Insert to avoid layout-sensitive KEY_V
- Windows: PowerShell SendKeys (built-in) or nircmd.exe (bundled)
@@ -971,7 +971,7 @@ UI icons come from `src/components/icons/` (vendored Nucleo core outline compone
- **Hyprland Wayland**: `wtype`, then `hyprctl` sendshortcut (avoids the sendshortcut stuck-modifier bug when wtype is installed)
- **Sway/wlroots Wayland**: `wtype` (requires the virtual keyboard protocol)
- **COSMIC Wayland**: `wtype` for terminals (Warp has no Shift+Insert paste); other windows paste with uinput Shift+Insert. Settings and onboarding ask for `wtype` there once something else pastes (`needsWtype` in `src/utils/linuxPasteTools.ts`), but `checkPasteTools` never reports it as the method
- - **GNOME/KDE Wayland**: RemoteDesktop portal keysyms, then uinput/ydotool
+ - **GNOME/KDE Wayland**: RemoteDesktop portal keysyms (Shift+Insert on KDE, except Warp), then uinput/ydotool
- **Wayland physical fallback**: Shift+Insert avoids layout-sensitive KEY_V; `ydotool` requires the `ydotoold` daemon
- Terminal detection: Auto-detects terminal emulators and uses Ctrl+Shift+V
- Fallback: Text copied to clipboard with manual paste instructions
diff --git a/src/helpers/clipboard.js b/src/helpers/clipboard.js
index b7ad6bb69..bb65edfc1 100644
--- a/src/helpers/clipboard.js
+++ b/src/helpers/clipboard.js
@@ -249,6 +249,16 @@ class ClipboardManager {
return null;
}
+ // `--type text` so a copied image never comes back as raw bytes.
+ _readWaylandClipboardText() {
+ if (!this._isWayland() || !this.commandExists("wl-paste")) return null;
+ try {
+ const result = spawnSync("wl-paste", ["--no-newline", "--type", "text"], { timeout: 200 });
+ if (result.status === 0) return result.stdout.toString();
+ } catch {}
+ return null;
+ }
+
// Accepts a Linux window class or a macOS app name. A short name like "st" would
// match inside unrelated names ("com.system76.CosmicEdit"), so it must be a whole word.
isTerminalSignature(signature) {
@@ -831,7 +841,10 @@ class ClipboardManager {
}
if (keys.length > 0) return { type: "formats", data };
- return { type: "text", data: text };
+ // The app runs on XWayland, and the compositor refuses its reads of a native
+ // Wayland app's clipboard while a Wayland window is focused (KWin does). Saving
+ // that empty read would make the restore wipe the user's clipboard (#2055).
+ return { type: "text", data: this._readWaylandClipboardText() ?? text };
}
_restoreClipboard(original) {
@@ -1803,7 +1816,11 @@ class ClipboardManager {
const tryPortalPaste = async () => {
try {
await this._runPortalPaste(linuxFastPaste, {
- shiftInsert: useShiftInsert,
+ // KWin resolves portal keysyms in the active layout only: on a
+ // non-Latin layout there is no XK_v, so Ctrl+V arrives as Ctrl alone
+ // while the helper still exits 0 (#2055). Insert is in every layout,
+ // but Warp binds paste to Ctrl+Shift+V only.
+ shiftInsert: useShiftInsert || (isKde && !signalsMatch("warp")),
terminal: isTerminalTarget,
});
this.safeLog("✅ Paste successful using linux-fast-paste --portal (RemoteDesktop)");
diff --git a/test/helpers/clipboardRestore.test.js b/test/helpers/clipboardRestore.test.js
index 001980a4e..87e6ebf51 100644
--- a/test/helpers/clipboardRestore.test.js
+++ b/test/helpers/clipboardRestore.test.js
@@ -237,6 +237,92 @@ test("restore is skipped when another clipboard write wins the race", async () =
assert.equal(fakeClipboard.text, "user copied something else");
});
+// XWayland can't read a native Wayland app's clipboard while a Wayland window is
+// focused, and restoring that empty read wiped the user's clipboard (#2055).
+// wl-paste exits 1 for an empty or non-text clipboard, and a read killed by the
+// timeout (status null) may have written only part of the text.
+for (const { when, status, stdout, saved } of [
+ {
+ when: "wl-paste exits 0",
+ status: 0,
+ stdout: "copied in a Wayland app",
+ saved: "copied in a Wayland app",
+ },
+ { when: "wl-paste exits 1", status: 1, stdout: "", saved: "" },
+ { when: "wl-paste times out mid-read", status: null, stdout: "copied in a Way", saved: "" },
+]) {
+ test(`an unreadable Wayland clipboard is saved as "${saved}" when ${when}`, async (t) => {
+ const platform = Object.getOwnPropertyDescriptor(process, "platform");
+ Object.defineProperty(process, "platform", { value: "linux" });
+ t.after(() => Object.defineProperty(process, "platform", platform));
+ resetClipboard({ formats: [] });
+ const spawnSyncCalls = [];
+ const Manager = loadClipboardManager({
+ spawnSync: (command, args) => {
+ spawnSyncCalls.push({ command, args });
+ return { status, stdout: Buffer.from(stdout) };
+ },
+ });
+ const manager = new Manager();
+ manager.commandExists = (command) => command === "wl-paste";
+
+ const snapshot = await withWaylandEnvironment("KDE", () => manager._saveClipboard());
+
+ assert.deepEqual(snapshot, { type: "text", data: saved });
+ assert.deepEqual(spawnSyncCalls, [
+ { command: "wl-paste", args: ["--no-newline", "--type", "text"] },
+ ]);
+ });
+}
+
+test("a clipboard XWayland can read is saved without asking wl-paste", async (t) => {
+ const platform = Object.getOwnPropertyDescriptor(process, "platform");
+ Object.defineProperty(process, "platform", { value: "linux" });
+ t.after(() => Object.defineProperty(process, "platform", platform));
+ resetClipboard({ text: "readable over X11" });
+ const spawnSyncCalls = [];
+ const Manager = loadClipboardManager({
+ spawnSync: (command, args) => {
+ spawnSyncCalls.push({ command, args });
+ return { status: 0, stdout: Buffer.from("Wayland side") };
+ },
+ });
+ const manager = new Manager();
+ manager.commandExists = (command) => command === "wl-paste";
+
+ const snapshot = await withWaylandEnvironment("KDE", () => manager._saveClipboard());
+
+ assert.deepEqual(snapshot, { type: "text", data: "readable over X11" });
+ assert.deepEqual(spawnSyncCalls, []);
+});
+
+test("an empty clipboard on X11 is saved without asking wl-paste", async (t) => {
+ const platform = Object.getOwnPropertyDescriptor(process, "platform");
+ Object.defineProperty(process, "platform", { value: "linux" });
+ const { XDG_SESSION_TYPE, WAYLAND_DISPLAY } = process.env;
+ process.env.XDG_SESSION_TYPE = "x11";
+ delete process.env.WAYLAND_DISPLAY;
+ t.after(() => {
+ Object.defineProperty(process, "platform", platform);
+ if (XDG_SESSION_TYPE === undefined) delete process.env.XDG_SESSION_TYPE;
+ else process.env.XDG_SESSION_TYPE = XDG_SESSION_TYPE;
+ if (WAYLAND_DISPLAY !== undefined) process.env.WAYLAND_DISPLAY = WAYLAND_DISPLAY;
+ });
+ resetClipboard({ formats: [] });
+ const spawnSyncCalls = [];
+ const Manager = loadClipboardManager({
+ spawnSync: (command, args) => {
+ spawnSyncCalls.push({ command, args });
+ return { status: 0, stdout: Buffer.from("Wayland side") };
+ },
+ });
+ const manager = new Manager();
+ manager.commandExists = (command) => command === "wl-paste";
+
+ assert.deepEqual(manager._saveClipboard(), { type: "text", data: "" });
+ assert.deepEqual(spawnSyncCalls, []);
+});
+
test("pasteText waits for prior clipboard restoration before starting the next paste", async () => {
const manager = new ClipboardManager();
const events = [];
@@ -697,6 +783,82 @@ test("KDE tries portal before uinput", async () => {
);
});
+// On a non-Latin layout KWin can't map XK_v, so the Ctrl+V (or Ctrl+Shift+V) a
+// detected window would get reaches it as Ctrl alone (#2055).
+for (const windowClass of ["chromium", "kitty"]) {
+ test(`KDE portal sends Shift+Insert to a detected ${windowClass} window`, async () => {
+ const spawnCalls = [];
+ const TestClipboardManager = loadClipboardManager({
+ spawn: createSpawn(spawnCalls, [0]),
+ });
+ const manager = new TestClipboardManager();
+ manager.commandExists = () => false;
+ manager.resolveLinuxFastPasteBinary = () => "/tmp/linux-fast-paste";
+ manager._readPortalToken = () => null;
+ manager._detectKdeWindowClass = () => windowClass;
+
+ await withWaylandEnvironment("KDE", () => manager.pasteLinux(null));
+
+ assert.deepEqual(
+ spawnCalls.map((call) => call.args),
+ [["--portal", "--shift-insert"]]
+ );
+ });
+}
+
+// Warp binds paste to Ctrl+Shift+V only, so it keeps that chord on KDE.
+test("KDE portal sends Ctrl+Shift+V to a detected Warp window", async () => {
+ const spawnCalls = [];
+ const TestClipboardManager = loadClipboardManager({
+ spawn: createSpawn(spawnCalls, [0]),
+ });
+ const manager = new TestClipboardManager();
+ manager.commandExists = () => false;
+ manager.resolveLinuxFastPasteBinary = () => "/tmp/linux-fast-paste";
+ manager._readPortalToken = () => null;
+ manager._detectKdeWindowClass = () => "dev.warp.warp";
+
+ await withWaylandEnvironment("KDE", () => manager.pasteLinux(null));
+
+ assert.deepEqual(
+ spawnCalls.map((call) => call.args),
+ [["--portal", "--terminal"]]
+ );
+});
+
+// The Shift+Insert switch for #2055 is KWin-specific: a detected GNOME window
+// keeps Ctrl+V through the portal.
+test("GNOME portal sends Ctrl+V to a detected window", async () => {
+ const spawnCalls = [];
+ const TestClipboardManager = loadClipboardManager({
+ spawn: createSpawn(spawnCalls, [0]),
+ spawnSync: (command, args) => {
+ if (command === "xdotool" && args.includes("getwindowclassname")) {
+ return { status: 0, stdout: Buffer.from("firefox\n") };
+ }
+ if (command === "xdotool" && args.length === 1) {
+ return { status: 0, stdout: Buffer.from("42\n") };
+ }
+ return { status: 1, stdout: Buffer.from("") };
+ },
+ });
+ const manager = new TestClipboardManager();
+ manager.commandExists = (command) => command === "xdotool";
+ manager.resolveLinuxFastPasteBinary = () => "/tmp/linux-fast-paste";
+ manager._readPortalToken = () => "restore-token";
+ manager._savePortalToken = () => {};
+
+ await withWaylandEnvironment("GNOME", () => {
+ process.env.DISPLAY = ":0";
+ return manager.pasteLinux(null);
+ });
+
+ assert.deepEqual(
+ spawnCalls.map((call) => call.args),
+ [["--portal", "--restore-token", "restore-token"]]
+ );
+});
+
test("portal exit zero succeeds with or without a restore token", async () => {
const calls = [];
const TestClipboardManager = loadClipboardManager({