From nobody Wed May 1 10:50:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503496351066584.0157766316283; Wed, 23 Aug 2017 06:52:31 -0700 (PDT) Received: from localhost ([::1]:43834 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkW57-00013G-Qc for importer@patchew.org; Wed, 23 Aug 2017 09:52:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55598) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkW4E-0000l0-Io for qemu-devel@nongnu.org; Wed, 23 Aug 2017 09:51:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dkW4B-00075K-92 for qemu-devel@nongnu.org; Wed, 23 Aug 2017 09:51:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33307) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dkW4B-00071J-07 for qemu-devel@nongnu.org; Wed, 23 Aug 2017 09:51:31 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 15DBB80B29 for ; Wed, 23 Aug 2017 13:51:28 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-82.ams2.redhat.com [10.36.116.82]) by smtp.corp.redhat.com (Postfix) with ESMTP id 31C6B7F474; Wed, 23 Aug 2017 13:51:14 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 53F42ECD; Wed, 23 Aug 2017 15:51:13 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 15DBB80B29 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=kraxel@redhat.com From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 23 Aug 2017 15:51:13 +0200 Message-Id: <20170823135113.25769-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 23 Aug 2017 13:51:28 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] virtio-input: send rel-wheel events for wheel buttons X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Gerd Hoffmann , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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. Based on a patch from Marc. Added property to enable/disable wheel axis. TODO: add compat properties for old machine types. Cc: Marc-Andr=C3=A9 Lureau Signed-off-by: Gerd Hoffmann Tested-by: Ladi Prosek --- include/hw/virtio/virtio-input.h | 1 + hw/input/virtio-input-hid.c | 119 +++++++++++++++++++++++++++++++++++= ++-- 2 files changed, 115 insertions(+), 5 deletions(-) diff --git a/include/hw/virtio/virtio-input.h b/include/hw/virtio/virtio-in= put.h index 91df57eca4..054c38836f 100644 --- a/include/hw/virtio/virtio-input.h +++ b/include/hw/virtio/virtio-input.h @@ -89,6 +89,7 @@ struct VirtIOInputHID { QemuInputHandler *handler; QemuInputHandlerState *hs; int ledstate; + bool wheel_axis; }; =20 struct VirtIOInputHost { diff --git a/hw/input/virtio-input-hid.c b/hw/input/virtio-input-hid.c index 46c038110c..79ab92e89f 100644 --- a/hw/input/virtio-input-hid.c +++ b/hw/input/virtio-input-hid.c @@ -190,6 +190,7 @@ static void virtio_input_key_config(VirtIOInput *vinput, static void virtio_input_handle_event(DeviceState *dev, QemuConsole *src, InputEvent *evt) { + VirtIOInputHID *vhid =3D VIRTIO_INPUT_HID(dev); VirtIOInput *vinput =3D VIRTIO_INPUT(dev); virtio_input_event event; int qcode; @@ -215,7 +216,14 @@ static void virtio_input_handle_event(DeviceState *dev= , QemuConsole *src, break; case INPUT_EVENT_KIND_BTN: btn =3D evt->u.btn.data; - if (keymap_button[btn->button]) { + if (vhid->wheel_axis && (btn->button =3D=3D INPUT_BUTTON_WHEEL_UP = || + btn->button =3D=3D INPUT_BUTTON_WHEEL_DOW= N)) { + event.type =3D cpu_to_le16(EV_REL); + event.code =3D cpu_to_le16(REL_WHEEL); + event.value =3D cpu_to_le32(btn->button =3D=3D INPUT_BUTTON_WH= EEL_UP + ? 1 : -1); + virtio_input_send(vinput, &event); + } else if (keymap_button[btn->button]) { event.type =3D cpu_to_le16(EV_KEY); event.code =3D cpu_to_le16(keymap_button[btn->button]); event.value =3D cpu_to_le32(btn->down ? 1 : 0); @@ -407,7 +415,7 @@ static QemuInputHandler virtio_mouse_handler =3D { .sync =3D virtio_input_handle_sync, }; =20 -static struct virtio_input_config virtio_mouse_config[] =3D { +static struct virtio_input_config virtio_mouse_config_v1[] =3D { { .select =3D VIRTIO_INPUT_CFG_ID_NAME, .size =3D sizeof(VIRTIO_ID_NAME_MOUSE), @@ -432,13 +440,53 @@ static struct virtio_input_config virtio_mouse_config= [] =3D { { /* end of list */ }, }; =20 +static struct virtio_input_config virtio_mouse_config_v2[] =3D { + { + .select =3D VIRTIO_INPUT_CFG_ID_NAME, + .size =3D sizeof(VIRTIO_ID_NAME_MOUSE), + .u.string =3D VIRTIO_ID_NAME_MOUSE, + },{ + .select =3D VIRTIO_INPUT_CFG_ID_DEVIDS, + .size =3D sizeof(struct virtio_input_devids), + .u.ids =3D { + .bustype =3D const_le16(BUS_VIRTUAL), + .vendor =3D const_le16(0x0627), /* same we use for usb hid de= vices */ + .product =3D const_le16(0x0002), + .version =3D const_le16(0x0002), + }, + },{ + .select =3D VIRTIO_INPUT_CFG_EV_BITS, + .subsel =3D EV_REL, + .size =3D 2, + .u.bitmap =3D { + (1 << REL_X) | (1 << REL_Y), + (1 << (REL_WHEEL - 8)) + }, + }, + { /* end of list */ }, +}; + +static Property virtio_mouse_properties[] =3D { + DEFINE_PROP_BOOL("wheel-axis", VirtIOInputHID, wheel_axis, true), + DEFINE_PROP_END_OF_LIST(), +}; + +static void virtio_mouse_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->props =3D virtio_mouse_properties; +} + static void virtio_mouse_init(Object *obj) { VirtIOInputHID *vhid =3D VIRTIO_INPUT_HID(obj); VirtIOInput *vinput =3D VIRTIO_INPUT(obj); =20 vhid->handler =3D &virtio_mouse_handler; - virtio_input_init_config(vinput, virtio_mouse_config); + virtio_input_init_config(vinput, vhid->wheel_axis + ? virtio_mouse_config_v2 + : virtio_mouse_config_v1); virtio_input_key_config(vinput, keymap_button, ARRAY_SIZE(keymap_button)); } @@ -448,6 +496,7 @@ static const TypeInfo virtio_mouse_info =3D { .parent =3D TYPE_VIRTIO_INPUT_HID, .instance_size =3D sizeof(VirtIOInputHID), .instance_init =3D virtio_mouse_init, + .class_init =3D virtio_mouse_class_init, }; =20 /* ----------------------------------------------------------------- */ @@ -459,7 +508,7 @@ static QemuInputHandler virtio_tablet_handler =3D { .sync =3D virtio_input_handle_sync, }; =20 -static struct virtio_input_config virtio_tablet_config[] =3D { +static struct virtio_input_config virtio_tablet_config_v1[] =3D { { .select =3D VIRTIO_INPUT_CFG_ID_NAME, .size =3D sizeof(VIRTIO_ID_NAME_TABLET), @@ -496,13 +545,72 @@ static struct virtio_input_config virtio_tablet_confi= g[] =3D { { /* end of list */ }, }; =20 +static struct virtio_input_config virtio_tablet_config_v2[] =3D { + { + .select =3D VIRTIO_INPUT_CFG_ID_NAME, + .size =3D sizeof(VIRTIO_ID_NAME_TABLET), + .u.string =3D VIRTIO_ID_NAME_TABLET, + },{ + .select =3D VIRTIO_INPUT_CFG_ID_DEVIDS, + .size =3D sizeof(struct virtio_input_devids), + .u.ids =3D { + .bustype =3D const_le16(BUS_VIRTUAL), + .vendor =3D const_le16(0x0627), /* same we use for usb hid de= vices */ + .product =3D const_le16(0x0003), + .version =3D const_le16(0x0002), + }, + },{ + .select =3D VIRTIO_INPUT_CFG_EV_BITS, + .subsel =3D EV_ABS, + .size =3D 1, + .u.bitmap =3D { + (1 << ABS_X) | (1 << ABS_Y), + }, + },{ + .select =3D VIRTIO_INPUT_CFG_EV_BITS, + .subsel =3D EV_REL, + .size =3D 2, + .u.bitmap =3D { + 0, + (1 << (REL_WHEEL - 8)) + }, + },{ + .select =3D VIRTIO_INPUT_CFG_ABS_INFO, + .subsel =3D ABS_X, + .size =3D sizeof(virtio_input_absinfo), + .u.abs.min =3D const_le32(INPUT_EVENT_ABS_MIN), + .u.abs.max =3D const_le32(INPUT_EVENT_ABS_MAX), + },{ + .select =3D VIRTIO_INPUT_CFG_ABS_INFO, + .subsel =3D ABS_Y, + .size =3D sizeof(virtio_input_absinfo), + .u.abs.min =3D const_le32(INPUT_EVENT_ABS_MIN), + .u.abs.max =3D const_le32(INPUT_EVENT_ABS_MAX), + }, + { /* end of list */ }, +}; + +static Property virtio_tablet_properties[] =3D { + DEFINE_PROP_BOOL("wheel-axis", VirtIOInputHID, wheel_axis, true), + DEFINE_PROP_END_OF_LIST(), +}; + +static void virtio_tablet_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->props =3D virtio_tablet_properties; +} + static void virtio_tablet_init(Object *obj) { VirtIOInputHID *vhid =3D VIRTIO_INPUT_HID(obj); VirtIOInput *vinput =3D VIRTIO_INPUT(obj); =20 vhid->handler =3D &virtio_tablet_handler; - virtio_input_init_config(vinput, virtio_tablet_config); + virtio_input_init_config(vinput, vhid->wheel_axis + ? virtio_tablet_config_v2 + : virtio_tablet_config_v1); virtio_input_key_config(vinput, keymap_button, ARRAY_SIZE(keymap_button)); } @@ -512,6 +620,7 @@ static const TypeInfo virtio_tablet_info =3D { .parent =3D TYPE_VIRTIO_INPUT_HID, .instance_size =3D sizeof(VirtIOInputHID), .instance_init =3D virtio_tablet_init, + .class_init =3D virtio_tablet_class_init, }; =20 /* ----------------------------------------------------------------- */ --=20 2.9.3