diff options
author | Devaev Maxim <[email protected]> | 2019-10-01 05:48:20 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2019-10-01 05:48:20 +0300 |
commit | 8cc5f631cafe84794c878244649ab11087631efd (patch) | |
tree | cca3e02fe967f5291b2ff791ad871e9e1fcf990e /kvmd/plugins/hid | |
parent | 74931a8096aed89ef7d03e327978d1a2963c92c7 (diff) |
horizontal scrolling for otg
Diffstat (limited to 'kvmd/plugins/hid')
-rw-r--r-- | kvmd/plugins/hid/__init__.py | 2 | ||||
-rw-r--r-- | kvmd/plugins/hid/otg/__init__.py | 4 | ||||
-rw-r--r-- | kvmd/plugins/hid/otg/mouse.py | 25 | ||||
-rw-r--r-- | kvmd/plugins/hid/serial.py | 7 |
4 files changed, 21 insertions, 17 deletions
diff --git a/kvmd/plugins/hid/__init__.py b/kvmd/plugins/hid/__init__.py index bb4ec677..5bc5ca52 100644 --- a/kvmd/plugins/hid/__init__.py +++ b/kvmd/plugins/hid/__init__.py @@ -57,7 +57,7 @@ class BaseHid(BasePlugin): async def send_mouse_button_event(self, button: str, state: bool) -> None: raise NotImplementedError - async def send_mouse_wheel_event(self, delta_y: int) -> None: + async def send_mouse_wheel_event(self, delta_x: int, delta_y: int) -> None: raise NotImplementedError async def clear_events(self) -> None: diff --git a/kvmd/plugins/hid/otg/__init__.py b/kvmd/plugins/hid/otg/__init__.py index 7129e5d4..1d05199b 100644 --- a/kvmd/plugins/hid/otg/__init__.py +++ b/kvmd/plugins/hid/otg/__init__.py @@ -121,8 +121,8 @@ class Plugin(BaseHid): async def send_mouse_move_event(self, to_x: int, to_y: int) -> None: self.__mouse_proc.send_move_event(to_x, to_y) - async def send_mouse_wheel_event(self, delta_y: int) -> None: - self.__mouse_proc.send_wheel_event(delta_y) + async def send_mouse_wheel_event(self, delta_x: int, delta_y: int) -> None: + self.__mouse_proc.send_wheel_event(delta_x, delta_y) async def clear_events(self) -> None: self.__keyboard_proc.send_clear_event() diff --git a/kvmd/plugins/hid/otg/mouse.py b/kvmd/plugins/hid/otg/mouse.py index 4132a1cc..1c0ad1df 100644 --- a/kvmd/plugins/hid/otg/mouse.py +++ b/kvmd/plugins/hid/otg/mouse.py @@ -66,9 +66,11 @@ class _MoveEvent(BaseEvent): @dataclasses.dataclass(frozen=True) class _WheelEvent(BaseEvent): + delta_x: int delta_y: int def __post_init__(self) -> None: + assert -127 <= self.delta_x <= 127 assert -127 <= self.delta_y <= 127 @@ -86,7 +88,7 @@ class MouseProcess(DeviceProcess): get_logger().info("Clearing HID-mouse events ...") if self._ensure_device(): try: - self._write_report(self.__make_report(0, self.__x, self.__y, 0)) # Release all buttons + self._write_report(self.__make_report(0, self.__x, self.__y, 0, 0)) # Release all buttons finally: self._close_device() @@ -103,8 +105,8 @@ class MouseProcess(DeviceProcess): def send_move_event(self, to_x: int, to_y: int) -> None: self._queue_event(_MoveEvent(to_x, to_y)) - def send_wheel_event(self, delta_y: int) -> None: - self._queue_event(_WheelEvent(delta_y)) + def send_wheel_event(self, delta_x: int, delta_y: int) -> None: + self._queue_event(_WheelEvent(delta_x, delta_y)) # ===== @@ -124,34 +126,35 @@ class MouseProcess(DeviceProcess): self.__clear_state() if reopen: self._close_device() - self.__send_current_state(0) + self.__send_current_state(0, 0) def __process_button_event(self, event: _ButtonEvent) -> None: if event.code & self.__pressed_buttons: # Ранее нажатую кнопку отжимаем self.__pressed_buttons &= ~event.code - if not self.__send_current_state(0): + if not self.__send_current_state(0, 0): return if event.state: # Нажимаем если нужно self.__pressed_buttons |= event.code - self.__send_current_state(0) + self.__send_current_state(0, 0) def __process_move_event(self, event: _MoveEvent) -> None: self.__x = event.to_x self.__y = event.to_y - self.__send_current_state(0) + self.__send_current_state(0, 0) def __process_wheel_event(self, event: _WheelEvent) -> None: - self.__send_current_state(event.delta_y) + self.__send_current_state(event.delta_x, event.delta_y) - def __send_current_state(self, delta_y: int) -> bool: + def __send_current_state(self, delta_x: int, delta_y: int) -> bool: ok = False if self._ensure_device(): ok = self._write_report(self.__make_report( buttons=self.__pressed_buttons, to_x=self.__x, to_y=self.__y, + delta_x=delta_x, delta_y=delta_y, )) if not ok: @@ -163,7 +166,7 @@ class MouseProcess(DeviceProcess): self.__x = 0 self.__y = 0 - def __make_report(self, buttons: int, to_x: int, to_y: int, delta_y: int) -> bytes: + def __make_report(self, buttons: int, to_x: int, to_y: int, delta_x: int, delta_y: int) -> bytes: to_x = (to_x + 32768) // 2 to_y = (to_y + 32768) // 2 - return struct.pack("<BHHb", buttons, to_x, to_y, delta_y) + return struct.pack("<BHHbb", buttons, to_x, to_y, delta_y, delta_x) diff --git a/kvmd/plugins/hid/serial.py b/kvmd/plugins/hid/serial.py index 40eb3268..9a5995e9 100644 --- a/kvmd/plugins/hid/serial.py +++ b/kvmd/plugins/hid/serial.py @@ -119,10 +119,11 @@ class _MouseButtonEvent(_BoolEvent): @dataclasses.dataclass(frozen=True) class _MouseWheelEvent(_IntEvent): def __post_init__(self) -> None: - assert self.x == 0 # Горизонтальная прокрутка пока не поддерживается + assert -127 <= self.x <= 127 assert -127 <= self.y <= 127 def make_command(self) -> bytes: + # Горизонтальная прокрутка пока не поддерживается return b"\x14\x00" + struct.pack(">b", self.y) + b"\x00\x00" @@ -253,8 +254,8 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst async def send_mouse_button_event(self, button: str, state: bool) -> None: await self.__send_bool_event(_MouseButtonEvent(button, state), self.__pressed_mouse_buttons) - async def send_mouse_wheel_event(self, delta_y: int) -> None: - await self.__send_int_event(_MouseWheelEvent(0, delta_y)) + async def send_mouse_wheel_event(self, delta_x: int, delta_y: int) -> None: + await self.__send_int_event(_MouseWheelEvent(delta_x, delta_y)) async def clear_events(self) -> None: if not self.__stop_event.is_set(): |