summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kvmd/apps/kvmd/api/hid.py19
-rw-r--r--kvmd/plugins/hid/__init__.py9
-rw-r--r--kvmd/plugins/hid/_mcu/__init__.py14
-rw-r--r--web/share/js/kvm/hid.js2
4 files changed, 25 insertions, 19 deletions
diff --git a/kvmd/apps/kvmd/api/hid.py b/kvmd/apps/kvmd/api/hid.py
index 9c39ab20..8e667b79 100644
--- a/kvmd/apps/kvmd/api/hid.py
+++ b/kvmd/apps/kvmd/api/hid.py
@@ -69,14 +69,17 @@ class HidApi:
async def __state_handler(self, _: Request) -> Response:
return make_json_response(await self.__hid.get_state())
- @exposed_http("POST", "/hid/keyboard/set_params")
- async def __keyboard_set_params_handler(self, request: Request) -> Response:
- self.__hid.set_keyboard_output(valid_hid_keyboard_output(request.query.get("output")))
- return make_json_response()
-
- @exposed_http("POST", "/hid/mouse/set_params")
- async def __mouse_set_params_handler(self, request: Request) -> Response:
- self.__hid.set_mouse_output(valid_hid_mouse_output(request.query.get("output")))
+ @exposed_http("POST", "/hid/set_params")
+ async def __set_params_handler(self, request: Request) -> Response:
+ params = {
+ key: validator(request.query.get(key))
+ for (key, validator) in [
+ ("keyboard_output", valid_hid_keyboard_output),
+ ("mouse_output", valid_hid_mouse_output),
+ ]
+ if request.query.get(key) is not None
+ }
+ await self.__hid.set_params(**params) # type: ignore
return make_json_response()
@exposed_http("POST", "/hid/set_connected")
diff --git a/kvmd/plugins/hid/__init__.py b/kvmd/plugins/hid/__init__.py
index 0ba82e1b..c275f075 100644
--- a/kvmd/plugins/hid/__init__.py
+++ b/kvmd/plugins/hid/__init__.py
@@ -25,6 +25,7 @@ from typing import Dict
from typing import Iterable
from typing import AsyncGenerator
from typing import Type
+from typing import Optional
from .. import BasePlugin
from .. import get_plugin_class
@@ -67,11 +68,9 @@ class BaseHid(BasePlugin):
def send_mouse_wheel_event(self, delta_x: int, delta_y: int) -> None:
raise NotImplementedError
- def set_keyboard_output(self, output: str) -> None:
- _ = output
-
- def set_mouse_output(self, output: str) -> None:
- _ = output
+ def set_params(self, keyboard_output: Optional[str]=None, mouse_output: Optional[str]=None) -> None:
+ _ = keyboard_output
+ _ = mouse_output
def set_connected(self, connected: bool) -> None:
_ = connected
diff --git a/kvmd/plugins/hid/_mcu/__init__.py b/kvmd/plugins/hid/_mcu/__init__.py
index 242de465..45302ba1 100644
--- a/kvmd/plugins/hid/_mcu/__init__.py
+++ b/kvmd/plugins/hid/_mcu/__init__.py
@@ -31,6 +31,7 @@ from typing import Dict
from typing import Iterable
from typing import Generator
from typing import AsyncGenerator
+from typing import Optional
from ....logging import get_logger
@@ -252,11 +253,14 @@ class BaseMcuHid(BaseHid, multiprocessing.Process): # pylint: disable=too-many-
def send_mouse_wheel_event(self, delta_x: int, delta_y: int) -> None:
self.__queue_event(MouseWheelEvent(delta_x, delta_y))
- def set_keyboard_output(self, output: str) -> None:
- self.__queue_event(SetKeyboardOutputEvent(output), clear=True)
-
- def set_mouse_output(self, output: str) -> None:
- self.__queue_event(SetMouseOutputEvent(output), clear=True)
+ def set_params(self, keyboard_output: Optional[str]=None, mouse_output: Optional[str]=None) -> None:
+ events: List[BaseEvent] = []
+ if keyboard_output is not None:
+ events.append(SetKeyboardOutputEvent(keyboard_output))
+ if mouse_output is not None:
+ events.append(SetMouseOutputEvent(mouse_output))
+ for (index, event) in enumerate(events, 1):
+ self.__queue_event(event, clear=(index == len(events)))
def set_connected(self, connected: bool) -> None:
self.__queue_event(SetConnectedEvent(connected), clear=True)
diff --git a/web/share/js/kvm/hid.js b/web/share/js/kvm/hid.js
index bb00d4a7..abda40c5 100644
--- a/web/share/js/kvm/hid.js
+++ b/web/share/js/kvm/hid.js
@@ -231,7 +231,7 @@ export function Hid() {
var __clickOutputsRadio = function(hid) {
let output = tools.radioGetValue(`hid-outputs-${hid}-radio`);
- let http = tools.makeRequest("POST", `/api/hid/${hid}/set_params?output=${output}`, function() {
+ let http = tools.makeRequest("POST", `/api/hid/set_params?${hid}_output=${output}`, function() {
if (http.readyState === 4) {
if (http.status !== 200) {
wm.error("Can't configure HID:<br>", http.responseText);