summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2023-06-05 16:37:02 +0300
committerMaxim Devaev <[email protected]>2023-06-05 16:37:02 +0300
commit66c1d321d2048feab7c786d64a5356660216ad38 (patch)
tree04b8de4ca556f629acc590be1491bffad31bf33f
parent82aedb9c4ea7b57f03fe83fe0edee4c511c883ef (diff)
vnc: force absolute usb mouse_output
-rw-r--r--kvmd/apps/__init__.py6
-rw-r--r--kvmd/apps/vnc/__init__.py1
-rw-r--r--kvmd/apps/vnc/server.py7
-rw-r--r--kvmd/clients/kvmd.py37
4 files changed, 36 insertions, 15 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py
index 1579c07b..04f88ffa 100644
--- a/kvmd/apps/__init__.py
+++ b/kvmd/apps/__init__.py
@@ -82,6 +82,7 @@ from ..validators.net import valid_mac
from ..validators.net import valid_ssl_ciphers
from ..validators.hid import valid_hid_key
+from ..validators.hid import valid_hid_mouse_output
from ..validators.hid import valid_hid_mouse_move
from ..validators.kvm import valid_stream_quality
@@ -662,8 +663,9 @@ def _get_config_scheme() -> dict:
},
"vnc": {
- "desired_fps": Option(30, type=valid_stream_fps),
- "keymap": Option("/usr/share/kvmd/keymaps/en-us", type=valid_abs_file),
+ "desired_fps": Option(30, type=valid_stream_fps),
+ "mouse_output": Option("usb", type=valid_hid_mouse_output),
+ "keymap": Option("/usr/share/kvmd/keymaps/en-us", type=valid_abs_file),
"server": {
"host": Option("::", type=valid_ip_or_host),
diff --git a/kvmd/apps/vnc/__init__.py b/kvmd/apps/vnc/__init__.py
index 3653f416..a5d3c781 100644
--- a/kvmd/apps/vnc/__init__.py
+++ b/kvmd/apps/vnc/__init__.py
@@ -69,6 +69,7 @@ def main(argv: (list[str] | None)=None) -> None:
x509_key_path=config.server.tls.x509.key,
desired_fps=config.desired_fps,
+ mouse_output=config.mouse_output,
keymap_path=config.keymap,
kvmd=KvmdClient(user_agent=user_agent, **config.kvmd._unpack()),
diff --git a/kvmd/apps/vnc/server.py b/kvmd/apps/vnc/server.py
index f4c431a9..f1203519 100644
--- a/kvmd/apps/vnc/server.py
+++ b/kvmd/apps/vnc/server.py
@@ -77,6 +77,7 @@ class _Client(RfbClient): # pylint: disable=too-many-instance-attributes
x509_key_path: str,
desired_fps: int,
+ mouse_output: str,
keymap_name: str,
symmap: dict[int, dict[int, str]],
@@ -105,6 +106,7 @@ class _Client(RfbClient): # pylint: disable=too-many-instance-attributes
)
self.__desired_fps = desired_fps
+ self.__mouse_output = mouse_output
self.__keymap_name = keymap_name
self.__symmap = symmap
@@ -159,6 +161,9 @@ class _Client(RfbClient): # pylint: disable=too-many-instance-attributes
assert self.__kvmd_session
try:
+ logger.info("%s [kvmd]: Applying HID params: mouse_output=%s ...", self._remote, self.__mouse_output)
+ await self.__kvmd_session.hid.set_params(mouse_output=self.__mouse_output)
+
async with self.__kvmd_session.ws() as self.__kvmd_ws:
logger.info("%s [kvmd]: Connected to KVMD websocket", self._remote)
self.__stage3_ws_connected.set_passed()
@@ -429,6 +434,7 @@ class VncServer: # pylint: disable=too-many-instance-attributes
vencrypt_enabled: bool,
desired_fps: int,
+ mouse_output: str,
keymap_path: str,
kvmd: KvmdClient,
@@ -484,6 +490,7 @@ class VncServer: # pylint: disable=too-many-instance-attributes
x509_cert_path=x509_cert_path,
x509_key_path=x509_key_path,
desired_fps=desired_fps,
+ mouse_output=mouse_output,
keymap_name=keymap_name,
symmap=symmap,
kvmd=kvmd,
diff --git a/kvmd/clients/kvmd.py b/kvmd/clients/kvmd.py
index f8511504..ec86378d 100644
--- a/kvmd/clients/kvmd.py
+++ b/kvmd/clients/kvmd.py
@@ -46,6 +46,18 @@ class _BaseApiPart:
self._ensure_http_session = ensure_http_session
self._make_url = make_url
+ async def _set_params(self, handle: str, **params: (int | str | None)) -> None:
+ session = self._ensure_http_session()
+ async with session.post(
+ url=self._make_url(handle),
+ params={
+ key: value
+ for (key, value) in params.items()
+ if value is not None
+ },
+ ) as response:
+ htclient.raise_not_200(response)
+
class _AuthApiPart(_BaseApiPart):
async def check(self) -> bool:
@@ -68,19 +80,11 @@ class _StreamerApiPart(_BaseApiPart):
return (await response.json())["result"]
async def set_params(self, quality: (int | None)=None, desired_fps: (int | None)=None) -> None:
- session = self._ensure_http_session()
- async with session.post(
- url=self._make_url("streamer/set_params"),
- params={
- key: value
- for (key, value) in [
- ("quality", quality),
- ("desired_fps", desired_fps),
- ]
- if value is not None
- },
- ) as response:
- htclient.raise_not_200(response)
+ await self._set_params(
+ "streamer/set_params",
+ quality=quality,
+ desired_fps=desired_fps,
+ )
class _HidApiPart(_BaseApiPart):
@@ -100,6 +104,13 @@ class _HidApiPart(_BaseApiPart):
) as response:
htclient.raise_not_200(response)
+ async def set_params(self, keyboard_output: (str | None)=None, mouse_output: (str | None)=None) -> None:
+ await self._set_params(
+ "hid/set_params",
+ keyboard_output=keyboard_output,
+ mouse_output=mouse_output,
+ )
+
class _AtxApiPart(_BaseApiPart):
async def get_state(self) -> dict: