mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 00:51:53 +08:00
option to disable jiggler
This commit is contained in:
@@ -25,6 +25,11 @@ import time
|
||||
|
||||
from typing import Iterable
|
||||
from typing import AsyncGenerator
|
||||
from typing import Any
|
||||
|
||||
from ...yamlconf import Option
|
||||
|
||||
from ...validators.basic import valid_bool
|
||||
|
||||
from .. import BasePlugin
|
||||
from .. import get_plugin_class
|
||||
@@ -32,11 +37,22 @@ from .. import get_plugin_class
|
||||
|
||||
# =====
|
||||
class BaseHid(BasePlugin):
|
||||
def __init__(self) -> None:
|
||||
self.__jiggler_enabled = False
|
||||
def __init__(self, jiggler_enabled: bool) -> None:
|
||||
self.__jiggler_enabled = jiggler_enabled
|
||||
self.__jiggler_active = False
|
||||
self.__jiggler_absolute = True
|
||||
self.__activity_ts = 0
|
||||
|
||||
@classmethod
|
||||
def _get_jiggler_options(cls) -> dict[str, Any]:
|
||||
return {
|
||||
"jiggler": {
|
||||
"enabled": Option(True, type=valid_bool, unpack_as="jiggler_enabled"),
|
||||
},
|
||||
}
|
||||
|
||||
# =====
|
||||
|
||||
def sysprep(self) -> None:
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -92,7 +108,7 @@ class BaseHid(BasePlugin):
|
||||
async def systask(self) -> None:
|
||||
factor = 1
|
||||
while True:
|
||||
if self.__jiggler_enabled and (self.__activity_ts + 60 < int(time.monotonic())):
|
||||
if self.__jiggler_active and (self.__activity_ts + 60 < int(time.monotonic())):
|
||||
if self.__jiggler_absolute:
|
||||
self.send_mouse_move_event(100 * factor, 100 * factor)
|
||||
else:
|
||||
@@ -106,11 +122,17 @@ class BaseHid(BasePlugin):
|
||||
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 _set_jiggler_active(self, active: bool) -> None:
|
||||
if self.__jiggler_enabled:
|
||||
self.__jiggler_active = active
|
||||
|
||||
def _get_jiggler_state(self) -> dict:
|
||||
return {"enabled": self.__jiggler_enabled}
|
||||
return {
|
||||
"jiggler": {
|
||||
"enabled": self.__jiggler_enabled,
|
||||
"active": self.__jiggler_active,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
# =====
|
||||
|
||||
@@ -114,10 +114,11 @@ class BaseMcuHid(BaseHid, multiprocessing.Process): # pylint: disable=too-many-
|
||||
retries_delay: float,
|
||||
errors_threshold: int,
|
||||
noop: bool,
|
||||
jiggler: dict[str, Any],
|
||||
**gpio_kwargs: Any,
|
||||
) -> None:
|
||||
|
||||
BaseHid.__init__(self)
|
||||
BaseHid.__init__(self, **jiggler)
|
||||
multiprocessing.Process.__init__(self, daemon=True)
|
||||
|
||||
self.__read_retries = read_retries
|
||||
@@ -161,6 +162,8 @@ class BaseMcuHid(BaseHid, multiprocessing.Process): # pylint: disable=too-many-
|
||||
"retries_delay": Option(0.5, type=valid_float_f01),
|
||||
"errors_threshold": Option(5, type=valid_int_f0),
|
||||
"noop": Option(False, type=valid_bool),
|
||||
|
||||
**cls._get_jiggler_options(),
|
||||
}
|
||||
|
||||
def sysprep(self) -> None:
|
||||
@@ -226,7 +229,7 @@ class BaseMcuHid(BaseHid, multiprocessing.Process): # pylint: disable=too-many-
|
||||
"absolute": absolute,
|
||||
"outputs": mouse_outputs,
|
||||
},
|
||||
"jiggler": self._get_jiggler_state(),
|
||||
**self._get_jiggler_state(),
|
||||
}
|
||||
|
||||
async def poll_state(self) -> AsyncGenerator[dict, None]:
|
||||
@@ -287,7 +290,7 @@ class BaseMcuHid(BaseHid, multiprocessing.Process): # pylint: disable=too-many-
|
||||
for (index, event) in enumerate(events, 1):
|
||||
self.__queue_event(event, clear=(index == len(events)))
|
||||
if jiggler is not None:
|
||||
self._set_jiggler_enabled(jiggler)
|
||||
self._set_jiggler_active(jiggler)
|
||||
self.__notifier.notify()
|
||||
|
||||
def set_connected(self, connected: bool) -> None:
|
||||
|
||||
@@ -25,6 +25,7 @@ import time
|
||||
|
||||
from typing import Iterable
|
||||
from typing import AsyncGenerator
|
||||
from typing import Any
|
||||
|
||||
from ....logging import get_logger
|
||||
|
||||
@@ -61,6 +62,7 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes
|
||||
|
||||
def __init__( # pylint: disable=too-many-arguments,too-many-locals
|
||||
self,
|
||||
|
||||
manufacturer: str,
|
||||
product: str,
|
||||
description: str,
|
||||
@@ -76,9 +78,11 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes
|
||||
max_clients: int,
|
||||
socket_timeout: float,
|
||||
select_timeout: float,
|
||||
|
||||
jiggler: dict[str, Any],
|
||||
) -> None:
|
||||
|
||||
super().__init__()
|
||||
super().__init__(**jiggler)
|
||||
self._set_jiggler_absolute(False)
|
||||
|
||||
self.__proc: (multiprocessing.Process | None) = None
|
||||
@@ -121,6 +125,8 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes
|
||||
"max_clients": Option(1, type=valid_int_f1),
|
||||
"socket_timeout": Option(5.0, type=valid_float_f01),
|
||||
"select_timeout": Option(1.0, type=valid_float_f01),
|
||||
|
||||
**cls._get_jiggler_options(),
|
||||
}
|
||||
|
||||
def sysprep(self) -> None:
|
||||
@@ -149,7 +155,7 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes
|
||||
"absolute": False,
|
||||
"outputs": outputs,
|
||||
},
|
||||
"jiggler": self._get_jiggler_state(),
|
||||
**self._get_jiggler_state(),
|
||||
}
|
||||
|
||||
async def poll_state(self) -> AsyncGenerator[dict, None]:
|
||||
@@ -207,7 +213,7 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes
|
||||
_ = keyboard_output
|
||||
_ = mouse_output
|
||||
if jiggler is not None:
|
||||
self._set_jiggler_enabled(jiggler)
|
||||
self._set_jiggler_active(jiggler)
|
||||
self.__notifier.notify()
|
||||
|
||||
# =====
|
||||
|
||||
@@ -26,6 +26,7 @@ import time
|
||||
|
||||
from typing import Iterable
|
||||
from typing import AsyncGenerator
|
||||
from typing import Any
|
||||
|
||||
from ....logging import get_logger
|
||||
|
||||
@@ -56,9 +57,10 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
|
||||
device_path: str,
|
||||
speed: int,
|
||||
read_timeout: float,
|
||||
jiggler: dict[str, Any],
|
||||
) -> None:
|
||||
|
||||
BaseHid.__init__(self)
|
||||
BaseHid.__init__(self, **jiggler)
|
||||
multiprocessing.Process.__init__(self, daemon=True)
|
||||
|
||||
self.__device_path = device_path
|
||||
@@ -86,6 +88,7 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
|
||||
"device": Option("/dev/kvmd-hid", type=valid_abs_path, unpack_as="device_path"),
|
||||
"speed": Option(9600, type=valid_tty_speed),
|
||||
"read_timeout": Option(0.3, type=valid_float_f01),
|
||||
**cls._get_jiggler_options(),
|
||||
}
|
||||
|
||||
def sysprep(self) -> None:
|
||||
@@ -113,7 +116,7 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
|
||||
"active": ("usb" if absolute else "usb_rel"),
|
||||
},
|
||||
},
|
||||
"jiggler": self._get_jiggler_state(),
|
||||
**self._get_jiggler_state(),
|
||||
}
|
||||
|
||||
async def poll_state(self) -> AsyncGenerator[dict, None]:
|
||||
@@ -174,7 +177,7 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
|
||||
self._set_jiggler_absolute(absolute)
|
||||
self.__notifier.notify()
|
||||
if jiggler is not None:
|
||||
self._set_jiggler_enabled(jiggler)
|
||||
self._set_jiggler_active(jiggler)
|
||||
self.__notifier.notify()
|
||||
|
||||
def set_connected(self, connected: bool) -> None:
|
||||
|
||||
@@ -49,11 +49,12 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes
|
||||
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__()
|
||||
super().__init__(**jiggler)
|
||||
|
||||
self.__udc = udc
|
||||
|
||||
@@ -112,6 +113,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(),
|
||||
}
|
||||
|
||||
def sysprep(self) -> None:
|
||||
@@ -145,7 +147,7 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes
|
||||
},
|
||||
**mouse_state,
|
||||
},
|
||||
"jiggler": self._get_jiggler_state(),
|
||||
**self._get_jiggler_state(),
|
||||
}
|
||||
|
||||
async def poll_state(self) -> AsyncGenerator[dict, None]:
|
||||
@@ -210,7 +212,7 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes
|
||||
self._set_jiggler_absolute(self.__mouse_current.is_absolute())
|
||||
self.__notifier.notify()
|
||||
if jiggler is not None:
|
||||
self._set_jiggler_enabled(jiggler)
|
||||
self._set_jiggler_active(jiggler)
|
||||
self.__notifier.notify()
|
||||
|
||||
def clear_events(self) -> None:
|
||||
|
||||
Reference in New Issue
Block a user