The internal input event representation has different requirements from
the QAPI representation. Using QAPI types directly spreads QAPI-specific
constraints throughout the internal input code. Keep that impact
localized by decoupling the two representations with a dedicated
conversion layer. The decoupled internal representation has the
following benefits:
- It avoids wrapper structs and pointer indirections required by QAPI.
They are useful at the QMP boundary, but unnecessary for internal
input events and make handlers more verbose.
- It enforces a single key code set while QAPI input events allow key
codes to be stored either as qnum or qcode. Having two code sets is
useful for QMP compatibility, but complicates internal input handling.
Commit af07e5ff02ae ("ui: convert key events to QKeyCodes
immediately") made qcode the only key code set used internally, but
the QAPI type does not enforce that and accessing the key code is
still tedious.
- It uses Linux key codes. They cover all keys represented by qcodes,
include additional keys, and allow QEMU to pass codes through from
Linux hosts to Linux guests. This also simplifies the code by avoiding
qcode aliases and matches the approach used by virtio and Xen. Since
this is an internal representation, QEMU can extend the key code set
if a QEMU-specific need arises.
Only the switch to Linux key codes is intended to change functional
behavior. The interfaces that require QKeyCode are still preserved and
QKeyCode_str() is still used to query key names. Changing QAPI to accept
Linux key codes is possible, but out of scope for this series.
This series is organized as follows:
Patches 1-6 convert the internal interfaces.
Patches 7-26 convert their users.
Patches 27-28 remove the old internal interfaces.
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
---
Changes in v3:
- Fixed qemu_input_event_send_key_number() to send the converted Linux key
code directly.
- Updated tools/qemu-vnc for the input event API changes.
- Prevented ui/kbd-state from reading or writing past its key bitmap
when given a key code outside the defined range.
- Changed Linux key code variables to use unsigned int.
- Link to v2: https://lore.kernel.org/qemu-devel/20260513-input-v2-0-b3cc0470308a@rsg.ci.i.u-tokyo.ac.jp
Changes in v2:
- Fixed an accidental overwrite of the key value in patch
"ui/input: Remove QAPI wrappers from QemuInputEvent".
- Added patch "ui/input: Prohibit sending KEY_RESERVED".
- Removed remaining unintended QKeyCode occurrences.
- Link to v1: https://lore.kernel.org/qemu-devel/20260509-input-v1-0-66f18d2edde6@rsg.ci.i.u-tokyo.ac.jp
To: qemu-devel@nongnu.org
Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Jan Kiszka <jan.kiszka@web.de>
Cc: Peter Maydell <peter.maydell@linaro.org>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Anthony PERARD <anthony@xenproject.org>
Cc: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>
Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Thomas Huth <th.huth+qemu@posteo.eu>
Cc: Alex Bennée <alex.bennee@linaro.org>
Cc: qemu-arm@nongnu.org
Cc: xen-devel@lists.xenproject.org
Cc: qemu-ppc@nongnu.org
Cc: Philippe Mathieu-Daudé <philmd@linaro.org>
Cc: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
---
Akihiko Odaki (29):
ui/input: Introduce QemuInputEvent typedef
ui/input: Remove QAPI wrappers from QemuInputEvent
ui/input: Store QKeyCode directly in QemuInputKeyEvent
ui/input: Use Linux key codes for internal key events
ui/input: Prohibit sending KEY_RESERVED
ui/console: Add qemu_text_console_put_linux()
ui/kbd-state: Use Linux key codes
hw/arm/musicpal: Use Linux key codes
hw/char/escc: Use Linux key codes
hw/display/xenfb: Use Linux key codes
hw/input/adb-kbd: Use Linux key codes
hw/input/hid: Use Linux key codes
hw/input/ps2: Use Linux key codes
hw/input/virtio-input: Use Linux key codes
hw/m68k/next-kbd: Use Linux key codes
replay: Use Linux key codes
ui/cocoa: Use Linux key codes
ui/dbus: Use Linux key codes
ui/gtk: Use Linux key codes
ui/input-barrier: Use Linux key codes
ui/input-legacy: Use Linux key codes
ui/input-linux: Use Linux key codes
ui/keymaps: Use Linux key codes
ui/sdl2: Use Linux key codes
ui/spice: Use Linux key codes
ui/vnc: Use Linux key codes
qemu-keymap: Use Linux key codes
ui/console: Remove qemu_text_console_put_qcode()
ui/input: Remove unused QKeyCode helpers and keymaps
include/qemu/typedefs.h | 1 +
include/system/replay.h | 2 +-
include/ui/console.h | 3 +-
include/ui/input.h | 92 ++++++++------
include/ui/kbd-state.h | 12 +-
replay/replay-internal.h | 6 +-
ui/x_keymap.h | 3 +-
chardev/msmouse.c | 12 +-
chardev/wctablet.c | 10 +-
hw/arm/musicpal.c | 31 +++--
hw/char/escc.c | 45 +++----
hw/display/xenfb.c | 51 +++-----
hw/input/adb-kbd.c | 246 ++++++++++++++++++------------------
hw/input/adb-mouse.c | 22 ++--
hw/input/hid.c | 41 +++---
hw/input/ps2.c | 118 +++++++++---------
hw/input/stellaris_gamepad.c | 11 +-
hw/input/virtio-input-hid.c | 89 +++++++------
hw/m68k/next-kbd.c | 128 +++++++++----------
qemu-keymap.c | 41 +++---
replay/replay-events.c | 6 +-
replay/replay-input.c | 117 ++++++------------
replay/replay.c | 2 +-
replay/stubs-system.c | 2 +-
tools/qemu-vnc/input.c | 9 +-
ui/console.c | 62 ++++++----
ui/dbus-console.c | 8 +-
ui/gtk.c | 50 ++++----
ui/input-barrier.c | 26 ++--
ui/input-keymap.c | 74 +++++------
ui/input-legacy.c | 47 +++----
ui/input-linux.c | 3 +-
ui/input.c | 214 ++++++++++++++------------------
ui/kbd-state.c | 61 +++++----
ui/keymaps.c | 4 +-
ui/sdl2-input.c | 17 +--
ui/spice-input.c | 3 +-
ui/vdagent.c | 20 ++-
ui/vnc.c | 25 ++--
ui/x_keymap.c | 24 ++--
hw/input/trace-events | 2 +-
tools/qemu-vnc/trace-events | 2 +-
ui/cocoa.m | 289 ++++++++++++++++++++++---------------------
ui/meson.build | 29 +++--
ui/trace-events | 5 +-
45 files changed, 980 insertions(+), 1085 deletions(-)
---
base-commit: e89049b3ba5f1f0468bc0d294173345597514a1b
change-id: 20260428-input-9b94f389ea55
Best regards,
--
Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>