fix(typer): use ClipboardManager instead of pyperclip for clipboard paste - #37
fix(typer): use ClipboardManager instead of pyperclip for clipboard paste#37nicktoper wants to merge 1 commit into
Conversation
_paste() called pyperclip.copy() directly, bypassing VOXD's own ClipboardManager. When PyGObject is installed, pyperclip selects its `gi`/GTK backend, which requires a running GTK main loop to own the clipboard selection. VOXD has no such loop, so the copy silently evaporates and the subsequent Ctrl+Shift+V pastes nothing. ClipboardManager already resolves the correct backend (wl-copy on Wayland, xclip/xsel on X11) and owns the selection properly. This makes the clipboard paste path a working alternative to keycode-based typing, which is significant for non-QWERTY layouts (AZERTY, QWERTZ, Colemak, pt-br, Swedish), where ydotool's keycode injection produces scrambled text - see jakovius#19. Verified on Pop!_OS 24.04 / COSMIC / Wayland: before the change wl-paste reported "Nothing is copied" after a transcription; after it, the transcript including accented characters (éàçùô) is on the clipboard and pastes correctly. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 583e9ccbf7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # no such loop, so the copy silently evaporates and the paste shortcut | ||
| # fires against an empty clipboard. ClipboardManager picks wl-copy on | ||
| # Wayland (xclip/xsel on X11), which owns the selection correctly. | ||
| ClipboardManager().copy(t) |
There was a problem hiding this comment.
Restore fallback when ClipboardManager cannot copy
When paste mode is used in an environment where the selected clipboard backend cannot actually copy (for example no wl-copy/xclip/xsel so ClipboardManager falls back to pyperclip and pyperclip raises, or xclip/wl-copy exits non-zero), ClipboardManager.copy() logs and returns instead of raising, so this try still proceeds to send the paste shortcut and can paste stale clipboard contents or nothing. The previous direct pyperclip.copy() path would enter the existing _type_char_by_char fallback on copy failure; this call needs equivalent failure signaling before triggering Ctrl+V/Ctrl+Shift+V.
Useful? React with 👍 / 👎.
Problem
SimulatedTyper._paste()callspyperclip.copy()directly, bypassing VOXD's ownClipboardManager.When PyGObject is installed, pyperclip selects its
gi/GTK backend:That backend needs a running GTK main loop to own the clipboard selection. VOXD has no such loop, so the copy silently evaporates — the clipboard ends up owned by nobody, and the
Ctrl+Shift+Vsent immediately afterwards pastes nothing.Reproduced on Pop!_OS 24.04 / COSMIC / Wayland, VOXD 1.7.0, with
typing_delay: 0(which routes through_paste()):The transcript itself was fine — it was written correctly to
output/last_recording.txt. Only the clipboard hop failed.Why it matters beyond Wayland
The clipboard path is the natural workaround for #19 (keyboard layout issue), where
ydotool's keycode injection produces scrambled text on non-QWERTY layouts — AZERTY, QWERTZ, Colemak, pt-br and Swedish are all reported there. One commenter on that issue notes the clipboard route "doesn't work" for them either, which this bug would explain: the workaround silently fails wherever pyperclip picks thegibackend.I hit this myself on AZERTY: keycode typing scrambled the text, so I switched to paste mode and got nothing at all.
Fix
Route
_paste()throughClipboardManager, which already resolves the correct backend (wl-copyon Wayland,xclip/xselon X11) and owns the selection properly. The class already existed and was already used elsewhere in the codebase — this just stops_paste()from going around it.The now-unused
import pyperclipis dropped fromtyper.py.clipboard.pystill imports it for its ownpyperclipfallback backend, so nothing else changes.Verification
Before, after a transcription:
After:
Accented characters survive the round-trip, and paste-into-window works in both terminal and GUI apps. Also confirmed
ClipboardManager()resolves towl-copyon this system, and thattyper.pyimports cleanly with no circular-import issue (clipboard.pyonly pulls invoxd.utils.libw).I could only test on Wayland/COSMIC — an X11 check would be worth having, though that path goes through
xclip/xsel, whichClipboardManagerhas handled all along.