diff options
author | Devaev Maxim <[email protected]> | 2020-05-25 01:39:12 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2020-05-25 01:39:18 +0300 |
commit | 499cbb0cc57346708525dd1d0059e65a74598980 (patch) | |
tree | 1985fdcfdafcddc2d34bbce0c16fe3cc5ba4617d /kvmd/keyboard | |
parent | eeece34312dc39f001c0718d07f12d90a279f736 (diff) |
improved some logging
Diffstat (limited to 'kvmd/keyboard')
-rw-r--r-- | kvmd/keyboard/keysym.py | 56 |
1 files changed, 26 insertions, 30 deletions
diff --git a/kvmd/keyboard/keysym.py b/kvmd/keyboard/keysym.py index 6517c7e1..3749f7da 100644 --- a/kvmd/keyboard/keysym.py +++ b/kvmd/keyboard/keysym.py @@ -25,7 +25,6 @@ import pkgutil import functools from typing import Dict -from typing import Optional import Xlib.keysymdef @@ -47,35 +46,32 @@ class SymmapWebKey: def build_symmap(path: str) -> Dict[int, SymmapWebKey]: # https://github.com/qemu/qemu/blob/95a9457fd44ad97c518858a4e1586a5498f9773c/ui/keymaps.c - return { - x11_code: web_key - for (x11_code, at1_key) in [ - *list(X11_TO_AT1.items()), - *list(_read_keyboard_layout(path).items()), - ] - if (web_key := _make_safe_web_key(at1_key)) is not None - } + logger = get_logger() + + symmap: Dict[int, SymmapWebKey] = {} + for (src, items) in [ + ("<builtin>", list(X11_TO_AT1.items())), + (path, list(_read_keyboard_layout(path).items())), + ]: + for (code, key) in items: + if (web_name := AT1_TO_WEB.get(key.code)) is not None: + if ( + (web_name in ["ShiftLeft", "ShiftRight"] and key.shift) # pylint: disable=too-many-boolean-expressions + or (web_name in ["AltLeft", "AltRight"] and key.altgr) + or (web_name in ["ControlLeft", "ControlRight"] and key.ctrl) + ): + logger.error("Invalid modifier key at mapping %s: %s / %s", src, web_name, key) + continue + symmap[code] = SymmapWebKey( + name=web_name, + shift=key.shift, + altgr=key.altgr, + ctrl=key.ctrl, + ) + return symmap # ===== -def _make_safe_web_key(key: At1Key) -> Optional[SymmapWebKey]: - if (web_name := AT1_TO_WEB.get(key.code)) is not None: - if ( - (web_name in ["ShiftLeft", "ShiftRight"] and key.shift) # pylint: disable=too-many-boolean-expressions - or (web_name in ["AltLeft", "AltRight"] and key.altgr) - or (web_name in ["ControlLeft", "ControlRight"] and key.ctrl) - ): - get_logger().error("Invalid modifier key: %s / %s", web_name, key) - return None # Ехал модификатор через модификатор - return SymmapWebKey( - name=web_name, - shift=key.shift, - altgr=key.altgr, - ctrl=key.ctrl, - ) - return None - - @functools.lru_cache() def _get_keysyms() -> Dict[str, int]: keysyms: Dict[str, int] = {} @@ -117,14 +113,14 @@ def _read_keyboard_layout(path: str) -> Dict[int, At1Key]: # Keysym to evdev (a parts = line.split() if len(parts) >= 2: - if (x11_code := _resolve_keysym(parts[0])) != 0: + if (code := _resolve_keysym(parts[0])) != 0: try: - layout[x11_code] = At1Key( + layout[code] = At1Key( code=int(parts[1], 16), shift=("shift" in parts[2:]), altgr=("altgr" in parts[2:]), ctrl=("ctrl" in parts[2:]), ) except ValueError as err: - logger.error("Can't parse layout line #%d: %s", number, str(err)) + logger.error("Syntax error at %s:%d: %s", path, number, err) return layout |