virtio-input: send rel-wheel events for wheel buttons
PATCH 1/1 virtio-input: send rel-wheel events for wheel buttons
qemu uses wheel-up/down button events for mouse wheel input, however linux applications typically want REL_WHEEL events.
This fixes wheel with linux guests. Tested with X11/wayland, and windows virtio-input driver.
--- hw/input/virtio-input-hid.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
hw/input/virtio-input-hid.c +11 -4
@@ -196,6 +196,7 @@ static void virtio_input_handle_event(DeviceState *dev, QemuConsole *src,InputKeyEvent *key;InputMoveEvent *move;InputBtnEvent *btn; +unsigned int map;switch (evt->type) {case INPUT_EVENT_KIND_KEY :
@@ -215,9 +216,15 @@ static void virtio_input_handle_event(DeviceState *dev, QemuConsole *src,break ;case INPUT_EVENT_KIND_BTN : btn = evt->u.btn.data; -if (keymap_button[btn->button]) { + map = keymap_button[btn->button]; +if (map ==BTN_GEAR_DOWN || map ==BTN_GEAR_UP ) { + event.type =cpu_to_le16 (EV_REL ); + event.code =cpu_to_le16 (REL_WHEEL ); + event.value =cpu_to_le32 (map ==BTN_GEAR_DOWN ?-1 :1 ); +virtio_input_send (vinput, &event); + }else if (map) { event.type =cpu_to_le16 (EV_KEY ); - event.code =cpu_to_le16 (keymap_button[btn->button]); + event.code =cpu_to_le16 (map); event.value =cpu_to_le32 (btn->down ?1 :0 );virtio_input_send (vinput, &event); }else {
@@ -424,9 +431,9 @@ static struct virtio_input_config virtio_mouse_config[] = { },{ .select = VIRTIO_INPUT_CFG_EV_BITS, .subsel = EV_REL, - .size = 1, + .size = 2, .u.bitmap = { - (1 << REL_X) | (1 << REL_Y), + (1 << REL_X) | (1 << REL_Y), (1 << (REL_WHEEL - 8)) }, }, { /* end of list */ },
Signature · 1 line
2.14.0.1.geff633fa0
Quoted 24 lines · Marc-André Lureau
qemu uses wheel-up/down button events for mouse wheel input, however linux applications typically want
REL_WHEELevents.This fixes wheel with linux guests. Tested with X11/wayland, and windows virtio-input driver.
Signed-off-by Marc-André Lureau <[email protected]>--- hw/input/virtio-input-hid.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)hw/input/virtio-input-hid.c +1
-0@@ -196,6 +196,7 @@ static void virtio_input_handle_event(DeviceState *dev, QemuConsole *src,InputKeyEvent *key;InputMoveEvent *move;InputBtnEvent *btn; +unsigned int map;switch (evt->type) {case INPUT_EVENT_KIND_KEY :
hw/input/virtio-input-hid.c static void virtio_input_handle_event(DeviceState *dev, QemuConsole *src, · line 223
Quoted 9 lines
hw/input/virtio-input-hid.c +5
-1@@ -215,9 +216,15 @@ static void virtio_input_handle_event(DeviceState *dev, QemuConsole *src,break ;case INPUT_EVENT_KIND_BTN : btn = evt->u.btn.data; -if (keymap_button[btn->button]) { + map = keymap_button[btn->button]; +if (map ==BTN_GEAR_DOWN || map ==BTN_GEAR_UP ) { + event.type =cpu_to_le16 (EV_REL ); + event.code =cpu_to_le16 (REL_WHEEL ); + event.value =cpu_to_le32 (map ==BTN_GEAR_DOWN ?-1 :1 );
I realize now that value is actually a signed integer in 2's complement format. Unfortunate that it's not documented.
Quoted 9 lines
hw/input/virtio-input-hid.c +3
-1+virtio_input_send (vinput, &event); + }else if (map) { event.type =cpu_to_le16 (EV_KEY ); - event.code =cpu_to_le16 (keymap_button[btn->button]); + event.code =cpu_to_le16 (map); event.value =cpu_to_le32 (btn->down ?1 :0 );virtio_input_send (vinput, &event); }else {
hw/input/virtio-input-hid.c static struct virtio_input_config virtio_mouse_config[] = { · line 436
Quoted 8 lines
hw/input/virtio-input-hid.c +2
-2@@ -424,9 +431,9 @@ static struct virtio_input_config virtio_mouse_config[] = { },{ .select = VIRTIO_INPUT_CFG_EV_BITS, .subsel = EV_REL, - .size = 1, + .size = 2, .u.bitmap = { - (1 << REL_X) | (1 << REL_Y), + (1 <<REL_X ) | (1 <<REL_Y ), (1 << (REL_WHEEL -8 ))
Works only when REL_WHEEL is between 8 and 15.
Add BUILD_BUG_ON?
hw/input/virtio-input-hid.c static struct virtio_input_config virtio_mouse_config[] = { · line 439
Quoted 3 lines
hw/input/virtio-input-hid.c +0
-0}, }, { /* end of list */ },
Is it problematic e.g. if you migrate from a host with REL_WHEEL to one without? Should we maintain a version without REL_WHEEL for old machine types?
Quoted 2 lines
Signature · 1 line
2.14.0.1.geff633fa0
Hi,
Quoted 10 lines
Quoted 7 lines
.select =
VIRTIO_INPUT_CFG_EV_BITS,
.subsel =EV_REL,
- .size = 1,
+ .size = 2,
.u.bitmap = {
- (1 <<REL_X) | (1 <<REL_Y),
+ (1 <<REL_X) | (1 << REL_Y), (1 << (REL_WHEEL- 8))Works only when
REL_WHEELis between 8 and 15.
AddBUILD_BUG_ON?
Not needed IMO, REL_WHEEL value is kernel/userspace abi and will never change.
Quoted 8 lines
Quoted 4 lines
},
},
{ /* end of list */ },Is it problematic e.g. if you migrate from a host with
REL_WHEELto one without? Should we maintain a version withoutREL_WHEELfor old machine types?
Yes, we need a compat property.
Possibly it is easier to fix on the guest side, assuming it is actually needed (see other reply).
cheers,
Gerd
Quoted 2 lines · Marc-André Lureau
qemu uses wheel-up/down button events for mouse wheel input, however linux applications typically want
REL_WHEELevents.
--verbose please.
Both should work just fine.
cheers,
Gerd
Hi
----- Original Message -----
Quoted 7 lines · Marc-André Lureau
Quoted 2 lines
qemu uses wheel-up/down button events for mouse wheel input, however linux applications typically want
REL_WHEELevents.--verbose please.
Both should work just fine.
I haven't done extensive review of all input code on linux, but from what I remember the event got dropped here:
https://cgit.freedesktop.org/xorg/driver/xf86-input-evdev/tree/src/evdev.c#n2720
It seems BTN_GEAR isn't clearly defined either.
Perhaps libinput does a better job at mapping the event, but we should consider older guests. Spice agent is using rel-wheel events, and we never had issues with it.
thanks