mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 00:51:53 +08:00
vnc: qemu ext keys
This commit is contained in:
@@ -23,7 +23,6 @@
|
||||
import pkgutil
|
||||
import functools
|
||||
|
||||
from typing import Tuple
|
||||
from typing import List
|
||||
from typing import Dict
|
||||
|
||||
@@ -32,6 +31,7 @@ import Xlib.keysymdef
|
||||
from ..logging import get_logger
|
||||
|
||||
from .mappings import At1Key
|
||||
from .mappings import WebModifiers
|
||||
from .mappings import X11_TO_AT1
|
||||
from .mappings import AT1_TO_WEB
|
||||
|
||||
@@ -43,23 +43,6 @@ class SymmapModifiers:
|
||||
CTRL: int = 0x4
|
||||
|
||||
|
||||
def switch_symmap_modifiers(modifiers: int, code: int, state: bool) -> Tuple[bool, int]:
|
||||
mod = 0
|
||||
if code == 65505 or code == 65506: # XK_Shift_L, XK_Shift_R
|
||||
mod = SymmapModifiers.SHIFT
|
||||
elif code == 65027: # AltGR aka XK_ISO_Level3_Shift
|
||||
mod = SymmapModifiers.ALTGR
|
||||
elif code == 65507 or code == 65508: # XK_Control_L, XK_Control_R
|
||||
mod = SymmapModifiers.CTRL
|
||||
if mod == 0:
|
||||
return (False, modifiers)
|
||||
if state:
|
||||
modifiers |= mod
|
||||
else:
|
||||
modifiers &= ~mod
|
||||
return (True, modifiers)
|
||||
|
||||
|
||||
def build_symmap(path: str) -> Dict[int, Dict[int, str]]:
|
||||
# https://github.com/qemu/qemu/blob/95a9457fd44ad97c518858a4e1586a5498f9773c/ui/keymaps.c
|
||||
logger = get_logger()
|
||||
@@ -74,9 +57,9 @@ def build_symmap(path: str) -> Dict[int, Dict[int, str]]:
|
||||
web_name = AT1_TO_WEB.get(key.code)
|
||||
if web_name 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)
|
||||
(web_name in WebModifiers.SHIFTS and key.shift) # pylint: disable=too-many-boolean-expressions
|
||||
or (web_name in WebModifiers.ALTS and key.altgr)
|
||||
or (web_name in WebModifiers.CTRLS and key.ctrl)
|
||||
):
|
||||
logger.error("Invalid modifier key at mapping %s: %s / %s", src, web_name, key)
|
||||
continue
|
||||
|
||||
@@ -153,6 +153,33 @@ KEYMAP: Dict[str, Key] = {
|
||||
}
|
||||
|
||||
|
||||
# =====
|
||||
class WebModifiers:
|
||||
SHIFT_LEFT = "ShiftLeft"
|
||||
SHIFT_RIGHT = "ShiftRight"
|
||||
SHIFTS = set([SHIFT_LEFT, SHIFT_RIGHT])
|
||||
|
||||
ALT_LEFT = "AltLeft"
|
||||
ALT_RIGHT = "AltRight"
|
||||
ALTS = set([ALT_LEFT, ALT_RIGHT])
|
||||
|
||||
CTRL_LEFT = "ControlLeft"
|
||||
CTRL_RIGHT = "ControlRight"
|
||||
CTRLS = set([CTRL_RIGHT, CTRL_RIGHT])
|
||||
|
||||
|
||||
class X11Modifiers:
|
||||
SHIFT_LEFT = 65505
|
||||
SHIFT_RIGHT = 65506
|
||||
SHIFTS = set([SHIFT_LEFT, SHIFT_RIGHT])
|
||||
|
||||
ALTGR = 65027 # XK_ISO_Level3_Shift
|
||||
|
||||
CTRL_LEFT = 65507
|
||||
CTRL_RIGHT = 65508
|
||||
CTRLS = set([CTRL_LEFT, CTRL_RIGHT])
|
||||
|
||||
|
||||
# =====
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class At1Key:
|
||||
|
||||
@@ -50,6 +50,33 @@ KEYMAP: Dict[str, Key] = {
|
||||
}
|
||||
|
||||
|
||||
# =====
|
||||
class WebModifiers:
|
||||
SHIFT_LEFT = "ShiftLeft"
|
||||
SHIFT_RIGHT = "ShiftRight"
|
||||
SHIFTS = set([SHIFT_LEFT, SHIFT_RIGHT])
|
||||
|
||||
ALT_LEFT = "AltLeft"
|
||||
ALT_RIGHT = "AltRight"
|
||||
ALTS = set([ALT_LEFT, ALT_RIGHT])
|
||||
|
||||
CTRL_LEFT = "ControlLeft"
|
||||
CTRL_RIGHT = "ControlRight"
|
||||
CTRLS = set([CTRL_RIGHT, CTRL_RIGHT])
|
||||
|
||||
|
||||
class X11Modifiers:
|
||||
SHIFT_LEFT = 65505
|
||||
SHIFT_RIGHT = 65506
|
||||
SHIFTS = set([SHIFT_LEFT, SHIFT_RIGHT])
|
||||
|
||||
ALTGR = 65027 # XK_ISO_Level3_Shift
|
||||
|
||||
CTRL_LEFT = 65507
|
||||
CTRL_RIGHT = 65508
|
||||
CTRLS = set([CTRL_LEFT, CTRL_RIGHT])
|
||||
|
||||
|
||||
# =====
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class At1Key:
|
||||
|
||||
@@ -25,16 +25,17 @@ from typing import Dict
|
||||
from typing import Generator
|
||||
|
||||
from .keysym import SymmapModifiers
|
||||
from .mappings import WebModifiers
|
||||
|
||||
|
||||
# =====
|
||||
def text_to_web_keys(
|
||||
text: str,
|
||||
symmap: Dict[int, Dict[int, str]],
|
||||
shift_key: str="ShiftLeft",
|
||||
shift_key: str=WebModifiers.SHIFT_LEFT,
|
||||
) -> Generator[Tuple[str, bool], None, None]:
|
||||
|
||||
assert shift_key in ["ShiftLeft", "ShiftRight"]
|
||||
assert shift_key in WebModifiers.SHIFTS
|
||||
|
||||
shifted = False
|
||||
for ch in text:
|
||||
|
||||
Reference in New Issue
Block a user