* [Qemu-devel] [PATCH 0/3] Fix qemu keymaps, part one
@ 2017-07-24 14:01 Gerd Hoffmann
  2017-07-24 14:01 ` [Qemu-devel] [PATCH 1/3] keysym: add next and prior Gerd Hoffmann
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Gerd Hoffmann @ 2017-07-24 14:01 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann
qemu carries a bunch of reverse keymaps in pc-bios/keymaps/, to map
keysyms it receives from vnc clients back to keycodes.  These keymaps
seem to be buggy and incomplete at times.  So, to tackle the issue once
for all, I've written a tool to generate those maps from xkb keyboard
layout data using libxkbcommon.
This patch series only adds the tool, it doesn't touch the maps in
pc-bios/keymaps/ yet.  I want some testing feedback first ...
How to test:
  (1) generate a map: "qemu-keymap -f testmap -l $layout"
  (2) use the map: "qemu -vnc $display -k testmap"
Gerd Hoffmann (3):
  keysym: add next and prior
  ui: move qemu_input_linux_to_qcode()
  Add qemu-keymap tool.
 configure          |  23 +++++
 Makefile           |   5 ++
 include/ui/input.h |   1 +
 ui/curses_keys.h   |   2 +
 ui/vnc_keysym.h    |   2 +
 qemu-keymap.c      | 243 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 ui/input-keymap.c  | 115 +++++++++++++++++++++++++
 ui/input-linux.c   | 113 -------------------------
 8 files changed, 391 insertions(+), 113 deletions(-)
 create mode 100644 qemu-keymap.c
-- 
2.9.3
^ permalink raw reply	[flat|nested] 7+ messages in thread
* [Qemu-devel] [PATCH 1/3] keysym: add next and prior
  2017-07-24 14:01 [Qemu-devel] [PATCH 0/3] Fix qemu keymaps, part one Gerd Hoffmann
@ 2017-07-24 14:01 ` Gerd Hoffmann
  2017-07-24 14:01 ` [Qemu-devel] [PATCH 2/3] ui: move qemu_input_linux_to_qcode() Gerd Hoffmann
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Gerd Hoffmann @ 2017-07-24 14:01 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann
Page-up and Page-down where renamed.  Add the names to the keysym list
so we can parse both old and new names.  The keypad versions are already
present in the vnc map.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/curses_keys.h | 2 ++
 ui/vnc_keysym.h  | 2 ++
 2 files changed, 4 insertions(+)
diff --git a/ui/curses_keys.h b/ui/curses_keys.h
index e39ef9e718..e9195a1671 100644
--- a/ui/curses_keys.h
+++ b/ui/curses_keys.h
@@ -480,7 +480,9 @@ static const name2keysym_t name2keysym[] = {
     { "Left", KEY_LEFT },
     { "Up", KEY_UP },
     { "Down", KEY_DOWN },
+    { "Next", KEY_NPAGE },
     { "Page_Down", KEY_NPAGE },
+    { "Prior", KEY_PPAGE },
     { "Page_Up", KEY_PPAGE },
     { "Insert", KEY_IC },
     { "Delete", KEY_DC },
diff --git a/ui/vnc_keysym.h b/ui/vnc_keysym.h
index 7fa2bc1f1c..e8a2ec73c5 100644
--- a/ui/vnc_keysym.h
+++ b/ui/vnc_keysym.h
@@ -254,7 +254,9 @@ static const name2keysym_t name2keysym[]={
 {"Left", 0xff51},      /* XK_Left */
 {"Up", 0xff52},        /* XK_Up */
 {"Down", 0xff54},      /* XK_Down */
+{"Next", 0xff56},
 {"Page_Down", 0xff56}, /* XK_Page_Down */
+{"Prior", 0xff55},
 {"Page_Up", 0xff55},   /* XK_Page_Up */
 {"Insert", 0xff63},    /* XK_Insert */
 {"Delete", 0xffff},    /* XK_Delete */
-- 
2.9.3
^ permalink raw reply related	[flat|nested] 7+ messages in thread
* [Qemu-devel] [PATCH 2/3] ui: move qemu_input_linux_to_qcode()
  2017-07-24 14:01 [Qemu-devel] [PATCH 0/3] Fix qemu keymaps, part one Gerd Hoffmann
  2017-07-24 14:01 ` [Qemu-devel] [PATCH 1/3] keysym: add next and prior Gerd Hoffmann
@ 2017-07-24 14:01 ` Gerd Hoffmann
  2017-07-24 14:01 ` [Qemu-devel] [PATCH 3/3] Add qemu-keymap tool Gerd Hoffmann
  2017-07-24 14:18 ` [Qemu-devel] [PATCH 0/3] Fix qemu keymaps, part one Daniel P. Berrange
  3 siblings, 0 replies; 7+ messages in thread
From: Gerd Hoffmann @ 2017-07-24 14:01 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann
Move from input-linux.c to input-keymap.c and export it,
so the function is available elsewhere too.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/ui/input.h |   1 +
 ui/input-keymap.c  | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 ui/input-linux.c   | 113 ----------------------------------------------------
 3 files changed, 116 insertions(+), 113 deletions(-)
diff --git a/include/ui/input.h b/include/ui/input.h
index 3cfd0f3363..c488585def 100644
--- a/include/ui/input.h
+++ b/include/ui/input.h
@@ -48,6 +48,7 @@ int qemu_input_key_value_to_number(const KeyValue *value);
 int qemu_input_key_value_to_qcode(const KeyValue *value);
 int qemu_input_key_value_to_scancode(const KeyValue *value, bool down,
                                      int *codes);
+int qemu_input_linux_to_qcode(unsigned int lnx);
 
 InputEvent *qemu_input_event_new_btn(InputButton btn, bool down);
 void qemu_input_queue_btn(QemuConsole *src, InputButton btn, bool down);
diff --git a/ui/input-keymap.c b/ui/input-keymap.c
index 8a1476fc48..d4972bb364 100644
--- a/ui/input-keymap.c
+++ b/ui/input-keymap.c
@@ -3,6 +3,115 @@
 #include "ui/keymaps.h"
 #include "ui/input.h"
 
+#include "standard-headers/linux/input.h"
+
+static int linux_to_qcode[KEY_CNT] = {
+    [KEY_ESC]            = Q_KEY_CODE_ESC,
+    [KEY_1]              = Q_KEY_CODE_1,
+    [KEY_2]              = Q_KEY_CODE_2,
+    [KEY_3]              = Q_KEY_CODE_3,
+    [KEY_4]              = Q_KEY_CODE_4,
+    [KEY_5]              = Q_KEY_CODE_5,
+    [KEY_6]              = Q_KEY_CODE_6,
+    [KEY_7]              = Q_KEY_CODE_7,
+    [KEY_8]              = Q_KEY_CODE_8,
+    [KEY_9]              = Q_KEY_CODE_9,
+    [KEY_0]              = Q_KEY_CODE_0,
+    [KEY_MINUS]          = Q_KEY_CODE_MINUS,
+    [KEY_EQUAL]          = Q_KEY_CODE_EQUAL,
+    [KEY_BACKSPACE]      = Q_KEY_CODE_BACKSPACE,
+    [KEY_TAB]            = Q_KEY_CODE_TAB,
+    [KEY_Q]              = Q_KEY_CODE_Q,
+    [KEY_W]              = Q_KEY_CODE_W,
+    [KEY_E]              = Q_KEY_CODE_E,
+    [KEY_R]              = Q_KEY_CODE_R,
+    [KEY_T]              = Q_KEY_CODE_T,
+    [KEY_Y]              = Q_KEY_CODE_Y,
+    [KEY_U]              = Q_KEY_CODE_U,
+    [KEY_I]              = Q_KEY_CODE_I,
+    [KEY_O]              = Q_KEY_CODE_O,
+    [KEY_P]              = Q_KEY_CODE_P,
+    [KEY_LEFTBRACE]      = Q_KEY_CODE_BRACKET_LEFT,
+    [KEY_RIGHTBRACE]     = Q_KEY_CODE_BRACKET_RIGHT,
+    [KEY_ENTER]          = Q_KEY_CODE_RET,
+    [KEY_LEFTCTRL]       = Q_KEY_CODE_CTRL,
+    [KEY_A]              = Q_KEY_CODE_A,
+    [KEY_S]              = Q_KEY_CODE_S,
+    [KEY_D]              = Q_KEY_CODE_D,
+    [KEY_F]              = Q_KEY_CODE_F,
+    [KEY_G]              = Q_KEY_CODE_G,
+    [KEY_H]              = Q_KEY_CODE_H,
+    [KEY_J]              = Q_KEY_CODE_J,
+    [KEY_K]              = Q_KEY_CODE_K,
+    [KEY_L]              = Q_KEY_CODE_L,
+    [KEY_SEMICOLON]      = Q_KEY_CODE_SEMICOLON,
+    [KEY_APOSTROPHE]     = Q_KEY_CODE_APOSTROPHE,
+    [KEY_GRAVE]          = Q_KEY_CODE_GRAVE_ACCENT,
+    [KEY_LEFTSHIFT]      = Q_KEY_CODE_SHIFT,
+    [KEY_BACKSLASH]      = Q_KEY_CODE_BACKSLASH,
+    [KEY_102ND]          = Q_KEY_CODE_LESS,
+    [KEY_Z]              = Q_KEY_CODE_Z,
+    [KEY_X]              = Q_KEY_CODE_X,
+    [KEY_C]              = Q_KEY_CODE_C,
+    [KEY_V]              = Q_KEY_CODE_V,
+    [KEY_B]              = Q_KEY_CODE_B,
+    [KEY_N]              = Q_KEY_CODE_N,
+    [KEY_M]              = Q_KEY_CODE_M,
+    [KEY_COMMA]          = Q_KEY_CODE_COMMA,
+    [KEY_DOT]            = Q_KEY_CODE_DOT,
+    [KEY_SLASH]          = Q_KEY_CODE_SLASH,
+    [KEY_RIGHTSHIFT]     = Q_KEY_CODE_SHIFT_R,
+    [KEY_LEFTALT]        = Q_KEY_CODE_ALT,
+    [KEY_SPACE]          = Q_KEY_CODE_SPC,
+    [KEY_CAPSLOCK]       = Q_KEY_CODE_CAPS_LOCK,
+    [KEY_F1]             = Q_KEY_CODE_F1,
+    [KEY_F2]             = Q_KEY_CODE_F2,
+    [KEY_F3]             = Q_KEY_CODE_F3,
+    [KEY_F4]             = Q_KEY_CODE_F4,
+    [KEY_F5]             = Q_KEY_CODE_F5,
+    [KEY_F6]             = Q_KEY_CODE_F6,
+    [KEY_F7]             = Q_KEY_CODE_F7,
+    [KEY_F8]             = Q_KEY_CODE_F8,
+    [KEY_F9]             = Q_KEY_CODE_F9,
+    [KEY_F10]            = Q_KEY_CODE_F10,
+    [KEY_NUMLOCK]        = Q_KEY_CODE_NUM_LOCK,
+    [KEY_SCROLLLOCK]     = Q_KEY_CODE_SCROLL_LOCK,
+    [KEY_KP0]            = Q_KEY_CODE_KP_0,
+    [KEY_KP1]            = Q_KEY_CODE_KP_1,
+    [KEY_KP2]            = Q_KEY_CODE_KP_2,
+    [KEY_KP3]            = Q_KEY_CODE_KP_3,
+    [KEY_KP4]            = Q_KEY_CODE_KP_4,
+    [KEY_KP5]            = Q_KEY_CODE_KP_5,
+    [KEY_KP6]            = Q_KEY_CODE_KP_6,
+    [KEY_KP7]            = Q_KEY_CODE_KP_7,
+    [KEY_KP8]            = Q_KEY_CODE_KP_8,
+    [KEY_KP9]            = Q_KEY_CODE_KP_9,
+    [KEY_KPMINUS]        = Q_KEY_CODE_KP_SUBTRACT,
+    [KEY_KPPLUS]         = Q_KEY_CODE_KP_ADD,
+    [KEY_KPDOT]          = Q_KEY_CODE_KP_DECIMAL,
+    [KEY_KPENTER]        = Q_KEY_CODE_KP_ENTER,
+    [KEY_KPSLASH]        = Q_KEY_CODE_KP_DIVIDE,
+    [KEY_KPASTERISK]     = Q_KEY_CODE_KP_MULTIPLY,
+    [KEY_F11]            = Q_KEY_CODE_F11,
+    [KEY_F12]            = Q_KEY_CODE_F12,
+    [KEY_RIGHTCTRL]      = Q_KEY_CODE_CTRL_R,
+    [KEY_SYSRQ]          = Q_KEY_CODE_SYSRQ,
+    [KEY_RIGHTALT]       = Q_KEY_CODE_ALT_R,
+    [KEY_HOME]           = Q_KEY_CODE_HOME,
+    [KEY_UP]             = Q_KEY_CODE_UP,
+    [KEY_PAGEUP]         = Q_KEY_CODE_PGUP,
+    [KEY_LEFT]           = Q_KEY_CODE_LEFT,
+    [KEY_RIGHT]          = Q_KEY_CODE_RIGHT,
+    [KEY_END]            = Q_KEY_CODE_END,
+    [KEY_DOWN]           = Q_KEY_CODE_DOWN,
+    [KEY_PAGEDOWN]       = Q_KEY_CODE_PGDN,
+    [KEY_INSERT]         = Q_KEY_CODE_INSERT,
+    [KEY_DELETE]         = Q_KEY_CODE_DELETE,
+    [KEY_LEFTMETA]       = Q_KEY_CODE_META_L,
+    [KEY_RIGHTMETA]      = Q_KEY_CODE_META_R,
+    [KEY_MENU]           = Q_KEY_CODE_MENU,
+};
+
 static const int qcode_to_number[] = {
     [Q_KEY_CODE_SHIFT] = 0x2a,
     [Q_KEY_CODE_SHIFT_R] = 0x36,
@@ -141,6 +250,12 @@ static const int qcode_to_number[] = {
 
 static int number_to_qcode[0x100];
 
+int qemu_input_linux_to_qcode(unsigned int lnx)
+{
+    assert(lnx < KEY_CNT);
+    return linux_to_qcode[lnx];
+}
+
 int qemu_input_key_value_to_number(const KeyValue *value)
 {
     if (value->type == KEY_VALUE_KIND_QCODE) {
diff --git a/ui/input-linux.c b/ui/input-linux.c
index 49d52a69cc..9720333b2c 100644
--- a/ui/input-linux.c
+++ b/ui/input-linux.c
@@ -16,119 +16,6 @@
 #include <sys/ioctl.h>
 #include "standard-headers/linux/input.h"
 
-static int linux_to_qcode[KEY_CNT] = {
-    [KEY_ESC]            = Q_KEY_CODE_ESC,
-    [KEY_1]              = Q_KEY_CODE_1,
-    [KEY_2]              = Q_KEY_CODE_2,
-    [KEY_3]              = Q_KEY_CODE_3,
-    [KEY_4]              = Q_KEY_CODE_4,
-    [KEY_5]              = Q_KEY_CODE_5,
-    [KEY_6]              = Q_KEY_CODE_6,
-    [KEY_7]              = Q_KEY_CODE_7,
-    [KEY_8]              = Q_KEY_CODE_8,
-    [KEY_9]              = Q_KEY_CODE_9,
-    [KEY_0]              = Q_KEY_CODE_0,
-    [KEY_MINUS]          = Q_KEY_CODE_MINUS,
-    [KEY_EQUAL]          = Q_KEY_CODE_EQUAL,
-    [KEY_BACKSPACE]      = Q_KEY_CODE_BACKSPACE,
-    [KEY_TAB]            = Q_KEY_CODE_TAB,
-    [KEY_Q]              = Q_KEY_CODE_Q,
-    [KEY_W]              = Q_KEY_CODE_W,
-    [KEY_E]              = Q_KEY_CODE_E,
-    [KEY_R]              = Q_KEY_CODE_R,
-    [KEY_T]              = Q_KEY_CODE_T,
-    [KEY_Y]              = Q_KEY_CODE_Y,
-    [KEY_U]              = Q_KEY_CODE_U,
-    [KEY_I]              = Q_KEY_CODE_I,
-    [KEY_O]              = Q_KEY_CODE_O,
-    [KEY_P]              = Q_KEY_CODE_P,
-    [KEY_LEFTBRACE]      = Q_KEY_CODE_BRACKET_LEFT,
-    [KEY_RIGHTBRACE]     = Q_KEY_CODE_BRACKET_RIGHT,
-    [KEY_ENTER]          = Q_KEY_CODE_RET,
-    [KEY_LEFTCTRL]       = Q_KEY_CODE_CTRL,
-    [KEY_A]              = Q_KEY_CODE_A,
-    [KEY_S]              = Q_KEY_CODE_S,
-    [KEY_D]              = Q_KEY_CODE_D,
-    [KEY_F]              = Q_KEY_CODE_F,
-    [KEY_G]              = Q_KEY_CODE_G,
-    [KEY_H]              = Q_KEY_CODE_H,
-    [KEY_J]              = Q_KEY_CODE_J,
-    [KEY_K]              = Q_KEY_CODE_K,
-    [KEY_L]              = Q_KEY_CODE_L,
-    [KEY_SEMICOLON]      = Q_KEY_CODE_SEMICOLON,
-    [KEY_APOSTROPHE]     = Q_KEY_CODE_APOSTROPHE,
-    [KEY_GRAVE]          = Q_KEY_CODE_GRAVE_ACCENT,
-    [KEY_LEFTSHIFT]      = Q_KEY_CODE_SHIFT,
-    [KEY_BACKSLASH]      = Q_KEY_CODE_BACKSLASH,
-    [KEY_102ND]          = Q_KEY_CODE_LESS,
-    [KEY_Z]              = Q_KEY_CODE_Z,
-    [KEY_X]              = Q_KEY_CODE_X,
-    [KEY_C]              = Q_KEY_CODE_C,
-    [KEY_V]              = Q_KEY_CODE_V,
-    [KEY_B]              = Q_KEY_CODE_B,
-    [KEY_N]              = Q_KEY_CODE_N,
-    [KEY_M]              = Q_KEY_CODE_M,
-    [KEY_COMMA]          = Q_KEY_CODE_COMMA,
-    [KEY_DOT]            = Q_KEY_CODE_DOT,
-    [KEY_SLASH]          = Q_KEY_CODE_SLASH,
-    [KEY_RIGHTSHIFT]     = Q_KEY_CODE_SHIFT_R,
-    [KEY_LEFTALT]        = Q_KEY_CODE_ALT,
-    [KEY_SPACE]          = Q_KEY_CODE_SPC,
-    [KEY_CAPSLOCK]       = Q_KEY_CODE_CAPS_LOCK,
-    [KEY_F1]             = Q_KEY_CODE_F1,
-    [KEY_F2]             = Q_KEY_CODE_F2,
-    [KEY_F3]             = Q_KEY_CODE_F3,
-    [KEY_F4]             = Q_KEY_CODE_F4,
-    [KEY_F5]             = Q_KEY_CODE_F5,
-    [KEY_F6]             = Q_KEY_CODE_F6,
-    [KEY_F7]             = Q_KEY_CODE_F7,
-    [KEY_F8]             = Q_KEY_CODE_F8,
-    [KEY_F9]             = Q_KEY_CODE_F9,
-    [KEY_F10]            = Q_KEY_CODE_F10,
-    [KEY_NUMLOCK]        = Q_KEY_CODE_NUM_LOCK,
-    [KEY_SCROLLLOCK]     = Q_KEY_CODE_SCROLL_LOCK,
-    [KEY_KP0]            = Q_KEY_CODE_KP_0,
-    [KEY_KP1]            = Q_KEY_CODE_KP_1,
-    [KEY_KP2]            = Q_KEY_CODE_KP_2,
-    [KEY_KP3]            = Q_KEY_CODE_KP_3,
-    [KEY_KP4]            = Q_KEY_CODE_KP_4,
-    [KEY_KP5]            = Q_KEY_CODE_KP_5,
-    [KEY_KP6]            = Q_KEY_CODE_KP_6,
-    [KEY_KP7]            = Q_KEY_CODE_KP_7,
-    [KEY_KP8]            = Q_KEY_CODE_KP_8,
-    [KEY_KP9]            = Q_KEY_CODE_KP_9,
-    [KEY_KPMINUS]        = Q_KEY_CODE_KP_SUBTRACT,
-    [KEY_KPPLUS]         = Q_KEY_CODE_KP_ADD,
-    [KEY_KPDOT]          = Q_KEY_CODE_KP_DECIMAL,
-    [KEY_KPENTER]        = Q_KEY_CODE_KP_ENTER,
-    [KEY_KPSLASH]        = Q_KEY_CODE_KP_DIVIDE,
-    [KEY_KPASTERISK]     = Q_KEY_CODE_KP_MULTIPLY,
-    [KEY_F11]            = Q_KEY_CODE_F11,
-    [KEY_F12]            = Q_KEY_CODE_F12,
-    [KEY_RIGHTCTRL]      = Q_KEY_CODE_CTRL_R,
-    [KEY_SYSRQ]          = Q_KEY_CODE_SYSRQ,
-    [KEY_RIGHTALT]       = Q_KEY_CODE_ALT_R,
-    [KEY_HOME]           = Q_KEY_CODE_HOME,
-    [KEY_UP]             = Q_KEY_CODE_UP,
-    [KEY_PAGEUP]         = Q_KEY_CODE_PGUP,
-    [KEY_LEFT]           = Q_KEY_CODE_LEFT,
-    [KEY_RIGHT]          = Q_KEY_CODE_RIGHT,
-    [KEY_END]            = Q_KEY_CODE_END,
-    [KEY_DOWN]           = Q_KEY_CODE_DOWN,
-    [KEY_PAGEDOWN]       = Q_KEY_CODE_PGDN,
-    [KEY_INSERT]         = Q_KEY_CODE_INSERT,
-    [KEY_DELETE]         = Q_KEY_CODE_DELETE,
-    [KEY_LEFTMETA]       = Q_KEY_CODE_META_L,
-    [KEY_RIGHTMETA]      = Q_KEY_CODE_META_R,
-    [KEY_MENU]           = Q_KEY_CODE_MENU,
-};
-
-static int qemu_input_linux_to_qcode(unsigned int lnx)
-{
-    assert(lnx < KEY_CNT);
-    return linux_to_qcode[lnx];
-}
-
 static bool linux_is_button(unsigned int lnx)
 {
     if (lnx < 0x100) {
-- 
2.9.3
^ permalink raw reply related	[flat|nested] 7+ messages in thread
* [Qemu-devel] [PATCH 3/3] Add qemu-keymap tool.
  2017-07-24 14:01 [Qemu-devel] [PATCH 0/3] Fix qemu keymaps, part one Gerd Hoffmann
  2017-07-24 14:01 ` [Qemu-devel] [PATCH 1/3] keysym: add next and prior Gerd Hoffmann
  2017-07-24 14:01 ` [Qemu-devel] [PATCH 2/3] ui: move qemu_input_linux_to_qcode() Gerd Hoffmann
@ 2017-07-24 14:01 ` Gerd Hoffmann
  2017-07-24 14:18 ` [Qemu-devel] [PATCH 0/3] Fix qemu keymaps, part one Daniel P. Berrange
  3 siblings, 0 replies; 7+ messages in thread
From: Gerd Hoffmann @ 2017-07-24 14:01 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann
qemu-keymap generates qemu reverse keymaps from xkb keymaps,
which can be used with the qemu "-k" command line switch.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 configure     |  23 ++++++
 Makefile      |   5 ++
 qemu-keymap.c | 243 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 271 insertions(+)
 create mode 100644 qemu-keymap.c
diff --git a/configure b/configure
index c573a777fc..e8e074c5f9 100755
--- a/configure
+++ b/configure
@@ -292,6 +292,7 @@ vde=""
 vnc_sasl=""
 vnc_jpeg=""
 vnc_png=""
+xkbcommon=""
 xen=""
 xen_ctrl_version=""
 xen_pv_domain_build="no"
@@ -2912,6 +2913,21 @@ EOF
 fi
 
 ##########################################
+# xkbcommon probe
+if test "$xkbcommon" != "no" ; then
+  if $pkg_config xkbcommon --exists; then
+    xkbcommon_cflags=$($pkg_config xkbcommon --cflags)
+    xkbcommon_libs=$($pkg_config xkbcommon --libs)
+    xkbcommon=yes
+  else
+    if test "$xkbcommon" = "yes" ; then
+      feature_not_found "xkbcommon" "Install libxkbcommon-devel"
+    fi
+    xkbcommon=no
+  fi
+fi
+
+##########################################
 # fnmatch() probe, used for ACL routines
 fnmatch="no"
 cat > $TMPC << EOF
@@ -5066,6 +5082,9 @@ if test "$softmmu" = yes ; then
     fi
   fi
 fi
+if test "$xkbcommon" = "yes"; then
+  tools="qemu-keymap\$(EXESUF) $tools"
+fi
 
 # Probe for guest agent support/options
 
@@ -5562,6 +5581,10 @@ fi
 if test "$vnc_png" = "yes" ; then
   echo "CONFIG_VNC_PNG=y" >> $config_host_mak
 fi
+if test "$xkbcommon" = "yes" ; then
+  echo "XKBCOMMON_CFLAGS=$xkbcommon_cflags" >> $config_host_mak
+  echo "XKBCOMMON_LIBS=$xkbcommon_libs" >> $config_host_mak
+fi
 if test "$fnmatch" = "yes" ; then
   echo "CONFIG_FNMATCH=y" >> $config_host_mak
 fi
diff --git a/Makefile b/Makefile
index ef721480eb..0b8ddfd2dd 100644
--- a/Makefile
+++ b/Makefile
@@ -381,6 +381,8 @@ qemu-io$(EXESUF): qemu-io.o $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj
 
 qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o $(COMMON_LDADDS)
 
+qemu-keymap$(EXESUF): qemu-keymap.o ui/input-keymap.o
+
 fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/9p-marshal.o fsdev/9p-iov-marshal.o $(COMMON_LDADDS)
 fsdev/virtfs-proxy-helper$(EXESUF): LIBS += -lcap
 
@@ -390,6 +392,9 @@ qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx $(SRC_PATH)/scripts/hxtool
 qemu-ga$(EXESUF): LIBS = $(LIBS_QGA)
 qemu-ga$(EXESUF): QEMU_CFLAGS += -I qga/qapi-generated
 
+qemu-keymap$(EXESUF): LIBS = $(XKBCOMMON_LIBS)
+qemu-keymap$(EXESUF): QEMU_CFLAGS += $(XKBCOMMON_CFLAGS)
+
 gen-out-type = $(subst .,-,$(suffix $@))
 
 qapi-py = $(SRC_PATH)/scripts/qapi.py $(SRC_PATH)/scripts/ordereddict.py
diff --git a/qemu-keymap.c b/qemu-keymap.c
new file mode 100644
index 0000000000..950fd54bdc
--- /dev/null
+++ b/qemu-keymap.c
@@ -0,0 +1,243 @@
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "qapi-types.h"
+#include "qemu/notify.h"
+#include "ui/input.h"
+
+#include <xkbcommon/xkbcommon.h>
+
+struct xkb_rule_names names = {
+    .rules   = NULL,
+    .model   = "pc105",
+    .layout  = "us",
+    .variant = NULL,
+    .options = NULL,
+};
+
+static xkb_mod_mask_t shift;
+static xkb_mod_mask_t ctrl;
+static xkb_mod_mask_t altgr;
+
+static xkb_mod_mask_t numlock;
+
+static FILE *outfile;
+
+/* ------------------------------------------------------------------------ */
+
+static void print_sym(xkb_keysym_t sym, uint32_t number, const char *mod)
+{
+    char name[64];
+
+    if (sym == XKB_KEY_NoSymbol) {
+        return;
+    }
+    xkb_keysym_get_name(sym, name, sizeof(name));
+    fprintf(outfile, "%s 0x%02x%s\n", name, number, mod);
+}
+
+static void walk_map(struct xkb_keymap *map, xkb_keycode_t code, void *data)
+{
+    struct xkb_state *state = data;
+    xkb_keysym_t kbase, knumlock, kshift, kaltgr, kaltgrshift;
+    uint32_t evdev, qcode, number;
+    KeyValue keyvalue;
+    char name[64];
+
+    fprintf(outfile, "\n");
+
+    /*
+     * map xkb keycode -> QKeyCode
+     *
+     * xkb keycode is linux evdev shifted by 8
+     */
+    evdev = code - 8;
+    qcode = qemu_input_linux_to_qcode(evdev);
+    if (qcode == Q_KEY_CODE_UNMAPPED) {
+        fprintf(outfile, "# evdev %d (0x%x): no evdev -> qcode mapping",
+                evdev, evdev);
+        goto nomap;
+    }
+
+    /*
+     * map QKeyCode -> number
+     *
+     * TODO: long-term we should use QKeyCode names in keymaps instead
+     */
+    keyvalue.type = KEY_VALUE_KIND_QCODE;
+    keyvalue.u.qcode.data = qcode;
+    number = qemu_input_key_value_to_number(&keyvalue);
+    if (number == 0) {
+        fprintf(outfile,
+                "# evdev %d (0x%x), qcode %d: no qcode -> number mapping",
+                evdev, evdev, qcode);
+        goto nomap;
+    }
+    fprintf(outfile, "# evdev %d (0x%x), qcode %d, number 0x%x\n",
+            evdev, evdev, qcode, number);
+
+    /*
+     * check which modifier states generate which keysyms
+     */
+    xkb_state_update_mask(state,  0, 0, 0,  0, 0, 0);
+    kbase = xkb_state_key_get_one_sym(state, code);
+    print_sym(kbase, number, "");
+
+    xkb_state_update_mask(state,  0, 0, numlock,  0, 0, 0);
+    knumlock = xkb_state_key_get_one_sym(state, code);
+    if (kbase != knumlock) {
+        print_sym(knumlock, number, " numlock");
+    }
+
+    xkb_state_update_mask(state,  shift, 0, 0,  0, 0, 0);
+    kshift = xkb_state_key_get_one_sym(state, code);
+    if (kbase != kshift && knumlock != kshift) {
+        print_sym(kshift, number, " shift");
+    }
+
+    xkb_state_update_mask(state,  altgr, 0, 0,  0, 0, 0);
+    kaltgr = xkb_state_key_get_one_sym(state, code);
+    if (kbase != kaltgr) {
+        print_sym(kaltgr, number, " altgr");
+    }
+
+    xkb_state_update_mask(state,  altgr | shift, 0, 0,  0, 0, 0);
+    kaltgrshift = xkb_state_key_get_one_sym(state, code);
+    if (kshift != kaltgrshift && kaltgr != kaltgrshift) {
+        print_sym(kaltgrshift, number, " shift altgr");
+    }
+    return;
+
+nomap:
+    xkb_state_update_mask(state,  0, 0, 0,  0, 0, 0);
+    kbase = xkb_state_key_get_one_sym(state, code);
+    xkb_keysym_get_name(kbase, name, sizeof(name));
+    fprintf(outfile, " (xkb keysym %s)\n", name);
+}
+
+static void usage(FILE *out)
+{
+    fprintf(out,
+            "\n"
+            "This tool generates qemu reverse keymaps from xkb keymaps,\n"
+            "which can be used with the qemu \"-k\" command line switch.\n"
+            "\n"
+            "usage: qemu-keymap <options>\n"
+            "options:\n"
+            "    -h             print this text\n"
+            "    -f <file>      set output file  (default: stdout)\n"
+            "    -m <model>     set kbd model    (default: %s)\n"
+            "    -l <layout>    set kbd layout   (default: %s)\n"
+            "    -v <variant>   set kbd variant  (default: %s)\n"
+            "    -o <options>   set kbd options  (default: %s)\n"
+            "\n",
+            names.model, names.layout,
+            names.variant ?: "-",
+            names.options ?: "-");
+}
+
+int main(int argc, char *argv[])
+{
+    struct xkb_context *ctx;
+    struct xkb_keymap *map;
+    struct xkb_state *state;
+    xkb_mod_index_t mod, mods;
+    int rc;
+
+    for (;;) {
+        rc = getopt(argc, argv, "hm:l:v:o:f:");
+        if (rc == -1)
+            break;
+        switch (rc) {
+        case 'm':
+            names.model = optarg;
+            break;
+        case 'l':
+            names.layout = optarg;
+            break;
+        case 'v':
+            names.variant = optarg;
+            break;
+        case 'o':
+            names.options = optarg;
+            break;
+        case 'f':
+            outfile = fopen(optarg, "w");
+            if (outfile == NULL) {
+                fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
+                exit(1);
+            }
+            break;
+        case 'h':
+            usage(stdout);
+            exit(0);
+        default:
+            usage(stderr);
+            exit(1);
+        }
+    }
+
+    if (outfile == NULL) {
+        outfile = stdout;
+    }
+
+    fprintf(outfile,
+            "#\n"
+            "# generated by qemu-keymap\n"
+            "#    model   : %s\n"
+            "#    layout  : %s\n"
+            "#    variant : %s\n"
+            "#    options : %s\n"
+            "#\n\n",
+            names.model, names.layout,
+            names.variant ?: "-",
+            names.options ?: "-");
+
+    ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
+    map = xkb_keymap_new_from_names(ctx, &names, XKB_KEYMAP_COMPILE_NO_FLAGS);
+    if (!map) {
+        /* libxkbcommon prints error */
+        exit(1);
+    }
+
+    fprintf(outfile, "# modifiers\n");
+    mods = xkb_keymap_num_mods(map);
+    for (mod = 0; mod < mods; mod++) {
+        fprintf(outfile, "#    %2d: %s\n",
+                mod, xkb_keymap_mod_get_name(map, mod));
+    }
+
+    mod = xkb_keymap_mod_get_index(map, "Shift");
+    shift = (1 << mod);
+    mod = xkb_keymap_mod_get_index(map, "Control");
+    ctrl = (1 << mod);
+    mod = xkb_keymap_mod_get_index(map, "AltGr");
+    altgr = (1 << mod);
+    mod = xkb_keymap_mod_get_index(map, "NumLock");
+    numlock = (1 << mod);
+
+    state = xkb_state_new(map);
+    xkb_keymap_key_for_each(map, walk_map, state);
+
+    /*
+     * add quirks
+     *
+     * Sometimes multiple keysyms generate the same keycodes.
+     * With our keycode -> keysym lookup we'll find only one
+     * of the keysyms.  So append them here.
+     */
+    fprintf(outfile, "\n# quirks section\n"
+            "\n"
+            "Print 0xb7\n"
+            "Sys_Req 0xb7\n"
+            "Execute 0xb7\n"
+            "\n"
+            "KP_Decimal 0x53 numlock\n"
+            "KP_Separator 0x53 numlock\n"
+            "\n"
+            "Alt_R 0xb8\n"
+            "ISO_Level3_Shift 0xb8\n"
+            "Mode_switch 0xb8\n"
+            "\n");
+
+    exit(0);
+}
-- 
2.9.3
^ permalink raw reply related	[flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH 0/3] Fix qemu keymaps, part one
  2017-07-24 14:01 [Qemu-devel] [PATCH 0/3] Fix qemu keymaps, part one Gerd Hoffmann
                   ` (2 preceding siblings ...)
  2017-07-24 14:01 ` [Qemu-devel] [PATCH 3/3] Add qemu-keymap tool Gerd Hoffmann
@ 2017-07-24 14:18 ` Daniel P. Berrange
  2017-07-24 14:23   ` Daniel P. Berrange
  2017-07-24 14:29   ` Gerd Hoffmann
  3 siblings, 2 replies; 7+ messages in thread
From: Daniel P. Berrange @ 2017-07-24 14:18 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: qemu-devel
On Mon, Jul 24, 2017 at 04:01:14PM +0200, Gerd Hoffmann wrote:
> qemu carries a bunch of reverse keymaps in pc-bios/keymaps/, to map
> keysyms it receives from vnc clients back to keycodes.  These keymaps
> seem to be buggy and incomplete at times.  So, to tackle the issue once
> for all, I've written a tool to generate those maps from xkb keyboard
> layout data using libxkbcommon.
> 
> This patch series only adds the tool, it doesn't touch the maps in
> pc-bios/keymaps/ yet.  I want some testing feedback first ...
Hmm, we recently split out the keymap database and code for generating
lookup tables (that was duplicated across spice-gtk, gtk-vnc, and libvirt)
into a shared git sub-module
  https://gitlab.com/keycodemap/keycodemapdb/
some other VNC clients were also switching to its use.
I was coincidentally working on a patch to get QEMU to use this too,
so all projects are aligned on the same data maps and thus share fixes
in this area.
IMHO that'd be preferable than doing something custom in QEMU only.
> How to test:
>   (1) generate a map: "qemu-keymap -f testmap -l $layout"
>   (2) use the map: "qemu -vnc $display -k testmap"
> 
> Gerd Hoffmann (3):
>   keysym: add next and prior
>   ui: move qemu_input_linux_to_qcode()
>   Add qemu-keymap tool.
Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH 0/3] Fix qemu keymaps, part one
  2017-07-24 14:18 ` [Qemu-devel] [PATCH 0/3] Fix qemu keymaps, part one Daniel P. Berrange
@ 2017-07-24 14:23   ` Daniel P. Berrange
  2017-07-24 14:29   ` Gerd Hoffmann
  1 sibling, 0 replies; 7+ messages in thread
From: Daniel P. Berrange @ 2017-07-24 14:23 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: qemu-devel
On Mon, Jul 24, 2017 at 03:18:25PM +0100, Daniel P. Berrange wrote:
> On Mon, Jul 24, 2017 at 04:01:14PM +0200, Gerd Hoffmann wrote:
> > qemu carries a bunch of reverse keymaps in pc-bios/keymaps/, to map
> > keysyms it receives from vnc clients back to keycodes.  These keymaps
> > seem to be buggy and incomplete at times.  So, to tackle the issue once
> > for all, I've written a tool to generate those maps from xkb keyboard
> > layout data using libxkbcommon.
> > 
> > This patch series only adds the tool, it doesn't touch the maps in
> > pc-bios/keymaps/ yet.  I want some testing feedback first ...
> 
> Hmm, we recently split out the keymap database and code for generating
> lookup tables (that was duplicated across spice-gtk, gtk-vnc, and libvirt)
> into a shared git sub-module
> 
>   https://gitlab.com/keycodemap/keycodemapdb/
> 
> some other VNC clients were also switching to its use.
> 
> I was coincidentally working on a patch to get QEMU to use this too,
> so all projects are aligned on the same data maps and thus share fixes
> in this area.
> 
> IMHO that'd be preferable than doing something custom in QEMU only.
Oh actually ignore that - we're talking about different areas of
keymapping. The stuff I was doing was primarily targetted as the
SDL / GTK frontends in QEMU which must convert from X/GTK key
maps to QEMU's XT keycodes, where as you were talking about the
VNC keymaps when not using the QEMU scancode extension for VNC.
So they're complementary, not mutually exclusive.
Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH 0/3] Fix qemu keymaps, part one
  2017-07-24 14:18 ` [Qemu-devel] [PATCH 0/3] Fix qemu keymaps, part one Daniel P. Berrange
  2017-07-24 14:23   ` Daniel P. Berrange
@ 2017-07-24 14:29   ` Gerd Hoffmann
  1 sibling, 0 replies; 7+ messages in thread
From: Gerd Hoffmann @ 2017-07-24 14:29 UTC (permalink / raw)
  To: Daniel P. Berrange; +Cc: qemu-devel
On Mon, 2017-07-24 at 15:18 +0100, Daniel P. Berrange wrote:
> On Mon, Jul 24, 2017 at 04:01:14PM +0200, Gerd Hoffmann wrote:
> > qemu carries a bunch of reverse keymaps in pc-bios/keymaps/, to map
> > keysyms it receives from vnc clients back to keycodes.  These
> > keymaps
> > seem to be buggy and incomplete at times.  So, to tackle the issue
> > once
> > for all, I've written a tool to generate those maps from xkb
> > keyboard
> > layout data using libxkbcommon.
> > 
> > This patch series only adds the tool, it doesn't touch the maps in
> > pc-bios/keymaps/ yet.  I want some testing feedback first ...
> 
> Hmm, we recently split out the keymap database and code for
> generating
> lookup tables (that was duplicated across spice-gtk, gtk-vnc, and
> libvirt)
> into a shared git sub-module
> 
>   https://gitlab.com/keycodemap/keycodemapdb/
> 
> some other VNC clients were also switching to its use.
> 
> I was coincidentally working on a patch to get QEMU to use this too,
> so all projects are aligned on the same data maps and thus share
> fixes
> in this area.
> 
> IMHO that'd be preferable than doing something custom in QEMU only.
This is a different issue.  gtk-vnc & friends have to map keycodes from
one system (ps/2, evdev, xorg, ...) to another.  qemu has to map
keysyms back to keycodes, using a reverse keymap, in case the vnc
client doesn't support VNC_ENCODING_EXT_KEY_EVENT.
cheers,
  Gerd
^ permalink raw reply	[flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-07-24 14:29 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-24 14:01 [Qemu-devel] [PATCH 0/3] Fix qemu keymaps, part one Gerd Hoffmann
2017-07-24 14:01 ` [Qemu-devel] [PATCH 1/3] keysym: add next and prior Gerd Hoffmann
2017-07-24 14:01 ` [Qemu-devel] [PATCH 2/3] ui: move qemu_input_linux_to_qcode() Gerd Hoffmann
2017-07-24 14:01 ` [Qemu-devel] [PATCH 3/3] Add qemu-keymap tool Gerd Hoffmann
2017-07-24 14:18 ` [Qemu-devel] [PATCH 0/3] Fix qemu keymaps, part one Daniel P. Berrange
2017-07-24 14:23   ` Daniel P. Berrange
2017-07-24 14:29   ` Gerd Hoffmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).