Skip to content

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

refactor(linux): improve Wayland paste detection with GNOME-specific handling and XWayland fallback support

Gabriel Stein3e44127cf31e
diff --git a/src/components/ui/PasteToolsInfo.tsx b/src/components/ui/PasteToolsInfo.tsx
index f5f09359f..3d295a879 100644
--- a/src/components/ui/PasteToolsInfo.tsx
+++ b/src/components/ui/PasteToolsInfo.tsx
@@ -56,6 +56,10 @@ export default function PasteToolsInfo({
// Linux with tools available
if (pasteToolsInfo.platform === "linux" && pasteToolsInfo.available) {
+ const method = pasteToolsInfo.method || "xdotool";
+ const methodSuffix =
+ pasteToolsInfo.isWayland && method === "xdotool" ? " (XWayland apps only)." : ".";
+
return (
<div className="border border-green-200 bg-green-50 rounded-lg p-4">
<div className="flex items-center justify-between">
@@ -64,8 +68,8 @@ export default function PasteToolsInfo({
<div>
<h3 className="font-semibold text-green-900">Automatic Pasting Ready</h3>
<p className="text-sm text-green-700">
- Using <code className="bg-green-100 px-1 rounded">{pasteToolsInfo.method}</code> for
- automatic text pasting.
+ Using <code className="bg-green-100 px-1 rounded">{method}</code> for automatic text
+ pasting{methodSuffix}
</p>
</div>
</div>
@@ -80,45 +84,74 @@ export default function PasteToolsInfo({
// Linux without tools - show helpful install instructions
if (pasteToolsInfo.platform === "linux" && !pasteToolsInfo.available) {
const isWayland = pasteToolsInfo.isWayland;
- const recommendedTool = pasteToolsInfo.recommendedInstall || (isWayland ? "wtype" : "xdotool");
+ const xwaylandAvailable = pasteToolsInfo.xwaylandAvailable;
+ const recommendedTool = pasteToolsInfo.recommendedInstall;
+ const showInstall = !!recommendedTool;
return (
<div className="border border-amber-200 bg-amber-50 rounded-lg p-4 space-y-3">
<div className="flex items-start gap-3">
<Info className="w-6 h-6 text-amber-600 flex-shrink-0 mt-0.5" />
<div className="flex-1">
- <h3 className="font-semibold text-amber-900">Optional: Enable Automatic Pasting</h3>
- <p className="text-sm text-amber-800 mt-1">
- For automatic text pasting, install{" "}
- <code className="bg-amber-100 px-1 rounded font-mono">{recommendedTool}</code>:
- </p>
+ <h3 className="font-semibold text-amber-900">
+ {showInstall ? "Optional: Enable Automatic Pasting" : "Clipboard Mode on Wayland"}
+ </h3>
- <div className="mt-3 bg-gray-900 text-gray-100 p-3 rounded-md font-mono text-xs overflow-x-auto">
- {isWayland ? (
- <>
- <div className="text-gray-400"># Fedora / RHEL</div>
- <div>sudo dnf install wtype</div>
- <div className="text-gray-400 mt-2"># Debian / Ubuntu</div>
- <div>sudo apt install wtype</div>
- <div className="text-gray-400 mt-2"># Arch Linux</div>
- <div>sudo pacman -S wtype</div>
- </>
- ) : (
- <>
- <div className="text-gray-400"># Debian / Ubuntu / Mint</div>
- <div>sudo apt install xdotool</div>
- <div className="text-gray-400 mt-2"># Fedora / RHEL</div>
- <div>sudo dnf install xdotool</div>
- <div className="text-gray-400 mt-2"># Arch Linux</div>
- <div>sudo pacman -S xdotool</div>
- </>
- )}
- </div>
+ {showInstall ? (
+ <>
+ <p className="text-sm text-amber-800 mt-1">
+ For automatic text pasting, install{" "}
+ <code className="bg-amber-100 px-1 rounded font-mono">{recommendedTool}</code>:
+ </p>
+
+ <div className="mt-3 bg-gray-900 text-gray-100 p-3 rounded-md font-mono text-xs overflow-x-auto">
+ {recommendedTool === "wtype" ? (
+ <>
+ <div className="text-gray-400"># Fedora / RHEL</div>
+ <div>sudo dnf install wtype</div>
+ <div className="text-gray-400 mt-2"># Debian / Ubuntu</div>
+ <div>sudo apt install wtype</div>
+ <div className="text-gray-400 mt-2"># Arch Linux</div>
+ <div>sudo pacman -S wtype</div>
+ </>
+ ) : (
+ <>
+ <div className="text-gray-400"># Debian / Ubuntu / Mint</div>
+ <div>sudo apt install xdotool</div>
+ <div className="text-gray-400 mt-2"># Fedora / RHEL</div>
+ <div>sudo dnf install xdotool</div>
+ <div className="text-gray-400 mt-2"># Arch Linux</div>
+ <div>sudo pacman -S xdotool</div>
+ </>
+ )}
+ </div>
+
+ {isWayland && recommendedTool === "wtype" && xwaylandAvailable && (
+ <p className="text-sm text-amber-700 mt-3">
+ Note: For XWayland apps, xdotool also works.
+ </p>
+ )}
- <p className="text-sm text-amber-700 mt-3">
- Without this tool, OpenWhispr will copy text to your clipboard. You can then paste
- manually with <kbd className="bg-amber-100 px-1 rounded text-xs">Ctrl+V</kbd>.
- </p>
+ {isWayland && recommendedTool !== "wtype" && (
+ <p className="text-sm text-amber-700 mt-3">
+ Note: automatic pasting works for XWayland apps only.
+ </p>
+ )}
+ </>
+ ) : (
+ <p className="text-sm text-amber-800 mt-1">
+ Automatic pasting isn't available on this Wayland session. OpenWhispr will copy text
+ to your clipboard so you can paste manually with{" "}
+ <kbd className="bg-amber-100 px-1 rounded text-xs">Ctrl+V</kbd>.
+ </p>
+ )}
+
+ {showInstall && (
+ <p className="text-sm text-amber-700 mt-3">
+ Without this tool, OpenWhispr will copy text to your clipboard. You can then paste
+ manually with <kbd className="bg-amber-100 px-1 rounded text-xs">Ctrl+V</kbd>.
+ </p>
+ )}
</div>
</div>
diff --git a/src/helpers/clipboard.js b/src/helpers/clipboard.js
index ba6d43647..e5c5e0a92 100644
--- a/src/helpers/clipboard.js
+++ b/src/helpers/clipboard.js
@@ -7,12 +7,31 @@ const fs = require("fs");
// Cache TTL constants - these mirror CACHE_CONFIG.AVAILABILITY_CHECK_TTL in src/config/constants.ts
const CACHE_TTL_MS = 30000;
+const getLinuxDesktopEnv = () =>
+ [process.env.XDG_CURRENT_DESKTOP, process.env.XDG_SESSION_DESKTOP, process.env.DESKTOP_SESSION]
+ .filter(Boolean)
+ .join(":")
+ .toLowerCase();
+
+const isGnomeDesktop = (desktopEnv) => desktopEnv.includes("gnome");
+
+const getLinuxSessionInfo = () => {
+ const isWayland =
+ (process.env.XDG_SESSION_TYPE || "").toLowerCase() === "wayland" ||
+ !!process.env.WAYLAND_DISPLAY;
+ const xwaylandAvailable = isWayland && !!process.env.DISPLAY;
+ const desktopEnv = getLinuxDesktopEnv();
+ const isGnome = isWayland && isGnomeDesktop(desktopEnv);
+
+ return { isWayland, xwaylandAvailable, desktopEnv, isGnome };
+};
+
// Platform-specific paste delays (ms before simulating keystroke)
// Each platform has different timing requirements based on their paste mechanism
const PASTE_DELAYS = {
darwin: 50, // macOS: AppleScript keystroke is async, needs time for clipboard to settle
- win32_nircmd: 30, // Windows nircmd: give clipboard time to sync
- win32_pwsh: 40, // Windows PowerShell: give clipboard time to sync
+ win32_nircmd: 30, // Windows nircmd: give clipboard time to sync
+ win32_pwsh: 40, // Windows PowerShell: give clipboard time to sync
linux: 0, // Linux: xdotool sends X11 events directly, no delay needed
};
@@ -20,8 +39,8 @@ const PASTE_DELAYS = {
// Ensures paste is fully processed before restoring original clipboard content
const RESTORE_DELAYS = {
darwin: 100, // macOS: AppleScript needs time to complete keystroke
- win32_nircmd: 80, // Windows nircmd: allow time for paste processing
- win32_pwsh: 80, // Windows PowerShell: allow time for paste processing
+ win32_nircmd: 80, // Windows nircmd: allow time for paste processing
+ win32_pwsh: 80, // Windows PowerShell: allow time for paste processing
linux: 200, // Linux: X11 event queue processing takes longer
};
@@ -98,6 +117,32 @@ class ClipboardManager {
}
}
+ // Check if a command exists on the system (cached)
+ commandExists(cmd) {
+ const now = Date.now();
+ const cached = this.commandAvailabilityCache.get(cmd);
+ if (cached && now < cached.expiresAt) {
+ return cached.exists;
+ }
+ try {
+ const res = spawnSync("sh", ["-c", `command -v ${cmd}`], {
+ stdio: "ignore",
+ });
+ const exists = res.status === 0;
+ this.commandAvailabilityCache.set(cmd, {
+ exists,
+ expiresAt: now + CACHE_TTL_MS,
+ });
+ return exists;
+ } catch {
+ this.commandAvailabilityCache.set(cmd, {
+ exists: false,
+ expiresAt: now + CACHE_TTL_MS,
+ });
+ return false;
+ }
+ }
+
async pasteText(text) {
const startTime = Date.now();
const platform = process.platform;
@@ -386,32 +431,28 @@ class ClipboardManager {
}
async pasteLinux(originalClipboard) {
- // Helper to check if a command exists
- const commandExists = (cmd) => {
- const now = Date.now();
- const cached = this.commandAvailabilityCache.get(cmd);
- if (cached && now < cached.expiresAt) {
- return cached.exists;
+ const { isWayland, xwaylandAvailable, isGnome } = getLinuxSessionInfo();
+ const xdotoolExists = this.commandExists("xdotool");
+ const wtypeExists = this.commandExists("wtype");
+
+ const getXdotoolWindowClass = () => {
+ if (!xdotoolExists || (isWayland && !xwaylandAvailable)) {
+ return null;
}
try {
- const res = spawnSync("sh", ["-c", `command -v ${cmd}`], {
- stdio: "ignore",
- });
- const exists = res.status === 0;
- this.commandAvailabilityCache.set(cmd, {
- exists,
- expiresAt: now + CACHE_TTL_MS,
- });
- return exists;
+ const result = spawnSync("xdotool", ["getactivewindow", "getwindowclassname"]);
+ if (result.status !== 0) {
+ return null;
+ }
+ const className = result.stdout.toString().toLowerCase().trim();
+ return className || null;
} catch {
- this.commandAvailabilityCache.set(cmd, {
- exists: false,
- expiresAt: now + CACHE_TTL_MS,
- });
- return false;
+ return null;
}
};
+ const xdotoolWindowClass = getXdotoolWindowClass();
+
// Detect if the focused window is a terminal emulator
// Terminals use Ctrl+Shift+V for paste (since Ctrl+V/C are used for process control)
const isTerminal = () => {
@@ -434,22 +475,17 @@ class ClipboardManager {
"yakuake",
];
- try {
- // Try xdotool (works on X11 and XWayland)
- if (commandExists("xdotool")) {
- const result = spawnSync("xdotool", ["getactivewindow", "getwindowclassname"]);
- if (result.status === 0) {
- const className = result.stdout.toString().toLowerCase().trim();
- const isTerminalWindow = terminalClasses.some((term) => className.includes(term));
- if (isTerminalWindow) {
- this.safeLog(`🖥️ Terminal detected via xdotool: ${className}`);
- }
- return isTerminalWindow;
- }
+ if (xdotoolWindowClass) {
+ const isTerminalWindow = terminalClasses.some((term) => xdotoolWindowClass.includes(term));
+ if (isTerminalWindow) {
+ this.safeLog(`🖥️ Terminal detected via xdotool: ${xdotoolWindowClass}`);
}
+ return isTerminalWindow;
+ }
+ try {
// Try kdotool for KDE Wayland (if available)
- if (commandExists("kdotool")) {
+ if (this.commandExists("kdotool")) {
// First get the active window ID
const windowIdResult = spawnSync("kdotool", ["getactivewindow"]);
if (windowIdResult.status === 0) {
@@ -472,38 +508,29 @@ class ClipboardManager {
return false;
};
- // Detect if running on Wayland or X11
- const isWayland =
- (process.env.XDG_SESSION_TYPE || "").toLowerCase() === "wayland" ||
- !!process.env.WAYLAND_DISPLAY;
-
const inTerminal = isTerminal();
const pasteKeys = inTerminal ? "ctrl+shift+v" : "ctrl+v";
+ const canUseWtype = isWayland && !isGnome;
+ const canUseXdotool = isWayland ? !!xdotoolWindowClass : xdotoolExists;
+
// Define paste tools in preference order based on display server
- const candidates = isWayland
- ? [
- // Wayland tools
- inTerminal
- ? {
- cmd: "wtype",
- args: ["-M", "ctrl", "-M", "shift", "-k", "v", "-m", "shift", "-m", "ctrl"],
- }
- : { cmd: "wtype", args: ["-M", "ctrl", "-k", "v", "-m", "ctrl"] },
- // ydotool requires uinput permissions but included as fallback
- inTerminal
- ? { cmd: "ydotool", args: ["key", "29:1", "42:1", "47:1", "47:0", "42:0", "29:0"] }
- : { cmd: "ydotool", args: ["key", "29:1", "47:1", "47:0", "29:0"] },
- // X11 fallback for XWayland
- { cmd: "xdotool", args: ["key", pasteKeys] },
- ]
- : [
- // X11 tools
- { cmd: "xdotool", args: ["key", pasteKeys] },
- ];
-
- // Filter to only available tools (commandExists is already cached)
- const available = candidates.filter((c) => commandExists(c.cmd));
+ const candidates = [
+ ...(canUseWtype
+ ? [
+ inTerminal
+ ? {
+ cmd: "wtype",
+ args: ["-M", "ctrl", "-M", "shift", "-k", "v", "-m", "shift", "-m", "ctrl"],
+ }
+ : { cmd: "wtype", args: ["-M", "ctrl", "-k", "v", "-m", "ctrl"] },
+ ]
+ : []),
+ ...(canUseXdotool ? [{ cmd: "xdotool", args: ["key", pasteKeys] }] : []),
+ ];
+
+ // Filter to only available tools (this.commandExists is already cached)
+ const available = candidates.filter((c) => this.commandExists(c.cmd));
// Attempt paste with a specific tool
const pasteWith = (tool) =>
@@ -550,8 +577,49 @@ class ClipboardManager {
}
// All tools failed - create specific error for renderer to handle
- const sessionInfo = isWayland ? "Wayland" : "X11";
- const errorMsg = `Clipboard copied, but paste simulation failed on ${sessionInfo}. Please install ${isWayland ? "wtype or ydotool" : "xdotool"} for automatic pasting, or paste manually with Ctrl+V.`;
+ let errorMsg;
+ if (isWayland) {
+ if (isGnome) {
+ if (!xwaylandAvailable) {
+ errorMsg =
+ "Clipboard copied, but GNOME Wayland blocks automatic pasting. Please paste manually with Ctrl+V.";
+ } else if (!xdotoolExists) {
+ errorMsg =
+ "Clipboard copied, but automatic pasting on GNOME Wayland requires xdotool for XWayland apps. Please install xdotool or paste manually with Ctrl+V.";
+ } else if (!xdotoolWindowClass) {
+ errorMsg =
+ "Clipboard copied, but the active app isn't running under XWayland. Please paste manually with Ctrl+V.";
+ } else {
+ errorMsg =
+ "Clipboard copied, but paste simulation failed via XWayland. Please paste manually with Ctrl+V.";
+ }
+ } else if (!wtypeExists) {
+ if (!xwaylandAvailable) {
+ errorMsg =
+ "Clipboard copied, but automatic pasting on Wayland requires wtype. Please install wtype or paste manually with Ctrl+V.";
+ } else if (!xdotoolExists) {
+ errorMsg =
+ "Clipboard copied, but automatic pasting on Wayland requires wtype (Wayland apps) or xdotool (XWayland apps). Please install one or paste manually with Ctrl+V.";
+ } else if (!xdotoolWindowClass) {
+ errorMsg =
+ "Clipboard copied, but the active app isn't running under XWayland. Please install wtype for Wayland apps or paste manually with Ctrl+V.";
+ } else {
+ errorMsg =
+ "Clipboard copied, but paste simulation failed via XWayland. Please paste manually with Ctrl+V.";
+ }
+ } else {
+ const xwaylandNote =
+ xwaylandAvailable && xdotoolExists
+ ? " If this is an XWayland app, xdotool can also be used."
+ : "";
+ errorMsg =
+ "Clipboard copied, but paste simulation failed on Wayland. Ensure your compositor supports the virtual keyboard protocol or paste manually with Ctrl+V." +
+ xwaylandNote;
+ }
+ } else {
+ errorMsg =
+ "Clipboard copied, but paste simulation failed on X11. Please install xdotool or paste manually with Ctrl+V.";
+ }
const err = new Error(errorMsg);
err.code = "PASTE_SIMULATION_FAILED";
throw err;
@@ -751,41 +819,41 @@ Would you like to open System Settings now?`;
}
// Linux - check for available paste tools
- const isWayland =
- (process.env.XDG_SESSION_TYPE || "").toLowerCase() === "wayland" ||
- !!process.env.WAYLAND_DISPLAY;
-
- const commandExists = (cmd) => {
- try {
- const res = spawnSync("sh", ["-c", `command -v ${cmd}`], {
- stdio: "ignore",
- });
- return res.status === 0;
- } catch {
- return false;
- }
- };
+ const { isWayland, xwaylandAvailable, isGnome } = getLinuxSessionInfo();
// Check which tools are available
const tools = [];
- const toolsToCheck = isWayland
- ? ["wtype", "ydotool", "xdotool"] // xdotool as fallback for XWayland
- : ["xdotool"];
+ const canUseWtype = isWayland && !isGnome;
+ const canUseXdotool = !isWayland || xwaylandAvailable;
- for (const tool of toolsToCheck) {
- if (commandExists(tool)) {
- tools.push(tool);
+ if (canUseWtype && this.commandExists("wtype")) {
+ tools.push("wtype");
+ }
+ if (canUseXdotool && this.commandExists("xdotool")) {
+ tools.push("xdotool");
+ }
+
+ const available = tools.length > 0;
+ let recommendedInstall;
+ if (!available) {
+ if (!isWayland) {
+ recommendedInstall = "xdotool";
+ } else if (isGnome) {
+ recommendedInstall = xwaylandAvailable ? "xdotool" : undefined;
+ } else {
+ recommendedInstall = "wtype";
}
}
return {
platform: "linux",
- available: tools.length > 0,
- method: tools.length > 0 ? tools[0] : null,
+ available,
+ method: available ? tools[0] : null,
requiresPermission: false,
isWayland,
+ xwaylandAvailable,
tools,
- recommendedInstall: isWayland ? "wtype" : "xdotool",
+ recommendedInstall,
};
}
}
diff --git a/src/hooks/usePermissions.ts b/src/hooks/usePermissions.ts
index c6d7c2899..f698625da 100644
--- a/src/hooks/usePermissions.ts
+++ b/src/hooks/usePermissions.ts
@@ -256,24 +256,42 @@ export const usePermissions = (
if (result?.available) {
setAccessibilityPermissionGranted(true);
if (showAlertDialog) {
+ const method = result.method || "xdotool";
+ const methodLabel =
+ result.isWayland && method === "xdotool" ? `${method} (XWayland apps)` : method;
showAlertDialog({
title: "Ready to Go!",
- description: `Automatic pasting is available using ${result.method}. You're all set!`,
+ description: `Automatic pasting is available using ${methodLabel}. You're all set!`,
});
}
} else {
// Don't block, but inform the user
const isWayland = result?.isWayland;
- const recommendedTool = isWayland ? "wtype" : "xdotool";
- const installCmd = isWayland
- ? "sudo dnf install wtype # Fedora\nsudo apt install wtype # Debian/Ubuntu"
- : "sudo apt install xdotool # Debian/Ubuntu/Mint\nsudo dnf install xdotool # Fedora";
+ const xwaylandAvailable = result?.xwaylandAvailable;
+ const recommendedTool = result?.recommendedInstall;
+ const installCmd =
+ recommendedTool === "wtype"
+ ? "sudo dnf install wtype # Fedora\nsudo apt install wtype # Debian/Ubuntu"
+ : "sudo apt install xdotool # Debian/Ubuntu/Mint\nsudo dnf install xdotool # Fedora";
if (showAlertDialog) {
- showAlertDialog({
- title: "Optional: Install Paste Tool",
- description: `For automatic pasting, install ${recommendedTool}:\n\n${installCmd}\n\nWithout this, you can still use OpenWhispr - text will be copied to your clipboard and you can paste with Ctrl+V.`,
- });
+ if (isWayland && !xwaylandAvailable && !recommendedTool) {
+ showAlertDialog({
+ title: "Clipboard Mode on Wayland",
+ description:
+ "Automatic pasting isn't available on this Wayland session. OpenWhispr will copy text to your clipboard and you can paste with Ctrl+V.",
+ });
+ } else {
+ const waylandNote = isWayland
+ ? recommendedTool === "wtype"
+ ? "\n\nNote: For XWayland apps, xdotool also works."
+ : "\n\nNote: Automatic pasting works for XWayland apps only."
+ : "";
+ showAlertDialog({
+ title: "Optional: Install Paste Tool",
+ description: `For automatic pasting, install ${recommendedTool || "xdotool"}:\n\n${installCmd}${waylandNote}\n\nWithout this, you can still use OpenWhispr - text will be copied to your clipboard and you can paste with Ctrl+V.`,
+ });
+ }
}
// Still allow proceeding - this is optional
setAccessibilityPermissionGranted(true);
diff --git a/src/types/electron.ts b/src/types/electron.ts
index f39df893d..b14d5d9ad 100644
--- a/src/types/electron.ts
+++ b/src/types/electron.ts
@@ -98,6 +98,7 @@ export interface PasteToolsResult {
method: string | null;
requiresPermission: boolean;
isWayland?: boolean;
+ xwaylandAvailable?: boolean;
tools?: string[];
recommendedInstall?: string;
}