@samitouri / QOSamiQemu / commits / c4ba089be4

qemu-keymap: Use Linux key codes

QemuInputEvent now stores Linux key codes for key events. Use those codes directly instead of translating between internal key code representations. Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-ID: <20260520-input-v3-27-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp>

Akihiko Odaki committed May 20, 2026 at 15:48 UTC c4ba089be4f96e4c9e5826847d016c9e7e11ef6d
1 file changed +20 -21
qemu-keymap.c
+20 -21
@@ -11,6 +11,7 @@
11 */
12 #include "qemu/osdep.h"
13 #include "qemu/notify.h"
14 +#include "standard-headers/linux/input-event-codes.h"
15 #include "ui/input.h"
16
17 #include <xkbcommon/xkbcommon.h>
@@ -32,19 +33,17 @@ static FILE *outfile;
33
34 /* ------------------------------------------------------------------------ */
35
35 -static uint32_t qcode_to_number(uint32_t qcode)
36 +static uint32_t linux_to_number(uint32_t lnx)
37 {
37 - KeyValue keyvalue;
38 uint32_t number;
39
40 - keyvalue.type = KEY_VALUE_KIND_QCODE;
41 - keyvalue.u.qcode.data = qcode;
42 - number = qemu_input_key_value_to_number(&keyvalue);
40 + assert(lnx < qemu_input_map_linux_to_qnum_len);
41 + number = qemu_input_map_linux_to_qnum[lnx];
42 assert(number != 0);
43 return number;
44 }
45
47 -static void print_sym(xkb_keysym_t sym, uint32_t qcode, const char *mod)
46 +static void print_sym(xkb_keysym_t sym, uint32_t lnx, const char *mod)
47 {
48 char name[64];
49
@@ -54,7 +53,7 @@ static void print_sym(xkb_keysym_t sym, uint32_t qcode, const char *mod)
53 xkb_keysym_get_name(sym, name, sizeof(name));
54
55 /* TODO: make ui/keymap.c parser accept QKeyCode names */
57 - fprintf(outfile, "%s 0x%02x%s\n", name, qcode_to_number(qcode), mod);
56 + fprintf(outfile, "%s 0x%02x%s\n", name, linux_to_number(lnx), mod);
57 }
58
59 static void walk_map(struct xkb_keymap *map, xkb_keycode_t code, void *data)
@@ -84,37 +83,37 @@ static void walk_map(struct xkb_keymap *map, xkb_keycode_t code, void *data)
83 fprintf(outfile, "# evdev %d (0x%x), QKeyCode \"%s\", number 0x%x\n",
84 evdev, evdev,
85 QKeyCode_str(qcode),
87 - qcode_to_number(qcode));
86 + linux_to_number(evdev));
87
88 /*
89 * check which modifier states generate which keysyms
90 */
91 xkb_state_update_mask(state, 0, 0, 0, 0, 0, 0);
92 kbase = xkb_state_key_get_one_sym(state, code);
94 - print_sym(kbase, qcode, "");
93 + print_sym(kbase, evdev, "");
94
95 xkb_state_update_mask(state, 0, 0, numlock, 0, 0, 0);
96 knumlock = xkb_state_key_get_one_sym(state, code);
97 if (kbase != knumlock) {
99 - print_sym(knumlock, qcode, " numlock");
98 + print_sym(knumlock, evdev, " numlock");
99 }
100
101 xkb_state_update_mask(state, shift, 0, 0, 0, 0, 0);
102 kshift = xkb_state_key_get_one_sym(state, code);
103 if (kbase != kshift && knumlock != kshift) {
105 - print_sym(kshift, qcode, " shift");
104 + print_sym(kshift, evdev, " shift");
105 }
106
107 xkb_state_update_mask(state, altgr, 0, 0, 0, 0, 0);
108 kaltgr = xkb_state_key_get_one_sym(state, code);
109 if (kbase != kaltgr) {
111 - print_sym(kaltgr, qcode, " altgr");
110 + print_sym(kaltgr, evdev, " altgr");
111 }
112
113 xkb_state_update_mask(state, altgr | shift, 0, 0, 0, 0, 0);
114 kaltgrshift = xkb_state_key_get_one_sym(state, code);
115 if (kshift != kaltgrshift && kaltgr != kaltgrshift) {
117 - print_sym(kaltgrshift, qcode, " shift altgr");
116 + print_sym(kaltgrshift, evdev, " shift altgr");
117 }
118 }
119
@@ -251,16 +250,16 @@ int main(int argc, char *argv[])
250 "# keysyms. So append them here.\n"
251 "#\n"
252 "\n");
254 - print_sym(XKB_KEY_Print, Q_KEY_CODE_SYSRQ, "");
255 - print_sym(XKB_KEY_Sys_Req, Q_KEY_CODE_SYSRQ, "");
256 - print_sym(XKB_KEY_Execute, Q_KEY_CODE_SYSRQ, "");
253 + print_sym(XKB_KEY_Print, KEY_SYSRQ, "");
254 + print_sym(XKB_KEY_Sys_Req, KEY_SYSRQ, "");
255 + print_sym(XKB_KEY_Execute, KEY_SYSRQ, "");
256
258 - print_sym(XKB_KEY_KP_Decimal, Q_KEY_CODE_KP_DECIMAL, " numlock");
259 - print_sym(XKB_KEY_KP_Separator, Q_KEY_CODE_KP_DECIMAL, " numlock");
257 + print_sym(XKB_KEY_KP_Decimal, KEY_KPDOT, " numlock");
258 + print_sym(XKB_KEY_KP_Separator, KEY_KPDOT, " numlock");
259
261 - print_sym(XKB_KEY_Alt_R, Q_KEY_CODE_ALT_R, "");
262 - print_sym(XKB_KEY_ISO_Level3_Shift, Q_KEY_CODE_ALT_R, "");
263 - print_sym(XKB_KEY_Mode_switch, Q_KEY_CODE_ALT_R, "");
260 + print_sym(XKB_KEY_Alt_R, KEY_RIGHTALT, "");
261 + print_sym(XKB_KEY_ISO_Level3_Shift, KEY_RIGHTALT, "");
262 + print_sym(XKB_KEY_Mode_switch, KEY_RIGHTALT, "");
263
264 fprintf(outfile,
265 "\n"