summaryrefslogtreecommitdiff
path: root/kvmd/apps
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2021-03-26 21:32:21 +0300
committerDevaev Maxim <[email protected]>2021-03-26 21:32:21 +0300
commita66221a494e35ab070d13291ce82928797bf95d4 (patch)
tree3dd496eccf1f3281dad1d545e50a111c28ccdfbc /kvmd/apps
parent1674cf70b3f925fe055398911761542c14d304e9 (diff)
fixed mouse remap
Diffstat (limited to 'kvmd/apps')
-rw-r--r--kvmd/apps/__init__.py10
-rw-r--r--kvmd/apps/kvmd/api/hid.py21
-rw-r--r--kvmd/apps/vnc/rfb/__init__.py7
3 files changed, 26 insertions, 12 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py
index aa724979..cb5666b9 100644
--- a/kvmd/apps/__init__.py
+++ b/kvmd/apps/__init__.py
@@ -39,6 +39,8 @@ 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
@@ -367,13 +369,13 @@ def _get_config_scheme() -> Dict:
"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),
+ "min": Option(MouseRange.MIN, type=valid_hid_mouse_move),
+ "max": Option(MouseRange.MAX, type=valid_hid_mouse_move),
},
"mouse_y_range": {
- "min": Option(-32768, type=valid_hid_mouse_move),
- "max": Option(32767, type=valid_hid_mouse_move),
+ "min": Option(MouseRange.MIN, type=valid_hid_mouse_move),
+ "max": Option(MouseRange.MAX, type=valid_hid_mouse_move),
},
# Dynamic content
diff --git a/kvmd/apps/kvmd/api/hid.py b/kvmd/apps/kvmd/api/hid.py
index d9a39a00..418e065d 100644
--- a/kvmd/apps/kvmd/api/hid.py
+++ b/kvmd/apps/kvmd/api/hid.py
@@ -33,6 +33,8 @@ from aiohttp.web import Request
from aiohttp.web import Response
from aiohttp.web import WebSocketResponse
+from ....mouse import MouseRange
+
from ....plugins.hid import BaseHid
from ....validators import raise_error
@@ -169,11 +171,11 @@ 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"], *self.__mouse_x_range)
- to_y = valid_hid_mouse_move(event["to"]["y"], *self.__mouse_y_range)
+ to_x = valid_hid_mouse_move(event["to"]["x"])
+ to_y = valid_hid_mouse_move(event["to"]["y"])
except Exception:
return
- self.__hid.send_mouse_move_event(to_x, to_y)
+ self.__send_mouse_move_event_remapped(to_x, to_y)
@exposed_ws("mouse_relative")
async def __ws_mouse_relative_handler(self, _: WebSocketResponse, event: Dict) -> None:
@@ -232,9 +234,9 @@ 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"), *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)
+ to_x = valid_hid_mouse_move(request.query.get("to_x"))
+ to_y = valid_hid_mouse_move(request.query.get("to_y"))
+ self.__send_mouse_move_event_remapped(to_x, to_y)
return make_json_response()
@exposed_http("POST", "/hid/events/send_mouse_relative")
@@ -245,6 +247,13 @@ class HidApi:
async def __events_send_mouse_wheel_handler(self, request: Request) -> Response:
return self.__process_delta_request(request, self.__hid.send_mouse_wheel_event)
+ def __send_mouse_move_event_remapped(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 __process_delta_request(self, request: Request, handler: Callable[[int, int], None]) -> Response:
delta_x = valid_hid_mouse_delta(request.query.get("delta_x"))
delta_y = valid_hid_mouse_delta(request.query.get("delta_y"))
diff --git a/kvmd/apps/vnc/rfb/__init__.py b/kvmd/apps/vnc/rfb/__init__.py
index 48805f27..8eff691a 100644
--- a/kvmd/apps/vnc/rfb/__init__.py
+++ b/kvmd/apps/vnc/rfb/__init__.py
@@ -32,8 +32,11 @@ from typing import Coroutine
from ....logging import get_logger
+from .... import tools
from .... import aiotools
+from ....mouse import MouseRange
+
from .errors import RfbError
from .errors import RfbConnectionError
@@ -444,8 +447,8 @@ class RfbClient(RfbClientStream): # pylint: disable=too-many-instance-attribute
"y": (-4 if buttons & 0x10 else (4 if buttons & 0x8 else 0)),
},
move={
- "x": round(to_x / self._width * 65535 + -32768),
- "y": round(to_y / self._height * 65535 + -32768),
+ "x": tools.remap(to_x, 0, self._width, *MouseRange.RANGE),
+ "y": tools.remap(to_y, 0, self._height, *MouseRange.RANGE),
},
)