diff options
Diffstat (limited to 'kvmd/plugins/hid/__init__.py')
-rw-r--r-- | kvmd/plugins/hid/__init__.py | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/kvmd/plugins/hid/__init__.py b/kvmd/plugins/hid/__init__.py index 2ef7495f..32f7aef1 100644 --- a/kvmd/plugins/hid/__init__.py +++ b/kvmd/plugins/hid/__init__.py @@ -20,6 +20,9 @@ # ========================================================================== # +import asyncio +import time + from typing import Iterable from typing import AsyncGenerator @@ -29,6 +32,11 @@ from .. import get_plugin_class # ===== class BaseHid(BasePlugin): + def __init__(self) -> None: + self.__jiggler_enabled = False + self.__jiggler_absolute = True + self.__activity_ts = 0 + def sysprep(self) -> None: raise NotImplementedError @@ -64,9 +72,14 @@ class BaseHid(BasePlugin): def send_mouse_wheel_event(self, delta_x: int, delta_y: int) -> None: raise NotImplementedError - def set_params(self, keyboard_output: (str | None)=None, mouse_output: (str | None)=None) -> None: - _ = keyboard_output - _ = mouse_output + def set_params( + self, + keyboard_output: (str | None)=None, + mouse_output: (str | None)=None, + jiggler: (bool | None)=None, + ) -> None: + + raise NotImplementedError def set_connected(self, connected: bool) -> None: _ = connected @@ -74,6 +87,31 @@ class BaseHid(BasePlugin): def clear_events(self) -> None: raise NotImplementedError + # ===== + + async def systask(self) -> None: + factor = 1 + while True: + if self.__jiggler_enabled and (self.__activity_ts + 60 < int(time.monotonic())): + if self.__jiggler_absolute: + self.send_mouse_move_event(100 * factor, 100 * factor) + else: + self.send_mouse_relative_event(10 * factor, 10 * factor) + factor *= -1 + await asyncio.sleep(1) + + def _bump_activity(self) -> None: + self.__activity_ts = int(time.monotonic()) + + def _set_jiggler_absolute(self, absolute: bool) -> None: + self.__jiggler_absolute = absolute + + def _set_jiggler_enabled(self, enabled: bool) -> None: + self.__jiggler_enabled = enabled + + def _get_jiggler_state(self) -> dict: + return {"enabled": self.__jiggler_enabled} + # ===== def get_hid_class(name: str) -> type[BaseHid]: |