Skip to content

ui/input: Decouple internal and QAPI input events

Akihiko Odaki qemu-arm qemu-devel 3 versions – In review

Get series with b4
b4 am [email protected] change-id 20260428-input-9b94f389ea55

Versions newest first

  1. v3 Latest29 patches 1 replyIn review
  2. v229 patches 1 replySuperseded
  3. v1 RFC28 patches 7 repliesSuperseded

Changes in v3 from the cover letter

- 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/[email protected]

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/29ui/input: Introduce QemuInputEvent typedefchardev/msmouse.c chardev/wctablet.c hw/arm/musicpal.c +19 more+47 -450 replies
2/29ui/input: Remove QAPI wrappers from QemuInputEventchardev/msmouse.c chardev/wctablet.c hw/arm/musicpal.c +16 more+299 -3310 replies
3/29ui/input: Store QKeyCode directly in QemuInputKeyEventhw/arm/musicpal.c hw/char/escc.c hw/display/xenfb.c +11 more+29 -700 replies
4/29ui/input: Use Linux key codes for internal key eventshw/arm/musicpal.c hw/char/escc.c hw/display/xenfb.c +13 more+151 -640 replies
5/29ui/input: Prohibit sending KEY_RESERVEDui/input.c+4 -00 replies
6/29ui/console: Add qemu_text_console_put_linux()include/ui/console.h ui/console.c+46 -220 replies
7/29ui/kbd-state: Use Linux key codesinclude/ui/kbd-state.h ui/cocoa.m ui/dbus-console.c +5 more+108 -590 replies
8/29hw/arm/musicpal: Use Linux key codeshw/arm/musicpal.c+10 -100 replies
9/29hw/char/escc: Use Linux key codeshw/char/escc.c+5 -40 replies
10/29hw/display/xenfb: Use Linux key codeshw/display/xenfb.c+3 -180 replies
11/29hw/input/adb-kbd: Use Linux key codeshw/input/adb-kbd.c+120 -1220 replies
12/29hw/input/hid: Use Linux key codeshw/input/hid.c+1 -20 replies
13/29hw/input/ps2: Use Linux key codeshw/input/ps2.c hw/input/trace-events+26 -270 replies
14/29hw/input/virtio-input: Use Linux key codeshw/input/virtio-input-hid.c+23 -170 replies
15/29hw/m68k/next-kbd: Use Linux key codeshw/m68k/next-kbd.c+59 -590 replies
16/29replay: Use Linux key codesreplay/replay-input.c replay/replay.c+4 -180 replies
17/29ui/cocoa: Use Linux key codesui/cocoa.m+148 -1800 replies
18/29ui/dbus: Use Linux key codesui/dbus-console.c+4 -40 replies
19/29ui/gtk: Use Linux key codesui/gtk.c ui/trace-events ui/x_keymap.c +1 more+45 -350 replies
20/29ui/input-barrier: Use Linux key codesui/input-barrier.c+13 -130 replies
21/29ui/input-legacy: Use Linux key codesui/input-legacy.c+5 -170 replies
22/29ui/input-linux: Use Linux key codesui/input-linux.c+1 -20 replies
23/29ui/keymaps: Use Linux key codesui/keymaps.c+1 -20 replies
24/29ui/sdl2: Use Linux key codesui/sdl2-input.c ui/trace-events+10 -100 replies
25/29ui/spice: Use Linux key codesui/spice-input.c+2 -10 replies
26/29ui/vnc: Use Linux key codesui/vnc.c+13 -160 replies
27/29qemu-keymap: Use Linux key codesqemu-keymap.c+20 -210 replies
28/29ui/console: Remove qemu_text_console_put_qcode()include/ui/console.h ui/console.c+0 -70 replies
29/29ui/input: Remove unused QKeyCode helpers and keymapsinclude/ui/input.h tools/qemu-vnc/input.c ui/input-keymap.c +2 more+0 -1260 replies

Reviews trailers per patch

None of the 29 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchMarc-André Lureau
SeriesR-b
1/29
2/29
3/29
4/29
5/29
6/29
7/29
8/29
9/29
10/29
11/29
12/29
13/29
14/29
15/29
16/29
17/29
18/29
19/29
20/29
21/29
22/29
23/29
24/29
25/29
26/29
27/29
28/29
29/29

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 00/29] ui/input: Decouple internal and QAPI input events

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.

---
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/[email protected]

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/[email protected]

To: [email protected]
Cc: Marc-André Lureau <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Jan Kiszka <[email protected]>
Cc: Peter Maydell <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony PERARD <[email protected]>
Cc: "Edgar E. Iglesias" <[email protected]>
Cc: Mark Cave-Ayland <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Gerd Hoffmann <[email protected]>
Cc: Thomas Huth <[email protected]>
Cc: Alex Bennée <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: Philippe Mathieu-Daudé <[email protected]>
Cc: Akihiko Odaki <[email protected]>

---
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,

Signature · 1 line
Akihiko Odaki <[email protected]>