提交 ce93f64b 编写于 作者: D Daniel P. Berrange

Fix keymap used to talk with QEMU

The QEMU 'sendkey' command expects keys to be encoded in the same
way as the RFB extended keycode set. Specifically it wants extended
keys to have the high bit of the first byte set, while the Linux
XT KBD driver codeset uses the low bit of the second byte. To deal
with this we introduce a new keymap 'RFB' and use that in the QEMU
driver

* include/libvirt/libvirt.h.in: Add VIR_KEYCODE_SET_RFB
* src/qemu/qemu_driver.c: Use RFB keycode set instead of XT KBD
* src/util/virkeycode-mapgen.py: Auto-generate the RFB keycode
  set from the XT KBD set
* src/util/virkeycode.c: Add RFB keycode entry to table. Add a
  verify check on cardinality of the codeOffset table
上级 7ac78e32
......@@ -1875,6 +1875,7 @@ typedef enum {
VIR_KEYCODE_SET_XT_KBD = 6,
VIR_KEYCODE_SET_USB = 7,
VIR_KEYCODE_SET_WIN32 = 8,
VIR_KEYCODE_SET_RFB = 9,
VIR_KEYCODE_SET_LAST,
} virKeycodeSet;
......
......@@ -1889,17 +1889,17 @@ static int qemuDomainSendKey(virDomainPtr domain,
virCheckFlags(0, -1);
/* translate the keycode to XT_KBD for qemu driver */
if (codeset != VIR_KEYCODE_SET_XT_KBD) {
/* translate the keycode to RFB for qemu driver */
if (codeset != VIR_KEYCODE_SET_RFB) {
int i;
int keycode;
for (i = 0; i < nkeycodes; i++) {
keycode = virKeycodeValueTranslate(codeset, VIR_KEYCODE_SET_XT_KBD,
keycode = virKeycodeValueTranslate(codeset, VIR_KEYCODE_SET_RFB,
keycodes[i]);
if (keycode < 0) {
qemuReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot translate keycode %u of %s codeset to xt_kbd keycode"),
_("cannot translate keycode %u of %s codeset to rfb keycode"),
keycodes[i],
virKeycodeSetTypeToString(codeset));
return -1;
......
......@@ -14,6 +14,7 @@ import sys
import re
namecolums = (0,2,10)
xtkbdkey_index = 8
def quotestring(str):
if str[0] != '"':
......@@ -35,10 +36,21 @@ sys.stdin.readline() # eat the fist line.
for line in sys.stdin.xreadlines():
a = re.match("([^,]*)," * 13 + "([^,]*)$", line[0:-1]).groups()
b = ""
rfbkey = 0
for i in namecolums:
b = b + (a[i] and quotestring(a[i]) or 'NULL') + ','
for i in [ x for x in range(12) if not x in namecolums ]:
b = b + (a[i] or '0') + ','
if i == xtkbdkey_index:
# RFB keycodes are XT kbd keycodes with a slightly
# different encoding of 0xe0 scan codes. RFB uses
# the high bit of the first byte, instead of the low
# bit of the second byte.
rfbkey = int(a[i] or '0')
rfbkey = (rfbkey & 0x100) >> 1 | (rfbkey & 0x7f)
# Append RFB keycode as the last column
b = b + str(rfbkey)
print " { " + b + "},"
print '};'
......@@ -38,6 +38,7 @@ struct keycode {
unsigned short xt_kbd;
unsigned short usb;
unsigned short win32;
unsigned short rfb;
};
#define VIRT_KEY_INTERNAL
......@@ -62,7 +63,10 @@ static unsigned int codeOffset[] = {
offsetof(struct keycode, usb),
[VIR_KEYCODE_SET_WIN32] =
offsetof(struct keycode, win32),
[VIR_KEYCODE_SET_RFB] =
offsetof(struct keycode, rfb),
};
verify(ARRAY_CARDINALITY(codeOffset) == VIR_KEYCODE_SET_LAST);
VIR_ENUM_IMPL(virKeycodeSet, VIR_KEYCODE_SET_LAST,
"linux",
......@@ -74,6 +78,7 @@ VIR_ENUM_IMPL(virKeycodeSet, VIR_KEYCODE_SET_LAST,
"xt_kbd",
"usb",
"win32",
"rfb",
);
static int __virKeycodeValueFromString(unsigned int name_offset,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册