summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2021-03-26 05:19:02 +0300
committerDevaev Maxim <[email protected]>2021-03-26 05:19:02 +0300
commite24228b8751f9f4152c4c76f5644f4e57607bf1f (patch)
tree92dfcf9fcb2122578964e15390ff7bb8100f3ee4 /kvmd
parent7f23f82a0d4147c2ce2369614827b9f8b583a234 (diff)
mouse input range
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/apps/__init__.py12
-rw-r--r--kvmd/apps/kvmd/__init__.py4
-rw-r--r--kvmd/apps/kvmd/api/hid.py24
-rw-r--r--kvmd/apps/kvmd/server.py7
-rw-r--r--kvmd/validators/hid.py4
5 files changed, 40 insertions, 11 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py
index ed6a3101..aa724979 100644
--- a/kvmd/apps/__init__.py
+++ b/kvmd/apps/__init__.py
@@ -363,7 +363,19 @@ 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),
+
+ "mouse_x_range": {
+ "min": Option(-32768, type=valid_hid_mouse_move),
+ "max": Option(32767, type=valid_hid_mouse_move),
+ },
+
+ "mouse_y_range": {
+ "min": Option(-32768, type=valid_hid_mouse_move),
+ "max": Option(32767, type=valid_hid_mouse_move),
+ },
+
# Dynamic content
},
diff --git a/kvmd/apps/kvmd/__init__.py b/kvmd/apps/kvmd/__init__.py
index 2a6dbeef..7b2b5e6e 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"])
+ hid_kwargs = config.kvmd.hid._unpack(ignore=["type", "keymap", "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,8 @@ def main(argv: Optional[List[str]]=None) -> None:
sync_chunk_size=config.server.sync_chunk_size,
keymap_path=config.hid.keymap,
+ 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(ignore=["heartbeat", "sync_chunk_size"]))
diff --git a/kvmd/apps/kvmd/api/hid.py b/kvmd/apps/kvmd/api/hid.py
index b865b6a8..d9a39a00 100644
--- a/kvmd/apps/kvmd/api/hid.py
+++ b/kvmd/apps/kvmd/api/hid.py
@@ -24,6 +24,7 @@ import os
import stat
import functools
+from typing import Tuple
from typing import Dict
from typing import Set
from typing import Callable
@@ -55,14 +56,25 @@ from ..http import make_json_response
# =====
class HidApi:
- def __init__(self, hid: BaseHid, keymap_path: str) -> None:
+ def __init__(
+ self,
+ hid: BaseHid,
+
+ keymap_path: str,
+
+ mouse_x_range: Tuple[int, int],
+ mouse_y_range: Tuple[int, int],
+ ) -> None:
+
self.__hid = hid
self.__keymaps_dir_path = os.path.dirname(keymap_path)
self.__default_keymap_name = os.path.basename(keymap_path)
-
self.__ensure_symmap(self.__default_keymap_name)
+ self.__mouse_x_range = mouse_x_range
+ self.__mouse_y_range = mouse_y_range
+
# =====
@exposed_http("GET", "/hid")
@@ -157,8 +169,8 @@ class HidApi:
@exposed_ws("mouse_move")
async def __ws_mouse_move_handler(self, _: WebSocketResponse, event: Dict) -> None:
try:
- to_x = valid_hid_mouse_move(event["to"]["x"])
- to_y = valid_hid_mouse_move(event["to"]["y"])
+ to_x = valid_hid_mouse_move(event["to"]["x"], *self.__mouse_x_range)
+ to_y = valid_hid_mouse_move(event["to"]["y"], *self.__mouse_y_range)
except Exception:
return
self.__hid.send_mouse_move_event(to_x, to_y)
@@ -220,8 +232,8 @@ class HidApi:
@exposed_http("POST", "/hid/events/send_mouse_move")
async def __events_send_mouse_move_handler(self, request: Request) -> Response:
- to_x = valid_hid_mouse_move(request.query.get("to_x"))
- to_y = valid_hid_mouse_move(request.query.get("to_y"))
+ to_x = valid_hid_mouse_move(request.query.get("to_x"), *self.__mouse_x_range)
+ to_y = valid_hid_mouse_move(request.query.get("to_y"), *self.__mouse_y_range)
self.__hid.send_mouse_move_event(to_x, to_y)
return make_json_response()
diff --git a/kvmd/apps/kvmd/server.py b/kvmd/apps/kvmd/server.py
index 71d9a5fa..84f21c08 100644
--- a/kvmd/apps/kvmd/server.py
+++ b/kvmd/apps/kvmd/server.py
@@ -27,6 +27,7 @@ import operator
import dataclasses
import json
+from typing import Tuple
from typing import List
from typing import Dict
from typing import Set
@@ -142,7 +143,7 @@ class _WsClient:
class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-instance-attributes
- def __init__( # pylint: disable=too-many-arguments
+ def __init__( # pylint: disable=too-many-arguments,too-many-locals
self,
auth_manager: AuthManager,
info_manager: InfoManager,
@@ -160,6 +161,8 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins
sync_chunk_size: int,
keymap_path: str,
+ mouse_x_range: Tuple[int, int],
+ mouse_y_range: Tuple[int, int],
stream_forever: bool,
) -> None:
@@ -199,7 +202,7 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins
LogApi(log_reader),
WolApi(wol),
UserGpioApi(user_gpio),
- HidApi(hid, keymap_path),
+ HidApi(hid, keymap_path, mouse_x_range, mouse_y_range),
AtxApi(atx),
MsdApi(msd, sync_chunk_size),
StreamerApi(streamer),
diff --git a/kvmd/validators/hid.py b/kvmd/validators/hid.py
index b51ff88a..bb7e26e1 100644
--- a/kvmd/validators/hid.py
+++ b/kvmd/validators/hid.py
@@ -42,9 +42,9 @@ def valid_hid_key(arg: Any) -> str:
return check_string_in_list(arg, "Keyboard key", KEYMAP, lower=False)
-def valid_hid_mouse_move(arg: Any) -> int:
+def valid_hid_mouse_move(arg: Any, move_min: int=-32768, move_max: int=32767) -> int:
arg = valid_number(arg, name="Mouse move")
- return min(max(-32768, arg), 32767)
+ return min(max(move_min, arg), move_max)
def valid_hid_mouse_button(arg: Any) -> str: