summaryrefslogtreecommitdiff
path: root/kvmd/plugins/hid/otg
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2024-11-02 14:26:39 +0200
committerMaxim Devaev <[email protected]>2024-11-02 14:26:39 +0200
commitd6b61cb407a729169af6d678de667dae842a86f5 (patch)
treeffd4185ae16a96795aecbb292fe0e36b2d4d3df1 /kvmd/plugins/hid/otg
parent8192b1fa95e263d41d1f9be4909dc58517b8da37 (diff)
refactoring
Diffstat (limited to 'kvmd/plugins/hid/otg')
-rw-r--r--kvmd/plugins/hid/otg/__init__.py50
-rw-r--r--kvmd/plugins/hid/otg/keyboard.py6
2 files changed, 26 insertions, 30 deletions
diff --git a/kvmd/plugins/hid/otg/__init__.py b/kvmd/plugins/hid/otg/__init__.py
index 7686ebdd..c95fb7fb 100644
--- a/kvmd/plugins/hid/otg/__init__.py
+++ b/kvmd/plugins/hid/otg/__init__.py
@@ -22,7 +22,6 @@
import copy
-from typing import Iterable
from typing import AsyncGenerator
from typing import Any
@@ -48,15 +47,20 @@ from .mouse import MouseProcess
class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes
def __init__(
self,
+ ignore_keys: list[str],
+ mouse_x_range: dict[str, Any],
+ mouse_y_range: dict[str, Any],
+ jiggler: dict[str, Any],
+
keyboard: dict[str, Any],
mouse: dict[str, Any],
mouse_alt: dict[str, Any],
- jiggler: dict[str, Any],
noop: bool,
+
udc: str, # XXX: Not from options, see /kvmd/apps/kvmd/__init__.py for details
) -> None:
- super().__init__(**jiggler)
+ super().__init__(ignore_keys=ignore_keys, **mouse_x_range, **mouse_y_range, **jiggler)
self.__udc = udc
@@ -115,7 +119,7 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes
"horizontal_wheel": Option(True, type=valid_bool),
},
"noop": Option(False, type=valid_bool),
- **cls._get_jiggler_options(),
+ **cls._get_base_options(),
}
def sysprep(self) -> None:
@@ -183,26 +187,6 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes
# =====
- def send_key_events(self, keys: Iterable[tuple[str, bool]]) -> None:
- self.__keyboard_proc.send_key_events(keys)
- self._bump_activity()
-
- def send_mouse_button_event(self, button: str, state: bool) -> None:
- self.__mouse_current.send_button_event(button, state)
- self._bump_activity()
-
- def send_mouse_move_event(self, to_x: int, to_y: int) -> None:
- self.__mouse_current.send_move_event(to_x, to_y)
- self._bump_activity()
-
- def send_mouse_relative_event(self, delta_x: int, delta_y: int) -> None:
- self.__mouse_current.send_relative_event(delta_x, delta_y)
- self._bump_activity()
-
- def send_mouse_wheel_event(self, delta_x: int, delta_y: int) -> None:
- self.__mouse_current.send_wheel_event(delta_x, delta_y)
- self._bump_activity()
-
def set_params(
self,
keyboard_output: (str | None)=None,
@@ -221,12 +205,26 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes
self._set_jiggler_active(jiggler)
self.__notifier.notify()
- def clear_events(self) -> None:
+ def _send_key_event(self, key: str, state: bool) -> None:
+ self.__keyboard_proc.send_key_event(key, state)
+
+ def _send_mouse_button_event(self, button: str, state: bool) -> None:
+ self.__mouse_current.send_button_event(button, state)
+
+ def _send_mouse_move_event(self, to_x: int, to_y: int) -> None:
+ self.__mouse_current.send_move_event(to_x, to_y)
+
+ def _send_mouse_relative_event(self, delta_x: int, delta_y: int) -> None:
+ self.__mouse_current.send_relative_event(delta_x, delta_y)
+
+ def _send_mouse_wheel_event(self, delta_x: int, delta_y: int) -> None:
+ self.__mouse_current.send_wheel_event(delta_x, delta_y)
+
+ def _clear_events(self) -> None:
self.__keyboard_proc.send_clear_event()
self.__mouse_proc.send_clear_event()
if self.__mouse_alt_proc:
self.__mouse_alt_proc.send_clear_event()
- self._bump_activity()
# =====
diff --git a/kvmd/plugins/hid/otg/keyboard.py b/kvmd/plugins/hid/otg/keyboard.py
index 9008db06..e82d95a3 100644
--- a/kvmd/plugins/hid/otg/keyboard.py
+++ b/kvmd/plugins/hid/otg/keyboard.py
@@ -20,7 +20,6 @@
# ========================================================================== #
-from typing import Iterable
from typing import Generator
from typing import Any
@@ -68,9 +67,8 @@ class KeyboardProcess(BaseDeviceProcess):
self._clear_queue()
self._queue_event(ResetEvent())
- def send_key_events(self, keys: Iterable[tuple[str, bool]]) -> None:
- for (key, state) in keys:
- self._queue_event(make_keyboard_event(key, state))
+ def send_key_event(self, key: str, state: bool) -> None:
+ self._queue_event(make_keyboard_event(key, state))
# =====