mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-09 19:56:48 +00:00
feat(console): typed text follows the VM's keyboard layout
"Type it" sent each character's keysym and let QEMU pick the key from its own US map, with Shift added for the US shifted characters. A VM on another layout got other characters: on Turkish Q, '"' typed 'İ', '@' typed "'", and ğ, ü, ş, ı, ö, ç typed nothing. The Clipboard dialog now asks for the VM's keyboard layout and remembers it per browser. Each character is typed as the key that makes it on that layout (its scancode), with Shift, AltGr or both (AltGr first: pressed after Shift, the right Alt is Alt on the Linux console), so the VM's own layout makes the character. The layout is fixed when typing starts. Text with a character no key types on the layout is not typed at all, and the dialog lists those characters: a password or a command with a character left out would be a wrong one. A layout is one file in console/layouts/: its name and, for each key, the characters it types plainly, with Shift, with AltGr and with Shift+AltGr. The view offers every file, US first. dev/console_layout.py writes a file from the system's XKB data as libxkbcommon computes it (through ctypes, no new dependency), mapping keys to DOM codes with noVNC's table from QEMU's keycodemapdb; it lists the dead keys it leaves out, and drops the keys the keyboard model lacks (the key left of Z on US pc104 keyboards). English (US) and Turkish Q come with it; the README says how to add one.
This commit is contained in:
parent
2b54198965
commit
bfa0fc9fe5
10 changed files with 431 additions and 21 deletions
|
|
@ -1,5 +1,9 @@
|
|||
# pylint: disable=no-name-in-module,no-member
|
||||
|
||||
import functools
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from appsettings.settings import app_settings
|
||||
from console import tokens
|
||||
from django.conf import settings
|
||||
|
|
@ -12,6 +16,22 @@ from vrtManager.connection import CONN_TCP, CONN_TLS
|
|||
from vrtManager.instance import wvmInstance
|
||||
from vrtManager.util import is_loopback
|
||||
|
||||
# one file a layout, written by dev/console_layout.py
|
||||
LAYOUTS_DIR = Path(__file__).resolve().parent / "layouts"
|
||||
|
||||
|
||||
@functools.cache
|
||||
def keyboard_layouts():
|
||||
"""The keyboard layouts the VNC console types text with, US first, then
|
||||
by name: {id: {"name": ..., "keys": {DOM code: [plain, Shift, AltGr,
|
||||
Shift+AltGr]}}}."""
|
||||
layouts = {}
|
||||
for path in LAYOUTS_DIR.glob("*.json"):
|
||||
layout = json.loads(path.read_text())
|
||||
layouts[path.stem] = {"name": layout["name"], "keys": layout["keys"]}
|
||||
us = layouts.pop("us")
|
||||
return {"us": us, **dict(sorted(layouts.items(), key=lambda item: item[1]["name"]))}
|
||||
|
||||
|
||||
def console(request, compute_id, uuid):
|
||||
"""The console page of the VM with this UUID on this compute. A console
|
||||
|
|
@ -89,4 +109,4 @@ def console(request, compute_id, uuid):
|
|||
"clip": app_settings.CONSOLE_CLIP_VIEWPORT == "True",
|
||||
"viewOnly": app_settings.CONSOLE_VIEW_ONLY == "True",
|
||||
}
|
||||
return render(request, "console-vnc.html", {"instance": instance, "vnc": vnc})
|
||||
return render(request, "console-vnc.html", {"instance": instance, "vnc": vnc, "layouts": keyboard_layouts()})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue