From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: qemu-devel@nongnu.org
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Subject: [GIT PULL 03/27] hw/i386/vmmouse: convert to QemuInputHandler API
Date: Wed, 17 Jun 2026 19:23:00 +0400 [thread overview]
Message-ID: <20260617-ui-input-v1-3-79e9aedc5899@redhat.com> (raw)
In-Reply-To: <20260617-ui-input-v1-0-79e9aedc5899@redhat.com>
Replace the legacy QEMUPutMouseEvent callback with a proper
QemuInputHandler registration. This eliminates one of the two
remaining users of the legacy input adapter in ui/input-legacy.c.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/i386/vmmouse.c | 115 +++++++++++++++++++++++++++++++++++++--------------
hw/i386/trace-events | 2 +-
2 files changed, 85 insertions(+), 32 deletions(-)
diff --git a/hw/i386/vmmouse.c b/hw/i386/vmmouse.c
index d54adb34a88..e289bce8e2e 100644
--- a/hw/i386/vmmouse.c
+++ b/hw/i386/vmmouse.c
@@ -68,7 +68,10 @@ struct VMMouseState {
uint16_t nb_queue;
uint16_t status;
uint8_t absolute;
- QEMUPutMouseEntry *entry;
+ QemuInputHandlerState *hs;
+ int axis[INPUT_AXIS__MAX];
+ int dz;
+ bool btns[INPUT_BUTTON__MAX];
ISAKBDState *i8042;
};
@@ -99,39 +102,78 @@ static uint32_t vmmouse_get_status(VMMouseState *s)
return (s->status << 16) | s->nb_queue;
}
-static void vmmouse_mouse_event(void *opaque, int x, int y, int dz, int buttons_state)
+static void vmmouse_input_event(DeviceState *dev, QemuConsole *src,
+ QemuInputEvent *evt)
{
- VMMouseState *s = opaque;
+ VMMouseState *s = VMMOUSE(dev);
+
+ switch (evt->type) {
+ case INPUT_EVENT_KIND_BTN:
+ if (evt->btn.down) {
+ if (evt->btn.button == INPUT_BUTTON_WHEEL_UP) {
+ s->dz--;
+ } else if (evt->btn.button == INPUT_BUTTON_WHEEL_DOWN) {
+ s->dz++;
+ }
+ }
+ s->btns[evt->btn.button] = evt->btn.down;
+ break;
+ case INPUT_EVENT_KIND_ABS:
+ if (evt->abs.axis == INPUT_AXIS_X) {
+ s->axis[INPUT_AXIS_X] =
+ qemu_input_scale_axis(evt->abs.value,
+ INPUT_EVENT_ABS_MIN, INPUT_EVENT_ABS_MAX,
+ VMMOUSE_MIN_X, VMMOUSE_MAX_X);
+ } else if (evt->abs.axis == INPUT_AXIS_Y) {
+ s->axis[INPUT_AXIS_Y] =
+ qemu_input_scale_axis(evt->abs.value,
+ INPUT_EVENT_ABS_MIN, INPUT_EVENT_ABS_MAX,
+ VMMOUSE_MIN_Y, VMMOUSE_MAX_Y);
+ }
+ break;
+ case INPUT_EVENT_KIND_REL:
+ s->axis[evt->rel.axis] += evt->rel.value;
+ break;
+ default:
+ break;
+ }
+}
+
+static void vmmouse_input_sync(DeviceState *dev)
+{
+ VMMouseState *s = VMMOUSE(dev);
int buttons = 0;
- if (s->nb_queue > (VMMOUSE_QUEUE_SIZE - 4))
+ if (s->nb_queue > (VMMOUSE_QUEUE_SIZE - 4)) {
return;
+ }
- trace_vmmouse_mouse_event(x, y, dz, buttons_state);
-
- if ((buttons_state & MOUSE_EVENT_LBUTTON))
+ if (s->btns[INPUT_BUTTON_LEFT]) {
buttons |= VMMOUSE_LEFT_BUTTON;
- if ((buttons_state & MOUSE_EVENT_RBUTTON))
+ }
+ if (s->btns[INPUT_BUTTON_RIGHT]) {
buttons |= VMMOUSE_RIGHT_BUTTON;
- if ((buttons_state & MOUSE_EVENT_MBUTTON))
+ }
+ if (s->btns[INPUT_BUTTON_MIDDLE]) {
buttons |= VMMOUSE_MIDDLE_BUTTON;
-
- if (s->absolute) {
- 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. */
+ }
+ if (!s->absolute) {
buttons |= VMMOUSE_RELATIVE_PACKET;
}
+ trace_vmmouse_queue_event(s->axis[INPUT_AXIS_X], s->axis[INPUT_AXIS_Y],
+ s->dz, buttons);
+
s->queue[s->nb_queue++] = buttons;
- s->queue[s->nb_queue++] = x;
- s->queue[s->nb_queue++] = y;
- s->queue[s->nb_queue++] = dz;
+ s->queue[s->nb_queue++] = s->axis[INPUT_AXIS_X];
+ s->queue[s->nb_queue++] = s->axis[INPUT_AXIS_Y];
+ s->queue[s->nb_queue++] = s->dz;
+ s->dz = 0;
+
+ if (!s->absolute) {
+ s->axis[INPUT_AXIS_X] = 0;
+ s->axis[INPUT_AXIS_Y] = 0;
+ }
/* need to still generate PS2 events to notify driver to
read from queue */
@@ -140,14 +182,25 @@ static void vmmouse_mouse_event(void *opaque, int x, int y, int dz, int buttons_
static void vmmouse_remove_handler(VMMouseState *s)
{
- if (s->entry) {
- qemu_remove_mouse_event_handler(s->entry);
- s->entry = NULL;
- }
+ g_clear_pointer(&s->hs, qemu_input_handler_unregister);
}
static void vmmouse_update_handler(VMMouseState *s, int absolute)
{
+ static const QemuInputHandler vmmouse_abs_handler = {
+ .name = "vmmouse",
+ .mask = INPUT_EVENT_MASK_BTN | INPUT_EVENT_MASK_ABS,
+ .event = vmmouse_input_event,
+ .sync = vmmouse_input_sync,
+ };
+
+ static const QemuInputHandler vmmouse_rel_handler = {
+ .name = "vmmouse",
+ .mask = INPUT_EVENT_MASK_BTN | INPUT_EVENT_MASK_REL,
+ .event = vmmouse_input_event,
+ .sync = vmmouse_input_sync,
+ };
+
if (s->status != 0) {
return;
}
@@ -155,11 +208,11 @@ static void vmmouse_update_handler(VMMouseState *s, int absolute)
s->absolute = absolute;
vmmouse_remove_handler(s);
}
- if (s->entry == NULL) {
- s->entry = qemu_add_mouse_event_handler(vmmouse_mouse_event,
- s, s->absolute,
- "vmmouse");
- qemu_activate_mouse_event_handler(s->entry);
+ if (s->hs == NULL) {
+ const QemuInputHandler *h = s->absolute ?
+ &vmmouse_abs_handler : &vmmouse_rel_handler;
+ s->hs = qemu_input_handler_register(DEVICE(s), h);
+ qemu_input_handler_activate(s->hs);
}
}
diff --git a/hw/i386/trace-events b/hw/i386/trace-events
index a1dfade20f1..a1a50d09109 100644
--- a/hw/i386/trace-events
+++ b/hw/i386/trace-events
@@ -134,7 +134,7 @@ 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_queue_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) ""
--
2.54.0
next prev parent reply other threads:[~2026-06-17 15:24 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-17 15:22 [GIT PULL 00/27] UI patches for 2026-06-17 Marc-André Lureau
2026-06-17 15:22 ` [GIT PULL 01/27] hmp-commands.hx: fix button_state doc Marc-André Lureau
2026-06-17 15:22 ` [GIT PULL 02/27] ui/hmp: move index_from_key() where it is used Marc-André Lureau
2026-06-17 15:23 ` Marc-André Lureau [this message]
2026-06-17 15:23 ` [GIT PULL 04/27] hw/usb/dev-wacom: convert to modern QemuInputHandler API Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 05/27] ui: move LED and key utilities to input.c, delete input-legacy.c Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 06/27] hw/input: replace fprint with LOG_GUEST_ERROR Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 07/27] ui/input: remove double-notification on qemu_mouse_set() Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 08/27] ui/input: remove dead declaration Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 09/27] ui/input: add LED state tracking to QemuInputHandlerState Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 10/27] hw/input/ps2: keep QemuInputHandlerState in PS2State Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 11/27] hw/arm: keep QemuInputHandlerState in musicpal Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 12/27] hw/input: keep QemuInputHandlerState in adb-kbd Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 13/27] hw/input: keep QemuInputHandlerState in stellaris Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 14/27] hw/m68k: keep QemuInputHandlerState in next-kbd Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 15/27] ui/input: qemu_input_handler_register to warn for unused result Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 16/27] hw/input/ps2: use qemu_input_handler_set_leds_mask() for LED state Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 17/27] hw/input/hid: " Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 18/27] hw/input/virtio-input-hid: " Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 19/27] ui/vnc: switch LED handling to Notifier-based input API Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 20/27] ui/spice: " Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 21/27] ui/dbus: " Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 22/27] ui/input: remove old LED handler broadcast queue Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 23/27] tools/qemu-vnc: Have console_get_mouse/keyboard take const QemuConsole Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 24/27] ui/input: Have qemu_input_is_absolute() take a " Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 25/27] ui/pixman: fix zero rowstride in qemu_pixman_image_new_shareable() Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 26/27] ui/sdl2: Explicitly specify EGL platform Marc-André Lureau
2026-06-17 15:23 ` [GIT PULL 27/27] ui/sdl2: Set GL ES profile before creating initial GL context Marc-André Lureau
2026-06-18 17:53 ` [GIT PULL 00/27] UI patches for 2026-06-17 Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260617-ui-input-v1-3-79e9aedc5899@redhat.com \
--to=marcandre.lureau@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.