diff options
author | Maxim Devaev <[email protected]> | 2020-11-03 04:50:08 +0300 |
---|---|---|
committer | GitHub <[email protected]> | 2020-11-03 04:50:08 +0300 |
commit | 544f4b3fecb84e2ae21eb71ec0c37c8bec38261c (patch) | |
tree | 9199dba963bf8dde4cf4137f61b0cb5119fb7159 /kvmd/apps | |
parent | 6ec82dde5d4eb4b52956fff2029f33c4e651b919 (diff) |
Relative (#18)
* refactoring
* basic relative mouse mode
Diffstat (limited to 'kvmd/apps')
-rw-r--r-- | kvmd/apps/kvmd/api/hid.py | 28 | ||||
-rw-r--r-- | kvmd/apps/otg/__init__.py | 8 | ||||
-rw-r--r-- | kvmd/apps/otg/hid/mouse.py | 53 |
3 files changed, 80 insertions, 9 deletions
diff --git a/kvmd/apps/kvmd/api/hid.py b/kvmd/apps/kvmd/api/hid.py index 573ed48c..7913fde6 100644 --- a/kvmd/apps/kvmd/api/hid.py +++ b/kvmd/apps/kvmd/api/hid.py @@ -40,7 +40,7 @@ from ....validators.os import valid_printable_filename from ....validators.kvm import valid_hid_key from ....validators.kvm import valid_hid_mouse_move from ....validators.kvm import valid_hid_mouse_button -from ....validators.kvm import valid_hid_mouse_wheel +from ....validators.kvm import valid_hid_mouse_delta from ....keyboard.keysym import build_symmap from ....keyboard.printer import text_to_web_keys @@ -142,11 +142,20 @@ class HidApi: return self.__hid.send_mouse_move_event(to_x, to_y) + @exposed_ws("mouse_relative") + async def __ws_mouse_relative_handler(self, _: WebSocketResponse, event: Dict) -> None: + try: + delta_x = valid_hid_mouse_delta(event["delta"]["x"]) + delta_y = valid_hid_mouse_delta(event["delta"]["y"]) + except Exception: + return + self.__hid.send_mouse_relative_event(delta_x, delta_y) + @exposed_ws("mouse_wheel") async def __ws_mouse_wheel_handler(self, _: WebSocketResponse, event: Dict) -> None: try: - delta_x = valid_hid_mouse_wheel(event["delta"]["x"]) - delta_y = valid_hid_mouse_wheel(event["delta"]["y"]) + delta_x = valid_hid_mouse_delta(event["delta"]["x"]) + delta_y = valid_hid_mouse_delta(event["delta"]["y"]) except Exception: return self.__hid.send_mouse_wheel_event(delta_x, delta_y) @@ -181,9 +190,16 @@ class HidApi: self.__hid.send_mouse_move_event(to_x, to_y) return make_json_response() + @exposed_http("POST", "/hid/events/send_mouse_relative") + async def __events_send_mouse_relative_handler(self, request: Request) -> Response: + delta_x = valid_hid_mouse_delta(request.query.get("delta_x")) + delta_y = valid_hid_mouse_delta(request.query.get("delta_y")) + self.__hid.send_mouse_relative_event(delta_x, delta_y) + return make_json_response() + @exposed_http("POST", "/hid/events/send_mouse_wheel") - async def __events_send_mouse_wheel(self, request: Request) -> Response: - delta_x = valid_hid_mouse_wheel(request.query.get("delta_x")) - delta_y = valid_hid_mouse_wheel(request.query.get("delta_y")) + async def __events_send_mouse_wheel_handler(self, request: Request) -> Response: + delta_x = valid_hid_mouse_delta(request.query.get("delta_x")) + delta_y = valid_hid_mouse_delta(request.query.get("delta_y")) self.__hid.send_mouse_wheel_event(delta_x, delta_y) return make_json_response() diff --git a/kvmd/apps/otg/__init__.py b/kvmd/apps/otg/__init__.py index 50c5b836..edaf541f 100644 --- a/kvmd/apps/otg/__init__.py +++ b/kvmd/apps/otg/__init__.py @@ -43,7 +43,8 @@ from .. import init from .hid import Hid from .hid.keyboard import KEYBOARD_HID -from .hid.mouse import MOUSE_HID +from .hid.mouse import MOUSE_ABSOLUTE_HID +from .hid.mouse import MOUSE_RELATIVE_HID # ===== @@ -203,7 +204,10 @@ def _cmd_start(config: Section) -> None: if config.kvmd.hid.type == "otg": logger.info("===== Required HID =====") _create_hid(gadget_path, config_path, 0, KEYBOARD_HID) - _create_hid(gadget_path, config_path, 1, MOUSE_HID) + if config.kvmd.hid.mouse.absolute: + _create_hid(gadget_path, config_path, 1, MOUSE_ABSOLUTE_HID) + else: + _create_hid(gadget_path, config_path, 1, MOUSE_RELATIVE_HID) if config.kvmd.msd.type == "otg": logger.info("===== Required MSD =====") diff --git a/kvmd/apps/otg/hid/mouse.py b/kvmd/apps/otg/hid/mouse.py index 57e75e43..dfb5adec 100644 --- a/kvmd/apps/otg/hid/mouse.py +++ b/kvmd/apps/otg/hid/mouse.py @@ -24,7 +24,7 @@ from . import Hid # ===== -MOUSE_HID = Hid( +MOUSE_ABSOLUTE_HID = Hid( protocol=0, # None protocol subclass=0, # No subclass @@ -84,3 +84,54 @@ MOUSE_HID = Hid( 0xC0, # END_COLLECTION ]), ) + +MOUSE_RELATIVE_HID = Hid( + protocol=2, # Mouse protocol + subclass=1, # Boot interface subclass + + report_length=5, + + report_descriptor=bytes([ + # https://github.com/NicoHood/HID/blob/0835e6a/src/SingleReport/BootMouse.cpp + + # Relative mouse + 0x05, 0x01, # USAGE_PAGE (Generic Desktop) + 0x09, 0x02, # USAGE (Mouse) + 0xA1, 0x01, # COLLECTION (Application) + + # 8 Buttons + 0x05, 0x09, # USAGE_PAGE (Button) + 0x19, 0x01, # USAGE_MINIMUM (Button 1) + 0x29, 0x08, # USAGE_MAXIMUM (Button 8) + 0x15, 0x00, # LOGICAL_MINIMUM (0) + 0x25, 0x01, # LOGICAL_MAXIMUM (1) + 0x95, 0x08, # REPORT_COUNT (8) + 0x75, 0x01, # REPORT_SIZE (1) + 0x81, 0x02, # INPUT (Data,Var,Abs) + + # X, Y + 0x05, 0x01, # USAGE_PAGE (Generic Desktop) + 0x09, 0x30, # USAGE (X) + 0x09, 0x31, # USAGE (Y) + + # Wheel + 0x09, 0x38, # USAGE (Wheel) + 0x15, 0x81, # LOGICAL_MINIMUM (-127) + 0x25, 0x7F, # LOGICAL_MAXIMUM (127) + 0x75, 0x08, # REPORT_SIZE (8) + 0x95, 0x03, # REPORT_COUNT (3) + 0x81, 0x06, # INPUT (Data,Var,Rel) + + # Horizontal wheel + 0x05, 0x0C, # USAGE PAGE (Consumer Devices) + 0x0A, 0x38, 0x02, # USAGE (AC Pan) + 0x15, 0x81, # LOGICAL_MINIMUM (-127) + 0x25, 0x7F, # LOGICAL_MAXIMUM (127) + 0x75, 0x08, # REPORT_SIZE (8) + 0x95, 0x01, # REPORT_COUNT (1) + 0x81, 0x06, # INPUT (Data,Var,Rel) + + # End + 0xC0, # END_COLLECTION + ]), +) |