diff options
Diffstat (limited to 'kvmd/apps')
-rw-r--r-- | kvmd/apps/__init__.py | 16 | ||||
-rw-r--r-- | kvmd/apps/kvmd/__init__.py | 5 | ||||
-rw-r--r-- | kvmd/apps/kvmd/api/hid.py | 84 | ||||
-rw-r--r-- | kvmd/apps/kvmd/server.py | 5 |
4 files changed, 23 insertions, 87 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py index dd1b8ff9..9d6d494a 100644 --- a/kvmd/apps/__init__.py +++ b/kvmd/apps/__init__.py @@ -33,8 +33,6 @@ import pygments.formatters from .. import tools -from ..mouse import MouseRange - from ..plugins import UnknownPluginError from ..plugins.auth import get_auth_service_class from ..plugins.hid import get_hid_class @@ -407,19 +405,7 @@ def _get_config_scheme() -> dict: "hid": { "type": Option("", type=valid_stripped_string_not_empty), - - "keymap": Option("/usr/share/kvmd/keymaps/en-us", type=valid_abs_file), - "ignore_keys": Option([], type=functools.partial(valid_string_list, subval=valid_hid_key)), - - "mouse_x_range": { - "min": Option(MouseRange.MIN, type=valid_hid_mouse_move), - "max": Option(MouseRange.MAX, type=valid_hid_mouse_move), - }, - "mouse_y_range": { - "min": Option(MouseRange.MIN, type=valid_hid_mouse_move), - "max": Option(MouseRange.MAX, type=valid_hid_mouse_move), - }, - + "keymap": Option("/usr/share/kvmd/keymaps/en-us", type=valid_abs_file), # Dynamic content }, diff --git a/kvmd/apps/kvmd/__init__.py b/kvmd/apps/kvmd/__init__.py index 7cf8430c..495a320f 100644 --- a/kvmd/apps/kvmd/__init__.py +++ b/kvmd/apps/kvmd/__init__.py @@ -56,7 +56,7 @@ def main(argv: (list[str] | None)=None) -> None: if config.kvmd.msd.type == "otg": msd_kwargs["gadget"] = config.otg.gadget # XXX: Small crutch to pass gadget name to the plugin - hid_kwargs = config.kvmd.hid._unpack(ignore=["type", "keymap", "ignore_keys", "mouse_x_range", "mouse_y_range"]) + hid_kwargs = config.kvmd.hid._unpack(ignore=["type", "keymap"]) if config.kvmd.hid.type == "otg": hid_kwargs["udc"] = config.otg.udc # XXX: Small crutch to pass UDC to the plugin @@ -103,9 +103,6 @@ def main(argv: (list[str] | None)=None) -> None: ), keymap_path=config.hid.keymap, - ignore_keys=config.hid.ignore_keys, - mouse_x_range=(config.hid.mouse_x_range.min, config.hid.mouse_x_range.max), - mouse_y_range=(config.hid.mouse_y_range.min, config.hid.mouse_y_range.max), stream_forever=config.streamer.forever, ).run(**config.server._unpack()) diff --git a/kvmd/apps/kvmd/api/hid.py b/kvmd/apps/kvmd/api/hid.py index 107fc858..51b9dc00 100644 --- a/kvmd/apps/kvmd/api/hid.py +++ b/kvmd/apps/kvmd/api/hid.py @@ -25,13 +25,12 @@ import stat import functools import struct +from typing import Iterable from typing import Callable from aiohttp.web import Request from aiohttp.web import Response -from ....mouse import MouseRange - from ....keyboard.keysym import build_symmap from ....keyboard.printer import text_to_web_keys @@ -59,12 +58,7 @@ class HidApi: def __init__( self, hid: BaseHid, - keymap_path: str, - ignore_keys: list[str], - - mouse_x_range: tuple[int, int], - mouse_y_range: tuple[int, int], ) -> None: self.__hid = hid @@ -73,11 +67,6 @@ class HidApi: self.__default_keymap_name = os.path.basename(keymap_path) self.__ensure_symmap(self.__default_keymap_name) - self.__ignore_keys = ignore_keys - - self.__mouse_x_range = mouse_x_range - self.__mouse_y_range = mouse_y_range - # ===== @exposed_http("GET", "/hid") @@ -134,7 +123,7 @@ class HidApi: if limit > 0: text = text[:limit] symmap = self.__ensure_symmap(req.query.get("keymap", self.__default_keymap_name)) - self.__hid.send_key_events(text_to_web_keys(text, symmap)) + self.__hid.send_key_events(text_to_web_keys(text, symmap), no_ignore_keys=True) return make_json_response() def __ensure_symmap(self, keymap_name: str) -> dict[int, dict[int, str]]: @@ -162,8 +151,7 @@ class HidApi: state = valid_bool(data[0]) except Exception: return - if key not in self.__ignore_keys: - self.__hid.send_key_events([(key, state)]) + self.__hid.send_key_event(key, state) @exposed_ws(2) async def __ws_bin_mouse_button_handler(self, _: WsSession, data: bytes) -> None: @@ -182,17 +170,17 @@ class HidApi: to_y = valid_hid_mouse_move(to_y) except Exception: return - self.__send_mouse_move_event(to_x, to_y) + self.__hid.send_mouse_move_event(to_x, to_y) @exposed_ws(4) async def __ws_bin_mouse_relative_handler(self, _: WsSession, data: bytes) -> None: - self.__process_ws_bin_delta_request(data, self.__hid.send_mouse_relative_event) + self.__process_ws_bin_delta_request(data, self.__hid.send_mouse_relative_events) @exposed_ws(5) async def __ws_bin_mouse_wheel_handler(self, _: WsSession, data: bytes) -> None: - self.__process_ws_bin_delta_request(data, self.__hid.send_mouse_wheel_event) + self.__process_ws_bin_delta_request(data, self.__hid.send_mouse_wheel_events) - def __process_ws_bin_delta_request(self, data: bytes, handler: Callable[[int, int], None]) -> None: + def __process_ws_bin_delta_request(self, data: bytes, handler: Callable[[Iterable[tuple[int, int]], bool], None]) -> None: try: squash = valid_bool(data[0]) data = data[1:] @@ -202,7 +190,7 @@ class HidApi: deltas.append((valid_hid_mouse_delta(delta_x), valid_hid_mouse_delta(delta_y))) except Exception: return - self.__send_mouse_delta_event(deltas, squash, handler) + handler(deltas, squash) # ===== @@ -213,8 +201,7 @@ class HidApi: state = valid_bool(event["state"]) except Exception: return - if key not in self.__ignore_keys: - self.__hid.send_key_events([(key, state)]) + self.__hid.send_key_event(key, state) @exposed_ws("mouse_button") async def __ws_mouse_button_handler(self, _: WsSession, event: dict) -> None: @@ -232,17 +219,17 @@ class HidApi: to_y = valid_hid_mouse_move(event["to"]["y"]) except Exception: return - self.__send_mouse_move_event(to_x, to_y) + self.__hid.send_mouse_move_event(to_x, to_y) @exposed_ws("mouse_relative") async def __ws_mouse_relative_handler(self, _: WsSession, event: dict) -> None: - self.__process_ws_delta_event(event, self.__hid.send_mouse_relative_event) + self.__process_ws_delta_event(event, self.__hid.send_mouse_relative_events) @exposed_ws("mouse_wheel") async def __ws_mouse_wheel_handler(self, _: WsSession, event: dict) -> None: - self.__process_ws_delta_event(event, self.__hid.send_mouse_wheel_event) + self.__process_ws_delta_event(event, self.__hid.send_mouse_wheel_events) - def __process_ws_delta_event(self, event: dict, handler: Callable[[int, int], None]) -> None: + def __process_ws_delta_event(self, event: dict, handler: Callable[[Iterable[tuple[int, int]], bool], None]) -> None: try: raw_delta = event["delta"] deltas = [ @@ -252,19 +239,18 @@ class HidApi: squash = valid_bool(event.get("squash", False)) except Exception: return - self.__send_mouse_delta_event(deltas, squash, handler) + handler(deltas, squash) # ===== @exposed_http("POST", "/hid/events/send_key") async def __events_send_key_handler(self, req: Request) -> Response: key = valid_hid_key(req.query.get("key")) - if key not in self.__ignore_keys: - if "state" in req.query: - state = valid_bool(req.query["state"]) - self.__hid.send_key_events([(key, state)]) - else: - self.__hid.send_key_events([(key, True), (key, False)]) + if "state" in req.query: + state = valid_bool(req.query["state"]) + self.__hid.send_key_event(key, state) + else: + self.__hid.send_key_events([(key, True), (key, False)]) return make_json_response() @exposed_http("POST", "/hid/events/send_mouse_button") @@ -282,7 +268,7 @@ class HidApi: async def __events_send_mouse_move_handler(self, req: Request) -> Response: to_x = valid_hid_mouse_move(req.query.get("to_x")) to_y = valid_hid_mouse_move(req.query.get("to_y")) - self.__send_mouse_move_event(to_x, to_y) + self.__hid.send_mouse_move_event(to_x, to_y) return make_json_response() @exposed_http("POST", "/hid/events/send_mouse_relative") @@ -298,33 +284,3 @@ class HidApi: delta_y = valid_hid_mouse_delta(req.query.get("delta_y")) handler(delta_x, delta_y) return make_json_response() - - # ===== - - def __send_mouse_move_event(self, to_x: int, to_y: int) -> None: - if self.__mouse_x_range != MouseRange.RANGE: - to_x = MouseRange.remap(to_x, *self.__mouse_x_range) - if self.__mouse_y_range != MouseRange.RANGE: - to_y = MouseRange.remap(to_y, *self.__mouse_y_range) - self.__hid.send_mouse_move_event(to_x, to_y) - - def __send_mouse_delta_event( - self, - deltas: list[tuple[int, int]], - squash: bool, - handler: Callable[[int, int], None], - ) -> None: - - if squash: - prev = (0, 0) - for cur in deltas: - if abs(prev[0] + cur[0]) > 127 or abs(prev[1] + cur[1]) > 127: - handler(*prev) - prev = cur - else: - prev = (prev[0] + cur[0], prev[1] + cur[1]) - if prev[0] or prev[1]: - handler(*prev) - else: - for xy in deltas: - handler(*xy) diff --git a/kvmd/apps/kvmd/server.py b/kvmd/apps/kvmd/server.py index d9e07484..74f74f26 100644 --- a/kvmd/apps/kvmd/server.py +++ b/kvmd/apps/kvmd/server.py @@ -173,9 +173,6 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins snapshoter: Snapshoter, keymap_path: str, - ignore_keys: list[str], - mouse_x_range: tuple[int, int], - mouse_y_range: tuple[int, int], stream_forever: bool, ) -> None: @@ -189,7 +186,7 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins self.__stream_forever = stream_forever - self.__hid_api = HidApi(hid, keymap_path, ignore_keys, mouse_x_range, mouse_y_range) # Ugly hack to get keymaps state + self.__hid_api = HidApi(hid, keymap_path) # Ugly hack to get keymaps state self.__apis: list[object] = [ self, AuthApi(auth_manager), |