summaryrefslogtreecommitdiff
path: root/kvmd/apps
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-05-23 11:57:19 +0300
committerDevaev Maxim <[email protected]>2020-05-23 11:57:19 +0300
commita795fe5ed63b960cbf24c9130ed37f9f7f33280c (patch)
tree51b884539614ed380cb19cd60e4dae7c8baab090 /kvmd/apps
parent17082c916a1d80d92bb5a51fed67f030f605f804 (diff)
additional keymapping info; refactoring
Diffstat (limited to 'kvmd/apps')
-rw-r--r--kvmd/apps/kvmd/api/hid.py4
-rw-r--r--kvmd/apps/vnc/__init__.py3
-rw-r--r--kvmd/apps/vnc/keysym.py97
3 files changed, 4 insertions, 100 deletions
diff --git a/kvmd/apps/kvmd/api/hid.py b/kvmd/apps/kvmd/api/hid.py
index 5283751a..8bdaac59 100644
--- a/kvmd/apps/kvmd/api/hid.py
+++ b/kvmd/apps/kvmd/api/hid.py
@@ -38,7 +38,7 @@ from ....validators.kvm import valid_hid_mouse_move
from ....validators.kvm import valid_hid_mouse_button
from ....validators.kvm import valid_hid_mouse_wheel
-from .... import keyprint
+from ....keyboard.printer import text_to_web_keys
from ..http import exposed_http
from ..http import exposed_ws
@@ -70,7 +70,7 @@ class HidApi:
if limit > 0:
text = text[:limit]
async with self.__key_lock:
- for (key, state) in keyprint.text_to_keys(text):
+ for (key, state) in text_to_web_keys(text):
self.__hid.send_key_event(key, state)
return make_json_response()
diff --git a/kvmd/apps/vnc/__init__.py b/kvmd/apps/vnc/__init__.py
index ef0f0c03..92fb073b 100644
--- a/kvmd/apps/vnc/__init__.py
+++ b/kvmd/apps/vnc/__init__.py
@@ -23,6 +23,8 @@
from typing import List
from typing import Optional
+from ...keyboard.keysym import build_symmap
+
from ...clients.kvmd import KvmdClient
from ...clients.streamer import StreamerClient
@@ -32,7 +34,6 @@ from .. import init
from .vncauth import VncAuthManager
from .server import VncServer
-from .keysym import build_symmap
# =====
diff --git a/kvmd/apps/vnc/keysym.py b/kvmd/apps/vnc/keysym.py
deleted file mode 100644
index 275eee5e..00000000
--- a/kvmd/apps/vnc/keysym.py
+++ /dev/null
@@ -1,97 +0,0 @@
-# ========================================================================== #
-# #
-# KVMD - The main Pi-KVM daemon. #
-# #
-# Copyright (C) 2020 Maxim Devaev <[email protected]> #
-# #
-# This program is free software: you can redistribute it and/or modify #
-# it under the terms of the GNU General Public License as published by #
-# the Free Software Foundation, either version 3 of the License, or #
-# (at your option) any later version. #
-# #
-# This program is distributed in the hope that it will be useful, #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
-# GNU General Public License for more details. #
-# #
-# You should have received a copy of the GNU General Public License #
-# along with this program. If not, see <https://www.gnu.org/licenses/>. #
-# #
-# ========================================================================== #
-
-
-import pkgutil
-import functools
-
-from typing import Dict
-
-import Xlib.keysymdef
-
-from ...logging import get_logger
-
-from ... import keymap
-
-
-# =====
-def build_symmap(path: str) -> Dict[int, str]:
- # https://github.com/qemu/qemu/blob/95a9457fd44ad97c518858a4e1586a5498f9773c/ui/keymaps.c
-
- symmap: Dict[int, str] = {}
- for (x11_code, at1_code) in keymap.X11_TO_AT1.items():
- symmap[x11_code] = keymap.AT1_TO_WEB[at1_code]
-
- for (x11_code, at1_code) in _read_keyboard_layout(path).items():
- if (web_name := keymap.AT1_TO_WEB.get(at1_code)) is not None:
- # mypy bug
- symmap[x11_code] = web_name # type: ignore
- return symmap
-
-
-# =====
-def _get_keysyms() -> Dict[str, int]:
- keysyms: Dict[str, int] = {}
- for (loader, module_name, _) in pkgutil.walk_packages(Xlib.keysymdef.__path__):
- module = loader.find_module(module_name).load_module(module_name)
- for keysym_name in dir(module):
- if keysym_name.startswith("XK_"):
- short_name = keysym_name[3:]
- if short_name.startswith("XF86_"):
- short_name = "XF86" + short_name[5:]
- # assert short_name not in keysyms, short_name
- keysyms[short_name] = int(getattr(module, keysym_name))
- return keysyms
-
-
-def _resolve_keysym(name: str) -> int:
- code = _get_keysyms().get(name)
- if code is not None:
- return code
- if len(name) == 5 and name[0] == "U": # Try unicode Uxxxx
- try:
- return int(name[1:], 16)
- except ValueError:
- pass
- return 0
-
-
-def _read_keyboard_layout(path: str) -> Dict[int, int]: # Keysym to evdev (at1)
- logger = get_logger(0)
- logger.info("Reading keyboard layout %s ...", path)
-
- with open(path) as layout_file:
- lines = list(map(str.strip, layout_file.read().split("\n")))
-
- layout: Dict[int, int] = {}
- for (number, line) in enumerate(lines):
- if len(line) == 0 or line.startswith(("#", "map ", "include ")):
- continue
-
- parts = line.split()
- if len(parts) >= 2:
- if (code := _resolve_keysym(parts[0])) != 0:
- try:
- layout[code] = int(parts[1], 16)
- except ValueError as err:
- logger.error("Can't parse layout line #%d: %s", number, str(err))
- return layout