Re: [PATCH RFC 12/28] hw/input/ps2: Use Linux key codes

2026-05-09 Thread Akihiko Odaki

On 2026/05/10 15:01, [email protected] wrote:

On Sat, 09 May 2026 19:34:24 +0900, Akihiko Odaki 
 wrote:

diff --git a/hw/input/ps2.c b/hw/input/ps2.c
index 93c3c737205..1f266bc6a07 100644
--- a/hw/input/ps2.c
+++ b/hw/input/ps2.c
@@ -126,17 +127,17 @@ static uint8_t translate_table[256] = {
  static unsigned int ps2_modifier_bit(QKeyCode key)


QemuInputKeyEvent.key is unsigned int after patch 4.


I ran a codebase-wide search of QKeyCode but there are clearly 
occurrences I missed (ui/vnc is another case you spotted). I'll 
double-check to ensure there won't be such except the intended cases.


Regards,
Akihiko Odaki



Re: [PATCH RFC 12/28] hw/input/ps2: Use Linux key codes

2026-05-09 Thread marcandre . lureau
On Sat, 09 May 2026 19:34:24 +0900, Akihiko Odaki 
 wrote:
> diff --git a/hw/input/ps2.c b/hw/input/ps2.c
> index 93c3c737205..1f266bc6a07 100644
> --- a/hw/input/ps2.c
> +++ b/hw/input/ps2.c
> @@ -126,17 +127,17 @@ static uint8_t translate_table[256] = {
>  static unsigned int ps2_modifier_bit(QKeyCode key)

QemuInputKeyEvent.key is unsigned int after patch 4.

-- 
Marc-André Lureau 




[PATCH RFC 12/28] hw/input/ps2: Use Linux key codes

2026-05-09 Thread Akihiko Odaki
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 
---
 hw/input/ps2.c| 49 -
 hw/input/trace-events |  2 +-
 2 files changed, 25 insertions(+), 26 deletions(-)

diff --git a/hw/input/ps2.c b/hw/input/ps2.c
index 93c3c7372054..1f266bc6a075 100644
--- a/hw/input/ps2.c
+++ b/hw/input/ps2.c
@@ -28,6 +28,7 @@
 #include "hw/core/sysbus.h"
 #include "hw/input/ps2.h"
 #include "migration/vmstate.h"
+#include "standard-headers/linux/input-event-codes.h"
 #include "ui/console.h"
 #include "ui/input.h"
 #include "system/reset.h"
@@ -126,17 +127,17 @@ static uint8_t translate_table[256] = {
 static unsigned int ps2_modifier_bit(QKeyCode key)
 {
 switch (key) {
-case Q_KEY_CODE_CTRL:
+case KEY_LEFTCTRL:
 return MOD_CTRL_L;
-case Q_KEY_CODE_CTRL_R:
+case KEY_RIGHTCTRL:
 return MOD_CTRL_R;
-case Q_KEY_CODE_SHIFT:
+case KEY_LEFTSHIFT:
 return MOD_SHIFT_L;
-case Q_KEY_CODE_SHIFT_R:
+case KEY_RIGHTSHIFT:
 return MOD_SHIFT_R;
-case Q_KEY_CODE_ALT:
+case KEY_LEFTALT:
 return MOD_ALT_L;
-case Q_KEY_CODE_ALT_R:
+case KEY_RIGHTALT:
 return MOD_ALT_R;
 default:
 return 0;
@@ -313,7 +314,6 @@ static void ps2_keyboard_event(DeviceState *dev, 
QemuConsole *src,
QemuInputEvent *evt)
 {
 PS2KbdState *s = (PS2KbdState *)dev;
-int qcode;
 uint16_t keycode = 0;
 int mod;
 
@@ -324,10 +324,9 @@ static void ps2_keyboard_event(DeviceState *dev, 
QemuConsole *src,
 
 qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER, NULL);
 assert(evt->type == INPUT_EVENT_KIND_KEY);
-qcode = qemu_input_linux_to_qcode(evt->key.key);
 
-mod = ps2_modifier_bit(qcode);
-trace_ps2_keyboard_event(s, qcode, evt->key.down, mod,
+mod = ps2_modifier_bit(evt->key.key);
+trace_ps2_keyboard_event(s, evt->key.key, evt->key.down, mod,
  s->modifiers, s->scancode_set, s->translate);
 if (evt->key.down) {
 s->modifiers |= mod;
@@ -336,7 +335,7 @@ static void ps2_keyboard_event(DeviceState *dev, 
QemuConsole *src,
 }
 
 if (s->scancode_set == 1) {
-if (qcode == Q_KEY_CODE_PAUSE) {
+if (evt->key.key == KEY_PAUSE) {
 if (s->modifiers & (MOD_CTRL_L | MOD_CTRL_R)) {
 if (evt->key.down) {
 ps2_put_keycode(s, 0xe0);
@@ -354,7 +353,7 @@ static void ps2_keyboard_event(DeviceState *dev, 
QemuConsole *src,
 ps2_put_keycode(s, 0xc5);
 }
 }
-} else if (qcode == Q_KEY_CODE_PRINT) {
+} else if (evt->key.key == KEY_SYSRQ) {
 if (s->modifiers & MOD_ALT_L) {
 if (evt->key.down) {
 ps2_put_keycode(s, 0xb8);
@@ -401,12 +400,12 @@ static void ps2_keyboard_event(DeviceState *dev, 
QemuConsole *src,
 ps2_put_keycode(s, 0xaa);
 }
 }
-} else if ((qcode == Q_KEY_CODE_LANG1 || qcode == Q_KEY_CODE_LANG2)
+} else if ((evt->key.key == KEY_HANGEUL || evt->key.key == KEY_HANJA)
&& !evt->key.down) {
 /* Ignore release for these keys */
 } else {
-if (qcode < qemu_input_map_qcode_to_atset1_len) {
-keycode = qemu_input_map_qcode_to_atset1[qcode];
+if (evt->key.key < qemu_input_map_linux_to_atset1_len) {
+keycode = qemu_input_map_linux_to_atset1[evt->key.key];
 }
 if (keycode) {
 if (keycode & 0xff00) {
@@ -418,11 +417,11 @@ static void ps2_keyboard_event(DeviceState *dev, 
QemuConsole *src,
 ps2_put_keycode(s, keycode & 0xff);
 } else {
 qemu_log_mask(LOG_UNIMP,
-  "ps2: ignoring key with qcode %d\n", qcode);
+  "ps2: ignoring key %u\n", evt->key.key);
 }
 }
 } else if (s->scancode_set == 2) {
-if (qcode == Q_KEY_CODE_PAUSE) {
+if (evt->key.key == KEY_PAUSE) {
 if (s->modifiers & (MOD_CTRL_L | MOD_CTRL_R)) {
 if (evt->key.down) {
 ps2_put_keycode(s, 0xe0);
@@ -443,7 +442,7 @@ static void ps2_keyboard_event(DeviceState *dev, 
QemuConsole *src,
 ps2_put_keycode(s, 0x77);
 }
 }
-} else if (qcode == Q_KEY_CODE_PRINT) {
+} else if (evt->key.key == KEY_SYSRQ) {
 if (s->modifiers & MOD_ALT_L) {
 if (evt->key.down) {
 ps2_put_keycode(s, 0xf0);
@@ -499,12 +498,12 @@ static void ps2_keyboard_event(DeviceState *dev, 
QemuConsole *src,
 ps2_put_keycode(s, 0x12);
 }
 }
-} else if ((qcode