Doubao-powered voice input for Linux, Wayland and Omarchy
fix(x11): probe optional desktop helpers
quanru8057eb1257fc
diff --git a/README.md b/README.mdindex 9a653f5..66a8aa3 100644--- a/README.md+++ b/README.md@@ -91,14 +91,16 @@ diagnostics. Use **Test endpoint** before enabling.| Desktop session | Automatic clipboard paste | Direct typing || --- | --- | --- || Hyprland / Wayland | `wl-copy`; known, unchanged window required | Optional `wtype` |-| Native X11 | `xclip` and `xdotool`; known, unchanged window/PID required | Unavailable; choose Clipboard paste |+| Native X11 | Optional `xclip` and `xdotool`; known, unchanged window/PID required | Unavailable; choose Clipboard paste || Other Wayland compositors | Retain the result for manual copying when focus cannot be verified | No supported automatic path |Native X11 uses Ctrl+V, or Ctrl+Shift+V for recognized terminal classes. Itsfloating overlay does not request activation; the window manager chooses itsposition. Hyprland keeps its bottom-anchored layer-shell overlay. PipeWiremicrophone selection works through `pw-record` on both desktops.-XWayland is not treated as a native X11 session.+XWayland is not treated as a native X11 session. The X11 helpers are probed at+runtime; without either one, recognition still works and the result is retained+for manual copying.### Text input methoddiff --git a/README.zh-CN.md b/README.zh-CN.mdindex eb2c737..5e3490b 100644--- a/README.zh-CN.md+++ b/README.zh-CN.md@@ -69,12 +69,13 @@ API Key 通过仅限当前用户读取的独立文件保存,不进入诊断信| 桌面会话 | 自动剪贴板粘贴 | 直接输入 || --- | --- | --- || Hyprland / Wayland | 使用 `wl-copy`,要求目标窗口已知且未变化 | 可选 `wtype` |-| 原生 X11 | 使用 `xclip` 和 `xdotool`,要求目标窗口及 PID 已知且未变化 | 不支持,请选择剪贴板粘贴 |+| 原生 X11 | 可选使用 `xclip` 和 `xdotool`,要求目标窗口及 PID 已知且未变化 | 不支持,请选择剪贴板粘贴 || 其他 Wayland 桌面 | 无法确认焦点时保留结果供手动复制 | 暂无支持的自动输入路径 |原生 X11 使用 Ctrl+V;识别到终端窗口时使用 Ctrl+Shift+V。悬浮窗不主动请求焦点,位置由窗口管理器决定。Hyprland 保留底部 layer-shell 悬浮窗。两个桌面都通过 `pw-record` 使用所选 PipeWire 麦克风。XWayland 不会被当作原生 X11 会话。+程序会在运行时探测 X11 辅助工具;缺少任一工具都不影响安装和识别,结果会保留供手动复制。### 文字输入方式diff --git a/debian/control b/debian/controlindex b67dd3f..b023f64 100644--- a/debian/control+++ b/debian/control@@ -17,13 +17,15 @@ Depends:gir1.2-webkit-6.0,libgtk-4-1,libwebkitgtk-6.0-4,- wl-clipboard,+ wl-clipboardRecommends:python3-pip,- python3-venv,+ python3-venvSuggests:python3-numpy,-Description: Doubao Say voice input for Linux/Wayland+ xclip,+ xdotool+Description: Doubao Say voice input for Linux desktopsTap or hold a configurable trigger, speak, and paste recognised textinto the focused input field. Backed by Doubao's streaming ASR..diff --git a/install.sh b/install.shindex ccb8618..0f07cf0 100755--- a/install.sh+++ b/install.sh@@ -65,9 +65,7 @@ fipackages=(python python-gobject python-cairo gtk4 webkitgtk-6.0 pipewire portaudio)# Match desktop.is_x11(); Python itself may not be installed at this stage.-if [[ -n ${DISPLAY:-} && -z ${WAYLAND_DISPLAY:-} && ${XDG_SESSION_TYPE:-} != wayland && -z ${HYPRLAND_INSTANCE_SIGNATURE:-} ]]; then- packages+=(xdotool xclip)-else+if [[ -z ${DISPLAY:-} || -n ${WAYLAND_DISPLAY:-} || ${XDG_SESSION_TYPE:-} == wayland || -n ${HYPRLAND_INSTANCE_SIGNATURE:-} ]]; thenpackages+=(gtk4-layer-shell wl-clipboard)fiif ! $BUNDLE; thendiff --git a/packaging/DEPENDENCIES.md b/packaging/DEPENDENCIES.mdindex 7b3d207..5c91ab2 100644--- a/packaging/DEPENDENCIES.md+++ b/packaging/DEPENDENCIES.md@@ -14,8 +14,10 @@ all source files or transitive system-library obligations.Wheels are distributed intact, including these notices. GTK, WebKit, PipeWire,PortAudio, Cairo and system PyGObject are installed by the OS and not bundled.-Keep their dependency requirements documented. Ruff is development-only, not-part of end-user archives. Rebuild this inventory when dependency pins change.+The optional X11 helpers `xdotool` and `xclip` are also not bundled; they are+probed at runtime and are not required for installation or Wayland. Ruff is+development-only, not part of end-user archives. Rebuild this inventory when+dependency pins change.Before public release: verify exact upstream code revisions and author notices,review full license texts and bundled-wheel contents, and record any additionaldiff --git a/packaging/INSTALL.md b/packaging/INSTALL.mdindex 3a204f7..c411ec3 100644--- a/packaging/INSTALL.md+++ b/packaging/INSTALL.md@@ -13,10 +13,10 @@ This bundle includes Python dependency wheels for the Python/CPU version in itsfilename (for example cpython-314 and x86_64). System libraries are not bundled.The recommended `./install.sh` detects missing Arch/Omarchy packages, shows theexact list and asks before installing them. Use `./install.sh --yes` only after-reviewing that list. Run it in the intended desktop session: native X11 selects-`xdotool` and `xclip`; Wayland selects `gtk4-layer-shell` and `wl-clipboard`.-The source installer, archive installer and runtime checks use the same desktop-requirements. XWayland's `DISPLAY` does not select native X11.+reviewing that list. Run it in the intended desktop session: Wayland selects+`gtk4-layer-shell` and `wl-clipboard`; native X11 uses GTK's built-in backend.+The source installer, archive installer and runtime checks use the same required+desktop dependencies. XWayland's `DISPLAY` does not select native X11.The equivalent manual command for Hyprland/Omarchy is:@@ -27,11 +27,15 @@ omarchy pkg add python python-gobject python-cairo gtk4 gtk4-layer-shell webkitgFor a native X11 session on Arch:```sh-sudo pacman -S --needed python python-gobject python-cairo gtk4 webkitgtk-6.0 pipewire portaudio xdotool xclip+sudo pacman -S --needed python python-gobject python-cairo gtk4 webkitgtk-6.0 pipewire portaudio```X11 requires GTK's GdkX11 backend, but neither layer-shell nor wl-clipboard.PipeWire is used on X11 and Wayland so microphone node selection matches capture.+Automatic paste on native X11 additionally uses the optional `xdotool` and+`xclip` helpers. They are probed at runtime and can be installed on Arch with+`sudo pacman -S --needed xdotool xclip`. If either is unavailable, installation+and startup still succeed and recognized text is retained for manual copying.CopyQ is not required. Ordinary clipboard paste replaces clipboard contents andmay be stored by a clipboard manager. Direct typing through optional `wtype`remains a Hyprland/Wayland feature; choose Clipboard paste on native X11.diff --git a/src/doubao_input/preflight.py b/src/doubao_input/preflight.pyindex 5707533..4e98a2b 100644--- a/src/doubao_input/preflight.py+++ b/src/doubao_input/preflight.py@@ -34,16 +34,30 @@ def check_system():results[namespace] = Trueexcept (ImportError, OSError, ValueError):results[namespace] = False- clipboard_tools = ("xdotool", "xclip") if is_x11() else ("wl-copy",)+ clipboard_tools = () if is_x11() else ("wl-copy",)for command in ("pw-record", "pw-dump", *clipboard_tools):results[command] = shutil.which(command) is not Nonereturn results+def check_optional_tools():+ """Report helpers that unlock optional desktop capabilities."""+ if not is_x11():+ return {}+ return {command: shutil.which(command) is not None+ for command in ("xdotool", "xclip")}++def main():results = check_runtime()+ optional = check_optional_tools()for name, passed in results.items():print(f"{'OK' if passed else 'MISSING'}: {name}")+ for name, passed in optional.items():+ print(f"{'OK' if passed else 'OPTIONAL MISSING'}: {name}")+ if optional and not all(optional.values()):+ print("INFO: native X11 automatic paste needs optional xdotool and xclip; "+ "recognized text is retained when they are unavailable")print("INFO: keyboard access " + ("available" if any(os.access(p, os.R_OK) for p in Path("/dev/input").glob("event*")) else "not available"))print("INFO: virtual keyboard access " + ("available" if os.access("/dev/uinput", os.W_OK) else "not available"))diff --git a/tests/test_desktop.py b/tests/test_desktop.pyindex 0967708..96c78dc 100644--- a/tests/test_desktop.py+++ b/tests/test_desktop.py@@ -52,15 +52,23 @@ class DesktopTest(TestCase):self.assertIn("GdkX11" if x11 else "Gtk4LayerShell", results)self.assertNotIn("Gtk4LayerShell" if x11 else "GdkX11", results)self.assertNotIn("copyq", results)+ optional = preflight.check_optional_tools()+ self.assertEqual(set(optional), {"xdotool", "xclip"} if x11 else set())+ self.assertTrue(all(optional.values()))self.assertNotIn("evdev", results)self.assertIn("evdev", preflight.check_runtime())- def test_missing_x11_tool_is_reported(self):+ def test_missing_x11_tool_is_optional_and_reported(self):with patch.dict(os.environ, SESSIONS[0][0], clear=True), \patch("gi.require_version"), \patch.object(preflight.importlib, "import_module"), \patch.object(preflight.shutil, "which", side_effect=lambda tool: None if tool == "xdotool" else tool):- self.assertFalse(preflight.check_system()["xdotool"])+ self.assertNotIn("xdotool", preflight.check_system())+ self.assertFalse(preflight.check_optional_tools()["xdotool"])+ with patch.object(preflight, "check_runtime", return_value={"required": True}), \+ patch.object(preflight, "check_optional_tools",+ return_value={"xdotool": False, "xclip": True}):+ self.assertEqual(preflight.main(), 0)@skipIf(os.geteuid() == 0, "The installer refuses root before checking dependencies")def test_installer_package_selection_matches_python_session_detection(self):@@ -79,7 +87,7 @@ class DesktopTest(TestCase):missing = next(line for line in result.stdout.splitlines()if line.startswith("Missing system packages:")).split()[3:]for package in ("xdotool", "xclip"):- self.assertEqual(package in missing, x11)+ self.assertNotIn(package, missing)for package in ("wl-clipboard", "gtk4-layer-shell"):self.assertEqual(package in missing, not x11)self.assertNotIn("copyq", missing)