Convert frontends to use keycodemapdb
v7 cover Convert frontends to use keycodemapdb
This is a followup to
v1: https://lists.nongnu.org/archive/html/qemu-devel/2017-08/msg02047.html
v2: https://lists.nongnu.org/archive/html/qemu-devel/2017-08/msg02471.html
v3: https://lists.nongnu.org/archive/html/qemu-devel/2017-08/msg02517.html
v4: https://lists.nongnu.org/archive/html/qemu-devel/2017-08/msg02708.html
v5: https://lists.nongnu.org/archive/html/qemu-devel/2017-09/msg02950.html
v6: https://lists.gnu.org/archive/html/qemu-devel/2017-12/msg01988.html
This new series contains just the patches for converting the ui frontends for SDL1, SDL2, and GTK to use keycodemapdb.
The particularly notable benefit is that this includes fixes such that SDL1 and GTK2/3 can actually work when using a non-Linux host Xorg/X11 server. Previously it would display but key handling was complete garbage, making it unusable in practice.
Changed in v7:
- Fix syntax error in win32 hack
Daniel P. Berrange (4):
ui: convert the SDL2 frontend to keycodemapdb
ui: convert GTK and SDL1 frontends to keycodemapdb
ui: add fix for GTK Pause key handling on Win32
ui: ignore hardware keycode 255 on win32
Makefile | 8 ++ include/ui/input.h | 24 +++++ ui/Makefile.objs | 5 +- ui/gtk.c | 220 ++++++++++++++++++++++++++----------------- ui/input-keymap.c | 8 ++ ui/sdl.c | 105 +++++++-------------- ui/sdl2-input.c | 16 +++- ui/sdl2-keymap.h | 267 ----------------------------------------------------- ui/trace-events | 9 +- ui/x_keymap.c | 250 +++++++++++++++++++------------------------------ ui/x_keymap.h | 8 +- 11 files changed, 330 insertions(+), 590 deletions(-) delete mode 100644 ui/sdl2-keymap.h
Signature · 1 line
2.14.3
PATCH v7 1/4 ui: convert the SDL2 frontend to keycodemapdb
The SDL2 scancodes are conveniently identical to the USB scancodes. Replace the sdl2_scancode_to_qcode table with an automatically generated table.
Missing entries in sdl2_scancode_to_qcode now fixed:
- 0x32 -> Q_KEY_CODE_BACKSLASH
- 0x66 -> Q_KEY_CODE_POWER
- 0x67 -> Q_KEY_CODE_KP_EQUALS
- 0x74 -> Q_KEY_CODE_OPEN
- 0x77 -> Q_KEY_CODE_FRONT
- 0x7f -> Q_KEY_CODE_AUDIOMUTE
- 0x80 -> Q_KEY_CODE_VOLUMEUP
- 0x81 -> Q_KEY_CODE_VOLUMEDOWN
- 0x85 -> Q_KEY_CODE_KP_COMMA
- 0x87 -> Q_KEY_CODE_RO
- 0x89 -> Q_KEY_CODE_YEN
- 0x8a -> Q_KEY_CODE_HENKAN
- 0x93 -> Q_KEY_CODE_HIRAGANA
- 0xe8 -> Q_KEY_CODE_AUDIOPLAY
- 0xe9 -> Q_KEY_CODE_AUDIOSTOP
- 0xea -> Q_KEY_CODE_AUDIOPREV
- 0xeb -> Q_KEY_CODE_AUDIONEXT
- 0xed -> Q_KEY_CODE_VOLUMEUP
- 0xee -> Q_KEY_CODE_VOLUMEDOWN
- 0xef -> Q_KEY_CODE_AUDIOMUTE
- 0xf1 -> Q_KEY_CODE_AC_BACK
- 0xf2 -> Q_KEY_CODE_AC_FORWARD
- 0xf3 -> Q_KEY_CODE_STOP
- 0xf4 -> Q_KEY_CODE_FIND
- 0xf8 -> Q_KEY_CODE_SLEEP
- 0xfa -> Q_KEY_CODE_AC_REFRESH
- 0xfb -> Q_KEY_CODE_CALCULATOR
And some mistakes corrected:
- 0x65 -> Q_KEY_CODE_COMPOSE, not duplicating Q_KEY_CODE_MENU
--- Makefile | 1 + include/ui/input.h | 3 + ui/input-keymap.c | 1 + ui/sdl2-input.c | 16 +++- ui/sdl2-keymap.h | 267 ----------------------------------------------------- 5 files changed, 16 insertions(+), 272 deletions(-) delete mode 100644 ui/sdl2-keymap.h
Makefile +1 -0
@@ -236,6 +236,7 @@ KEYCODEMAP_FILES = \ ui/input-keymap-qcode-to-qnum.c \ ui/input-keymap-qnum-to-qcode.c \ ui/input-keymap-qcode-to-linux.c \ + ui/input-keymap-usb-to-qcode.c \ $(NULL) GENERATED_FILES += $(KEYCODEMAP_FILES)
include/ui/input.h +3 -0
@@ -80,4 +80,7 @@ extern const guint16 qemu_input_map_qnum_to_qcode[];extern const guint qemu_input_map_qcode_to_linux_len;extern const guint16 qemu_input_map_qcode_to_linux[]; +extern const guint qemu_input_map_usb_to_qcode_len; +extern const guint16 qemu_input_map_usb_to_qcode[]; +#endif /* INPUT_H */
ui/input-keymap.c +1 -0
@@ -9,6 +9,7 @@#include "ui/input-keymap-qcode-to-qnum.c" #include "ui/input-keymap-qnum-to-qcode.c" #include "ui/input-keymap-qcode-to-linux.c" +#include "ui/input-keymap-usb-to-qcode.c" int qemu_input_linux_to_qcode (unsigned int lnx) {
ui/sdl2-input.c +11 -5
@@ -30,8 +30,6 @@#include "ui/sdl2.h" #include "sysemu/sysemu.h" -#include "sdl2-keymap.h" -static uint8_t modifiers_state[SDL_NUM_SCANCODES ];void sdl2_reset_keys (struct sdl2_console *scon)
@@ -39,9 +37,11 @@ void sdl2_reset_keys(struct sdl2_console *scon)QemuConsole *con = scon ? scon->dcl.con :NULL ;int i; -for (i =0 ; i <SDL_NUM_SCANCODES ; i++) { +for (i =0 ; + i <SDL_NUM_SCANCODES && i < qemu_input_map_usb_to_qcode_len ; + i++) {if (modifiers_state[i]) { -int qcode = sdl2_scancode_to_qcode[i]; +int qcode = qemu_input_map_usb_to_qcode[i];qemu_input_event_send_key_qcode (con, qcode, false); modifiers_state[i] =0 ; }
@@ -51,9 +51,15 @@ void sdl2_reset_keys(struct sdl2_console *scon)void sdl2_process_key (struct sdl2_console *scon,SDL_KeyboardEvent *ev) { -int qcode = sdl2_scancode_to_qcode[ev->keysym.scancode]; +int qcode;QemuConsole *con = scon ? scon->dcl.con :NULL ; +if (ev->keysym.scancode >= qemu_input_map_usb_to_qcode_len) { +return ; + } + + qcode = qemu_input_map_usb_to_qcode[ev->keysym.scancode]; +if (!qemu_console_is_graphic (con)) {if (ev->type ==SDL_KEYDOWN ) {switch (ev->keysym.scancode) {
ui/sdl2-keymap.h deleted +0 -267
267 lines not on this page · raw message
Signature · 1 line
2.14.3
PATCH v7 2/4 ui: convert GTK and SDL1 frontends to keycodemapdb
In reply to Daniel P. BerrangeThe x_keycode_to_pc_keycode and evdev_keycode_to_pc_keycode tables are replaced with automatically generated tables. In addition the X11 heuristics are improved to detect running on XQuartz and XWin X11 servers, to activate the correct OS-X and Win32 keycode maps.
--- Makefile | 7 ++ include/ui/input.h | 21 +++++ ui/Makefile.objs | 5 +- ui/gtk.c | 205 +++++++++++++++++++++++++------------------ ui/input-keymap.c | 7 ++ ui/sdl.c | 105 +++++++--------------- ui/trace-events | 9 +- ui/x_keymap.c | 250 ++++++++++++++++++++--------------------------------- ui/x_keymap.h | 8 +- 9 files changed, 300 insertions(+), 317 deletions(-)
Makefile +7 -0
@@ -232,11 +232,18 @@ KEYCODEMAP_GEN = $(SRC_PATH)/ui/keycodemapdb/tools/keymap-gen KEYCODEMAP_CSV = $(SRC_PATH)/ui/keycodemapdb/data/keymaps.csv KEYCODEMAP_FILES = \ + ui/input-keymap-atset1-to-qcode.c \ ui/input-keymap-linux-to-qcode.c \ ui/input-keymap-qcode-to-qnum.c \ ui/input-keymap-qnum-to-qcode.c \ ui/input-keymap-qcode-to-linux.c \ ui/input-keymap-usb-to-qcode.c \ + ui/input-keymap-win32-to-qcode.c \ + ui/input-keymap-x11-to-qcode.c \ + ui/input-keymap-xorgevdev-to-qcode.c \ + ui/input-keymap-xorgkbd-to-qcode.c \ + ui/input-keymap-xorgxquartz-to-qcode.c \ + ui/input-keymap-xorgxwin-to-qcode.c \ $(NULL) GENERATED_FILES += $(KEYCODEMAP_FILES)
include/ui/input.h +21 -0
@@ -68,6 +68,9 @@ void qemu_input_check_mode_change(void);void qemu_add_mouse_mode_change_notifier (Notifier *notify);void qemu_remove_mouse_mode_change_notifier (Notifier *notify); +extern const guint qemu_input_map_atset1_to_qcode_len; +extern const guint16 qemu_input_map_atset1_to_qcode[]; +extern const guint qemu_input_map_linux_to_qcode_len;extern const guint16 qemu_input_map_linux_to_qcode[];
@@ -83,4 +86,22 @@ extern const guint16 qemu_input_map_qcode_to_linux[];extern const guint qemu_input_map_usb_to_qcode_len;extern const guint16 qemu_input_map_usb_to_qcode[]; +extern const guint qemu_input_map_win32_to_qcode_len; +extern const guint16 qemu_input_map_win32_to_qcode[]; + +extern const guint qemu_input_map_x11_to_qcode_len; +extern const guint16 qemu_input_map_x11_to_qcode[]; + +extern const guint qemu_input_map_xorgevdev_to_qcode_len; +extern const guint16 qemu_input_map_xorgevdev_to_qcode[]; + +extern const guint qemu_input_map_xorgkbd_to_qcode_len; +extern const guint16 qemu_input_map_xorgkbd_to_qcode[]; + +extern const guint qemu_input_map_xorgxquartz_to_qcode_len; +extern const guint16 qemu_input_map_xorgxquartz_to_qcode[]; + +extern const guint qemu_input_map_xorgxwin_to_qcode_len; +extern const guint16 qemu_input_map_xorgxwin_to_qcode[]; +#endif /* INPUT_H */
ui/Makefile.objs +3 -2
@@ -11,11 +11,12 @@ common-obj-y += keymaps.o console.o cursor.o qemu-pixman.o common-obj-y += input.o input-keymap.o input-legacy.o common-obj-$(CONFIG_LINUX) += input-linux.o common-obj-$(CONFIG_SPICE) += spice-core.o spice-input.o spice-display.o -common-obj-$(CONFIG_SDL) += sdl.mo x_keymap.o +common-obj-$(CONFIG_SDL) += sdl.mo common-obj-$(CONFIG_COCOA) += cocoa.o common-obj-$(CONFIG_CURSES) += curses.o common-obj-$(CONFIG_VNC) += $(vnc-obj-y) -common-obj-$(CONFIG_GTK) += gtk.o x_keymap.o +common-obj-$(CONFIG_GTK) += gtk.o +common-obj-$(if $(CONFIG_WIN32),n,$(if $(CONFIG_SDL),y,$(CONFIG_GTK))) += x_keymap.o ifeq ($(CONFIG_SDLABI),1.2) sdl.mo-objs := sdl.o sdl_zoom.o
ui/gtk.c +123 -82
307 lines not on this page · raw message
ui/input-keymap.c +7 -0
@@ -5,11 +5,18 @@#include "standard-headers/linux/input.h" +#include "ui/input-keymap-atset1-to-qcode.c" #include "ui/input-keymap-linux-to-qcode.c" #include "ui/input-keymap-qcode-to-qnum.c" #include "ui/input-keymap-qnum-to-qcode.c" #include "ui/input-keymap-qcode-to-linux.c" #include "ui/input-keymap-usb-to-qcode.c" +#include "ui/input-keymap-win32-to-qcode.c" +#include "ui/input-keymap-x11-to-qcode.c" +#include "ui/input-keymap-xorgevdev-to-qcode.c" +#include "ui/input-keymap-xorgkbd-to-qcode.c" +#include "ui/input-keymap-xorgxquartz-to-qcode.c" +#include "ui/input-keymap-xorgxwin-to-qcode.c" int qemu_input_linux_to_qcode (unsigned int lnx) {
ui/sdl.c +31 -74
144 lines not on this page · raw message
ui/trace-events +8 -1
@@ -18,9 +18,10 @@ ppm_save(const char *filename, void *display_surface) "%s surface=%p" # ui/gtk.c gd_switch(const char *tab, int width, int height) "tab=%s, width=%d, height=%d" gd_update(const char *tab, int x, int y, int w, int h) "tab=%s, x=%d, y=%d, w=%d, h=%d" -gd_key_event(const char *tab, int gdk_keycode, int qemu_keycode, const char *action) "tab=%s, translated GDK keycode %d to QEMU keycode %d (%s)" +gd_key_event(const char *tab, int gdk_keycode, int qkeycode, const char *action) "tab=%s, translated GDK keycode %d to QKeyCode %d (%s)" gd_grab(const char *tab, const char *device, const char *reason) "tab=%s, dev=%s, reason=%s" gd_ungrab(const char *tab, const char *device) "tab=%s, dev=%s" +gd_keymap_windowing(const char *name) "backend=%s" # ui/vnc.c vnc_key_guest_leds(bool caps, bool num, bool scroll) "caps %d, num %d, scroll %d"
@@ -79,3 +80,9 @@ qemu_spice_create_update(uint32_t left, uint32_t right, uint32_t top, uint32_t b keymap_parse(const char *file) "file %s" keymap_add(const char *type, int sym, int code, const char *line) "%-6s sym=0x%04x code=0x%04x (line: %s)" keymap_unmapped(int sym) "sym=0x%04x" + +# ui/x_keymap.c +xkeymap_extension(const char *name) "extension '%s'" +xkeymap_vendor(const char *name) "vendor '%s'" +xkeymap_keycodes(const char *name) "keycodes '%s'" +xkeymap_keymap(const char *name) "keymap '%s'"
ui/x_keymap.c +96 -154
265 lines not on this page · raw message
ui/x_keymap.h +4 -4
@@ -1,7 +1,7 @@/* -* QEMU SDL display driver +* QEMU X11 keymaps * -* Copyright (c) 2003 Fabrice Bellard +* Copyright (c) 2017 Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal
@@ -25,8 +25,8 @@#ifndef QEMU_X_KEYMAP_H #define QEMU_X_KEYMAP_H -uint8_t translate_xfree86_keycode (const int key); +#include <X11/Xlib.h> -uint8_t translate_evdev_keycode (const int key); +const guint16 *qemu_xkeymap_mapping_table (Display *dpy,size_t *maplen);#endif
Signature · 1 line
2.14.3
PATCH v7 3/4 ui: add fix for GTK Pause key handling on Win32
In reply to Daniel P. BerrangeVersions of GTK prior to 3.22 did not correctly set the keyval field when VK_PAUSE was received on Windows.
--- ui/gtk.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
ui/gtk.c +8 -1
@@ -1206,7 +1206,14 @@ static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque)return TRUE; } -if (key->keyval == GDK_KEY_Pause) { + if (key->keyval == GDK_KEY_Pause +#ifdef G_OS_WIN32 +/* for some reason GDK does not fill keyval for VK_PAUSE +* See https://bugzilla.gnome.org/show_bug.cgi?id=769214 +*/ + || key->hardware_keycode ==VK_PAUSE +#endif + ) {qemu_input_event_send_key_qcode (vc->gfx.dcl.con,Q_KEY_CODE_PAUSE , key->type ==GDK_KEY_PRESS );return TRUE;
Signature · 1 line
2.14.3
PATCH v7 4/4 ui: ignore hardware keycode 255 on win32
In reply to Daniel P. BerrangeIt is a reserved value and doesn't have a corresponding valid scancode.
--- ui/gtk.c | 6 ++++++ 1 file changed, 6 insertions(+)
ui/gtk.c +6 -0
@@ -1206,6 +1206,12 @@ static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque)return TRUE; } +#ifdef WIN32 +/* on windows, we ought to ignore the reserved key event? */ +if (key->hardware_keycode ==0xff ) +return false; +#endif + if (key->keyval == GDK_KEY_Pause#ifdef G_OS_WIN32 /* for some reason GDK does not fill keyval for VK_PAUSE
Signature · 1 line
2.14.3