Skip to content

fix(linux): prefer ydotool over xdotool on GNOME Wayland#202

Open
wrt54gl wants to merge 2 commits intoOpenWhispr:mainfrom
wrt54gl:fix/gnome-wayland-paste
Open

fix(linux): prefer ydotool over xdotool on GNOME Wayland#202
wrt54gl wants to merge 2 commits intoOpenWhispr:mainfrom
wrt54gl:fix/gnome-wayland-paste

Conversation

@wrt54gl
Copy link

@wrt54gl wrt54gl commented Feb 6, 2026

Summary

  • On GNOME Wayland, reorder paste tool candidates to try ydotool before xdotool
  • Use AT-SPI2 accessibility API for terminal detection on GNOME Wayland, since xdotool always returns OpenWhispr's own window
  • Send Ctrl+Shift+V for detected terminals, Ctrl+V for everything else

Problem

On GNOME Wayland, xdotool can only interact with XWayland windows. When OpenWhispr (an Electron/XWayland app) attempts to paste into a native Wayland window (e.g. gnome-terminal, GNOME Text Editor), xdotool targets OpenWhispr's own XWayland window instead, silently reports success (exit code 0), and prevents fallback to ydotool.

Additionally, terminal detection via xdotool getwindowclassname fails on GNOME Wayland because xdotool always returns OpenWhispr's own window class — not the actual focused window. This causes the wrong paste shortcut to be sent.

Solution

1. Prefer ydotool on GNOME Wayland

On GNOME Wayland (isGnome && isWayland), ydotool is now tried before xdotool in the candidates array. ydotool works at the kernel input level and sends keystrokes to whatever window has compositor focus, regardless of whether it's a native Wayland or XWayland window.

2. AT-SPI2 terminal detection

Since xdotool can't reliably detect the focused window on GNOME Wayland, terminal detection now uses the AT-SPI2 accessibility API via a lightweight Python script (~88ms). AT-SPI2 can see both native Wayland and XWayland windows and correctly identifies the active application (e.g. org.gnome.Terminal).

The detection flow on GNOME Wayland:

  1. Query AT-SPI2 for the active application name (excluding gnome-shell)
  2. Match against known terminal class names
  3. If terminal → ydotool sends Ctrl+Shift+V; otherwise → ydotool sends Ctrl+V

Falls back to xdotool/kdotool detection if AT-SPI2 is unavailable.

3. Correct paste shortcuts

  • Terminals: Ctrl+Shift+V (the standard terminal paste shortcut)
  • Other apps (GNOME Text Editor, Chrome, etc.): Ctrl+V

Dependencies

  • python3 with gi (PyGObject) and AT-SPI2 bindings — standard on GNOME desktop installations
  • ydotool + ydotoold daemon for keystroke injection

Test plan

  • Test paste into gnome-terminal on GNOME Wayland
  • Test paste into GNOME Text Editor (native Wayland GTK4 app) on GNOME Wayland
  • Test paste into Chrome on GNOME Wayland
  • Verify no regression on X11 sessions (xdotool still preferred)
  • Verify no regression on non-GNOME Wayland (e.g. KDE, wtype still preferred)
  • Verify graceful fallback when python3/AT-SPI2 is unavailable

Tested on Debian 13 (trixie) with GNOME Shell 48.7, NVIDIA RTX A400 (driver 550.x), Wayland session.

🤖 Generated with Claude Code

Wendel Toews and others added 2 commits February 6, 2026 17:29
On GNOME Wayland, xdotool can only interact with XWayland windows.
When OpenWhispr (an Electron/XWayland app) tries to paste, xdotool
targets OpenWhispr's own window instead of the focused native Wayland
window, silently reports success, and prevents fallback to ydotool.

This commit reorders the paste tool candidates on GNOME Wayland to
try ydotool first. It also uses Ctrl+Shift+V with ydotool since
terminal detection via xdotool/kdotool fails for native Wayland
windows. Ctrl+Shift+V works correctly in both terminals (paste) and
other apps (paste without formatting).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
On GNOME Wayland, xdotool always returns OpenWhispr's own XWayland
window instead of the actual focused window, making terminal detection
fail. This caused ydotool to always send Ctrl+Shift+V (which doesn't
work in apps like GNOME Text Editor) or always Ctrl+V (which doesn't
work in terminals).

Use the AT-SPI2 accessibility API to detect the active application,
which works for both native Wayland and XWayland windows. This lets
ydotool send the correct keystroke: Ctrl+Shift+V for terminals,
Ctrl+V for everything else.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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