diff options
-rw-r--r-- | kvmd/apps/kvmd/api/hid.py | 20 | ||||
-rw-r--r-- | kvmd/plugins/hid/__init__.py | 4 | ||||
-rw-r--r-- | kvmd/plugins/hid/otg/__init__.py | 6 | ||||
-rw-r--r-- | kvmd/plugins/hid/otg/keyboard.py | 15 | ||||
-rw-r--r-- | kvmd/plugins/hid/serial.py | 7 |
5 files changed, 28 insertions, 24 deletions
diff --git a/kvmd/apps/kvmd/api/hid.py b/kvmd/apps/kvmd/api/hid.py index 3580c373..b005d6ef 100644 --- a/kvmd/apps/kvmd/api/hid.py +++ b/kvmd/apps/kvmd/api/hid.py @@ -22,7 +22,6 @@ import os import stat -import asyncio import functools from typing import Dict @@ -66,8 +65,6 @@ class HidApi: self.__ensure_symmap(self.__default_keymap_name) - self.__key_lock = asyncio.Lock() - # ===== @exposed_http("GET", "/hid") @@ -102,9 +99,7 @@ class HidApi: if limit > 0: text = text[:limit] symmap = self.__ensure_symmap(request.query.get("keymap", self.__default_keymap_name)) - async with self.__key_lock: - for (key, state) in text_to_web_keys(text, symmap): - self.__hid.send_key_event(key, state) + self.__hid.send_key_events(text_to_web_keys(text, symmap)) return make_json_response() def __ensure_symmap(self, keymap_name: str) -> Dict[int, SymmapWebKey]: @@ -127,13 +122,12 @@ class HidApi: @exposed_ws("key") async def __ws_key_handler(self, _: WebSocketResponse, event: Dict) -> None: - async with self.__key_lock: - try: - key = valid_hid_key(event["key"]) - state = valid_bool(event["state"]) - except Exception: - return - self.__hid.send_key_event(key, state) + try: + key = valid_hid_key(event["key"]) + state = valid_bool(event["state"]) + except Exception: + return + self.__hid.send_key_events([(key, state)]) @exposed_ws("mouse_button") async def __ws_mouse_button_handler(self, _: WebSocketResponse, event: Dict) -> None: diff --git a/kvmd/plugins/hid/__init__.py b/kvmd/plugins/hid/__init__.py index 5227d673..8f4cb02c 100644 --- a/kvmd/plugins/hid/__init__.py +++ b/kvmd/plugins/hid/__init__.py @@ -20,7 +20,9 @@ # ========================================================================== # +from typing import Tuple from typing import Dict +from typing import Iterable from typing import AsyncGenerator from typing import Type @@ -48,7 +50,7 @@ class BaseHid(BasePlugin): # ===== - def send_key_event(self, key: str, state: bool) -> None: + def send_key_events(self, keys: Iterable[Tuple[str, bool]]) -> None: raise NotImplementedError def send_mouse_button_event(self, button: str, state: bool) -> None: diff --git a/kvmd/plugins/hid/otg/__init__.py b/kvmd/plugins/hid/otg/__init__.py index 3dc49c72..95566d34 100644 --- a/kvmd/plugins/hid/otg/__init__.py +++ b/kvmd/plugins/hid/otg/__init__.py @@ -20,7 +20,9 @@ # ========================================================================== # +from typing import Tuple from typing import Dict +from typing import Iterable from typing import AsyncGenerator from typing import Any @@ -113,8 +115,8 @@ class Plugin(BaseHid): # ===== - def send_key_event(self, key: str, state: bool) -> None: - self.__keyboard_proc.send_key_event(key, state) + def send_key_events(self, keys: Iterable[Tuple[str, bool]]) -> None: + self.__keyboard_proc.send_key_events(keys) def send_mouse_button_event(self, button: str, state: bool) -> None: self.__mouse_proc.send_button_event(button, state) diff --git a/kvmd/plugins/hid/otg/keyboard.py b/kvmd/plugins/hid/otg/keyboard.py index 63c15889..e0243798 100644 --- a/kvmd/plugins/hid/otg/keyboard.py +++ b/kvmd/plugins/hid/otg/keyboard.py @@ -22,8 +22,10 @@ import dataclasses +from typing import Tuple from typing import List from typing import Set +from typing import Iterable from typing import Optional from typing import Any @@ -89,12 +91,13 @@ class KeyboardProcess(BaseDeviceProcess): self._clear_queue() self._queue_event(_ResetEvent()) - def send_key_event(self, key: str, state: bool) -> None: - otg_key = KEYMAP[key].otg - if otg_key.is_modifier: - self._queue_event(_ModifierEvent(otg_key, state)) - else: - self._queue_event(_KeyEvent(otg_key, state)) + def send_key_events(self, keys: Iterable[Tuple[str, bool]]) -> None: + for (key, state) in keys: + otg_key = KEYMAP[key].otg + if otg_key.is_modifier: + self._queue_event(_ModifierEvent(otg_key, state)) + else: + self._queue_event(_KeyEvent(otg_key, state)) # ===== diff --git a/kvmd/plugins/hid/serial.py b/kvmd/plugins/hid/serial.py index c9705543..e9b65479 100644 --- a/kvmd/plugins/hid/serial.py +++ b/kvmd/plugins/hid/serial.py @@ -30,8 +30,10 @@ import struct import errno import time +from typing import Tuple from typing import List from typing import Dict +from typing import Iterable from typing import AsyncGenerator import serial @@ -273,8 +275,9 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst # ===== - def send_key_event(self, key: str, state: bool) -> None: - self.__queue_event(_KeyEvent(key, state)) + def send_key_events(self, keys: Iterable[Tuple[str, bool]]) -> None: + for (key, state) in keys: + self.__queue_event(_KeyEvent(key, state)) def send_mouse_button_event(self, button: str, state: bool) -> None: self.__queue_event(_MouseButtonEvent(button, state)) |