diff options
author | Devaev Maxim <[email protected]> | 2021-05-06 19:38:49 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2021-05-06 19:38:49 +0300 |
commit | 3aa92a87d4df60d7a0fcc09bf3091e2110a48458 (patch) | |
tree | c76f96b9ca917dbebb0e76601f81c27ba84c164b | |
parent | e35aa1199b0a8756a43ec77c64058bd5ebf0d934 (diff) |
option to ignore some keys
-rw-r--r-- | kvmd/apps/__init__.py | 2 | ||||
-rw-r--r-- | kvmd/apps/kvmd/__init__.py | 3 | ||||
-rw-r--r-- | kvmd/apps/kvmd/api/hid.py | 18 | ||||
-rw-r--r-- | kvmd/apps/kvmd/server.py | 3 |
4 files changed, 17 insertions, 9 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py index 1e54dfa3..30992f33 100644 --- a/kvmd/apps/__init__.py +++ b/kvmd/apps/__init__.py @@ -370,12 +370,12 @@ def _get_config_scheme() -> Dict: "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), diff --git a/kvmd/apps/kvmd/__init__.py b/kvmd/apps/kvmd/__init__.py index 7b2b5e6e..ae4f51a3 100644 --- a/kvmd/apps/kvmd/__init__.py +++ b/kvmd/apps/kvmd/__init__.py @@ -59,7 +59,7 @@ def main(argv: Optional[List[str]]=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", "mouse_x_range", "mouse_y_range"]) + hid_kwargs = config.kvmd.hid._unpack(ignore=["type", "keymap", "ignore_keys", "mouse_x_range", "mouse_y_range"]) if config.kvmd.hid.type == "otg": hid_kwargs["udc"] = config.otg.udc # XXX: Small crutch to pass UDC to the plugin @@ -104,6 +104,7 @@ def main(argv: Optional[List[str]]=None) -> None: sync_chunk_size=config.server.sync_chunk_size, 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), diff --git a/kvmd/apps/kvmd/api/hid.py b/kvmd/apps/kvmd/api/hid.py index 71e711ff..47606884 100644 --- a/kvmd/apps/kvmd/api/hid.py +++ b/kvmd/apps/kvmd/api/hid.py @@ -25,6 +25,7 @@ import stat import functools from typing import Tuple +from typing import List from typing import Dict from typing import Set from typing import Callable @@ -63,6 +64,7 @@ class HidApi: hid: BaseHid, keymap_path: str, + ignore_keys: List[str], mouse_x_range: Tuple[int, int], mouse_y_range: Tuple[int, int], @@ -74,6 +76,8 @@ 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 @@ -160,7 +164,8 @@ class HidApi: state = valid_bool(event["state"]) except Exception: return - self.__hid.send_key_events([(key, state)]) + if key not in self.__ignore_keys: + self.__hid.send_key_events([(key, state)]) @exposed_ws("mouse_button") async def __ws_mouse_button_handler(self, _: WebSocketResponse, event: Dict) -> None: @@ -217,11 +222,12 @@ class HidApi: @exposed_http("POST", "/hid/events/send_key") async def __events_send_key_handler(self, request: Request) -> Response: key = valid_hid_key(request.query.get("key")) - if "state" in request.query: - state = valid_bool(request.query["state"]) - self.__hid.send_key_events([(key, state)]) - else: - self.__hid.send_key_events([(key, True), (key, False)]) + if key not in self.__ignore_keys: + if "state" in request.query: + state = valid_bool(request.query["state"]) + self.__hid.send_key_events([(key, state)]) + else: + self.__hid.send_key_events([(key, True), (key, False)]) return make_json_response() @exposed_http("POST", "/hid/events/send_mouse_button") diff --git a/kvmd/apps/kvmd/server.py b/kvmd/apps/kvmd/server.py index fcd21ae0..2d58d81f 100644 --- a/kvmd/apps/kvmd/server.py +++ b/kvmd/apps/kvmd/server.py @@ -161,6 +161,7 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins sync_chunk_size: int, keymap_path: str, + ignore_keys: List[str], mouse_x_range: Tuple[int, int], mouse_y_range: Tuple[int, int], @@ -195,7 +196,7 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins ], ] - self.__hid_api = HidApi(hid, keymap_path, mouse_x_range, mouse_y_range) # Ugly hack to get keymaps state + self.__hid_api = HidApi(hid, keymap_path, ignore_keys, mouse_x_range, mouse_y_range) # Ugly hack to get keymaps state self.__apis: List[object] = [ self, AuthApi(auth_manager), |