:p
atchew
Login
From: Marc-André Lureau <marcandre.lureau@redhat.com> The following changes since commit 9ef497755afc252fb8e060c9ea6b0987abfd20b6: Merge tag 'pull-vfio-20230911' of https://github.com/legoater/qemu into staging (2023-09-11 09:13:08 -0400) are available in the Git repository at: https://gitlab.com/marcandre.lureau/qemu.git tags/ui-pull-request for you to fetch changes up to a92e7bb4cad57cc5c8817fb18fb25650507b69f8: ui: add precondition for dpy_get_ui_info() (2023-09-12 11:14:09 +0400) ---------------------------------------------------------------- UI patch queue - vhost-user-gpu: support dmabuf modifiers - fix VNC crash when there are no active_console - cleanups and refactoring in ui/vc code ---------------------------------------------------------------- Erico Nunes (3): docs: vhost-user-gpu: add protocol changes for dmabuf modifiers contrib/vhost-user-gpu: add support for sending dmabuf modifiers vhost-user-gpu: support dmabuf modifiers Marc-André Lureau (11): vmmouse: replace DPRINTF with tracing vmmouse: use explicit code ui/vc: remove kbd_put_keysym() and update function calls ui/vc: rename kbd_put to qemu_text_console functions ui/console: remove redundant format field ui/vc: preliminary QemuTextConsole changes before split ui/vc: split off the VC part from console.c ui/console: move DisplaySurface to its own header virtio-gpu/win32: set the destroy function on load ui: fix crash when there are no active_console ui: add precondition for dpy_get_ui_info() docs/interop/vhost-user-gpu.rst | 26 +- contrib/vhost-user-gpu/vugpu.h | 9 + include/ui/console.h | 94 +- include/ui/surface.h | 95 ++ ui/console-priv.h | 43 + contrib/vhost-user-gpu/vhost-user-gpu.c | 5 +- contrib/vhost-user-gpu/virgl.c | 51 +- hw/display/vhost-user-gpu.c | 17 +- hw/display/virtio-gpu.c | 4 +- hw/i386/vmmouse.c | 40 +- ui/console-gl.c | 2 +- ui/console-vc.c | 1079 ++++++++++++++++++++++ ui/console.c | 1119 +---------------------- ui/curses.c | 2 +- ui/gtk.c | 8 +- ui/sdl2-input.c | 4 +- ui/sdl2.c | 2 +- ui/spice-display.c | 2 +- ui/vnc.c | 56 +- hw/i386/trace-events | 10 + ui/cocoa.m | 2 +- ui/meson.build | 1 + 22 files changed, 1426 insertions(+), 1245 deletions(-) create mode 100644 include/ui/surface.h create mode 100644 ui/console-priv.h create mode 100644 ui/console-vc.c -- 2.41.0
From: Erico Nunes <ernunes@redhat.com> VHOST_USER_GPU_DMABUF_SCANOUT2 is defined as a message with all the contents of VHOST_USER_GPU_DMABUF_SCANOUT plus the dmabuf modifiers which were ommitted. The VHOST_USER_GPU_PROTOCOL_F_DMABUF2 protocol feature is defined as a way to check whether this new message is supported or not. Signed-off-by: Erico Nunes <ernunes@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Sergio Lopez <slp@redhat.com> Message-Id: <20230714153900.475857-2-ernunes@redhat.com> --- docs/interop/vhost-user-gpu.rst | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/interop/vhost-user-gpu.rst b/docs/interop/vhost-user-gpu.rst index XXXXXXX..XXXXXXX 100644 --- a/docs/interop/vhost-user-gpu.rst +++ b/docs/interop/vhost-user-gpu.rst @@ -XXX,XX +XXX,XX @@ VhostUserGpuEdidRequest :scanout-id: ``u32``, the scanout to get edid from +VhostUserGpuDMABUFScanout2 +^^^^^^^^^^^^^^^^^^^^^^^^^^ + ++----------------+----------+ +| dmabuf_scanout | modifier | ++----------------+----------+ + +:dmabuf_scanout: ``VhostUserGpuDMABUFScanout``, filled as described in the + VhostUserGpuDMABUFScanout structure. + +:modifier: ``u64``, the DMABUF modifiers + + C structure ----------- @@ -XXX,XX +XXX,XX @@ Protocol features .. code:: c - #define VHOST_USER_GPU_PROTOCOL_F_EDID 0 + #define VHOST_USER_GPU_PROTOCOL_F_EDID 0 + #define VHOST_USER_GPU_PROTOCOL_F_DMABUF2 1 New messages and communication changes are negotiated thanks to the ``VHOST_USER_GPU_GET_PROTOCOL_FEATURES`` and @@ -XXX,XX +XXX,XX @@ Message types Retrieve the EDID data for a given scanout. This message requires the ``VHOST_USER_GPU_PROTOCOL_F_EDID`` protocol feature to be supported. + +``VHOST_USER_GPU_DMABUF_SCANOUT2`` + :id: 12 + :request payload: ``VhostUserGpuDMABUFScanout2`` + :reply payload: N/A + + Same as VHOST_USER_GPU_DMABUF_SCANOUT, but also sends the dmabuf modifiers + appended to the message, which were not provided in the other message. + This message requires the ``VHOST_USER_GPU_PROTOCOL_F_DMABUF2`` protocol + feature to be supported. -- 2.41.0
From: Erico Nunes <ernunes@redhat.com> virglrenderer recently added virgl_renderer_resource_get_info_ext as a new api, which gets resource information, including dmabuf modifiers. We have to support dmabuf modifiers since the driver may choose to allocate buffers with these modifiers for efficiency, and importing buffers without modifiers information may result in completely broken rendering. Signed-off-by: Erico Nunes <ernunes@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Sergio Lopez <slp@redhat.com> Message-Id: <20230714153900.475857-3-ernunes@redhat.com> --- contrib/vhost-user-gpu/vugpu.h | 9 +++++ contrib/vhost-user-gpu/vhost-user-gpu.c | 5 ++- contrib/vhost-user-gpu/virgl.c | 51 +++++++++++++++++++++++-- 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/contrib/vhost-user-gpu/vugpu.h b/contrib/vhost-user-gpu/vugpu.h index XXXXXXX..XXXXXXX 100644 --- a/contrib/vhost-user-gpu/vugpu.h +++ b/contrib/vhost-user-gpu/vugpu.h @@ -XXX,XX +XXX,XX @@ typedef enum VhostUserGpuRequest { VHOST_USER_GPU_DMABUF_SCANOUT, VHOST_USER_GPU_DMABUF_UPDATE, VHOST_USER_GPU_GET_EDID, + VHOST_USER_GPU_DMABUF_SCANOUT2, } VhostUserGpuRequest; typedef struct VhostUserGpuDisplayInfoReply { @@ -XXX,XX +XXX,XX @@ typedef struct VhostUserGpuDMABUFScanout { int fd_drm_fourcc; } QEMU_PACKED VhostUserGpuDMABUFScanout; +typedef struct VhostUserGpuDMABUFScanout2 { + struct VhostUserGpuDMABUFScanout dmabuf_scanout; + uint64_t modifier; +} QEMU_PACKED VhostUserGpuDMABUFScanout2; + typedef struct VhostUserGpuEdidRequest { uint32_t scanout_id; } QEMU_PACKED VhostUserGpuEdidRequest; @@ -XXX,XX +XXX,XX @@ typedef struct VhostUserGpuMsg { VhostUserGpuScanout scanout; VhostUserGpuUpdate update; VhostUserGpuDMABUFScanout dmabuf_scanout; + VhostUserGpuDMABUFScanout2 dmabuf_scanout2; VhostUserGpuEdidRequest edid_req; struct virtio_gpu_resp_edid resp_edid; struct virtio_gpu_resp_display_info display_info; @@ -XXX,XX +XXX,XX @@ static VhostUserGpuMsg m __attribute__ ((unused)); #define VHOST_USER_GPU_MSG_FLAG_REPLY 0x4 #define VHOST_USER_GPU_PROTOCOL_F_EDID 0 +#define VHOST_USER_GPU_PROTOCOL_F_DMABUF2 1 struct virtio_gpu_scanout { uint32_t width, height; @@ -XXX,XX +XXX,XX @@ typedef struct VuGpu { bool virgl; bool virgl_inited; bool edid_inited; + bool use_modifiers; uint32_t inflight; struct virtio_gpu_scanout scanout[VIRTIO_GPU_MAX_SCANOUTS]; diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c b/contrib/vhost-user-gpu/vhost-user-gpu.c index XXXXXXX..XXXXXXX 100644 --- a/contrib/vhost-user-gpu/vhost-user-gpu.c +++ b/contrib/vhost-user-gpu/vhost-user-gpu.c @@ -XXX,XX +XXX,XX @@ static gboolean protocol_features_cb(gint fd, GIOCondition condition, gpointer user_data) { const uint64_t protocol_edid = (1 << VHOST_USER_GPU_PROTOCOL_F_EDID); + const uint64_t protocol_dmabuf2 = (1 << VHOST_USER_GPU_PROTOCOL_F_DMABUF2); VuGpu *g = user_data; uint64_t protocol_features; VhostUserGpuMsg msg = { @@ -XXX,XX +XXX,XX @@ protocol_features_cb(gint fd, GIOCondition condition, gpointer user_data) return G_SOURCE_CONTINUE; } - protocol_features &= protocol_edid; + protocol_features &= (protocol_edid | protocol_dmabuf2); msg = (VhostUserGpuMsg) { .request = VHOST_USER_GPU_SET_PROTOCOL_FEATURES, @@ -XXX,XX +XXX,XX @@ protocol_features_cb(gint fd, GIOCondition condition, gpointer user_data) exit(EXIT_FAILURE); } + g->use_modifiers = !!(protocol_features & protocol_dmabuf2); + return G_SOURCE_REMOVE; } diff --git a/contrib/vhost-user-gpu/virgl.c b/contrib/vhost-user-gpu/virgl.c index XXXXXXX..XXXXXXX 100644 --- a/contrib/vhost-user-gpu/virgl.c +++ b/contrib/vhost-user-gpu/virgl.c @@ -XXX,XX +XXX,XX @@ virgl_resource_detach_backing(VuGpu *g, vg_cleanup_mapping_iov(g, res_iovs, num_iovs); } +static int +virgl_get_resource_info_modifiers(uint32_t resource_id, + struct virgl_renderer_resource_info *info, + uint64_t *modifiers) +{ + int ret; +#ifdef VIRGL_RENDERER_RESOURCE_INFO_EXT_VERSION + struct virgl_renderer_resource_info_ext info_ext; + ret = virgl_renderer_resource_get_info_ext(resource_id, &info_ext); + if (ret < 0) { + return ret; + } + + *info = info_ext.base; + *modifiers = info_ext.modifiers; +#else + ret = virgl_renderer_resource_get_info(resource_id, info); + if (ret < 0) { + return ret; + } + + /* + * Before virgl_renderer_resource_get_info_ext, + * getting the modifiers was not possible. + */ + *modifiers = 0; +#endif + + return 0; +} + static void virgl_cmd_set_scanout(VuGpu *g, struct virtio_gpu_ctrl_command *cmd) @@ -XXX,XX +XXX,XX @@ virgl_cmd_set_scanout(VuGpu *g, memset(&info, 0, sizeof(info)); if (ss.resource_id && ss.r.width && ss.r.height) { - ret = virgl_renderer_resource_get_info(ss.resource_id, &info); + uint64_t modifiers = 0; + ret = virgl_get_resource_info_modifiers(ss.resource_id, &info, + &modifiers); if (ret == -1) { g_critical("%s: illegal resource specified %d\n", __func__, ss.resource_id); @@ -XXX,XX +XXX,XX @@ virgl_cmd_set_scanout(VuGpu *g, } assert(fd >= 0); VhostUserGpuMsg msg = { - .request = VHOST_USER_GPU_DMABUF_SCANOUT, - .size = sizeof(VhostUserGpuDMABUFScanout), .payload.dmabuf_scanout.scanout_id = ss.scanout_id, .payload.dmabuf_scanout.x = ss.r.x, .payload.dmabuf_scanout.y = ss.r.y, @@ -XXX,XX +XXX,XX @@ virgl_cmd_set_scanout(VuGpu *g, .payload.dmabuf_scanout.fd_flags = info.flags, .payload.dmabuf_scanout.fd_drm_fourcc = info.drm_fourcc }; + + if (g->use_modifiers) { + /* + * The mesage uses all the fields set in dmabuf_scanout plus + * modifiers which is appended after VhostUserGpuDMABUFScanout. + */ + msg.request = VHOST_USER_GPU_DMABUF_SCANOUT2; + msg.size = sizeof(VhostUserGpuDMABUFScanout2); + msg.payload.dmabuf_scanout2.modifier = modifiers; + } else { + msg.request = VHOST_USER_GPU_DMABUF_SCANOUT; + msg.size = sizeof(VhostUserGpuDMABUFScanout); + } + vg_send_msg(g, &msg, fd); close(fd); } else { -- 2.41.0
From: Erico Nunes <ernunes@redhat.com> When the backend sends VHOST_USER_GPU_DMABUF_SCANOUT2, handle it by getting the modifiers information which is now available. Signed-off-by: Erico Nunes <ernunes@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Sergio Lopez <slp@redhat.com> Message-Id: <20230714153900.475857-4-ernunes@redhat.com> --- hw/display/vhost-user-gpu.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c index XXXXXXX..XXXXXXX 100644 --- a/hw/display/vhost-user-gpu.c +++ b/hw/display/vhost-user-gpu.c @@ -XXX,XX +XXX,XX @@ typedef enum VhostUserGpuRequest { VHOST_USER_GPU_DMABUF_SCANOUT, VHOST_USER_GPU_DMABUF_UPDATE, VHOST_USER_GPU_GET_EDID, + VHOST_USER_GPU_DMABUF_SCANOUT2, } VhostUserGpuRequest; typedef struct VhostUserGpuDisplayInfoReply { @@ -XXX,XX +XXX,XX @@ typedef struct VhostUserGpuDMABUFScanout { int fd_drm_fourcc; } QEMU_PACKED VhostUserGpuDMABUFScanout; +typedef struct VhostUserGpuDMABUFScanout2 { + struct VhostUserGpuDMABUFScanout dmabuf_scanout; + uint64_t modifier; +} QEMU_PACKED VhostUserGpuDMABUFScanout2; + typedef struct VhostUserGpuEdidRequest { uint32_t scanout_id; } QEMU_PACKED VhostUserGpuEdidRequest; @@ -XXX,XX +XXX,XX @@ typedef struct VhostUserGpuMsg { VhostUserGpuScanout scanout; VhostUserGpuUpdate update; VhostUserGpuDMABUFScanout dmabuf_scanout; + VhostUserGpuDMABUFScanout2 dmabuf_scanout2; VhostUserGpuEdidRequest edid_req; struct virtio_gpu_resp_edid resp_edid; struct virtio_gpu_resp_display_info display_info; @@ -XXX,XX +XXX,XX @@ static VhostUserGpuMsg m __attribute__ ((unused)); #define VHOST_USER_GPU_MSG_FLAG_REPLY 0x4 #define VHOST_USER_GPU_PROTOCOL_F_EDID 0 +#define VHOST_USER_GPU_PROTOCOL_F_DMABUF2 1 static void vhost_user_gpu_update_blocked(VhostUserGPU *g, bool blocked); @@ -XXX,XX +XXX,XX @@ vhost_user_gpu_handle_display(VhostUserGPU *g, VhostUserGpuMsg *msg) .flags = VHOST_USER_GPU_MSG_FLAG_REPLY, .size = sizeof(uint64_t), .payload = { - .u64 = (1 << VHOST_USER_GPU_PROTOCOL_F_EDID) + .u64 = (1 << VHOST_USER_GPU_PROTOCOL_F_EDID) | + (1 << VHOST_USER_GPU_PROTOCOL_F_DMABUF2) } }; @@ -XXX,XX +XXX,XX @@ vhost_user_gpu_handle_display(VhostUserGPU *g, VhostUserGpuMsg *msg) break; } + case VHOST_USER_GPU_DMABUF_SCANOUT2: case VHOST_USER_GPU_DMABUF_SCANOUT: { VhostUserGpuDMABUFScanout *m = &msg->payload.dmabuf_scanout; int fd = qemu_chr_fe_get_msgfd(&g->vhost_chr); @@ -XXX,XX +XXX,XX @@ vhost_user_gpu_handle_display(VhostUserGPU *g, VhostUserGpuMsg *msg) .fourcc = m->fd_drm_fourcc, .y0_top = m->fd_flags & VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP, }; + if (msg->request == VHOST_USER_GPU_DMABUF_SCANOUT2) { + VhostUserGpuDMABUFScanout2 *m2 = &msg->payload.dmabuf_scanout2; + dmabuf->modifier = m2->modifier; + } + dpy_gl_scanout_dmabuf(con, dmabuf); break; } -- 2.41.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- hw/i386/vmmouse.c | 29 ++++++++++++++--------------- hw/i386/trace-events | 10 ++++++++++ 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/hw/i386/vmmouse.c b/hw/i386/vmmouse.c index XXXXXXX..XXXXXXX 100644 --- a/hw/i386/vmmouse.c +++ b/hw/i386/vmmouse.c @@ -XXX,XX +XXX,XX @@ #include "cpu.h" #include "qom/object.h" +#include "trace.h" + /* debug only vmmouse */ //#define DEBUG_VMMOUSE @@ -XXX,XX +XXX,XX @@ #define VMMOUSE_RIGHT_BUTTON 0x10 #define VMMOUSE_MIDDLE_BUTTON 0x08 -#ifdef DEBUG_VMMOUSE -#define DPRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__) -#else -#define DPRINTF(fmt, ...) do { } while (0) -#endif - #define TYPE_VMMOUSE "vmmouse" OBJECT_DECLARE_SIMPLE_TYPE(VMMouseState, VMMOUSE) @@ -XXX,XX +XXX,XX @@ static void vmmouse_set_data(const uint32_t *data) static uint32_t vmmouse_get_status(VMMouseState *s) { - DPRINTF("vmmouse_get_status()\n"); + trace_vmmouse_get_status(); + return (s->status << 16) | s->nb_queue; } @@ -XXX,XX +XXX,XX @@ static void vmmouse_mouse_event(void *opaque, int x, int y, int dz, int buttons_ if (s->nb_queue > (VMMOUSE_QUEUE_SIZE - 4)) return; - DPRINTF("vmmouse_mouse_event(%d, %d, %d, %d)\n", - x, y, dz, buttons_state); + trace_vmmouse_mouse_event(x, y, dz, buttons_state); if ((buttons_state & MOUSE_EVENT_LBUTTON)) buttons |= VMMOUSE_LEFT_BUTTON; @@ -XXX,XX +XXX,XX @@ static void vmmouse_update_handler(VMMouseState *s, int absolute) static void vmmouse_read_id(VMMouseState *s) { - DPRINTF("vmmouse_read_id()\n"); + trace_vmmouse_read_id(); if (s->nb_queue == VMMOUSE_QUEUE_SIZE) return; @@ -XXX,XX +XXX,XX @@ static void vmmouse_read_id(VMMouseState *s) static void vmmouse_request_relative(VMMouseState *s) { - DPRINTF("vmmouse_request_relative()\n"); + trace_vmmouse_request_relative(); + vmmouse_update_handler(s, 0); } static void vmmouse_request_absolute(VMMouseState *s) { - DPRINTF("vmmouse_request_absolute()\n"); + trace_vmmouse_request_absolute(); + vmmouse_update_handler(s, 1); } static void vmmouse_disable(VMMouseState *s) { - DPRINTF("vmmouse_disable()\n"); + trace_vmmouse_disable(); + s->status = 0xffff; vmmouse_remove_handler(s); } @@ -XXX,XX +XXX,XX @@ static void vmmouse_data(VMMouseState *s, uint32_t *data, uint32_t size) { int i; - DPRINTF("vmmouse_data(%d)\n", size); + trace_vmmouse_data(size); if (size == 0 || size > 6 || size > s->nb_queue) { printf("vmmouse: driver requested too much data %d\n", size); @@ -XXX,XX +XXX,XX @@ static void vmmouse_realizefn(DeviceState *dev, Error **errp) { VMMouseState *s = VMMOUSE(dev); - DPRINTF("vmmouse_init\n"); + trace_vmmouse_init(); if (!s->i8042) { error_setg(errp, "'i8042' link is not set"); diff --git a/hw/i386/trace-events b/hw/i386/trace-events index XXXXXXX..XXXXXXX 100644 --- a/hw/i386/trace-events +++ b/hw/i386/trace-events @@ -XXX,XX +XXX,XX @@ x86_pic_interrupt(int irqn, int level) "PIC interrupt #%d level:%d" # port92.c port92_read(uint8_t val) "port92: read 0x%02x" port92_write(uint8_t val) "port92: write 0x%02x" + +# vmmouse.c +vmmouse_get_status(void) "" +vmmouse_mouse_event(int x, int y, int dz, int buttons_state) "event: x=%d y=%d dz=%d state=%d" +vmmouse_init(void) "" +vmmouse_read_id(void) "" +vmmouse_request_relative(void) "" +vmmouse_request_absolute(void) "" +vmmouse_disable(void) "" +vmmouse_data(uint32_t size) "data: size=%" PRIu32 -- 2.41.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> It's weird to shift x & y without obvious reason. Let's make this more explicit and future-proof. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- hw/i386/vmmouse.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/hw/i386/vmmouse.c b/hw/i386/vmmouse.c index XXXXXXX..XXXXXXX 100644 --- a/hw/i386/vmmouse.c +++ b/hw/i386/vmmouse.c @@ -XXX,XX +XXX,XX @@ #define VMMOUSE_RIGHT_BUTTON 0x10 #define VMMOUSE_MIDDLE_BUTTON 0x08 +#define VMMOUSE_MIN_X 0 +#define VMMOUSE_MIN_Y 0 +#define VMMOUSE_MAX_X 0xFFFF +#define VMMOUSE_MAX_Y 0xFFFF + #define TYPE_VMMOUSE "vmmouse" OBJECT_DECLARE_SIMPLE_TYPE(VMMouseState, VMMOUSE) @@ -XXX,XX +XXX,XX @@ static void vmmouse_mouse_event(void *opaque, int x, int y, int dz, int buttons_ buttons |= VMMOUSE_MIDDLE_BUTTON; if (s->absolute) { - x <<= 1; - y <<= 1; + x = qemu_input_scale_axis(x, + INPUT_EVENT_ABS_MIN, INPUT_EVENT_ABS_MAX, + VMMOUSE_MIN_X, VMMOUSE_MAX_X); + y = qemu_input_scale_axis(y, + INPUT_EVENT_ABS_MIN, INPUT_EVENT_ABS_MAX, + VMMOUSE_MIN_Y, VMMOUSE_MAX_Y); } else{ /* add for guest vmmouse driver to judge this is a relative packet. */ buttons |= VMMOUSE_RELATIVE_PACKET; -- 2.41.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> The function calls to `kbd_put_keysym` have been updated to now call `kbd_put_keysym_console` with a NULL console parameter. Like most console functions, NULL argument is now for the active console. This will allow to rename the text console functions in a consistent manner. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> --- include/ui/console.h | 1 - ui/console.c | 14 ++++++------ ui/curses.c | 2 +- ui/vnc.c | 54 ++++++++++++++++++++++---------------------- ui/cocoa.m | 2 +- 5 files changed, 36 insertions(+), 37 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index XXXXXXX..XXXXXXX 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -XXX,XX +XXX,XX @@ bool qemu_mouse_set(int index, Error **errp); void kbd_put_keysym_console(QemuTextConsole *s, int keysym); bool kbd_put_qcode_console(QemuTextConsole *s, int qcode, bool ctrl); void kbd_put_string_console(QemuTextConsole *s, const char *str, int len); -void kbd_put_keysym(int keysym); /* Touch devices */ typedef struct touch_slot { diff --git a/ui/console.c b/ui/console.c index XXXXXXX..XXXXXXX 100644 --- a/ui/console.c +++ b/ui/console.c @@ -XXX,XX +XXX,XX @@ void kbd_put_keysym_console(QemuTextConsole *s, int keysym) int c; uint32_t num_free; + if (!s) { + if (!QEMU_IS_TEXT_CONSOLE(active_console)) { + return; + } + s = QEMU_TEXT_CONSOLE(active_console); + } + switch(keysym) { case QEMU_KEY_CTRL_UP: console_scroll(s, -1); @@ -XXX,XX +XXX,XX @@ void kbd_put_string_console(QemuTextConsole *s, const char *str, int len) } } -void kbd_put_keysym(int keysym) -{ - if (QEMU_IS_TEXT_CONSOLE(active_console)) { - kbd_put_keysym_console(QEMU_TEXT_CONSOLE(active_console), keysym); - } -} - static void text_console_invalidate(void *opaque) { QemuTextConsole *s = QEMU_TEXT_CONSOLE(opaque); diff --git a/ui/curses.c b/ui/curses.c index XXXXXXX..XXXXXXX 100644 --- a/ui/curses.c +++ b/ui/curses.c @@ -XXX,XX +XXX,XX @@ static void curses_refresh(DisplayChangeListener *dcl) if (keysym == -1) keysym = chr; - kbd_put_keysym(keysym); + kbd_put_keysym_console(NULL, keysym); } } } diff --git a/ui/vnc.c b/ui/vnc.c index XXXXXXX..XXXXXXX 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -XXX,XX +XXX,XX @@ static void do_key_event(VncState *vs, int down, int keycode, int sym) case 0xb8: /* Right ALT */ break; case 0xc8: - kbd_put_keysym(QEMU_KEY_UP); + kbd_put_keysym_console(NULL, QEMU_KEY_UP); break; case 0xd0: - kbd_put_keysym(QEMU_KEY_DOWN); + kbd_put_keysym_console(NULL, QEMU_KEY_DOWN); break; case 0xcb: - kbd_put_keysym(QEMU_KEY_LEFT); + kbd_put_keysym_console(NULL, QEMU_KEY_LEFT); break; case 0xcd: - kbd_put_keysym(QEMU_KEY_RIGHT); + kbd_put_keysym_console(NULL, QEMU_KEY_RIGHT); break; case 0xd3: - kbd_put_keysym(QEMU_KEY_DELETE); + kbd_put_keysym_console(NULL, QEMU_KEY_DELETE); break; case 0xc7: - kbd_put_keysym(QEMU_KEY_HOME); + kbd_put_keysym_console(NULL, QEMU_KEY_HOME); break; case 0xcf: - kbd_put_keysym(QEMU_KEY_END); + kbd_put_keysym_console(NULL, QEMU_KEY_END); break; case 0xc9: - kbd_put_keysym(QEMU_KEY_PAGEUP); + kbd_put_keysym_console(NULL, QEMU_KEY_PAGEUP); break; case 0xd1: - kbd_put_keysym(QEMU_KEY_PAGEDOWN); + kbd_put_keysym_console(NULL, QEMU_KEY_PAGEDOWN); break; case 0x47: - kbd_put_keysym(numlock ? '7' : QEMU_KEY_HOME); + kbd_put_keysym_console(NULL, numlock ? '7' : QEMU_KEY_HOME); break; case 0x48: - kbd_put_keysym(numlock ? '8' : QEMU_KEY_UP); + kbd_put_keysym_console(NULL, numlock ? '8' : QEMU_KEY_UP); break; case 0x49: - kbd_put_keysym(numlock ? '9' : QEMU_KEY_PAGEUP); + kbd_put_keysym_console(NULL, numlock ? '9' : QEMU_KEY_PAGEUP); break; case 0x4b: - kbd_put_keysym(numlock ? '4' : QEMU_KEY_LEFT); + kbd_put_keysym_console(NULL, numlock ? '4' : QEMU_KEY_LEFT); break; case 0x4c: - kbd_put_keysym('5'); + kbd_put_keysym_console(NULL, '5'); break; case 0x4d: - kbd_put_keysym(numlock ? '6' : QEMU_KEY_RIGHT); + kbd_put_keysym_console(NULL, numlock ? '6' : QEMU_KEY_RIGHT); break; case 0x4f: - kbd_put_keysym(numlock ? '1' : QEMU_KEY_END); + kbd_put_keysym_console(NULL, numlock ? '1' : QEMU_KEY_END); break; case 0x50: - kbd_put_keysym(numlock ? '2' : QEMU_KEY_DOWN); + kbd_put_keysym_console(NULL, numlock ? '2' : QEMU_KEY_DOWN); break; case 0x51: - kbd_put_keysym(numlock ? '3' : QEMU_KEY_PAGEDOWN); + kbd_put_keysym_console(NULL, numlock ? '3' : QEMU_KEY_PAGEDOWN); break; case 0x52: - kbd_put_keysym('0'); + kbd_put_keysym_console(NULL, '0'); break; case 0x53: - kbd_put_keysym(numlock ? '.' : QEMU_KEY_DELETE); + kbd_put_keysym_console(NULL, numlock ? '.' : QEMU_KEY_DELETE); break; case 0xb5: - kbd_put_keysym('/'); + kbd_put_keysym_console(NULL, '/'); break; case 0x37: - kbd_put_keysym('*'); + kbd_put_keysym_console(NULL, '*'); break; case 0x4a: - kbd_put_keysym('-'); + kbd_put_keysym_console(NULL, '-'); break; case 0x4e: - kbd_put_keysym('+'); + kbd_put_keysym_console(NULL, '+'); break; case 0x9c: - kbd_put_keysym('\n'); + kbd_put_keysym_console(NULL, '\n'); break; default: if (control) { - kbd_put_keysym(sym & 0x1f); + kbd_put_keysym_console(NULL, sym & 0x1f); } else { - kbd_put_keysym(sym); + kbd_put_keysym_console(NULL, sym); } break; } diff --git a/ui/cocoa.m b/ui/cocoa.m index XXXXXXX..XXXXXXX 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -XXX,XX +XXX,XX @@ - (void) handleMonitorInput:(NSEvent *)event } if (keysym) { - kbd_put_keysym(keysym); + kbd_put_keysym_console(NULL, keysym); } } -- 2.41.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> They are QemuTextConsole functions, let's make it clear. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> --- include/ui/console.h | 6 ++--- ui/console.c | 10 ++++---- ui/curses.c | 2 +- ui/gtk.c | 6 ++--- ui/sdl2-input.c | 4 ++-- ui/sdl2.c | 2 +- ui/vnc.c | 54 ++++++++++++++++++++++---------------------- ui/cocoa.m | 2 +- 8 files changed, 43 insertions(+), 43 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index XXXXXXX..XXXXXXX 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -XXX,XX +XXX,XX @@ bool qemu_mouse_set(int index, Error **errp); #define QEMU_KEY_CTRL_PAGEUP 0xe406 #define QEMU_KEY_CTRL_PAGEDOWN 0xe407 -void kbd_put_keysym_console(QemuTextConsole *s, int keysym); -bool kbd_put_qcode_console(QemuTextConsole *s, int qcode, bool ctrl); -void kbd_put_string_console(QemuTextConsole *s, const char *str, int len); +void qemu_text_console_put_keysym(QemuTextConsole *s, int keysym); +bool qemu_text_console_put_qcode(QemuTextConsole *s, int qcode, bool ctrl); +void qemu_text_console_put_string(QemuTextConsole *s, const char *str, int len); /* Touch devices */ typedef struct touch_slot { diff --git a/ui/console.c b/ui/console.c index XXXXXXX..XXXXXXX 100644 --- a/ui/console.c +++ b/ui/console.c @@ -XXX,XX +XXX,XX @@ static void kbd_send_chars(QemuTextConsole *s) } /* called when an ascii key is pressed */ -void kbd_put_keysym_console(QemuTextConsole *s, int keysym) +void qemu_text_console_put_keysym(QemuTextConsole *s, int keysym) { uint8_t buf[16], *q; int c; @@ -XXX,XX +XXX,XX @@ static const int ctrl_qcode_to_keysym[Q_KEY_CODE__MAX] = { [Q_KEY_CODE_PGDN] = QEMU_KEY_CTRL_PAGEDOWN, }; -bool kbd_put_qcode_console(QemuTextConsole *s, int qcode, bool ctrl) +bool qemu_text_console_put_qcode(QemuTextConsole *s, int qcode, bool ctrl) { int keysym; @@ -XXX,XX +XXX,XX @@ bool kbd_put_qcode_console(QemuTextConsole *s, int qcode, bool ctrl) if (keysym == 0) { return false; } - kbd_put_keysym_console(s, keysym); + qemu_text_console_put_keysym(s, keysym); return true; } -void kbd_put_string_console(QemuTextConsole *s, const char *str, int len) +void qemu_text_console_put_string(QemuTextConsole *s, const char *str, int len) { int i; for (i = 0; i < len && str[i]; i++) { - kbd_put_keysym_console(s, str[i]); + qemu_text_console_put_keysym(s, str[i]); } } diff --git a/ui/curses.c b/ui/curses.c index XXXXXXX..XXXXXXX 100644 --- a/ui/curses.c +++ b/ui/curses.c @@ -XXX,XX +XXX,XX @@ static void curses_refresh(DisplayChangeListener *dcl) if (keysym == -1) keysym = chr; - kbd_put_keysym_console(NULL, keysym); + qemu_text_console_put_keysym(NULL, keysym); } } } diff --git a/ui/gtk.c b/ui/gtk.c index XXXXXXX..XXXXXXX 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -XXX,XX +XXX,XX @@ static gboolean gd_text_key_down(GtkWidget *widget, QemuTextConsole *con = QEMU_TEXT_CONSOLE(vc->gfx.dcl.con); if (key->keyval == GDK_KEY_Delete) { - kbd_put_qcode_console(con, Q_KEY_CODE_DELETE, false); + qemu_text_console_put_qcode(con, Q_KEY_CODE_DELETE, false); } else if (key->length) { - kbd_put_string_console(con, key->string, key->length); + qemu_text_console_put_string(con, key->string, key->length); } else { int qcode = gd_map_keycode(gd_get_keycode(key)); - kbd_put_qcode_console(con, qcode, false); + qemu_text_console_put_qcode(con, qcode, false); } return TRUE; } diff --git a/ui/sdl2-input.c b/ui/sdl2-input.c index XXXXXXX..XXXXXXX 100644 --- a/ui/sdl2-input.c +++ b/ui/sdl2-input.c @@ -XXX,XX +XXX,XX @@ void sdl2_process_key(struct sdl2_console *scon, if (ev->type == SDL_KEYDOWN) { switch (qcode) { case Q_KEY_CODE_RET: - kbd_put_keysym_console(s, '\n'); + qemu_text_console_put_keysym(s, '\n'); break; default: - kbd_put_qcode_console(s, qcode, ctrl); + qemu_text_console_put_qcode(s, qcode, ctrl); break; } } diff --git a/ui/sdl2.c b/ui/sdl2.c index XXXXXXX..XXXXXXX 100644 --- a/ui/sdl2.c +++ b/ui/sdl2.c @@ -XXX,XX +XXX,XX @@ static void handle_textinput(SDL_Event *ev) } if (QEMU_IS_TEXT_CONSOLE(con)) { - kbd_put_string_console(QEMU_TEXT_CONSOLE(con), ev->text.text, strlen(ev->text.text)); + qemu_text_console_put_string(QEMU_TEXT_CONSOLE(con), ev->text.text, strlen(ev->text.text)); } } diff --git a/ui/vnc.c b/ui/vnc.c index XXXXXXX..XXXXXXX 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -XXX,XX +XXX,XX @@ static void do_key_event(VncState *vs, int down, int keycode, int sym) case 0xb8: /* Right ALT */ break; case 0xc8: - kbd_put_keysym_console(NULL, QEMU_KEY_UP); + qemu_text_console_put_keysym(NULL, QEMU_KEY_UP); break; case 0xd0: - kbd_put_keysym_console(NULL, QEMU_KEY_DOWN); + qemu_text_console_put_keysym(NULL, QEMU_KEY_DOWN); break; case 0xcb: - kbd_put_keysym_console(NULL, QEMU_KEY_LEFT); + qemu_text_console_put_keysym(NULL, QEMU_KEY_LEFT); break; case 0xcd: - kbd_put_keysym_console(NULL, QEMU_KEY_RIGHT); + qemu_text_console_put_keysym(NULL, QEMU_KEY_RIGHT); break; case 0xd3: - kbd_put_keysym_console(NULL, QEMU_KEY_DELETE); + qemu_text_console_put_keysym(NULL, QEMU_KEY_DELETE); break; case 0xc7: - kbd_put_keysym_console(NULL, QEMU_KEY_HOME); + qemu_text_console_put_keysym(NULL, QEMU_KEY_HOME); break; case 0xcf: - kbd_put_keysym_console(NULL, QEMU_KEY_END); + qemu_text_console_put_keysym(NULL, QEMU_KEY_END); break; case 0xc9: - kbd_put_keysym_console(NULL, QEMU_KEY_PAGEUP); + qemu_text_console_put_keysym(NULL, QEMU_KEY_PAGEUP); break; case 0xd1: - kbd_put_keysym_console(NULL, QEMU_KEY_PAGEDOWN); + qemu_text_console_put_keysym(NULL, QEMU_KEY_PAGEDOWN); break; case 0x47: - kbd_put_keysym_console(NULL, numlock ? '7' : QEMU_KEY_HOME); + qemu_text_console_put_keysym(NULL, numlock ? '7' : QEMU_KEY_HOME); break; case 0x48: - kbd_put_keysym_console(NULL, numlock ? '8' : QEMU_KEY_UP); + qemu_text_console_put_keysym(NULL, numlock ? '8' : QEMU_KEY_UP); break; case 0x49: - kbd_put_keysym_console(NULL, numlock ? '9' : QEMU_KEY_PAGEUP); + qemu_text_console_put_keysym(NULL, numlock ? '9' : QEMU_KEY_PAGEUP); break; case 0x4b: - kbd_put_keysym_console(NULL, numlock ? '4' : QEMU_KEY_LEFT); + qemu_text_console_put_keysym(NULL, numlock ? '4' : QEMU_KEY_LEFT); break; case 0x4c: - kbd_put_keysym_console(NULL, '5'); + qemu_text_console_put_keysym(NULL, '5'); break; case 0x4d: - kbd_put_keysym_console(NULL, numlock ? '6' : QEMU_KEY_RIGHT); + qemu_text_console_put_keysym(NULL, numlock ? '6' : QEMU_KEY_RIGHT); break; case 0x4f: - kbd_put_keysym_console(NULL, numlock ? '1' : QEMU_KEY_END); + qemu_text_console_put_keysym(NULL, numlock ? '1' : QEMU_KEY_END); break; case 0x50: - kbd_put_keysym_console(NULL, numlock ? '2' : QEMU_KEY_DOWN); + qemu_text_console_put_keysym(NULL, numlock ? '2' : QEMU_KEY_DOWN); break; case 0x51: - kbd_put_keysym_console(NULL, numlock ? '3' : QEMU_KEY_PAGEDOWN); + qemu_text_console_put_keysym(NULL, numlock ? '3' : QEMU_KEY_PAGEDOWN); break; case 0x52: - kbd_put_keysym_console(NULL, '0'); + qemu_text_console_put_keysym(NULL, '0'); break; case 0x53: - kbd_put_keysym_console(NULL, numlock ? '.' : QEMU_KEY_DELETE); + qemu_text_console_put_keysym(NULL, numlock ? '.' : QEMU_KEY_DELETE); break; case 0xb5: - kbd_put_keysym_console(NULL, '/'); + qemu_text_console_put_keysym(NULL, '/'); break; case 0x37: - kbd_put_keysym_console(NULL, '*'); + qemu_text_console_put_keysym(NULL, '*'); break; case 0x4a: - kbd_put_keysym_console(NULL, '-'); + qemu_text_console_put_keysym(NULL, '-'); break; case 0x4e: - kbd_put_keysym_console(NULL, '+'); + qemu_text_console_put_keysym(NULL, '+'); break; case 0x9c: - kbd_put_keysym_console(NULL, '\n'); + qemu_text_console_put_keysym(NULL, '\n'); break; default: if (control) { - kbd_put_keysym_console(NULL, sym & 0x1f); + qemu_text_console_put_keysym(NULL, sym & 0x1f); } else { - kbd_put_keysym_console(NULL, sym); + qemu_text_console_put_keysym(NULL, sym); } break; } diff --git a/ui/cocoa.m b/ui/cocoa.m index XXXXXXX..XXXXXXX 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -XXX,XX +XXX,XX @@ - (void) handleMonitorInput:(NSEvent *)event } if (keysym) { - kbd_put_keysym_console(NULL, keysym); + qemu_text_console_put_keysym(NULL, keysym); } } -- 2.41.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> It's already part of PIXMAN image. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> --- include/ui/console.h | 15 +++++++-------- ui/console-gl.c | 2 +- ui/console.c | 4 +--- ui/gtk.c | 2 +- ui/spice-display.c | 2 +- ui/vnc.c | 2 +- 6 files changed, 12 insertions(+), 15 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index XXXXXXX..XXXXXXX 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -XXX,XX +XXX,XX @@ typedef struct ScanoutTexture { } ScanoutTexture; typedef struct DisplaySurface { - pixman_format_code_t format; pixman_image_t *image; uint8_t flags; #ifdef CONFIG_OPENGL @@ -XXX,XX +XXX,XX @@ static inline int surface_height(DisplaySurface *s) return pixman_image_get_height(s->image); } +static inline pixman_format_code_t surface_format(DisplaySurface *s) +{ + return pixman_image_get_format(s->image); +} + static inline int surface_bits_per_pixel(DisplaySurface *s) { - int bits = PIXMAN_FORMAT_BPP(s->format); + int bits = PIXMAN_FORMAT_BPP(surface_format(s)); return bits; } static inline int surface_bytes_per_pixel(DisplaySurface *s) { - int bits = PIXMAN_FORMAT_BPP(s->format); + int bits = PIXMAN_FORMAT_BPP(surface_format(s)); return DIV_ROUND_UP(bits, 8); } -static inline pixman_format_code_t surface_format(DisplaySurface *s) -{ - return s->format; -} - typedef uint32_t console_ch_t; static inline void console_write_ch(console_ch_t *dest, uint32_t ch) diff --git a/ui/console-gl.c b/ui/console-gl.c index XXXXXXX..XXXXXXX 100644 --- a/ui/console-gl.c +++ b/ui/console-gl.c @@ -XXX,XX +XXX,XX @@ void surface_gl_create_texture(QemuGLShader *gls, return; } - switch (surface->format) { + switch (surface_format(surface)) { case PIXMAN_BE_b8g8r8x8: case PIXMAN_BE_b8g8r8a8: surface->glformat = GL_BGRA_EXT; diff --git a/ui/console.c b/ui/console.c index XXXXXXX..XXXXXXX 100644 --- a/ui/console.c +++ b/ui/console.c @@ -XXX,XX +XXX,XX @@ DisplaySurface *qemu_create_displaysurface_from(int width, int height, DisplaySurface *surface = g_new0(DisplaySurface, 1); trace_displaysurface_create_from(surface, width, height, format); - surface->format = format; - surface->image = pixman_image_create_bits(surface->format, + surface->image = pixman_image_create_bits(format, width, height, (void *)data, linesize); assert(surface->image != NULL); @@ -XXX,XX +XXX,XX @@ DisplaySurface *qemu_create_displaysurface_pixman(pixman_image_t *image) DisplaySurface *surface = g_new0(DisplaySurface, 1); trace_displaysurface_create_pixman(surface); - surface->format = pixman_image_get_format(image); surface->image = pixman_image_ref(image); return surface; diff --git a/ui/gtk.c b/ui/gtk.c index XXXXXXX..XXXXXXX 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -XXX,XX +XXX,XX @@ static void gd_switch(DisplayChangeListener *dcl, } vc->gfx.ds = surface; - if (surface->format == PIXMAN_x8r8g8b8) { + if (surface_format(surface) == PIXMAN_x8r8g8b8) { /* * PIXMAN_x8r8g8b8 == CAIRO_FORMAT_RGB24 * diff --git a/ui/spice-display.c b/ui/spice-display.c index XXXXXXX..XXXXXXX 100644 --- a/ui/spice-display.c +++ b/ui/spice-display.c @@ -XXX,XX +XXX,XX @@ void qemu_spice_display_switch(SimpleSpiceDisplay *ssd, } if (ssd->ds) { ssd->surface = pixman_image_ref(ssd->ds->image); - ssd->mirror = qemu_pixman_mirror_create(ssd->ds->format, + ssd->mirror = qemu_pixman_mirror_create(surface_format(ssd->ds), ssd->ds->image); qemu_spice_create_host_primary(ssd); } diff --git a/ui/vnc.c b/ui/vnc.c index XXXXXXX..XXXXXXX 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -XXX,XX +XXX,XX @@ static void vnc_dpy_switch(DisplayChangeListener *dcl, /* guest surface */ qemu_pixman_image_unref(vd->guest.fb); vd->guest.fb = pixman_image_ref(surface->image); - vd->guest.format = surface->format; + vd->guest.format = surface_format(surface); if (pageflip) { -- 2.41.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> Those changes will help to split console.c unit in the following commit. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> --- ui/console.c | 52 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/ui/console.c b/ui/console.c index XXXXXXX..XXXXXXX 100644 --- a/ui/console.c +++ b/ui/console.c @@ -XXX,XX +XXX,XX @@ static QEMUTimer *cursor_timer; static void dpy_refresh(DisplayState *s); static DisplayState *get_alloc_displaystate(void); -static void text_console_update_cursor(void *opaque); +static void qemu_text_console_update_cursor(void *opaque); static bool displaychangelistener_has_dmabuf(DisplayChangeListener *dcl); static bool console_compatible_with(QemuConsole *con, DisplayChangeListener *dcl, Error **errp); @@ -XXX,XX +XXX,XX @@ static void displaychangelistener_display_console(DisplayChangeListener *dcl, } } +static void +qemu_text_console_select(QemuTextConsole *c) +{ + dpy_text_resize(QEMU_CONSOLE(c), c->width, c->height); + qemu_text_console_update_cursor(NULL); +} + void console_select(unsigned int index) { DisplayChangeListener *dcl; @@ -XXX,XX +XXX,XX @@ void console_select(unsigned int index) } if (QEMU_IS_TEXT_CONSOLE(s)) { - dpy_text_resize(s, QEMU_TEXT_CONSOLE(s)->width, QEMU_TEXT_CONSOLE(s)->height); - text_console_update_cursor(NULL); + qemu_text_console_select(QEMU_TEXT_CONSOLE(s)); } } } @@ -XXX,XX +XXX,XX @@ static void kbd_send_chars(QemuTextConsole *s) } /* called when an ascii key is pressed */ -void qemu_text_console_put_keysym(QemuTextConsole *s, int keysym) +static void qemu_text_console_handle_keysym(QemuTextConsole *s, int keysym) { uint8_t buf[16], *q; int c; uint32_t num_free; - if (!s) { - if (!QEMU_IS_TEXT_CONSOLE(active_console)) { - return; - } - s = QEMU_TEXT_CONSOLE(active_console); - } - switch(keysym) { case QEMU_KEY_CTRL_UP: console_scroll(s, -1); @@ -XXX,XX +XXX,XX @@ void qemu_text_console_put_keysym(QemuTextConsole *s, int keysym) } } +void qemu_text_console_put_keysym(QemuTextConsole *s, int keysym) +{ + if (!s) { + if (!QEMU_IS_TEXT_CONSOLE(active_console)) { + return; + } + s = QEMU_TEXT_CONSOLE(active_console); + } + + qemu_text_console_handle_keysym(s, keysym); +} + static const int qcode_to_keysym[Q_KEY_CODE__MAX] = { [Q_KEY_CODE_UP] = QEMU_KEY_UP, [Q_KEY_CODE_DOWN] = QEMU_KEY_DOWN, @@ -XXX,XX +XXX,XX @@ qemu_text_console_class_init(ObjectClass *oc, void *data) { if (!cursor_timer) { cursor_timer = timer_new_ms(QEMU_CLOCK_REALTIME, - text_console_update_cursor, NULL); + qemu_text_console_update_cursor, NULL); } } @@ -XXX,XX +XXX,XX @@ void register_displaychangelistener(DisplayChangeListener *dcl) if (QEMU_IS_GRAPHIC_CONSOLE(con)) { dcl_set_graphic_cursor(dcl, QEMU_GRAPHIC_CONSOLE(con)); } - text_console_update_cursor(NULL); + qemu_text_console_update_cursor(NULL); } void update_displaychangelistener(DisplayChangeListener *dcl, @@ -XXX,XX +XXX,XX @@ bool qemu_console_is_multihead(DeviceState *dev) return false; } + +static const char * +qemu_text_console_get_label(QemuTextConsole *c) +{ + return c->chr ? c->chr->label : NULL; +} + char *qemu_console_get_label(QemuConsole *con) { if (QEMU_IS_GRAPHIC_CONSOLE(con)) { @@ -XXX,XX +XXX,XX @@ char *qemu_console_get_label(QemuConsole *con) } return g_strdup("VGA"); } else if (QEMU_IS_TEXT_CONSOLE(con)) { - QemuTextConsole *c = QEMU_TEXT_CONSOLE(con); - if (c->chr && c->chr->label) { - return g_strdup(c->chr->label); + const char *label = qemu_text_console_get_label(QEMU_TEXT_CONSOLE(con)); + if (label) { + return g_strdup(label); } } @@ -XXX,XX +XXX,XX @@ int qemu_invalidate_text_consoles(void) return count; } -static void text_console_update_cursor(void *opaque) +static void qemu_text_console_update_cursor(void *opaque) { cursor_visible_phase = !cursor_visible_phase; -- 2.41.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> Move common declarations to console-priv.h, and add a new unit console-vc.c which will handle VC/chardev rendering, when pixman is available. (if necessary, the move could be done chunk by chunks) Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> --- ui/console-priv.h | 43 ++ ui/console-vc.c | 1079 ++++++++++++++++++++++++++++++++++++++++++++ ui/console.c | 1096 +-------------------------------------------- ui/meson.build | 1 + 4 files changed, 1126 insertions(+), 1093 deletions(-) create mode 100644 ui/console-priv.h create mode 100644 ui/console-vc.c diff --git a/ui/console-priv.h b/ui/console-priv.h new file mode 100644 index XXXXXXX..XXXXXXX --- /dev/null +++ b/ui/console-priv.h @@ -XXX,XX +XXX,XX @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * QEMU UI Console + */ +#ifndef CONSOLE_PRIV_H +#define CONSOLE_PRIV_H + +#include "ui/console.h" +#include "qemu/coroutine.h" +#include "qemu/timer.h" + +#include "vgafont.h" + +#define FONT_HEIGHT 16 +#define FONT_WIDTH 8 + +struct QemuConsole { + Object parent; + + int index; + DisplayState *ds; + DisplaySurface *surface; + DisplayScanout scanout; + int dcls; + DisplayGLCtx *gl; + int gl_block; + QEMUTimer *gl_unblock_timer; + int window_id; + QemuUIInfo ui_info; + QEMUTimer *ui_timer; + const GraphicHwOps *hw_ops; + void *hw; + CoQueue dump_queue; + + QTAILQ_ENTRY(QemuConsole) next; +}; + +void qemu_text_console_select(QemuTextConsole *c); +const char * qemu_text_console_get_label(QemuTextConsole *c); +void qemu_text_console_update_cursor(void); +void qemu_text_console_handle_keysym(QemuTextConsole *s, int keysym); + +#endif diff --git a/ui/console-vc.c b/ui/console-vc.c new file mode 100644 index XXXXXXX..XXXXXXX --- /dev/null +++ b/ui/console-vc.c @@ -XXX,XX +XXX,XX @@ +/* + * SPDX-License-Identifier: MIT + * QEMU VC + */ +#include "qemu/osdep.h" + +#include "chardev/char.h" +#include "qapi/error.h" +#include "qemu/fifo8.h" +#include "qemu/option.h" +#include "ui/console.h" + +#include "trace.h" +#include "console-priv.h" + +#define DEFAULT_BACKSCROLL 512 +#define CONSOLE_CURSOR_PERIOD 500 + +typedef struct TextAttributes { + uint8_t fgcol:4; + uint8_t bgcol:4; + uint8_t bold:1; + uint8_t uline:1; + uint8_t blink:1; + uint8_t invers:1; + uint8_t unvisible:1; +} TextAttributes; + +#define TEXT_ATTRIBUTES_DEFAULT ((TextAttributes) { \ + .fgcol = QEMU_COLOR_WHITE, \ + .bgcol = QEMU_COLOR_BLACK \ +}) + +typedef struct TextCell { + uint8_t ch; + TextAttributes t_attrib; +} TextCell; + +#define MAX_ESC_PARAMS 3 + +enum TTYState { + TTY_STATE_NORM, + TTY_STATE_ESC, + TTY_STATE_CSI, +}; + +typedef struct QemuTextConsole { + QemuConsole parent; + + int width; + int height; + int total_height; + int backscroll_height; + int x, y; + int y_displayed; + int y_base; + TextCell *cells; + int text_x[2], text_y[2], cursor_invalidate; + int echo; + + int update_x0; + int update_y0; + int update_x1; + int update_y1; + + Chardev *chr; + /* fifo for key pressed */ + Fifo8 out_fifo; +} QemuTextConsole; + +typedef QemuConsoleClass QemuTextConsoleClass; + +OBJECT_DEFINE_TYPE(QemuTextConsole, qemu_text_console, QEMU_TEXT_CONSOLE, QEMU_CONSOLE) + +typedef struct QemuFixedTextConsole { + QemuTextConsole parent; +} QemuFixedTextConsole; + +typedef QemuTextConsoleClass QemuFixedTextConsoleClass; + +OBJECT_DEFINE_TYPE(QemuFixedTextConsole, qemu_fixed_text_console, QEMU_FIXED_TEXT_CONSOLE, QEMU_TEXT_CONSOLE) + +struct VCChardev { + Chardev parent; + QemuTextConsole *console; + + enum TTYState state; + int esc_params[MAX_ESC_PARAMS]; + int nb_esc_params; + TextAttributes t_attrib; /* currently active text attributes */ + int x_saved, y_saved; +}; +typedef struct VCChardev VCChardev; + +static const pixman_color_t color_table_rgb[2][8] = { + { /* dark */ + [QEMU_COLOR_BLACK] = QEMU_PIXMAN_COLOR_BLACK, + [QEMU_COLOR_BLUE] = QEMU_PIXMAN_COLOR(0x00, 0x00, 0xaa), /* blue */ + [QEMU_COLOR_GREEN] = QEMU_PIXMAN_COLOR(0x00, 0xaa, 0x00), /* green */ + [QEMU_COLOR_CYAN] = QEMU_PIXMAN_COLOR(0x00, 0xaa, 0xaa), /* cyan */ + [QEMU_COLOR_RED] = QEMU_PIXMAN_COLOR(0xaa, 0x00, 0x00), /* red */ + [QEMU_COLOR_MAGENTA] = QEMU_PIXMAN_COLOR(0xaa, 0x00, 0xaa), /* magenta */ + [QEMU_COLOR_YELLOW] = QEMU_PIXMAN_COLOR(0xaa, 0xaa, 0x00), /* yellow */ + [QEMU_COLOR_WHITE] = QEMU_PIXMAN_COLOR_GRAY, + }, + { /* bright */ + [QEMU_COLOR_BLACK] = QEMU_PIXMAN_COLOR_BLACK, + [QEMU_COLOR_BLUE] = QEMU_PIXMAN_COLOR(0x00, 0x00, 0xff), /* blue */ + [QEMU_COLOR_GREEN] = QEMU_PIXMAN_COLOR(0x00, 0xff, 0x00), /* green */ + [QEMU_COLOR_CYAN] = QEMU_PIXMAN_COLOR(0x00, 0xff, 0xff), /* cyan */ + [QEMU_COLOR_RED] = QEMU_PIXMAN_COLOR(0xff, 0x00, 0x00), /* red */ + [QEMU_COLOR_MAGENTA] = QEMU_PIXMAN_COLOR(0xff, 0x00, 0xff), /* magenta */ + [QEMU_COLOR_YELLOW] = QEMU_PIXMAN_COLOR(0xff, 0xff, 0x00), /* yellow */ + [QEMU_COLOR_WHITE] = QEMU_PIXMAN_COLOR(0xff, 0xff, 0xff), /* white */ + } +}; + +static bool cursor_visible_phase; +static QEMUTimer *cursor_timer; + +const char * +qemu_text_console_get_label(QemuTextConsole *c) +{ + return c->chr ? c->chr->label : NULL; +} + +static void qemu_console_fill_rect(QemuConsole *con, int posx, int posy, + int width, int height, pixman_color_t color) +{ + DisplaySurface *surface = qemu_console_surface(con); + pixman_rectangle16_t rect = { + .x = posx, .y = posy, .width = width, .height = height + }; + + assert(surface); + pixman_image_fill_rectangles(PIXMAN_OP_SRC, surface->image, + &color, 1, &rect); +} + +/* copy from (xs, ys) to (xd, yd) a rectangle of size (w, h) */ +static void qemu_console_bitblt(QemuConsole *con, + int xs, int ys, int xd, int yd, int w, int h) +{ + DisplaySurface *surface = qemu_console_surface(con); + + assert(surface); + pixman_image_composite(PIXMAN_OP_SRC, + surface->image, NULL, surface->image, + xs, ys, 0, 0, xd, yd, w, h); +} + +static void vga_putcharxy(QemuConsole *s, int x, int y, int ch, + TextAttributes *t_attrib) +{ + static pixman_image_t *glyphs[256]; + DisplaySurface *surface = qemu_console_surface(s); + pixman_color_t fgcol, bgcol; + + assert(surface); + if (t_attrib->invers) { + bgcol = color_table_rgb[t_attrib->bold][t_attrib->fgcol]; + fgcol = color_table_rgb[t_attrib->bold][t_attrib->bgcol]; + } else { + fgcol = color_table_rgb[t_attrib->bold][t_attrib->fgcol]; + bgcol = color_table_rgb[t_attrib->bold][t_attrib->bgcol]; + } + + if (!glyphs[ch]) { + glyphs[ch] = qemu_pixman_glyph_from_vgafont(FONT_HEIGHT, vgafont16, ch); + } + qemu_pixman_glyph_render(glyphs[ch], surface->image, + &fgcol, &bgcol, x, y, FONT_WIDTH, FONT_HEIGHT); +} + +static void invalidate_xy(QemuTextConsole *s, int x, int y) +{ + if (!qemu_console_is_visible(QEMU_CONSOLE(s))) { + return; + } + if (s->update_x0 > x * FONT_WIDTH) + s->update_x0 = x * FONT_WIDTH; + if (s->update_y0 > y * FONT_HEIGHT) + s->update_y0 = y * FONT_HEIGHT; + if (s->update_x1 < (x + 1) * FONT_WIDTH) + s->update_x1 = (x + 1) * FONT_WIDTH; + if (s->update_y1 < (y + 1) * FONT_HEIGHT) + s->update_y1 = (y + 1) * FONT_HEIGHT; +} + +static void console_show_cursor(QemuTextConsole *s, int show) +{ + TextCell *c; + int y, y1; + int x = s->x; + + s->cursor_invalidate = 1; + + if (x >= s->width) { + x = s->width - 1; + } + y1 = (s->y_base + s->y) % s->total_height; + y = y1 - s->y_displayed; + if (y < 0) { + y += s->total_height; + } + if (y < s->height) { + c = &s->cells[y1 * s->width + x]; + if (show && cursor_visible_phase) { + TextAttributes t_attrib = TEXT_ATTRIBUTES_DEFAULT; + t_attrib.invers = !(t_attrib.invers); /* invert fg and bg */ + vga_putcharxy(QEMU_CONSOLE(s), x, y, c->ch, &t_attrib); + } else { + vga_putcharxy(QEMU_CONSOLE(s), x, y, c->ch, &(c->t_attrib)); + } + invalidate_xy(s, x, y); + } +} + +static void console_refresh(QemuTextConsole *s) +{ + DisplaySurface *surface = qemu_console_surface(QEMU_CONSOLE(s)); + TextCell *c; + int x, y, y1; + + assert(surface); + s->text_x[0] = 0; + s->text_y[0] = 0; + s->text_x[1] = s->width - 1; + s->text_y[1] = s->height - 1; + s->cursor_invalidate = 1; + + qemu_console_fill_rect(QEMU_CONSOLE(s), 0, 0, surface_width(surface), surface_height(surface), + color_table_rgb[0][QEMU_COLOR_BLACK]); + y1 = s->y_displayed; + for (y = 0; y < s->height; y++) { + c = s->cells + y1 * s->width; + for (x = 0; x < s->width; x++) { + vga_putcharxy(QEMU_CONSOLE(s), x, y, c->ch, + &(c->t_attrib)); + c++; + } + if (++y1 == s->total_height) { + y1 = 0; + } + } + console_show_cursor(s, 1); + dpy_gfx_update(QEMU_CONSOLE(s), 0, 0, + surface_width(surface), surface_height(surface)); +} + +static void console_scroll(QemuTextConsole *s, int ydelta) +{ + int i, y1; + + if (ydelta > 0) { + for(i = 0; i < ydelta; i++) { + if (s->y_displayed == s->y_base) + break; + if (++s->y_displayed == s->total_height) + s->y_displayed = 0; + } + } else { + ydelta = -ydelta; + i = s->backscroll_height; + if (i > s->total_height - s->height) + i = s->total_height - s->height; + y1 = s->y_base - i; + if (y1 < 0) + y1 += s->total_height; + for(i = 0; i < ydelta; i++) { + if (s->y_displayed == y1) + break; + if (--s->y_displayed < 0) + s->y_displayed = s->total_height - 1; + } + } + console_refresh(s); +} + +static void kbd_send_chars(QemuTextConsole *s) +{ + uint32_t len, avail; + + len = qemu_chr_be_can_write(s->chr); + avail = fifo8_num_used(&s->out_fifo); + while (len > 0 && avail > 0) { + const uint8_t *buf; + uint32_t size; + + buf = fifo8_pop_buf(&s->out_fifo, MIN(len, avail), &size); + qemu_chr_be_write(s->chr, buf, size); + len = qemu_chr_be_can_write(s->chr); + avail -= size; + } +} + +/* called when an ascii key is pressed */ +void qemu_text_console_handle_keysym(QemuTextConsole *s, int keysym) +{ + uint8_t buf[16], *q; + int c; + uint32_t num_free; + + switch(keysym) { + case QEMU_KEY_CTRL_UP: + console_scroll(s, -1); + break; + case QEMU_KEY_CTRL_DOWN: + console_scroll(s, 1); + break; + case QEMU_KEY_CTRL_PAGEUP: + console_scroll(s, -10); + break; + case QEMU_KEY_CTRL_PAGEDOWN: + console_scroll(s, 10); + break; + default: + /* convert the QEMU keysym to VT100 key string */ + q = buf; + if (keysym >= 0xe100 && keysym <= 0xe11f) { + *q++ = '\033'; + *q++ = '['; + c = keysym - 0xe100; + if (c >= 10) + *q++ = '0' + (c / 10); + *q++ = '0' + (c % 10); + *q++ = '~'; + } else if (keysym >= 0xe120 && keysym <= 0xe17f) { + *q++ = '\033'; + *q++ = '['; + *q++ = keysym & 0xff; + } else if (s->echo && (keysym == '\r' || keysym == '\n')) { + qemu_chr_write(s->chr, (uint8_t *)"\r", 1, true); + *q++ = '\n'; + } else { + *q++ = keysym; + } + if (s->echo) { + qemu_chr_write(s->chr, buf, q - buf, true); + } + num_free = fifo8_num_free(&s->out_fifo); + fifo8_push_all(&s->out_fifo, buf, MIN(num_free, q - buf)); + kbd_send_chars(s); + break; + } +} + +static void text_console_update(void *opaque, console_ch_t *chardata) +{ + QemuTextConsole *s = QEMU_TEXT_CONSOLE(opaque); + int i, j, src; + + if (s->text_x[0] <= s->text_x[1]) { + src = (s->y_base + s->text_y[0]) * s->width; + chardata += s->text_y[0] * s->width; + for (i = s->text_y[0]; i <= s->text_y[1]; i ++) + for (j = 0; j < s->width; j++, src++) { + console_write_ch(chardata ++, + ATTR2CHTYPE(s->cells[src].ch, + s->cells[src].t_attrib.fgcol, + s->cells[src].t_attrib.bgcol, + s->cells[src].t_attrib.bold)); + } + dpy_text_update(QEMU_CONSOLE(s), s->text_x[0], s->text_y[0], + s->text_x[1] - s->text_x[0], i - s->text_y[0]); + s->text_x[0] = s->width; + s->text_y[0] = s->height; + s->text_x[1] = 0; + s->text_y[1] = 0; + } + if (s->cursor_invalidate) { + dpy_text_cursor(QEMU_CONSOLE(s), s->x, s->y); + s->cursor_invalidate = 0; + } +} + +static void text_console_resize(QemuTextConsole *t) +{ + QemuConsole *s = QEMU_CONSOLE(t); + TextCell *cells, *c, *c1; + int w1, x, y, last_width, w, h; + + assert(s->scanout.kind == SCANOUT_SURFACE); + + w = surface_width(s->surface) / FONT_WIDTH; + h = surface_height(s->surface) / FONT_HEIGHT; + if (w == t->width && h == t->height) { + return; + } + + last_width = t->width; + t->width = w; + t->height = h; + + w1 = MIN(t->width, last_width); + + cells = g_new(TextCell, t->width * t->total_height + 1); + for (y = 0; y < t->total_height; y++) { + c = &cells[y * t->width]; + if (w1 > 0) { + c1 = &t->cells[y * last_width]; + for (x = 0; x < w1; x++) { + *c++ = *c1++; + } + } + for (x = w1; x < t->width; x++) { + c->ch = ' '; + c->t_attrib = TEXT_ATTRIBUTES_DEFAULT; + c++; + } + } + g_free(t->cells); + t->cells = cells; +} + +static void vc_put_lf(VCChardev *vc) +{ + QemuTextConsole *s = vc->console; + TextCell *c; + int x, y1; + + s->y++; + if (s->y >= s->height) { + s->y = s->height - 1; + + if (s->y_displayed == s->y_base) { + if (++s->y_displayed == s->total_height) + s->y_displayed = 0; + } + if (++s->y_base == s->total_height) + s->y_base = 0; + if (s->backscroll_height < s->total_height) + s->backscroll_height++; + y1 = (s->y_base + s->height - 1) % s->total_height; + c = &s->cells[y1 * s->width]; + for(x = 0; x < s->width; x++) { + c->ch = ' '; + c->t_attrib = TEXT_ATTRIBUTES_DEFAULT; + c++; + } + if (s->y_displayed == s->y_base) { + s->text_x[0] = 0; + s->text_y[0] = 0; + s->text_x[1] = s->width - 1; + s->text_y[1] = s->height - 1; + + qemu_console_bitblt(QEMU_CONSOLE(s), 0, FONT_HEIGHT, 0, 0, + s->width * FONT_WIDTH, + (s->height - 1) * FONT_HEIGHT); + qemu_console_fill_rect(QEMU_CONSOLE(s), 0, (s->height - 1) * FONT_HEIGHT, + s->width * FONT_WIDTH, FONT_HEIGHT, + color_table_rgb[0][TEXT_ATTRIBUTES_DEFAULT.bgcol]); + s->update_x0 = 0; + s->update_y0 = 0; + s->update_x1 = s->width * FONT_WIDTH; + s->update_y1 = s->height * FONT_HEIGHT; + } + } +} + +/* Set console attributes depending on the current escape codes. + * NOTE: I know this code is not very efficient (checking every color for it + * self) but it is more readable and better maintainable. + */ +static void vc_handle_escape(VCChardev *vc) +{ + int i; + + for (i = 0; i < vc->nb_esc_params; i++) { + switch (vc->esc_params[i]) { + case 0: /* reset all console attributes to default */ + vc->t_attrib = TEXT_ATTRIBUTES_DEFAULT; + break; + case 1: + vc->t_attrib.bold = 1; + break; + case 4: + vc->t_attrib.uline = 1; + break; + case 5: + vc->t_attrib.blink = 1; + break; + case 7: + vc->t_attrib.invers = 1; + break; + case 8: + vc->t_attrib.unvisible = 1; + break; + case 22: + vc->t_attrib.bold = 0; + break; + case 24: + vc->t_attrib.uline = 0; + break; + case 25: + vc->t_attrib.blink = 0; + break; + case 27: + vc->t_attrib.invers = 0; + break; + case 28: + vc->t_attrib.unvisible = 0; + break; + /* set foreground color */ + case 30: + vc->t_attrib.fgcol = QEMU_COLOR_BLACK; + break; + case 31: + vc->t_attrib.fgcol = QEMU_COLOR_RED; + break; + case 32: + vc->t_attrib.fgcol = QEMU_COLOR_GREEN; + break; + case 33: + vc->t_attrib.fgcol = QEMU_COLOR_YELLOW; + break; + case 34: + vc->t_attrib.fgcol = QEMU_COLOR_BLUE; + break; + case 35: + vc->t_attrib.fgcol = QEMU_COLOR_MAGENTA; + break; + case 36: + vc->t_attrib.fgcol = QEMU_COLOR_CYAN; + break; + case 37: + vc->t_attrib.fgcol = QEMU_COLOR_WHITE; + break; + /* set background color */ + case 40: + vc->t_attrib.bgcol = QEMU_COLOR_BLACK; + break; + case 41: + vc->t_attrib.bgcol = QEMU_COLOR_RED; + break; + case 42: + vc->t_attrib.bgcol = QEMU_COLOR_GREEN; + break; + case 43: + vc->t_attrib.bgcol = QEMU_COLOR_YELLOW; + break; + case 44: + vc->t_attrib.bgcol = QEMU_COLOR_BLUE; + break; + case 45: + vc->t_attrib.bgcol = QEMU_COLOR_MAGENTA; + break; + case 46: + vc->t_attrib.bgcol = QEMU_COLOR_CYAN; + break; + case 47: + vc->t_attrib.bgcol = QEMU_COLOR_WHITE; + break; + } + } +} + +static void vc_update_xy(VCChardev *vc, int x, int y) +{ + QemuTextConsole *s = vc->console; + TextCell *c; + int y1, y2; + + s->text_x[0] = MIN(s->text_x[0], x); + s->text_x[1] = MAX(s->text_x[1], x); + s->text_y[0] = MIN(s->text_y[0], y); + s->text_y[1] = MAX(s->text_y[1], y); + + y1 = (s->y_base + y) % s->total_height; + y2 = y1 - s->y_displayed; + if (y2 < 0) { + y2 += s->total_height; + } + if (y2 < s->height) { + if (x >= s->width) { + x = s->width - 1; + } + c = &s->cells[y1 * s->width + x]; + vga_putcharxy(QEMU_CONSOLE(s), x, y2, c->ch, + &(c->t_attrib)); + invalidate_xy(s, x, y2); + } +} + +static void vc_clear_xy(VCChardev *vc, int x, int y) +{ + QemuTextConsole *s = vc->console; + int y1 = (s->y_base + y) % s->total_height; + if (x >= s->width) { + x = s->width - 1; + } + TextCell *c = &s->cells[y1 * s->width + x]; + c->ch = ' '; + c->t_attrib = TEXT_ATTRIBUTES_DEFAULT; + vc_update_xy(vc, x, y); +} + +static void vc_put_one(VCChardev *vc, int ch) +{ + QemuTextConsole *s = vc->console; + TextCell *c; + int y1; + if (s->x >= s->width) { + /* line wrap */ + s->x = 0; + vc_put_lf(vc); + } + y1 = (s->y_base + s->y) % s->total_height; + c = &s->cells[y1 * s->width + s->x]; + c->ch = ch; + c->t_attrib = vc->t_attrib; + vc_update_xy(vc, s->x, s->y); + s->x++; +} + +static void vc_respond_str(VCChardev *vc, const char *buf) +{ + while (*buf) { + vc_put_one(vc, *buf); + buf++; + } +} + +/* set cursor, checking bounds */ +static void vc_set_cursor(VCChardev *vc, int x, int y) +{ + QemuTextConsole *s = vc->console; + + if (x < 0) { + x = 0; + } + if (y < 0) { + y = 0; + } + if (y >= s->height) { + y = s->height - 1; + } + if (x >= s->width) { + x = s->width - 1; + } + + s->x = x; + s->y = y; +} + +static void vc_putchar(VCChardev *vc, int ch) +{ + QemuTextConsole *s = vc->console; + int i; + int x, y; + char response[40]; + + switch(vc->state) { + case TTY_STATE_NORM: + switch(ch) { + case '\r': /* carriage return */ + s->x = 0; + break; + case '\n': /* newline */ + vc_put_lf(vc); + break; + case '\b': /* backspace */ + if (s->x > 0) + s->x--; + break; + case '\t': /* tabspace */ + if (s->x + (8 - (s->x % 8)) > s->width) { + s->x = 0; + vc_put_lf(vc); + } else { + s->x = s->x + (8 - (s->x % 8)); + } + break; + case '\a': /* alert aka. bell */ + /* TODO: has to be implemented */ + break; + case 14: + /* SI (shift in), character set 0 (ignored) */ + break; + case 15: + /* SO (shift out), character set 1 (ignored) */ + break; + case 27: /* esc (introducing an escape sequence) */ + vc->state = TTY_STATE_ESC; + break; + default: + vc_put_one(vc, ch); + break; + } + break; + case TTY_STATE_ESC: /* check if it is a terminal escape sequence */ + if (ch == '[') { + for(i=0;i<MAX_ESC_PARAMS;i++) + vc->esc_params[i] = 0; + vc->nb_esc_params = 0; + vc->state = TTY_STATE_CSI; + } else { + vc->state = TTY_STATE_NORM; + } + break; + case TTY_STATE_CSI: /* handle escape sequence parameters */ + if (ch >= '0' && ch <= '9') { + if (vc->nb_esc_params < MAX_ESC_PARAMS) { + int *param = &vc->esc_params[vc->nb_esc_params]; + int digit = (ch - '0'); + + *param = (*param <= (INT_MAX - digit) / 10) ? + *param * 10 + digit : INT_MAX; + } + } else { + if (vc->nb_esc_params < MAX_ESC_PARAMS) + vc->nb_esc_params++; + if (ch == ';' || ch == '?') { + break; + } + trace_console_putchar_csi(vc->esc_params[0], vc->esc_params[1], + ch, vc->nb_esc_params); + vc->state = TTY_STATE_NORM; + switch(ch) { + case 'A': + /* move cursor up */ + if (vc->esc_params[0] == 0) { + vc->esc_params[0] = 1; + } + vc_set_cursor(vc, s->x, s->y - vc->esc_params[0]); + break; + case 'B': + /* move cursor down */ + if (vc->esc_params[0] == 0) { + vc->esc_params[0] = 1; + } + vc_set_cursor(vc, s->x, s->y + vc->esc_params[0]); + break; + case 'C': + /* move cursor right */ + if (vc->esc_params[0] == 0) { + vc->esc_params[0] = 1; + } + vc_set_cursor(vc, s->x + vc->esc_params[0], s->y); + break; + case 'D': + /* move cursor left */ + if (vc->esc_params[0] == 0) { + vc->esc_params[0] = 1; + } + vc_set_cursor(vc, s->x - vc->esc_params[0], s->y); + break; + case 'G': + /* move cursor to column */ + vc_set_cursor(vc, vc->esc_params[0] - 1, s->y); + break; + case 'f': + case 'H': + /* move cursor to row, column */ + vc_set_cursor(vc, vc->esc_params[1] - 1, vc->esc_params[0] - 1); + break; + case 'J': + switch (vc->esc_params[0]) { + case 0: + /* clear to end of screen */ + for (y = s->y; y < s->height; y++) { + for (x = 0; x < s->width; x++) { + if (y == s->y && x < s->x) { + continue; + } + vc_clear_xy(vc, x, y); + } + } + break; + case 1: + /* clear from beginning of screen */ + for (y = 0; y <= s->y; y++) { + for (x = 0; x < s->width; x++) { + if (y == s->y && x > s->x) { + break; + } + vc_clear_xy(vc, x, y); + } + } + break; + case 2: + /* clear entire screen */ + for (y = 0; y <= s->height; y++) { + for (x = 0; x < s->width; x++) { + vc_clear_xy(vc, x, y); + } + } + break; + } + break; + case 'K': + switch (vc->esc_params[0]) { + case 0: + /* clear to eol */ + for(x = s->x; x < s->width; x++) { + vc_clear_xy(vc, x, s->y); + } + break; + case 1: + /* clear from beginning of line */ + for (x = 0; x <= s->x && x < s->width; x++) { + vc_clear_xy(vc, x, s->y); + } + break; + case 2: + /* clear entire line */ + for(x = 0; x < s->width; x++) { + vc_clear_xy(vc, x, s->y); + } + break; + } + break; + case 'm': + vc_handle_escape(vc); + break; + case 'n': + switch (vc->esc_params[0]) { + case 5: + /* report console status (always succeed)*/ + vc_respond_str(vc, "\033[0n"); + break; + case 6: + /* report cursor position */ + sprintf(response, "\033[%d;%dR", + (s->y_base + s->y) % s->total_height + 1, + s->x + 1); + vc_respond_str(vc, response); + break; + } + break; + case 's': + /* save cursor position */ + vc->x_saved = s->x; + vc->y_saved = s->y; + break; + case 'u': + /* restore cursor position */ + s->x = vc->x_saved; + s->y = vc->y_saved; + break; + default: + trace_console_putchar_unhandled(ch); + break; + } + break; + } + } +} + +#define TYPE_CHARDEV_VC "chardev-vc" +DECLARE_INSTANCE_CHECKER(VCChardev, VC_CHARDEV, + TYPE_CHARDEV_VC) + +static int vc_chr_write(Chardev *chr, const uint8_t *buf, int len) +{ + VCChardev *drv = VC_CHARDEV(chr); + QemuTextConsole *s = drv->console; + int i; + + s->update_x0 = s->width * FONT_WIDTH; + s->update_y0 = s->height * FONT_HEIGHT; + s->update_x1 = 0; + s->update_y1 = 0; + console_show_cursor(s, 0); + for(i = 0; i < len; i++) { + vc_putchar(drv, buf[i]); + } + console_show_cursor(s, 1); + if (s->update_x0 < s->update_x1) { + dpy_gfx_update(QEMU_CONSOLE(s), s->update_x0, s->update_y0, + s->update_x1 - s->update_x0, + s->update_y1 - s->update_y0); + } + return len; +} + +void qemu_text_console_update_cursor(void) +{ + cursor_visible_phase = !cursor_visible_phase; + + if (qemu_invalidate_text_consoles()) { + timer_mod(cursor_timer, + qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + CONSOLE_CURSOR_PERIOD / 2); + } +} + +static void +cursor_timer_cb(void *opaque) +{ + qemu_text_console_update_cursor(); +} + +static void text_console_invalidate(void *opaque) +{ + QemuTextConsole *s = QEMU_TEXT_CONSOLE(opaque); + + if (!QEMU_IS_FIXED_TEXT_CONSOLE(s)) { + text_console_resize(QEMU_TEXT_CONSOLE(s)); + } + console_refresh(s); +} + +static void +qemu_text_console_finalize(Object *obj) +{ +} + +static void +qemu_text_console_class_init(ObjectClass *oc, void *data) +{ + if (!cursor_timer) { + cursor_timer = timer_new_ms(QEMU_CLOCK_REALTIME, cursor_timer_cb, NULL); + } +} + +static const GraphicHwOps text_console_ops = { + .invalidate = text_console_invalidate, + .text_update = text_console_update, +}; + +static void +qemu_text_console_init(Object *obj) +{ + QemuTextConsole *c = QEMU_TEXT_CONSOLE(obj); + + fifo8_create(&c->out_fifo, 16); + c->total_height = DEFAULT_BACKSCROLL; + QEMU_CONSOLE(c)->hw_ops = &text_console_ops; + QEMU_CONSOLE(c)->hw = c; +} + +static void +qemu_fixed_text_console_finalize(Object *obj) +{ +} + +static void +qemu_fixed_text_console_class_init(ObjectClass *oc, void *data) +{ +} + +static void +qemu_fixed_text_console_init(Object *obj) +{ +} + +static void vc_chr_accept_input(Chardev *chr) +{ + VCChardev *drv = VC_CHARDEV(chr); + + kbd_send_chars(drv->console); +} + +static void vc_chr_set_echo(Chardev *chr, bool echo) +{ + VCChardev *drv = VC_CHARDEV(chr); + + drv->console->echo = echo; +} + +void qemu_text_console_select(QemuTextConsole *c) +{ + dpy_text_resize(QEMU_CONSOLE(c), c->width, c->height); + qemu_text_console_update_cursor(); +} + +static void vc_chr_open(Chardev *chr, + ChardevBackend *backend, + bool *be_opened, + Error **errp) +{ + ChardevVC *vc = backend->u.vc.data; + VCChardev *drv = VC_CHARDEV(chr); + QemuTextConsole *s; + unsigned width = 0; + unsigned height = 0; + + if (vc->has_width) { + width = vc->width; + } else if (vc->has_cols) { + width = vc->cols * FONT_WIDTH; + } + + if (vc->has_height) { + height = vc->height; + } else if (vc->has_rows) { + height = vc->rows * FONT_HEIGHT; + } + + trace_console_txt_new(width, height); + if (width == 0 || height == 0) { + s = QEMU_TEXT_CONSOLE(object_new(TYPE_QEMU_TEXT_CONSOLE)); + width = qemu_console_get_width(NULL, 80 * FONT_WIDTH); + height = qemu_console_get_height(NULL, 24 * FONT_HEIGHT); + } else { + s = QEMU_TEXT_CONSOLE(object_new(TYPE_QEMU_FIXED_TEXT_CONSOLE)); + } + + dpy_gfx_replace_surface(QEMU_CONSOLE(s), qemu_create_displaysurface(width, height)); + + s->chr = chr; + drv->console = s; + + /* set current text attributes to default */ + drv->t_attrib = TEXT_ATTRIBUTES_DEFAULT; + text_console_resize(s); + + if (chr->label) { + char *msg; + + drv->t_attrib.bgcol = QEMU_COLOR_BLUE; + msg = g_strdup_printf("%s console\r\n", chr->label); + qemu_chr_write(chr, (uint8_t *)msg, strlen(msg), true); + g_free(msg); + drv->t_attrib = TEXT_ATTRIBUTES_DEFAULT; + } + + *be_opened = true; +} + +static void vc_chr_parse(QemuOpts *opts, ChardevBackend *backend, Error **errp) +{ + int val; + ChardevVC *vc; + + backend->type = CHARDEV_BACKEND_KIND_VC; + vc = backend->u.vc.data = g_new0(ChardevVC, 1); + qemu_chr_parse_common(opts, qapi_ChardevVC_base(vc)); + + val = qemu_opt_get_number(opts, "width", 0); + if (val != 0) { + vc->has_width = true; + vc->width = val; + } + + val = qemu_opt_get_number(opts, "height", 0); + if (val != 0) { + vc->has_height = true; + vc->height = val; + } + + val = qemu_opt_get_number(opts, "cols", 0); + if (val != 0) { + vc->has_cols = true; + vc->cols = val; + } + + val = qemu_opt_get_number(opts, "rows", 0); + if (val != 0) { + vc->has_rows = true; + vc->rows = val; + } +} + +static void char_vc_class_init(ObjectClass *oc, void *data) +{ + ChardevClass *cc = CHARDEV_CLASS(oc); + + cc->parse = vc_chr_parse; + cc->open = vc_chr_open; + cc->chr_write = vc_chr_write; + cc->chr_accept_input = vc_chr_accept_input; + cc->chr_set_echo = vc_chr_set_echo; +} + +static const TypeInfo char_vc_type_info = { + .name = TYPE_CHARDEV_VC, + .parent = TYPE_CHARDEV, + .instance_size = sizeof(VCChardev), + .class_init = char_vc_class_init, +}; + +void qemu_console_early_init(void) +{ + /* set the default vc driver */ + if (!object_class_by_name(TYPE_CHARDEV_VC)) { + type_register(&char_vc_type_info); + } +} diff --git a/ui/console.c b/ui/console.c index XXXXXXX..XXXXXXX 100644 --- a/ui/console.c +++ b/ui/console.c @@ -XXX,XX +XXX,XX @@ #include "qapi/qapi-commands-ui.h" #include "qapi/visitor.h" #include "qemu/coroutine.h" -#include "qemu/fifo8.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" #include "qemu/module.h" #include "qemu/option.h" -#include "qemu/timer.h" #include "chardev/char.h" #include "trace.h" #include "exec/memory.h" #include "qom/object.h" -#define DEFAULT_BACKSCROLL 512 -#define CONSOLE_CURSOR_PERIOD 500 - -typedef struct TextAttributes { - uint8_t fgcol:4; - uint8_t bgcol:4; - uint8_t bold:1; - uint8_t uline:1; - uint8_t blink:1; - uint8_t invers:1; - uint8_t unvisible:1; -} TextAttributes; - -#define TEXT_ATTRIBUTES_DEFAULT ((TextAttributes) { \ - .fgcol = QEMU_COLOR_WHITE, \ - .bgcol = QEMU_COLOR_BLACK \ -}) - -typedef struct TextCell { - uint8_t ch; - TextAttributes t_attrib; -} TextCell; - -#define MAX_ESC_PARAMS 3 - -enum TTYState { - TTY_STATE_NORM, - TTY_STATE_ESC, - TTY_STATE_CSI, -}; - -struct QemuConsole { - Object parent; - - int index; - DisplayState *ds; - DisplaySurface *surface; - DisplayScanout scanout; - int dcls; - DisplayGLCtx *gl; - int gl_block; - QEMUTimer *gl_unblock_timer; - int window_id; - QemuUIInfo ui_info; - QEMUTimer *ui_timer; - const GraphicHwOps *hw_ops; - void *hw; - CoQueue dump_queue; - - QTAILQ_ENTRY(QemuConsole) next; -}; +#include "console-priv.h" OBJECT_DEFINE_ABSTRACT_TYPE(QemuConsole, qemu_console, QEMU_CONSOLE, OBJECT) @@ -XXX,XX +XXX,XX @@ typedef QemuConsoleClass QemuGraphicConsoleClass; OBJECT_DEFINE_TYPE(QemuGraphicConsole, qemu_graphic_console, QEMU_GRAPHIC_CONSOLE, QEMU_CONSOLE) -typedef struct QemuTextConsole { - QemuConsole parent; - - int width; - int height; - int total_height; - int backscroll_height; - int x, y; - int y_displayed; - int y_base; - TextCell *cells; - int text_x[2], text_y[2], cursor_invalidate; - int echo; - - int update_x0; - int update_y0; - int update_x1; - int update_y1; - - Chardev *chr; - /* fifo for key pressed */ - Fifo8 out_fifo; -} QemuTextConsole; - -typedef QemuConsoleClass QemuTextConsoleClass; - -OBJECT_DEFINE_TYPE(QemuTextConsole, qemu_text_console, QEMU_TEXT_CONSOLE, QEMU_CONSOLE) - -typedef struct QemuFixedTextConsole { - QemuTextConsole parent; -} QemuFixedTextConsole; - -typedef QemuTextConsoleClass QemuFixedTextConsoleClass; - -OBJECT_DEFINE_TYPE(QemuFixedTextConsole, qemu_fixed_text_console, QEMU_FIXED_TEXT_CONSOLE, QEMU_TEXT_CONSOLE) - -struct VCChardev { - Chardev parent; - QemuTextConsole *console; - - enum TTYState state; - int esc_params[MAX_ESC_PARAMS]; - int nb_esc_params; - TextAttributes t_attrib; /* currently active text attributes */ - int x_saved, y_saved; -}; -typedef struct VCChardev VCChardev; - struct DisplayState { QEMUTimer *gui_timer; uint64_t last_update; @@ -XXX,XX +XXX,XX @@ static DisplayState *display_state; static QemuConsole *active_console; static QTAILQ_HEAD(, QemuConsole) consoles = QTAILQ_HEAD_INITIALIZER(consoles); -static bool cursor_visible_phase; -static QEMUTimer *cursor_timer; static void dpy_refresh(DisplayState *s); static DisplayState *get_alloc_displaystate(void); -static void qemu_text_console_update_cursor(void *opaque); static bool displaychangelistener_has_dmabuf(DisplayChangeListener *dcl); static bool console_compatible_with(QemuConsole *con, DisplayChangeListener *dcl, Error **errp); @@ -XXX,XX +XXX,XX @@ void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata) } } -static void qemu_console_fill_rect(QemuConsole *con, int posx, int posy, - int width, int height, pixman_color_t color) -{ - DisplaySurface *surface = qemu_console_surface(con); - pixman_rectangle16_t rect = { - .x = posx, .y = posy, .width = width, .height = height - }; - - assert(surface); - pixman_image_fill_rectangles(PIXMAN_OP_SRC, surface->image, - &color, 1, &rect); -} - -/* copy from (xs, ys) to (xd, yd) a rectangle of size (w, h) */ -static void qemu_console_bitblt(QemuConsole *con, - int xs, int ys, int xd, int yd, int w, int h) -{ - DisplaySurface *surface = qemu_console_surface(con); - - assert(surface); - pixman_image_composite(PIXMAN_OP_SRC, - surface->image, NULL, surface->image, - xs, ys, 0, 0, xd, yd, w, h); -} - -/***********************************************************/ -/* basic char display */ - -#define FONT_HEIGHT 16 -#define FONT_WIDTH 8 - -#include "vgafont.h" - -static const pixman_color_t color_table_rgb[2][8] = { - { /* dark */ - [QEMU_COLOR_BLACK] = QEMU_PIXMAN_COLOR_BLACK, - [QEMU_COLOR_BLUE] = QEMU_PIXMAN_COLOR(0x00, 0x00, 0xaa), /* blue */ - [QEMU_COLOR_GREEN] = QEMU_PIXMAN_COLOR(0x00, 0xaa, 0x00), /* green */ - [QEMU_COLOR_CYAN] = QEMU_PIXMAN_COLOR(0x00, 0xaa, 0xaa), /* cyan */ - [QEMU_COLOR_RED] = QEMU_PIXMAN_COLOR(0xaa, 0x00, 0x00), /* red */ - [QEMU_COLOR_MAGENTA] = QEMU_PIXMAN_COLOR(0xaa, 0x00, 0xaa), /* magenta */ - [QEMU_COLOR_YELLOW] = QEMU_PIXMAN_COLOR(0xaa, 0xaa, 0x00), /* yellow */ - [QEMU_COLOR_WHITE] = QEMU_PIXMAN_COLOR_GRAY, - }, - { /* bright */ - [QEMU_COLOR_BLACK] = QEMU_PIXMAN_COLOR_BLACK, - [QEMU_COLOR_BLUE] = QEMU_PIXMAN_COLOR(0x00, 0x00, 0xff), /* blue */ - [QEMU_COLOR_GREEN] = QEMU_PIXMAN_COLOR(0x00, 0xff, 0x00), /* green */ - [QEMU_COLOR_CYAN] = QEMU_PIXMAN_COLOR(0x00, 0xff, 0xff), /* cyan */ - [QEMU_COLOR_RED] = QEMU_PIXMAN_COLOR(0xff, 0x00, 0x00), /* red */ - [QEMU_COLOR_MAGENTA] = QEMU_PIXMAN_COLOR(0xff, 0x00, 0xff), /* magenta */ - [QEMU_COLOR_YELLOW] = QEMU_PIXMAN_COLOR(0xff, 0xff, 0x00), /* yellow */ - [QEMU_COLOR_WHITE] = QEMU_PIXMAN_COLOR(0xff, 0xff, 0xff), /* white */ - } -}; - -static void vga_putcharxy(QemuConsole *s, int x, int y, int ch, - TextAttributes *t_attrib) -{ - static pixman_image_t *glyphs[256]; - DisplaySurface *surface = qemu_console_surface(s); - pixman_color_t fgcol, bgcol; - - assert(surface); - if (t_attrib->invers) { - bgcol = color_table_rgb[t_attrib->bold][t_attrib->fgcol]; - fgcol = color_table_rgb[t_attrib->bold][t_attrib->bgcol]; - } else { - fgcol = color_table_rgb[t_attrib->bold][t_attrib->fgcol]; - bgcol = color_table_rgb[t_attrib->bold][t_attrib->bgcol]; - } - - if (!glyphs[ch]) { - glyphs[ch] = qemu_pixman_glyph_from_vgafont(FONT_HEIGHT, vgafont16, ch); - } - qemu_pixman_glyph_render(glyphs[ch], surface->image, - &fgcol, &bgcol, x, y, FONT_WIDTH, FONT_HEIGHT); -} - -static void text_console_resize(QemuTextConsole *t) -{ - QemuConsole *s = QEMU_CONSOLE(t); - TextCell *cells, *c, *c1; - int w1, x, y, last_width, w, h; - - assert(s->scanout.kind == SCANOUT_SURFACE); - - w = surface_width(s->surface) / FONT_WIDTH; - h = surface_height(s->surface) / FONT_HEIGHT; - if (w == t->width && h == t->height) { - return; - } - - last_width = t->width; - t->width = w; - t->height = h; - - w1 = MIN(t->width, last_width); - - cells = g_new(TextCell, t->width * t->total_height + 1); - for (y = 0; y < t->total_height; y++) { - c = &cells[y * t->width]; - if (w1 > 0) { - c1 = &t->cells[y * last_width]; - for (x = 0; x < w1; x++) { - *c++ = *c1++; - } - } - for (x = w1; x < t->width; x++) { - c->ch = ' '; - c->t_attrib = TEXT_ATTRIBUTES_DEFAULT; - c++; - } - } - g_free(t->cells); - t->cells = cells; -} - -static void invalidate_xy(QemuTextConsole *s, int x, int y) -{ - if (!qemu_console_is_visible(QEMU_CONSOLE(s))) { - return; - } - if (s->update_x0 > x * FONT_WIDTH) - s->update_x0 = x * FONT_WIDTH; - if (s->update_y0 > y * FONT_HEIGHT) - s->update_y0 = y * FONT_HEIGHT; - if (s->update_x1 < (x + 1) * FONT_WIDTH) - s->update_x1 = (x + 1) * FONT_WIDTH; - if (s->update_y1 < (y + 1) * FONT_HEIGHT) - s->update_y1 = (y + 1) * FONT_HEIGHT; -} - -static void vc_update_xy(VCChardev *vc, int x, int y) -{ - QemuTextConsole *s = vc->console; - TextCell *c; - int y1, y2; - - s->text_x[0] = MIN(s->text_x[0], x); - s->text_x[1] = MAX(s->text_x[1], x); - s->text_y[0] = MIN(s->text_y[0], y); - s->text_y[1] = MAX(s->text_y[1], y); - - y1 = (s->y_base + y) % s->total_height; - y2 = y1 - s->y_displayed; - if (y2 < 0) { - y2 += s->total_height; - } - if (y2 < s->height) { - if (x >= s->width) { - x = s->width - 1; - } - c = &s->cells[y1 * s->width + x]; - vga_putcharxy(QEMU_CONSOLE(s), x, y2, c->ch, - &(c->t_attrib)); - invalidate_xy(s, x, y2); - } -} - -static void console_show_cursor(QemuTextConsole *s, int show) -{ - TextCell *c; - int y, y1; - int x = s->x; - - s->cursor_invalidate = 1; - - if (x >= s->width) { - x = s->width - 1; - } - y1 = (s->y_base + s->y) % s->total_height; - y = y1 - s->y_displayed; - if (y < 0) { - y += s->total_height; - } - if (y < s->height) { - c = &s->cells[y1 * s->width + x]; - if (show && cursor_visible_phase) { - TextAttributes t_attrib = TEXT_ATTRIBUTES_DEFAULT; - t_attrib.invers = !(t_attrib.invers); /* invert fg and bg */ - vga_putcharxy(QEMU_CONSOLE(s), x, y, c->ch, &t_attrib); - } else { - vga_putcharxy(QEMU_CONSOLE(s), x, y, c->ch, &(c->t_attrib)); - } - invalidate_xy(s, x, y); - } -} - -static void console_refresh(QemuTextConsole *s) -{ - DisplaySurface *surface = qemu_console_surface(QEMU_CONSOLE(s)); - TextCell *c; - int x, y, y1; - - assert(surface); - s->text_x[0] = 0; - s->text_y[0] = 0; - s->text_x[1] = s->width - 1; - s->text_y[1] = s->height - 1; - s->cursor_invalidate = 1; - - qemu_console_fill_rect(QEMU_CONSOLE(s), 0, 0, surface_width(surface), surface_height(surface), - color_table_rgb[0][QEMU_COLOR_BLACK]); - y1 = s->y_displayed; - for (y = 0; y < s->height; y++) { - c = s->cells + y1 * s->width; - for (x = 0; x < s->width; x++) { - vga_putcharxy(QEMU_CONSOLE(s), x, y, c->ch, - &(c->t_attrib)); - c++; - } - if (++y1 == s->total_height) { - y1 = 0; - } - } - console_show_cursor(s, 1); - dpy_gfx_update(QEMU_CONSOLE(s), 0, 0, - surface_width(surface), surface_height(surface)); -} - -static void console_scroll(QemuTextConsole *s, int ydelta) -{ - int i, y1; - - if (ydelta > 0) { - for(i = 0; i < ydelta; i++) { - if (s->y_displayed == s->y_base) - break; - if (++s->y_displayed == s->total_height) - s->y_displayed = 0; - } - } else { - ydelta = -ydelta; - i = s->backscroll_height; - if (i > s->total_height - s->height) - i = s->total_height - s->height; - y1 = s->y_base - i; - if (y1 < 0) - y1 += s->total_height; - for(i = 0; i < ydelta; i++) { - if (s->y_displayed == y1) - break; - if (--s->y_displayed < 0) - s->y_displayed = s->total_height - 1; - } - } - console_refresh(s); -} - -static void vc_put_lf(VCChardev *vc) -{ - QemuTextConsole *s = vc->console; - TextCell *c; - int x, y1; - - s->y++; - if (s->y >= s->height) { - s->y = s->height - 1; - - if (s->y_displayed == s->y_base) { - if (++s->y_displayed == s->total_height) - s->y_displayed = 0; - } - if (++s->y_base == s->total_height) - s->y_base = 0; - if (s->backscroll_height < s->total_height) - s->backscroll_height++; - y1 = (s->y_base + s->height - 1) % s->total_height; - c = &s->cells[y1 * s->width]; - for(x = 0; x < s->width; x++) { - c->ch = ' '; - c->t_attrib = TEXT_ATTRIBUTES_DEFAULT; - c++; - } - if (s->y_displayed == s->y_base) { - s->text_x[0] = 0; - s->text_y[0] = 0; - s->text_x[1] = s->width - 1; - s->text_y[1] = s->height - 1; - - qemu_console_bitblt(QEMU_CONSOLE(s), 0, FONT_HEIGHT, 0, 0, - s->width * FONT_WIDTH, - (s->height - 1) * FONT_HEIGHT); - qemu_console_fill_rect(QEMU_CONSOLE(s), 0, (s->height - 1) * FONT_HEIGHT, - s->width * FONT_WIDTH, FONT_HEIGHT, - color_table_rgb[0][TEXT_ATTRIBUTES_DEFAULT.bgcol]); - s->update_x0 = 0; - s->update_y0 = 0; - s->update_x1 = s->width * FONT_WIDTH; - s->update_y1 = s->height * FONT_HEIGHT; - } - } -} - -/* Set console attributes depending on the current escape codes. - * NOTE: I know this code is not very efficient (checking every color for it - * self) but it is more readable and better maintainable. - */ -static void vc_handle_escape(VCChardev *vc) -{ - int i; - - for (i = 0; i < vc->nb_esc_params; i++) { - switch (vc->esc_params[i]) { - case 0: /* reset all console attributes to default */ - vc->t_attrib = TEXT_ATTRIBUTES_DEFAULT; - break; - case 1: - vc->t_attrib.bold = 1; - break; - case 4: - vc->t_attrib.uline = 1; - break; - case 5: - vc->t_attrib.blink = 1; - break; - case 7: - vc->t_attrib.invers = 1; - break; - case 8: - vc->t_attrib.unvisible = 1; - break; - case 22: - vc->t_attrib.bold = 0; - break; - case 24: - vc->t_attrib.uline = 0; - break; - case 25: - vc->t_attrib.blink = 0; - break; - case 27: - vc->t_attrib.invers = 0; - break; - case 28: - vc->t_attrib.unvisible = 0; - break; - /* set foreground color */ - case 30: - vc->t_attrib.fgcol = QEMU_COLOR_BLACK; - break; - case 31: - vc->t_attrib.fgcol = QEMU_COLOR_RED; - break; - case 32: - vc->t_attrib.fgcol = QEMU_COLOR_GREEN; - break; - case 33: - vc->t_attrib.fgcol = QEMU_COLOR_YELLOW; - break; - case 34: - vc->t_attrib.fgcol = QEMU_COLOR_BLUE; - break; - case 35: - vc->t_attrib.fgcol = QEMU_COLOR_MAGENTA; - break; - case 36: - vc->t_attrib.fgcol = QEMU_COLOR_CYAN; - break; - case 37: - vc->t_attrib.fgcol = QEMU_COLOR_WHITE; - break; - /* set background color */ - case 40: - vc->t_attrib.bgcol = QEMU_COLOR_BLACK; - break; - case 41: - vc->t_attrib.bgcol = QEMU_COLOR_RED; - break; - case 42: - vc->t_attrib.bgcol = QEMU_COLOR_GREEN; - break; - case 43: - vc->t_attrib.bgcol = QEMU_COLOR_YELLOW; - break; - case 44: - vc->t_attrib.bgcol = QEMU_COLOR_BLUE; - break; - case 45: - vc->t_attrib.bgcol = QEMU_COLOR_MAGENTA; - break; - case 46: - vc->t_attrib.bgcol = QEMU_COLOR_CYAN; - break; - case 47: - vc->t_attrib.bgcol = QEMU_COLOR_WHITE; - break; - } - } -} - -static void vc_clear_xy(VCChardev *vc, int x, int y) -{ - QemuTextConsole *s = vc->console; - int y1 = (s->y_base + y) % s->total_height; - if (x >= s->width) { - x = s->width - 1; - } - TextCell *c = &s->cells[y1 * s->width + x]; - c->ch = ' '; - c->t_attrib = TEXT_ATTRIBUTES_DEFAULT; - vc_update_xy(vc, x, y); -} - -static void vc_put_one(VCChardev *vc, int ch) -{ - QemuTextConsole *s = vc->console; - TextCell *c; - int y1; - if (s->x >= s->width) { - /* line wrap */ - s->x = 0; - vc_put_lf(vc); - } - y1 = (s->y_base + s->y) % s->total_height; - c = &s->cells[y1 * s->width + s->x]; - c->ch = ch; - c->t_attrib = vc->t_attrib; - vc_update_xy(vc, s->x, s->y); - s->x++; -} - -static void vc_respond_str(VCChardev *vc, const char *buf) -{ - while (*buf) { - vc_put_one(vc, *buf); - buf++; - } -} - -/* set cursor, checking bounds */ -static void vc_set_cursor(VCChardev *vc, int x, int y) -{ - QemuTextConsole *s = vc->console; - - if (x < 0) { - x = 0; - } - if (y < 0) { - y = 0; - } - if (y >= s->height) { - y = s->height - 1; - } - if (x >= s->width) { - x = s->width - 1; - } - - s->x = x; - s->y = y; -} - -static void vc_putchar(VCChardev *vc, int ch) -{ - QemuTextConsole *s = vc->console; - int i; - int x, y; - char response[40]; - - switch(vc->state) { - case TTY_STATE_NORM: - switch(ch) { - case '\r': /* carriage return */ - s->x = 0; - break; - case '\n': /* newline */ - vc_put_lf(vc); - break; - case '\b': /* backspace */ - if (s->x > 0) - s->x--; - break; - case '\t': /* tabspace */ - if (s->x + (8 - (s->x % 8)) > s->width) { - s->x = 0; - vc_put_lf(vc); - } else { - s->x = s->x + (8 - (s->x % 8)); - } - break; - case '\a': /* alert aka. bell */ - /* TODO: has to be implemented */ - break; - case 14: - /* SI (shift in), character set 0 (ignored) */ - break; - case 15: - /* SO (shift out), character set 1 (ignored) */ - break; - case 27: /* esc (introducing an escape sequence) */ - vc->state = TTY_STATE_ESC; - break; - default: - vc_put_one(vc, ch); - break; - } - break; - case TTY_STATE_ESC: /* check if it is a terminal escape sequence */ - if (ch == '[') { - for(i=0;i<MAX_ESC_PARAMS;i++) - vc->esc_params[i] = 0; - vc->nb_esc_params = 0; - vc->state = TTY_STATE_CSI; - } else { - vc->state = TTY_STATE_NORM; - } - break; - case TTY_STATE_CSI: /* handle escape sequence parameters */ - if (ch >= '0' && ch <= '9') { - if (vc->nb_esc_params < MAX_ESC_PARAMS) { - int *param = &vc->esc_params[vc->nb_esc_params]; - int digit = (ch - '0'); - - *param = (*param <= (INT_MAX - digit) / 10) ? - *param * 10 + digit : INT_MAX; - } - } else { - if (vc->nb_esc_params < MAX_ESC_PARAMS) - vc->nb_esc_params++; - if (ch == ';' || ch == '?') { - break; - } - trace_console_putchar_csi(vc->esc_params[0], vc->esc_params[1], - ch, vc->nb_esc_params); - vc->state = TTY_STATE_NORM; - switch(ch) { - case 'A': - /* move cursor up */ - if (vc->esc_params[0] == 0) { - vc->esc_params[0] = 1; - } - vc_set_cursor(vc, s->x, s->y - vc->esc_params[0]); - break; - case 'B': - /* move cursor down */ - if (vc->esc_params[0] == 0) { - vc->esc_params[0] = 1; - } - vc_set_cursor(vc, s->x, s->y + vc->esc_params[0]); - break; - case 'C': - /* move cursor right */ - if (vc->esc_params[0] == 0) { - vc->esc_params[0] = 1; - } - vc_set_cursor(vc, s->x + vc->esc_params[0], s->y); - break; - case 'D': - /* move cursor left */ - if (vc->esc_params[0] == 0) { - vc->esc_params[0] = 1; - } - vc_set_cursor(vc, s->x - vc->esc_params[0], s->y); - break; - case 'G': - /* move cursor to column */ - vc_set_cursor(vc, vc->esc_params[0] - 1, s->y); - break; - case 'f': - case 'H': - /* move cursor to row, column */ - vc_set_cursor(vc, vc->esc_params[1] - 1, vc->esc_params[0] - 1); - break; - case 'J': - switch (vc->esc_params[0]) { - case 0: - /* clear to end of screen */ - for (y = s->y; y < s->height; y++) { - for (x = 0; x < s->width; x++) { - if (y == s->y && x < s->x) { - continue; - } - vc_clear_xy(vc, x, y); - } - } - break; - case 1: - /* clear from beginning of screen */ - for (y = 0; y <= s->y; y++) { - for (x = 0; x < s->width; x++) { - if (y == s->y && x > s->x) { - break; - } - vc_clear_xy(vc, x, y); - } - } - break; - case 2: - /* clear entire screen */ - for (y = 0; y <= s->height; y++) { - for (x = 0; x < s->width; x++) { - vc_clear_xy(vc, x, y); - } - } - break; - } - break; - case 'K': - switch (vc->esc_params[0]) { - case 0: - /* clear to eol */ - for(x = s->x; x < s->width; x++) { - vc_clear_xy(vc, x, s->y); - } - break; - case 1: - /* clear from beginning of line */ - for (x = 0; x <= s->x && x < s->width; x++) { - vc_clear_xy(vc, x, s->y); - } - break; - case 2: - /* clear entire line */ - for(x = 0; x < s->width; x++) { - vc_clear_xy(vc, x, s->y); - } - break; - } - break; - case 'm': - vc_handle_escape(vc); - break; - case 'n': - switch (vc->esc_params[0]) { - case 5: - /* report console status (always succeed)*/ - vc_respond_str(vc, "\033[0n"); - break; - case 6: - /* report cursor position */ - sprintf(response, "\033[%d;%dR", - (s->y_base + s->y) % s->total_height + 1, - s->x + 1); - vc_respond_str(vc, response); - break; - } - break; - case 's': - /* save cursor position */ - vc->x_saved = s->x; - vc->y_saved = s->y; - break; - case 'u': - /* restore cursor position */ - s->x = vc->x_saved; - s->y = vc->y_saved; - break; - default: - trace_console_putchar_unhandled(ch); - break; - } - break; - } - } -} - static void displaychangelistener_gfx_switch(DisplayChangeListener *dcl, struct DisplaySurface *new_surface, bool update) @@ -XXX,XX +XXX,XX @@ static void displaychangelistener_display_console(DisplayChangeListener *dcl, } } -static void -qemu_text_console_select(QemuTextConsole *c) -{ - dpy_text_resize(QEMU_CONSOLE(c), c->width, c->height); - qemu_text_console_update_cursor(NULL); -} - void console_select(unsigned int index) { DisplayChangeListener *dcl; @@ -XXX,XX +XXX,XX @@ void console_select(unsigned int index) } } -#define TYPE_CHARDEV_VC "chardev-vc" -DECLARE_INSTANCE_CHECKER(VCChardev, VC_CHARDEV, - TYPE_CHARDEV_VC) - -static int vc_chr_write(Chardev *chr, const uint8_t *buf, int len) -{ - VCChardev *drv = VC_CHARDEV(chr); - QemuTextConsole *s = drv->console; - int i; - - s->update_x0 = s->width * FONT_WIDTH; - s->update_y0 = s->height * FONT_HEIGHT; - s->update_x1 = 0; - s->update_y1 = 0; - console_show_cursor(s, 0); - for(i = 0; i < len; i++) { - vc_putchar(drv, buf[i]); - } - console_show_cursor(s, 1); - if (s->update_x0 < s->update_x1) { - dpy_gfx_update(QEMU_CONSOLE(s), s->update_x0, s->update_y0, - s->update_x1 - s->update_x0, - s->update_y1 - s->update_y0); - } - return len; -} - -static void kbd_send_chars(QemuTextConsole *s) -{ - uint32_t len, avail; - - len = qemu_chr_be_can_write(s->chr); - avail = fifo8_num_used(&s->out_fifo); - while (len > 0 && avail > 0) { - const uint8_t *buf; - uint32_t size; - - buf = fifo8_pop_buf(&s->out_fifo, MIN(len, avail), &size); - qemu_chr_be_write(s->chr, buf, size); - len = qemu_chr_be_can_write(s->chr); - avail -= size; - } -} - -/* called when an ascii key is pressed */ -static void qemu_text_console_handle_keysym(QemuTextConsole *s, int keysym) -{ - uint8_t buf[16], *q; - int c; - uint32_t num_free; - - switch(keysym) { - case QEMU_KEY_CTRL_UP: - console_scroll(s, -1); - break; - case QEMU_KEY_CTRL_DOWN: - console_scroll(s, 1); - break; - case QEMU_KEY_CTRL_PAGEUP: - console_scroll(s, -10); - break; - case QEMU_KEY_CTRL_PAGEDOWN: - console_scroll(s, 10); - break; - default: - /* convert the QEMU keysym to VT100 key string */ - q = buf; - if (keysym >= 0xe100 && keysym <= 0xe11f) { - *q++ = '\033'; - *q++ = '['; - c = keysym - 0xe100; - if (c >= 10) - *q++ = '0' + (c / 10); - *q++ = '0' + (c % 10); - *q++ = '~'; - } else if (keysym >= 0xe120 && keysym <= 0xe17f) { - *q++ = '\033'; - *q++ = '['; - *q++ = keysym & 0xff; - } else if (s->echo && (keysym == '\r' || keysym == '\n')) { - qemu_chr_write(s->chr, (uint8_t *)"\r", 1, true); - *q++ = '\n'; - } else { - *q++ = keysym; - } - if (s->echo) { - qemu_chr_write(s->chr, buf, q - buf, true); - } - num_free = fifo8_num_free(&s->out_fifo); - fifo8_push_all(&s->out_fifo, buf, MIN(num_free, q - buf)); - kbd_send_chars(s); - break; - } -} - void qemu_text_console_put_keysym(QemuTextConsole *s, int keysym) { if (!s) { @@ -XXX,XX +XXX,XX @@ void qemu_text_console_put_string(QemuTextConsole *s, const char *str, int len) } } -static void text_console_invalidate(void *opaque) -{ - QemuTextConsole *s = QEMU_TEXT_CONSOLE(opaque); - - if (!QEMU_IS_FIXED_TEXT_CONSOLE(s)) { - text_console_resize(QEMU_TEXT_CONSOLE(s)); - } - console_refresh(s); -} - -static void text_console_update(void *opaque, console_ch_t *chardata) -{ - QemuTextConsole *s = QEMU_TEXT_CONSOLE(opaque); - int i, j, src; - - if (s->text_x[0] <= s->text_x[1]) { - src = (s->y_base + s->text_y[0]) * s->width; - chardata += s->text_y[0] * s->width; - for (i = s->text_y[0]; i <= s->text_y[1]; i ++) - for (j = 0; j < s->width; j++, src++) { - console_write_ch(chardata ++, - ATTR2CHTYPE(s->cells[src].ch, - s->cells[src].t_attrib.fgcol, - s->cells[src].t_attrib.bgcol, - s->cells[src].t_attrib.bold)); - } - dpy_text_update(QEMU_CONSOLE(s), s->text_x[0], s->text_y[0], - s->text_x[1] - s->text_x[0], i - s->text_y[0]); - s->text_x[0] = s->width; - s->text_y[0] = s->height; - s->text_x[1] = 0; - s->text_y[1] = 0; - } - if (s->cursor_invalidate) { - dpy_text_cursor(QEMU_CONSOLE(s), s->x, s->y); - s->cursor_invalidate = 0; - } -} - static void qemu_console_register(QemuConsole *c) { @@ -XXX,XX +XXX,XX @@ qemu_graphic_console_init(Object *obj) { } -static void -qemu_text_console_finalize(Object *obj) -{ -} - -static void -qemu_text_console_class_init(ObjectClass *oc, void *data) -{ - if (!cursor_timer) { - cursor_timer = timer_new_ms(QEMU_CLOCK_REALTIME, - qemu_text_console_update_cursor, NULL); - } -} - -static const GraphicHwOps text_console_ops = { - .invalidate = text_console_invalidate, - .text_update = text_console_update, -}; - -static void -qemu_text_console_init(Object *obj) -{ - QemuTextConsole *c = QEMU_TEXT_CONSOLE(obj); - - fifo8_create(&c->out_fifo, 16); - c->total_height = DEFAULT_BACKSCROLL; - QEMU_CONSOLE(c)->hw_ops = &text_console_ops; - QEMU_CONSOLE(c)->hw = c; -} - -static void -qemu_fixed_text_console_finalize(Object *obj) -{ -} - -static void -qemu_fixed_text_console_class_init(ObjectClass *oc, void *data) -{ -} - -static void -qemu_fixed_text_console_init(Object *obj) -{ -} - #ifdef WIN32 void qemu_displaysurface_win32_set_handle(DisplaySurface *surface, HANDLE h, uint32_t offset) @@ -XXX,XX +XXX,XX @@ dcl_set_graphic_cursor(DisplayChangeListener *dcl, QemuGraphicConsole *con) dcl->ops->dpy_mouse_set(dcl, con->cursor_x, con->cursor_y, con->cursor_on); } } + void register_displaychangelistener(DisplayChangeListener *dcl) { QemuConsole *con; @@ -XXX,XX +XXX,XX @@ void register_displaychangelistener(DisplayChangeListener *dcl) if (QEMU_IS_GRAPHIC_CONSOLE(con)) { dcl_set_graphic_cursor(dcl, QEMU_GRAPHIC_CONSOLE(con)); } - qemu_text_console_update_cursor(NULL); + qemu_text_console_update_cursor(); } void update_displaychangelistener(DisplayChangeListener *dcl, @@ -XXX,XX +XXX,XX @@ bool qemu_console_is_multihead(DeviceState *dev) return false; } - -static const char * -qemu_text_console_get_label(QemuTextConsole *c) -{ - return c->chr ? c->chr->label : NULL; -} - char *qemu_console_get_label(QemuConsole *con) { if (QEMU_IS_GRAPHIC_CONSOLE(con)) { @@ -XXX,XX +XXX,XX @@ int qemu_console_get_height(QemuConsole *con, int fallback) } } -static void vc_chr_accept_input(Chardev *chr) -{ - VCChardev *drv = VC_CHARDEV(chr); - - kbd_send_chars(drv->console); -} - -static void vc_chr_set_echo(Chardev *chr, bool echo) -{ - VCChardev *drv = VC_CHARDEV(chr); - - drv->console->echo = echo; -} - int qemu_invalidate_text_consoles(void) { QemuConsole *s; @@ -XXX,XX +XXX,XX @@ int qemu_invalidate_text_consoles(void) return count; } -static void qemu_text_console_update_cursor(void *opaque) -{ - cursor_visible_phase = !cursor_visible_phase; - - if (qemu_invalidate_text_consoles()) { - timer_mod(cursor_timer, - qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + CONSOLE_CURSOR_PERIOD / 2); - } -} - -static void vc_chr_open(Chardev *chr, - ChardevBackend *backend, - bool *be_opened, - Error **errp) -{ - ChardevVC *vc = backend->u.vc.data; - VCChardev *drv = VC_CHARDEV(chr); - QemuTextConsole *s; - unsigned width = 0; - unsigned height = 0; - - if (vc->has_width) { - width = vc->width; - } else if (vc->has_cols) { - width = vc->cols * FONT_WIDTH; - } - - if (vc->has_height) { - height = vc->height; - } else if (vc->has_rows) { - height = vc->rows * FONT_HEIGHT; - } - - trace_console_txt_new(width, height); - if (width == 0 || height == 0) { - s = QEMU_TEXT_CONSOLE(object_new(TYPE_QEMU_TEXT_CONSOLE)); - width = qemu_console_get_width(NULL, 80 * FONT_WIDTH); - height = qemu_console_get_height(NULL, 24 * FONT_HEIGHT); - } else { - s = QEMU_TEXT_CONSOLE(object_new(TYPE_QEMU_FIXED_TEXT_CONSOLE)); - } - - dpy_gfx_replace_surface(QEMU_CONSOLE(s), qemu_create_displaysurface(width, height)); - - s->chr = chr; - drv->console = s; - - /* set current text attributes to default */ - drv->t_attrib = TEXT_ATTRIBUTES_DEFAULT; - text_console_resize(s); - - if (chr->label) { - char *msg; - - drv->t_attrib.bgcol = QEMU_COLOR_BLUE; - msg = g_strdup_printf("%s console\r\n", chr->label); - qemu_chr_write(chr, (uint8_t *)msg, strlen(msg), true); - g_free(msg); - drv->t_attrib = TEXT_ATTRIBUTES_DEFAULT; - } - - *be_opened = true; -} - void qemu_console_resize(QemuConsole *s, int width, int height) { DisplaySurface *surface = qemu_console_surface(s); @@ -XXX,XX +XXX,XX @@ void qemu_display_help(void) } } } - -static void vc_chr_parse(QemuOpts *opts, ChardevBackend *backend, Error **errp) -{ - int val; - ChardevVC *vc; - - backend->type = CHARDEV_BACKEND_KIND_VC; - vc = backend->u.vc.data = g_new0(ChardevVC, 1); - qemu_chr_parse_common(opts, qapi_ChardevVC_base(vc)); - - val = qemu_opt_get_number(opts, "width", 0); - if (val != 0) { - vc->has_width = true; - vc->width = val; - } - - val = qemu_opt_get_number(opts, "height", 0); - if (val != 0) { - vc->has_height = true; - vc->height = val; - } - - val = qemu_opt_get_number(opts, "cols", 0); - if (val != 0) { - vc->has_cols = true; - vc->cols = val; - } - - val = qemu_opt_get_number(opts, "rows", 0); - if (val != 0) { - vc->has_rows = true; - vc->rows = val; - } -} - -static void char_vc_class_init(ObjectClass *oc, void *data) -{ - ChardevClass *cc = CHARDEV_CLASS(oc); - - cc->parse = vc_chr_parse; - cc->open = vc_chr_open; - cc->chr_write = vc_chr_write; - cc->chr_accept_input = vc_chr_accept_input; - cc->chr_set_echo = vc_chr_set_echo; -} - -static const TypeInfo char_vc_type_info = { - .name = TYPE_CHARDEV_VC, - .parent = TYPE_CHARDEV, - .instance_size = sizeof(VCChardev), - .class_init = char_vc_class_init, -}; - -void qemu_console_early_init(void) -{ - /* set the default vc driver */ - if (!object_class_by_name(TYPE_CHARDEV_VC)) { - type_register(&char_vc_type_info); - } -} diff --git a/ui/meson.build b/ui/meson.build index XXXXXXX..XXXXXXX 100644 --- a/ui/meson.build +++ b/ui/meson.build @@ -XXX,XX +XXX,XX @@ system_ss.add(png) system_ss.add(files( 'clipboard.c', 'console.c', + 'console-vc.c', 'cursor.c', 'input-keymap.c', 'input-legacy.c', -- 2.41.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> Mostly for readability reasons. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> --- include/ui/console.h | 84 +-------------------------------------- include/ui/surface.h | 95 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 83 deletions(-) create mode 100644 include/ui/surface.h diff --git a/include/ui/console.h b/include/ui/console.h index XXXXXXX..XXXXXXX 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -XXX,XX +XXX,XX @@ #include "qemu/notify.h" #include "qapi/qapi-types-ui.h" #include "ui/input.h" - -#ifdef CONFIG_OPENGL -# include <epoxy/gl.h> -# include "ui/shader.h" -#endif +#include "ui/surface.h" #define TYPE_QEMU_CONSOLE "qemu-console" OBJECT_DECLARE_TYPE(QemuConsole, QemuConsoleClass, QEMU_CONSOLE) @@ -XXX,XX +XXX,XX @@ struct QemuConsoleClass { ObjectClass parent_class; }; -#define QEMU_ALLOCATED_FLAG 0x01 -#define QEMU_PLACEHOLDER_FLAG 0x02 - typedef struct ScanoutTexture { uint32_t backing_id; bool backing_y_0_top; @@ -XXX,XX +XXX,XX @@ typedef struct ScanoutTexture { void *d3d_tex2d; } ScanoutTexture; -typedef struct DisplaySurface { - pixman_image_t *image; - uint8_t flags; -#ifdef CONFIG_OPENGL - GLenum glformat; - GLenum gltype; - GLuint texture; -#endif -#ifdef WIN32 - HANDLE handle; - uint32_t handle_offset; -#endif -} DisplaySurface; - typedef struct QemuUIInfo { /* physical dimension */ uint16_t width_mm; @@ -XXX,XX +XXX,XX @@ struct DisplayGLCtx { }; DisplayState *init_displaystate(void); -DisplaySurface *qemu_create_displaysurface_from(int width, int height, - pixman_format_code_t format, - int linesize, uint8_t *data); -DisplaySurface *qemu_create_displaysurface_pixman(pixman_image_t *image); -DisplaySurface *qemu_create_placeholder_surface(int w, int h, - const char *msg); -#ifdef WIN32 -void qemu_displaysurface_win32_set_handle(DisplaySurface *surface, - HANDLE h, uint32_t offset); -#endif -PixelFormat qemu_default_pixelformat(int bpp); - -DisplaySurface *qemu_create_displaysurface(int width, int height); -void qemu_free_displaysurface(DisplaySurface *surface); - -static inline int is_buffer_shared(DisplaySurface *surface) -{ - return !(surface->flags & QEMU_ALLOCATED_FLAG); -} - -static inline int is_placeholder(DisplaySurface *surface) -{ - return surface->flags & QEMU_PLACEHOLDER_FLAG; -} void register_displaychangelistener(DisplayChangeListener *dcl); void update_displaychangelistener(DisplayChangeListener *dcl, @@ -XXX,XX +XXX,XX @@ int dpy_gl_ctx_make_current(QemuConsole *con, QEMUGLContext ctx); bool console_has_gl(QemuConsole *con); -static inline int surface_stride(DisplaySurface *s) -{ - return pixman_image_get_stride(s->image); -} - -static inline void *surface_data(DisplaySurface *s) -{ - return pixman_image_get_data(s->image); -} - -static inline int surface_width(DisplaySurface *s) -{ - return pixman_image_get_width(s->image); -} - -static inline int surface_height(DisplaySurface *s) -{ - return pixman_image_get_height(s->image); -} - -static inline pixman_format_code_t surface_format(DisplaySurface *s) -{ - return pixman_image_get_format(s->image); -} - -static inline int surface_bits_per_pixel(DisplaySurface *s) -{ - int bits = PIXMAN_FORMAT_BPP(surface_format(s)); - return bits; -} - -static inline int surface_bytes_per_pixel(DisplaySurface *s) -{ - int bits = PIXMAN_FORMAT_BPP(surface_format(s)); - return DIV_ROUND_UP(bits, 8); -} - typedef uint32_t console_ch_t; static inline void console_write_ch(console_ch_t *dest, uint32_t ch) diff --git a/include/ui/surface.h b/include/ui/surface.h new file mode 100644 index XXXXXXX..XXXXXXX --- /dev/null +++ b/include/ui/surface.h @@ -XXX,XX +XXX,XX @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * QEMU UI Console + */ +#ifndef SURFACE_H +#define SURFACE_H + +#include "ui/qemu-pixman.h" + +#ifdef CONFIG_OPENGL +# include <epoxy/gl.h> +# include "ui/shader.h" +#endif + +#define QEMU_ALLOCATED_FLAG 0x01 +#define QEMU_PLACEHOLDER_FLAG 0x02 + +typedef struct DisplaySurface { + pixman_image_t *image; + uint8_t flags; +#ifdef CONFIG_OPENGL + GLenum glformat; + GLenum gltype; + GLuint texture; +#endif +#ifdef WIN32 + HANDLE handle; + uint32_t handle_offset; +#endif +} DisplaySurface; + +PixelFormat qemu_default_pixelformat(int bpp); + +DisplaySurface *qemu_create_displaysurface_from(int width, int height, + pixman_format_code_t format, + int linesize, uint8_t *data); +DisplaySurface *qemu_create_displaysurface_pixman(pixman_image_t *image); +DisplaySurface *qemu_create_placeholder_surface(int w, int h, + const char *msg); +#ifdef WIN32 +void qemu_displaysurface_win32_set_handle(DisplaySurface *surface, + HANDLE h, uint32_t offset); +#endif + +DisplaySurface *qemu_create_displaysurface(int width, int height); +void qemu_free_displaysurface(DisplaySurface *surface); + +static inline int is_buffer_shared(DisplaySurface *surface) +{ + return !(surface->flags & QEMU_ALLOCATED_FLAG); +} + +static inline int is_placeholder(DisplaySurface *surface) +{ + return surface->flags & QEMU_PLACEHOLDER_FLAG; +} + +static inline int surface_stride(DisplaySurface *s) +{ + return pixman_image_get_stride(s->image); +} + +static inline void *surface_data(DisplaySurface *s) +{ + return pixman_image_get_data(s->image); +} + +static inline int surface_width(DisplaySurface *s) +{ + return pixman_image_get_width(s->image); +} + +static inline int surface_height(DisplaySurface *s) +{ + return pixman_image_get_height(s->image); +} + +static inline pixman_format_code_t surface_format(DisplaySurface *s) +{ + return pixman_image_get_format(s->image); +} + +static inline int surface_bits_per_pixel(DisplaySurface *s) +{ + int bits = PIXMAN_FORMAT_BPP(surface_format(s)); + return bits; +} + +static inline int surface_bytes_per_pixel(DisplaySurface *s) +{ + int bits = PIXMAN_FORMAT_BPP(surface_format(s)); + return DIV_ROUND_UP(bits, 8); +} + +#endif -- 2.41.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> Don't forget to unmap the resource memory. Fixes: commit 9462ff469 ("virtio-gpu/win32: allocate shareable 2d resources/images") Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- hw/display/virtio-gpu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index XXXXXXX..XXXXXXX 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -XXX,XX +XXX,XX @@ static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size, g_free(res); return -EINVAL; } - +#ifdef WIN32 + pixman_image_set_destroy_function(res->image, win32_pixman_image_destroy, res->handle); +#endif res->addrs = g_new(uint64_t, res->iov_cnt); res->iov = g_new(struct iovec, res->iov_cnt); -- 2.41.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> Thread 1 "qemu-system-x86" received signal SIGSEGV, Segmentation fault. 0x0000555555888630 in dpy_ui_info_supported (con=0x0) at ../ui/console.c:812 812 return con->hw_ops->ui_info != NULL; (gdb) bt #0 0x0000555555888630 in dpy_ui_info_supported (con=0x0) at ../ui/console.c:812 #1 0x00005555558a44b1 in protocol_client_msg (vs=0x5555578c76c0, data=0x5555581e93f0 <incomplete sequence \373>, len=24) at ../ui/vnc.c:2585 #2 0x00005555558a19ac in vnc_client_read (vs=0x5555578c76c0) at ../ui/vnc.c:1607 #3 0x00005555558a1ac2 in vnc_client_io (ioc=0x5555581eb0e0, condition=G_IO_IN, opaque=0x5555578c76c0) at ../ui/vnc.c:1635 Fixes: https://issues.redhat.com/browse/RHEL-2600 Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Albert Esteve <aesteve@redhat.com> --- ui/console.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ui/console.c b/ui/console.c index XXXXXXX..XXXXXXX 100644 --- a/ui/console.c +++ b/ui/console.c @@ -XXX,XX +XXX,XX @@ bool dpy_ui_info_supported(QemuConsole *con) if (con == NULL) { con = active_console; } + if (con == NULL) { + return false; + } return con->hw_ops->ui_info != NULL; } -- 2.41.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> Ensure that it only get called when dpy_ui_info_supported(). The function should always return a result. There should be a non-null console or active_console. Modify the argument to be const as well. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Albert Esteve <aesteve@redhat.com> --- include/ui/console.h | 2 +- ui/console.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index XXXXXXX..XXXXXXX 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -XXX,XX +XXX,XX @@ void update_displaychangelistener(DisplayChangeListener *dcl, uint64_t interval); void unregister_displaychangelistener(DisplayChangeListener *dcl); -bool dpy_ui_info_supported(QemuConsole *con); +bool dpy_ui_info_supported(const QemuConsole *con); const QemuUIInfo *dpy_get_ui_info(const QemuConsole *con); int dpy_set_ui_info(QemuConsole *con, QemuUIInfo *info, bool delay); diff --git a/ui/console.c b/ui/console.c index XXXXXXX..XXXXXXX 100644 --- a/ui/console.c +++ b/ui/console.c @@ -XXX,XX +XXX,XX @@ static void dpy_set_ui_info_timer(void *opaque) con->hw_ops->ui_info(con->hw, head, &con->ui_info); } -bool dpy_ui_info_supported(QemuConsole *con) +bool dpy_ui_info_supported(const QemuConsole *con) { if (con == NULL) { con = active_console; @@ -XXX,XX +XXX,XX @@ bool dpy_ui_info_supported(QemuConsole *con) const QemuUIInfo *dpy_get_ui_info(const QemuConsole *con) { + assert(dpy_ui_info_supported(con)); + if (con == NULL) { con = active_console; } -- 2.41.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> The following changes since commit 3f129ea545f16e82b5e43fcc3866b134b7cc4dfc: Merge tag 'pull-vfio-20260520' of https://github.com/legoater/qemu into staging (2026-05-20 16:53:28 -0400) are available in the Git repository at: https://gitlab.com/marcandre.lureau/qemu.git tags/ui-pull-request for you to fetch changes up to 64abff825b6fab9366b582f4d54eb2d12985c0b7: ui/gtk: Fix focus loss on re-attachment with single VC (2026-05-21 15:29:58 +0400) ---------------------------------------------------------------- UI pull request - ui/input: Decouple internal and QAPI input events - VNC OOB fixes - vt100 fixes - GTK focus fix ---------------------------------------------------------------- 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 Daniel P. Berrangé (4): ui/vnc: fix OOB read access in VNC SASL mechname array ui/vnc: fix OOB write in VNC stats array ui/vnc: fix OOB write in lossy rect worker code ui/vnc: fix OOB read updating VNC update frequency stats Dongwon Kim (1): ui/gtk: Fix focus loss on re-attachment with single VC Heechan Kang (1): ui: fix validation of VNC extended clipboard data length Marc-André Lureau (1): ui/vt100: add vt100_fini() check Peter Maydell (2): ui/vt100: Standardize on uint8_t for "ch" byte variables ui/vt100: Take byte as uint8_t in bh_utf8_decode() 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/vnc.h | 4 +- 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 | 55 ++++--- 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-auth-sasl.c | 2 + ui/vnc-clipboard.c | 9 +- ui/vnc.c | 41 ++--- ui/vt100.c | 11 +- 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 +- 49 files changed, 1014 insertions(+), 1098 deletions(-) -- 2.54.0
From: Peter Maydell <peter.maydell@linaro.org> The vt100 code is rather confused about how it handles bytes of data to be sent to the terminal: * vt100_input() takes a buffer of uint8_t * each byte is passed to vt100_putchar(), which takes "int ch" * that calls vt100_put_one(), which also takes "int ch" * vt100_put_one() sets TextCell::ch, which is uint8_t again * various places pass the TextCell:ch value to vt100_putcharxy(), which takes "int ch" again, but uses it unchecked as an index into a 256-entry array This confuses Coverity (e.g. CID 1659590) and the reader, who may be unsure whether the "int" variable really does hold only valid byte values 0..255 and whether we need to bounds-check before doing array dereferences. Standardize on keeping known-byte data in uint8_t all the way through. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-ID: <20260512104210.3330835-2-peter.maydell@linaro.org> --- ui/vt100.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/vt100.c b/ui/vt100.c index XXXXXXX..XXXXXXX 100644 --- a/ui/vt100.c +++ b/ui/vt100.c @@ -XXX,XX +XXX,XX @@ static void image_bitblt(pixman_image_t *image, xs, ys, 0, 0, xd, yd, w, h); } -static void vt100_putcharxy(QemuVT100 *vt, int x, int y, int ch, +static void vt100_putcharxy(QemuVT100 *vt, int x, int y, uint8_t ch, TextAttributes *t_attrib) { static pixman_image_t *glyphs[256]; @@ -XXX,XX +XXX,XX @@ static uint32_t bh_utf8_decode(uint32_t *state, uint32_t *codep, uint32_t byte) return *state; } -static void vt100_put_one(QemuVT100 *vt, int ch) +static void vt100_put_one(QemuVT100 *vt, uint8_t ch) { TextCell *c; int y1; @@ -XXX,XX +XXX,XX @@ static void vt100_restore_cursor(QemuVT100 *vt) vt->t_attrib = vt->t_attrib_saved; } -static void vt100_putchar(QemuVT100 *vt, int ch) +static void vt100_putchar(QemuVT100 *vt, uint8_t ch) { int i; int x, y; -- 2.54.0
From: Peter Maydell <peter.maydell@linaro.org> The bh_utf8_decode() UTF8 decoder takes its next byte as a "uint32_t byte" parameter, but it assumes it to be in bounds as it immediately indexes into its array with it. Use "uint8_t" as the argument type instead. This moves us away from the upstream implementation slightly, but it is the same type as we use in the one callsite, and it makes it clear that we can't be indexing off the end of the array with this guest-derived data. This probably helps make Coverity a bit happier (CID 1659590). Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-ID: <20260512104210.3330835-3-peter.maydell@linaro.org> --- ui/vt100.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/vt100.c b/ui/vt100.c index XXXXXXX..XXXXXXX 100644 --- a/ui/vt100.c +++ b/ui/vt100.c @@ -XXX,XX +XXX,XX @@ static void vt100_clear_xy(QemuVT100 *vt, int x, int y) #define BH_UTF8_ACCEPT 0 #define BH_UTF8_REJECT 12 -static uint32_t bh_utf8_decode(uint32_t *state, uint32_t *codep, uint32_t byte) +static uint32_t bh_utf8_decode(uint32_t *state, uint32_t *codep, uint8_t byte) { static const uint8_t utf8d[] = { /* character class lookup */ -- 2.54.0
From: Marc-André Lureau <marcandre.lureau@redhat.com> vt100_fini() is called unconditonally from qemu_text_console_finalize(), but it may not have been vt100_init()/opened: fix the crash in that case. Fixes: 8fa294482eb ("ui/console-vc: move VT100 state machine ...") Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- ui/vt100.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ui/vt100.c b/ui/vt100.c index XXXXXXX..XXXXXXX 100644 --- a/ui/vt100.c +++ b/ui/vt100.c @@ -XXX,XX +XXX,XX @@ void vt100_init(QemuVT100 *vt, void vt100_fini(QemuVT100 *vt) { + if (!QTAILQ_IN_USE(vt, list)) { + return; + } QTAILQ_REMOVE(&vt100s, vt, list); fifo8_destroy(&vt->out_fifo); g_free(vt->cells); -- 2.54.0
From: Daniel P. Berrangé <berrange@redhat.com> When reading the SASL mechname array off the VNC connection, if malicious, the received data may contain embedded NULs. If this happens the memory buffer returned by g_strndup may be shorter than the original data. Unfortunately the code continued to index into this buffer with an offset equal to the original length. This is a potential OOB read of the array. Fixes: 5847d9e1 (ui/vnc: simplify and avoid strncpy) Reported-by: boy juju <agx1657748706@gmail.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-ID: <20260521103353.1645561-2-berrange@redhat.com> --- ui/vnc-auth-sasl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ui/vnc-auth-sasl.c b/ui/vnc-auth-sasl.c index XXXXXXX..XXXXXXX 100644 --- a/ui/vnc-auth-sasl.c +++ b/ui/vnc-auth-sasl.c @@ -XXX,XX +XXX,XX @@ static int protocol_client_auth_sasl_mechname(VncState *vs, uint8_t *data, size_ char *mechname = g_strndup((const char *) data, len); trace_vnc_auth_sasl_mech_choose(vs, mechname); + /* If 'data' had embedded NUL the dup'd string might now be shorter */ + len = strlen(mechname); if (strncmp(vs->sasl.mechlist, mechname, len) == 0) { if (vs->sasl.mechlist[len] != '\0' && vs->sasl.mechlist[len] != ',') { -- 2.54.0
From: Daniel P. Berrangé <berrange@redhat.com> The VncSurface struct maintains update statistics in an array: VncRectStat stats[VNC_STAT_ROWS][VNC_STAT_COLS]; where the dimensions are defined as: #define VNC_STAT_RECT 64 #define VNC_STAT_COLS (VNC_MAX_WIDTH / VNC_STAT_RECT) #define VNC_STAT_ROWS (VNC_MAX_HEIGHT / VNC_STAT_RECT) If VNC_MAX_WIDTH / VNC_MAX_HEIGHT are not an exact multiple of VNC_STAT_REC, the COLS/ROWS will be undersized by 1. Unfortunately: #define VNC_MAX_HEIGHT 2160 is not a multiple of 64, so there is potential for OOB reads and writes in the 'stats' array, if the guest surface is over 2112 pixels in height. An array overflow occurs when vnc_update_stats() records new statistics, either scribbling over data later in the VncDisplay struct that 'stats' is embedded in, or performing an OOB write on the allocated struct memory. Fixes: CVE-2026-48002 Reported-by: boy juju <agx1657748706@gmail.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-ID: <20260521103353.1645561-3-berrange@redhat.com> --- ui/vnc.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/vnc.h b/ui/vnc.h index XXXXXXX..XXXXXXX 100644 --- a/ui/vnc.h +++ b/ui/vnc.h @@ -XXX,XX +XXX,XX @@ typedef void VncSendHextileTile(VncState *vs, #define VNC_DIRTY_BPL(x) (sizeof((x)->dirty) / VNC_MAX_HEIGHT * BITS_PER_BYTE) #define VNC_STAT_RECT 64 -#define VNC_STAT_COLS (VNC_MAX_WIDTH / VNC_STAT_RECT) -#define VNC_STAT_ROWS (VNC_MAX_HEIGHT / VNC_STAT_RECT) +#define VNC_STAT_COLS DIV_ROUND_UP(VNC_MAX_WIDTH, VNC_STAT_RECT) +#define VNC_STAT_ROWS DIV_ROUND_UP(VNC_MAX_HEIGHT, VNC_STAT_RECT) #define VNC_AUTH_CHALLENGE_SIZE 16 -- 2.54.0
From: Daniel P. Berrangé <berrange@redhat.com> Incorrect calculation of the boundary condition when tracking lossy rectangles in the worker thread will result in an OOB write which can corrupt further worker state, and/or trigger any guard pages that may lie beyond the VncWorker struct. This can be triggered through careful choice of the display resolution in the guest OS by an unprivileged user. Fixes: CVE-2026-48002 Reported-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-ID: <20260521103353.1645561-4-berrange@redhat.com> [Marc-André - added assert() suggest by philmd@linaro.org] Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- ui/vnc.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index XXXXXXX..XXXXXXX 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -XXX,XX +XXX,XX @@ void vnc_sent_lossy_rect(VncWorker *worker, int x, int y, int w, int h) { int i, j; - w = (x + w) / VNC_STAT_RECT; - h = (y + h) / VNC_STAT_RECT; + w = DIV_ROUND_UP((x + w), VNC_STAT_RECT); + h = DIV_ROUND_UP((y + h), VNC_STAT_RECT); + assert(h <= VNC_STAT_ROWS) + assert(w <= VNC_STAT_COLS) x /= VNC_STAT_RECT; y /= VNC_STAT_RECT; - for (j = y; j <= h; j++) { - for (i = x; i <= w; i++) { + for (j = y; j < h; j++) { + for (i = x; i < w; i++) { worker->lossy_rect[j][i] = 1; } } -- 2.54.0
From: Daniel P. Berrangé <berrange@redhat.com> Incorrect loop bounds in vnc_update_freq result in iterating past the last row and past the last column in the VNC stats array. With suitably chosen dimensions this could be a OOB read that accesses memory beyond the VncDisplay struct that the stats array is embedded in. Should this hit a guard page, it could trigger a guest crash. If it does not, then the VNC frequency stats will be updated with garbage. Fixes: CVE-2026-48003 Reported-by: boy juju <agx1657748706@gmail.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-ID: <20260521103353.1645561-5-berrange@redhat.com> --- ui/vnc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index XXXXXXX..XXXXXXX 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -XXX,XX +XXX,XX @@ double vnc_update_freq(VncState *vs, int x, int y, int w, int h) int i, j; double total = 0; int num = 0; + int x_end = x + w; + int y_end = y + h; x = QEMU_ALIGN_DOWN(x, VNC_STAT_RECT); y = QEMU_ALIGN_DOWN(y, VNC_STAT_RECT); - for (j = y; j <= y + h; j += VNC_STAT_RECT) { - for (i = x; i <= x + w; i += VNC_STAT_RECT) { + for (j = y; j < y_end; j += VNC_STAT_RECT) { + for (i = x; i < x_end; i += VNC_STAT_RECT) { total += vnc_stat_rect(vs->vd, i, j)->freq; num++; } -- 2.54.0
From: Heechan Kang <gganji11@naver.com> QEMU's VNC extended clipboard handler inflates a client-controlled compressed clipboard payload. The code checks the declared text size against the total inflated buffer size: if (tsize < size) but then copies from: tbuf = buf + 4; qemu_clipboard_set_data(..., tsize, tbuf, true); The correct bound is the remaining data length after the 4-byte length field, not the total inflated buffer length. As a result, a VNC client can make QEMU copy up to 3 bytes past the end of the inflated heap buffer. With a second VNC client, those copied bytes are observable through the normal VNC extended clipboard PROVIDE path. Fixes: CVE-2026-8343 Reported-by: Heechan Kang <gganji11@naver.com> Reported-by: Feifan Qian <bea1e@proton.me> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Heechan Kang <gganji11@naver.com> [DB: added #include and 'return' statements] Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-ID: <20260512095543.459949-1-berrange@redhat.com> --- ui/vnc-clipboard.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ui/vnc-clipboard.c b/ui/vnc-clipboard.c index XXXXXXX..XXXXXXX 100644 --- a/ui/vnc-clipboard.c +++ b/ui/vnc-clipboard.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" +#include "qemu/error-report.h" #include "vnc.h" #include "vnc-jobs.h" @@ -XXX,XX +XXX,XX @@ void vnc_client_cut_text_ext(VncState *vs, int32_t len, uint32_t flags, uint8_t buf && size >= 4) { uint32_t tsize = read_u32(buf, 0); uint8_t *tbuf = buf + 4; - if (tsize < size) { + if (tsize <= size - 4) { qemu_clipboard_set_data(&vs->cbpeer, vs->cbinfo, QEMU_CLIPBOARD_TYPE_TEXT, tsize, tbuf, true); + } else { + error_report("vnc: malformed extended clipboard payload " + "with text length %u exceeding available %u", + tsize, size - 4); + vnc_client_error(vs); + return; } } } -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> Add QemuInputEvent as the input subsystem's name for InputEvent and use it in input handler, queue, and replay interfaces. This prepares for decoupling QEMU's internal input event representation from the QAPI InputEvent type. 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-1-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- include/qemu/typedefs.h | 1 + include/system/replay.h | 2 +- include/ui/input.h | 6 +++--- replay/replay-internal.h | 6 +++--- chardev/msmouse.c | 2 +- chardev/wctablet.c | 2 +- hw/arm/musicpal.c | 2 +- hw/char/escc.c | 4 ++-- hw/display/xenfb.c | 4 ++-- hw/input/adb-kbd.c | 2 +- hw/input/adb-mouse.c | 2 +- hw/input/hid.c | 4 ++-- hw/input/ps2.c | 4 ++-- hw/input/stellaris_gamepad.c | 2 +- hw/input/virtio-input-hid.c | 2 +- hw/m68k/next-kbd.c | 3 ++- replay/replay-events.c | 4 ++-- replay/replay-input.c | 8 ++++---- replay/stubs-system.c | 2 +- ui/input-legacy.c | 2 +- ui/input.c | 26 +++++++++++++------------- ui/vdagent.c | 2 +- 22 files changed, 47 insertions(+), 45 deletions(-) diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index XXXXXXX..XXXXXXX 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -XXX,XX +XXX,XX @@ typedef struct QBool QBool; typedef struct QDict QDict; typedef struct QEMUBH QEMUBH; typedef struct QemuConsole QemuConsole; +typedef struct InputEvent QemuInputEvent; typedef struct QEMUCursor QEMUCursor; typedef struct QEMUFile QEMUFile; typedef struct QemuMutex QemuMutex; diff --git a/include/system/replay.h b/include/system/replay.h index XXXXXXX..XXXXXXX 100644 --- a/include/system/replay.h +++ b/include/system/replay.h @@ -XXX,XX +XXX,XX @@ void replay_bh_schedule_event(QEMUBH *bh); void replay_bh_schedule_oneshot_event(AioContext *ctx, QEMUBHFunc *cb, void *opaque); /*! Adds input event to the queue */ -void replay_input_event(QemuConsole *src, InputEvent *evt); +void replay_input_event(QemuConsole *src, QemuInputEvent *evt); /*! Adds input sync event to the queue */ void replay_input_sync_event(void); /*! Adds block layer event to the queue */ diff --git a/include/ui/input.h b/include/ui/input.h index XXXXXXX..XXXXXXX 100644 --- a/include/ui/input.h +++ b/include/ui/input.h @@ -XXX,XX +XXX,XX @@ typedef struct QemuInputHandler QemuInputHandler; typedef struct QemuInputHandlerState QemuInputHandlerState; typedef void (*QemuInputHandlerEvent)(DeviceState *dev, QemuConsole *src, - InputEvent *evt); + QemuInputEvent *evt); typedef void (*QemuInputHandlerSync)(DeviceState *dev); struct QemuInputHandler { @@ -XXX,XX +XXX,XX @@ void qemu_input_handler_unregister(QemuInputHandlerState *s); void qemu_input_handler_bind(QemuInputHandlerState *s, const char *device_id, int head, Error **errp); -void qemu_input_event_send(QemuConsole *src, InputEvent *evt); -void qemu_input_event_send_impl(QemuConsole *src, InputEvent *evt); +void qemu_input_event_send(QemuConsole *src, QemuInputEvent *evt); +void qemu_input_event_send_impl(QemuConsole *src, QemuInputEvent *evt); void qemu_input_event_sync(void); void qemu_input_event_sync_impl(void); diff --git a/replay/replay-internal.h b/replay/replay-internal.h index XXXXXXX..XXXXXXX 100644 --- a/replay/replay-internal.h +++ b/replay/replay-internal.h @@ -XXX,XX +XXX,XX @@ void replay_add_event(ReplayAsyncEventKind event_kind, void *opaque, /* Input events */ /*! Saves input event to the log */ -void replay_save_input_event(InputEvent *evt); +void replay_save_input_event(QemuInputEvent *evt); /*! Reads input event from the log */ -InputEvent *replay_read_input_event(void); +QemuInputEvent *replay_read_input_event(void); /*! Adds input event to the queue */ -void replay_add_input_event(struct InputEvent *event); +void replay_add_input_event(QemuInputEvent *event); /*! Adds input sync event to the queue */ void replay_add_input_sync_event(void); diff --git a/chardev/msmouse.c b/chardev/msmouse.c index XXXXXXX..XXXXXXX 100644 --- a/chardev/msmouse.c +++ b/chardev/msmouse.c @@ -XXX,XX +XXX,XX @@ static void msmouse_queue_event(MouseChardev *mouse) } static void msmouse_input_event(DeviceState *dev, QemuConsole *src, - InputEvent *evt) + QemuInputEvent *evt) { MouseChardev *mouse = MOUSE_CHARDEV(dev); InputMoveEvent *move; diff --git a/chardev/wctablet.c b/chardev/wctablet.c index XXXXXXX..XXXXXXX 100644 --- a/chardev/wctablet.c +++ b/chardev/wctablet.c @@ -XXX,XX +XXX,XX @@ static void wctablet_queue_event(TabletChardev *tablet) } static void wctablet_input_event(DeviceState *dev, QemuConsole *src, - InputEvent *evt) + QemuInputEvent *evt) { TabletChardev *tablet = (TabletChardev *)dev; InputMoveEvent *move; diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c index XXXXXXX..XXXXXXX 100644 --- a/hw/arm/musicpal.c +++ b/hw/arm/musicpal.c @@ -XXX,XX +XXX,XX @@ struct musicpal_key_state { }; static void musicpal_key_event(DeviceState *dev, QemuConsole *src, - InputEvent *evt) + QemuInputEvent *evt) { musicpal_key_state *s = MUSICPAL_KEY(dev); InputKeyEvent *key = evt->u.key.data; diff --git a/hw/char/escc.c b/hw/char/escc.c index XXXXXXX..XXXXXXX 100644 --- a/hw/char/escc.c +++ b/hw/char/escc.c @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_escc = { }; static void sunkbd_handle_event(DeviceState *dev, QemuConsole *src, - InputEvent *evt) + QemuInputEvent *evt) { ESCCChannelState *s = (ESCCChannelState *)dev; int qcode, keycode; @@ -XXX,XX +XXX,XX @@ static void handle_kbd_command(ESCCChannelState *s, int val) } static void sunmouse_handle_event(DeviceState *dev, QemuConsole *src, - InputEvent *evt) + QemuInputEvent *evt) { ESCCChannelState *s = (ESCCChannelState *)dev; InputMoveEvent *move; diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index XXXXXXX..XXXXXXX 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -XXX,XX +XXX,XX @@ static int xenfb_send_position(struct XenInput *xenfb, * already has code for dealing with this... */ static void xenfb_key_event(DeviceState *dev, QemuConsole *src, - InputEvent *evt) + QemuInputEvent *evt) { struct XenInput *xenfb = (struct XenInput *)dev; InputKeyEvent *key = evt->u.key.data; @@ -XXX,XX +XXX,XX @@ static void xenfb_key_event(DeviceState *dev, QemuConsole *src, * the button state. */ static void xenfb_mouse_event(DeviceState *dev, QemuConsole *src, - InputEvent *evt) + QemuInputEvent *evt) { struct XenInput *xenfb = (struct XenInput *)dev; InputBtnEvent *btn; diff --git a/hw/input/adb-kbd.c b/hw/input/adb-kbd.c index XXXXXXX..XXXXXXX 100644 --- a/hw/input/adb-kbd.c +++ b/hw/input/adb-kbd.c @@ -XXX,XX +XXX,XX @@ static bool adb_kbd_has_data(ADBDevice *d) /* This is where keyboard events enter this file */ static void adb_keyboard_event(DeviceState *dev, QemuConsole *src, - InputEvent *evt) + QemuInputEvent *evt) { KBDState *s = (KBDState *)dev; int qcode, keycode; diff --git a/hw/input/adb-mouse.c b/hw/input/adb-mouse.c index XXXXXXX..XXXXXXX 100644 --- a/hw/input/adb-mouse.c +++ b/hw/input/adb-mouse.c @@ -XXX,XX +XXX,XX @@ struct ADBMouseClass { #define ADB_MOUSE_BUTTON_RIGHT 0x02 static void adb_mouse_handle_event(DeviceState *dev, QemuConsole *src, - InputEvent *evt) + QemuInputEvent *evt) { MouseState *s = (MouseState *)dev; InputMoveEvent *move; diff --git a/hw/input/hid.c b/hw/input/hid.c index XXXXXXX..XXXXXXX 100644 --- a/hw/input/hid.c +++ b/hw/input/hid.c @@ -XXX,XX +XXX,XX @@ void hid_set_next_idle(HIDState *hs) } static void hid_pointer_event(DeviceState *dev, QemuConsole *src, - InputEvent *evt) + QemuInputEvent *evt) { static const int bmap[INPUT_BUTTON__MAX] = { [INPUT_BUTTON_LEFT] = 0x01, @@ -XXX,XX +XXX,XX @@ static void hid_pointer_sync(DeviceState *dev) } static void hid_keyboard_event(DeviceState *dev, QemuConsole *src, - InputEvent *evt) + QemuInputEvent *evt) { HIDState *hs = (HIDState *)dev; int scancodes[3], i, count; diff --git a/hw/input/ps2.c b/hw/input/ps2.c index XXXXXXX..XXXXXXX 100644 --- a/hw/input/ps2.c +++ b/hw/input/ps2.c @@ -XXX,XX +XXX,XX @@ static void ps2_put_keycode(void *opaque, int keycode) } static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src, - InputEvent *evt) + QemuInputEvent *evt) { PS2KbdState *s = (PS2KbdState *)dev; InputKeyEvent *key = evt->u.key.data; @@ -XXX,XX +XXX,XX @@ static int ps2_mouse_send_packet(PS2MouseState *s) } static void ps2_mouse_event(DeviceState *dev, QemuConsole *src, - InputEvent *evt) + QemuInputEvent *evt) { static const int bmap[INPUT_BUTTON__MAX] = { [INPUT_BUTTON_LEFT] = PS2_MOUSE_BUTTON_LEFT, diff --git a/hw/input/stellaris_gamepad.c b/hw/input/stellaris_gamepad.c index XXXXXXX..XXXXXXX 100644 --- a/hw/input/stellaris_gamepad.c +++ b/hw/input/stellaris_gamepad.c @@ -XXX,XX +XXX,XX @@ #include "ui/console.h" static void stellaris_gamepad_event(DeviceState *dev, QemuConsole *src, - InputEvent *evt) + QemuInputEvent *evt) { StellarisGamepad *s = STELLARIS_GAMEPAD(dev); InputKeyEvent *key = evt->u.key.data; diff --git a/hw/input/virtio-input-hid.c b/hw/input/virtio-input-hid.c index XXXXXXX..XXXXXXX 100644 --- a/hw/input/virtio-input-hid.c +++ b/hw/input/virtio-input-hid.c @@ -XXX,XX +XXX,XX @@ static void virtio_input_extend_config(VirtIOInput *vinput, } static void virtio_input_handle_event(DeviceState *dev, QemuConsole *src, - InputEvent *evt) + QemuInputEvent *evt) { VirtIOInput *vinput = VIRTIO_INPUT(dev); virtio_input_event event; diff --git a/hw/m68k/next-kbd.c b/hw/m68k/next-kbd.c index XXXXXXX..XXXXXXX 100644 --- a/hw/m68k/next-kbd.c +++ b/hw/m68k/next-kbd.c @@ -XXX,XX +XXX,XX @@ static void nextkbd_put_keycode(NextKBDState *s, int keycode) /* s->update_irq(s->update_arg, 1); */ } -static void nextkbd_event(DeviceState *dev, QemuConsole *src, InputEvent *evt) +static void nextkbd_event(DeviceState *dev, QemuConsole *src, + QemuInputEvent *evt) { NextKBDState *s = NEXTKBD(dev); int qcode, keycode; diff --git a/replay/replay-events.c b/replay/replay-events.c index XXXXXXX..XXXXXXX 100644 --- a/replay/replay-events.c +++ b/replay/replay-events.c @@ -XXX,XX +XXX,XX @@ static void replay_run_event(Event *event) ((QEMUBHFunc *)event->opaque)(event->opaque2); break; case REPLAY_ASYNC_EVENT_INPUT: - qemu_input_event_send_impl(NULL, (InputEvent *)event->opaque); + qemu_input_event_send_impl(NULL, (QemuInputEvent *)event->opaque); qapi_free_InputEvent((InputEvent *)event->opaque); break; case REPLAY_ASYNC_EVENT_INPUT_SYNC: @@ -XXX,XX +XXX,XX @@ void replay_bh_schedule_oneshot_event(AioContext *ctx, } } -void replay_add_input_event(struct InputEvent *event) +void replay_add_input_event(QemuInputEvent *event) { replay_add_event(REPLAY_ASYNC_EVENT_INPUT, event, NULL, 0); } diff --git a/replay/replay-input.c b/replay/replay-input.c index XXXXXXX..XXXXXXX 100644 --- a/replay/replay-input.c +++ b/replay/replay-input.c @@ -XXX,XX +XXX,XX @@ #include "qapi/clone-visitor.h" #include "qapi/qapi-visit-ui.h" -void replay_save_input_event(InputEvent *evt) +void replay_save_input_event(QemuInputEvent *evt) { InputKeyEvent *key; InputBtnEvent *btn; @@ -XXX,XX +XXX,XX @@ void replay_save_input_event(InputEvent *evt) } } -InputEvent *replay_read_input_event(void) +QemuInputEvent *replay_read_input_event(void) { - InputEvent evt; + QemuInputEvent evt; KeyValue keyValue; InputKeyEvent key; key.key = &keyValue; @@ -XXX,XX +XXX,XX @@ InputEvent *replay_read_input_event(void) return QAPI_CLONE(InputEvent, &evt); } -void replay_input_event(QemuConsole *src, InputEvent *evt) +void replay_input_event(QemuConsole *src, QemuInputEvent *evt) { if (replay_mode == REPLAY_MODE_PLAY) { /* Nothing */ diff --git a/replay/stubs-system.c b/replay/stubs-system.c index XXXXXXX..XXXXXXX 100644 --- a/replay/stubs-system.c +++ b/replay/stubs-system.c @@ -XXX,XX +XXX,XX @@ #include "system/replay.h" #include "ui/input.h" -void replay_input_event(QemuConsole *src, InputEvent *evt) +void replay_input_event(QemuConsole *src, QemuInputEvent *evt) { qemu_input_event_send_impl(src, evt); } diff --git a/ui/input-legacy.c b/ui/input-legacy.c index XXXXXXX..XXXXXXX 100644 --- a/ui/input-legacy.c +++ b/ui/input-legacy.c @@ -XXX,XX +XXX,XX @@ void qmp_send_key(KeyValueList *keys, bool has_hold_time, int64_t hold_time, } static void legacy_mouse_event(DeviceState *dev, QemuConsole *src, - InputEvent *evt) + QemuInputEvent *evt) { static const int bmap[INPUT_BUTTON__MAX] = { [INPUT_BUTTON_LEFT] = MOUSE_EVENT_LBUTTON, diff --git a/ui/input.c b/ui/input.c index XXXXXXX..XXXXXXX 100644 --- a/ui/input.c +++ b/ui/input.c @@ -XXX,XX +XXX,XX @@ struct QemuInputEventQueue { QEMUTimer *timer; uint32_t delay_ms; QemuConsole *src; - InputEvent *evt; + QemuInputEvent *evt; QTAILQ_ENTRY(QemuInputEventQueue) node; }; @@ -XXX,XX +XXX,XX @@ void qmp_input_send_event(const char *device, qemu_input_event_sync(); } -static void qemu_input_event_trace(QemuConsole *src, InputEvent *evt) +static void qemu_input_event_trace(QemuConsole *src, QemuInputEvent *evt) { const char *name; int qcode, idx = -1; @@ -XXX,XX +XXX,XX @@ static void qemu_input_queue_delay(QemuInputEventQueueHead *queue, } static void qemu_input_queue_event(QemuInputEventQueueHead *queue, - QemuConsole *src, InputEvent *evt) + QemuConsole *src, QemuInputEvent *evt) { QemuInputEventQueue *item = g_new0(QemuInputEventQueue, 1); @@ -XXX,XX +XXX,XX @@ static void qemu_input_queue_sync(QemuInputEventQueueHead *queue) queue_count++; } -void qemu_input_event_send_impl(QemuConsole *src, InputEvent *evt) +void qemu_input_event_send_impl(QemuConsole *src, QemuInputEvent *evt) { QemuInputHandlerState *s; @@ -XXX,XX +XXX,XX @@ void qemu_input_event_send_impl(QemuConsole *src, InputEvent *evt) s->events++; } -void qemu_input_event_send(QemuConsole *src, InputEvent *evt) +void qemu_input_event_send(QemuConsole *src, QemuInputEvent *evt) { /* Expect all parts of QEMU to send events with QCodes exclusively. * Key numbers are only supported as end-user input via QMP */ @@ -XXX,XX +XXX,XX @@ void qemu_input_event_sync(void) replay_input_sync_event(); } -static InputEvent *qemu_input_event_new_key(KeyValue *key, bool down) +static QemuInputEvent *qemu_input_event_new_key(KeyValue *key, bool down) { - InputEvent *evt = g_new0(InputEvent, 1); + QemuInputEvent *evt = g_new0(QemuInputEvent, 1); evt->u.key.data = g_new0(InputKeyEvent, 1); evt->type = INPUT_EVENT_KIND_KEY; evt->u.key.data->key = key; @@ -XXX,XX +XXX,XX @@ static InputEvent *qemu_input_event_new_key(KeyValue *key, bool down) void qemu_input_event_send_key(QemuConsole *src, KeyValue *key, bool down) { - InputEvent *evt; + QemuInputEvent *evt; evt = qemu_input_event_new_key(key, down); if (QTAILQ_EMPTY(&kbd_queue)) { qemu_input_event_send(src, evt); @@ -XXX,XX +XXX,XX @@ void qemu_input_queue_btn(QemuConsole *src, InputButton btn, bool down) .button = btn, .down = down, }; - InputEvent evt = { + QemuInputEvent evt = { .type = INPUT_EVENT_KIND_BTN, .u.btn.data = &bevt, }; @@ -XXX,XX +XXX,XX @@ void qemu_input_queue_rel(QemuConsole *src, InputAxis axis, int value) .axis = axis, .value = value, }; - InputEvent evt = { + QemuInputEvent evt = { .type = INPUT_EVENT_KIND_REL, .u.rel.data = &move, }; @@ -XXX,XX +XXX,XX @@ void qemu_input_queue_abs(QemuConsole *src, InputAxis axis, int value, INPUT_EVENT_ABS_MIN, INPUT_EVENT_ABS_MAX), }; - InputEvent evt = { + QemuInputEvent evt = { .type = INPUT_EVENT_KIND_ABS, .u.abs.data = &move, }; @@ -XXX,XX +XXX,XX @@ void qemu_input_queue_mtt(QemuConsole *src, InputMultiTouchType type, .slot = slot, .tracking_id = tracking_id, }; - InputEvent evt = { + QemuInputEvent evt = { .type = INPUT_EVENT_KIND_MTT, .u.mtt.data = &mtt, }; @@ -XXX,XX +XXX,XX @@ void qemu_input_queue_mtt_abs(QemuConsole *src, InputAxis axis, int value, INPUT_EVENT_ABS_MIN, INPUT_EVENT_ABS_MAX), }; - InputEvent evt = { + QemuInputEvent evt = { .type = INPUT_EVENT_KIND_MTT, .u.mtt.data = &mtt, }; diff --git a/ui/vdagent.c b/ui/vdagent.c index XXXXXXX..XXXXXXX 100644 --- a/ui/vdagent.c +++ b/ui/vdagent.c @@ -XXX,XX +XXX,XX @@ static void vdagent_send_mouse(VDAgentChardev *vd) } static void vdagent_pointer_event(DeviceState *dev, QemuConsole *src, - InputEvent *evt) + QemuInputEvent *evt) { static const int bmap[INPUT_BUTTON__MAX] = { [INPUT_BUTTON_LEFT] = VD_AGENT_LBUTTON_MASK, -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> QAPI represents union members with wrapper structs and pointer indirections. They are useful at the QMP boundary, but unnecessary for QEMU's internal input events and make handlers more verbose. Define QemuInputEvent as a plain internal tagged union and convert input handlers, queues, and replay code to access payloads directly. 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-2-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- include/qemu/typedefs.h | 2 +- include/ui/input.h | 16 ++++ chardev/msmouse.c | 10 +- chardev/wctablet.c | 8 +- hw/arm/musicpal.c | 11 +-- hw/char/escc.c | 32 +++---- hw/display/xenfb.c | 32 +++---- hw/input/adb-kbd.c | 4 +- hw/input/adb-mouse.c | 20 ++-- hw/input/hid.c | 36 +++---- hw/input/ps2.c | 67 ++++++------- hw/input/stellaris_gamepad.c | 9 +- hw/input/virtio-input-hid.c | 53 +++++------ hw/m68k/next-kbd.c | 9 +- replay/replay-events.c | 2 +- replay/replay-input.c | 101 ++++++++------------ ui/input-legacy.c | 23 ++--- ui/input.c | 177 ++++++++++++++++++++--------------- ui/vdagent.c | 18 ++-- 19 files changed, 299 insertions(+), 331 deletions(-) diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index XXXXXXX..XXXXXXX 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -XXX,XX +XXX,XX @@ typedef struct QBool QBool; typedef struct QDict QDict; typedef struct QEMUBH QEMUBH; typedef struct QemuConsole QemuConsole; -typedef struct InputEvent QemuInputEvent; +typedef struct QemuInputEvent QemuInputEvent; typedef struct QEMUCursor QEMUCursor; typedef struct QEMUFile QEMUFile; typedef struct QemuMutex QemuMutex; diff --git a/include/ui/input.h b/include/ui/input.h index XXXXXXX..XXXXXXX 100644 --- a/include/ui/input.h +++ b/include/ui/input.h @@ -XXX,XX +XXX,XX @@ typedef struct QemuInputHandler QemuInputHandler; typedef struct QemuInputHandlerState QemuInputHandlerState; +typedef struct QemuInputKeyEvent { + KeyValue key; + bool down; +} QemuInputKeyEvent; + +typedef struct QemuInputEvent { + InputEventKind type; + union { + QemuInputKeyEvent key; + InputBtnEvent btn; + InputMoveEvent rel; + InputMoveEvent abs; + InputMultiTouchEvent mtt; + }; +} QemuInputEvent; + typedef void (*QemuInputHandlerEvent)(DeviceState *dev, QemuConsole *src, QemuInputEvent *evt); typedef void (*QemuInputHandlerSync)(DeviceState *dev); diff --git a/chardev/msmouse.c b/chardev/msmouse.c index XXXXXXX..XXXXXXX 100644 --- a/chardev/msmouse.c +++ b/chardev/msmouse.c @@ -XXX,XX +XXX,XX @@ static void msmouse_input_event(DeviceState *dev, QemuConsole *src, QemuInputEvent *evt) { MouseChardev *mouse = MOUSE_CHARDEV(dev); - InputMoveEvent *move; - InputBtnEvent *btn; /* Ignore events if serial mouse powered down. */ if (!MSMOUSE_PWR(mouse->tiocm)) { @@ -XXX,XX +XXX,XX @@ static void msmouse_input_event(DeviceState *dev, QemuConsole *src, switch (evt->type) { case INPUT_EVENT_KIND_REL: - move = evt->u.rel.data; - mouse->axis[move->axis] += move->value; + mouse->axis[evt->rel.axis] += evt->rel.value; break; case INPUT_EVENT_KIND_BTN: - btn = evt->u.btn.data; - mouse->btns[btn->button] = btn->down; - mouse->btnc[btn->button] = true; + mouse->btns[evt->btn.button] = evt->btn.down; + mouse->btnc[evt->btn.button] = true; break; default: diff --git a/chardev/wctablet.c b/chardev/wctablet.c index XXXXXXX..XXXXXXX 100644 --- a/chardev/wctablet.c +++ b/chardev/wctablet.c @@ -XXX,XX +XXX,XX @@ static void wctablet_input_event(DeviceState *dev, QemuConsole *src, QemuInputEvent *evt) { TabletChardev *tablet = (TabletChardev *)dev; - InputMoveEvent *move; - InputBtnEvent *btn; switch (evt->type) { case INPUT_EVENT_KIND_ABS: - move = evt->u.abs.data; - tablet->axis[move->axis] = move->value; + tablet->axis[evt->abs.axis] = evt->abs.value; break; case INPUT_EVENT_KIND_BTN: - btn = evt->u.btn.data; - tablet->btns[btn->button] = btn->down; + tablet->btns[evt->btn.button] = evt->btn.down; break; default: diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c index XXXXXXX..XXXXXXX 100644 --- a/hw/arm/musicpal.c +++ b/hw/arm/musicpal.c @@ -XXX,XX +XXX,XX @@ static void musicpal_key_event(DeviceState *dev, QemuConsole *src, QemuInputEvent *evt) { musicpal_key_state *s = MUSICPAL_KEY(dev); - InputKeyEvent *key = evt->u.key.data; - int qcode = qemu_input_key_value_to_qcode(key->key); + int qcode = qemu_input_key_value_to_qcode(&evt->key.key); uint32_t event = 0; int i; @@ -XXX,XX +XXX,XX @@ static void musicpal_key_event(DeviceState *dev, QemuConsole *src, * but do not repeat already-pressed buttons for the other key inputs. */ if (!(event & (MP_KEY_WHEEL_NAV | MP_KEY_WHEEL_VOL))) { - if (key->down && (s->pressed_keys & event)) { + if (evt->key.down && (s->pressed_keys & event)) { event = 0; } } if (event) { /* Raise GPIO pin first if repeating a key */ - if (key->down && (s->pressed_keys & event)) { + if (evt->key.down && (s->pressed_keys & event)) { for (i = 0; i <= 7; i++) { if (event & (1 << i)) { qemu_set_irq(s->out[i], 1); @@ -XXX,XX +XXX,XX @@ static void musicpal_key_event(DeviceState *dev, QemuConsole *src, } for (i = 0; i <= 7; i++) { if (event & (1 << i)) { - qemu_set_irq(s->out[i], !key->down); + qemu_set_irq(s->out[i], !evt->key.down); } } - if (key->down) { + if (evt->key.down) { s->pressed_keys |= event; } else { s->pressed_keys &= ~event; diff --git a/hw/char/escc.c b/hw/char/escc.c index XXXXXXX..XXXXXXX 100644 --- a/hw/char/escc.c +++ b/hw/char/escc.c @@ -XXX,XX +XXX,XX @@ static void sunkbd_handle_event(DeviceState *dev, QemuConsole *src, { ESCCChannelState *s = (ESCCChannelState *)dev; int qcode, keycode; - InputKeyEvent *key; assert(evt->type == INPUT_EVENT_KIND_KEY); - key = evt->u.key.data; - qcode = qemu_input_key_value_to_qcode(key->key); + qcode = qemu_input_key_value_to_qcode(&evt->key.key); trace_escc_sunkbd_event_in(qcode, QKeyCode_str(qcode), - key->down); + evt->key.down); if (qcode == Q_KEY_CODE_CAPS_LOCK) { - if (key->down) { + if (evt->key.down) { s->caps_lock_mode ^= 1; if (s->caps_lock_mode == 2) { return; /* Drop second press */ @@ -XXX,XX +XXX,XX @@ static void sunkbd_handle_event(DeviceState *dev, QemuConsole *src, } if (qcode == Q_KEY_CODE_NUM_LOCK) { - if (key->down) { + if (evt->key.down) { s->num_lock_mode ^= 1; if (s->num_lock_mode == 2) { return; /* Drop second press */ @@ -XXX,XX +XXX,XX @@ static void sunkbd_handle_event(DeviceState *dev, QemuConsole *src, } keycode = qemu_input_map_qcode_to_sun[qcode]; - if (!key->down) { + if (!evt->key.down) { keycode |= 0x80; } trace_escc_sunkbd_event_out(keycode); @@ -XXX,XX +XXX,XX @@ static void sunmouse_handle_event(DeviceState *dev, QemuConsole *src, QemuInputEvent *evt) { ESCCChannelState *s = (ESCCChannelState *)dev; - InputMoveEvent *move; - InputBtnEvent *btn; static const int bmap[INPUT_BUTTON__MAX] = { [INPUT_BUTTON_LEFT] = 0x4, [INPUT_BUTTON_MIDDLE] = 0x2, @@ -XXX,XX +XXX,XX @@ static void sunmouse_handle_event(DeviceState *dev, QemuConsole *src, switch (evt->type) { case INPUT_EVENT_KIND_REL: - move = evt->u.rel.data; - if (move->axis == INPUT_AXIS_X) { - s->sunmouse_dx += move->value; - } else if (move->axis == INPUT_AXIS_Y) { - s->sunmouse_dy -= move->value; + if (evt->rel.axis == INPUT_AXIS_X) { + s->sunmouse_dx += evt->rel.value; + } else if (evt->rel.axis == INPUT_AXIS_Y) { + s->sunmouse_dy -= evt->rel.value; } break; case INPUT_EVENT_KIND_BTN: - btn = evt->u.btn.data; - if (bmap[btn->button]) { - if (btn->down) { - s->sunmouse_buttons |= bmap[btn->button]; + if (bmap[evt->btn.button]) { + if (evt->btn.down) { + s->sunmouse_buttons |= bmap[evt->btn.button]; } else { - s->sunmouse_buttons &= ~bmap[btn->button]; + s->sunmouse_buttons &= ~bmap[evt->btn.button]; } /* Indicate we have a supported button event */ s->sunmouse_buttons |= 0x80; diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index XXXXXXX..XXXXXXX 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -XXX,XX +XXX,XX @@ static void xenfb_key_event(DeviceState *dev, QemuConsole *src, QemuInputEvent *evt) { struct XenInput *xenfb = (struct XenInput *)dev; - InputKeyEvent *key = evt->u.key.data; - int qcode = qemu_input_key_value_to_qcode(key->key); + int qcode = qemu_input_key_value_to_qcode(&evt->key.key); int lnx; if (qcode < qemu_input_map_qcode_to_linux_len) { lnx = qemu_input_map_qcode_to_linux[qcode]; if (lnx) { - trace_xenfb_key_event(xenfb, lnx, key->down); - xenfb_send_key(xenfb, key->down, lnx); + trace_xenfb_key_event(xenfb, lnx, evt->key.down); + xenfb_send_key(xenfb, evt->key.down, lnx); } } } @@ -XXX,XX +XXX,XX @@ static void xenfb_mouse_event(DeviceState *dev, QemuConsole *src, QemuInputEvent *evt) { struct XenInput *xenfb = (struct XenInput *)dev; - InputBtnEvent *btn; - InputMoveEvent *move; QemuConsole *con; DisplaySurface *surface; int scale; switch (evt->type) { case INPUT_EVENT_KIND_BTN: - btn = evt->u.btn.data; - switch (btn->button) { + switch (evt->btn.button) { case INPUT_BUTTON_LEFT: - xenfb_send_key(xenfb, btn->down, BTN_LEFT); + xenfb_send_key(xenfb, evt->btn.down, BTN_LEFT); break; case INPUT_BUTTON_RIGHT: - xenfb_send_key(xenfb, btn->down, BTN_LEFT + 1); + xenfb_send_key(xenfb, evt->btn.down, BTN_LEFT + 1); break; case INPUT_BUTTON_MIDDLE: - xenfb_send_key(xenfb, btn->down, BTN_LEFT + 2); + xenfb_send_key(xenfb, evt->btn.down, BTN_LEFT + 2); break; case INPUT_BUTTON_WHEEL_UP: - if (btn->down) { + if (evt->btn.down) { xenfb->wheel--; } break; case INPUT_BUTTON_WHEEL_DOWN: - if (btn->down) { + if (evt->btn.down) { xenfb->wheel++; } break; @@ -XXX,XX +XXX,XX @@ static void xenfb_mouse_event(DeviceState *dev, QemuConsole *src, break; case INPUT_EVENT_KIND_ABS: - move = evt->u.abs.data; if (xenfb->raw_pointer_wanted) { - xenfb->axis[move->axis] = move->value; + xenfb->axis[evt->abs.axis] = evt->abs.value; } else { con = qemu_console_lookup_by_index(0); if (!con) { @@ -XXX,XX +XXX,XX @@ static void xenfb_mouse_event(DeviceState *dev, QemuConsole *src, return; } surface = qemu_console_surface(con); - switch (move->axis) { + switch (evt->abs.axis) { case INPUT_AXIS_X: scale = surface_width(surface) - 1; break; @@ -XXX,XX +XXX,XX @@ static void xenfb_mouse_event(DeviceState *dev, QemuConsole *src, default: g_assert_not_reached(); } - xenfb->axis[move->axis] = move->value * scale / 0x7fff; + xenfb->axis[evt->abs.axis] = evt->abs.value * scale / 0x7fff; } break; case INPUT_EVENT_KIND_REL: - move = evt->u.rel.data; - xenfb->axis[move->axis] += move->value; + xenfb->axis[evt->rel.axis] += evt->rel.value; break; default: diff --git a/hw/input/adb-kbd.c b/hw/input/adb-kbd.c index XXXXXXX..XXXXXXX 100644 --- a/hw/input/adb-kbd.c +++ b/hw/input/adb-kbd.c @@ -XXX,XX +XXX,XX @@ static void adb_keyboard_event(DeviceState *dev, QemuConsole *src, KBDState *s = (KBDState *)dev; int qcode, keycode; - qcode = qemu_input_key_value_to_qcode(evt->u.key.data->key); + qcode = qemu_input_key_value_to_qcode(&evt->key.key); if (qcode >= ARRAY_SIZE(qcode_to_adb_keycode)) { return; } @@ -XXX,XX +XXX,XX @@ static void adb_keyboard_event(DeviceState *dev, QemuConsole *src, trace_adb_device_kbd_no_key(); return; } - if (evt->u.key.data->down == false) { /* if key release event */ + if (evt->key.down == false) { /* if key release event */ keycode = keycode | 0x80; /* create keyboard break code */ } diff --git a/hw/input/adb-mouse.c b/hw/input/adb-mouse.c index XXXXXXX..XXXXXXX 100644 --- a/hw/input/adb-mouse.c +++ b/hw/input/adb-mouse.c @@ -XXX,XX +XXX,XX @@ static void adb_mouse_handle_event(DeviceState *dev, QemuConsole *src, QemuInputEvent *evt) { MouseState *s = (MouseState *)dev; - InputMoveEvent *move; - InputBtnEvent *btn; static const int bmap[INPUT_BUTTON__MAX] = { [INPUT_BUTTON_LEFT] = ADB_MOUSE_BUTTON_LEFT, [INPUT_BUTTON_RIGHT] = ADB_MOUSE_BUTTON_RIGHT, @@ -XXX,XX +XXX,XX @@ static void adb_mouse_handle_event(DeviceState *dev, QemuConsole *src, switch (evt->type) { case INPUT_EVENT_KIND_REL: - move = evt->u.rel.data; - if (move->axis == INPUT_AXIS_X) { - s->dx += move->value; - } else if (move->axis == INPUT_AXIS_Y) { - s->dy += move->value; + if (evt->rel.axis == INPUT_AXIS_X) { + s->dx += evt->rel.value; + } else if (evt->rel.axis == INPUT_AXIS_Y) { + s->dy += evt->rel.value; } break; case INPUT_EVENT_KIND_BTN: - btn = evt->u.btn.data; - if (bmap[btn->button]) { - if (btn->down) { - s->buttons_state |= bmap[btn->button]; + if (bmap[evt->btn.button]) { + if (evt->btn.down) { + s->buttons_state |= bmap[evt->btn.button]; } else { - s->buttons_state &= ~bmap[btn->button]; + s->buttons_state &= ~bmap[evt->btn.button]; } } break; diff --git a/hw/input/hid.c b/hw/input/hid.c index XXXXXXX..XXXXXXX 100644 --- a/hw/input/hid.c +++ b/hw/input/hid.c @@ -XXX,XX +XXX,XX @@ static void hid_pointer_event(DeviceState *dev, QemuConsole *src, }; HIDState *hs = (HIDState *)dev; HIDPointerEvent *e; - InputMoveEvent *move; - InputBtnEvent *btn; assert(hs->n < QUEUE_LENGTH); e = &hs->ptr.queue[(hs->head + hs->n) & QUEUE_MASK]; switch (evt->type) { case INPUT_EVENT_KIND_REL: - move = evt->u.rel.data; - if (move->axis == INPUT_AXIS_X) { - e->xdx += move->value; - } else if (move->axis == INPUT_AXIS_Y) { - e->ydy += move->value; + if (evt->rel.axis == INPUT_AXIS_X) { + e->xdx += evt->rel.value; + } else if (evt->rel.axis == INPUT_AXIS_Y) { + e->ydy += evt->rel.value; } break; case INPUT_EVENT_KIND_ABS: - move = evt->u.abs.data; - if (move->axis == INPUT_AXIS_X) { - e->xdx = move->value; - } else if (move->axis == INPUT_AXIS_Y) { - e->ydy = move->value; + if (evt->abs.axis == INPUT_AXIS_X) { + e->xdx = evt->abs.value; + } else if (evt->abs.axis == INPUT_AXIS_Y) { + e->ydy = evt->abs.value; } break; case INPUT_EVENT_KIND_BTN: - btn = evt->u.btn.data; - if (btn->down) { - e->buttons_state |= bmap[btn->button]; - if (btn->button == INPUT_BUTTON_WHEEL_UP) { + if (evt->btn.down) { + e->buttons_state |= bmap[evt->btn.button]; + if (evt->btn.button == INPUT_BUTTON_WHEEL_UP) { e->dz--; - } else if (btn->button == INPUT_BUTTON_WHEEL_DOWN) { + } else if (evt->btn.button == INPUT_BUTTON_WHEEL_DOWN) { e->dz++; } } else { - e->buttons_state &= ~bmap[btn->button]; + e->buttons_state &= ~bmap[evt->btn.button]; } break; @@ -XXX,XX +XXX,XX @@ static void hid_keyboard_event(DeviceState *dev, QemuConsole *src, HIDState *hs = (HIDState *)dev; int scancodes[3], i, count; int slot; - InputKeyEvent *key = evt->u.key.data; - count = qemu_input_key_value_to_scancode(key->key, - key->down, + count = qemu_input_key_value_to_scancode(&evt->key.key, + evt->key.down, scancodes); if (hs->n + count > QUEUE_LENGTH) { trace_hid_kbd_queue_full(); diff --git a/hw/input/ps2.c b/hw/input/ps2.c index XXXXXXX..XXXXXXX 100644 --- a/hw/input/ps2.c +++ b/hw/input/ps2.c @@ -XXX,XX +XXX,XX @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src, QemuInputEvent *evt) { PS2KbdState *s = (PS2KbdState *)dev; - InputKeyEvent *key = evt->u.key.data; int qcode; uint16_t keycode = 0; int mod; @@ -XXX,XX +XXX,XX @@ 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_key_value_to_qcode(key->key); + qcode = qemu_input_key_value_to_qcode(&evt->key.key); mod = ps2_modifier_bit(qcode); - trace_ps2_keyboard_event(s, qcode, key->down, mod, + trace_ps2_keyboard_event(s, qcode, evt->key.down, mod, s->modifiers, s->scancode_set, s->translate); - if (key->down) { + if (evt->key.down) { s->modifiers |= mod; } else { s->modifiers &= ~mod; @@ -XXX,XX +XXX,XX @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src, if (s->scancode_set == 1) { if (qcode == Q_KEY_CODE_PAUSE) { if (s->modifiers & (MOD_CTRL_L | MOD_CTRL_R)) { - if (key->down) { + if (evt->key.down) { ps2_put_keycode(s, 0xe0); ps2_put_keycode(s, 0x46); ps2_put_keycode(s, 0xe0); ps2_put_keycode(s, 0xc6); } } else { - if (key->down) { + if (evt->key.down) { ps2_put_keycode(s, 0xe1); ps2_put_keycode(s, 0x1d); ps2_put_keycode(s, 0x45); @@ -XXX,XX +XXX,XX @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src, } } else if (qcode == Q_KEY_CODE_PRINT) { if (s->modifiers & MOD_ALT_L) { - if (key->down) { + if (evt->key.down) { ps2_put_keycode(s, 0xb8); ps2_put_keycode(s, 0x38); ps2_put_keycode(s, 0x54); @@ -XXX,XX +XXX,XX @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src, ps2_put_keycode(s, 0x38); } } else if (s->modifiers & MOD_ALT_R) { - if (key->down) { + if (evt->key.down) { ps2_put_keycode(s, 0xe0); ps2_put_keycode(s, 0xb8); ps2_put_keycode(s, 0xe0); @@ -XXX,XX +XXX,XX @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src, } } else if (s->modifiers & (MOD_SHIFT_L | MOD_CTRL_L | MOD_SHIFT_R | MOD_CTRL_R)) { - if (key->down) { + if (evt->key.down) { ps2_put_keycode(s, 0xe0); ps2_put_keycode(s, 0x37); } else { @@ -XXX,XX +XXX,XX @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src, ps2_put_keycode(s, 0xb7); } } else { - if (key->down) { + if (evt->key.down) { ps2_put_keycode(s, 0xe0); ps2_put_keycode(s, 0x2a); ps2_put_keycode(s, 0xe0); @@ -XXX,XX +XXX,XX @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src, } } } else if ((qcode == Q_KEY_CODE_LANG1 || qcode == Q_KEY_CODE_LANG2) - && !key->down) { + && !evt->key.down) { /* Ignore release for these keys */ } else { if (qcode < qemu_input_map_qcode_to_atset1_len) { @@ -XXX,XX +XXX,XX @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src, if (keycode & 0xff00) { ps2_put_keycode(s, keycode >> 8); } - if (!key->down) { + if (!evt->key.down) { keycode |= 0x80; } ps2_put_keycode(s, keycode & 0xff); @@ -XXX,XX +XXX,XX @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src, } else if (s->scancode_set == 2) { if (qcode == Q_KEY_CODE_PAUSE) { if (s->modifiers & (MOD_CTRL_L | MOD_CTRL_R)) { - if (key->down) { + if (evt->key.down) { ps2_put_keycode(s, 0xe0); ps2_put_keycode(s, 0x7e); ps2_put_keycode(s, 0xe0); @@ -XXX,XX +XXX,XX @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src, ps2_put_keycode(s, 0x7e); } } else { - if (key->down) { + if (evt->key.down) { ps2_put_keycode(s, 0xe1); ps2_put_keycode(s, 0x14); ps2_put_keycode(s, 0x77); @@ -XXX,XX +XXX,XX @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src, } } else if (qcode == Q_KEY_CODE_PRINT) { if (s->modifiers & MOD_ALT_L) { - if (key->down) { + if (evt->key.down) { ps2_put_keycode(s, 0xf0); ps2_put_keycode(s, 0x11); ps2_put_keycode(s, 0x11); @@ -XXX,XX +XXX,XX @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src, ps2_put_keycode(s, 0x11); } } else if (s->modifiers & MOD_ALT_R) { - if (key->down) { + if (evt->key.down) { ps2_put_keycode(s, 0xe0); ps2_put_keycode(s, 0xf0); ps2_put_keycode(s, 0x11); @@ -XXX,XX +XXX,XX @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src, } } else if (s->modifiers & (MOD_SHIFT_L | MOD_CTRL_L | MOD_SHIFT_R | MOD_CTRL_R)) { - if (key->down) { + if (evt->key.down) { ps2_put_keycode(s, 0xe0); ps2_put_keycode(s, 0x7c); } else { @@ -XXX,XX +XXX,XX @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src, ps2_put_keycode(s, 0x7c); } } else { - if (key->down) { + if (evt->key.down) { ps2_put_keycode(s, 0xe0); ps2_put_keycode(s, 0x12); ps2_put_keycode(s, 0xe0); @@ -XXX,XX +XXX,XX @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src, } } } else if ((qcode == Q_KEY_CODE_LANG1 || qcode == Q_KEY_CODE_LANG2) && - !key->down) { + !evt->key.down) { /* Ignore release for these keys */ } else { if (qcode < qemu_input_map_qcode_to_atset2_len) { @@ -XXX,XX +XXX,XX @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src, if (keycode & 0xff00) { ps2_put_keycode(s, keycode >> 8); } - if (!key->down) { + if (!evt->key.down) { ps2_put_keycode(s, 0xf0); } ps2_put_keycode(s, keycode & 0xff); @@ -XXX,XX +XXX,XX @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src, } if (keycode) { /* FIXME: break code should be configured on a key by key basis */ - if (!key->down) { + if (!evt->key.down) { ps2_put_keycode(s, 0xf0); } ps2_put_keycode(s, keycode); @@ -XXX,XX +XXX,XX @@ static void ps2_mouse_event(DeviceState *dev, QemuConsole *src, [INPUT_BUTTON_EXTRA] = PS2_MOUSE_BUTTON_EXTRA, }; PS2MouseState *s = (PS2MouseState *)dev; - InputMoveEvent *move; - InputBtnEvent *btn; /* check if deltas are recorded when disabled */ if (!(s->mouse_status & MOUSE_STATUS_ENABLED)) { @@ -XXX,XX +XXX,XX @@ static void ps2_mouse_event(DeviceState *dev, QemuConsole *src, switch (evt->type) { case INPUT_EVENT_KIND_REL: - move = evt->u.rel.data; - if (move->axis == INPUT_AXIS_X) { - s->mouse_dx += move->value; - } else if (move->axis == INPUT_AXIS_Y) { - s->mouse_dy -= move->value; + if (evt->rel.axis == INPUT_AXIS_X) { + s->mouse_dx += evt->rel.value; + } else if (evt->rel.axis == INPUT_AXIS_Y) { + s->mouse_dy -= evt->rel.value; } break; case INPUT_EVENT_KIND_BTN: - btn = evt->u.btn.data; - if (btn->down) { - s->mouse_buttons |= bmap[btn->button]; - if (btn->button == INPUT_BUTTON_WHEEL_UP) { + if (evt->btn.down) { + s->mouse_buttons |= bmap[evt->btn.button]; + if (evt->btn.button == INPUT_BUTTON_WHEEL_UP) { s->mouse_dz--; - } else if (btn->button == INPUT_BUTTON_WHEEL_DOWN) { + } else if (evt->btn.button == INPUT_BUTTON_WHEEL_DOWN) { s->mouse_dz++; } - if (btn->button == INPUT_BUTTON_WHEEL_RIGHT) { + if (evt->btn.button == INPUT_BUTTON_WHEEL_RIGHT) { s->mouse_dw--; - } else if (btn->button == INPUT_BUTTON_WHEEL_LEFT) { + } else if (evt->btn.button == INPUT_BUTTON_WHEEL_LEFT) { s->mouse_dw++; } } else { - s->mouse_buttons &= ~bmap[btn->button]; + s->mouse_buttons &= ~bmap[evt->btn.button]; } break; diff --git a/hw/input/stellaris_gamepad.c b/hw/input/stellaris_gamepad.c index XXXXXXX..XXXXXXX 100644 --- a/hw/input/stellaris_gamepad.c +++ b/hw/input/stellaris_gamepad.c @@ -XXX,XX +XXX,XX @@ static void stellaris_gamepad_event(DeviceState *dev, QemuConsole *src, QemuInputEvent *evt) { StellarisGamepad *s = STELLARIS_GAMEPAD(dev); - InputKeyEvent *key = evt->u.key.data; - int qcode = qemu_input_key_value_to_qcode(key->key); + int qcode = qemu_input_key_value_to_qcode(&evt->key.key); int i; for (i = 0; i < s->num_buttons; i++) { - if (s->keycodes[i] == qcode && s->pressed[i] != key->down) { - s->pressed[i] = key->down; - qemu_set_irq(s->irqs[i], key->down); + if (s->keycodes[i] == qcode && s->pressed[i] != evt->key.down) { + s->pressed[i] = evt->key.down; + qemu_set_irq(s->irqs[i], evt->key.down); } } } diff --git a/hw/input/virtio-input-hid.c b/hw/input/virtio-input-hid.c index XXXXXXX..XXXXXXX 100644 --- a/hw/input/virtio-input-hid.c +++ b/hw/input/virtio-input-hid.c @@ -XXX,XX +XXX,XX @@ static void virtio_input_handle_event(DeviceState *dev, QemuConsole *src, VirtIOInput *vinput = VIRTIO_INPUT(dev); virtio_input_event event; int qcode; - InputKeyEvent *key; - InputMoveEvent *move; - InputBtnEvent *btn; - InputMultiTouchEvent *mtt; switch (evt->type) { case INPUT_EVENT_KIND_KEY: - key = evt->u.key.data; - qcode = qemu_input_key_value_to_qcode(key->key); + qcode = qemu_input_key_value_to_qcode(&evt->key.key); if (qcode < qemu_input_map_qcode_to_linux_len && qemu_input_map_qcode_to_linux[qcode]) { event.type = cpu_to_le16(EV_KEY); event.code = cpu_to_le16(qemu_input_map_qcode_to_linux[qcode]); - event.value = cpu_to_le32(key->down ? 1 : 0); + event.value = cpu_to_le32(evt->key.down ? 1 : 0); virtio_input_send(vinput, &event); } else { - if (key->down) { + if (evt->key.down) { fprintf(stderr, "%s: unmapped key: %d [%s]\n", __func__, qcode, QKeyCode_str(qcode)); } } break; case INPUT_EVENT_KIND_BTN: - btn = evt->u.btn.data; - if ((btn->button == INPUT_BUTTON_WHEEL_UP || - btn->button == INPUT_BUTTON_WHEEL_DOWN) && - btn->down) { + if ((evt->btn.button == INPUT_BUTTON_WHEEL_UP || + evt->btn.button == INPUT_BUTTON_WHEEL_DOWN) && + evt->btn.down) { event.type = cpu_to_le16(EV_REL); event.code = cpu_to_le16(REL_WHEEL); - event.value = cpu_to_le32(btn->button == INPUT_BUTTON_WHEEL_UP + event.value = cpu_to_le32(evt->btn.button == INPUT_BUTTON_WHEEL_UP ? 1 : -1); virtio_input_send(vinput, &event); - } else if (keymap_button[btn->button]) { + } else if (keymap_button[evt->btn.button]) { event.type = cpu_to_le16(EV_KEY); - event.code = cpu_to_le16(keymap_button[btn->button]); - event.value = cpu_to_le32(btn->down ? 1 : 0); + event.code = cpu_to_le16(keymap_button[evt->btn.button]); + event.value = cpu_to_le32(evt->btn.down ? 1 : 0); virtio_input_send(vinput, &event); } else { - if (btn->down) { + if (evt->btn.down) { fprintf(stderr, "%s: unmapped button: %d [%s]\n", __func__, - btn->button, - InputButton_str(btn->button)); + evt->btn.button, + InputButton_str(evt->btn.button)); } } break; case INPUT_EVENT_KIND_REL: - move = evt->u.rel.data; event.type = cpu_to_le16(EV_REL); - event.code = cpu_to_le16(axismap_rel[move->axis]); - event.value = cpu_to_le32(move->value); + event.code = cpu_to_le16(axismap_rel[evt->rel.axis]); + event.value = cpu_to_le32(evt->rel.value); virtio_input_send(vinput, &event); break; case INPUT_EVENT_KIND_ABS: - move = evt->u.abs.data; event.type = cpu_to_le16(EV_ABS); - event.code = cpu_to_le16(axismap_abs[move->axis]); - event.value = cpu_to_le32(move->value); + event.code = cpu_to_le16(axismap_abs[evt->abs.axis]); + event.value = cpu_to_le32(evt->abs.value); virtio_input_send(vinput, &event); break; case INPUT_EVENT_KIND_MTT: - mtt = evt->u.mtt.data; - if (mtt->type == INPUT_MULTI_TOUCH_TYPE_DATA) { + if (evt->mtt.type == INPUT_MULTI_TOUCH_TYPE_DATA) { event.type = cpu_to_le16(EV_ABS); - event.code = cpu_to_le16(axismap_tch[mtt->axis]); - event.value = cpu_to_le32(mtt->value); + event.code = cpu_to_le16(axismap_tch[evt->mtt.axis]); + event.value = cpu_to_le32(evt->mtt.value); virtio_input_send(vinput, &event); } else { event.type = cpu_to_le16(EV_ABS); event.code = cpu_to_le16(ABS_MT_SLOT); - event.value = cpu_to_le32(mtt->slot); + event.value = cpu_to_le32(evt->mtt.slot); virtio_input_send(vinput, &event); event.type = cpu_to_le16(EV_ABS); event.code = cpu_to_le16(ABS_MT_TRACKING_ID); - event.value = cpu_to_le32(mtt->tracking_id); + event.value = cpu_to_le32(evt->mtt.tracking_id); virtio_input_send(vinput, &event); } break; diff --git a/hw/m68k/next-kbd.c b/hw/m68k/next-kbd.c index XXXXXXX..XXXXXXX 100644 --- a/hw/m68k/next-kbd.c +++ b/hw/m68k/next-kbd.c @@ -XXX,XX +XXX,XX @@ static void nextkbd_event(DeviceState *dev, QemuConsole *src, { NextKBDState *s = NEXTKBD(dev); int qcode, keycode; - bool key_down = evt->u.key.data->down; - qcode = qemu_input_key_value_to_qcode(evt->u.key.data->key); + qcode = qemu_input_key_value_to_qcode(&evt->key.key); if (qcode >= ARRAY_SIZE(qcode_to_nextkbd_keycode)) { return; } /* Shift key currently has no keycode, so handle separately */ if (qcode == Q_KEY_CODE_SHIFT) { - if (key_down) { + if (evt->key.down) { s->shift |= KD_LSHIFT; } else { s->shift &= ~KD_LSHIFT; @@ -XXX,XX +XXX,XX @@ static void nextkbd_event(DeviceState *dev, QemuConsole *src, } if (qcode == Q_KEY_CODE_SHIFT_R) { - if (key_down) { + if (evt->key.down) { s->shift |= KD_RSHIFT; } else { s->shift &= ~KD_RSHIFT; @@ -XXX,XX +XXX,XX @@ static void nextkbd_event(DeviceState *dev, QemuConsole *src, } /* If key release event, create keyboard break code */ - if (!key_down) { + if (!evt->key.down) { keycode |= 0x80; } diff --git a/replay/replay-events.c b/replay/replay-events.c index XXXXXXX..XXXXXXX 100644 --- a/replay/replay-events.c +++ b/replay/replay-events.c @@ -XXX,XX +XXX,XX @@ static void replay_run_event(Event *event) break; case REPLAY_ASYNC_EVENT_INPUT: qemu_input_event_send_impl(NULL, (QemuInputEvent *)event->opaque); - qapi_free_InputEvent((InputEvent *)event->opaque); + g_free(event->opaque); break; case REPLAY_ASYNC_EVENT_INPUT_SYNC: qemu_input_event_sync_impl(); diff --git a/replay/replay-input.c b/replay/replay-input.c index XXXXXXX..XXXXXXX 100644 --- a/replay/replay-input.c +++ b/replay/replay-input.c @@ -XXX,XX +XXX,XX @@ void replay_save_input_event(QemuInputEvent *evt) { - InputKeyEvent *key; - InputBtnEvent *btn; - InputMoveEvent *move; - InputMultiTouchEvent *mtt; replay_put_dword(evt->type); switch (evt->type) { case INPUT_EVENT_KIND_KEY: - key = evt->u.key.data; - replay_put_dword(key->key->type); + replay_put_dword(evt->key.key.type); - switch (key->key->type) { + switch (evt->key.key.type) { case KEY_VALUE_KIND_NUMBER: - replay_put_qword(key->key->u.number.data); - replay_put_byte(key->down); + replay_put_qword(evt->key.key.u.number.data); + replay_put_byte(evt->key.down); break; case KEY_VALUE_KIND_QCODE: - replay_put_dword(key->key->u.qcode.data); - replay_put_byte(key->down); + replay_put_dword(evt->key.key.u.qcode.data); + replay_put_byte(evt->key.down); break; case KEY_VALUE_KIND__MAX: /* keep gcc happy */ @@ -XXX,XX +XXX,XX @@ void replay_save_input_event(QemuInputEvent *evt) } break; case INPUT_EVENT_KIND_BTN: - btn = evt->u.btn.data; - replay_put_dword(btn->button); - replay_put_byte(btn->down); + replay_put_dword(evt->btn.button); + replay_put_byte(evt->btn.down); break; case INPUT_EVENT_KIND_REL: - move = evt->u.rel.data; - replay_put_dword(move->axis); - replay_put_qword(move->value); + replay_put_dword(evt->rel.axis); + replay_put_qword(evt->rel.value); break; case INPUT_EVENT_KIND_ABS: - move = evt->u.abs.data; - replay_put_dword(move->axis); - replay_put_qword(move->value); + replay_put_dword(evt->abs.axis); + replay_put_qword(evt->abs.value); break; case INPUT_EVENT_KIND_MTT: - mtt = evt->u.mtt.data; - replay_put_dword(mtt->type); - replay_put_qword(mtt->slot); - replay_put_qword(mtt->tracking_id); - replay_put_dword(mtt->axis); - replay_put_qword(mtt->value); + replay_put_dword(evt->mtt.type); + replay_put_qword(evt->mtt.slot); + replay_put_qword(evt->mtt.tracking_id); + replay_put_dword(evt->mtt.axis); + replay_put_qword(evt->mtt.value); break; case INPUT_EVENT_KIND__MAX: /* keep gcc happy */ @@ -XXX,XX +XXX,XX @@ void replay_save_input_event(QemuInputEvent *evt) QemuInputEvent *replay_read_input_event(void) { - QemuInputEvent evt; - KeyValue keyValue; - InputKeyEvent key; - key.key = &keyValue; - InputBtnEvent btn; - InputMoveEvent rel; - InputMoveEvent abs; - InputMultiTouchEvent mtt; + QemuInputEvent *evt = g_new(QemuInputEvent, 1); - evt.type = replay_get_dword(); - switch (evt.type) { + evt->type = replay_get_dword(); + switch (evt->type) { case INPUT_EVENT_KIND_KEY: - evt.u.key.data = &key; - evt.u.key.data->key->type = replay_get_dword(); + evt->key.key.type = replay_get_dword(); - switch (evt.u.key.data->key->type) { + switch (evt->key.key.type) { case KEY_VALUE_KIND_NUMBER: - evt.u.key.data->key->u.number.data = replay_get_qword(); - evt.u.key.data->down = replay_get_byte(); + evt->key.key.u.number.data = replay_get_qword(); + evt->key.down = replay_get_byte(); break; case KEY_VALUE_KIND_QCODE: - evt.u.key.data->key->u.qcode.data = (QKeyCode)replay_get_dword(); - evt.u.key.data->down = replay_get_byte(); + evt->key.key.u.qcode.data = (QKeyCode)replay_get_dword(); + evt->key.down = replay_get_byte(); break; case KEY_VALUE_KIND__MAX: /* keep gcc happy */ @@ -XXX,XX +XXX,XX @@ QemuInputEvent *replay_read_input_event(void) } break; case INPUT_EVENT_KIND_BTN: - evt.u.btn.data = &btn; - evt.u.btn.data->button = (InputButton)replay_get_dword(); - evt.u.btn.data->down = replay_get_byte(); + evt->btn.button = (InputButton)replay_get_dword(); + evt->btn.down = replay_get_byte(); break; case INPUT_EVENT_KIND_REL: - evt.u.rel.data = &rel; - evt.u.rel.data->axis = (InputAxis)replay_get_dword(); - evt.u.rel.data->value = replay_get_qword(); + evt->rel.axis = (InputAxis)replay_get_dword(); + evt->rel.value = replay_get_qword(); break; case INPUT_EVENT_KIND_ABS: - evt.u.abs.data = &abs; - evt.u.abs.data->axis = (InputAxis)replay_get_dword(); - evt.u.abs.data->value = replay_get_qword(); + evt->abs.axis = (InputAxis)replay_get_dword(); + evt->abs.value = replay_get_qword(); break; case INPUT_EVENT_KIND_MTT: - evt.u.mtt.data = &mtt; - evt.u.mtt.data->type = (InputMultiTouchType)replay_get_dword(); - evt.u.mtt.data->slot = replay_get_qword(); - evt.u.mtt.data->tracking_id = replay_get_qword(); - evt.u.mtt.data->axis = (InputAxis)replay_get_dword(); - evt.u.mtt.data->value = replay_get_qword(); + evt->mtt.type = (InputMultiTouchType)replay_get_dword(); + evt->mtt.slot = replay_get_qword(); + evt->mtt.tracking_id = replay_get_qword(); + evt->mtt.axis = (InputAxis)replay_get_dword(); + evt->mtt.value = replay_get_qword(); break; case INPUT_EVENT_KIND__MAX: /* keep gcc happy */ break; } - return QAPI_CLONE(InputEvent, &evt); + return evt; } void replay_input_event(QemuConsole *src, QemuInputEvent *evt) @@ -XXX,XX +XXX,XX @@ void replay_input_event(QemuConsole *src, QemuInputEvent *evt) if (replay_mode == REPLAY_MODE_PLAY) { /* Nothing */ } else if (replay_mode == REPLAY_MODE_RECORD) { - replay_add_input_event(QAPI_CLONE(InputEvent, evt)); + QemuInputEvent *clone = g_new(QemuInputEvent, 1); + *clone = *evt; + replay_add_input_event(clone); } else { qemu_input_event_send_impl(src, evt); } diff --git a/ui/input-legacy.c b/ui/input-legacy.c index XXXXXXX..XXXXXXX 100644 --- a/ui/input-legacy.c +++ b/ui/input-legacy.c @@ -XXX,XX +XXX,XX @@ static void legacy_mouse_event(DeviceState *dev, QemuConsole *src, [INPUT_BUTTON_RIGHT] = MOUSE_EVENT_RBUTTON, }; QEMUPutMouseEntry *s = (QEMUPutMouseEntry *)dev; - InputBtnEvent *btn; - InputMoveEvent *move; switch (evt->type) { case INPUT_EVENT_KIND_BTN: - btn = evt->u.btn.data; - if (btn->down) { - s->buttons |= bmap[btn->button]; + if (evt->btn.down) { + s->buttons |= bmap[evt->btn.button]; } else { - s->buttons &= ~bmap[btn->button]; + s->buttons &= ~bmap[evt->btn.button]; } - if (btn->down && btn->button == INPUT_BUTTON_WHEEL_UP) { + if (evt->btn.down && evt->btn.button == INPUT_BUTTON_WHEEL_UP) { s->qemu_put_mouse_event(s->qemu_put_mouse_event_opaque, s->axis[INPUT_AXIS_X], s->axis[INPUT_AXIS_Y], -1, s->buttons); } - if (btn->down && btn->button == INPUT_BUTTON_WHEEL_DOWN) { + if (evt->btn.down && evt->btn.button == INPUT_BUTTON_WHEEL_DOWN) { s->qemu_put_mouse_event(s->qemu_put_mouse_event_opaque, s->axis[INPUT_AXIS_X], s->axis[INPUT_AXIS_Y], 1, s->buttons); } - if (btn->down && btn->button == INPUT_BUTTON_WHEEL_RIGHT) { + if (evt->btn.down && evt->btn.button == INPUT_BUTTON_WHEEL_RIGHT) { s->qemu_put_mouse_event(s->qemu_put_mouse_event_opaque, s->axis[INPUT_AXIS_X], s->axis[INPUT_AXIS_Y], -2, s->buttons); } - if (btn->down && btn->button == INPUT_BUTTON_WHEEL_LEFT) { + if (evt->btn.down && evt->btn.button == INPUT_BUTTON_WHEEL_LEFT) { s->qemu_put_mouse_event(s->qemu_put_mouse_event_opaque, s->axis[INPUT_AXIS_X], s->axis[INPUT_AXIS_Y], @@ -XXX,XX +XXX,XX @@ static void legacy_mouse_event(DeviceState *dev, QemuConsole *src, } break; case INPUT_EVENT_KIND_ABS: - move = evt->u.abs.data; - s->axis[move->axis] = move->value; + s->axis[evt->abs.axis] = evt->abs.value; break; case INPUT_EVENT_KIND_REL: - move = evt->u.rel.data; - s->axis[move->axis] += move->value; + s->axis[evt->rel.axis] += evt->rel.value; break; default: break; diff --git a/ui/input.c b/ui/input.c index XXXXXXX..XXXXXXX 100644 --- a/ui/input.c +++ b/ui/input.c @@ -XXX,XX +XXX,XX @@ struct QemuInputEventQueue { QEMUTimer *timer; uint32_t delay_ms; QemuConsole *src; - QemuInputEvent *evt; + QemuInputEvent evt; QTAILQ_ENTRY(QemuInputEventQueue) node; }; @@ -XXX,XX +XXX,XX @@ void qmp_input_send_event(const char *device, } for (e = events; e != NULL; e = e->next) { - InputEvent *evt = e->value; + InputEvent *qapi = e->value; + QemuInputEvent evt; + + evt.type = qapi->type; + + switch (qapi->type) { + case INPUT_EVENT_KIND_KEY: { + KeyValue *key = qapi->u.key.data->key; + QKeyCode code; + + switch (key->type) { + case KEY_VALUE_KIND_NUMBER: + code = qemu_input_key_number_to_qcode(key->u.number.data); + break; + case KEY_VALUE_KIND_QCODE: + code = key->u.qcode.data; + break; + default: + g_assert_not_reached(); + } + + evt.key.key.type = KEY_VALUE_KIND_QCODE; + evt.key.key.u.qcode.data = code; + evt.key.down = qapi->u.key.data->down; + break; + } - if (evt->type == INPUT_EVENT_KIND_KEY && - evt->u.key.data->key->type == KEY_VALUE_KIND_NUMBER) { - KeyValue *key = evt->u.key.data->key; - QKeyCode code = qemu_input_key_number_to_qcode(key->u.number.data); - qemu_input_event_send_key_qcode(con, code, evt->u.key.data->down); - } else { - qemu_input_event_send(con, evt); + case INPUT_EVENT_KIND_BTN: + evt.btn = *qapi->u.btn.data; + break; + + case INPUT_EVENT_KIND_REL: + evt.rel = *qapi->u.rel.data; + break; + + case INPUT_EVENT_KIND_ABS: + evt.abs = *qapi->u.abs.data; + break; + + case INPUT_EVENT_KIND_MTT: + evt.mtt = *qapi->u.mtt.data; + break; + + default: + g_assert_not_reached(); } + + qemu_input_event_send(con, &evt); } qemu_input_event_sync(); @@ -XXX,XX +XXX,XX @@ static void qemu_input_event_trace(QemuConsole *src, QemuInputEvent *evt) { const char *name; int qcode, idx = -1; - InputKeyEvent *key; + QemuInputKeyEvent *key; InputBtnEvent *btn; InputMoveEvent *move; InputMultiTouchEvent *mtt; @@ -XXX,XX +XXX,XX @@ static void qemu_input_event_trace(QemuConsole *src, QemuInputEvent *evt) } switch (evt->type) { case INPUT_EVENT_KIND_KEY: - key = evt->u.key.data; - switch (key->key->type) { + key = &evt->key; + switch (evt->key.key.type) { case KEY_VALUE_KIND_NUMBER: - qcode = qemu_input_key_number_to_qcode(key->key->u.number.data); + qcode = qemu_input_key_number_to_qcode(key->key.u.number.data); name = QKeyCode_str(qcode); - trace_input_event_key_number(idx, key->key->u.number.data, + trace_input_event_key_number(idx, key->key.u.number.data, name, key->down); break; case KEY_VALUE_KIND_QCODE: - name = QKeyCode_str(key->key->u.qcode.data); + name = QKeyCode_str(key->key.u.qcode.data); trace_input_event_key_qcode(idx, name, key->down); break; case KEY_VALUE_KIND__MAX: @@ -XXX,XX +XXX,XX @@ static void qemu_input_event_trace(QemuConsole *src, QemuInputEvent *evt) } break; case INPUT_EVENT_KIND_BTN: - btn = evt->u.btn.data; + btn = &evt->btn; name = btn->button < INPUT_BUTTON__MAX ? InputButton_str(btn->button) : "invalid"; trace_input_event_btn(idx, name, btn->down); break; case INPUT_EVENT_KIND_REL: - move = evt->u.rel.data; + move = &evt->rel; name = move->axis < INPUT_AXIS__MAX ? InputAxis_str(move->axis) : "invalid"; trace_input_event_rel(idx, name, move->value); break; case INPUT_EVENT_KIND_ABS: - move = evt->u.abs.data; + move = &evt->abs; name = move->axis < INPUT_AXIS__MAX ? InputAxis_str(move->axis) : "invalid"; trace_input_event_abs(idx, name, move->value); break; case INPUT_EVENT_KIND_MTT: - mtt = evt->u.mtt.data; + mtt = &evt->mtt; name = mtt->axis < INPUT_AXIS__MAX ? InputAxis_str(mtt->axis) : "invalid"; trace_input_event_mtt(idx, name, mtt->value); break; @@ -XXX,XX +XXX,XX @@ static void qemu_input_queue_process(void *opaque) + item->delay_ms); return; case QEMU_INPUT_QUEUE_EVENT: - qemu_input_event_send(item->src, item->evt); - qapi_free_InputEvent(item->evt); + qemu_input_event_send(item->src, &item->evt); break; case QEMU_INPUT_QUEUE_SYNC: qemu_input_event_sync(); @@ -XXX,XX +XXX,XX @@ static void qemu_input_queue_event(QemuInputEventQueueHead *queue, item->type = QEMU_INPUT_QUEUE_EVENT; item->src = src; - item->evt = evt; + item->evt = *evt; QTAILQ_INSERT_TAIL(queue, item, node); queue_count++; } @@ -XXX,XX +XXX,XX @@ void qemu_input_event_send(QemuConsole *src, QemuInputEvent *evt) /* Expect all parts of QEMU to send events with QCodes exclusively. * Key numbers are only supported as end-user input via QMP */ assert(!(evt->type == INPUT_EVENT_KIND_KEY && - evt->u.key.data->key->type == KEY_VALUE_KIND_NUMBER)); + evt->key.key.type == KEY_VALUE_KIND_NUMBER)); /* @@ -XXX,XX +XXX,XX @@ void qemu_input_event_send(QemuConsole *src, QemuInputEvent *evt) * need to deal with this mistake */ if (evt->type == INPUT_EVENT_KIND_KEY && - evt->u.key.data->key->u.qcode.data == Q_KEY_CODE_SYSRQ) { - evt->u.key.data->key->u.qcode.data = Q_KEY_CODE_PRINT; + evt->key.key.u.qcode.data == Q_KEY_CODE_SYSRQ) { + evt->key.key.u.qcode.data = Q_KEY_CODE_PRINT; } if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) { @@ -XXX,XX +XXX,XX @@ void qemu_input_event_sync(void) replay_input_sync_event(); } -static QemuInputEvent *qemu_input_event_new_key(KeyValue *key, bool down) -{ - QemuInputEvent *evt = g_new0(QemuInputEvent, 1); - evt->u.key.data = g_new0(InputKeyEvent, 1); - evt->type = INPUT_EVENT_KIND_KEY; - evt->u.key.data->key = key; - evt->u.key.data->down = down; - return evt; -} - void qemu_input_event_send_key(QemuConsole *src, KeyValue *key, bool down) { - QemuInputEvent *evt; - evt = qemu_input_event_new_key(key, down); + QemuInputEvent evt = { + .type = INPUT_EVENT_KIND_KEY, + .key = { + .key = *key, + .down = down, + }, + }; + + g_free(key); + if (QTAILQ_EMPTY(&kbd_queue)) { - qemu_input_event_send(src, evt); + qemu_input_event_send(src, &evt); qemu_input_event_sync(); - qapi_free_InputEvent(evt); } else if (queue_count < queue_limit) { - qemu_input_queue_event(&kbd_queue, src, evt); + qemu_input_queue_event(&kbd_queue, src, &evt); qemu_input_queue_sync(&kbd_queue); - } else { - qapi_free_InputEvent(evt); } } @@ -XXX,XX +XXX,XX @@ void qemu_input_event_send_key_delay(uint32_t delay_ms) void qemu_input_queue_btn(QemuConsole *src, InputButton btn, bool down) { - InputBtnEvent bevt = { - .button = btn, - .down = down, - }; QemuInputEvent evt = { .type = INPUT_EVENT_KIND_BTN, - .u.btn.data = &bevt, + .btn = { + .button = btn, + .down = down, + } }; qemu_input_event_send(src, &evt); @@ -XXX,XX +XXX,XX @@ int qemu_input_scale_axis(int value, void qemu_input_queue_rel(QemuConsole *src, InputAxis axis, int value) { - InputMoveEvent move = { - .axis = axis, - .value = value, - }; QemuInputEvent evt = { .type = INPUT_EVENT_KIND_REL, - .u.rel.data = &move, + .rel = { + .axis = axis, + .value = value, + }, }; qemu_input_event_send(src, &evt); @@ -XXX,XX +XXX,XX @@ void qemu_input_queue_rel(QemuConsole *src, InputAxis axis, int value) void qemu_input_queue_abs(QemuConsole *src, InputAxis axis, int value, int min_in, int max_in) { - InputMoveEvent move = { - .axis = axis, - .value = qemu_input_scale_axis(value, min_in, max_in, - INPUT_EVENT_ABS_MIN, - INPUT_EVENT_ABS_MAX), - }; QemuInputEvent evt = { .type = INPUT_EVENT_KIND_ABS, - .u.abs.data = &move, + .abs = { + .axis = axis, + .value = qemu_input_scale_axis(value, min_in, max_in, + INPUT_EVENT_ABS_MIN, + INPUT_EVENT_ABS_MAX), + }, }; qemu_input_event_send(src, &evt); @@ -XXX,XX +XXX,XX @@ void qemu_input_queue_abs(QemuConsole *src, InputAxis axis, int value, void qemu_input_queue_mtt(QemuConsole *src, InputMultiTouchType type, int slot, int tracking_id) { - InputMultiTouchEvent mtt = { - .type = type, - .slot = slot, - .tracking_id = tracking_id, - }; QemuInputEvent evt = { .type = INPUT_EVENT_KIND_MTT, - .u.mtt.data = &mtt, + .mtt = { + .type = type, + .slot = slot, + .tracking_id = tracking_id, + }, }; qemu_input_event_send(src, &evt); @@ -XXX,XX +XXX,XX @@ void qemu_input_queue_mtt(QemuConsole *src, InputMultiTouchType type, void qemu_input_queue_mtt_abs(QemuConsole *src, InputAxis axis, int value, int min_in, int max_in, int slot, int tracking_id) { - InputMultiTouchEvent mtt = { - .type = INPUT_MULTI_TOUCH_TYPE_DATA, - .slot = slot, - .tracking_id = tracking_id, - .axis = axis, - .value = qemu_input_scale_axis(value, min_in, max_in, - INPUT_EVENT_ABS_MIN, - INPUT_EVENT_ABS_MAX), - }; QemuInputEvent evt = { .type = INPUT_EVENT_KIND_MTT, - .u.mtt.data = &mtt, + .mtt = { + .type = INPUT_MULTI_TOUCH_TYPE_DATA, + .slot = slot, + .tracking_id = tracking_id, + .axis = axis, + .value = qemu_input_scale_axis(value, min_in, max_in, + INPUT_EVENT_ABS_MIN, + INPUT_EVENT_ABS_MAX), + } }; qemu_input_event_send(src, &evt); diff --git a/ui/vdagent.c b/ui/vdagent.c index XXXXXXX..XXXXXXX 100644 --- a/ui/vdagent.c +++ b/ui/vdagent.c @@ -XXX,XX +XXX,XX @@ static void vdagent_pointer_event(DeviceState *dev, QemuConsole *src, }; VDAgentChardev *vd = container_of(dev, struct VDAgentChardev, mouse_dev); - InputMoveEvent *move; - InputBtnEvent *btn; uint32_t xres, yres; switch (evt->type) { case INPUT_EVENT_KIND_ABS: - move = evt->u.abs.data; xres = qemu_console_get_width(src, 1024); yres = qemu_console_get_height(src, 768); - if (move->axis == INPUT_AXIS_X) { - vd->mouse_x = qemu_input_scale_axis(move->value, + if (evt->abs.axis == INPUT_AXIS_X) { + vd->mouse_x = qemu_input_scale_axis(evt->abs.value, INPUT_EVENT_ABS_MIN, INPUT_EVENT_ABS_MAX, 0, xres); - } else if (move->axis == INPUT_AXIS_Y) { - vd->mouse_y = qemu_input_scale_axis(move->value, + } else if (evt->abs.axis == INPUT_AXIS_Y) { + vd->mouse_y = qemu_input_scale_axis(evt->abs.value, INPUT_EVENT_ABS_MIN, INPUT_EVENT_ABS_MAX, 0, yres); @@ -XXX,XX +XXX,XX @@ static void vdagent_pointer_event(DeviceState *dev, QemuConsole *src, break; case INPUT_EVENT_KIND_BTN: - btn = evt->u.btn.data; - if (btn->down) { - vd->mouse_btn |= bmap[btn->button]; + if (evt->btn.down) { + vd->mouse_btn |= bmap[evt->btn.button]; } else { - vd->mouse_btn &= ~bmap[btn->button]; + vd->mouse_btn &= ~bmap[evt->btn.button]; } break; -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> Since commit af07e5ff02ae ("ui: convert key events to QKeyCodes immediately"), all internal key events are expected to be represented as QKeyCode. Replace KeyValue in QemuInputKeyEvent with QKeyCode to enforce that and simplify key code retrieval. 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-3-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- include/ui/input.h | 5 ++--- hw/arm/musicpal.c | 2 +- hw/char/escc.c | 2 +- hw/display/xenfb.c | 2 +- hw/input/adb-kbd.c | 2 +- hw/input/hid.c | 5 ++--- hw/input/ps2.c | 2 +- hw/input/stellaris_gamepad.c | 2 +- hw/input/virtio-input-hid.c | 2 +- hw/m68k/next-kbd.c | 2 +- replay/replay-input.c | 29 ++++++----------------------- ui/input-keymap.c | 9 ++++----- ui/input.c | 34 +++++++--------------------------- ui/trace-events | 1 - 14 files changed, 29 insertions(+), 70 deletions(-) diff --git a/include/ui/input.h b/include/ui/input.h index XXXXXXX..XXXXXXX 100644 --- a/include/ui/input.h +++ b/include/ui/input.h @@ -XXX,XX +XXX,XX @@ typedef struct QemuInputHandler QemuInputHandler; typedef struct QemuInputHandlerState QemuInputHandlerState; typedef struct QemuInputKeyEvent { - KeyValue key; + QKeyCode key; bool down; } QemuInputKeyEvent; @@ -XXX,XX +XXX,XX @@ void qemu_input_event_send_key_delay(uint32_t delay_ms); int qemu_input_key_number_to_qcode(unsigned int nr); int qemu_input_key_value_to_number(const KeyValue *value); int qemu_input_key_value_to_qcode(const KeyValue *value); -int qemu_input_key_value_to_scancode(const KeyValue *value, bool down, - int *codes); +int qemu_input_qcode_to_scancode(QKeyCode qcode, bool down, int *codes); int qemu_input_linux_to_qcode(unsigned int lnx); void qemu_input_queue_btn(QemuConsole *src, InputButton btn, bool down); diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c index XXXXXXX..XXXXXXX 100644 --- a/hw/arm/musicpal.c +++ b/hw/arm/musicpal.c @@ -XXX,XX +XXX,XX @@ static void musicpal_key_event(DeviceState *dev, QemuConsole *src, QemuInputEvent *evt) { musicpal_key_state *s = MUSICPAL_KEY(dev); - int qcode = qemu_input_key_value_to_qcode(&evt->key.key); + int qcode = evt->key.key; uint32_t event = 0; int i; diff --git a/hw/char/escc.c b/hw/char/escc.c index XXXXXXX..XXXXXXX 100644 --- a/hw/char/escc.c +++ b/hw/char/escc.c @@ -XXX,XX +XXX,XX @@ static void sunkbd_handle_event(DeviceState *dev, QemuConsole *src, int qcode, keycode; assert(evt->type == INPUT_EVENT_KIND_KEY); - qcode = qemu_input_key_value_to_qcode(&evt->key.key); + qcode = evt->key.key; trace_escc_sunkbd_event_in(qcode, QKeyCode_str(qcode), evt->key.down); diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index XXXXXXX..XXXXXXX 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -XXX,XX +XXX,XX @@ static void xenfb_key_event(DeviceState *dev, QemuConsole *src, QemuInputEvent *evt) { struct XenInput *xenfb = (struct XenInput *)dev; - int qcode = qemu_input_key_value_to_qcode(&evt->key.key); + int qcode = evt->key.key; int lnx; if (qcode < qemu_input_map_qcode_to_linux_len) { diff --git a/hw/input/adb-kbd.c b/hw/input/adb-kbd.c index XXXXXXX..XXXXXXX 100644 --- a/hw/input/adb-kbd.c +++ b/hw/input/adb-kbd.c @@ -XXX,XX +XXX,XX @@ static void adb_keyboard_event(DeviceState *dev, QemuConsole *src, KBDState *s = (KBDState *)dev; int qcode, keycode; - qcode = qemu_input_key_value_to_qcode(&evt->key.key); + qcode = evt->key.key; if (qcode >= ARRAY_SIZE(qcode_to_adb_keycode)) { return; } diff --git a/hw/input/hid.c b/hw/input/hid.c index XXXXXXX..XXXXXXX 100644 --- a/hw/input/hid.c +++ b/hw/input/hid.c @@ -XXX,XX +XXX,XX @@ static void hid_keyboard_event(DeviceState *dev, QemuConsole *src, int scancodes[3], i, count; int slot; - count = qemu_input_key_value_to_scancode(&evt->key.key, - evt->key.down, - scancodes); + count = qemu_input_qcode_to_scancode(evt->key.key, evt->key.down, + scancodes); if (hs->n + count > QUEUE_LENGTH) { trace_hid_kbd_queue_full(); return; diff --git a/hw/input/ps2.c b/hw/input/ps2.c index XXXXXXX..XXXXXXX 100644 --- a/hw/input/ps2.c +++ b/hw/input/ps2.c @@ -XXX,XX +XXX,XX @@ 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_key_value_to_qcode(&evt->key.key); + qcode = evt->key.key; mod = ps2_modifier_bit(qcode); trace_ps2_keyboard_event(s, qcode, evt->key.down, mod, diff --git a/hw/input/stellaris_gamepad.c b/hw/input/stellaris_gamepad.c index XXXXXXX..XXXXXXX 100644 --- a/hw/input/stellaris_gamepad.c +++ b/hw/input/stellaris_gamepad.c @@ -XXX,XX +XXX,XX @@ static void stellaris_gamepad_event(DeviceState *dev, QemuConsole *src, QemuInputEvent *evt) { StellarisGamepad *s = STELLARIS_GAMEPAD(dev); - int qcode = qemu_input_key_value_to_qcode(&evt->key.key); + int qcode = evt->key.key; int i; for (i = 0; i < s->num_buttons; i++) { diff --git a/hw/input/virtio-input-hid.c b/hw/input/virtio-input-hid.c index XXXXXXX..XXXXXXX 100644 --- a/hw/input/virtio-input-hid.c +++ b/hw/input/virtio-input-hid.c @@ -XXX,XX +XXX,XX @@ static void virtio_input_handle_event(DeviceState *dev, QemuConsole *src, switch (evt->type) { case INPUT_EVENT_KIND_KEY: - qcode = qemu_input_key_value_to_qcode(&evt->key.key); + qcode = evt->key.key; if (qcode < qemu_input_map_qcode_to_linux_len && qemu_input_map_qcode_to_linux[qcode]) { event.type = cpu_to_le16(EV_KEY); diff --git a/hw/m68k/next-kbd.c b/hw/m68k/next-kbd.c index XXXXXXX..XXXXXXX 100644 --- a/hw/m68k/next-kbd.c +++ b/hw/m68k/next-kbd.c @@ -XXX,XX +XXX,XX @@ static void nextkbd_event(DeviceState *dev, QemuConsole *src, NextKBDState *s = NEXTKBD(dev); int qcode, keycode; - qcode = qemu_input_key_value_to_qcode(&evt->key.key); + qcode = evt->key.key; if (qcode >= ARRAY_SIZE(qcode_to_nextkbd_keycode)) { return; } diff --git a/replay/replay-input.c b/replay/replay-input.c index XXXXXXX..XXXXXXX 100644 --- a/replay/replay-input.c +++ b/replay/replay-input.c @@ -XXX,XX +XXX,XX @@ void replay_save_input_event(QemuInputEvent *evt) switch (evt->type) { case INPUT_EVENT_KIND_KEY: - replay_put_dword(evt->key.key.type); - - switch (evt->key.key.type) { - case KEY_VALUE_KIND_NUMBER: - replay_put_qword(evt->key.key.u.number.data); - replay_put_byte(evt->key.down); - break; - case KEY_VALUE_KIND_QCODE: - replay_put_dword(evt->key.key.u.qcode.data); - replay_put_byte(evt->key.down); - break; - case KEY_VALUE_KIND__MAX: - /* keep gcc happy */ - break; - } + replay_put_dword(KEY_VALUE_KIND_QCODE); + replay_put_dword(evt->key.key); + replay_put_byte(evt->key.down); break; case INPUT_EVENT_KIND_BTN: replay_put_dword(evt->btn.button); @@ -XXX,XX +XXX,XX @@ QemuInputEvent *replay_read_input_event(void) evt->type = replay_get_dword(); switch (evt->type) { case INPUT_EVENT_KIND_KEY: - evt->key.key.type = replay_get_dword(); - - switch (evt->key.key.type) { + switch (replay_get_dword()) { case KEY_VALUE_KIND_NUMBER: - evt->key.key.u.number.data = replay_get_qword(); + evt->key.key = qemu_input_key_number_to_qcode(replay_get_qword()); evt->key.down = replay_get_byte(); break; case KEY_VALUE_KIND_QCODE: - evt->key.key.u.qcode.data = (QKeyCode)replay_get_dword(); + evt->key.key = (QKeyCode)replay_get_dword(); evt->key.down = replay_get_byte(); break; - case KEY_VALUE_KIND__MAX: - /* keep gcc happy */ - break; } break; case INPUT_EVENT_KIND_BTN: diff --git a/ui/input-keymap.c b/ui/input-keymap.c index XXXXXXX..XXXXXXX 100644 --- a/ui/input-keymap.c +++ b/ui/input-keymap.c @@ -XXX,XX +XXX,XX @@ int qemu_input_key_value_to_qcode(const KeyValue *value) } } -int qemu_input_key_value_to_scancode(const KeyValue *value, bool down, - int *codes) +int qemu_input_qcode_to_scancode(QKeyCode qcode, bool down, int *codes) { - int keycode = qemu_input_key_value_to_number(value); + int keycode = qcode < qemu_input_map_qcode_to_qnum_len ? + qemu_input_map_qcode_to_qnum[qcode] : 0; int count = 0; - if (value->type == KEY_VALUE_KIND_QCODE && - value->u.qcode.data == Q_KEY_CODE_PAUSE) { + if (qcode == Q_KEY_CODE_PAUSE) { /* specific case */ int v = down ? 0 : 0x80; codes[count++] = 0xe1; diff --git a/ui/input.c b/ui/input.c index XXXXXXX..XXXXXXX 100644 --- a/ui/input.c +++ b/ui/input.c @@ -XXX,XX +XXX,XX @@ void qmp_input_send_event(const char *device, g_assert_not_reached(); } - evt.key.key.type = KEY_VALUE_KIND_QCODE; - evt.key.key.u.qcode.data = code; + evt.key.key = code; evt.key.down = qapi->u.key.data->down; break; } @@ -XXX,XX +XXX,XX @@ void qmp_input_send_event(const char *device, static void qemu_input_event_trace(QemuConsole *src, QemuInputEvent *evt) { const char *name; - int qcode, idx = -1; + int idx = -1; QemuInputKeyEvent *key; InputBtnEvent *btn; InputMoveEvent *move; @@ -XXX,XX +XXX,XX @@ static void qemu_input_event_trace(QemuConsole *src, QemuInputEvent *evt) switch (evt->type) { case INPUT_EVENT_KIND_KEY: key = &evt->key; - switch (evt->key.key.type) { - case KEY_VALUE_KIND_NUMBER: - qcode = qemu_input_key_number_to_qcode(key->key.u.number.data); - name = QKeyCode_str(qcode); - trace_input_event_key_number(idx, key->key.u.number.data, - name, key->down); - break; - case KEY_VALUE_KIND_QCODE: - name = QKeyCode_str(key->key.u.qcode.data); - trace_input_event_key_qcode(idx, name, key->down); - break; - case KEY_VALUE_KIND__MAX: - /* keep gcc happy */ - break; - } + name = QKeyCode_str(key->key); + trace_input_event_key_qcode(idx, name, key->down); break; case INPUT_EVENT_KIND_BTN: btn = &evt->btn; @@ -XXX,XX +XXX,XX @@ void qemu_input_event_send_impl(QemuConsole *src, QemuInputEvent *evt) void qemu_input_event_send(QemuConsole *src, QemuInputEvent *evt) { - /* Expect all parts of QEMU to send events with QCodes exclusively. - * Key numbers are only supported as end-user input via QMP */ - assert(!(evt->type == INPUT_EVENT_KIND_KEY && - evt->key.key.type == KEY_VALUE_KIND_NUMBER)); - - /* * 'sysrq' was mistakenly added to hack around the fact that * the ps2 driver was not generating correct scancodes sequences @@ -XXX,XX +XXX,XX @@ void qemu_input_event_send(QemuConsole *src, QemuInputEvent *evt) * need to deal with this mistake */ if (evt->type == INPUT_EVENT_KIND_KEY && - evt->key.key.u.qcode.data == Q_KEY_CODE_SYSRQ) { - evt->key.key.u.qcode.data = Q_KEY_CODE_PRINT; + evt->key.key == Q_KEY_CODE_SYSRQ) { + evt->key.key = Q_KEY_CODE_PRINT; } if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) { @@ -XXX,XX +XXX,XX @@ void qemu_input_event_send_key(QemuConsole *src, KeyValue *key, bool down) QemuInputEvent evt = { .type = INPUT_EVENT_KIND_KEY, .key = { - .key = *key, + .key = qemu_input_key_value_to_qcode(key), .down = down, }, }; diff --git a/ui/trace-events b/ui/trace-events index XXXXXXX..XXXXXXX 100644 --- a/ui/trace-events +++ b/ui/trace-events @@ -XXX,XX +XXX,XX @@ vnc_tight_zlib_init(void *state, int stream_id, const void *opaque) "VNC tight z # input.c -input_event_key_number(int conidx, int number, const char *qcode, bool down) "con %d, key number 0x%x [%s], down %d" input_event_key_qcode(int conidx, const char *qcode, bool down) "con %d, key qcode %s, down %d" input_event_btn(int conidx, const char *btn, bool down) "con %d, button %s, down %d" input_event_rel(int conidx, const char *axis, int value) "con %d, axis %s, value %d" -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> Linux input key codes are a better internal representation than QKeyCode: - With Linux input key codes as the internal representation, keys previously lost solely because the middle layer between event sources and sinks used QKeyCode will be preserved, since Linux key codes cover all keys that those sources and sinks use. For example, KEY_KPJPCOMMA cannot be represented with QKeyCode, but it is widely supported by event sources and sinks since it is included in linux, atset1, atset2, usb, x11, osx, qnum (derived from atset1), xorgxquartz, and xorgevdev (derived from linux). - They make it possible to pass through Linux host key codes to Linux guests to preserve all key inputs. - They simplify consumers by avoiding QKeyCode aliases, namely asterisk/kp_multiply and sysrq/print. This matches the approach used by virtio and Xen. 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-4-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- include/ui/input.h | 49 ++++++++++++++++++++++++++++++- hw/arm/musicpal.c | 2 +- hw/char/escc.c | 2 +- hw/display/xenfb.c | 2 +- hw/input/adb-kbd.c | 2 +- hw/input/hid.c | 3 +- hw/input/ps2.c | 2 +- hw/input/stellaris_gamepad.c | 2 +- hw/input/virtio-input-hid.c | 2 +- hw/m68k/next-kbd.c | 2 +- replay/replay-input.c | 11 +++++-- tools/qemu-vnc/input.c | 13 +++++++-- ui/input-keymap.c | 56 +++++++++++++++++++++++++++++------- ui/input.c | 51 ++++++++++---------------------- tools/qemu-vnc/trace-events | 2 +- ui/meson.build | 14 +++++++++ 16 files changed, 151 insertions(+), 64 deletions(-) diff --git a/include/ui/input.h b/include/ui/input.h index XXXXXXX..XXXXXXX 100644 --- a/include/ui/input.h +++ b/include/ui/input.h @@ -XXX,XX +XXX,XX @@ typedef struct QemuInputHandler QemuInputHandler; typedef struct QemuInputHandlerState QemuInputHandlerState; typedef struct QemuInputKeyEvent { - QKeyCode key; + unsigned int key; bool down; } QemuInputKeyEvent; @@ -XXX,XX +XXX,XX @@ void qemu_input_event_sync(void); void qemu_input_event_sync_impl(void); void qemu_input_event_send_key(QemuConsole *src, KeyValue *key, bool down); +void qemu_input_event_send_key_linux(QemuConsole *src, unsigned int lnx, + bool down); void qemu_input_event_send_key_number(QemuConsole *src, int num, bool down); void qemu_input_event_send_key_qcode(QemuConsole *src, QKeyCode q, bool down); void qemu_input_event_send_key_delay(uint32_t delay_ms); int qemu_input_key_number_to_qcode(unsigned int nr); +unsigned int qemu_input_key_number_to_linux(unsigned int nr); int qemu_input_key_value_to_number(const KeyValue *value); int qemu_input_key_value_to_qcode(const KeyValue *value); +unsigned int qemu_input_key_value_to_linux(const KeyValue *value); int qemu_input_qcode_to_scancode(QKeyCode qcode, bool down, int *codes); +int qemu_input_linux_to_scancode(unsigned int lnx, bool down, int *codes); int qemu_input_linux_to_qcode(unsigned int lnx); void qemu_input_queue_btn(QemuConsole *src, InputButton btn, bool down); @@ -XXX,XX +XXX,XX @@ 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_atset1_to_linux_len; +extern const guint16 qemu_input_map_atset1_to_linux[]; + extern const guint qemu_input_map_linux_to_qcode_len; extern const guint16 qemu_input_map_linux_to_qcode[]; extern const guint qemu_input_map_qcode_to_atset1_len; extern const guint16 qemu_input_map_qcode_to_atset1[]; +extern const guint qemu_input_map_linux_to_atset1_len; +extern const guint16 qemu_input_map_linux_to_atset1[]; + extern const guint qemu_input_map_qcode_to_atset2_len; extern const guint16 qemu_input_map_qcode_to_atset2[]; +extern const guint qemu_input_map_linux_to_atset2_len; +extern const guint16 qemu_input_map_linux_to_atset2[]; + extern const guint qemu_input_map_qcode_to_atset3_len; extern const guint16 qemu_input_map_qcode_to_atset3[]; +extern const guint qemu_input_map_linux_to_atset3_len; +extern const guint16 qemu_input_map_linux_to_atset3[]; + 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_qcode_to_qnum_len; extern const guint16 qemu_input_map_qcode_to_qnum[]; +extern const guint qemu_input_map_linux_to_qnum_len; +extern const guint16 qemu_input_map_linux_to_qnum[]; + extern const guint qemu_input_map_qcode_to_sun_len; extern const guint16 qemu_input_map_qcode_to_sun[]; +extern const guint qemu_input_map_linux_to_sun_len; +extern const guint16 qemu_input_map_linux_to_sun[]; + extern const guint qemu_input_map_qnum_to_qcode_len; extern const guint16 qemu_input_map_qnum_to_qcode[]; +extern const guint qemu_input_map_qnum_to_linux_len; +extern const guint16 qemu_input_map_qnum_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_usb_to_linux_len; +extern const guint16 qemu_input_map_usb_to_linux[]; + 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_win32_to_linux_len; +extern const guint16 qemu_input_map_win32_to_linux[]; + 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_x11_to_linux_len; +extern const guint16 qemu_input_map_x11_to_linux[]; + 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_xorgkbd_to_linux_len; +extern const guint16 qemu_input_map_xorgkbd_to_linux[]; + 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_xorgxquartz_to_linux_len; +extern const guint16 qemu_input_map_xorgxquartz_to_linux[]; + extern const guint qemu_input_map_xorgxwin_to_qcode_len; extern const guint16 qemu_input_map_xorgxwin_to_qcode[]; +extern const guint qemu_input_map_xorgxwin_to_linux_len; +extern const guint16 qemu_input_map_xorgxwin_to_linux[]; + extern const guint qemu_input_map_osx_to_qcode_len; extern const guint16 qemu_input_map_osx_to_qcode[]; +extern const guint qemu_input_map_osx_to_linux_len; +extern const guint16 qemu_input_map_osx_to_linux[]; + #endif /* INPUT_H */ diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c index XXXXXXX..XXXXXXX 100644 --- a/hw/arm/musicpal.c +++ b/hw/arm/musicpal.c @@ -XXX,XX +XXX,XX @@ static void musicpal_key_event(DeviceState *dev, QemuConsole *src, QemuInputEvent *evt) { musicpal_key_state *s = MUSICPAL_KEY(dev); - int qcode = evt->key.key; + int qcode = qemu_input_linux_to_qcode(evt->key.key); uint32_t event = 0; int i; diff --git a/hw/char/escc.c b/hw/char/escc.c index XXXXXXX..XXXXXXX 100644 --- a/hw/char/escc.c +++ b/hw/char/escc.c @@ -XXX,XX +XXX,XX @@ static void sunkbd_handle_event(DeviceState *dev, QemuConsole *src, int qcode, keycode; assert(evt->type == INPUT_EVENT_KIND_KEY); - qcode = evt->key.key; + qcode = qemu_input_linux_to_qcode(evt->key.key); trace_escc_sunkbd_event_in(qcode, QKeyCode_str(qcode), evt->key.down); diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index XXXXXXX..XXXXXXX 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -XXX,XX +XXX,XX @@ static void xenfb_key_event(DeviceState *dev, QemuConsole *src, QemuInputEvent *evt) { struct XenInput *xenfb = (struct XenInput *)dev; - int qcode = evt->key.key; + int qcode = qemu_input_linux_to_qcode(evt->key.key); int lnx; if (qcode < qemu_input_map_qcode_to_linux_len) { diff --git a/hw/input/adb-kbd.c b/hw/input/adb-kbd.c index XXXXXXX..XXXXXXX 100644 --- a/hw/input/adb-kbd.c +++ b/hw/input/adb-kbd.c @@ -XXX,XX +XXX,XX @@ static void adb_keyboard_event(DeviceState *dev, QemuConsole *src, KBDState *s = (KBDState *)dev; int qcode, keycode; - qcode = evt->key.key; + qcode = qemu_input_linux_to_qcode(evt->key.key); if (qcode >= ARRAY_SIZE(qcode_to_adb_keycode)) { return; } diff --git a/hw/input/hid.c b/hw/input/hid.c index XXXXXXX..XXXXXXX 100644 --- a/hw/input/hid.c +++ b/hw/input/hid.c @@ -XXX,XX +XXX,XX @@ static void hid_keyboard_event(DeviceState *dev, QemuConsole *src, QemuInputEvent *evt) { HIDState *hs = (HIDState *)dev; + int qcode = qemu_input_linux_to_qcode(evt->key.key); int scancodes[3], i, count; int slot; - count = qemu_input_qcode_to_scancode(evt->key.key, evt->key.down, + count = qemu_input_qcode_to_scancode(qcode, evt->key.down, scancodes); if (hs->n + count > QUEUE_LENGTH) { trace_hid_kbd_queue_full(); diff --git a/hw/input/ps2.c b/hw/input/ps2.c index XXXXXXX..XXXXXXX 100644 --- a/hw/input/ps2.c +++ b/hw/input/ps2.c @@ -XXX,XX +XXX,XX @@ 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 = evt->key.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, diff --git a/hw/input/stellaris_gamepad.c b/hw/input/stellaris_gamepad.c index XXXXXXX..XXXXXXX 100644 --- a/hw/input/stellaris_gamepad.c +++ b/hw/input/stellaris_gamepad.c @@ -XXX,XX +XXX,XX @@ static void stellaris_gamepad_event(DeviceState *dev, QemuConsole *src, QemuInputEvent *evt) { StellarisGamepad *s = STELLARIS_GAMEPAD(dev); - int qcode = evt->key.key; + int qcode = qemu_input_linux_to_qcode(evt->key.key); int i; for (i = 0; i < s->num_buttons; i++) { diff --git a/hw/input/virtio-input-hid.c b/hw/input/virtio-input-hid.c index XXXXXXX..XXXXXXX 100644 --- a/hw/input/virtio-input-hid.c +++ b/hw/input/virtio-input-hid.c @@ -XXX,XX +XXX,XX @@ static void virtio_input_handle_event(DeviceState *dev, QemuConsole *src, switch (evt->type) { case INPUT_EVENT_KIND_KEY: - qcode = evt->key.key; + qcode = qemu_input_linux_to_qcode(evt->key.key); if (qcode < qemu_input_map_qcode_to_linux_len && qemu_input_map_qcode_to_linux[qcode]) { event.type = cpu_to_le16(EV_KEY); diff --git a/hw/m68k/next-kbd.c b/hw/m68k/next-kbd.c index XXXXXXX..XXXXXXX 100644 --- a/hw/m68k/next-kbd.c +++ b/hw/m68k/next-kbd.c @@ -XXX,XX +XXX,XX @@ static void nextkbd_event(DeviceState *dev, QemuConsole *src, NextKBDState *s = NEXTKBD(dev); int qcode, keycode; - qcode = evt->key.key; + qcode = qemu_input_linux_to_qcode(evt->key.key); if (qcode >= ARRAY_SIZE(qcode_to_nextkbd_keycode)) { return; } diff --git a/replay/replay-input.c b/replay/replay-input.c index XXXXXXX..XXXXXXX 100644 --- a/replay/replay-input.c +++ b/replay/replay-input.c @@ -XXX,XX +XXX,XX @@ void replay_save_input_event(QemuInputEvent *evt) switch (evt->type) { case INPUT_EVENT_KIND_KEY: replay_put_dword(KEY_VALUE_KIND_QCODE); - replay_put_dword(evt->key.key); + replay_put_dword(qemu_input_linux_to_qcode(evt->key.key)); replay_put_byte(evt->key.down); break; case INPUT_EVENT_KIND_BTN: @@ -XXX,XX +XXX,XX @@ void replay_save_input_event(QemuInputEvent *evt) QemuInputEvent *replay_read_input_event(void) { QemuInputEvent *evt = g_new(QemuInputEvent, 1); + int qcode; evt->type = replay_get_dword(); switch (evt->type) { case INPUT_EVENT_KIND_KEY: switch (replay_get_dword()) { case KEY_VALUE_KIND_NUMBER: - evt->key.key = qemu_input_key_number_to_qcode(replay_get_qword()); + qcode = qemu_input_key_number_to_qcode(replay_get_qword()); evt->key.down = replay_get_byte(); break; case KEY_VALUE_KIND_QCODE: - evt->key.key = (QKeyCode)replay_get_dword(); + qcode = (QKeyCode)replay_get_dword(); evt->key.down = replay_get_byte(); break; + default: + g_assert_not_reached(); } + evt->key.key = qcode < qemu_input_map_qcode_to_linux_len ? + qemu_input_map_qcode_to_linux[qcode] : 0; break; case INPUT_EVENT_KIND_BTN: evt->btn.button = (InputButton)replay_get_dword(); diff --git a/tools/qemu-vnc/input.c b/tools/qemu-vnc/input.c index XXXXXXX..XXXXXXX 100644 --- a/tools/qemu-vnc/input.c +++ b/tools/qemu-vnc/input.c @@ -XXX,XX +XXX,XX @@ void qemu_input_event_send_key_delay(uint32_t delay_ms) } void qemu_input_event_send_key_qcode(QemuConsole *src, QKeyCode q, bool down) +{ + unsigned int lnx = qemu_input_map_qcode_to_linux[q]; + qemu_input_event_send_key_linux(src, lnx, down); +} + +void qemu_input_event_send_key_linux(QemuConsole *src, unsigned int lnx, + bool down) { QemuDBusDisplay1Keyboard *kbd; guint qnum; - trace_qemu_vnc_key_event(q, down); + trace_qemu_vnc_key_event(lnx, down); if (!src) { return; @@ -XXX,XX +XXX,XX @@ void qemu_input_event_send_key_qcode(QemuConsole *src, QKeyCode q, bool down) return; } - if (q >= qemu_input_map_qcode_to_qnum_len) { + if (lnx >= qemu_input_map_linux_to_qnum_len) { return; } - qnum = qemu_input_map_qcode_to_qnum[q]; + qnum = qemu_input_map_linux_to_qnum[lnx]; if (down) { qemu_dbus_display1_keyboard_call_press( diff --git a/ui/input-keymap.c b/ui/input-keymap.c index XXXXXXX..XXXXXXX 100644 --- a/ui/input-keymap.c +++ b/ui/input-keymap.c @@ -XXX,XX +XXX,XX @@ #include "standard-headers/linux/input.h" #include "ui/input-keymap-atset1-to-qcode.c.inc" +#include "ui/input-keymap-atset1-to-linux.c.inc" #include "ui/input-keymap-linux-to-qcode.c.inc" #include "ui/input-keymap-qcode-to-atset1.c.inc" +#include "ui/input-keymap-linux-to-atset1.c.inc" #include "ui/input-keymap-qcode-to-atset2.c.inc" +#include "ui/input-keymap-linux-to-atset2.c.inc" #include "ui/input-keymap-qcode-to-atset3.c.inc" +#include "ui/input-keymap-linux-to-atset3.c.inc" #include "ui/input-keymap-qcode-to-linux.c.inc" #include "ui/input-keymap-qcode-to-qnum.c.inc" +#include "ui/input-keymap-linux-to-qnum.c.inc" #include "ui/input-keymap-qcode-to-sun.c.inc" +#include "ui/input-keymap-linux-to-sun.c.inc" #include "ui/input-keymap-qnum-to-qcode.c.inc" +#include "ui/input-keymap-qnum-to-linux.c.inc" #include "ui/input-keymap-usb-to-qcode.c.inc" +#include "ui/input-keymap-usb-to-linux.c.inc" #include "ui/input-keymap-win32-to-qcode.c.inc" +#include "ui/input-keymap-win32-to-linux.c.inc" #include "ui/input-keymap-x11-to-qcode.c.inc" +#include "ui/input-keymap-x11-to-linux.c.inc" #include "ui/input-keymap-xorgevdev-to-qcode.c.inc" #include "ui/input-keymap-xorgkbd-to-qcode.c.inc" +#include "ui/input-keymap-xorgkbd-to-linux.c.inc" #include "ui/input-keymap-xorgxquartz-to-qcode.c.inc" +#include "ui/input-keymap-xorgxquartz-to-linux.c.inc" #include "ui/input-keymap-xorgxwin-to-qcode.c.inc" +#include "ui/input-keymap-xorgxwin-to-linux.c.inc" #include "ui/input-keymap-osx-to-qcode.c.inc" +#include "ui/input-keymap-osx-to-linux.c.inc" int qemu_input_linux_to_qcode(unsigned int lnx) { @@ -XXX,XX +XXX,XX @@ int qemu_input_key_value_to_number(const KeyValue *value) int qemu_input_key_number_to_qcode(unsigned int nr) { - if (nr >= qemu_input_map_qnum_to_qcode_len) { - return 0; + return qemu_input_linux_to_qcode(qemu_input_key_number_to_linux(nr)); +} + +unsigned int qemu_input_key_number_to_linux(unsigned int nr) +{ + if (nr >= qemu_input_map_qnum_to_linux_len) { + return KEY_RESERVED; } - return qemu_input_map_qnum_to_qcode[nr]; + return qemu_input_map_qnum_to_linux[nr]; } int qemu_input_key_value_to_qcode(const KeyValue *value) { - if (value->type == KEY_VALUE_KIND_QCODE) { - return value->u.qcode.data; - } else { - assert(value->type == KEY_VALUE_KIND_NUMBER); - return qemu_input_key_number_to_qcode(value->u.number.data); + return qemu_input_linux_to_qcode(qemu_input_key_value_to_linux(value)); +} + +unsigned int qemu_input_key_value_to_linux(const KeyValue *value) +{ + switch (value->type) { + case KEY_VALUE_KIND_NUMBER: + return qemu_input_key_number_to_linux(value->u.number.data); + + case KEY_VALUE_KIND_QCODE: + return qemu_input_map_qcode_to_linux[value->u.qcode.data]; + + default: + g_assert_not_reached(); } } int qemu_input_qcode_to_scancode(QKeyCode qcode, bool down, int *codes) { - int keycode = qcode < qemu_input_map_qcode_to_qnum_len ? - qemu_input_map_qcode_to_qnum[qcode] : 0; + return qemu_input_linux_to_scancode(qemu_input_map_qcode_to_linux[qcode], + down, codes); +} + +int qemu_input_linux_to_scancode(unsigned int lnx, bool down, int *codes) +{ + int keycode = lnx < qemu_input_map_linux_to_qnum_len ? + qemu_input_map_linux_to_qnum[lnx] : 0; int count = 0; - if (qcode == Q_KEY_CODE_PAUSE) { + if (lnx == KEY_PAUSE) { /* specific case */ int v = down ? 0 : 0x80; codes[count++] = 0xe1; diff --git a/ui/input.c b/ui/input.c index XXXXXXX..XXXXXXX 100644 --- a/ui/input.c +++ b/ui/input.c @@ -XXX,XX +XXX,XX @@ void qmp_input_send_event(const char *device, evt.type = qapi->type; switch (qapi->type) { - case INPUT_EVENT_KIND_KEY: { - KeyValue *key = qapi->u.key.data->key; - QKeyCode code; - - switch (key->type) { - case KEY_VALUE_KIND_NUMBER: - code = qemu_input_key_number_to_qcode(key->u.number.data); - break; - case KEY_VALUE_KIND_QCODE: - code = key->u.qcode.data; - break; - default: - g_assert_not_reached(); - } - - evt.key.key = code; + case INPUT_EVENT_KIND_KEY: + evt.key.key = qemu_input_key_value_to_linux(qapi->u.key.data->key); evt.key.down = qapi->u.key.data->down; break; - } case INPUT_EVENT_KIND_BTN: evt.btn = *qapi->u.btn.data; @@ -XXX,XX +XXX,XX @@ static void qemu_input_event_trace(QemuConsole *src, QemuInputEvent *evt) switch (evt->type) { case INPUT_EVENT_KIND_KEY: key = &evt->key; - name = QKeyCode_str(key->key); + name = QKeyCode_str(qemu_input_linux_to_qcode(key->key)); trace_input_event_key_qcode(idx, name, key->down); break; case INPUT_EVENT_KIND_BTN: @@ -XXX,XX +XXX,XX @@ void qemu_input_event_send_impl(QemuConsole *src, QemuInputEvent *evt) void qemu_input_event_send(QemuConsole *src, QemuInputEvent *evt) { - /* - * 'sysrq' was mistakenly added to hack around the fact that - * the ps2 driver was not generating correct scancodes sequences - * when 'alt+print' was pressed. This flaw is now fixed and the - * 'sysrq' key serves no further purpose. We normalize it to - * 'print', so that downstream receivers of the event don't - * need to deal with this mistake - */ - if (evt->type == INPUT_EVENT_KIND_KEY && - evt->key.key == Q_KEY_CODE_SYSRQ) { - evt->key.key = Q_KEY_CODE_PRINT; - } - if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) { return; } @@ -XXX,XX +XXX,XX @@ void qemu_input_event_sync(void) } void qemu_input_event_send_key(QemuConsole *src, KeyValue *key, bool down) +{ + unsigned int lnx = qemu_input_key_value_to_linux(key); + + g_free(key); + qemu_input_event_send_key_linux(src, lnx, down); +} + +void qemu_input_event_send_key_linux(QemuConsole *src, unsigned int lnx, + bool down) { QemuInputEvent evt = { .type = INPUT_EVENT_KIND_KEY, .key = { - .key = qemu_input_key_value_to_qcode(key), + .key = lnx, .down = down, }, }; - g_free(key); - if (QTAILQ_EMPTY(&kbd_queue)) { qemu_input_event_send(src, &evt); qemu_input_event_sync(); @@ -XXX,XX +XXX,XX @@ void qemu_input_event_send_key(QemuConsole *src, KeyValue *key, bool down) void qemu_input_event_send_key_number(QemuConsole *src, int num, bool down) { - QKeyCode code = qemu_input_key_number_to_qcode(num); - qemu_input_event_send_key_qcode(src, code, down); + unsigned int lnx = qemu_input_key_number_to_linux(num); + qemu_input_event_send_key_linux(src, lnx, down); } void qemu_input_event_send_key_qcode(QemuConsole *src, QKeyCode q, bool down) diff --git a/tools/qemu-vnc/trace-events b/tools/qemu-vnc/trace-events index XXXXXXX..XXXXXXX 100644 --- a/tools/qemu-vnc/trace-events +++ b/tools/qemu-vnc/trace-events @@ -XXX,XX +XXX,XX @@ qemu_vnc_cursor_define(int width, int height, int hot_x, int hot_y) "w=%d h=%d h qemu_vnc_input_abs(uint32_t x, uint32_t y) "x=%u y=%u" qemu_vnc_input_btn(int button, bool press) "button=%d press=%d" qemu_vnc_input_rel(int dx, int dy) "dx=%d dy=%d" -qemu_vnc_key_event(int qcode, bool down) "qcode=%d down=%d" +qemu_vnc_key_event(unsigned int lnx, bool down) "lnx=%u down=%d" qemu_vnc_owner_appeared(const char *name) "peer=%s" qemu_vnc_owner_vanished(const char *name) "peer=%s" qemu_vnc_scanout(uint32_t width, uint32_t height, uint32_t stride, uint32_t format) "w=%u h=%u stride=%u fmt=0x%x" diff --git a/ui/meson.build b/ui/meson.build index XXXXXXX..XXXXXXX 100644 --- a/ui/meson.build +++ b/ui/meson.build @@ -XXX,XX +XXX,XX @@ keymaps = [ ['atset1', 'qcode'], + ['atset1', 'linux'], ['linux', 'qcode'], ['qcode', 'atset1'], + ['linux', 'atset1'], ['qcode', 'atset2'], + ['linux', 'atset2'], ['qcode', 'atset3'], + ['linux', 'atset3'], ['qcode', 'linux'], ['qcode', 'qnum'], + ['linux', 'qnum'], ['qcode', 'sun'], + ['linux', 'sun'], ['qnum', 'qcode'], + ['qnum', 'linux'], ['usb', 'qcode'], + ['usb', 'linux'], ['win32', 'qcode'], + ['win32', 'linux'], ['x11', 'qcode'], + ['x11', 'linux'], ['xorgevdev', 'qcode'], ['xorgkbd', 'qcode'], + ['xorgkbd', 'linux'], ['xorgxquartz', 'qcode'], + ['xorgxquartz', 'linux'], ['xorgxwin', 'qcode'], + ['xorgxwin', 'linux'], ['osx', 'qcode'], + ['osx', 'linux'], ] if have_system or xkbcommon.found() -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> xenfb and virtio-input no longer need key mapping because they operate on Linux key codes, but removing the key mapping code loses the ability to filter out KEY_RESERVED. Drop KEY_RESERVED at the common input event entry point so the logic is shared by both devices and no downstream input handler receives KEY_RESERVED accidentally. 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-5-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- ui/input.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ui/input.c b/ui/input.c index XXXXXXX..XXXXXXX 100644 --- a/ui/input.c +++ b/ui/input.c @@ -XXX,XX +XXX,XX @@ void qemu_input_event_send_impl(QemuConsole *src, QemuInputEvent *evt) void qemu_input_event_send(QemuConsole *src, QemuInputEvent *evt) { + if (evt->type == INPUT_EVENT_KIND_KEY && !evt->key.key) { + return; + } + if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) { return; } -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> Add a text console helper that accepts Linux input key codes and use it as the common implementation for qemu_text_console_put_qcode(). This lets callers that already use Linux key codes avoid converting them back to QKeyCode. 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-6-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- include/ui/console.h | 2 ++ ui/console.c | 66 +++++++++++++++++++++++++++++--------------- 2 files changed, 46 insertions(+), 22 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index XXXXXXX..XXXXXXX 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -XXX,XX +XXX,XX @@ bool qemu_mouse_set(int index, Error **errp); void qemu_text_console_put_keysym(QemuTextConsole *s, int keysym); bool qemu_text_console_put_qcode(QemuTextConsole *s, int qcode, bool ctrl); +bool qemu_text_console_put_linux(QemuTextConsole *s, unsigned int lnx, + bool ctrl); void qemu_text_console_put_string(QemuTextConsole *s, const char *str, int len); /* consoles */ diff --git a/ui/console.c b/ui/console.c index XXXXXXX..XXXXXXX 100644 --- a/ui/console.c +++ b/ui/console.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" +#include "standard-headers/linux/input-event-codes.h" #include "ui/console.h" #include "ui/vgafont.h" #include "hw/core/qdev.h" @@ -XXX,XX +XXX,XX @@ void qemu_text_console_put_keysym(QemuTextConsole *s, int keysym) qemu_text_console_handle_keysym(s, keysym); } -static const int qcode_to_keysym[Q_KEY_CODE__MAX] = { - [Q_KEY_CODE_UP] = QEMU_KEY_UP, - [Q_KEY_CODE_DOWN] = QEMU_KEY_DOWN, - [Q_KEY_CODE_RIGHT] = QEMU_KEY_RIGHT, - [Q_KEY_CODE_LEFT] = QEMU_KEY_LEFT, - [Q_KEY_CODE_HOME] = QEMU_KEY_HOME, - [Q_KEY_CODE_END] = QEMU_KEY_END, - [Q_KEY_CODE_PGUP] = QEMU_KEY_PAGEUP, - [Q_KEY_CODE_PGDN] = QEMU_KEY_PAGEDOWN, - [Q_KEY_CODE_DELETE] = QEMU_KEY_DELETE, - [Q_KEY_CODE_TAB] = QEMU_KEY_TAB, - [Q_KEY_CODE_BACKSPACE] = QEMU_KEY_BACKSPACE, +static const int linux_to_keysym[] = { + [KEY_UP] = QEMU_KEY_UP, + [KEY_DOWN] = QEMU_KEY_DOWN, + [KEY_RIGHT] = QEMU_KEY_RIGHT, + [KEY_LEFT] = QEMU_KEY_LEFT, + [KEY_HOME] = QEMU_KEY_HOME, + [KEY_END] = QEMU_KEY_END, + [KEY_PAGEUP] = QEMU_KEY_PAGEUP, + [KEY_PAGEDOWN] = QEMU_KEY_PAGEDOWN, + [KEY_DELETE] = QEMU_KEY_DELETE, + [KEY_TAB] = QEMU_KEY_TAB, + [KEY_BACKSPACE] = QEMU_KEY_BACKSPACE, }; -static const int ctrl_qcode_to_keysym[Q_KEY_CODE__MAX] = { - [Q_KEY_CODE_UP] = QEMU_KEY_CTRL_UP, - [Q_KEY_CODE_DOWN] = QEMU_KEY_CTRL_DOWN, - [Q_KEY_CODE_RIGHT] = QEMU_KEY_CTRL_RIGHT, - [Q_KEY_CODE_LEFT] = QEMU_KEY_CTRL_LEFT, - [Q_KEY_CODE_HOME] = QEMU_KEY_CTRL_HOME, - [Q_KEY_CODE_END] = QEMU_KEY_CTRL_END, - [Q_KEY_CODE_PGUP] = QEMU_KEY_CTRL_PAGEUP, - [Q_KEY_CODE_PGDN] = QEMU_KEY_CTRL_PAGEDOWN, +static const int ctrl_linux_to_keysym[] = { + [KEY_UP] = QEMU_KEY_CTRL_UP, + [KEY_DOWN] = QEMU_KEY_CTRL_DOWN, + [KEY_RIGHT] = QEMU_KEY_CTRL_RIGHT, + [KEY_LEFT] = QEMU_KEY_CTRL_LEFT, + [KEY_HOME] = QEMU_KEY_CTRL_HOME, + [KEY_END] = QEMU_KEY_CTRL_END, + [KEY_PAGEUP] = QEMU_KEY_CTRL_PAGEUP, + [KEY_PAGEDOWN] = QEMU_KEY_CTRL_PAGEDOWN, }; bool qemu_text_console_put_qcode(QemuTextConsole *s, int qcode, bool ctrl) { + unsigned int lnx = qemu_input_map_qcode_to_linux[qcode]; + return qemu_text_console_put_linux(s, lnx, ctrl); +} + +bool qemu_text_console_put_linux(QemuTextConsole *s, unsigned int lnx, + bool ctrl) +{ + size_t maplen; + const int *map; int keysym; - keysym = ctrl ? ctrl_qcode_to_keysym[qcode] : qcode_to_keysym[qcode]; + if (ctrl) { + maplen = ARRAY_SIZE(ctrl_linux_to_keysym); + map = ctrl_linux_to_keysym; + } else { + maplen = ARRAY_SIZE(linux_to_keysym); + map = linux_to_keysym; + } + + if (lnx >= maplen) { + return false; + } + + keysym = map[lnx]; if (keysym == 0) { return false; } -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> 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-7-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- include/ui/kbd-state.h | 12 ++++---- ui/dbus-console.c | 4 +-- ui/gtk.c | 7 +++-- ui/kbd-state.c | 61 +++++++++++++++++++++----------------- ui/keymaps.c | 3 +- ui/sdl2-input.c | 3 +- ui/vnc.c | 10 +++++-- ui/cocoa.m | 67 +++++++++++++++++++++++++++++++----------- 8 files changed, 108 insertions(+), 59 deletions(-) diff --git a/include/ui/kbd-state.h b/include/ui/kbd-state.h index XXXXXXX..XXXXXXX 100644 --- a/include/ui/kbd-state.h +++ b/include/ui/kbd-state.h @@ -XXX,XX +XXX,XX @@ void qkbd_state_free(QKbdState *kbd); * This function takes care to not send suspious events (keyup event * for a key not pressed for example). * + * This function drops events with key codes outside the defined range. + * * @kbd: state tracker state. - * @qcode: the key pressed or released. + * @lnx: the key pressed or released. * @down: true for key down events, false otherwise. */ -void qkbd_state_key_event(QKbdState *kbd, QKeyCode qcode, bool down); +void qkbd_state_key_event(QKbdState *kbd, unsigned int lnx, bool down); /** * qkbd_state_set_delay: set key press delay. @@ -XXX,XX +XXX,XX @@ void qkbd_state_set_delay(QKbdState *kbd, int delay_ms); /** * qkbd_state_key_get: get key state. * - * Returns true when the key is down. + * Returns true when the key code is in the defined range and the key is down. * * @kbd: state tracker state. - * @qcode: the key to query. + * @lnx: the key to query. */ -bool qkbd_state_key_get(QKbdState *kbd, QKeyCode qcode); +bool qkbd_state_key_get(QKbdState *kbd, unsigned int lnx); /** * qkbd_state_modifier_get: get modifier state. diff --git a/ui/dbus-console.c b/ui/dbus-console.c index XXXXXXX..XXXXXXX 100644 --- a/ui/dbus-console.c +++ b/ui/dbus-console.c @@ -XXX,XX +XXX,XX @@ dbus_kbd_press(DBusDisplayConsole *ddc, trace_dbus_kbd_press(arg_keycode); - qkbd_state_key_event(ddc->kbd, qcode, true); + qkbd_state_key_event(ddc->kbd, qemu_input_map_qcode_to_linux[qcode], true); qemu_dbus_display1_keyboard_complete_press(ddc->iface_kbd, invocation); @@ -XXX,XX +XXX,XX @@ dbus_kbd_release(DBusDisplayConsole *ddc, trace_dbus_kbd_release(arg_keycode); - qkbd_state_key_event(ddc->kbd, qcode, false); + qkbd_state_key_event(ddc->kbd, qemu_input_map_qcode_to_linux[qcode], false); qemu_dbus_display1_keyboard_complete_release(ddc->iface_kbd, invocation); diff --git a/ui/gtk.c b/ui/gtk.c index XXXXXXX..XXXXXXX 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -XXX,XX +XXX,XX @@ static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque) || key->hardware_keycode == VK_PAUSE #endif ) { - qkbd_state_key_event(vc->gfx.kbd, Q_KEY_CODE_PAUSE, + qkbd_state_key_event(vc->gfx.kbd, + qemu_input_map_qcode_to_linux[Q_KEY_CODE_PAUSE], key->type == GDK_KEY_PRESS); return TRUE; } @@ -XXX,XX +XXX,XX @@ static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque) keycode = gd_get_keycode(key); qcode = gd_map_keycode(keycode); - trace_gd_key_event(vc->label, keycode, qcode, + trace_gd_key_event(vc->label, keycode, qemu_input_map_qcode_to_linux[qcode], (key->type == GDK_KEY_PRESS) ? "down" : "up"); - qkbd_state_key_event(vc->gfx.kbd, qcode, + qkbd_state_key_event(vc->gfx.kbd, qemu_input_map_qcode_to_linux[qcode], key->type == GDK_KEY_PRESS); return TRUE; diff --git a/ui/kbd-state.c b/ui/kbd-state.c index XXXXXXX..XXXXXXX 100644 --- a/ui/kbd-state.c +++ b/ui/kbd-state.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" #include "qemu/bitmap.h" +#include "standard-headers/linux/input-event-codes.h" #include "ui/console.h" #include "ui/input.h" #include "ui/kbd-state.h" @@ -XXX,XX +XXX,XX @@ struct QKbdState { QemuConsole *con; int key_delay_ms; - DECLARE_BITMAP(keys, Q_KEY_CODE__MAX); + DECLARE_BITMAP(keys, KEY_CNT); DECLARE_BITMAP(mods, QKBD_MOD__MAX); }; static void qkbd_state_modifier_update(QKbdState *kbd, - QKeyCode qcode1, QKeyCode qcode2, + unsigned int lnx1, unsigned int lnx2, QKbdModifier mod) { - if (test_bit(qcode1, kbd->keys) || test_bit(qcode2, kbd->keys)) { + if (test_bit(lnx1, kbd->keys) || test_bit(lnx2, kbd->keys)) { set_bit(mod, kbd->mods); } else { clear_bit(mod, kbd->mods); @@ -XXX,XX +XXX,XX @@ bool qkbd_state_modifier_get(QKbdState *kbd, QKbdModifier mod) return test_bit(mod, kbd->mods); } -bool qkbd_state_key_get(QKbdState *kbd, QKeyCode qcode) +bool qkbd_state_key_get(QKbdState *kbd, unsigned int lnx) { - return test_bit(qcode, kbd->keys); + return lnx < KEY_CNT && test_bit(lnx, kbd->keys); } -void qkbd_state_key_event(QKbdState *kbd, QKeyCode qcode, bool down) +void qkbd_state_key_event(QKbdState *kbd, unsigned int lnx, bool down) { - bool state = test_bit(qcode, kbd->keys); + bool state; + + if (lnx >= KEY_CNT) { + return; + } + + state = test_bit(lnx, kbd->keys); if (down == false /* got key-up event */ && state == false /* key is not pressed */) { @@ -XXX,XX +XXX,XX @@ void qkbd_state_key_event(QKbdState *kbd, QKeyCode qcode, bool down) /* update key and modifier state */ if (down) { - set_bit(qcode, kbd->keys); + set_bit(lnx, kbd->keys); } else { - clear_bit(qcode, kbd->keys); + clear_bit(lnx, kbd->keys); } - switch (qcode) { - case Q_KEY_CODE_SHIFT: - case Q_KEY_CODE_SHIFT_R: - qkbd_state_modifier_update(kbd, Q_KEY_CODE_SHIFT, Q_KEY_CODE_SHIFT_R, + switch (lnx) { + case KEY_LEFTSHIFT: + case KEY_RIGHTSHIFT: + qkbd_state_modifier_update(kbd, KEY_LEFTSHIFT, KEY_RIGHTSHIFT, QKBD_MOD_SHIFT); break; - case Q_KEY_CODE_CTRL: - case Q_KEY_CODE_CTRL_R: - qkbd_state_modifier_update(kbd, Q_KEY_CODE_CTRL, Q_KEY_CODE_CTRL_R, + case KEY_LEFTCTRL: + case KEY_RIGHTCTRL: + qkbd_state_modifier_update(kbd, KEY_LEFTCTRL, KEY_RIGHTCTRL, QKBD_MOD_CTRL); break; - case Q_KEY_CODE_ALT: - qkbd_state_modifier_update(kbd, Q_KEY_CODE_ALT, Q_KEY_CODE_ALT, + case KEY_LEFTALT: + qkbd_state_modifier_update(kbd, KEY_LEFTALT, KEY_LEFTALT, QKBD_MOD_ALT); break; - case Q_KEY_CODE_ALT_R: - qkbd_state_modifier_update(kbd, Q_KEY_CODE_ALT_R, Q_KEY_CODE_ALT_R, + case KEY_RIGHTALT: + qkbd_state_modifier_update(kbd, KEY_RIGHTALT, KEY_RIGHTALT, QKBD_MOD_ALTGR); break; - case Q_KEY_CODE_CAPS_LOCK: + case KEY_CAPSLOCK: if (down) { change_bit(QKBD_MOD_CAPSLOCK, kbd->mods); } break; - case Q_KEY_CODE_NUM_LOCK: + case KEY_NUMLOCK: if (down) { change_bit(QKBD_MOD_NUMLOCK, kbd->mods); } @@ -XXX,XX +XXX,XX @@ void qkbd_state_key_event(QKbdState *kbd, QKeyCode qcode, bool down) /* send to guest */ if (qemu_console_is_graphic(kbd->con)) { - qemu_input_event_send_key_qcode(kbd->con, qcode, down); + qemu_input_event_send_key_linux(kbd->con, lnx, down); if (kbd->key_delay_ms) { qemu_input_event_send_key_delay(kbd->key_delay_ms); } @@ -XXX,XX +XXX,XX @@ void qkbd_state_key_event(QKbdState *kbd, QKeyCode qcode, bool down) void qkbd_state_lift_all_keys(QKbdState *kbd) { - int qcode; + unsigned int lnx; - for (qcode = 0; qcode < Q_KEY_CODE__MAX; qcode++) { - if (test_bit(qcode, kbd->keys)) { - qkbd_state_key_event(kbd, qcode, false); + for (lnx = 0; lnx < KEY_CNT; lnx++) { + if (test_bit(lnx, kbd->keys)) { + qkbd_state_key_event(kbd, lnx, false); } } } diff --git a/ui/keymaps.c b/ui/keymaps.c index XXXXXXX..XXXXXXX 100644 --- a/ui/keymaps.c +++ b/ui/keymaps.c @@ -XXX,XX +XXX,XX @@ int keysym2scancode(kbd_layout_t *k, int keysym, for (i = 0; i < keysym2code->count; i++) { QKeyCode qcode = qemu_input_key_number_to_qcode (keysym2code->keycodes[i]); - if (kbd && qkbd_state_key_get(kbd, qcode)) { + unsigned int lnx = qemu_input_map_qcode_to_linux[qcode]; + if (kbd && qkbd_state_key_get(kbd, lnx)) { return keysym2code->keycodes[i]; } } diff --git a/ui/sdl2-input.c b/ui/sdl2-input.c index XXXXXXX..XXXXXXX 100644 --- a/ui/sdl2-input.c +++ b/ui/sdl2-input.c @@ -XXX,XX +XXX,XX @@ void sdl2_process_key(struct sdl2_console *scon, qcode = qemu_input_map_usb_to_qcode[ev->keysym.scancode]; trace_sdl2_process_key(ev->keysym.scancode, qcode, ev->type == SDL_KEYDOWN ? "down" : "up"); - qkbd_state_key_event(scon->kbd, qcode, ev->type == SDL_KEYDOWN); + qkbd_state_key_event(scon->kbd, qemu_input_map_qcode_to_linux[qcode], + ev->type == SDL_KEYDOWN); if (QEMU_IS_TEXT_CONSOLE(con)) { QemuTextConsole *s = QEMU_TEXT_CONSOLE(con); diff --git a/ui/vnc.c b/ui/vnc.c index XXXXXXX..XXXXXXX 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -XXX,XX +XXX,XX @@ static void pointer_event(VncState *vs, int button_mask, int x, int y) static void press_key(VncState *vs, QKeyCode qcode) { - qkbd_state_key_event(vs->vd->kbd, qcode, true); - qkbd_state_key_event(vs->vd->kbd, qcode, false); + qkbd_state_key_event(vs->vd->kbd, qemu_input_map_qcode_to_linux[qcode], + true); + + qkbd_state_key_event(vs->vd->kbd, qemu_input_map_qcode_to_linux[qcode], + false); } static void vnc_led_state_change(VncState *vs) @@ -XXX,XX +XXX,XX @@ static void do_key_event(VncState *vs, int down, int keycode, int sym) } } - qkbd_state_key_event(vs->vd->kbd, qcode, down); + qkbd_state_key_event(vs->vd->kbd, qemu_input_map_qcode_to_linux[qcode], + down); if (QEMU_IS_TEXT_CONSOLE(vs->vd->dcl.con)) { QemuTextConsole *con = QEMU_TEXT_CONSOLE(vs->vd->dcl.con); bool numlock = qkbd_state_modifier_get(vs->vd->kbd, QKBD_MOD_NUMLOCK); diff --git a/ui/cocoa.m b/ui/cocoa.m index XXXXXXX..XXXXXXX 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -XXX,XX +XXX,XX @@ - (void) setFullGrab:(id)sender } - (void) toggleKey: (int)keycode { - qkbd_state_key_event(kbd, keycode, !qkbd_state_key_get(kbd, keycode)); + unsigned int lnx = qemu_input_map_qcode_to_linux[keycode]; + qkbd_state_key_event(kbd, lnx, !qkbd_state_key_get(kbd, lnx)); } // Does the work of sending input to the monitor @@ -XXX,XX +XXX,XX @@ - (bool) handleEventLocked:(NSEvent *)event */ if (!!(modifiers & NSEventModifierFlagCapsLock) != qkbd_state_modifier_get(kbd, QKBD_MOD_CAPSLOCK)) { - qkbd_state_key_event(kbd, Q_KEY_CODE_CAPS_LOCK, true); - qkbd_state_key_event(kbd, Q_KEY_CODE_CAPS_LOCK, false); + qkbd_state_key_event(kbd, + qemu_input_map_qcode_to_linux[Q_KEY_CODE_CAPS_LOCK], + true); + qkbd_state_key_event(kbd, + qemu_input_map_qcode_to_linux[Q_KEY_CODE_CAPS_LOCK], + false); } if (!(modifiers & NSEventModifierFlagShift)) { - qkbd_state_key_event(kbd, Q_KEY_CODE_SHIFT, false); - qkbd_state_key_event(kbd, Q_KEY_CODE_SHIFT_R, false); + qkbd_state_key_event(kbd, + qemu_input_map_qcode_to_linux[Q_KEY_CODE_SHIFT], + false); + qkbd_state_key_event(kbd, + qemu_input_map_qcode_to_linux[Q_KEY_CODE_SHIFT_R], + false); } if (!(modifiers & NSEventModifierFlagControl)) { - qkbd_state_key_event(kbd, Q_KEY_CODE_CTRL, false); - qkbd_state_key_event(kbd, Q_KEY_CODE_CTRL_R, false); + qkbd_state_key_event(kbd, + qemu_input_map_qcode_to_linux[Q_KEY_CODE_CTRL], + false); + qkbd_state_key_event(kbd, + qemu_input_map_qcode_to_linux[Q_KEY_CODE_CTRL_R], + false); } if (!(modifiers & NSEventModifierFlagOption)) { if (swap_opt_cmd) { - qkbd_state_key_event(kbd, Q_KEY_CODE_META_L, false); - qkbd_state_key_event(kbd, Q_KEY_CODE_META_R, false); + qkbd_state_key_event(kbd, + qemu_input_map_qcode_to_linux[Q_KEY_CODE_META_L], + false); + qkbd_state_key_event(kbd, + qemu_input_map_qcode_to_linux[Q_KEY_CODE_META_R], + false); } else { - qkbd_state_key_event(kbd, Q_KEY_CODE_ALT, false); - qkbd_state_key_event(kbd, Q_KEY_CODE_ALT_R, false); + qkbd_state_key_event(kbd, + qemu_input_map_qcode_to_linux[Q_KEY_CODE_ALT], + false); + qkbd_state_key_event(kbd, + qemu_input_map_qcode_to_linux[Q_KEY_CODE_ALT_R], + false); } } if (!(modifiers & NSEventModifierFlagCommand)) { if (swap_opt_cmd) { - qkbd_state_key_event(kbd, Q_KEY_CODE_ALT, false); - qkbd_state_key_event(kbd, Q_KEY_CODE_ALT_R, false); + qkbd_state_key_event(kbd, + qemu_input_map_qcode_to_linux[Q_KEY_CODE_ALT], + false); + qkbd_state_key_event(kbd, + qemu_input_map_qcode_to_linux[Q_KEY_CODE_ALT_R], + false); } else { - qkbd_state_key_event(kbd, Q_KEY_CODE_META_L, false); - qkbd_state_key_event(kbd, Q_KEY_CODE_META_R, false); + qkbd_state_key_event(kbd, + qemu_input_map_qcode_to_linux[Q_KEY_CODE_META_L], + false); + qkbd_state_key_event(kbd, + qemu_input_map_qcode_to_linux[Q_KEY_CODE_META_R], + false); } } @@ -XXX,XX +XXX,XX @@ - (bool) handleEventLocked:(NSEvent *)event } if (qemu_console_is_graphic(dcl.con)) { - qkbd_state_key_event(kbd, keycode, true); + qkbd_state_key_event(kbd, + qemu_input_map_qcode_to_linux[keycode], + true); } else { [self handleMonitorInput: event]; } @@ -XXX,XX +XXX,XX @@ - (bool) handleEventLocked:(NSEvent *)event } if (qemu_console_is_graphic(dcl.con)) { - qkbd_state_key_event(kbd, keycode, false); + qkbd_state_key_event(kbd, + qemu_input_map_qcode_to_linux[keycode], + false); } return true; case NSEventTypeScrollWheel: -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> 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-8-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- hw/arm/musicpal.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c index XXXXXXX..XXXXXXX 100644 --- a/hw/arm/musicpal.c +++ b/hw/arm/musicpal.c @@ -XXX,XX +XXX,XX @@ #include "hw/core/ptimer.h" #include "hw/core/qdev-properties.h" #include "hw/block/flash.h" +#include "standard-headers/linux/input-event-codes.h" #include "ui/console.h" #include "hw/i2c/i2c.h" #include "hw/i2c/bitbang_i2c.h" @@ -XXX,XX +XXX,XX @@ static void musicpal_key_event(DeviceState *dev, QemuConsole *src, QemuInputEvent *evt) { musicpal_key_state *s = MUSICPAL_KEY(dev); - int qcode = qemu_input_linux_to_qcode(evt->key.key); uint32_t event = 0; int i; - switch (qcode) { - case Q_KEY_CODE_UP: + switch (evt->key.key) { + case KEY_UP: event = MP_KEY_WHEEL_NAV | MP_KEY_WHEEL_NAV_INV; break; - case Q_KEY_CODE_DOWN: + case KEY_DOWN: event = MP_KEY_WHEEL_NAV; break; - case Q_KEY_CODE_LEFT: + case KEY_LEFT: event = MP_KEY_WHEEL_VOL | MP_KEY_WHEEL_VOL_INV; break; - case Q_KEY_CODE_RIGHT: + case KEY_RIGHT: event = MP_KEY_WHEEL_VOL; break; - case Q_KEY_CODE_F: + case KEY_F: event = MP_KEY_BTN_FAVORITS; break; - case Q_KEY_CODE_TAB: + case KEY_TAB: event = MP_KEY_BTN_VOLUME; break; - case Q_KEY_CODE_RET: + case KEY_ENTER: event = MP_KEY_BTN_NAVIGATION; break; - case Q_KEY_CODE_M: + case KEY_M: event = MP_KEY_BTN_MENU; break; } -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> 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-9-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- hw/char/escc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hw/char/escc.c b/hw/char/escc.c index XXXXXXX..XXXXXXX 100644 --- a/hw/char/escc.c +++ b/hw/char/escc.c @@ -XXX,XX +XXX,XX @@ #include "migration/vmstate.h" #include "qemu/module.h" #include "hw/char/escc.h" +#include "standard-headers/linux/input-event-codes.h" #include "ui/console.h" #include "qemu/cutils.h" @@ -XXX,XX +XXX,XX @@ static void sunkbd_handle_event(DeviceState *dev, QemuConsole *src, trace_escc_sunkbd_event_in(qcode, QKeyCode_str(qcode), evt->key.down); - if (qcode == Q_KEY_CODE_CAPS_LOCK) { + if (evt->key.key == KEY_CAPSLOCK) { if (evt->key.down) { s->caps_lock_mode ^= 1; if (s->caps_lock_mode == 2) { @@ -XXX,XX +XXX,XX @@ static void sunkbd_handle_event(DeviceState *dev, QemuConsole *src, } } - if (qcode == Q_KEY_CODE_NUM_LOCK) { + if (evt->key.key == KEY_NUMLOCK) { if (evt->key.down) { s->num_lock_mode ^= 1; if (s->num_lock_mode == 2) { @@ -XXX,XX +XXX,XX @@ static void sunkbd_handle_event(DeviceState *dev, QemuConsole *src, } } - if (qcode >= qemu_input_map_qcode_to_sun_len) { + if (evt->key.key >= qemu_input_map_linux_to_sun_len) { return; } - keycode = qemu_input_map_qcode_to_sun[qcode]; + keycode = qemu_input_map_linux_to_sun[evt->key.key]; if (!evt->key.down) { keycode |= 0x80; } -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> 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-10-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- hw/display/xenfb.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/hw/display/xenfb.c b/hw/display/xenfb.c index XXXXXXX..XXXXXXX 100644 --- a/hw/display/xenfb.c +++ b/hw/display/xenfb.c @@ -XXX,XX +XXX,XX @@ static int xenfb_send_position(struct XenInput *xenfb, return xenfb_kbd_event(xenfb, &event); } -/* - * Send a key event from the client to the guest OS - * QEMU gives us a QCode. - * We have to turn this into a Linux Input layer keycode. - * - * Wish we could just send scancodes straight to the guest which - * already has code for dealing with this... - */ +/* Send a key event from the client to the guest OS */ static void xenfb_key_event(DeviceState *dev, QemuConsole *src, QemuInputEvent *evt) { struct XenInput *xenfb = (struct XenInput *)dev; - int qcode = qemu_input_linux_to_qcode(evt->key.key); - int lnx; - if (qcode < qemu_input_map_qcode_to_linux_len) { - lnx = qemu_input_map_qcode_to_linux[qcode]; - - if (lnx) { - trace_xenfb_key_event(xenfb, lnx, evt->key.down); - xenfb_send_key(xenfb, evt->key.down, lnx); - } - } + trace_xenfb_key_event(xenfb, evt->key.key, evt->key.down); + xenfb_send_key(xenfb, evt->key.down, evt->key.key); } /* -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> 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-11-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- hw/input/adb-kbd.c | 242 ++++++++++++++++++++++----------------------- 1 file changed, 120 insertions(+), 122 deletions(-) diff --git a/hw/input/adb-kbd.c b/hw/input/adb-kbd.c index XXXXXXX..XXXXXXX 100644 --- a/hw/input/adb-kbd.c +++ b/hw/input/adb-kbd.c @@ -XXX,XX +XXX,XX @@ #include "hw/input/adb.h" #include "migration/vmstate.h" #include "qemu/module.h" +#include "standard-headers/linux/input-event-codes.h" #include "ui/input.h" #include "hw/input/adb-keys.h" #include "adb-internal.h" @@ -XXX,XX +XXX,XX @@ struct ADBKeyboardClass { /* The adb keyboard doesn't have every key imaginable */ #define NO_KEY 0xff -int qcode_to_adb_keycode[] = { +int linux_to_adb_keycode[] = { /* Make sure future additions are automatically set to NO_KEY */ - [0 ... 0xff] = NO_KEY, - - [Q_KEY_CODE_SHIFT] = ADB_KEY_LEFT_SHIFT, - [Q_KEY_CODE_SHIFT_R] = ADB_KEY_RIGHT_SHIFT, - [Q_KEY_CODE_ALT] = ADB_KEY_LEFT_OPTION, - [Q_KEY_CODE_ALT_R] = ADB_KEY_RIGHT_OPTION, - [Q_KEY_CODE_CTRL] = ADB_KEY_LEFT_CONTROL, - [Q_KEY_CODE_CTRL_R] = ADB_KEY_RIGHT_CONTROL, - [Q_KEY_CODE_META_L] = ADB_KEY_COMMAND, - [Q_KEY_CODE_META_R] = ADB_KEY_COMMAND, - [Q_KEY_CODE_SPC] = ADB_KEY_SPACEBAR, - - [Q_KEY_CODE_ESC] = ADB_KEY_ESC, - [Q_KEY_CODE_1] = ADB_KEY_1, - [Q_KEY_CODE_2] = ADB_KEY_2, - [Q_KEY_CODE_3] = ADB_KEY_3, - [Q_KEY_CODE_4] = ADB_KEY_4, - [Q_KEY_CODE_5] = ADB_KEY_5, - [Q_KEY_CODE_6] = ADB_KEY_6, - [Q_KEY_CODE_7] = ADB_KEY_7, - [Q_KEY_CODE_8] = ADB_KEY_8, - [Q_KEY_CODE_9] = ADB_KEY_9, - [Q_KEY_CODE_0] = ADB_KEY_0, - [Q_KEY_CODE_MINUS] = ADB_KEY_MINUS, - [Q_KEY_CODE_EQUAL] = ADB_KEY_EQUAL, - [Q_KEY_CODE_BACKSPACE] = ADB_KEY_DELETE, - [Q_KEY_CODE_TAB] = ADB_KEY_TAB, - [Q_KEY_CODE_Q] = ADB_KEY_Q, - [Q_KEY_CODE_W] = ADB_KEY_W, - [Q_KEY_CODE_E] = ADB_KEY_E, - [Q_KEY_CODE_R] = ADB_KEY_R, - [Q_KEY_CODE_T] = ADB_KEY_T, - [Q_KEY_CODE_Y] = ADB_KEY_Y, - [Q_KEY_CODE_U] = ADB_KEY_U, - [Q_KEY_CODE_I] = ADB_KEY_I, - [Q_KEY_CODE_O] = ADB_KEY_O, - [Q_KEY_CODE_P] = ADB_KEY_P, - [Q_KEY_CODE_BRACKET_LEFT] = ADB_KEY_LEFT_BRACKET, - [Q_KEY_CODE_BRACKET_RIGHT] = ADB_KEY_RIGHT_BRACKET, - [Q_KEY_CODE_RET] = ADB_KEY_RETURN, - [Q_KEY_CODE_A] = ADB_KEY_A, - [Q_KEY_CODE_S] = ADB_KEY_S, - [Q_KEY_CODE_D] = ADB_KEY_D, - [Q_KEY_CODE_F] = ADB_KEY_F, - [Q_KEY_CODE_G] = ADB_KEY_G, - [Q_KEY_CODE_H] = ADB_KEY_H, - [Q_KEY_CODE_J] = ADB_KEY_J, - [Q_KEY_CODE_K] = ADB_KEY_K, - [Q_KEY_CODE_L] = ADB_KEY_L, - [Q_KEY_CODE_SEMICOLON] = ADB_KEY_SEMICOLON, - [Q_KEY_CODE_APOSTROPHE] = ADB_KEY_APOSTROPHE, - [Q_KEY_CODE_GRAVE_ACCENT] = ADB_KEY_GRAVE_ACCENT, - [Q_KEY_CODE_BACKSLASH] = ADB_KEY_BACKSLASH, - [Q_KEY_CODE_Z] = ADB_KEY_Z, - [Q_KEY_CODE_X] = ADB_KEY_X, - [Q_KEY_CODE_C] = ADB_KEY_C, - [Q_KEY_CODE_V] = ADB_KEY_V, - [Q_KEY_CODE_B] = ADB_KEY_B, - [Q_KEY_CODE_N] = ADB_KEY_N, - [Q_KEY_CODE_M] = ADB_KEY_M, - [Q_KEY_CODE_COMMA] = ADB_KEY_COMMA, - [Q_KEY_CODE_DOT] = ADB_KEY_PERIOD, - [Q_KEY_CODE_SLASH] = ADB_KEY_FORWARD_SLASH, - [Q_KEY_CODE_ASTERISK] = ADB_KEY_KP_MULTIPLY, - [Q_KEY_CODE_CAPS_LOCK] = ADB_KEY_CAPS_LOCK, - - [Q_KEY_CODE_F1] = ADB_KEY_F1, - [Q_KEY_CODE_F2] = ADB_KEY_F2, - [Q_KEY_CODE_F3] = ADB_KEY_F3, - [Q_KEY_CODE_F4] = ADB_KEY_F4, - [Q_KEY_CODE_F5] = ADB_KEY_F5, - [Q_KEY_CODE_F6] = ADB_KEY_F6, - [Q_KEY_CODE_F7] = ADB_KEY_F7, - [Q_KEY_CODE_F8] = ADB_KEY_F8, - [Q_KEY_CODE_F9] = ADB_KEY_F9, - [Q_KEY_CODE_F10] = ADB_KEY_F10, - [Q_KEY_CODE_F11] = ADB_KEY_F11, - [Q_KEY_CODE_F12] = ADB_KEY_F12, - [Q_KEY_CODE_PRINT] = ADB_KEY_F13, - [Q_KEY_CODE_SYSRQ] = ADB_KEY_F13, - [Q_KEY_CODE_SCROLL_LOCK] = ADB_KEY_F14, - [Q_KEY_CODE_PAUSE] = ADB_KEY_F15, - - [Q_KEY_CODE_NUM_LOCK] = ADB_KEY_KP_CLEAR, - [Q_KEY_CODE_KP_EQUALS] = ADB_KEY_KP_EQUAL, - [Q_KEY_CODE_KP_DIVIDE] = ADB_KEY_KP_DIVIDE, - [Q_KEY_CODE_KP_MULTIPLY] = ADB_KEY_KP_MULTIPLY, - [Q_KEY_CODE_KP_SUBTRACT] = ADB_KEY_KP_SUBTRACT, - [Q_KEY_CODE_KP_ADD] = ADB_KEY_KP_PLUS, - [Q_KEY_CODE_KP_ENTER] = ADB_KEY_KP_ENTER, - [Q_KEY_CODE_KP_DECIMAL] = ADB_KEY_KP_PERIOD, - [Q_KEY_CODE_KP_0] = ADB_KEY_KP_0, - [Q_KEY_CODE_KP_1] = ADB_KEY_KP_1, - [Q_KEY_CODE_KP_2] = ADB_KEY_KP_2, - [Q_KEY_CODE_KP_3] = ADB_KEY_KP_3, - [Q_KEY_CODE_KP_4] = ADB_KEY_KP_4, - [Q_KEY_CODE_KP_5] = ADB_KEY_KP_5, - [Q_KEY_CODE_KP_6] = ADB_KEY_KP_6, - [Q_KEY_CODE_KP_7] = ADB_KEY_KP_7, - [Q_KEY_CODE_KP_8] = ADB_KEY_KP_8, - [Q_KEY_CODE_KP_9] = ADB_KEY_KP_9, - - [Q_KEY_CODE_UP] = ADB_KEY_UP, - [Q_KEY_CODE_DOWN] = ADB_KEY_DOWN, - [Q_KEY_CODE_LEFT] = ADB_KEY_LEFT, - [Q_KEY_CODE_RIGHT] = ADB_KEY_RIGHT, - - [Q_KEY_CODE_HELP] = ADB_KEY_HELP, - [Q_KEY_CODE_INSERT] = ADB_KEY_HELP, - [Q_KEY_CODE_DELETE] = ADB_KEY_FORWARD_DELETE, - [Q_KEY_CODE_HOME] = ADB_KEY_HOME, - [Q_KEY_CODE_END] = ADB_KEY_END, - [Q_KEY_CODE_PGUP] = ADB_KEY_PAGE_UP, - [Q_KEY_CODE_PGDN] = ADB_KEY_PAGE_DOWN, - - [Q_KEY_CODE_POWER] = ADB_KEY_POWER + [0 ... KEY_MAX] = NO_KEY, + + [KEY_LEFTSHIFT] = ADB_KEY_LEFT_SHIFT, + [KEY_RIGHTSHIFT] = ADB_KEY_RIGHT_SHIFT, + [KEY_LEFTALT] = ADB_KEY_LEFT_OPTION, + [KEY_RIGHTALT] = ADB_KEY_RIGHT_OPTION, + [KEY_LEFTCTRL] = ADB_KEY_LEFT_CONTROL, + [KEY_RIGHTCTRL] = ADB_KEY_RIGHT_CONTROL, + [KEY_LEFTMETA] = ADB_KEY_COMMAND, + [KEY_RIGHTMETA] = ADB_KEY_COMMAND, + [KEY_SPACE] = ADB_KEY_SPACEBAR, + + [KEY_ESC] = ADB_KEY_ESC, + [KEY_1] = ADB_KEY_1, + [KEY_2] = ADB_KEY_2, + [KEY_3] = ADB_KEY_3, + [KEY_4] = ADB_KEY_4, + [KEY_5] = ADB_KEY_5, + [KEY_6] = ADB_KEY_6, + [KEY_7] = ADB_KEY_7, + [KEY_8] = ADB_KEY_8, + [KEY_9] = ADB_KEY_9, + [KEY_0] = ADB_KEY_0, + [KEY_MINUS] = ADB_KEY_MINUS, + [KEY_EQUAL] = ADB_KEY_EQUAL, + [KEY_BACKSPACE] = ADB_KEY_DELETE, + [KEY_TAB] = ADB_KEY_TAB, + [KEY_Q] = ADB_KEY_Q, + [KEY_W] = ADB_KEY_W, + [KEY_E] = ADB_KEY_E, + [KEY_R] = ADB_KEY_R, + [KEY_T] = ADB_KEY_T, + [KEY_Y] = ADB_KEY_Y, + [KEY_U] = ADB_KEY_U, + [KEY_I] = ADB_KEY_I, + [KEY_O] = ADB_KEY_O, + [KEY_P] = ADB_KEY_P, + [KEY_LEFTBRACE] = ADB_KEY_LEFT_BRACKET, + [KEY_RIGHTBRACE] = ADB_KEY_RIGHT_BRACKET, + [KEY_ENTER] = ADB_KEY_RETURN, + [KEY_A] = ADB_KEY_A, + [KEY_S] = ADB_KEY_S, + [KEY_D] = ADB_KEY_D, + [KEY_F] = ADB_KEY_F, + [KEY_G] = ADB_KEY_G, + [KEY_H] = ADB_KEY_H, + [KEY_J] = ADB_KEY_J, + [KEY_K] = ADB_KEY_K, + [KEY_L] = ADB_KEY_L, + [KEY_SEMICOLON] = ADB_KEY_SEMICOLON, + [KEY_APOSTROPHE] = ADB_KEY_APOSTROPHE, + [KEY_GRAVE] = ADB_KEY_GRAVE_ACCENT, + [KEY_BACKSLASH] = ADB_KEY_BACKSLASH, + [KEY_Z] = ADB_KEY_Z, + [KEY_X] = ADB_KEY_X, + [KEY_C] = ADB_KEY_C, + [KEY_V] = ADB_KEY_V, + [KEY_B] = ADB_KEY_B, + [KEY_N] = ADB_KEY_N, + [KEY_M] = ADB_KEY_M, + [KEY_COMMA] = ADB_KEY_COMMA, + [KEY_DOT] = ADB_KEY_PERIOD, + [KEY_SLASH] = ADB_KEY_FORWARD_SLASH, + [KEY_CAPSLOCK] = ADB_KEY_CAPS_LOCK, + + [KEY_F1] = ADB_KEY_F1, + [KEY_F2] = ADB_KEY_F2, + [KEY_F3] = ADB_KEY_F3, + [KEY_F4] = ADB_KEY_F4, + [KEY_F5] = ADB_KEY_F5, + [KEY_F6] = ADB_KEY_F6, + [KEY_F7] = ADB_KEY_F7, + [KEY_F8] = ADB_KEY_F8, + [KEY_F9] = ADB_KEY_F9, + [KEY_F10] = ADB_KEY_F10, + [KEY_F11] = ADB_KEY_F11, + [KEY_F12] = ADB_KEY_F12, + [KEY_SYSRQ] = ADB_KEY_F13, + [KEY_SCROLLLOCK] = ADB_KEY_F14, + [KEY_PAUSE] = ADB_KEY_F15, + + [KEY_NUMLOCK] = ADB_KEY_KP_CLEAR, + [KEY_KPEQUAL] = ADB_KEY_KP_EQUAL, + [KEY_KPSLASH] = ADB_KEY_KP_DIVIDE, + [KEY_KPASTERISK] = ADB_KEY_KP_MULTIPLY, + [KEY_KPMINUS] = ADB_KEY_KP_SUBTRACT, + [KEY_KPPLUS] = ADB_KEY_KP_PLUS, + [KEY_KPENTER] = ADB_KEY_KP_ENTER, + [KEY_KPDOT] = ADB_KEY_KP_PERIOD, + [KEY_KP0] = ADB_KEY_KP_0, + [KEY_KP1] = ADB_KEY_KP_1, + [KEY_KP2] = ADB_KEY_KP_2, + [KEY_KP3] = ADB_KEY_KP_3, + [KEY_KP4] = ADB_KEY_KP_4, + [KEY_KP5] = ADB_KEY_KP_5, + [KEY_KP6] = ADB_KEY_KP_6, + [KEY_KP7] = ADB_KEY_KP_7, + [KEY_KP8] = ADB_KEY_KP_8, + [KEY_KP9] = ADB_KEY_KP_9, + + [KEY_UP] = ADB_KEY_UP, + [KEY_DOWN] = ADB_KEY_DOWN, + [KEY_LEFT] = ADB_KEY_LEFT, + [KEY_RIGHT] = ADB_KEY_RIGHT, + + [KEY_HELP] = ADB_KEY_HELP, + [KEY_INSERT] = ADB_KEY_HELP, + [KEY_DELETE] = ADB_KEY_FORWARD_DELETE, + [KEY_HOME] = ADB_KEY_HOME, + [KEY_END] = ADB_KEY_END, + [KEY_PAGEUP] = ADB_KEY_PAGE_UP, + [KEY_PAGEDOWN] = ADB_KEY_PAGE_DOWN, + + [KEY_POWER] = ADB_KEY_POWER }; static void adb_kbd_put_keycode(void *opaque, int keycode) @@ -XXX,XX +XXX,XX @@ static void adb_keyboard_event(DeviceState *dev, QemuConsole *src, QemuInputEvent *evt) { KBDState *s = (KBDState *)dev; - int qcode, keycode; + int keycode; - qcode = qemu_input_linux_to_qcode(evt->key.key); - if (qcode >= ARRAY_SIZE(qcode_to_adb_keycode)) { + if (evt->key.key >= ARRAY_SIZE(linux_to_adb_keycode)) { return; } - /* FIXME: take handler into account when translating qcode */ - keycode = qcode_to_adb_keycode[qcode]; + /* FIXME: take handler into account when translating evt->key.key */ + keycode = linux_to_adb_keycode[evt->key.key]; if (keycode == NO_KEY) { /* We don't want to send this to the guest */ trace_adb_device_kbd_no_key(); return; -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> 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-12-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- hw/input/hid.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hw/input/hid.c b/hw/input/hid.c index XXXXXXX..XXXXXXX 100644 --- a/hw/input/hid.c +++ b/hw/input/hid.c @@ -XXX,XX +XXX,XX @@ static void hid_keyboard_event(DeviceState *dev, QemuConsole *src, QemuInputEvent *evt) { HIDState *hs = (HIDState *)dev; - int qcode = qemu_input_linux_to_qcode(evt->key.key); int scancodes[3], i, count; int slot; - count = qemu_input_qcode_to_scancode(qcode, evt->key.down, + count = qemu_input_linux_to_scancode(evt->key.key, evt->key.down, scancodes); if (hs->n + count > QUEUE_LENGTH) { trace_hid_kbd_queue_full(); -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> 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-13-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- hw/input/ps2.c | 51 +++++++++++++++++++++---------------------- hw/input/trace-events | 2 +- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/hw/input/ps2.c b/hw/input/ps2.c index XXXXXXX..XXXXXXX 100644 --- a/hw/input/ps2.c +++ b/hw/input/ps2.c @@ -XXX,XX +XXX,XX @@ #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" @@ -XXX,XX +XXX,XX @@ static uint8_t translate_table[256] = { 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, }; -static unsigned int ps2_modifier_bit(QKeyCode key) +static unsigned int ps2_modifier_bit(unsigned int 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; @@ -XXX,XX +XXX,XX @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src, QemuInputEvent *evt) { PS2KbdState *s = (PS2KbdState *)dev; - int qcode; uint16_t keycode = 0; int mod; @@ -XXX,XX +XXX,XX @@ 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; @@ -XXX,XX +XXX,XX @@ 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); @@ -XXX,XX +XXX,XX @@ 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); @@ -XXX,XX +XXX,XX @@ 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) { @@ -XXX,XX +XXX,XX @@ 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); @@ -XXX,XX +XXX,XX @@ 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); @@ -XXX,XX +XXX,XX @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src, ps2_put_keycode(s, 0x12); } } - } 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_atset2_len) { - keycode = qemu_input_map_qcode_to_atset2[qcode]; + if (evt->key.key < qemu_input_map_linux_to_atset2_len) { + keycode = qemu_input_map_linux_to_atset2[evt->key.key]; } if (keycode) { if (keycode & 0xff00) { @@ -XXX,XX +XXX,XX @@ 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 == 3) { - if (qcode < qemu_input_map_qcode_to_atset3_len) { - keycode = qemu_input_map_qcode_to_atset3[qcode]; + if (evt->key.key < qemu_input_map_linux_to_atset3_len) { + keycode = qemu_input_map_linux_to_atset3[evt->key.key]; } if (keycode) { /* FIXME: break code should be configured on a key by key basis */ @@ -XXX,XX +XXX,XX @@ static void ps2_keyboard_event(DeviceState *dev, QemuConsole *src, ps2_put_keycode(s, keycode); } else { qemu_log_mask(LOG_UNIMP, - "ps2: ignoring key with qcode %d\n", qcode); + "ps2: ignoring key %u\n", evt->key.key); } } } diff --git a/hw/input/trace-events b/hw/input/trace-events index XXXXXXX..XXXXXXX 100644 --- a/hw/input/trace-events +++ b/hw/input/trace-events @@ -XXX,XX +XXX,XX @@ pckbd_kbd_write_data(uint64_t val) "0x%02"PRIx64 # ps2.c ps2_put_keycode(void *opaque, int keycode) "%p keycode 0x%02x" -ps2_keyboard_event(void *opaque, int qcode, int down, unsigned int modifier, unsigned int modifiers, int set, int xlate) "%p qcode %d down %d modifier 0x%x modifiers 0x%x set %d xlate %d" +ps2_keyboard_event(void *opaque, unsigned int lnx, int down, unsigned int modifier, unsigned int modifiers, int set, int xlate) "%p lnx %u down %d modifier 0x%x modifiers 0x%x set %d xlate %d" ps2_read_data(void *opaque) "%p" ps2_set_ledstate(void *s, int ledstate) "%p ledstate %d" ps2_reset_keyboard(void *s) "%p" -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> 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-14-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- hw/input/virtio-input-hid.c | 40 +++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/hw/input/virtio-input-hid.c b/hw/input/virtio-input-hid.c index XXXXXXX..XXXXXXX 100644 --- a/hw/input/virtio-input-hid.c +++ b/hw/input/virtio-input-hid.c @@ -XXX,XX +XXX,XX @@ static void virtio_input_handle_event(DeviceState *dev, QemuConsole *src, { VirtIOInput *vinput = VIRTIO_INPUT(dev); virtio_input_event event; - int qcode; switch (evt->type) { case INPUT_EVENT_KIND_KEY: - qcode = qemu_input_linux_to_qcode(evt->key.key); - if (qcode < qemu_input_map_qcode_to_linux_len && - qemu_input_map_qcode_to_linux[qcode]) { - event.type = cpu_to_le16(EV_KEY); - event.code = cpu_to_le16(qemu_input_map_qcode_to_linux[qcode]); - event.value = cpu_to_le32(evt->key.down ? 1 : 0); - virtio_input_send(vinput, &event); - } else { - if (evt->key.down) { - fprintf(stderr, "%s: unmapped key: %d [%s]\n", __func__, - qcode, QKeyCode_str(qcode)); - } - } + event.type = cpu_to_le16(EV_KEY); + event.code = cpu_to_le16(evt->key.key); + event.value = cpu_to_le32(evt->key.down ? 1 : 0); + virtio_input_send(vinput, &event); break; case INPUT_EVENT_KIND_BTN: if ((evt->btn.button == INPUT_BUTTON_WHEEL_UP || @@ -XXX,XX +XXX,XX @@ static void virtio_keyboard_init(Object *obj) { VirtIOInputHID *vhid = VIRTIO_INPUT_HID(obj); VirtIOInput *vinput = VIRTIO_INPUT(obj); + virtio_input_config ext = { + .select = VIRTIO_INPUT_CFG_EV_BITS, + .subsel = EV_KEY, + .size = DIV_ROUND_UP(KEY_REPLY, 8) + }; + unsigned int i; vhid->handler = &virtio_keyboard_handler; virtio_input_init_config(vinput, virtio_keyboard_config); - virtio_input_extend_config(vinput, qemu_input_map_qcode_to_linux, - qemu_input_map_qcode_to_linux_len, - VIRTIO_INPUT_CFG_EV_BITS, EV_KEY); + + /* + * Cover as many keys as possible since we cannot tell what keys the host + * supports. This follows Linux xen-kbdfront's approach: + * https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/diff/drivers/input/xen-kbdfront.c?id=4ee36dc08e5c4d16d078f59acd6d9d536f9718dd + * + * Stop before KEY_REPLY for migration compatibility. + */ + for (i = KEY_ESC; i < KEY_REPLY; i++) { + ext.u.bitmap[i / 8] |= (1 << (i % 8)); + } + + virtio_input_add_config(vinput, &ext); } static const TypeInfo virtio_keyboard_info = { -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> 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-15-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- hw/m68k/next-kbd.c | 118 ++++++++++++++++++++++----------------------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/hw/m68k/next-kbd.c b/hw/m68k/next-kbd.c index XXXXXXX..XXXXXXX 100644 --- a/hw/m68k/next-kbd.c +++ b/hw/m68k/next-kbd.c @@ -XXX,XX +XXX,XX @@ #include "qemu/log.h" #include "hw/core/sysbus.h" #include "hw/m68k/next-cube.h" +#include "standard-headers/linux/input-event-codes.h" #include "ui/console.h" #include "migration/vmstate.h" #include "qom/object.h" @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps kbd_ops = { .endianness = DEVICE_BIG_ENDIAN, }; -static const int qcode_to_nextkbd_keycode[] = { - [Q_KEY_CODE_ESC] = 0x49, - [Q_KEY_CODE_1] = 0x4a, - [Q_KEY_CODE_2] = 0x4b, - [Q_KEY_CODE_3] = 0x4c, - [Q_KEY_CODE_4] = 0x4d, - [Q_KEY_CODE_5] = 0x50, - [Q_KEY_CODE_6] = 0x4f, - [Q_KEY_CODE_7] = 0x4e, - [Q_KEY_CODE_8] = 0x1e, - [Q_KEY_CODE_9] = 0x1f, - [Q_KEY_CODE_0] = 0x20, - [Q_KEY_CODE_MINUS] = 0x1d, - [Q_KEY_CODE_EQUAL] = 0x1c, - [Q_KEY_CODE_BACKSPACE] = 0x1b, - - [Q_KEY_CODE_Q] = 0x42, - [Q_KEY_CODE_W] = 0x43, - [Q_KEY_CODE_E] = 0x44, - [Q_KEY_CODE_R] = 0x45, - [Q_KEY_CODE_T] = 0x48, - [Q_KEY_CODE_Y] = 0x47, - [Q_KEY_CODE_U] = 0x46, - [Q_KEY_CODE_I] = 0x06, - [Q_KEY_CODE_O] = 0x07, - [Q_KEY_CODE_P] = 0x08, - [Q_KEY_CODE_RET] = 0x2a, - [Q_KEY_CODE_A] = 0x39, - [Q_KEY_CODE_S] = 0x3a, - - [Q_KEY_CODE_D] = 0x3b, - [Q_KEY_CODE_F] = 0x3c, - [Q_KEY_CODE_G] = 0x3d, - [Q_KEY_CODE_H] = 0x40, - [Q_KEY_CODE_J] = 0x3f, - [Q_KEY_CODE_K] = 0x3e, - [Q_KEY_CODE_L] = 0x2d, - [Q_KEY_CODE_SEMICOLON] = 0x2c, - [Q_KEY_CODE_APOSTROPHE] = 0x2b, - [Q_KEY_CODE_GRAVE_ACCENT] = 0x26, - [Q_KEY_CODE_Z] = 0x31, - [Q_KEY_CODE_X] = 0x32, - [Q_KEY_CODE_C] = 0x33, - [Q_KEY_CODE_V] = 0x34, - - [Q_KEY_CODE_B] = 0x35, - [Q_KEY_CODE_N] = 0x37, - [Q_KEY_CODE_M] = 0x36, - [Q_KEY_CODE_COMMA] = 0x2e, - [Q_KEY_CODE_DOT] = 0x2f, - [Q_KEY_CODE_SLASH] = 0x30, - - [Q_KEY_CODE_SPC] = 0x38, +static const int linux_to_nextkbd_keycode[] = { + [KEY_ESC] = 0x49, + [KEY_1] = 0x4a, + [KEY_2] = 0x4b, + [KEY_3] = 0x4c, + [KEY_4] = 0x4d, + [KEY_5] = 0x50, + [KEY_6] = 0x4f, + [KEY_7] = 0x4e, + [KEY_8] = 0x1e, + [KEY_9] = 0x1f, + [KEY_0] = 0x20, + [KEY_MINUS] = 0x1d, + [KEY_EQUAL] = 0x1c, + [KEY_BACKSPACE] = 0x1b, + + [KEY_Q] = 0x42, + [KEY_W] = 0x43, + [KEY_E] = 0x44, + [KEY_R] = 0x45, + [KEY_T] = 0x48, + [KEY_Y] = 0x47, + [KEY_U] = 0x46, + [KEY_I] = 0x06, + [KEY_O] = 0x07, + [KEY_P] = 0x08, + [KEY_ENTER] = 0x2a, + [KEY_A] = 0x39, + [KEY_S] = 0x3a, + + [KEY_D] = 0x3b, + [KEY_F] = 0x3c, + [KEY_G] = 0x3d, + [KEY_H] = 0x40, + [KEY_J] = 0x3f, + [KEY_K] = 0x3e, + [KEY_L] = 0x2d, + [KEY_SEMICOLON] = 0x2c, + [KEY_APOSTROPHE] = 0x2b, + [KEY_GRAVE] = 0x26, + [KEY_Z] = 0x31, + [KEY_X] = 0x32, + [KEY_C] = 0x33, + [KEY_V] = 0x34, + + [KEY_B] = 0x35, + [KEY_N] = 0x37, + [KEY_M] = 0x36, + [KEY_COMMA] = 0x2e, + [KEY_DOT] = 0x2f, + [KEY_SLASH] = 0x30, + + [KEY_SPACE] = 0x38, }; static void nextkbd_put_keycode(NextKBDState *s, int keycode) @@ -XXX,XX +XXX,XX @@ static void nextkbd_event(DeviceState *dev, QemuConsole *src, QemuInputEvent *evt) { NextKBDState *s = NEXTKBD(dev); - int qcode, keycode; + int keycode; - qcode = qemu_input_linux_to_qcode(evt->key.key); - if (qcode >= ARRAY_SIZE(qcode_to_nextkbd_keycode)) { + if (evt->key.key >= ARRAY_SIZE(linux_to_nextkbd_keycode)) { return; } /* Shift key currently has no keycode, so handle separately */ - if (qcode == Q_KEY_CODE_SHIFT) { + if (evt->key.key == KEY_LEFTSHIFT) { if (evt->key.down) { s->shift |= KD_LSHIFT; } else { @@ -XXX,XX +XXX,XX @@ static void nextkbd_event(DeviceState *dev, QemuConsole *src, } } - if (qcode == Q_KEY_CODE_SHIFT_R) { + if (evt->key.key == KEY_RIGHTSHIFT) { if (evt->key.down) { s->shift |= KD_RSHIFT; } else { @@ -XXX,XX +XXX,XX @@ static void nextkbd_event(DeviceState *dev, QemuConsole *src, } } - keycode = qcode_to_nextkbd_keycode[qcode]; + keycode = linux_to_nextkbd_keycode[evt->key.key]; if (!keycode) { return; } -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> 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-16-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- replay/replay-input.c | 20 +++----------------- replay/replay.c | 2 +- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/replay/replay-input.c b/replay/replay-input.c index XXXXXXX..XXXXXXX 100644 --- a/replay/replay-input.c +++ b/replay/replay-input.c @@ -XXX,XX +XXX,XX @@ void replay_save_input_event(QemuInputEvent *evt) switch (evt->type) { case INPUT_EVENT_KIND_KEY: - replay_put_dword(KEY_VALUE_KIND_QCODE); - replay_put_dword(qemu_input_linux_to_qcode(evt->key.key)); + replay_put_dword(evt->key.key); replay_put_byte(evt->key.down); break; case INPUT_EVENT_KIND_BTN: @@ -XXX,XX +XXX,XX @@ void replay_save_input_event(QemuInputEvent *evt) QemuInputEvent *replay_read_input_event(void) { QemuInputEvent *evt = g_new(QemuInputEvent, 1); - int qcode; evt->type = replay_get_dword(); switch (evt->type) { case INPUT_EVENT_KIND_KEY: - switch (replay_get_dword()) { - case KEY_VALUE_KIND_NUMBER: - qcode = qemu_input_key_number_to_qcode(replay_get_qword()); - evt->key.down = replay_get_byte(); - break; - case KEY_VALUE_KIND_QCODE: - qcode = (QKeyCode)replay_get_dword(); - evt->key.down = replay_get_byte(); - break; - default: - g_assert_not_reached(); - } - evt->key.key = qcode < qemu_input_map_qcode_to_linux_len ? - qemu_input_map_qcode_to_linux[qcode] : 0; + evt->key.key = replay_get_dword(); + evt->key.down = replay_get_byte(); break; case INPUT_EVENT_KIND_BTN: evt->btn.button = (InputButton)replay_get_dword(); diff --git a/replay/replay.c b/replay/replay.c index XXXXXXX..XXXXXXX 100644 --- a/replay/replay.c +++ b/replay/replay.c @@ -XXX,XX +XXX,XX @@ /* Current version of the replay mechanism. Increase it when file format changes. */ -#define REPLAY_VERSION 0xe0200d +#define REPLAY_VERSION 0xe0200e /* Size of replay log header */ #define HEADER_SIZE (sizeof(uint32_t) + sizeof(uint64_t)) -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> 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-17-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- ui/cocoa.m | 328 ++++++++++++++++++++++++----------------------------- 1 file changed, 148 insertions(+), 180 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index XXXXXXX..XXXXXXX 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -XXX,XX +XXX,XX @@ #include "qemu/help-texts.h" #include "qemu-main.h" +#include "standard-headers/linux/input-event-codes.h" #include "ui/clipboard.h" #include "ui/console.h" #include "ui/input.h" @@ -XXX,XX +XXX,XX @@ static bool bool_with_bql(BoolCodeBlock block) return val; } -// Mac to QKeyCode conversion -static const int mac_to_qkeycode_map[] = { - [kVK_ANSI_A] = Q_KEY_CODE_A, - [kVK_ANSI_B] = Q_KEY_CODE_B, - [kVK_ANSI_C] = Q_KEY_CODE_C, - [kVK_ANSI_D] = Q_KEY_CODE_D, - [kVK_ANSI_E] = Q_KEY_CODE_E, - [kVK_ANSI_F] = Q_KEY_CODE_F, - [kVK_ANSI_G] = Q_KEY_CODE_G, - [kVK_ANSI_H] = Q_KEY_CODE_H, - [kVK_ANSI_I] = Q_KEY_CODE_I, - [kVK_ANSI_J] = Q_KEY_CODE_J, - [kVK_ANSI_K] = Q_KEY_CODE_K, - [kVK_ANSI_L] = Q_KEY_CODE_L, - [kVK_ANSI_M] = Q_KEY_CODE_M, - [kVK_ANSI_N] = Q_KEY_CODE_N, - [kVK_ANSI_O] = Q_KEY_CODE_O, - [kVK_ANSI_P] = Q_KEY_CODE_P, - [kVK_ANSI_Q] = Q_KEY_CODE_Q, - [kVK_ANSI_R] = Q_KEY_CODE_R, - [kVK_ANSI_S] = Q_KEY_CODE_S, - [kVK_ANSI_T] = Q_KEY_CODE_T, - [kVK_ANSI_U] = Q_KEY_CODE_U, - [kVK_ANSI_V] = Q_KEY_CODE_V, - [kVK_ANSI_W] = Q_KEY_CODE_W, - [kVK_ANSI_X] = Q_KEY_CODE_X, - [kVK_ANSI_Y] = Q_KEY_CODE_Y, - [kVK_ANSI_Z] = Q_KEY_CODE_Z, - - [kVK_ANSI_0] = Q_KEY_CODE_0, - [kVK_ANSI_1] = Q_KEY_CODE_1, - [kVK_ANSI_2] = Q_KEY_CODE_2, - [kVK_ANSI_3] = Q_KEY_CODE_3, - [kVK_ANSI_4] = Q_KEY_CODE_4, - [kVK_ANSI_5] = Q_KEY_CODE_5, - [kVK_ANSI_6] = Q_KEY_CODE_6, - [kVK_ANSI_7] = Q_KEY_CODE_7, - [kVK_ANSI_8] = Q_KEY_CODE_8, - [kVK_ANSI_9] = Q_KEY_CODE_9, - - [kVK_ANSI_Grave] = Q_KEY_CODE_GRAVE_ACCENT, - [kVK_ANSI_Minus] = Q_KEY_CODE_MINUS, - [kVK_ANSI_Equal] = Q_KEY_CODE_EQUAL, - [kVK_Delete] = Q_KEY_CODE_BACKSPACE, - [kVK_CapsLock] = Q_KEY_CODE_CAPS_LOCK, - [kVK_Tab] = Q_KEY_CODE_TAB, - [kVK_Return] = Q_KEY_CODE_RET, - [kVK_ANSI_LeftBracket] = Q_KEY_CODE_BRACKET_LEFT, - [kVK_ANSI_RightBracket] = Q_KEY_CODE_BRACKET_RIGHT, - [kVK_ANSI_Backslash] = Q_KEY_CODE_BACKSLASH, - [kVK_ANSI_Semicolon] = Q_KEY_CODE_SEMICOLON, - [kVK_ANSI_Quote] = Q_KEY_CODE_APOSTROPHE, - [kVK_ANSI_Comma] = Q_KEY_CODE_COMMA, - [kVK_ANSI_Period] = Q_KEY_CODE_DOT, - [kVK_ANSI_Slash] = Q_KEY_CODE_SLASH, - [kVK_Space] = Q_KEY_CODE_SPC, - - [kVK_ANSI_Keypad0] = Q_KEY_CODE_KP_0, - [kVK_ANSI_Keypad1] = Q_KEY_CODE_KP_1, - [kVK_ANSI_Keypad2] = Q_KEY_CODE_KP_2, - [kVK_ANSI_Keypad3] = Q_KEY_CODE_KP_3, - [kVK_ANSI_Keypad4] = Q_KEY_CODE_KP_4, - [kVK_ANSI_Keypad5] = Q_KEY_CODE_KP_5, - [kVK_ANSI_Keypad6] = Q_KEY_CODE_KP_6, - [kVK_ANSI_Keypad7] = Q_KEY_CODE_KP_7, - [kVK_ANSI_Keypad8] = Q_KEY_CODE_KP_8, - [kVK_ANSI_Keypad9] = Q_KEY_CODE_KP_9, - [kVK_ANSI_KeypadDecimal] = Q_KEY_CODE_KP_DECIMAL, - [kVK_ANSI_KeypadEnter] = Q_KEY_CODE_KP_ENTER, - [kVK_ANSI_KeypadPlus] = Q_KEY_CODE_KP_ADD, - [kVK_ANSI_KeypadMinus] = Q_KEY_CODE_KP_SUBTRACT, - [kVK_ANSI_KeypadMultiply] = Q_KEY_CODE_KP_MULTIPLY, - [kVK_ANSI_KeypadDivide] = Q_KEY_CODE_KP_DIVIDE, - [kVK_ANSI_KeypadEquals] = Q_KEY_CODE_KP_EQUALS, - [kVK_ANSI_KeypadClear] = Q_KEY_CODE_NUM_LOCK, - - [kVK_UpArrow] = Q_KEY_CODE_UP, - [kVK_DownArrow] = Q_KEY_CODE_DOWN, - [kVK_LeftArrow] = Q_KEY_CODE_LEFT, - [kVK_RightArrow] = Q_KEY_CODE_RIGHT, - - [kVK_Help] = Q_KEY_CODE_INSERT, - [kVK_Home] = Q_KEY_CODE_HOME, - [kVK_PageUp] = Q_KEY_CODE_PGUP, - [kVK_PageDown] = Q_KEY_CODE_PGDN, - [kVK_End] = Q_KEY_CODE_END, - [kVK_ForwardDelete] = Q_KEY_CODE_DELETE, - - [kVK_Escape] = Q_KEY_CODE_ESC, +// Mac to Linux conversion +static const unsigned int mac_to_linux_map[] = { + [kVK_ANSI_A] = KEY_A, + [kVK_ANSI_B] = KEY_B, + [kVK_ANSI_C] = KEY_C, + [kVK_ANSI_D] = KEY_D, + [kVK_ANSI_E] = KEY_E, + [kVK_ANSI_F] = KEY_F, + [kVK_ANSI_G] = KEY_G, + [kVK_ANSI_H] = KEY_H, + [kVK_ANSI_I] = KEY_I, + [kVK_ANSI_J] = KEY_J, + [kVK_ANSI_K] = KEY_K, + [kVK_ANSI_L] = KEY_L, + [kVK_ANSI_M] = KEY_M, + [kVK_ANSI_N] = KEY_N, + [kVK_ANSI_O] = KEY_O, + [kVK_ANSI_P] = KEY_P, + [kVK_ANSI_Q] = KEY_Q, + [kVK_ANSI_R] = KEY_R, + [kVK_ANSI_S] = KEY_S, + [kVK_ANSI_T] = KEY_T, + [kVK_ANSI_U] = KEY_U, + [kVK_ANSI_V] = KEY_V, + [kVK_ANSI_W] = KEY_W, + [kVK_ANSI_X] = KEY_X, + [kVK_ANSI_Y] = KEY_Y, + [kVK_ANSI_Z] = KEY_Z, + + [kVK_ANSI_0] = KEY_0, + [kVK_ANSI_1] = KEY_1, + [kVK_ANSI_2] = KEY_2, + [kVK_ANSI_3] = KEY_3, + [kVK_ANSI_4] = KEY_4, + [kVK_ANSI_5] = KEY_5, + [kVK_ANSI_6] = KEY_6, + [kVK_ANSI_7] = KEY_7, + [kVK_ANSI_8] = KEY_8, + [kVK_ANSI_9] = KEY_9, + + [kVK_ANSI_Grave] = KEY_GRAVE, + [kVK_ANSI_Minus] = KEY_MINUS, + [kVK_ANSI_Equal] = KEY_EQUAL, + [kVK_Delete] = KEY_BACKSPACE, + [kVK_CapsLock] = KEY_CAPSLOCK, + [kVK_Tab] = KEY_TAB, + [kVK_Return] = KEY_ENTER, + [kVK_ANSI_LeftBracket] = KEY_LEFTBRACE, + [kVK_ANSI_RightBracket] = KEY_RIGHTBRACE, + [kVK_ANSI_Backslash] = KEY_BACKSLASH, + [kVK_ANSI_Semicolon] = KEY_SEMICOLON, + [kVK_ANSI_Quote] = KEY_APOSTROPHE, + [kVK_ANSI_Comma] = KEY_COMMA, + [kVK_ANSI_Period] = KEY_DOT, + [kVK_ANSI_Slash] = KEY_SLASH, + [kVK_Space] = KEY_SPACE, + + [kVK_ANSI_Keypad0] = KEY_KP0, + [kVK_ANSI_Keypad1] = KEY_KP1, + [kVK_ANSI_Keypad2] = KEY_KP2, + [kVK_ANSI_Keypad3] = KEY_KP3, + [kVK_ANSI_Keypad4] = KEY_KP4, + [kVK_ANSI_Keypad5] = KEY_KP5, + [kVK_ANSI_Keypad6] = KEY_KP6, + [kVK_ANSI_Keypad7] = KEY_KP7, + [kVK_ANSI_Keypad8] = KEY_KP8, + [kVK_ANSI_Keypad9] = KEY_KP9, + [kVK_ANSI_KeypadDecimal] = KEY_KPDOT, + [kVK_ANSI_KeypadEnter] = KEY_KPENTER, + [kVK_ANSI_KeypadPlus] = KEY_KPPLUS, + [kVK_ANSI_KeypadMinus] = KEY_KPMINUS, + [kVK_ANSI_KeypadMultiply] = KEY_KPASTERISK, + [kVK_ANSI_KeypadDivide] = KEY_KPSLASH, + [kVK_ANSI_KeypadEquals] = KEY_KPEQUAL, + [kVK_ANSI_KeypadClear] = KEY_NUMLOCK, + + [kVK_UpArrow] = KEY_UP, + [kVK_DownArrow] = KEY_DOWN, + [kVK_LeftArrow] = KEY_LEFT, + [kVK_RightArrow] = KEY_RIGHT, + + [kVK_Help] = KEY_INSERT, + [kVK_Home] = KEY_HOME, + [kVK_PageUp] = KEY_PAGEUP, + [kVK_PageDown] = KEY_PAGEDOWN, + [kVK_End] = KEY_END, + [kVK_ForwardDelete] = KEY_DELETE, + + [kVK_Escape] = KEY_ESC, /* The Power key can't be used directly because the operating system uses * it. This key can be emulated by using it in place of another key such as * F1. Don't forget to disable the real key binding. */ - /* [kVK_F1] = Q_KEY_CODE_POWER, */ - - [kVK_F1] = Q_KEY_CODE_F1, - [kVK_F2] = Q_KEY_CODE_F2, - [kVK_F3] = Q_KEY_CODE_F3, - [kVK_F4] = Q_KEY_CODE_F4, - [kVK_F5] = Q_KEY_CODE_F5, - [kVK_F6] = Q_KEY_CODE_F6, - [kVK_F7] = Q_KEY_CODE_F7, - [kVK_F8] = Q_KEY_CODE_F8, - [kVK_F9] = Q_KEY_CODE_F9, - [kVK_F10] = Q_KEY_CODE_F10, - [kVK_F11] = Q_KEY_CODE_F11, - [kVK_F12] = Q_KEY_CODE_F12, - [kVK_F13] = Q_KEY_CODE_PRINT, - [kVK_F14] = Q_KEY_CODE_SCROLL_LOCK, - [kVK_F15] = Q_KEY_CODE_PAUSE, + /* [kVK_F1] = KEY_POWER, */ + + [kVK_F1] = KEY_F1, + [kVK_F2] = KEY_F2, + [kVK_F3] = KEY_F3, + [kVK_F4] = KEY_F4, + [kVK_F5] = KEY_F5, + [kVK_F6] = KEY_F6, + [kVK_F7] = KEY_F7, + [kVK_F8] = KEY_F8, + [kVK_F9] = KEY_F9, + [kVK_F10] = KEY_F10, + [kVK_F11] = KEY_F11, + [kVK_F12] = KEY_F12, + [kVK_F13] = KEY_SYSRQ, + [kVK_F14] = KEY_SCROLLLOCK, + [kVK_F15] = KEY_PAUSE, // JIS keyboards only - [kVK_JIS_Yen] = Q_KEY_CODE_YEN, - [kVK_JIS_Underscore] = Q_KEY_CODE_RO, - [kVK_JIS_KeypadComma] = Q_KEY_CODE_KP_COMMA, - [kVK_JIS_Eisu] = Q_KEY_CODE_MUHENKAN, - [kVK_JIS_Kana] = Q_KEY_CODE_HENKAN, + [kVK_JIS_Yen] = KEY_YEN, + [kVK_JIS_Underscore] = KEY_RO, + [kVK_JIS_KeypadComma] = KEY_KPCOMMA, + [kVK_JIS_Eisu] = KEY_MUHENKAN, + [kVK_JIS_Kana] = KEY_HENKAN, /* * The eject and volume keys can't be used here because they are handled at @@ -XXX,XX +XXX,XX @@ static bool bool_with_bql(BoolCodeBlock block) */ }; -static int cocoa_keycode_to_qemu(int keycode) +static unsigned int cocoa_keycode_to_linux(int keycode) { - if (ARRAY_SIZE(mac_to_qkeycode_map) <= keycode) { + if (ARRAY_SIZE(mac_to_linux_map) <= keycode) { error_report("(cocoa) warning unknown keycode 0x%x", keycode); return 0; } - return mac_to_qkeycode_map[keycode]; + return mac_to_linux_map[keycode]; } /* Displays an alert dialog box with the specified message */ @@ -XXX,XX +XXX,XX @@ - (void) setFullGrab:(id)sender CFRelease(tapEventsSrc); } -- (void) toggleKey: (int)keycode { - unsigned int lnx = qemu_input_map_qcode_to_linux[keycode]; - qkbd_state_key_event(kbd, lnx, !qkbd_state_key_get(kbd, lnx)); +- (void) toggleKey: (unsigned int)keycode { + qkbd_state_key_event(kbd, keycode, !qkbd_state_key_get(kbd, keycode)); } // Does the work of sending input to the monitor @@ -XXX,XX +XXX,XX @@ - (bool) handleEventLocked:(NSEvent *)event /* Return true if we handled the event, false if it should be given to OSX */ COCOA_DEBUG("QemuCocoaView: handleEvent\n"); InputButton button; - int keycode = 0; + unsigned int keycode; NSUInteger modifiers = [event modifierFlags]; /* @@ -XXX,XX +XXX,XX @@ - (bool) handleEventLocked:(NSEvent *)event */ if (!!(modifiers & NSEventModifierFlagCapsLock) != qkbd_state_modifier_get(kbd, QKBD_MOD_CAPSLOCK)) { - qkbd_state_key_event(kbd, - qemu_input_map_qcode_to_linux[Q_KEY_CODE_CAPS_LOCK], - true); - qkbd_state_key_event(kbd, - qemu_input_map_qcode_to_linux[Q_KEY_CODE_CAPS_LOCK], - false); + qkbd_state_key_event(kbd, KEY_CAPSLOCK, true); + qkbd_state_key_event(kbd, KEY_CAPSLOCK, false); } if (!(modifiers & NSEventModifierFlagShift)) { - qkbd_state_key_event(kbd, - qemu_input_map_qcode_to_linux[Q_KEY_CODE_SHIFT], - false); - qkbd_state_key_event(kbd, - qemu_input_map_qcode_to_linux[Q_KEY_CODE_SHIFT_R], - false); + qkbd_state_key_event(kbd, KEY_LEFTSHIFT, false); + qkbd_state_key_event(kbd, KEY_RIGHTSHIFT, false); } if (!(modifiers & NSEventModifierFlagControl)) { - qkbd_state_key_event(kbd, - qemu_input_map_qcode_to_linux[Q_KEY_CODE_CTRL], - false); - qkbd_state_key_event(kbd, - qemu_input_map_qcode_to_linux[Q_KEY_CODE_CTRL_R], - false); + qkbd_state_key_event(kbd, KEY_LEFTCTRL, false); + qkbd_state_key_event(kbd, KEY_RIGHTCTRL, false); } if (!(modifiers & NSEventModifierFlagOption)) { if (swap_opt_cmd) { - qkbd_state_key_event(kbd, - qemu_input_map_qcode_to_linux[Q_KEY_CODE_META_L], - false); - qkbd_state_key_event(kbd, - qemu_input_map_qcode_to_linux[Q_KEY_CODE_META_R], - false); + qkbd_state_key_event(kbd, KEY_LEFTMETA, false); + qkbd_state_key_event(kbd, KEY_RIGHTMETA, false); } else { - qkbd_state_key_event(kbd, - qemu_input_map_qcode_to_linux[Q_KEY_CODE_ALT], - false); - qkbd_state_key_event(kbd, - qemu_input_map_qcode_to_linux[Q_KEY_CODE_ALT_R], - false); + qkbd_state_key_event(kbd, KEY_LEFTALT, false); + qkbd_state_key_event(kbd, KEY_RIGHTALT, false); } } if (!(modifiers & NSEventModifierFlagCommand)) { if (swap_opt_cmd) { - qkbd_state_key_event(kbd, - qemu_input_map_qcode_to_linux[Q_KEY_CODE_ALT], - false); - qkbd_state_key_event(kbd, - qemu_input_map_qcode_to_linux[Q_KEY_CODE_ALT_R], - false); + qkbd_state_key_event(kbd, KEY_LEFTALT, false); + qkbd_state_key_event(kbd, KEY_RIGHTALT, false); } else { - qkbd_state_key_event(kbd, - qemu_input_map_qcode_to_linux[Q_KEY_CODE_META_L], - false); - qkbd_state_key_event(kbd, - qemu_input_map_qcode_to_linux[Q_KEY_CODE_META_R], - false); + qkbd_state_key_event(kbd, KEY_LEFTMETA, false); + qkbd_state_key_event(kbd, KEY_RIGHTMETA, false); } } @@ -XXX,XX +XXX,XX @@ - (bool) handleEventLocked:(NSEvent *)event switch ([event keyCode]) { case kVK_Shift: if (!!(modifiers & NSEventModifierFlagShift)) { - [self toggleKey:Q_KEY_CODE_SHIFT]; + [self toggleKey:KEY_LEFTSHIFT]; } break; case kVK_RightShift: if (!!(modifiers & NSEventModifierFlagShift)) { - [self toggleKey:Q_KEY_CODE_SHIFT_R]; + [self toggleKey:KEY_RIGHTSHIFT]; } break; case kVK_Control: if (!!(modifiers & NSEventModifierFlagControl)) { - [self toggleKey:Q_KEY_CODE_CTRL]; + [self toggleKey:KEY_LEFTCTRL]; } break; case kVK_RightControl: if (!!(modifiers & NSEventModifierFlagControl)) { - [self toggleKey:Q_KEY_CODE_CTRL_R]; + [self toggleKey:KEY_RIGHTCTRL]; } break; case kVK_Option: if (!!(modifiers & NSEventModifierFlagOption)) { if (swap_opt_cmd) { - [self toggleKey:Q_KEY_CODE_META_L]; + [self toggleKey:KEY_LEFTMETA]; } else { - [self toggleKey:Q_KEY_CODE_ALT]; + [self toggleKey:KEY_LEFTALT]; } } break; @@ -XXX,XX +XXX,XX @@ - (bool) handleEventLocked:(NSEvent *)event case kVK_RightOption: if (!!(modifiers & NSEventModifierFlagOption)) { if (swap_opt_cmd) { - [self toggleKey:Q_KEY_CODE_META_R]; + [self toggleKey:KEY_RIGHTMETA]; } else { - [self toggleKey:Q_KEY_CODE_ALT_R]; + [self toggleKey:KEY_RIGHTALT]; } } break; @@ -XXX,XX +XXX,XX @@ - (bool) handleEventLocked:(NSEvent *)event !!(modifiers & NSEventModifierFlagCommand) && left_command_key_enabled) { if (swap_opt_cmd) { - [self toggleKey:Q_KEY_CODE_ALT]; + [self toggleKey:KEY_LEFTALT]; } else { - [self toggleKey:Q_KEY_CODE_META_L]; + [self toggleKey:KEY_LEFTMETA]; } } break; @@ -XXX,XX +XXX,XX @@ - (bool) handleEventLocked:(NSEvent *)event if (isMouseGrabbed && !!(modifiers & NSEventModifierFlagCommand)) { if (swap_opt_cmd) { - [self toggleKey:Q_KEY_CODE_ALT_R]; + [self toggleKey:KEY_RIGHTALT]; } else { - [self toggleKey:Q_KEY_CODE_META_R]; + [self toggleKey:KEY_RIGHTMETA]; } } break; } return true; case NSEventTypeKeyDown: - keycode = cocoa_keycode_to_qemu([event keyCode]); + keycode = cocoa_keycode_to_linux([event keyCode]); // forward command key combos to the host UI unless the mouse is grabbed if (!isMouseGrabbed && ([event modifierFlags] & NSEventModifierFlagCommand)) { @@ -XXX,XX +XXX,XX @@ - (bool) handleEventLocked:(NSEvent *)event } if (qemu_console_is_graphic(dcl.con)) { - qkbd_state_key_event(kbd, - qemu_input_map_qcode_to_linux[keycode], - true); + qkbd_state_key_event(kbd, keycode, true); } else { [self handleMonitorInput: event]; } return true; case NSEventTypeKeyUp: - keycode = cocoa_keycode_to_qemu([event keyCode]); + keycode = cocoa_keycode_to_linux([event keyCode]); // don't pass the guest a spurious key-up if we treated this // command-key combo as a host UI action @@ -XXX,XX +XXX,XX @@ - (bool) handleEventLocked:(NSEvent *)event } if (qemu_console_is_graphic(dcl.con)) { - qkbd_state_key_event(kbd, - qemu_input_map_qcode_to_linux[keycode], - false); + qkbd_state_key_event(kbd, keycode, false); } return true; case NSEventTypeScrollWheel: -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> 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-18-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- ui/dbus-console.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ui/dbus-console.c b/ui/dbus-console.c index XXXXXXX..XXXXXXX 100644 --- a/ui/dbus-console.c +++ b/ui/dbus-console.c @@ -XXX,XX +XXX,XX @@ dbus_kbd_press(DBusDisplayConsole *ddc, GDBusMethodInvocation *invocation, guint arg_keycode) { - QKeyCode qcode = qemu_input_key_number_to_qcode(arg_keycode); + unsigned int lnx = qemu_input_key_number_to_linux(arg_keycode); trace_dbus_kbd_press(arg_keycode); - qkbd_state_key_event(ddc->kbd, qemu_input_map_qcode_to_linux[qcode], true); + qkbd_state_key_event(ddc->kbd, lnx, true); qemu_dbus_display1_keyboard_complete_press(ddc->iface_kbd, invocation); @@ -XXX,XX +XXX,XX @@ dbus_kbd_release(DBusDisplayConsole *ddc, GDBusMethodInvocation *invocation, guint arg_keycode) { - QKeyCode qcode = qemu_input_key_number_to_qcode(arg_keycode); + unsigned int lnx = qemu_input_key_number_to_linux(arg_keycode); trace_dbus_kbd_release(arg_keycode); - qkbd_state_key_event(ddc->kbd, qemu_input_map_qcode_to_linux[qcode], false); + qkbd_state_key_event(ddc->kbd, lnx, false); qemu_dbus_display1_keyboard_complete_release(ddc->iface_kbd, invocation); -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> 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-19-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- ui/x_keymap.h | 3 ++- ui/gtk.c | 51 ++++++++++++++++++++++++++++--------------------- ui/x_keymap.c | 24 ++++++++++++----------- ui/trace-events | 2 +- 4 files changed, 45 insertions(+), 35 deletions(-) diff --git a/ui/x_keymap.h b/ui/x_keymap.h index XXXXXXX..XXXXXXX 100644 --- a/ui/x_keymap.h +++ b/ui/x_keymap.h @@ -XXX,XX +XXX,XX @@ #include <X11/Xlib.h> -const guint16 *qemu_xkeymap_mapping_table(Display *dpy, size_t *maplen); +const guint16 *qemu_xkeymap_mapping_table(Display *dpy, size_t *maplen, + bool *evdev); #endif diff --git a/ui/gtk.c b/ui/gtk.c index XXXXXXX..XXXXXXX 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -XXX,XX +XXX,XX @@ #include <math.h> #include "trace.h" +#include "standard-headers/linux/input-event-codes.h" #include "ui/input.h" #include "system/runstate.h" #include "system/system.h" @@ -XXX,XX +XXX,XX @@ static const guint16 *keycode_map; static size_t keycode_maplen; +static bool keycode_xorgevdev; struct VCChardev { Chardev parent; @@ -XXX,XX +XXX,XX @@ static gboolean gd_touch_event(GtkWidget *widget, GdkEventTouch *touch, return TRUE; } -static const guint16 *gd_get_keymap(size_t *maplen) +static const guint16 *gd_get_keymap(size_t *maplen, bool *xorgevdev) { GdkDisplay *dpy = gdk_display_get_default(); + *maplen = 0; + *xorgevdev = false; + #ifdef GDK_WINDOWING_X11 if (GDK_IS_X11_DISPLAY(dpy)) { trace_gd_keymap_windowing("x11"); return qemu_xkeymap_mapping_table( - gdk_x11_display_get_xdisplay(dpy), maplen); + gdk_x11_display_get_xdisplay(dpy), maplen, xorgevdev); } #endif #ifdef GDK_WINDOWING_WAYLAND if (GDK_IS_WAYLAND_DISPLAY(dpy)) { trace_gd_keymap_windowing("wayland"); - *maplen = qemu_input_map_xorgevdev_to_qcode_len; - return qemu_input_map_xorgevdev_to_qcode; + *xorgevdev = true; + return NULL; } #endif #ifdef GDK_WINDOWING_WIN32 if (GDK_IS_WIN32_DISPLAY(dpy)) { trace_gd_keymap_windowing("win32"); - *maplen = qemu_input_map_atset1_to_qcode_len; - return qemu_input_map_atset1_to_qcode; + *maplen = qemu_input_map_atset1_to_linux_len; + return qemu_input_map_atset1_to_linux; } #endif #ifdef GDK_WINDOWING_QUARTZ if (GDK_IS_QUARTZ_DISPLAY(dpy)) { trace_gd_keymap_windowing("quartz"); - *maplen = qemu_input_map_osx_to_qcode_len; - return qemu_input_map_osx_to_qcode; + *maplen = qemu_input_map_osx_to_linux_len; + return qemu_input_map_osx_to_linux; } #endif @@ -XXX,XX +XXX,XX @@ static const guint16 *gd_get_keymap(size_t *maplen) g_warning("experimental: using broadway, x11 virtual keysym\n" "mapping - with very limited support. See also\n" "https://bugzilla.gnome.org/show_bug.cgi?id=700105"); - *maplen = qemu_input_map_x11_to_qcode_len; - return qemu_input_map_x11_to_qcode; + *maplen = qemu_input_map_x11_to_linux_len; + return qemu_input_map_x11_to_linux; } #endif @@ -XXX,XX +XXX,XX @@ static const guint16 *gd_get_keymap(size_t *maplen) } -static int gd_map_keycode(int scancode) +static unsigned int gd_map_keycode(int scancode) { + if (keycode_xorgevdev) { + return scancode < 8 ? KEY_RESERVED : scancode - 8; + } if (!keycode_map) { return 0; } @@ -XXX,XX +XXX,XX @@ static gboolean gd_text_key_down(GtkWidget *widget, QemuTextConsole *con = QEMU_TEXT_CONSOLE(vc->gfx.dcl.con); if (key->keyval == GDK_KEY_Delete) { - qemu_text_console_put_qcode(con, Q_KEY_CODE_DELETE, false); + qemu_text_console_put_linux(con, KEY_DELETE, false); } else if (key->length) { qemu_text_console_put_string(con, key->string, key->length); } else { - int qcode = gd_map_keycode(gd_get_keycode(key)); - qemu_text_console_put_qcode(con, qcode, false); + unsigned int lnx = gd_map_keycode(gd_get_keycode(key)); + qemu_text_console_put_linux(con, lnx, false); } return TRUE; } @@ -XXX,XX +XXX,XX @@ static gboolean gd_text_key_down(GtkWidget *widget, static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque) { VirtualConsole *vc = opaque; - int keycode, qcode; + int keycode; + unsigned int lnx; #ifdef G_OS_WIN32 /* on windows, we ought to ignore the reserved key event? */ @@ -XXX,XX +XXX,XX @@ static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque) || key->hardware_keycode == VK_PAUSE #endif ) { - qkbd_state_key_event(vc->gfx.kbd, - qemu_input_map_qcode_to_linux[Q_KEY_CODE_PAUSE], + qkbd_state_key_event(vc->gfx.kbd, KEY_PAUSE, key->type == GDK_KEY_PRESS); return TRUE; } keycode = gd_get_keycode(key); - qcode = gd_map_keycode(keycode); + lnx = gd_map_keycode(keycode); - trace_gd_key_event(vc->label, keycode, qemu_input_map_qcode_to_linux[qcode], + trace_gd_key_event(vc->label, keycode, lnx, (key->type == GDK_KEY_PRESS) ? "down" : "up"); - qkbd_state_key_event(vc->gfx.kbd, qemu_input_map_qcode_to_linux[qcode], - key->type == GDK_KEY_PRESS); + qkbd_state_key_event(vc->gfx.kbd, lnx, key->type == GDK_KEY_PRESS); return TRUE; } @@ -XXX,XX +XXX,XX @@ static void early_gtk_display_init(DisplayOptions *opts) #endif } - keycode_map = gd_get_keymap(&keycode_maplen); + keycode_map = gd_get_keymap(&keycode_maplen, &keycode_xorgevdev); #if defined(CONFIG_VTE) type_register_static(&char_gd_vc_type_info); diff --git a/ui/x_keymap.c b/ui/x_keymap.c index XXXXXXX..XXXXXXX 100644 --- a/ui/x_keymap.c +++ b/ui/x_keymap.c @@ -XXX,XX +XXX,XX @@ static gboolean check_for_xquartz(Display *dpy) return match; } -const guint16 *qemu_xkeymap_mapping_table(Display *dpy, size_t *maplen) +const guint16 *qemu_xkeymap_mapping_table(Display *dpy, size_t *maplen, + bool *evdev) { XkbDescPtr desc; const gchar *keycodes = NULL; - const guint16 *map; + const guint16 *map = NULL; /* There is no easy way to determine what X11 server * and platform & keyboard driver is in use. Thus we @@ -XXX,XX +XXX,XX @@ const guint16 *qemu_xkeymap_mapping_table(Display *dpy, size_t *maplen) XkbFreeKeyboard(desc, XkbGBN_AllComponentsMask, True); } + *maplen = 0; + *evdev = false; + if (check_for_xwin(dpy)) { trace_xkeymap_keymap("xwin"); - *maplen = qemu_input_map_xorgxwin_to_qcode_len; - map = qemu_input_map_xorgxwin_to_qcode; + *maplen = qemu_input_map_xorgxwin_to_linux_len; + map = qemu_input_map_xorgxwin_to_linux; } else if (check_for_xquartz(dpy)) { trace_xkeymap_keymap("xquartz"); - *maplen = qemu_input_map_xorgxquartz_to_qcode_len; - map = qemu_input_map_xorgxquartz_to_qcode; + *maplen = qemu_input_map_xorgxquartz_to_linux_len; + map = qemu_input_map_xorgxquartz_to_linux; } else if ((keycodes && g_str_has_prefix(keycodes, "evdev")) || (XKeysymToKeycode(dpy, XK_Page_Up) == 0x70)) { trace_xkeymap_keymap("evdev"); - *maplen = qemu_input_map_xorgevdev_to_qcode_len; - map = qemu_input_map_xorgevdev_to_qcode; + *evdev = true; } else if ((keycodes && g_str_has_prefix(keycodes, "xfree86")) || (XKeysymToKeycode(dpy, XK_Page_Up) == 0x63)) { trace_xkeymap_keymap("kbd"); - *maplen = qemu_input_map_xorgkbd_to_qcode_len; - map = qemu_input_map_xorgkbd_to_qcode; + *maplen = qemu_input_map_xorgkbd_to_linux_len; + map = qemu_input_map_xorgkbd_to_linux; } else { trace_xkeymap_keymap("NULL"); g_warning("Unknown X11 keycode mapping '%s'.\n" @@ -XXX,XX +XXX,XX @@ const guint16 *qemu_xkeymap_mapping_table(Display *dpy, size_t *maplen) " - xprop -root\n" " - xdpyinfo\n", keycodes ? keycodes : "<null>"); - map = NULL; } if (keycodes) { XFree((void *)keycodes); diff --git a/ui/trace-events b/ui/trace-events index XXXXXXX..XXXXXXX 100644 --- a/ui/trace-events +++ b/ui/trace-events @@ -XXX,XX +XXX,XX @@ ppm_save(int fd, void *image) "fd=%d image=%p" # 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 qkeycode, const char *action) "tab=%s, translated GDK keycode %d to QKeyCode %d (%s)" +gd_key_event(const char *tab, int gdk_keycode, unsigned int lnx, const char *action) "tab=%s, translated GDK keycode %d to Linux %u (%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" -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> 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-20-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- ui/input-barrier.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/ui/input-barrier.c b/ui/input-barrier.c index XXXXXXX..XXXXXXX 100644 --- a/ui/input-barrier.c +++ b/ui/input-barrier.c @@ -XXX,XX +XXX,XX @@ static const char *cmd_names[] = { static kbd_layout_t *kbd_layout; -static int input_barrier_to_qcode(uint16_t keyid, uint16_t keycode) +static unsigned int input_barrier_to_linux(uint16_t keyid, uint16_t keycode) { /* keycode is optional, if it is not provided use keyid */ - if (keycode && keycode <= qemu_input_map_xorgkbd_to_qcode_len) { - return qemu_input_map_xorgkbd_to_qcode[keycode]; + if (keycode && keycode <= qemu_input_map_xorgkbd_to_linux_len) { + return qemu_input_map_xorgkbd_to_linux[keycode]; } if (keyid >= 0xE000 && keyid <= 0xEFFF) { @@ -XXX,XX +XXX,XX @@ static int input_barrier_to_qcode(uint16_t keyid, uint16_t keycode) if (kbd_layout) { keycode = keysym2scancode(kbd_layout, keyid, NULL, false); - return qemu_input_key_number_to_qcode(keycode); + return qemu_input_key_number_to_linux(keycode); } - return qemu_input_map_x11_to_qcode[keyid]; + return qemu_input_map_x11_to_linux[keyid]; } static int input_barrier_to_mouse(uint8_t buttonid) @@ -XXX,XX +XXX,XX @@ static gboolean writecmd(InputBarrier *ib, struct barrierMsg *msg) /* keyboard */ case barrierCmdDKeyDown: - qemu_input_event_send_key_qcode(NULL, - input_barrier_to_qcode(msg->key.keyid, msg->key.button), + qemu_input_event_send_key_linux(NULL, + input_barrier_to_linux(msg->key.keyid, msg->key.button), true); break; case barrierCmdDKeyRepeat: for (i = 0; i < msg->repeat.repeat; i++) { - qemu_input_event_send_key_qcode(NULL, - input_barrier_to_qcode(msg->repeat.keyid, msg->repeat.button), + qemu_input_event_send_key_linux(NULL, + input_barrier_to_linux(msg->repeat.keyid, msg->repeat.button), false); - qemu_input_event_send_key_qcode(NULL, - input_barrier_to_qcode(msg->repeat.keyid, msg->repeat.button), + qemu_input_event_send_key_linux(NULL, + input_barrier_to_linux(msg->repeat.keyid, msg->repeat.button), true); } break; case barrierCmdDKeyUp: - qemu_input_event_send_key_qcode(NULL, - input_barrier_to_qcode(msg->key.keyid, msg->key.button), + qemu_input_event_send_key_linux(NULL, + input_barrier_to_linux(msg->key.keyid, msg->key.button), false); break; default: -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> 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-21-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- ui/input-legacy.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/ui/input-legacy.c b/ui/input-legacy.c index XXXXXXX..XXXXXXX 100644 --- a/ui/input-legacy.c +++ b/ui/input-legacy.c @@ -XXX,XX +XXX,XX @@ int index_from_key(const char *key, size_t key_length) return i; } -static KeyValue *copy_key_value(KeyValue *src) -{ - KeyValue *dst = g_new(KeyValue, 1); - memcpy(dst, src, sizeof(*src)); - if (dst->type == KEY_VALUE_KIND_NUMBER) { - QKeyCode code = qemu_input_key_number_to_qcode(dst->u.number.data); - dst->type = KEY_VALUE_KIND_QCODE; - dst->u.qcode.data = code; - } - return dst; -} - void qmp_send_key(KeyValueList *keys, bool has_hold_time, int64_t hold_time, Error **errp) { KeyValueList *p; - KeyValue **up = NULL; + unsigned int *up = NULL; int count = 0; if (!has_hold_time) { @@ -XXX,XX +XXX,XX @@ void qmp_send_key(KeyValueList *keys, bool has_hold_time, int64_t hold_time, } for (p = keys; p != NULL; p = p->next) { - qemu_input_event_send_key(NULL, copy_key_value(p->value), true); - qemu_input_event_send_key_delay(hold_time); up = g_realloc(up, sizeof(*up) * (count+1)); - up[count] = copy_key_value(p->value); + up[count] = qemu_input_key_value_to_linux(p->value); + qemu_input_event_send_key_linux(NULL, up[count], true); + qemu_input_event_send_key_delay(hold_time); count++; } while (count) { count--; - qemu_input_event_send_key(NULL, up[count], false); + qemu_input_event_send_key_linux(NULL, up[count], false); qemu_input_event_send_key_delay(hold_time); } g_free(up); -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> 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-22-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- ui/input-linux.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ui/input-linux.c b/ui/input-linux.c index XXXXXXX..XXXXXXX 100644 --- a/ui/input-linux.c +++ b/ui/input-linux.c @@ -XXX,XX +XXX,XX @@ static void input_linux_handle_keyboard(InputLinux *il, /* send event to guest when grab is active */ if (il->grab_active && !input_linux_should_skip(il, event)) { - int qcode = qemu_input_linux_to_qcode(event->code); - qemu_input_event_send_key_qcode(NULL, qcode, event->value); + qemu_input_event_send_key_linux(NULL, event->code, event->value); } /* hotkey -> record switch request ... */ -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> 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-23-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- ui/keymaps.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ui/keymaps.c b/ui/keymaps.c index XXXXXXX..XXXXXXX 100644 --- a/ui/keymaps.c +++ b/ui/keymaps.c @@ -XXX,XX +XXX,XX @@ int keysym2scancode(kbd_layout_t *k, int keysym, * On keyup: Try find a key which is actually down. */ for (i = 0; i < keysym2code->count; i++) { - QKeyCode qcode = qemu_input_key_number_to_qcode + unsigned int lnx = qemu_input_key_number_to_linux (keysym2code->keycodes[i]); - unsigned int lnx = qemu_input_map_qcode_to_linux[qcode]; if (kbd && qkbd_state_key_get(kbd, lnx)) { return keysym2code->keycodes[i]; } -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> 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-24-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- ui/sdl2-input.c | 18 +++++++++--------- ui/trace-events | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ui/sdl2-input.c b/ui/sdl2-input.c index XXXXXXX..XXXXXXX 100644 --- a/ui/sdl2-input.c +++ b/ui/sdl2-input.c @@ -XXX,XX +XXX,XX @@ /* Ported SDL 1.2 code to 2.0 by Dave Airlie. */ #include "qemu/osdep.h" +#include "standard-headers/linux/input-event-codes.h" #include "ui/console.h" #include "ui/input.h" #include "ui/sdl2.h" @@ -XXX,XX +XXX,XX @@ void sdl2_process_key(struct sdl2_console *scon, SDL_KeyboardEvent *ev) { - int qcode; + unsigned int lnx; QemuConsole *con = scon->dcl.con; - if (ev->keysym.scancode >= qemu_input_map_usb_to_qcode_len) { + if (ev->keysym.scancode >= qemu_input_map_usb_to_linux_len) { return; } - qcode = qemu_input_map_usb_to_qcode[ev->keysym.scancode]; - trace_sdl2_process_key(ev->keysym.scancode, qcode, + lnx = qemu_input_map_usb_to_linux[ev->keysym.scancode]; + trace_sdl2_process_key(ev->keysym.scancode, lnx, ev->type == SDL_KEYDOWN ? "down" : "up"); - qkbd_state_key_event(scon->kbd, qemu_input_map_qcode_to_linux[qcode], - ev->type == SDL_KEYDOWN); + qkbd_state_key_event(scon->kbd, lnx, ev->type == SDL_KEYDOWN); if (QEMU_IS_TEXT_CONSOLE(con)) { QemuTextConsole *s = QEMU_TEXT_CONSOLE(con); bool ctrl = qkbd_state_modifier_get(scon->kbd, QKBD_MOD_CTRL); if (ev->type == SDL_KEYDOWN) { - switch (qcode) { - case Q_KEY_CODE_RET: + switch (lnx) { + case KEY_ENTER: qemu_text_console_put_keysym(s, '\n'); break; default: - qemu_text_console_put_qcode(s, qcode, ctrl); + qemu_text_console_put_linux(s, lnx, ctrl); break; } } diff --git a/ui/trace-events b/ui/trace-events index XXXXXXX..XXXXXXX 100644 --- a/ui/trace-events +++ b/ui/trace-events @@ -XXX,XX +XXX,XX @@ input_event_mtt(int conidx, const char *axis, int value) "con %d, axis %s, value input_event_sync(void) "" # sdl2-input.c -sdl2_process_key(int sdl_scancode, int qcode, const char *action) "translated SDL scancode %d to QKeyCode %d (%s)" +sdl2_process_key(int sdl_scancode, unsigned int lnx, const char *action) "translated SDL scancode %d to Linux scancode %u (%s)" # spice-display.c qemu_spice_add_memslot(int qid, uint32_t slot_id, unsigned long virt_start, unsigned long virt_end, int async) "%d %u: host virt 0x%lx - 0x%lx async=%d" -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> 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-25-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- ui/spice-input.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ui/spice-input.c b/ui/spice-input.c index XXXXXXX..XXXXXXX 100644 --- a/ui/spice-input.c +++ b/ui/spice-input.c @@ -XXX,XX +XXX,XX @@ #include <spice.h> #include <spice/enums.h> +#include "standard-headers/linux/input-event-codes.h" #include "ui/qemu-spice.h" #include "ui/console.h" #include "keymaps.h" @@ -XXX,XX +XXX,XX @@ static void kbd_push_key(SpiceKbdInstance *sin, uint8_t scancode) if (scancode == pauseseq[kbd->pauseseq]) { kbd->pauseseq++; if (kbd->pauseseq == G_N_ELEMENTS(pauseseq)) { - qemu_input_event_send_key_qcode(NULL, Q_KEY_CODE_PAUSE, true); + qemu_input_event_send_key_linux(NULL, KEY_PAUSE, true); kbd->pauseseq = 0; } return; -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> 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-26-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- ui/vnc.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index XXXXXXX..XXXXXXX 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -XXX,XX +XXX,XX @@ #include "qapi/qapi-events-ui.h" #include "qapi/error.h" #include "qapi/qapi-commands-ui.h" +#include "standard-headers/linux/input-event-codes.h" #include "ui/console.h" #include "ui/input.h" #include "crypto/hash.h" @@ -XXX,XX +XXX,XX @@ static void pointer_event(VncState *vs, int button_mask, int x, int y) qemu_input_event_sync(); } -static void press_key(VncState *vs, QKeyCode qcode) +static void press_key(VncState *vs, unsigned int lnx) { - qkbd_state_key_event(vs->vd->kbd, qemu_input_map_qcode_to_linux[qcode], - true); - - qkbd_state_key_event(vs->vd->kbd, qemu_input_map_qcode_to_linux[qcode], - false); + qkbd_state_key_event(vs->vd->kbd, lnx, true); + qkbd_state_key_event(vs->vd->kbd, lnx, false); } static void vnc_led_state_change(VncState *vs) @@ -XXX,XX +XXX,XX @@ static void kbd_leds(void *opaque, int ledstate) static void do_key_event(VncState *vs, int down, int keycode, int sym) { - QKeyCode qcode = qemu_input_key_number_to_qcode(keycode); + unsigned int lnx = qemu_input_key_number_to_linux(keycode); /* QEMU console switch */ - switch (qcode) { - case Q_KEY_CODE_1 ... Q_KEY_CODE_9: /* '1' to '9' keys */ + switch (lnx) { + case KEY_1 ... KEY_9: /* '1' to '9' keys */ if (down && qkbd_state_modifier_get(vs->vd->kbd, QKBD_MOD_CTRL) && qkbd_state_modifier_get(vs->vd->kbd, QKBD_MOD_ALT)) { - QemuConsole *con = qemu_console_lookup_by_index(qcode - Q_KEY_CODE_1); + QemuConsole *con = qemu_console_lookup_by_index(lnx - KEY_1); if (con) { qemu_console_unregister_listener(&vs->vd->dcl); qkbd_state_switch_console(vs->vd->kbd, con); @@ -XXX,XX +XXX,XX @@ static void do_key_event(VncState *vs, int down, int keycode, int sym) if (keysym_is_numlock(vs->vd->kbd_layout, sym & 0xFFFF)) { if (!qkbd_state_modifier_get(vs->vd->kbd, QKBD_MOD_NUMLOCK)) { trace_vnc_key_sync_numlock(true); - press_key(vs, Q_KEY_CODE_NUM_LOCK); + press_key(vs, KEY_NUMLOCK); } } else { if (qkbd_state_modifier_get(vs->vd->kbd, QKBD_MOD_NUMLOCK)) { trace_vnc_key_sync_numlock(false); - press_key(vs, Q_KEY_CODE_NUM_LOCK); + press_key(vs, KEY_NUMLOCK); } } } @@ -XXX,XX +XXX,XX @@ static void do_key_event(VncState *vs, int down, int keycode, int sym) if (capslock) { if (uppercase == shift) { trace_vnc_key_sync_capslock(false); - press_key(vs, Q_KEY_CODE_CAPS_LOCK); + press_key(vs, KEY_CAPSLOCK); } } else { if (uppercase != shift) { trace_vnc_key_sync_capslock(true); - press_key(vs, Q_KEY_CODE_CAPS_LOCK); + press_key(vs, KEY_CAPSLOCK); } } } - qkbd_state_key_event(vs->vd->kbd, qemu_input_map_qcode_to_linux[qcode], - down); + qkbd_state_key_event(vs->vd->kbd, lnx, down); if (QEMU_IS_TEXT_CONSOLE(vs->vd->dcl.con)) { QemuTextConsole *con = QEMU_TEXT_CONSOLE(vs->vd->dcl.con); bool numlock = qkbd_state_modifier_get(vs->vd->kbd, QKBD_MOD_NUMLOCK); -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> 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> --- qemu-keymap.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/qemu-keymap.c b/qemu-keymap.c index XXXXXXX..XXXXXXX 100644 --- a/qemu-keymap.c +++ b/qemu-keymap.c @@ -XXX,XX +XXX,XX @@ */ #include "qemu/osdep.h" #include "qemu/notify.h" +#include "standard-headers/linux/input-event-codes.h" #include "ui/input.h" #include <xkbcommon/xkbcommon.h> @@ -XXX,XX +XXX,XX @@ static FILE *outfile; /* ------------------------------------------------------------------------ */ -static uint32_t qcode_to_number(uint32_t qcode) +static uint32_t linux_to_number(uint32_t lnx) { - KeyValue keyvalue; uint32_t number; - keyvalue.type = KEY_VALUE_KIND_QCODE; - keyvalue.u.qcode.data = qcode; - number = qemu_input_key_value_to_number(&keyvalue); + assert(lnx < qemu_input_map_linux_to_qnum_len); + number = qemu_input_map_linux_to_qnum[lnx]; assert(number != 0); return number; } -static void print_sym(xkb_keysym_t sym, uint32_t qcode, const char *mod) +static void print_sym(xkb_keysym_t sym, uint32_t lnx, const char *mod) { char name[64]; @@ -XXX,XX +XXX,XX @@ static void print_sym(xkb_keysym_t sym, uint32_t qcode, const char *mod) xkb_keysym_get_name(sym, name, sizeof(name)); /* TODO: make ui/keymap.c parser accept QKeyCode names */ - fprintf(outfile, "%s 0x%02x%s\n", name, qcode_to_number(qcode), mod); + fprintf(outfile, "%s 0x%02x%s\n", name, linux_to_number(lnx), mod); } static void walk_map(struct xkb_keymap *map, xkb_keycode_t code, void *data) @@ -XXX,XX +XXX,XX @@ static void walk_map(struct xkb_keymap *map, xkb_keycode_t code, void *data) fprintf(outfile, "# evdev %d (0x%x), QKeyCode \"%s\", number 0x%x\n", evdev, evdev, QKeyCode_str(qcode), - qcode_to_number(qcode)); + linux_to_number(evdev)); /* * check which modifier states generate which keysyms */ xkb_state_update_mask(state, 0, 0, 0, 0, 0, 0); kbase = xkb_state_key_get_one_sym(state, code); - print_sym(kbase, qcode, ""); + print_sym(kbase, evdev, ""); xkb_state_update_mask(state, 0, 0, numlock, 0, 0, 0); knumlock = xkb_state_key_get_one_sym(state, code); if (kbase != knumlock) { - print_sym(knumlock, qcode, " numlock"); + print_sym(knumlock, evdev, " numlock"); } xkb_state_update_mask(state, shift, 0, 0, 0, 0, 0); kshift = xkb_state_key_get_one_sym(state, code); if (kbase != kshift && knumlock != kshift) { - print_sym(kshift, qcode, " shift"); + print_sym(kshift, evdev, " shift"); } xkb_state_update_mask(state, altgr, 0, 0, 0, 0, 0); kaltgr = xkb_state_key_get_one_sym(state, code); if (kbase != kaltgr) { - print_sym(kaltgr, qcode, " altgr"); + print_sym(kaltgr, evdev, " altgr"); } xkb_state_update_mask(state, altgr | shift, 0, 0, 0, 0, 0); kaltgrshift = xkb_state_key_get_one_sym(state, code); if (kshift != kaltgrshift && kaltgr != kaltgrshift) { - print_sym(kaltgrshift, qcode, " shift altgr"); + print_sym(kaltgrshift, evdev, " shift altgr"); } } @@ -XXX,XX +XXX,XX @@ int main(int argc, char *argv[]) "# keysyms. So append them here.\n" "#\n" "\n"); - print_sym(XKB_KEY_Print, Q_KEY_CODE_SYSRQ, ""); - print_sym(XKB_KEY_Sys_Req, Q_KEY_CODE_SYSRQ, ""); - print_sym(XKB_KEY_Execute, Q_KEY_CODE_SYSRQ, ""); + print_sym(XKB_KEY_Print, KEY_SYSRQ, ""); + print_sym(XKB_KEY_Sys_Req, KEY_SYSRQ, ""); + print_sym(XKB_KEY_Execute, KEY_SYSRQ, ""); - print_sym(XKB_KEY_KP_Decimal, Q_KEY_CODE_KP_DECIMAL, " numlock"); - print_sym(XKB_KEY_KP_Separator, Q_KEY_CODE_KP_DECIMAL, " numlock"); + print_sym(XKB_KEY_KP_Decimal, KEY_KPDOT, " numlock"); + print_sym(XKB_KEY_KP_Separator, KEY_KPDOT, " numlock"); - print_sym(XKB_KEY_Alt_R, Q_KEY_CODE_ALT_R, ""); - print_sym(XKB_KEY_ISO_Level3_Shift, Q_KEY_CODE_ALT_R, ""); - print_sym(XKB_KEY_Mode_switch, Q_KEY_CODE_ALT_R, ""); + print_sym(XKB_KEY_Alt_R, KEY_RIGHTALT, ""); + print_sym(XKB_KEY_ISO_Level3_Shift, KEY_RIGHTALT, ""); + print_sym(XKB_KEY_Mode_switch, KEY_RIGHTALT, ""); fprintf(outfile, "\n" -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> It is no longer used. 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-28-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- include/ui/console.h | 1 - ui/console.c | 6 ------ 2 files changed, 7 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index XXXXXXX..XXXXXXX 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -XXX,XX +XXX,XX @@ bool qemu_mouse_set(int index, Error **errp); #define QEMU_KEY_CTRL_PAGEDOWN 0xe407 void qemu_text_console_put_keysym(QemuTextConsole *s, int keysym); -bool qemu_text_console_put_qcode(QemuTextConsole *s, int qcode, bool ctrl); bool qemu_text_console_put_linux(QemuTextConsole *s, unsigned int lnx, bool ctrl); void qemu_text_console_put_string(QemuTextConsole *s, const char *str, int len); diff --git a/ui/console.c b/ui/console.c index XXXXXXX..XXXXXXX 100644 --- a/ui/console.c +++ b/ui/console.c @@ -XXX,XX +XXX,XX @@ static const int ctrl_linux_to_keysym[] = { [KEY_PAGEDOWN] = QEMU_KEY_CTRL_PAGEDOWN, }; -bool qemu_text_console_put_qcode(QemuTextConsole *s, int qcode, bool ctrl) -{ - unsigned int lnx = qemu_input_map_qcode_to_linux[qcode]; - return qemu_text_console_put_linux(s, lnx, ctrl); -} - bool qemu_text_console_put_linux(QemuTextConsole *s, unsigned int lnx, bool ctrl) { -- 2.54.0
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> Their users have migrated to Linux key codes. 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-29-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp> --- include/ui/input.h | 50 ------------------------------------------ tools/qemu-vnc/input.c | 6 ----- ui/input-keymap.c | 39 -------------------------------- ui/input.c | 16 -------------- ui/meson.build | 15 ------------- 5 files changed, 126 deletions(-) diff --git a/include/ui/input.h b/include/ui/input.h index XXXXXXX..XXXXXXX 100644 --- a/include/ui/input.h +++ b/include/ui/input.h @@ -XXX,XX +XXX,XX @@ void qemu_input_event_send_impl(QemuConsole *src, QemuInputEvent *evt); void qemu_input_event_sync(void); void qemu_input_event_sync_impl(void); -void qemu_input_event_send_key(QemuConsole *src, KeyValue *key, bool down); void qemu_input_event_send_key_linux(QemuConsole *src, unsigned int lnx, bool down); void qemu_input_event_send_key_number(QemuConsole *src, int num, bool down); -void qemu_input_event_send_key_qcode(QemuConsole *src, QKeyCode q, bool down); void qemu_input_event_send_key_delay(uint32_t delay_ms); int qemu_input_key_number_to_qcode(unsigned int nr); unsigned int qemu_input_key_number_to_linux(unsigned int nr); -int qemu_input_key_value_to_number(const KeyValue *value); -int qemu_input_key_value_to_qcode(const KeyValue *value); unsigned int qemu_input_key_value_to_linux(const KeyValue *value); -int qemu_input_qcode_to_scancode(QKeyCode qcode, bool down, int *codes); int qemu_input_linux_to_scancode(unsigned int lnx, bool down, int *codes); int qemu_input_linux_to_qcode(unsigned int lnx); @@ -XXX,XX +XXX,XX @@ 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_atset1_to_linux_len; extern const guint16 qemu_input_map_atset1_to_linux[]; extern const guint qemu_input_map_linux_to_qcode_len; extern const guint16 qemu_input_map_linux_to_qcode[]; -extern const guint qemu_input_map_qcode_to_atset1_len; -extern const guint16 qemu_input_map_qcode_to_atset1[]; - extern const guint qemu_input_map_linux_to_atset1_len; extern const guint16 qemu_input_map_linux_to_atset1[]; -extern const guint qemu_input_map_qcode_to_atset2_len; -extern const guint16 qemu_input_map_qcode_to_atset2[]; - extern const guint qemu_input_map_linux_to_atset2_len; extern const guint16 qemu_input_map_linux_to_atset2[]; -extern const guint qemu_input_map_qcode_to_atset3_len; -extern const guint16 qemu_input_map_qcode_to_atset3[]; - extern const guint qemu_input_map_linux_to_atset3_len; extern const guint16 qemu_input_map_linux_to_atset3[]; 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_qcode_to_qnum_len; -extern const guint16 qemu_input_map_qcode_to_qnum[]; - extern const guint qemu_input_map_linux_to_qnum_len; extern const guint16 qemu_input_map_linux_to_qnum[]; -extern const guint qemu_input_map_qcode_to_sun_len; -extern const guint16 qemu_input_map_qcode_to_sun[]; - extern const guint qemu_input_map_linux_to_sun_len; extern const guint16 qemu_input_map_linux_to_sun[]; -extern const guint qemu_input_map_qnum_to_qcode_len; -extern const guint16 qemu_input_map_qnum_to_qcode[]; - extern const guint qemu_input_map_qnum_to_linux_len; extern const guint16 qemu_input_map_qnum_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_usb_to_linux_len; extern const guint16 qemu_input_map_usb_to_linux[]; -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_win32_to_linux_len; extern const guint16 qemu_input_map_win32_to_linux[]; -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_x11_to_linux_len; extern const guint16 qemu_input_map_x11_to_linux[]; -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_xorgkbd_to_linux_len; extern const guint16 qemu_input_map_xorgkbd_to_linux[]; -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_xorgxquartz_to_linux_len; extern const guint16 qemu_input_map_xorgxquartz_to_linux[]; -extern const guint qemu_input_map_xorgxwin_to_qcode_len; -extern const guint16 qemu_input_map_xorgxwin_to_qcode[]; - extern const guint qemu_input_map_xorgxwin_to_linux_len; extern const guint16 qemu_input_map_xorgxwin_to_linux[]; -extern const guint qemu_input_map_osx_to_qcode_len; -extern const guint16 qemu_input_map_osx_to_qcode[]; - extern const guint qemu_input_map_osx_to_linux_len; extern const guint16 qemu_input_map_osx_to_linux[]; diff --git a/tools/qemu-vnc/input.c b/tools/qemu-vnc/input.c index XXXXXXX..XXXXXXX 100644 --- a/tools/qemu-vnc/input.c +++ b/tools/qemu-vnc/input.c @@ -XXX,XX +XXX,XX @@ void qemu_input_event_send_key_delay(uint32_t delay_ms) { } -void qemu_input_event_send_key_qcode(QemuConsole *src, QKeyCode q, bool down) -{ - unsigned int lnx = qemu_input_map_qcode_to_linux[q]; - qemu_input_event_send_key_linux(src, lnx, down); -} - void qemu_input_event_send_key_linux(QemuConsole *src, unsigned int lnx, bool down) { diff --git a/ui/input-keymap.c b/ui/input-keymap.c index XXXXXXX..XXXXXXX 100644 --- a/ui/input-keymap.c +++ b/ui/input-keymap.c @@ -XXX,XX +XXX,XX @@ #include "standard-headers/linux/input.h" -#include "ui/input-keymap-atset1-to-qcode.c.inc" #include "ui/input-keymap-atset1-to-linux.c.inc" #include "ui/input-keymap-linux-to-qcode.c.inc" -#include "ui/input-keymap-qcode-to-atset1.c.inc" #include "ui/input-keymap-linux-to-atset1.c.inc" -#include "ui/input-keymap-qcode-to-atset2.c.inc" #include "ui/input-keymap-linux-to-atset2.c.inc" -#include "ui/input-keymap-qcode-to-atset3.c.inc" #include "ui/input-keymap-linux-to-atset3.c.inc" #include "ui/input-keymap-qcode-to-linux.c.inc" -#include "ui/input-keymap-qcode-to-qnum.c.inc" #include "ui/input-keymap-linux-to-qnum.c.inc" -#include "ui/input-keymap-qcode-to-sun.c.inc" #include "ui/input-keymap-linux-to-sun.c.inc" -#include "ui/input-keymap-qnum-to-qcode.c.inc" #include "ui/input-keymap-qnum-to-linux.c.inc" -#include "ui/input-keymap-usb-to-qcode.c.inc" #include "ui/input-keymap-usb-to-linux.c.inc" -#include "ui/input-keymap-win32-to-qcode.c.inc" #include "ui/input-keymap-win32-to-linux.c.inc" -#include "ui/input-keymap-x11-to-qcode.c.inc" #include "ui/input-keymap-x11-to-linux.c.inc" -#include "ui/input-keymap-xorgevdev-to-qcode.c.inc" -#include "ui/input-keymap-xorgkbd-to-qcode.c.inc" #include "ui/input-keymap-xorgkbd-to-linux.c.inc" -#include "ui/input-keymap-xorgxquartz-to-qcode.c.inc" #include "ui/input-keymap-xorgxquartz-to-linux.c.inc" -#include "ui/input-keymap-xorgxwin-to-qcode.c.inc" #include "ui/input-keymap-xorgxwin-to-linux.c.inc" -#include "ui/input-keymap-osx-to-qcode.c.inc" #include "ui/input-keymap-osx-to-linux.c.inc" int qemu_input_linux_to_qcode(unsigned int lnx) @@ -XXX,XX +XXX,XX @@ int qemu_input_linux_to_qcode(unsigned int lnx) return qemu_input_map_linux_to_qcode[lnx]; } -int qemu_input_key_value_to_number(const KeyValue *value) -{ - if (value->type == KEY_VALUE_KIND_QCODE) { - if (value->u.qcode.data >= qemu_input_map_qcode_to_qnum_len) { - return 0; - } - return qemu_input_map_qcode_to_qnum[value->u.qcode.data]; - } else { - assert(value->type == KEY_VALUE_KIND_NUMBER); - return value->u.number.data; - } -} - int qemu_input_key_number_to_qcode(unsigned int nr) { return qemu_input_linux_to_qcode(qemu_input_key_number_to_linux(nr)); @@ -XXX,XX +XXX,XX @@ unsigned int qemu_input_key_number_to_linux(unsigned int nr) return qemu_input_map_qnum_to_linux[nr]; } -int qemu_input_key_value_to_qcode(const KeyValue *value) -{ - return qemu_input_linux_to_qcode(qemu_input_key_value_to_linux(value)); -} - unsigned int qemu_input_key_value_to_linux(const KeyValue *value) { switch (value->type) { @@ -XXX,XX +XXX,XX @@ unsigned int qemu_input_key_value_to_linux(const KeyValue *value) } } -int qemu_input_qcode_to_scancode(QKeyCode qcode, bool down, int *codes) -{ - return qemu_input_linux_to_scancode(qemu_input_map_qcode_to_linux[qcode], - down, codes); -} - int qemu_input_linux_to_scancode(unsigned int lnx, bool down, int *codes) { int keycode = lnx < qemu_input_map_linux_to_qnum_len ? diff --git a/ui/input.c b/ui/input.c index XXXXXXX..XXXXXXX 100644 --- a/ui/input.c +++ b/ui/input.c @@ -XXX,XX +XXX,XX @@ void qemu_input_event_sync(void) replay_input_sync_event(); } -void qemu_input_event_send_key(QemuConsole *src, KeyValue *key, bool down) -{ - unsigned int lnx = qemu_input_key_value_to_linux(key); - - g_free(key); - qemu_input_event_send_key_linux(src, lnx, down); -} - void qemu_input_event_send_key_linux(QemuConsole *src, unsigned int lnx, bool down) { @@ -XXX,XX +XXX,XX @@ void qemu_input_event_send_key_number(QemuConsole *src, int num, bool down) qemu_input_event_send_key_linux(src, lnx, down); } -void qemu_input_event_send_key_qcode(QemuConsole *src, QKeyCode q, bool down) -{ - KeyValue *key = g_new0(KeyValue, 1); - key->type = KEY_VALUE_KIND_QCODE; - key->u.qcode.data = q; - qemu_input_event_send_key(src, key, down); -} - void qemu_input_event_send_key_delay(uint32_t delay_ms) { if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) { diff --git a/ui/meson.build b/ui/meson.build index XXXXXXX..XXXXXXX 100644 --- a/ui/meson.build +++ b/ui/meson.build @@ -XXX,XX +XXX,XX @@ keymaps = [ - ['atset1', 'qcode'], ['atset1', 'linux'], ['linux', 'qcode'], - ['qcode', 'atset1'], ['linux', 'atset1'], - ['qcode', 'atset2'], ['linux', 'atset2'], - ['qcode', 'atset3'], ['linux', 'atset3'], ['qcode', 'linux'], - ['qcode', 'qnum'], ['linux', 'qnum'], - ['qcode', 'sun'], ['linux', 'sun'], - ['qnum', 'qcode'], ['qnum', 'linux'], - ['usb', 'qcode'], ['usb', 'linux'], - ['win32', 'qcode'], ['win32', 'linux'], - ['x11', 'qcode'], ['x11', 'linux'], - ['xorgevdev', 'qcode'], - ['xorgkbd', 'qcode'], ['xorgkbd', 'linux'], - ['xorgxquartz', 'qcode'], ['xorgxquartz', 'linux'], - ['xorgxwin', 'qcode'], ['xorgxwin', 'linux'], - ['osx', 'qcode'], ['osx', 'linux'], ] -- 2.54.0
From: Dongwon Kim <dongwon.kim@intel.com> When QEMU is launched with a single virtual console (e.g., using --nodefaults), detaching and then closing the detached window leaves the main window's notebook without an active focus target which makes keyboard unfunctional on re-attached VC. Fix this by explicitly calling gtk_widget_grab_focus on the active VC's focus widget during the window close handler. Cc: Marc-André Lureau <marcandre.lureau@redhat.com> Cc: Philippe Mathieu-Daudé <philmd@linaro.org> Cc: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Dongwon Kim <dongwon.kim@intel.com> Message-ID: <20260520002645.1910740-1-dongwon.kim@intel.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- ui/gtk.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ui/gtk.c b/ui/gtk.c index XXXXXXX..XXXXXXX 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -XXX,XX +XXX,XX @@ static gboolean gd_tab_window_close(GtkWidget *widget, GdkEvent *event, vc->gfx.ectx = NULL; } #endif + + if (vc == gd_vc_find_by_menu(s)) { + gtk_widget_grab_focus(vc->focus); + } + return TRUE; } -- 2.54.0