Migrate to Python daemon

This commit is contained in:
Thales Maciel 2026-02-07 15:12:17 -03:00
parent 49ef349d48
commit d81f3dbffe
42 changed files with 660 additions and 1816 deletions

50
src/inject.py Normal file
View file

@ -0,0 +1,50 @@
import subprocess
import sys
def write_clipboard(text: str) -> None:
proc = subprocess.run(
["xclip", "-selection", "clipboard", "-in", "-quiet", "-loops", "1"],
input=text,
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
if proc.returncode != 0:
raise RuntimeError(proc.stderr.strip() or "xclip failed")
def paste_clipboard() -> None:
proc = subprocess.run(
["xdotool", "key", "--clearmodifiers", "ctrl+v"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
)
if proc.returncode != 0:
raise RuntimeError(proc.stderr.strip() or "xdotool paste failed")
def type_text(text: str) -> None:
if not text:
return
proc = subprocess.run(
["xdotool", "type", "--clearmodifiers", "--delay", "1", text],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
)
if proc.returncode != 0:
raise RuntimeError(proc.stderr.strip() or "xdotool type failed")
def inject(text: str, backend: str) -> None:
backend = (backend or "").strip().lower()
if backend in ("", "clipboard"):
write_clipboard(text)
paste_clipboard()
return
if backend == "injection":
type_text(text)
return
raise ValueError(f"unknown injection backend: {backend}")