Skip to contentSkip to conversation

Fix SDL keymapping when run against non-Linux X11 server

PATCH In review Daniel P. Berrange 2 participants 9 messages Jan 17, 2012 – Jan 18, 2012 Kbuild

lore
Share & tools
lore
#0 lore raw

cover Fix SDL keymapping when run against non-Linux X11 server

The following two patches make the SDL display keymapping work correctly when QEMU is executed on Linux, but displayed on an OS-X or Win32 X11 server. As an added bonus, I included support for the SDL Quartz and Win32 video drivers, but I'm not clear if QEMU actually works with them.

The changes are based on code pulled as-is from GTK-VNC / SPICE-GTK which have had good success with this approach.

This is in response to this bug report

http://lists.nongnu.org/archive/html/qemu-devel/2012-01/msg01418.html

#1 lore raw

PATCH 1/2 Rewrite the way keycode conversions are performed

From: "Daniel P. Berrange" <[email protected]>

The SDL video display code needs to convert between the SDL keyboard event keycodes, and QEMU's internal keycode set (a variant of the xt coding). Currently the SDL code is only able todo this when it is built for X11, and running against a Linux X11 server using evdev or xfree86 keymaps. If running against an OS-X or Win32 X11 server the keycode mapping falls back to xfre86, which is completely wrong. There is no mapping at all done, if built against an SDL library with direct Win32 or Quartz display support.

After initial creation, this QEMU code was later copied into GTK-VNC to deal with the same problem. GTK-VNC came across the same problem described above and rewrote the mapping code from scratch. Instead of creating two arrays for the specific conversions required, the GTK-VNC code created a CSV file containing data for all commonly known keycode sets (Linux evdev, OS-X, AT set1, AT set2, AT set3, XT, XT Linux KBD driver, USB HID, Win32, Xwin XT variant, Xorg KBD XT variant). A script is then used to generate C arrays for the particular conversions required. The CSV file has since been reused in both the SPICE-GTK and libvirt codebases, unchanged.

This patch rewrites QEMU's SDL code to use this same approach, and in the process adds support for 4 new targets, SDL X11 on Win32 Xorg server, SDL X11 on OS-X Xorg server, SDL Win32 and SDL Quartz.

In the near future the 'keymap-gen.pl' and 'keymaps.csv' files will be placed into a dedicated GIT repo which can be added to QEMU, libvirt, SPICE-GTK & GTK-VNC via a git submodule, instead of requiring manual copying.

* Makefile: Add rules for generating keymap data files
* Makefile.objs: Replace x_keymap.o with sdl_keymap.o
* ui/keymap-gen.pl: Script for generating keycode mapping tables
* ui/keymaps.csv: Master datafile of keycode mappings
* ui/sdl.c: Rewrite sdl_keyevent_to_keycode to use new mapping code
* ui/sdl_keymap.c,ui/sdl_keymap.h: Add APIs for detecting suitable keymap tables & performing keymap conversions
* ui/x_keymap.[ch]: Remove obsolete files

---
 Makefile         |   40 +++++-
 Makefile.objs    |    2 +-
 ui/keymap-gen.pl |  210 ++++++++++++++++++++++++
 ui/keymaps.csv   |  464 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ui/sdl.c         |   88 ++---------
 ui/sdl_keymap.c  |  241 ++++++++++++++++++++++++++++
 ui/sdl_keymap.h  |   32 ++++
 ui/x_keymap.c    |  168 --------------------
 ui/x_keymap.h    |   32 ----
 9 files changed, 998 insertions(+), 279 deletions(-)
 create mode 100644 ui/keymap-gen.pl
 create mode 100644 ui/keymaps.csv
 create mode 100644 ui/sdl_keymap.c
 create mode 100644 ui/sdl_keymap.h
 delete mode 100644 ui/x_keymap.c
 delete mode 100644 ui/x_keymap.h
Makefile +39 -1
index 2bbc547..f776c30 100644
@@ -116,7 +116,45 @@ QEMU_CFLAGS+=$(GLIB_CFLAGS)
 
 ui/cocoa.o: ui/cocoa.m
 
-ui/sdl.o audio/sdlaudio.o ui/sdl_zoom.o baum.o: QEMU_CFLAGS += $(SDL_CFLAGS)
+ui/sdl.o audio/sdlaudio.o ui/sdl_zoom.o ui/sdl_keymap.o baum.o: QEMU_CFLAGS += $(SDL_CFLAGS)
+
+KEYMAP_GEN = ui/keymap-gen.pl
+KEYMAP_CSV = ui/keymaps.csv
+
+SDL_KEYMAPS = \
+        ui/sdl_keymap_xorgevdev2rfb.c \
+        ui/sdl_keymap_xorgkbd2rfb.c \
+        ui/sdl_keymap_xorgxquartz2rfb.c \
+        ui/sdl_keymap_xorgxwin2rfb.c \
+        ui/sdl_keymap_osx2rfb.c \
+        ui/sdl_keymap_win322rfb.c
+
+$(SDL_KEYMAPS): $(KEYMAP_GEN) $(KEYMAP_CSV)
+GENERATED_SOURCES += $(SDL_KEYMAPS)
+
+# Avoid need for perl(Text::CSV) by end users
+# XXXX how does QEMU make file deal with this
+#EXTRA_DIST += $(SDL_KEYMAPS)
+
+ui/sdl_keymap.c: $(SDL_KEYMAPS)
+
+ui/sdl_keymap_xorgevdev2rfb.c: $(KEYMAP_CSV)
+	$(call quiet-command,perl $(KEYMAP_GEN) $< xorgevdev rfb > $@ || rm $@, "  GEN $@")
+
+ui/sdl_keymap_xorgkbd2rfb.c: $(KEYMAP_CSV)
+	$(call quiet-command,perl $(KEYMAP_GEN) $< xorgkbd rfb > $@ || rm $@, "  GEN $@")
+
+ui/sdl_keymap_xorgxquartz2rfb.c: $(KEYMAP_CSV)
+	$(call quiet-command,perl $(KEYMAP_GEN) $< xorgxquartz rfb > $@ || rm $@, "  GEN $@")
+
+ui/sdl_keymap_xorgxwin2rfb.c: $(KEYMAP_CSV)
+	$(call quiet-command,perl $(KEYMAP_GEN) $< xorgxwin rfb > $@ || rm $@, "  GEN $@")
+
+ui/sdl_keymap_osx2rfb.c: $(KEYMAP_CSV)
+	$(call quiet-command,perl $(KEYMAP_GEN) $< osx rfb > $@ || rm $@, "  GEN $@")
+
+ui/sdl_keymap_win322rfb.c: $(KEYMAP_CSV)
+	$(call quiet-command,perl $(KEYMAP_GEN) $< win32 rfb > $@ || rm $@, "  GEN $@")
 
 ui/vnc.o: QEMU_CFLAGS += $(VNC_TLS_CFLAGS)
 
Makefile.objs +1 -1
index 4f6d26c..e549f7c 100644
@@ -139,7 +139,7 @@ audio-obj-y += wavcapture.o
 common-obj-y += $(addprefix audio/, $(audio-obj-y))
 
 ui-obj-y += keymaps.o
-ui-obj-$(CONFIG_SDL) += sdl.o sdl_zoom.o x_keymap.o
+ui-obj-$(CONFIG_SDL) += sdl.o sdl_zoom.o sdl_keymap.o
 ui-obj-$(CONFIG_COCOA) += cocoa.o
 ui-obj-$(CONFIG_CURSES) += curses.o
 vnc-obj-y += vnc.o d3des.o
ui/keymap-gen.pl new file +210 -0

210 lines not on this page · raw message

ui/keymaps.csv new file +464 -0

464 lines not on this page · raw message

ui/sdl.c +11 -77

110 lines not on this page · raw message

ui/sdl_keymap.c new file +241 -0

241 lines not on this page · raw message

ui/sdl_keymap.h new file +32 -0
new file mode 100644
index 0000000..fb51e16
@@ -0,0 +1,32 @@
+/*
+ * QEMU SDL keycode mapping
+ *
+ * Copyright (C) 2006  Anthony Liguori <[email protected]>
+ * Copyright (C) 2009-2012 Daniel P. Berrange <[email protected]>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.0 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#ifndef QEMU_SDL_KEYMAP_H
+#define QEMU_SDL_KEYMAP_H
+
+#include <glib.h>
+
+const guint16 *qemu_sdl_keymap_detect_table(size_t *maplen);
+guint16 qemu_sdl_keymap_convert(const guint16 *keycode_map,
+				size_t keycode_maplen,
+				guint16 keycode);
+
+#endif /* QEMU_SDL_KEYMAP_H */
ui/x_keymap.c deleted +0 -168

168 lines not on this page · raw message

ui/x_keymap.h deleted +0 -32
deleted file mode 100644
index afde2e9..0000000
@@ -1,32 +0,0 @@
-/*
- * QEMU SDL display driver
- *
- * Copyright (c) 2003 Fabrice Bellard
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#ifndef QEMU_X_KEYMAP_H
-#define QEMU_X_KEYMAP_H
-
-uint8_t translate_xfree86_keycode(const int key);
-
-uint8_t translate_evdev_keycode(const int key);
-
-#endif
Signature · 1 line
1.7.7.5
#8 lore raw

PATCH 2/2 Add pre-generated keymaps

In reply to Daniel P. Berrange

From: "Daniel P. Berrange" <[email protected]>

To avoid the need for QEMU maintainers to have the perl Text::CSV module on their build machines, add pre-generated keymaps for each of the 6 conversions needed for QEMU's SDL driver

---
 ui/sdl_keymap_osx2rfb.c         |  117 +++++++++++++++++++
 ui/sdl_keymap_win322rfb.c       |  140 +++++++++++++++++++++++
 ui/sdl_keymap_xorgevdev2rfb.c   |  240 +++++++++++++++++++++++++++++++++++++++
 ui/sdl_keymap_xorgkbd2rfb.c     |  112 ++++++++++++++++++
 ui/sdl_keymap_xorgxquartz2rfb.c |  117 +++++++++++++++++++
 ui/sdl_keymap_xorgxwin2rfb.c    |  112 ++++++++++++++++++
 6 files changed, 838 insertions(+), 0 deletions(-)
 create mode 100644 ui/sdl_keymap_osx2rfb.c
 create mode 100644 ui/sdl_keymap_win322rfb.c
 create mode 100644 ui/sdl_keymap_xorgevdev2rfb.c
 create mode 100644 ui/sdl_keymap_xorgkbd2rfb.c
 create mode 100644 ui/sdl_keymap_xorgxquartz2rfb.c
 create mode 100644 ui/sdl_keymap_xorgxwin2rfb.c
ui/sdl_keymap_osx2rfb.c new file +117 -0
new file mode 100644
index 0000000..62cd692
@@ -0,0 +1,117 @@
+static const guint16 keymap_osx2rfb[] = {
+  [0x0] = 0x1e,        /* 0 (ANSI_A) => 30 via 30 (KEY_A) */
+  [0x1] = 0x1f,        /* 1 (ANSI_S) => 31 via 31 (KEY_S) */
+  [0x2] = 0x20,        /* 2 (ANSI_D) => 32 via 32 (KEY_D) */
+  [0x3] = 0x21,        /* 3 (ANSI_F) => 33 via 33 (KEY_F) */
+  [0x4] = 0x23,        /* 4 (ANSI_H) => 35 via 35 (KEY_H) */
+  [0x5] = 0x22,        /* 5 (ANSI_G) => 34 via 34 (KEY_G) */
+  [0x6] = 0x2c,        /* 6 (ANSI_Z) => 44 via 44 (KEY_Z) */
+  [0x7] = 0x2d,        /* 7 (ANSI_X) => 45 via 45 (KEY_X) */
+  [0x8] = 0x2e,        /* 8 (ANSI_C) => 46 via 46 (KEY_C) */
+  [0x9] = 0x2f,        /* 9 (ANSI_V) => 47 via 47 (KEY_V) */
+  [0xa] = 0x70,        /* 10 (ISO_Section) => 112 via 170 (KEY_ISO) */
+  [0xb] = 0x30,        /* 11 (ANSI_B) => 48 via 48 (KEY_B) */
+  [0xc] = 0x10,        /* 12 (ANSI_Q) => 16 via 16 (KEY_Q) */
+  [0xd] = 0x11,        /* 13 (ANSI_W) => 17 via 17 (KEY_W) */
+  [0xe] = 0x12,        /* 14 (ANSI_E) => 18 via 18 (KEY_E) */
+  [0xf] = 0x13,        /* 15 (ANSI_R) => 19 via 19 (KEY_R) */
+  [0x10] = 0x15,       /* 16 (ANSI_Y) => 21 via 21 (KEY_Y) */
+  [0x11] = 0x14,       /* 17 (ANSI_T) => 20 via 20 (KEY_T) */
+  [0x12] = 0x2,        /* 18 (ANSI_1) => 2 via 2 (KEY_1) */
+  [0x13] = 0x3,        /* 19 (ANSI_2) => 3 via 3 (KEY_2) */
+  [0x14] = 0x4,        /* 20 (ANSI_3) => 4 via 4 (KEY_3) */
+  [0x15] = 0x5,        /* 21 (ANSI_4) => 5 via 5 (KEY_4) */
+  [0x16] = 0x7,        /* 22 (ANSI_6) => 7 via 7 (KEY_6) */
+  [0x17] = 0x6,        /* 23 (ANSI_5) => 6 via 6 (KEY_5) */
+  [0x18] = 0xd,        /* 24 (ANSI_Equal) => 13 via 13 (KEY_EQUAL) */
+  [0x19] = 0xa,        /* 25 (ANSI_9) => 10 via 10 (KEY_9) */
+  [0x1a] = 0x8,        /* 26 (ANSI_7) => 8 via 8 (KEY_7) */
+  [0x1b] = 0xc,        /* 27 (ANSI_Minus) => 12 via 12 (KEY_MINUS) */
+  [0x1c] = 0x9,        /* 28 (ANSI_8) => 9 via 9 (KEY_8) */
+  [0x1d] = 0xb,        /* 29 (ANSI_0) => 11 via 11 (KEY_0) */
+  [0x1e] = 0x1b,       /* 30 (ANSI_RightBracket) => 27 via 27 (KEY_RIGHTBRACE) */
+  [0x1f] = 0x18,       /* 31 (ANSI_O) => 24 via 24 (KEY_O) */
+  [0x20] = 0x16,       /* 32 (ANSI_U) => 22 via 22 (KEY_U) */
+  [0x21] = 0x1a,       /* 33 (ANSI_LeftBracket) => 26 via 26 (KEY_LEFTBRACE) */
+  [0x22] = 0x17,       /* 34 (ANSI_I) => 23 via 23 (KEY_I) */
+  [0x23] = 0x19,       /* 35 (ANSI_P) => 25 via 25 (KEY_P) */
+  [0x24] = 0x1c,       /* 36 (Return) => 28 via 28 (KEY_ENTER) */
+  [0x25] = 0x26,       /* 37 (ANSI_L) => 38 via 38 (KEY_L) */
+  [0x26] = 0x24,       /* 38 (ANSI_J) => 36 via 36 (KEY_J) */
+  [0x27] = 0x28,       /* 39 (ANSI_Quote) => 40 via 40 (KEY_APOSTROPHE) */
+  [0x28] = 0x25,       /* 40 (ANSI_K) => 37 via 37 (KEY_K) */
+  [0x29] = 0x27,       /* 41 (ANSI_Semicolon) => 39 via 39 (KEY_SEMICOLON) */
+  [0x2a] = 0x2b,       /* 42 (ANSI_Backslash) => 43 via 43 (KEY_BACKSLASH) */
+  [0x2b] = 0x33,       /* 43 (ANSI_Comma) => 51 via 51 (KEY_COMMA) */
+  [0x2c] = 0x35,       /* 44 (ANSI_Slash) => 53 via 53 (KEY_SLASH) */
+  [0x2d] = 0x31,       /* 45 (ANSI_N) => 49 via 49 (KEY_N) */
+  [0x2e] = 0x32,       /* 46 (ANSI_M) => 50 via 50 (KEY_M) */
+  [0x2f] = 0x34,       /* 47 (ANSI_Period) => 52 via 52 (KEY_DOT) */
+  [0x30] = 0xf,        /* 48 (Tab) => 15 via 15 (KEY_TAB) */
+  [0x31] = 0x39,       /* 49 (Space) => 57 via 57 (KEY_SPACE) */
+  [0x32] = 0x29,       /* 50 (ANSI_Grave) => 41 via 41 (KEY_GRAVE) */
+  [0x33] = 0xe,        /* 51 (Delete) => 14 via 14 (KEY_BACKSPACE) */
+  [0x35] = 0x1,        /* 53 (Escape) => 1 via 1 (KEY_ESC) */
+  [0x37] = 0xdb,       /* 55 (Command) => 219 via 125 (KEY_LEFTMETA) */
+  [0x38] = 0x2a,       /* 56 (Shift) => 42 via 42 (KEY_LEFTSHIFT) */
+  [0x39] = 0x3a,       /* 57 (CapsLock) => 58 via 58 (KEY_CAPSLOCK) */
+  [0x3a] = 0x38,       /* 58 (Option) => 56 via 56 (KEY_LEFTALT) */
+  [0x3b] = 0x1d,       /* 59 (Control) => 29 via 29 (KEY_LEFTCTRL) */
+  [0x3c] = 0x36,       /* 60 (RightShift) => 54 via 54 (KEY_RIGHTSHIFT) */
+  [0x3d] = 0xb8,       /* 61 (RightOption) => 184 via 100 (KEY_RIGHTALT) */
+  [0x3e] = 0x9d,       /* 62 (RightControl) => 157 via 97 (KEY_RIGHTCTRL) */
+  [0x3f] = 0xdd,       /* 63 (Function) => 221 via 127 (KEY_COMPOSE) */
+  [0x40] = 0x83,       /* 64 (F17) => 131 via 187 (KEY_F17) */
+  [0x41] = 0x53,       /* 65 (ANSI_KeypadDecimal) => 83 via 83 (KEY_KPDOT) */
+  [0x43] = 0x37,       /* 67 (ANSI_KeypadMultiply) => 55 via 55 (KEY_KPASTERISK) */
+  [0x45] = 0x4e,       /* 69 (ANSI_KeypadPlus) => 78 via 78 (KEY_KPPLUS) */
+  [0x47] = 0x7e,       /* 71 (ANSI_KeypadClear????) => 126 via 121 (KEY_KPCOMMA) */
+  [0x48] = 0xb0,       /* 72 (VolumeUp) => 176 via 115 (KEY_VOLUMEUP) */
+  [0x49] = 0xae,       /* 73 (VolumeDown) => 174 via 114 (KEY_VOLUMEDOWN) */
+  [0x4a] = 0xa0,       /* 74 (Mute) => 160 via 113 (KEY_MUTE) */
+  [0x4b] = 0xb5,       /* 75 (ANSI_KeypadDivide) => 181 via 98 (KEY_KPSLASH) */
+  [0x4c] = 0x9c,       /* 76 (ANSI_KeypadEnter) => 156 via 96 (KEY_KPENTER) */
+  [0x4e] = 0x4a,       /* 78 (ANSI_KeypadMinus) => 74 via 74 (KEY_KPMINUS) */
+  [0x4f] = 0xf7,       /* 79 (F18) => 247 via 188 (KEY_F18) */
+  [0x50] = 0x84,       /* 80 (F19) => 132 via 189 (KEY_F19) */
+  [0x51] = 0x59,       /* 81 (ANSI_KeypadEquals) => 89 via 117 (KEY_KPEQUAL) */
+  [0x52] = 0x52,       /* 82 (ANSI_Keypad0) => 82 via 82 (KEY_KP0) */
+  [0x53] = 0x4f,       /* 83 (ANSI_Keypad1) => 79 via 79 (KEY_KP1) */
+  [0x54] = 0x50,       /* 84 (ANSI_Keypad2) => 80 via 80 (KEY_KP2) */
+  [0x55] = 0x51,       /* 85 (ANSI_Keypad3) => 81 via 81 (KEY_KP3) */
+  [0x56] = 0x4b,       /* 86 (ANSI_Keypad4) => 75 via 75 (KEY_KP4) */
+  [0x57] = 0x4c,       /* 87 (ANSI_Keypad5) => 76 via 76 (KEY_KP5) */
+  [0x58] = 0x4d,       /* 88 (ANSI_Keypad6) => 77 via 77 (KEY_KP6) */
+  [0x59] = 0x47,       /* 89 (ANSI_Keypad7) => 71 via 71 (KEY_KP7) */
+  [0x5a] = 0x5a,       /* 90 (F20) => 90 via 190 (KEY_F20) */
+  [0x5b] = 0x48,       /* 91 (ANSI_Keypad8) => 72 via 72 (KEY_KP8) */
+  [0x5c] = 0x49,       /* 92 (ANSI_Keypad9) => 73 via 73 (KEY_KP9) */
+  [0x5d] = 0x7d,       /* 93 (JIS_Yen) => 125 via 124 (KEY_YEN) */
+  [0x5f] = 0x5c,       /* 95 (JIS_KeypadComma) => 92 via 95 (KEY_KPJPCOMMA) */
+  [0x60] = 0x3f,       /* 96 (F5) => 63 via 63 (KEY_F5) */
+  [0x61] = 0x40,       /* 97 (F6) => 64 via 64 (KEY_F6) */
+  [0x62] = 0x41,       /* 98 (F7) => 65 via 65 (KEY_F7) */
+  [0x63] = 0x3d,       /* 99 (F3) => 61 via 61 (KEY_F3) */
+  [0x64] = 0x42,       /* 100 (F8) => 66 via 66 (KEY_F8) */
+  [0x65] = 0x43,       /* 101 (F9) => 67 via 67 (KEY_F9) */
+  [0x67] = 0x57,       /* 103 (F11) => 87 via 87 (KEY_F11) */
+  [0x68] = 0x78,       /* 104 (JIS_Kana????) => 120 via 90 (KEY_KATAKANA) */
+  [0x69] = 0x5d,       /* 105 (F13) => 93 via 183 (KEY_F13) */
+  [0x6a] = 0x55,       /* 106 (F16) => 85 via 186 (KEY_F16) */
+  [0x6b] = 0x5e,       /* 107 (F14) => 94 via 184 (KEY_F14) */
+  [0x6d] = 0x44,       /* 109 (F10) => 68 via 68 (KEY_F10) */
+  [0x6f] = 0x58,       /* 111 (F12) => 88 via 88 (KEY_F12) */
+  [0x71] = 0x5f,       /* 113 (F15) => 95 via 185 (KEY_F15) */
+  [0x73] = 0xc7,       /* 115 (Home) => 199 via 102 (KEY_HOME) */
+  [0x74] = 0xc9,       /* 116 (PageUp) => 201 via 104 (KEY_PAGEUP) */
+  [0x75] = 0xd3,       /* 117 (ForwardDelete) => 211 via 111 (KEY_DELETE) */
+  [0x76] = 0x3e,       /* 118 (F4) => 62 via 62 (KEY_F4) */
+  [0x77] = 0xcf,       /* 119 (End) => 207 via 107 (KEY_END) */
+  [0x78] = 0x3c,       /* 120 (F2) => 60 via 60 (KEY_F2) */
+  [0x79] = 0xd1,       /* 121 (PageDown) => 209 via 109 (KEY_PAGEDOWN) */
+  [0x7a] = 0x3b,       /* 122 (F1) => 59 via 59 (KEY_F1) */
+  [0x7b] = 0xcb,       /* 123 (LeftArrow) => 203 via 105 (KEY_LEFT) */
+  [0x7c] = 0xcd,       /* 124 (RightArrow) => 205 via 106 (KEY_RIGHT) */
+  [0x7d] = 0xd0,       /* 125 (DownArrow) => 208 via 108 (KEY_DOWN) */
+  [0x7e] = 0xc8,       /* 126 (UpArrow) => 200 via 103 (KEY_UP) */
+};
ui/sdl_keymap_win322rfb.c new file +140 -0

140 lines not on this page · raw message

ui/sdl_keymap_xorgevdev2rfb.c new file +240 -0

240 lines not on this page · raw message

ui/sdl_keymap_xorgkbd2rfb.c new file +112 -0

112 lines not on this page · raw message

ui/sdl_keymap_xorgxquartz2rfb.c new file +117 -0

117 lines not on this page · raw message

ui/sdl_keymap_xorgxwin2rfb.c new file +112 -0

112 lines not on this page · raw message

Signature · 1 line
1.7.7.5
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] Rewrite the way keycode conversions are performed

In reply to Daniel P. Berrange
Quoted 18 lines · Daniel P. Berrange
Makefile +9 -1
index 2bbc547..f776c30 100644
@@ -116,7 +116,45 @@ QEMU_CFLAGS+=$(GLIB_CFLAGS)
 
 ui/cocoa.o: ui/cocoa.m
 
-ui/sdl.o audio/sdlaudio.o ui/sdl_zoom.o baum.o: QEMU_CFLAGS += $(SDL_CFLAGS)
+ui/sdl.o audio/sdlaudio.o ui/sdl_zoom.o ui/sdl_keymap.o baum.o: QEMU_CFLAGS += $(SDL_CFLAGS)
+
+KEYMAP_GEN = ui/keymap-gen.pl
+KEYMAP_CSV = ui/keymaps.csv
+
+SDL_KEYMAPS = \
+        ui/sdl_keymap_xorgevdev2rfb.c \
+        ui/sdl_keymap_xorgkbd2rfb.c \
+        ui/sdl_keymap_xorgxquartz2rfb.c \

Makefile QEMU_CFLAGS+=$(GLIB_CFLAGS) · line 137

Quoted 10 lines
Makefile +10 -0
+        ui/sdl_keymap_xorgxwin2rfb.c \
+        ui/sdl_keymap_osx2rfb.c \
+        ui/sdl_keymap_win322rfb.c
+
+$(SDL_KEYMAPS): $(KEYMAP_GEN) $(KEYMAP_CSV)
+GENERATED_SOURCES += $(SDL_KEYMAPS)
+
+# Avoid need for perl(Text::CSV) by end users
+# XXXX how does QEMU make file deal with this
+#EXTRA_DIST += $(SDL_KEYMAPS)

I'm obviously looking for feedback here as to what QEMU's equivalent to automake's 'make dist' target is and how to tell it to pull in extra files ?

Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] Rewrite the way keycode conversions are performed

In reply to Daniel P. Berrange
Quoted 81 lines · Daniel P. Berrange

From: "Daniel P. Berrange"<[email protected]>

The SDL video display code needs to convert between the SDL keyboard event keycodes, and QEMU's internal keycode set (a variant of the xt coding). Currently the SDL code is only able todo this when it is built for X11, and running against a Linux X11 server using evdev or xfree86 keymaps. If running against an OS-X or Win32 X11 server the keycode mapping falls back to xfre86, which is completely wrong. There is no mapping at all done, if built against an SDL library with direct Win32 or Quartz display support.

After initial creation, this QEMU code was later copied into GTK-VNC to deal with the same problem. GTK-VNC came across the same problem described above and rewrote the mapping code from scratch. Instead of creating two arrays for the specific conversions required, the GTK-VNC code created a CSV file containing data for all commonly known keycode sets (Linux evdev, OS-X, AT set1, AT set2, AT set3, XT, XT Linux KBD driver, USB HID, Win32, Xwin XT variant, Xorg KBD XT variant). A script is then used to generate C arrays for the particular conversions required. The CSV file has since been reused in both the SPICE-GTK and libvirt codebases, unchanged.

This patch rewrites QEMU's SDL code to use this same approach, and in the process adds support for 4 new targets, SDL X11 on Win32 Xorg server, SDL X11 on OS-X Xorg server, SDL Win32 and SDL Quartz.

In the near future the 'keymap-gen.pl' and 'keymaps.csv' files will be placed into a dedicated GIT repo which can be added to QEMU, libvirt, SPICE-GTK& GTK-VNC via a git submodule, instead of requiring manual copying.

* Makefile: Add rules for generating keymap data files
* Makefile.objs: Replace x_keymap.o with sdl_keymap.o
* ui/keymap-gen.pl: Script for generating keycode mapping tables
* ui/keymaps.csv: Master datafile of keycode mappings
* ui/sdl.c: Rewrite sdl_keyevent_to_keycode to use new mapping code
* ui/sdl_keymap.c,ui/sdl_keymap.h: Add APIs for detecting suitable keymap tables& performing keymap conversions
* ui/x_keymap.[ch]: Remove obsolete files

---
  Makefile         |   40 +++++-
  Makefile.objs    |    2 +-
  ui/keymap-gen.pl |  210 ++++++++++++++++++++++++
  ui/keymaps.csv   |  464 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
  ui/sdl.c         |   88 ++---------
  ui/sdl_keymap.c  |  241 ++++++++++++++++++++++++++++
  ui/sdl_keymap.h  |   32 ++++
  ui/x_keymap.c    |  168 --------------------
  ui/x_keymap.h    |   32 ----
  9 files changed, 998 insertions(+), 279 deletions(-)

create mode 100644 ui/keymap-gen.pl
create mode 100644 ui/keymaps.csv
create mode 100644 ui/sdl_keymap.c
create mode 100644 ui/sdl_keymap.h
delete mode 100644 ui/x_keymap.c
delete mode 100644 ui/x_keymap.h

Makefile +14 -1
index 2bbc547..f776c30 100644
@@ -116,7 +116,45 @@ QEMU_CFLAGS+=$(GLIB_CFLAGS)
 
  ui/cocoa.o: ui/cocoa.m
 
-ui/sdl.o audio/sdlaudio.o ui/sdl_zoom.o baum.o: QEMU_CFLAGS += $(SDL_CFLAGS)
+ui/sdl.o audio/sdlaudio.o ui/sdl_zoom.o ui/sdl_keymap.o baum.o: QEMU_CFLAGS += $(SDL_CFLAGS)
+
+KEYMAP_GEN = ui/keymap-gen.pl
+KEYMAP_CSV = ui/keymaps.csv
+
+SDL_KEYMAPS = \
+        ui/sdl_keymap_xorgevdev2rfb.c \
+        ui/sdl_keymap_xorgkbd2rfb.c \
+        ui/sdl_keymap_xorgxquartz2rfb.c \
+        ui/sdl_keymap_xorgxwin2rfb.c \
+        ui/sdl_keymap_osx2rfb.c \
+        ui/sdl_keymap_win322rfb.c
+
+$(SDL_KEYMAPS): $(KEYMAP_GEN) $(KEYMAP_CSV)

Makefile QEMU_CFLAGS+=$(GLIB_CFLAGS) · line 142

Quoted 10 lines
Makefile +10 -0
+GENERATED_SOURCES += $(SDL_KEYMAPS)
+
+# Avoid need for perl(Text::CSV) by end users
+# XXXX how does QEMU make file deal with this
+#EXTRA_DIST += $(SDL_KEYMAPS)
+
+ui/sdl_keymap.c: $(SDL_KEYMAPS)
+
+ui/sdl_keymap_xorgevdev2rfb.c: $(KEYMAP_CSV)
+	$(call quiet-command,perl $(KEYMAP_GEN) $<  xorgevdev rfb>  $@ || rm $@, "  GEN $@")

I'm not sure I'm prepared to add a perl build dependency. That's particularly hard for Windows users. We could alternatively use a python version of keymap-gen but then we're forking from gtk-vnc/gtk-spice.

Maybe it makes sense to create a small library for dealing with keymaps? Then we could all link against it and probe for that conditionally?

Regards,

Anthony Liguori

#4 lore raw

Re: [Qemu-devel] [PATCH 1/2] Rewrite the way keycode conversions are performed

Quoted 89 lines · Anthony Liguori
Quoted 88 lines · Daniel P. Berrange

From: "Daniel P. Berrange"<[email protected]>

The SDL video display code needs to convert between the SDL keyboard event keycodes, and QEMU's internal keycode set (a variant of the xt coding). Currently the SDL code is only able todo this when it is built for X11, and running against a Linux X11 server using evdev or xfree86 keymaps. If running against an OS-X or Win32 X11 server the keycode mapping falls back to xfre86, which is completely wrong. There is no mapping at all done, if built against an SDL library with direct Win32 or Quartz display support.

After initial creation, this QEMU code was later copied into GTK-VNC to deal with the same problem. GTK-VNC came across the same problem described above and rewrote the mapping code from scratch. Instead of creating two arrays for the specific conversions required, the GTK-VNC code created a CSV file containing data for all commonly known keycode sets (Linux evdev, OS-X, AT set1, AT set2, AT set3, XT, XT Linux KBD driver, USB HID, Win32, Xwin XT variant, Xorg KBD XT variant). A script is then used to generate C arrays for the particular conversions required. The CSV file has since been reused in both the SPICE-GTK and libvirt codebases, unchanged.

This patch rewrites QEMU's SDL code to use this same approach, and in the process adds support for 4 new targets, SDL X11 on Win32 Xorg server, SDL X11 on OS-X Xorg server, SDL Win32 and SDL Quartz.

In the near future the 'keymap-gen.pl' and 'keymaps.csv' files will be placed into a dedicated GIT repo which can be added to QEMU, libvirt, SPICE-GTK& GTK-VNC via a git submodule, instead of requiring manual copying.

* Makefile: Add rules for generating keymap data files
* Makefile.objs: Replace x_keymap.o with sdl_keymap.o
* ui/keymap-gen.pl: Script for generating keycode mapping tables
* ui/keymaps.csv: Master datafile of keycode mappings
* ui/sdl.c: Rewrite sdl_keyevent_to_keycode to use new mapping code
* ui/sdl_keymap.c,ui/sdl_keymap.h: Add APIs for detecting suitable keymap tables& performing keymap conversions
* ui/x_keymap.[ch]: Remove obsolete files

---
 Makefile         |   40 +++++-
 Makefile.objs    |    2 +-
 ui/keymap-gen.pl |  210 ++++++++++++++++++++++++
 ui/keymaps.csv   |  464 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ui/sdl.c         |   88 ++---------
 ui/sdl_keymap.c  |  241 ++++++++++++++++++++++++++++
 ui/sdl_keymap.h  |   32 ++++
 ui/x_keymap.c    |  168 --------------------
 ui/x_keymap.h    |   32 ----
 9 files changed, 998 insertions(+), 279 deletions(-)
 create mode 100644 ui/keymap-gen.pl
 create mode 100644 ui/keymaps.csv
 create mode 100644 ui/sdl_keymap.c
 create mode 100644 ui/sdl_keymap.h
 delete mode 100644 ui/x_keymap.c
 delete mode 100644 ui/x_keymap.h
Makefile +21 -1
index 2bbc547..f776c30 100644
@@ -116,7 +116,45 @@ QEMU_CFLAGS+=$(GLIB_CFLAGS)
 
 ui/cocoa.o: ui/cocoa.m
 
-ui/sdl.o audio/sdlaudio.o ui/sdl_zoom.o baum.o: QEMU_CFLAGS += $(SDL_CFLAGS)
+ui/sdl.o audio/sdlaudio.o ui/sdl_zoom.o ui/sdl_keymap.o baum.o: QEMU_CFLAGS += $(SDL_CFLAGS)
+
+KEYMAP_GEN = ui/keymap-gen.pl
+KEYMAP_CSV = ui/keymaps.csv
+
+SDL_KEYMAPS = \
+        ui/sdl_keymap_xorgevdev2rfb.c \
+        ui/sdl_keymap_xorgkbd2rfb.c \
+        ui/sdl_keymap_xorgxquartz2rfb.c \
+        ui/sdl_keymap_xorgxwin2rfb.c \
+        ui/sdl_keymap_osx2rfb.c \
+        ui/sdl_keymap_win322rfb.c
+
+$(SDL_KEYMAPS): $(KEYMAP_GEN) $(KEYMAP_CSV)
+GENERATED_SOURCES += $(SDL_KEYMAPS)
+
+# Avoid need for perl(Text::CSV) by end users
+# XXXX how does QEMU make file deal with this
+#EXTRA_DIST += $(SDL_KEYMAPS)
+
+ui/sdl_keymap.c: $(SDL_KEYMAPS)
Quoted 8 lines

Makefile QEMU_CFLAGS+=$(GLIB_CFLAGS)

Quoted 3 lines
Makefile +3 -0
+
+ui/sdl_keymap_xorgevdev2rfb.c: $(KEYMAP_CSV)
+	$(call quiet-command,perl $(KEYMAP_GEN) $<  xorgevdev rfb>  $@ || rm $@, "  GEN $@")

I'm not sure I'm prepared to add a perl build dependency. That's particularly hard for Windows users. We could alternatively use a python version of keymap-gen but then we're forking from gtk-vnc/gtk-spice.

I expected as much, which is why I sent the 2nd patch which actually adds the generated files to GIT, so Perl is not required unless someone decides to update the keymaps.csv file.

Quoted 3 lines

Maybe it makes sense to create a small library for dealing with keymaps? Then we could all link against it and probe for that conditionally?

I don't think it is worth doing a library just for the keymap tables. It could be worth creating a set of add-on libraries (eg libsdl-keymap, libgdk-keymap, etc) for doing the keymap hueristics. In the immediate future though, my intent is to request a GIT repository on freedesktop.org to host the keymaps.csv file and a generator script, which could just be just included in apps using a GIT submodule approach.

I'm not wedded to Perl for the generator, so if it is more convenient to use another language, even C, I can easily do that too.

Is it acceptable to just commit the generated tables to QEMU GIT in the immediate term though, so users can get the fixes without needing perl ?

Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#5 lore raw

Re: [Qemu-devel] [PATCH 1/2] Rewrite the way keycode conversions are performed

Quoted 107 lines · Daniel P. Berrange
Quoted 89 lines · Anthony Liguori
Quoted 88 lines · Daniel P. Berrange

From: "Daniel P. Berrange"<[email protected]>

The SDL video display code needs to convert between the SDL keyboard event keycodes, and QEMU's internal keycode set (a variant of the xt coding). Currently the SDL code is only able todo this when it is built for X11, and running against a Linux X11 server using evdev or xfree86 keymaps. If running against an OS-X or Win32 X11 server the keycode mapping falls back to xfre86, which is completely wrong. There is no mapping at all done, if built against an SDL library with direct Win32 or Quartz display support.

After initial creation, this QEMU code was later copied into GTK-VNC to deal with the same problem. GTK-VNC came across the same problem described above and rewrote the mapping code from scratch. Instead of creating two arrays for the specific conversions required, the GTK-VNC code created a CSV file containing data for all commonly known keycode sets (Linux evdev, OS-X, AT set1, AT set2, AT set3, XT, XT Linux KBD driver, USB HID, Win32, Xwin XT variant, Xorg KBD XT variant). A script is then used to generate C arrays for the particular conversions required. The CSV file has since been reused in both the SPICE-GTK and libvirt codebases, unchanged.

This patch rewrites QEMU's SDL code to use this same approach, and in the process adds support for 4 new targets, SDL X11 on Win32 Xorg server, SDL X11 on OS-X Xorg server, SDL Win32 and SDL Quartz.

In the near future the 'keymap-gen.pl' and 'keymaps.csv' files will be placed into a dedicated GIT repo which can be added to
QEMU, libvirt, SPICE-GTK& GTK-VNC via a git submodule, instead
of requiring manual copying.

* Makefile: Add rules for generating keymap data files
* Makefile.objs: Replace x_keymap.o with sdl_keymap.o
* ui/keymap-gen.pl: Script for generating keycode mapping tables
* ui/keymaps.csv: Master datafile of keycode mappings
* ui/sdl.c: Rewrite sdl_keyevent_to_keycode to use new mapping code
* ui/sdl_keymap.c,ui/sdl_keymap.h: Add APIs for detecting
suitable keymap tables& performing keymap conversions
* ui/x_keymap.[ch]: Remove obsolete files

---
  Makefile         |   40 +++++-
  Makefile.objs    |    2 +-
  ui/keymap-gen.pl |  210 ++++++++++++++++++++++++
  ui/keymaps.csv   |  464 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
  ui/sdl.c         |   88 ++---------
  ui/sdl_keymap.c  |  241 ++++++++++++++++++++++++++++
  ui/sdl_keymap.h  |   32 ++++
  ui/x_keymap.c    |  168 --------------------
  ui/x_keymap.h    |   32 ----
  9 files changed, 998 insertions(+), 279 deletions(-)

create mode 100644 ui/keymap-gen.pl
create mode 100644 ui/keymaps.csv
create mode 100644 ui/sdl_keymap.c
create mode 100644 ui/sdl_keymap.h
delete mode 100644 ui/x_keymap.c
delete mode 100644 ui/x_keymap.h

Makefile +21 -1
index 2bbc547..f776c30 100644
@@ -116,7 +116,45 @@ QEMU_CFLAGS+=$(GLIB_CFLAGS)
 
  ui/cocoa.o: ui/cocoa.m
 
-ui/sdl.o audio/sdlaudio.o ui/sdl_zoom.o baum.o: QEMU_CFLAGS += $(SDL_CFLAGS)
+ui/sdl.o audio/sdlaudio.o ui/sdl_zoom.o ui/sdl_keymap.o baum.o: QEMU_CFLAGS += $(SDL_CFLAGS)
+
+KEYMAP_GEN = ui/keymap-gen.pl
+KEYMAP_CSV = ui/keymaps.csv
+
+SDL_KEYMAPS = \
+        ui/sdl_keymap_xorgevdev2rfb.c \
+        ui/sdl_keymap_xorgkbd2rfb.c \
+        ui/sdl_keymap_xorgxquartz2rfb.c \
+        ui/sdl_keymap_xorgxwin2rfb.c \
+        ui/sdl_keymap_osx2rfb.c \
+        ui/sdl_keymap_win322rfb.c
+
+$(SDL_KEYMAPS): $(KEYMAP_GEN) $(KEYMAP_CSV)
+GENERATED_SOURCES += $(SDL_KEYMAPS)
+
+# Avoid need for perl(Text::CSV) by end users
+# XXXX how does QEMU make file deal with this
+#EXTRA_DIST += $(SDL_KEYMAPS)
+
+ui/sdl_keymap.c: $(SDL_KEYMAPS)
Quoted 8 lines

Makefile QEMU_CFLAGS+=$(GLIB_CFLAGS)

Quoted 3 lines
Makefile +3 -0
+
+ui/sdl_keymap_xorgevdev2rfb.c: $(KEYMAP_CSV)
+	$(call quiet-command,perl $(KEYMAP_GEN) $<   xorgevdev rfb>   $@ || rm $@, "  GEN $@")

I'm not sure I'm prepared to add a perl build dependency. That's particularly hard for Windows users. We could alternatively use a python version of keymap-gen but then we're forking from gtk-vnc/gtk-spice.

I expected as much, which is why I sent the 2nd patch which actually adds the generated files to GIT, so Perl is not required unless someone decides to update the keymaps.csv file.

Quoted 3 lines

Maybe it makes sense to create a small library for dealing with keymaps? Then we could all link against it and probe for that conditionally?

Quoted 7 lines

I don't think it is worth doing a library just for the keymap tables. It could be worth creating a set of add-on libraries (eg libsdl-keymap, libgdk-keymap, etc) for doing the keymap hueristics. In the immediate future though, my intent is to request a GIT repository on freedesktop.org to host the keymaps.csv file and a generator script, which could just be just included in apps using a GIT submodule approach.

Ah, we already do git submodules so I'd much prefer we wait to do this. Is this something that you are going to do in the very near future or only sort of near future?

Quoted 8 lines

I'm not wedded to Perl for the generator, so if it is more convenient to use another language, even C, I can easily do that too.

Is it acceptable to just commit the generated tables to QEMU GIT in the immediate term though, so users can get the fixes without needing perl ?

I'd rather go the git submodule approach than copy code from a separate project.
I can include the .c files in the tree based on the submodule and we can
update the .c files whenever the submodule is bumped.

Regards,

Anthony Liguori

Quoted 1 line

Daniel

#6 lore raw

Re: [Qemu-devel] [PATCH 1/2] Rewrite the way keycode conversions are performed

Quoted 116 lines · Anthony Liguori
Quoted 107 lines · Daniel P. Berrange
Quoted 89 lines · Anthony Liguori
Quoted 88 lines · Daniel P. Berrange

From: "Daniel P. Berrange"<[email protected]>

The SDL video display code needs to convert between the SDL keyboard event keycodes, and QEMU's internal keycode set (a variant of the xt coding). Currently the SDL code is only able todo this when it is built for X11, and running against a Linux X11 server using evdev or xfree86 keymaps. If running against an OS-X or Win32 X11 server the keycode mapping falls back to xfre86, which is completely wrong. There is no mapping at all done, if built against an SDL library with direct Win32 or Quartz display support.

After initial creation, this QEMU code was later copied into GTK-VNC to deal with the same problem. GTK-VNC came across the same problem described above and rewrote the mapping code from scratch. Instead of creating two arrays for the specific conversions required, the GTK-VNC code created a CSV file containing data for all commonly known keycode sets (Linux evdev, OS-X, AT set1, AT set2, AT set3, XT, XT Linux KBD driver, USB HID, Win32, Xwin XT variant, Xorg KBD XT variant). A script is then used to generate C arrays for the particular conversions required. The CSV file has since been reused in both the SPICE-GTK and libvirt codebases, unchanged.

This patch rewrites QEMU's SDL code to use this same approach, and in the process adds support for 4 new targets, SDL X11 on Win32 Xorg server, SDL X11 on OS-X Xorg server, SDL Win32 and SDL Quartz.

In the near future the 'keymap-gen.pl' and 'keymaps.csv' files will be placed into a dedicated GIT repo which can be added to
QEMU, libvirt, SPICE-GTK& GTK-VNC via a git submodule, instead
of requiring manual copying.

* Makefile: Add rules for generating keymap data files
* Makefile.objs: Replace x_keymap.o with sdl_keymap.o
* ui/keymap-gen.pl: Script for generating keycode mapping tables
* ui/keymaps.csv: Master datafile of keycode mappings
* ui/sdl.c: Rewrite sdl_keyevent_to_keycode to use new mapping code
* ui/sdl_keymap.c,ui/sdl_keymap.h: Add APIs for detecting
suitable keymap tables& performing keymap conversions
* ui/x_keymap.[ch]: Remove obsolete files

---
 Makefile         |   40 +++++-
 Makefile.objs    |    2 +-
 ui/keymap-gen.pl |  210 ++++++++++++++++++++++++
 ui/keymaps.csv   |  464 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ui/sdl.c         |   88 ++---------
 ui/sdl_keymap.c  |  241 ++++++++++++++++++++++++++++
 ui/sdl_keymap.h  |   32 ++++
 ui/x_keymap.c    |  168 --------------------
 ui/x_keymap.h    |   32 ----
 9 files changed, 998 insertions(+), 279 deletions(-)
 create mode 100644 ui/keymap-gen.pl
 create mode 100644 ui/keymaps.csv
 create mode 100644 ui/sdl_keymap.c
 create mode 100644 ui/sdl_keymap.h
 delete mode 100644 ui/x_keymap.c
 delete mode 100644 ui/x_keymap.h
Makefile +21 -1
index 2bbc547..f776c30 100644
@@ -116,7 +116,45 @@ QEMU_CFLAGS+=$(GLIB_CFLAGS)
 
 ui/cocoa.o: ui/cocoa.m
 
-ui/sdl.o audio/sdlaudio.o ui/sdl_zoom.o baum.o: QEMU_CFLAGS += $(SDL_CFLAGS)
+ui/sdl.o audio/sdlaudio.o ui/sdl_zoom.o ui/sdl_keymap.o baum.o: QEMU_CFLAGS += $(SDL_CFLAGS)
+
+KEYMAP_GEN = ui/keymap-gen.pl
+KEYMAP_CSV = ui/keymaps.csv
+
+SDL_KEYMAPS = \
+        ui/sdl_keymap_xorgevdev2rfb.c \
+        ui/sdl_keymap_xorgkbd2rfb.c \
+        ui/sdl_keymap_xorgxquartz2rfb.c \
+        ui/sdl_keymap_xorgxwin2rfb.c \
+        ui/sdl_keymap_osx2rfb.c \
+        ui/sdl_keymap_win322rfb.c
+
+$(SDL_KEYMAPS): $(KEYMAP_GEN) $(KEYMAP_CSV)
+GENERATED_SOURCES += $(SDL_KEYMAPS)
+
+# Avoid need for perl(Text::CSV) by end users
+# XXXX how does QEMU make file deal with this
+#EXTRA_DIST += $(SDL_KEYMAPS)
+
+ui/sdl_keymap.c: $(SDL_KEYMAPS)
Quoted 8 lines

Makefile QEMU_CFLAGS+=$(GLIB_CFLAGS)

Quoted 3 lines
Makefile +3 -0
+
+ui/sdl_keymap_xorgevdev2rfb.c: $(KEYMAP_CSV)
+	$(call quiet-command,perl $(KEYMAP_GEN) $<   xorgevdev rfb>   $@ || rm $@, "  GEN $@")

I'm not sure I'm prepared to add a perl build dependency. That's particularly hard for Windows users. We could alternatively use a python version of keymap-gen but then we're forking from gtk-vnc/gtk-spice.

I expected as much, which is why I sent the 2nd patch which actually adds the generated files to GIT, so Perl is not required unless someone decides to update the keymaps.csv file.

Quoted 3 lines

Maybe it makes sense to create a small library for dealing with keymaps? Then we could all link against it and probe for that conditionally?

Quoted 7 lines

I don't think it is worth doing a library just for the keymap tables. It could be worth creating a set of add-on libraries (eg libsdl-keymap, libgdk-keymap, etc) for doing the keymap hueristics. In the immediate future though, my intent is to request a GIT repository on freedesktop.org to host the keymaps.csv file and a generator script, which could just be just included in apps using a GIT submodule approach.

Quoted 3 lines

Ah, we already do git submodules so I'd much prefer we wait to do this. Is this something that you are going to do in the very near future or only sort of near future?

I can probably get it done in the next week or two

Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#7 lore raw

Re: [Qemu-devel] [PATCH 1/2] Rewrite the way keycode conversions are performed

Quoted 117 lines · Daniel P. Berrange
Quoted 116 lines · Anthony Liguori
Quoted 114 lines · Daniel P. Berrange
Quoted 89 lines · Anthony Liguori
Quoted 88 lines · Daniel P. Berrange

From: "Daniel P. Berrange"<[email protected]>

The SDL video display code needs to convert between the SDL keyboard event keycodes, and QEMU's internal keycode set (a variant of the xt coding). Currently the SDL code is only able todo this when it is built for X11, and running against a Linux X11 server using evdev or xfree86 keymaps. If running against an OS-X or Win32 X11 server the keycode mapping falls back to xfre86, which is completely wrong. There is no mapping at all done, if built against an SDL library with direct Win32 or Quartz display support.

After initial creation, this QEMU code was later copied into GTK-VNC to deal with the same problem. GTK-VNC came across the same problem described above and rewrote the mapping code from scratch. Instead of creating two arrays for the specific conversions required, the GTK-VNC code created a CSV file containing data for all commonly known keycode sets (Linux evdev, OS-X, AT set1, AT set2, AT set3, XT, XT Linux KBD driver, USB HID, Win32, Xwin XT variant, Xorg KBD XT variant). A script is then used to generate C arrays for the particular conversions required. The CSV file has since been reused in both the SPICE-GTK and libvirt codebases, unchanged.

This patch rewrites QEMU's SDL code to use this same approach, and in the process adds support for 4 new targets, SDL X11 on Win32 Xorg server, SDL X11 on OS-X Xorg server, SDL Win32 and SDL Quartz.

In the near future the 'keymap-gen.pl' and 'keymaps.csv' files will be placed into a dedicated GIT repo which can be added to
QEMU, libvirt, SPICE-GTK& GTK-VNC via a git submodule, instead
of requiring manual copying.

* Makefile: Add rules for generating keymap data files
* Makefile.objs: Replace x_keymap.o with sdl_keymap.o
* ui/keymap-gen.pl: Script for generating keycode mapping tables
* ui/keymaps.csv: Master datafile of keycode mappings
* ui/sdl.c: Rewrite sdl_keyevent_to_keycode to use new mapping code
* ui/sdl_keymap.c,ui/sdl_keymap.h: Add APIs for detecting
suitable keymap tables& performing keymap conversions
* ui/x_keymap.[ch]: Remove obsolete files

---
  Makefile         |   40 +++++-
  Makefile.objs    |    2 +-
  ui/keymap-gen.pl |  210 ++++++++++++++++++++++++
  ui/keymaps.csv   |  464 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
  ui/sdl.c         |   88 ++---------
  ui/sdl_keymap.c  |  241 ++++++++++++++++++++++++++++
  ui/sdl_keymap.h  |   32 ++++
  ui/x_keymap.c    |  168 --------------------
  ui/x_keymap.h    |   32 ----
  9 files changed, 998 insertions(+), 279 deletions(-)

create mode 100644 ui/keymap-gen.pl
create mode 100644 ui/keymaps.csv
create mode 100644 ui/sdl_keymap.c
create mode 100644 ui/sdl_keymap.h
delete mode 100644 ui/x_keymap.c
delete mode 100644 ui/x_keymap.h

Makefile +21 -1
index 2bbc547..f776c30 100644
@@ -116,7 +116,45 @@ QEMU_CFLAGS+=$(GLIB_CFLAGS)
 
  ui/cocoa.o: ui/cocoa.m
 
-ui/sdl.o audio/sdlaudio.o ui/sdl_zoom.o baum.o: QEMU_CFLAGS += $(SDL_CFLAGS)
+ui/sdl.o audio/sdlaudio.o ui/sdl_zoom.o ui/sdl_keymap.o baum.o: QEMU_CFLAGS += $(SDL_CFLAGS)
+
+KEYMAP_GEN = ui/keymap-gen.pl
+KEYMAP_CSV = ui/keymaps.csv
+
+SDL_KEYMAPS = \
+        ui/sdl_keymap_xorgevdev2rfb.c \
+        ui/sdl_keymap_xorgkbd2rfb.c \
+        ui/sdl_keymap_xorgxquartz2rfb.c \
+        ui/sdl_keymap_xorgxwin2rfb.c \
+        ui/sdl_keymap_osx2rfb.c \
+        ui/sdl_keymap_win322rfb.c
+
+$(SDL_KEYMAPS): $(KEYMAP_GEN) $(KEYMAP_CSV)
+GENERATED_SOURCES += $(SDL_KEYMAPS)
+
+# Avoid need for perl(Text::CSV) by end users
+# XXXX how does QEMU make file deal with this
+#EXTRA_DIST += $(SDL_KEYMAPS)
+
+ui/sdl_keymap.c: $(SDL_KEYMAPS)
Quoted 8 lines

Makefile QEMU_CFLAGS+=$(GLIB_CFLAGS)

Quoted 3 lines
Makefile +3 -0
+
+ui/sdl_keymap_xorgevdev2rfb.c: $(KEYMAP_CSV)
+	$(call quiet-command,perl $(KEYMAP_GEN) $<    xorgevdev rfb>    $@ || rm $@, "  GEN $@")

I'm not sure I'm prepared to add a perl build dependency. That's particularly hard for Windows users. We could alternatively use a python version of keymap-gen but then we're forking from gtk-vnc/gtk-spice.

I expected as much, which is why I sent the 2nd patch which actually adds the generated files to GIT, so Perl is not required unless someone decides to update the keymaps.csv file.

Quoted 3 lines

Maybe it makes sense to create a small library for dealing with keymaps? Then we could all link against it and probe for that conditionally?

I don't think it is worth doing a library just for the keymap tables. It could be worth creating a set of add-on libraries (eg libsdl-keymap, libgdk-keymap, etc) for doing the keymap hueristics. In the immediate future though, my intent is to request a GIT repository on freedesktop.org to host the keymaps.csv file and a generator script, which could just be just included in apps using a GIT submodule approach.

Quoted 5 lines
Quoted 3 lines

Ah, we already do git submodules so I'd much prefer we wait to do this. Is this something that you are going to do in the very near future or only sort of near future?

I can probably get it done in the next week or two

Okay, let me know, and I can help with the submodule bits.

Thanks,

Anthony Liguori

Quoted 2 lines

Daniel