Fix X11 display lifecycle leaks in text injection
This commit is contained in:
parent
5f756ea04e
commit
48d7460f57
2 changed files with 94 additions and 12 deletions
|
|
@ -258,23 +258,35 @@ class X11Adapter:
|
|||
|
||||
def _paste_clipboard(self) -> None:
|
||||
dpy = display.Display()
|
||||
self._send_combo(dpy, ["Control_L", "Shift_L", "v"])
|
||||
try:
|
||||
self._send_combo(dpy, ["Control_L", "Shift_L", "v"])
|
||||
finally:
|
||||
try:
|
||||
dpy.close()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def _type_text(self, text: str) -> None:
|
||||
if not text:
|
||||
return
|
||||
dpy = display.Display()
|
||||
for ch in text:
|
||||
if ch == "\n":
|
||||
self._send_combo(dpy, ["Return"])
|
||||
continue
|
||||
keysym, needs_shift = self._keysym_for_char(ch)
|
||||
if keysym is None:
|
||||
continue
|
||||
if needs_shift:
|
||||
self._send_combo(dpy, ["Shift_L", keysym], already_keysym=True)
|
||||
else:
|
||||
self._send_combo(dpy, [keysym], already_keysym=True)
|
||||
try:
|
||||
for ch in text:
|
||||
if ch == "\n":
|
||||
self._send_combo(dpy, ["Return"])
|
||||
continue
|
||||
keysym, needs_shift = self._keysym_for_char(ch)
|
||||
if keysym is None:
|
||||
continue
|
||||
if needs_shift:
|
||||
self._send_combo(dpy, ["Shift_L", keysym], already_keysym=True)
|
||||
else:
|
||||
self._send_combo(dpy, [keysym], already_keysym=True)
|
||||
finally:
|
||||
try:
|
||||
dpy.close()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def _send_combo(self, dpy: display.Display, keys: Iterable[str | int], already_keysym: bool = False) -> None:
|
||||
keycodes: list[int] = []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue