From d93639ba8dcd003f82221f4ed99159755f2213c3 Mon Sep 17 00:00:00 2001 From: Maxim Devaev Date: Sun, 3 Nov 2024 18:28:28 +0200 Subject: hid with granularity prototype --- kvmd/apps/vnc/server.py | 6 +++++- kvmd/plugins/hid/__init__.py | 13 +++++++++++++ kvmd/plugins/hid/_mcu/__init__.py | 1 + kvmd/plugins/hid/bt/__init__.py | 1 + kvmd/plugins/hid/ch9329/__init__.py | 1 + kvmd/plugins/hid/otg/__init__.py | 1 + 6 files changed, 22 insertions(+), 1 deletion(-) (limited to 'kvmd') diff --git a/kvmd/apps/vnc/server.py b/kvmd/apps/vnc/server.py index c14bb21f..e8524a38 100644 --- a/kvmd/apps/vnc/server.py +++ b/kvmd/apps/vnc/server.py @@ -189,7 +189,11 @@ class _Client(RfbClient): # pylint: disable=too-many-instance-attributes self.__shared_params.name = name elif event_type == "hid_state": - if self._encodings.has_leds_state: + if ( + self._encodings.has_leds_state + and ("keyboard" in event) + and ("leds" in event["keyboard"]) + ): await self._send_leds_state(**event["keyboard"]["leds"]) # ===== diff --git a/kvmd/plugins/hid/__init__.py b/kvmd/plugins/hid/__init__.py index f7debe1d..73ff5d04 100644 --- a/kvmd/plugins/hid/__init__.py +++ b/kvmd/plugins/hid/__init__.py @@ -101,6 +101,19 @@ class BaseHid(BasePlugin): # pylint: disable=too-many-instance-attributes raise NotImplementedError async def poll_state(self) -> AsyncGenerator[dict, None]: + # ==== Granularity table ==== + # - enabled -- Full + # - online -- Partial + # - busy -- Partial + # - connected -- Partial, nullable + # - keyboard.online -- Partial + # - keyboard.outputs -- Partial + # - keyboard.leds -- Partial + # - mouse.online -- Partial + # - mouse.outputs -- Partial, follows with absolute + # - mouse.absolute -- Partial, follows with outputs + # =========================== + yield {} raise NotImplementedError diff --git a/kvmd/plugins/hid/_mcu/__init__.py b/kvmd/plugins/hid/_mcu/__init__.py index a4c903b7..d6f04f76 100644 --- a/kvmd/plugins/hid/_mcu/__init__.py +++ b/kvmd/plugins/hid/_mcu/__init__.py @@ -217,6 +217,7 @@ class BaseMcuHid(BaseHid, multiprocessing.Process): # pylint: disable=too-many- mouse_outputs["active"] = active_mouse return { + "enabled": True, "online": online, "busy": bool(state["busy"]), "connected": (bool(outputs2 & 0b01000000) if outputs2 & 0b10000000 else None), diff --git a/kvmd/plugins/hid/bt/__init__.py b/kvmd/plugins/hid/bt/__init__.py index 4d0effb5..0c95a6d5 100644 --- a/kvmd/plugins/hid/bt/__init__.py +++ b/kvmd/plugins/hid/bt/__init__.py @@ -141,6 +141,7 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes state = await self.__server.get_state() outputs: dict = {"available": [], "active": ""} return { + "enabled": True, "online": True, "busy": False, "connected": None, diff --git a/kvmd/plugins/hid/ch9329/__init__.py b/kvmd/plugins/hid/ch9329/__init__.py index c5d10688..1b235090 100644 --- a/kvmd/plugins/hid/ch9329/__init__.py +++ b/kvmd/plugins/hid/ch9329/__init__.py @@ -104,6 +104,7 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst absolute = self.__mouse.is_absolute() leds = await self.__keyboard.get_leds() return { + "enabled": True, "online": state["online"], "busy": False, "connected": None, diff --git a/kvmd/plugins/hid/otg/__init__.py b/kvmd/plugins/hid/otg/__init__.py index c95fb7fb..25424257 100644 --- a/kvmd/plugins/hid/otg/__init__.py +++ b/kvmd/plugins/hid/otg/__init__.py @@ -134,6 +134,7 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes keyboard_state = await self.__keyboard_proc.get_state() mouse_state = await self.__mouse_current.get_state() return { + "enabled": True, "online": True, "busy": False, "connected": None, -- cgit v1.2.3