mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 17:20:30 +08:00
mouse input range
This commit is contained in:
parent
7f23f82a0d
commit
e24228b875
@ -363,7 +363,19 @@ def _get_config_scheme() -> Dict:
|
|||||||
|
|
||||||
"hid": {
|
"hid": {
|
||||||
"type": Option("", type=valid_stripped_string_not_empty),
|
"type": Option("", type=valid_stripped_string_not_empty),
|
||||||
|
|
||||||
"keymap": Option("/usr/share/kvmd/keymaps/en-us", type=valid_abs_file),
|
"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
|
# Dynamic content
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -59,7 +59,7 @@ def main(argv: Optional[List[str]]=None) -> None:
|
|||||||
if config.kvmd.msd.type == "otg":
|
if config.kvmd.msd.type == "otg":
|
||||||
msd_kwargs["gadget"] = config.otg.gadget # XXX: Small crutch to pass gadget name to the plugin
|
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":
|
if config.kvmd.hid.type == "otg":
|
||||||
hid_kwargs["udc"] = config.otg.udc # XXX: Small crutch to pass UDC to the plugin
|
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,
|
sync_chunk_size=config.server.sync_chunk_size,
|
||||||
|
|
||||||
keymap_path=config.hid.keymap,
|
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,
|
stream_forever=config.streamer.forever,
|
||||||
).run(**config.server._unpack(ignore=["heartbeat", "sync_chunk_size"]))
|
).run(**config.server._unpack(ignore=["heartbeat", "sync_chunk_size"]))
|
||||||
|
|||||||
@ -24,6 +24,7 @@ import os
|
|||||||
import stat
|
import stat
|
||||||
import functools
|
import functools
|
||||||
|
|
||||||
|
from typing import Tuple
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
from typing import Set
|
from typing import Set
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
@ -55,14 +56,25 @@ from ..http import make_json_response
|
|||||||
|
|
||||||
# =====
|
# =====
|
||||||
class HidApi:
|
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.__hid = hid
|
||||||
|
|
||||||
self.__keymaps_dir_path = os.path.dirname(keymap_path)
|
self.__keymaps_dir_path = os.path.dirname(keymap_path)
|
||||||
self.__default_keymap_name = os.path.basename(keymap_path)
|
self.__default_keymap_name = os.path.basename(keymap_path)
|
||||||
|
|
||||||
self.__ensure_symmap(self.__default_keymap_name)
|
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")
|
@exposed_http("GET", "/hid")
|
||||||
@ -157,8 +169,8 @@ class HidApi:
|
|||||||
@exposed_ws("mouse_move")
|
@exposed_ws("mouse_move")
|
||||||
async def __ws_mouse_move_handler(self, _: WebSocketResponse, event: Dict) -> None:
|
async def __ws_mouse_move_handler(self, _: WebSocketResponse, event: Dict) -> None:
|
||||||
try:
|
try:
|
||||||
to_x = valid_hid_mouse_move(event["to"]["x"])
|
to_x = valid_hid_mouse_move(event["to"]["x"], *self.__mouse_x_range)
|
||||||
to_y = valid_hid_mouse_move(event["to"]["y"])
|
to_y = valid_hid_mouse_move(event["to"]["y"], *self.__mouse_y_range)
|
||||||
except Exception:
|
except Exception:
|
||||||
return
|
return
|
||||||
self.__hid.send_mouse_move_event(to_x, to_y)
|
self.__hid.send_mouse_move_event(to_x, to_y)
|
||||||
@ -220,8 +232,8 @@ class HidApi:
|
|||||||
|
|
||||||
@exposed_http("POST", "/hid/events/send_mouse_move")
|
@exposed_http("POST", "/hid/events/send_mouse_move")
|
||||||
async def __events_send_mouse_move_handler(self, request: Request) -> Response:
|
async def __events_send_mouse_move_handler(self, request: Request) -> Response:
|
||||||
to_x = valid_hid_mouse_move(request.query.get("to_x"))
|
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"))
|
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)
|
self.__hid.send_mouse_move_event(to_x, to_y)
|
||||||
return make_json_response()
|
return make_json_response()
|
||||||
|
|
||||||
|
|||||||
@ -27,6 +27,7 @@ import operator
|
|||||||
import dataclasses
|
import dataclasses
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
from typing import Tuple
|
||||||
from typing import List
|
from typing import List
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
from typing import Set
|
from typing import Set
|
||||||
@ -142,7 +143,7 @@ class _WsClient:
|
|||||||
|
|
||||||
|
|
||||||
class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-instance-attributes
|
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,
|
self,
|
||||||
auth_manager: AuthManager,
|
auth_manager: AuthManager,
|
||||||
info_manager: InfoManager,
|
info_manager: InfoManager,
|
||||||
@ -160,6 +161,8 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins
|
|||||||
sync_chunk_size: int,
|
sync_chunk_size: int,
|
||||||
|
|
||||||
keymap_path: str,
|
keymap_path: str,
|
||||||
|
mouse_x_range: Tuple[int, int],
|
||||||
|
mouse_y_range: Tuple[int, int],
|
||||||
|
|
||||||
stream_forever: bool,
|
stream_forever: bool,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -199,7 +202,7 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins
|
|||||||
LogApi(log_reader),
|
LogApi(log_reader),
|
||||||
WolApi(wol),
|
WolApi(wol),
|
||||||
UserGpioApi(user_gpio),
|
UserGpioApi(user_gpio),
|
||||||
HidApi(hid, keymap_path),
|
HidApi(hid, keymap_path, mouse_x_range, mouse_y_range),
|
||||||
AtxApi(atx),
|
AtxApi(atx),
|
||||||
MsdApi(msd, sync_chunk_size),
|
MsdApi(msd, sync_chunk_size),
|
||||||
StreamerApi(streamer),
|
StreamerApi(streamer),
|
||||||
|
|||||||
@ -42,9 +42,9 @@ def valid_hid_key(arg: Any) -> str:
|
|||||||
return check_string_in_list(arg, "Keyboard key", KEYMAP, lower=False)
|
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")
|
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:
|
def valid_hid_mouse_button(arg: Any) -> str:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user