summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2023-10-26 08:28:18 +0300
committerMaxim Devaev <[email protected]>2023-10-26 08:28:18 +0300
commit7bb553110068fa0ae5a5ed230d58322ded385ade (patch)
tree810c056d9b03aea5b0c3929546b7b4486558297e
parentaec67270205ac9d149c0c71a1891f4942eba477b (diff)
option to disable jiggler
-rw-r--r--kvmd/plugins/hid/__init__.py34
-rw-r--r--kvmd/plugins/hid/_mcu/__init__.py9
-rw-r--r--kvmd/plugins/hid/bt/__init__.py12
-rw-r--r--kvmd/plugins/hid/ch9329/__init__.py9
-rw-r--r--kvmd/plugins/hid/otg/__init__.py8
-rw-r--r--web/kvm/index.html2
-rw-r--r--web/kvm/navbar-system.pug2
-rw-r--r--web/share/js/kvm/hid.js3
8 files changed, 58 insertions, 21 deletions
diff --git a/kvmd/plugins/hid/__init__.py b/kvmd/plugins/hid/__init__.py
index 32f7aef1..c58749b4 100644
--- a/kvmd/plugins/hid/__init__.py
+++ b/kvmd/plugins/hid/__init__.py
@@ -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,
+ },
+ }
# =====
diff --git a/kvmd/plugins/hid/_mcu/__init__.py b/kvmd/plugins/hid/_mcu/__init__.py
index bdd2ee32..7f5f7a74 100644
--- a/kvmd/plugins/hid/_mcu/__init__.py
+++ b/kvmd/plugins/hid/_mcu/__init__.py
@@ -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:
diff --git a/kvmd/plugins/hid/bt/__init__.py b/kvmd/plugins/hid/bt/__init__.py
index d8065c92..1b50f26a 100644
--- a/kvmd/plugins/hid/bt/__init__.py
+++ b/kvmd/plugins/hid/bt/__init__.py
@@ -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()
# =====
diff --git a/kvmd/plugins/hid/ch9329/__init__.py b/kvmd/plugins/hid/ch9329/__init__.py
index 7f846b2f..4e2be8c9 100644
--- a/kvmd/plugins/hid/ch9329/__init__.py
+++ b/kvmd/plugins/hid/ch9329/__init__.py
@@ -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:
diff --git a/kvmd/plugins/hid/otg/__init__.py b/kvmd/plugins/hid/otg/__init__.py
index 30357c9a..61b8a194 100644
--- a/kvmd/plugins/hid/otg/__init__.py
+++ b/kvmd/plugins/hid/otg/__init__.py
@@ -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:
diff --git a/web/kvm/index.html b/web/kvm/index.html
index 33533dc1..9338e756 100644
--- a/web/kvm/index.html
+++ b/web/kvm/index.html
@@ -350,7 +350,7 @@
</div>
</td>
</tr>
- <tr>
+ <tr class="feature-disabled" id="hid-jiggler">
<td>Mouse jiggler:</td>
<td align="right">
<div class="switch-box">
diff --git a/web/kvm/navbar-system.pug b/web/kvm/navbar-system.pug
index f41e0abb..d1016d42 100644
--- a/web/kvm/navbar-system.pug
+++ b/web/kvm/navbar-system.pug
@@ -103,7 +103,7 @@ li(id="system-dropdown" class="right")
table(class="kv")
tr(id="hid-connect" class="feature-disabled")
+menu_switch_notable("hid-connect-switch", "Connect HID to Server", true, true)
- tr
+ tr(id="hid-jiggler" class="feature-disabled")
+menu_switch_notable("hid-jiggler-switch", "Mouse jiggler", false, false)
tr
+menu_switch_notable("hid-mute-switch", "Mute HID input events", true, false)
diff --git a/web/share/js/kvm/hid.js b/web/share/js/kvm/hid.js
index 6d9d8597..c097c81d 100644
--- a/web/share/js/kvm/hid.js
+++ b/web/share/js/kvm/hid.js
@@ -133,7 +133,8 @@ export function Hid(__getGeometry, __recorder) {
let has_relative_squash = false;
if (state) {
- $("hid-jiggler-switch").checked = !!state.jiggler.enabled;
+ tools.feature.setEnabled($("hid-jiggler"), state.jiggler.enabled);
+ $("hid-jiggler-switch").checked = state.jiggler.active;
}
if (state && state.online) {
let keyboard_outputs = state.keyboard.outputs.available;