From nobody Sat May 18 22:54:10 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1676737429; cv=none; d=zohomail.com; s=zohoarc; b=cXy5vmT1kGt9MBQRbOBwHom4g09WaUcjKdRv7H8sGJIfWhUy/HHf2sKwunJTqHlCP29nJ/MF+Dd+25BF56/iTsvxSk10t2FTCqXV7ke+UwutdhYOi7DxzVhz2nsoHKxDM39Spm6/PUoIsLfRvM338/8CPY5s4WJPkHe5hu4/jcs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676737429; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AXsN5/MnVh+hhjmiTeAPyIO/3hAECUACAx+QVNV9yXE=; b=RfPWvhzEa3x9/eMQ5zaSMUGvbQ3N8F4UOVGHMOLS8Hz/eY8YfG38+8ulnS24Kejss1lREphs12gkkkLkUWqoUjjwjH5Iu/uhY/1tlWKXWIGlW0hxSVgR1EkOu1lVSj3jJBG8M2xvmUU0SELJsVlEkGkPOmXxD0pksDVkJL6Xux0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676737429651153.79235603294217; Sat, 18 Feb 2023 08:23:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pTPzR-00034i-Uv; Sat, 18 Feb 2023 11:23:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pTPzM-00033v-SY for qemu-devel@nongnu.org; Sat, 18 Feb 2023 11:23:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pTPzJ-0002Yn-Pl for qemu-devel@nongnu.org; Sat, 18 Feb 2023 11:23:04 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-505-8sTQvnMuNNiJ_wB6kgNNlw-1; Sat, 18 Feb 2023 11:21:12 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8CF1E802314; Sat, 18 Feb 2023 16:21:12 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.33.36.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id 372C61731B; Sat, 18 Feb 2023 16:21:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676737381; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AXsN5/MnVh+hhjmiTeAPyIO/3hAECUACAx+QVNV9yXE=; b=RmepBBttXfowRI5rLbPZ7ADx3R7qpkoLY3QbDVgRdke/2/TbQPpVzZ5PEwsk50tlda1iI+ XS2coqTFUVHdN9RZZSwFOPEY/CB9rLwlgEwV/eWhAlyHdJDjCCzyU6Jb9thZZXwUjU75Pe lMus0GnBx2GIE6Tfm91/IZwZ9Cf4BeI= X-MC-Unique: 8sTQvnMuNNiJ_wB6kgNNlw-1 From: Sergio Lopez To: qemu-devel@nongnu.org Cc: Pavel Dovgalyuk , "Michael S. Tsirkin" , Gerd Hoffmann , Markus Armbruster , Paolo Bonzini , Eric Blake , Sergio Lopez Subject: [PATCH 1/4] virtio-input: generalize virtio_input_key_config() Date: Sat, 18 Feb 2023 17:22:13 +0100 Message-Id: <20230218162216.46944-2-slp@redhat.com> In-Reply-To: <20230218162216.46944-1-slp@redhat.com> References: <20230218162216.46944-1-slp@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=slp@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676737431054100003 Content-Type: text/plain; charset="utf-8" As there are other bitmap-based config properties that need to be dealt in a similar fashion as VIRTIO_INPUT_CFG_EV_BITS, generalize the function to receive select and subsel as arguments, and rename it to virtio_input_extend_config() Signed-off-by: Sergio Lopez Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/input/virtio-input-hid.c | 38 ++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/hw/input/virtio-input-hid.c b/hw/input/virtio-input-hid.c index a7a244a95d..d28dab69ba 100644 --- a/hw/input/virtio-input-hid.c +++ b/hw/input/virtio-input-hid.c @@ -44,30 +44,31 @@ static const unsigned short axismap_abs[INPUT_AXIS__MAX= ] =3D { =20 /* ----------------------------------------------------------------- */ =20 -static void virtio_input_key_config(VirtIOInput *vinput, - const unsigned short *keymap, - size_t mapsize) +static void virtio_input_extend_config(VirtIOInput *vinput, + const unsigned short *map, + size_t mapsize, + uint8_t select, uint8_t subsel) { - virtio_input_config keys; + virtio_input_config ext; int i, bit, byte, bmax =3D 0; =20 - memset(&keys, 0, sizeof(keys)); + memset(&ext, 0, sizeof(ext)); for (i =3D 0; i < mapsize; i++) { - bit =3D keymap[i]; + bit =3D map[i]; if (!bit) { continue; } byte =3D bit / 8; bit =3D bit % 8; - keys.u.bitmap[byte] |=3D (1 << bit); + ext.u.bitmap[byte] |=3D (1 << bit); if (bmax < byte+1) { bmax =3D byte+1; } } - keys.select =3D VIRTIO_INPUT_CFG_EV_BITS; - keys.subsel =3D EV_KEY; - keys.size =3D bmax; - virtio_input_add_config(vinput, &keys); + ext.select =3D select; + ext.subsel =3D subsel; + ext.size =3D bmax; + virtio_input_add_config(vinput, &ext); } =20 static void virtio_input_handle_event(DeviceState *dev, QemuConsole *src, @@ -281,8 +282,9 @@ static void virtio_keyboard_init(Object *obj) =20 vhid->handler =3D &virtio_keyboard_handler; virtio_input_init_config(vinput, virtio_keyboard_config); - virtio_input_key_config(vinput, qemu_input_map_qcode_to_linux, - qemu_input_map_qcode_to_linux_len); + 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); } =20 static const TypeInfo virtio_keyboard_info =3D { @@ -373,8 +375,9 @@ static void virtio_mouse_init(Object *obj) 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)); + virtio_input_extend_config(vinput, keymap_button, + ARRAY_SIZE(keymap_button), + VIRTIO_INPUT_CFG_EV_BITS, EV_KEY); } =20 static const TypeInfo virtio_mouse_info =3D { @@ -497,8 +500,9 @@ static void virtio_tablet_init(Object *obj) 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)); + virtio_input_extend_config(vinput, keymap_button, + ARRAY_SIZE(keymap_button), + VIRTIO_INPUT_CFG_EV_BITS, EV_KEY); } =20 static const TypeInfo virtio_tablet_info =3D { --=20 2.38.1 From nobody Sat May 18 22:54:10 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1676737396; cv=none; d=zohomail.com; s=zohoarc; b=f0SSjXF0QTXlvxFoirgpL3vKVsQNC0kugHZ2uiuFU+zWRgBOTUB2546FIhAgxysH6TacBhAGAOM2Xvf/eoCSHWlhCMvkeqDknRy43d2mLdtwXJ7FlvpsvQvPLB+p3YsdYAD471oMCtOs/9huLiPJk2FohpIqr5hYnmu5dqWaDKE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676737396; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6WFU2be/AGDaepm+bgXrvdnpnpBV4i1Z00AMMcDcWtI=; b=cbiPGsHu8Es3P76SUhcBicHwThKyXeyzrR+f3qAyF/YE6kPiezqOjWfgiboV4DeG5NlHUsgi30EBPgHADeV2y5IqLU4iJE0F2def2PZz0tjRrxos2EB2q/aGQUoA+CXqag7tUoeN9euGw+8Sx0Rg+kwDIJbP2h1CKJGsficZ9HY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676737396869986.8894608548455; Sat, 18 Feb 2023 08:23:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pTPyy-0002yr-A5; Sat, 18 Feb 2023 11:22:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pTPyv-0002yS-W8 for qemu-devel@nongnu.org; Sat, 18 Feb 2023 11:22:38 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pTPyt-0002Vm-Dx for qemu-devel@nongnu.org; Sat, 18 Feb 2023 11:22:37 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-313-oECEWRa4Mnq7yA8DM_YpmA-1; Sat, 18 Feb 2023 11:21:14 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4BD6A101A52E; Sat, 18 Feb 2023 16:21:14 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.33.36.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id CC4251731B; Sat, 18 Feb 2023 16:21:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676737354; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6WFU2be/AGDaepm+bgXrvdnpnpBV4i1Z00AMMcDcWtI=; b=jBTFNi9x5jFKU7p+P0KSAcKDxzm8TVVkCZOi3o5Tvtygou/ZvAXPrrpVxC7DKE7estAA8V QKIwY1U0Ua2590TQFn2Eqw3ImUTiy0uU1E4iz6mZ+Rlqk34iVLf0zeU+BQYMkpBAwzoSn1 XDZ/Kx0Lv/EhpSbv6VkAeD5s9Rofqdc= X-MC-Unique: oECEWRa4Mnq7yA8DM_YpmA-1 From: Sergio Lopez To: qemu-devel@nongnu.org Cc: Pavel Dovgalyuk , "Michael S. Tsirkin" , Gerd Hoffmann , Markus Armbruster , Paolo Bonzini , Eric Blake , Sergio Lopez Subject: [PATCH 2/4] virtio-input: add a virtio-mulitouch device Date: Sat, 18 Feb 2023 17:22:14 +0100 Message-Id: <20230218162216.46944-3-slp@redhat.com> In-Reply-To: <20230218162216.46944-1-slp@redhat.com> References: <20230218162216.46944-1-slp@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=slp@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676737399187100007 Content-Type: text/plain; charset="utf-8" Add a virtio-multitouch device to the family of devices emulated by virtio-input implementing the Multi-touch protocol as descripted here: https://www.kernel.org/doc/html/latest/input/multi-touch-protocol.html?high= light=3Dmulti+touch This patch just add the device itself, without connecting it to any backends. The following patches will add helpers in "ui" and will enable the GTK3 backend to transpose multi-touch events from the host to the guest. Signed-off-by: Sergio Lopez Reviewed-by: Pavel Dovgalyuk --- hw/input/virtio-input-hid.c | 123 ++++++++++++++++++++++++++++++- hw/virtio/virtio-input-pci.c | 25 ++++++- include/hw/virtio/virtio-input.h | 9 ++- include/ui/input.h | 3 + qapi/ui.json | 45 ++++++++++- replay/replay-input.c | 18 +++++ ui/input.c | 6 ++ ui/trace-events | 1 + 8 files changed, 216 insertions(+), 14 deletions(-) diff --git a/hw/input/virtio-input-hid.c b/hw/input/virtio-input-hid.c index d28dab69ba..34109873ac 100644 --- a/hw/input/virtio-input-hid.c +++ b/hw/input/virtio-input-hid.c @@ -16,9 +16,11 @@ =20 #include "standard-headers/linux/input.h" =20 -#define VIRTIO_ID_NAME_KEYBOARD "QEMU Virtio Keyboard" -#define VIRTIO_ID_NAME_MOUSE "QEMU Virtio Mouse" -#define VIRTIO_ID_NAME_TABLET "QEMU Virtio Tablet" +#define VIRTIO_ID_NAME_KEYBOARD "QEMU Virtio Keyboard" +#define VIRTIO_ID_NAME_MOUSE "QEMU Virtio Mouse" +#define VIRTIO_ID_NAME_TABLET "QEMU Virtio Tablet" +#define VIRTIO_ID_NAME_MULTITOUCH "QEMU Virtio Multitouch" +#define VIRTIO_ID_SERIAL_MULTITOUCH "virtio-touchscreen-0" =20 /* ----------------------------------------------------------------- */ =20 @@ -30,6 +32,7 @@ static const unsigned short keymap_button[INPUT_BUTTON__M= AX] =3D { [INPUT_BUTTON_WHEEL_DOWN] =3D BTN_GEAR_DOWN, [INPUT_BUTTON_SIDE] =3D BTN_SIDE, [INPUT_BUTTON_EXTRA] =3D BTN_EXTRA, + [INPUT_BUTTON_TOUCH] =3D BTN_TOUCH, }; =20 static const unsigned short axismap_rel[INPUT_AXIS__MAX] =3D { @@ -42,6 +45,11 @@ static const unsigned short axismap_abs[INPUT_AXIS__MAX]= =3D { [INPUT_AXIS_Y] =3D ABS_Y, }; =20 +static const unsigned short axismap_tch[INPUT_AXIS__MAX] =3D { + [INPUT_AXIS_X] =3D ABS_MT_POSITION_X, + [INPUT_AXIS_Y] =3D ABS_MT_POSITION_Y, +}; + /* ----------------------------------------------------------------- */ =20 static void virtio_input_extend_config(VirtIOInput *vinput, @@ -81,6 +89,7 @@ static void virtio_input_handle_event(DeviceState *dev, Q= emuConsole *src, InputKeyEvent *key; InputMoveEvent *move; InputBtnEvent *btn; + InputMultitouchEvent *mtt; =20 switch (evt->type) { case INPUT_EVENT_KIND_KEY: @@ -137,6 +146,24 @@ static void virtio_input_handle_event(DeviceState *dev= , QemuConsole *src, event.value =3D cpu_to_le32(move->value); virtio_input_send(vinput, &event); break; + case INPUT_EVENT_KIND_MTT: + mtt =3D evt->u.mtt.data; + if (mtt->type =3D=3D INPUT_MULTITOUCH_TYPE_DATA) { + event.type =3D cpu_to_le16(EV_ABS); + event.code =3D cpu_to_le16(axismap_tch[mtt->axis]); + event.value =3D cpu_to_le32(mtt->value); + virtio_input_send(vinput, &event); + } else { + event.type =3D cpu_to_le16(EV_ABS); + event.code =3D cpu_to_le16(ABS_MT_SLOT); + event.value =3D cpu_to_le32(mtt->slot); + virtio_input_send(vinput, &event); + event.type =3D cpu_to_le16(EV_ABS); + event.code =3D cpu_to_le16(ABS_MT_TRACKING_ID); + event.value =3D cpu_to_le32(mtt->tracking_id); + virtio_input_send(vinput, &event); + } + break; default: /* keep gcc happy */ break; @@ -515,12 +542,102 @@ static const TypeInfo virtio_tablet_info =3D { =20 /* ----------------------------------------------------------------- */ =20 +static QemuInputHandler virtio_multitouch_handler =3D { + .name =3D VIRTIO_ID_NAME_MULTITOUCH, + .mask =3D INPUT_EVENT_MASK_BTN | INPUT_EVENT_MASK_MTT, + .event =3D virtio_input_handle_event, + .sync =3D virtio_input_handle_sync, +}; + +static struct virtio_input_config virtio_multitouch_config[] =3D { + { + .select =3D VIRTIO_INPUT_CFG_ID_NAME, + .size =3D sizeof(VIRTIO_ID_NAME_MULTITOUCH), + .u.string =3D VIRTIO_ID_NAME_MULTITOUCH, + },{ + .select =3D VIRTIO_INPUT_CFG_ID_SERIAL, + .size =3D sizeof(VIRTIO_ID_SERIAL_MULTITOUCH), + .u.string =3D VIRTIO_ID_SERIAL_MULTITOUCH, + },{ + .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(0x0001), + }, + },{ + .select =3D VIRTIO_INPUT_CFG_ABS_INFO, + .subsel =3D ABS_MT_SLOT, + .size =3D sizeof(virtio_input_absinfo), + .u.abs.min =3D const_le32(INPUT_EVENT_SLOTS_MIN), + .u.abs.max =3D const_le32(INPUT_EVENT_SLOTS_MAX), + },{ + .select =3D VIRTIO_INPUT_CFG_ABS_INFO, + .subsel =3D ABS_MT_TRACKING_ID, + .size =3D sizeof(virtio_input_absinfo), + .u.abs.min =3D const_le32(INPUT_EVENT_SLOTS_MIN), + .u.abs.max =3D const_le32(INPUT_EVENT_SLOTS_MAX), + },{ + .select =3D VIRTIO_INPUT_CFG_ABS_INFO, + .subsel =3D ABS_MT_POSITION_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_MT_POSITION_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 void virtio_multitouch_init(Object *obj) +{ + VirtIOInputHID *vhid =3D VIRTIO_INPUT_HID(obj); + VirtIOInput *vinput =3D VIRTIO_INPUT(obj); + unsigned short abs_props[] =3D { + INPUT_PROP_DIRECT, + }; + unsigned short abs_bits[] =3D { + ABS_MT_SLOT, + ABS_MT_TRACKING_ID, + ABS_MT_POSITION_X, + ABS_MT_POSITION_Y, + }; + + vhid->handler =3D &virtio_multitouch_handler; + virtio_input_init_config(vinput, virtio_multitouch_config); + virtio_input_extend_config(vinput, keymap_button, + ARRAY_SIZE(keymap_button), + VIRTIO_INPUT_CFG_EV_BITS, EV_KEY); + virtio_input_extend_config(vinput, abs_props, + ARRAY_SIZE(abs_props), + VIRTIO_INPUT_CFG_PROP_BITS, 0); + virtio_input_extend_config(vinput, abs_bits, + ARRAY_SIZE(abs_bits), + VIRTIO_INPUT_CFG_EV_BITS, EV_ABS); +} + +static const TypeInfo virtio_multitouch_info =3D { + .name =3D TYPE_VIRTIO_MULTITOUCH, + .parent =3D TYPE_VIRTIO_INPUT_HID, + .instance_size =3D sizeof(VirtIOInputHID), + .instance_init =3D virtio_multitouch_init, +}; + +/* ----------------------------------------------------------------- */ + static void virtio_register_types(void) { type_register_static(&virtio_input_hid_info); type_register_static(&virtio_keyboard_info); type_register_static(&virtio_mouse_info); type_register_static(&virtio_tablet_info); + type_register_static(&virtio_multitouch_info); } =20 type_init(virtio_register_types) diff --git a/hw/virtio/virtio-input-pci.c b/hw/virtio/virtio-input-pci.c index a9d0992389..a53edf46c4 100644 --- a/hw/virtio/virtio-input-pci.c +++ b/hw/virtio/virtio-input-pci.c @@ -25,10 +25,11 @@ struct VirtIOInputPCI { VirtIOInput vdev; }; =20 -#define TYPE_VIRTIO_INPUT_HID_PCI "virtio-input-hid-pci" -#define TYPE_VIRTIO_KEYBOARD_PCI "virtio-keyboard-pci" -#define TYPE_VIRTIO_MOUSE_PCI "virtio-mouse-pci" -#define TYPE_VIRTIO_TABLET_PCI "virtio-tablet-pci" +#define TYPE_VIRTIO_INPUT_HID_PCI "virtio-input-hid-pci" +#define TYPE_VIRTIO_KEYBOARD_PCI "virtio-keyboard-pci" +#define TYPE_VIRTIO_MOUSE_PCI "virtio-mouse-pci" +#define TYPE_VIRTIO_TABLET_PCI "virtio-tablet-pci" +#define TYPE_VIRTIO_MULTITOUCH_PCI "virtio-multitouch-pci" OBJECT_DECLARE_SIMPLE_TYPE(VirtIOInputHIDPCI, VIRTIO_INPUT_HID_PCI) =20 struct VirtIOInputHIDPCI { @@ -102,6 +103,14 @@ static void virtio_tablet_initfn(Object *obj) TYPE_VIRTIO_TABLET); } =20 +static void virtio_multitouch_initfn(Object *obj) +{ + VirtIOInputHIDPCI *dev =3D VIRTIO_INPUT_HID_PCI(obj); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VIRTIO_MULTITOUCH); +} + static const TypeInfo virtio_input_pci_info =3D { .name =3D TYPE_VIRTIO_INPUT_PCI, .parent =3D TYPE_VIRTIO_PCI, @@ -140,6 +149,13 @@ static const VirtioPCIDeviceTypeInfo virtio_tablet_pci= _info =3D { .instance_init =3D virtio_tablet_initfn, }; =20 +static const VirtioPCIDeviceTypeInfo virtio_multitouch_pci_info =3D { + .generic_name =3D TYPE_VIRTIO_MULTITOUCH_PCI, + .parent =3D TYPE_VIRTIO_INPUT_HID_PCI, + .instance_size =3D sizeof(VirtIOInputHIDPCI), + .instance_init =3D virtio_multitouch_initfn, +}; + static void virtio_pci_input_register(void) { /* Base types: */ @@ -150,6 +166,7 @@ static void virtio_pci_input_register(void) virtio_pci_types_register(&virtio_keyboard_pci_info); virtio_pci_types_register(&virtio_mouse_pci_info); virtio_pci_types_register(&virtio_tablet_pci_info); + virtio_pci_types_register(&virtio_multitouch_pci_info); } =20 type_init(virtio_pci_input_register) diff --git a/include/hw/virtio/virtio-input.h b/include/hw/virtio/virtio-in= put.h index f2da63d309..08f1591424 100644 --- a/include/hw/virtio/virtio-input.h +++ b/include/hw/virtio/virtio-input.h @@ -24,10 +24,11 @@ OBJECT_DECLARE_TYPE(VirtIOInput, VirtIOInputClass, #define VIRTIO_INPUT_GET_PARENT_CLASS(obj) \ OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_INPUT) =20 -#define TYPE_VIRTIO_INPUT_HID "virtio-input-hid-device" -#define TYPE_VIRTIO_KEYBOARD "virtio-keyboard-device" -#define TYPE_VIRTIO_MOUSE "virtio-mouse-device" -#define TYPE_VIRTIO_TABLET "virtio-tablet-device" +#define TYPE_VIRTIO_INPUT_HID "virtio-input-hid-device" +#define TYPE_VIRTIO_KEYBOARD "virtio-keyboard-device" +#define TYPE_VIRTIO_MOUSE "virtio-mouse-device" +#define TYPE_VIRTIO_TABLET "virtio-tablet-device" +#define TYPE_VIRTIO_MULTITOUCH "virtio-multitouch-device" =20 OBJECT_DECLARE_SIMPLE_TYPE(VirtIOInputHID, VIRTIO_INPUT_HID) #define VIRTIO_INPUT_HID_GET_PARENT_CLASS(obj) \ diff --git a/include/ui/input.h b/include/ui/input.h index c86219a1c1..2a3dffd417 100644 --- a/include/ui/input.h +++ b/include/ui/input.h @@ -8,9 +8,12 @@ #define INPUT_EVENT_MASK_BTN (1< 0x7ffff +# +# Since: 2.0 +## +{ 'struct' : 'InputMultitouchEvent', + 'data' : { 'type' : 'InputMultitouchType', + 'slot' : 'int', + 'tracking-id': 'int', + 'axis' : 'InputAxis', + 'value' : 'int' } } + ## # @InputEventKind: # # Since: 2.0 ## { 'enum': 'InputEventKind', - 'data': [ 'key', 'btn', 'rel', 'abs' ] } + 'data': [ 'key', 'btn', 'rel', 'abs', 'mtt' ] } =20 ## # @InputKeyEventWrapper: @@ -1088,6 +1117,14 @@ { 'struct': 'InputMoveEventWrapper', 'data': { 'data': 'InputMoveEvent' } } =20 +## +# @InputMultitouchEventWrapper: +# +# Since: 2.0 +## +{ 'struct': 'InputMultitouchEventWrapper', + 'data': { 'data': 'InputMultitouchEvent' } } + ## # @InputEvent: # @@ -1099,6 +1136,7 @@ # - 'btn': Input event of pointer buttons # - 'rel': Input event of relative pointer motion # - 'abs': Input event of absolute pointer motion +# - 'mtt': Input event of Multitouch # # Since: 2.0 ## @@ -1108,7 +1146,8 @@ 'data' : { 'key' : 'InputKeyEventWrapper', 'btn' : 'InputBtnEventWrapper', 'rel' : 'InputMoveEventWrapper', - 'abs' : 'InputMoveEventWrapper' } } + 'abs' : 'InputMoveEventWrapper', + 'mtt' : 'InputMultitouchEventWrapper' } } =20 ## # @input-send-event: diff --git a/replay/replay-input.c b/replay/replay-input.c index 1147e3d34e..092f6b5ee9 100644 --- a/replay/replay-input.c +++ b/replay/replay-input.c @@ -22,6 +22,7 @@ void replay_save_input_event(InputEvent *evt) InputKeyEvent *key; InputBtnEvent *btn; InputMoveEvent *move; + InputMultitouchEvent *mtt; replay_put_dword(evt->type); =20 switch (evt->type) { @@ -58,6 +59,14 @@ void replay_save_input_event(InputEvent *evt) replay_put_dword(move->axis); replay_put_qword(move->value); break; + case INPUT_EVENT_KIND_MTT: + mtt =3D 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); + break; case INPUT_EVENT_KIND__MAX: /* keep gcc happy */ break; @@ -73,6 +82,7 @@ InputEvent *replay_read_input_event(void) InputBtnEvent btn; InputMoveEvent rel; InputMoveEvent abs; + InputMultitouchEvent mtt; =20 evt.type =3D replay_get_dword(); switch (evt.type) { @@ -109,6 +119,14 @@ InputEvent *replay_read_input_event(void) evt.u.abs.data->axis =3D (InputAxis)replay_get_dword(); evt.u.abs.data->value =3D replay_get_qword(); break; + case INPUT_EVENT_KIND_MTT: + evt.u.mtt.data =3D &mtt; + evt.u.mtt.data->type =3D (InputMultitouchType)replay_get_dword(); + evt.u.mtt.data->slot =3D replay_get_qword(); + evt.u.mtt.data->tracking_id =3D replay_get_qword(); + evt.u.mtt.data->axis =3D (InputAxis)replay_get_dword(); + evt.u.mtt.data->value =3D replay_get_qword(); + break; case INPUT_EVENT_KIND__MAX: /* keep gcc happy */ break; diff --git a/ui/input.c b/ui/input.c index f2d1e7a3a7..f788db20f7 100644 --- a/ui/input.c +++ b/ui/input.c @@ -212,6 +212,7 @@ static void qemu_input_event_trace(QemuConsole *src, In= putEvent *evt) InputKeyEvent *key; InputBtnEvent *btn; InputMoveEvent *move; + InputMultitouchEvent *mtt; =20 if (src) { idx =3D qemu_console_get_index(src); @@ -250,6 +251,11 @@ static void qemu_input_event_trace(QemuConsole *src, I= nputEvent *evt) name =3D InputAxis_str(move->axis); trace_input_event_abs(idx, name, move->value); break; + case INPUT_EVENT_KIND_MTT: + mtt =3D evt->u.mtt.data; + name =3D InputAxis_str(mtt->axis); + trace_input_event_mtt(idx, name, mtt->value); + break; case INPUT_EVENT_KIND__MAX: /* keep gcc happy */ break; diff --git a/ui/trace-events b/ui/trace-events index 977577fbba..6747361745 100644 --- a/ui/trace-events +++ b/ui/trace-events @@ -90,6 +90,7 @@ input_event_key_qcode(int conidx, const char *qcode, bool= down) "con %d, key qco 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" input_event_abs(int conidx, const char *axis, int value) "con %d, axis %s,= value 0x%x" +input_event_mtt(int conidx, const char *axis, int value) "con %d, axis %s,= value 0x%x" input_event_sync(void) "" input_mouse_mode(int absolute) "absolute %d" =20 --=20 2.38.1 From nobody Sat May 18 22:54:10 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1676737419; cv=none; d=zohomail.com; s=zohoarc; b=Xb5FHP1+eMcQWxlYqTMVlPDXkmpK5rGz8mDIWmhKfVYhdyCnH2dJ86Tc6+jpZhiOYhPfdKY6JD+ELmrUaW7PGTUMSKxZee9JQtE0ysoe3BRlTaxKj3o17BBlzTbNor1TuCJfVas7T20XyyGiJYFb4nSsrjUPT82oB4pi1Zj92cg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676737419; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jdsZMfmG13E3u0d8KfhRcr7kuPFXQEB/eoYUE0NxlrM=; b=V2YzmGLJnBu0awrRQ+ES6hMzyjqtEOZCYgmNDqXRhnGydqpLrXoWPp4Kw89wh21SIaWSYiPa/vDvHpCvwk5FG5994ctY6xI2cO7Eu9n5vIHA0nyjI2E4pVowzDMbRzrlXliyb/xBJANU3eVyvxL6AMlvnBvsCfUXSeHIAnVrnbU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676737419096984.66894390243; Sat, 18 Feb 2023 08:23:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pTPzR-00034h-UC; Sat, 18 Feb 2023 11:23:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pTPzM-00033u-To for qemu-devel@nongnu.org; Sat, 18 Feb 2023 11:23:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pTPzJ-0002Yp-RX for qemu-devel@nongnu.org; Sat, 18 Feb 2023 11:23:04 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-561-zPgMR4XeN9-mExterN5Dqw-1; Sat, 18 Feb 2023 11:21:16 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DF3F81871CC6; Sat, 18 Feb 2023 16:21:15 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.33.36.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id 89D9A1731B; Sat, 18 Feb 2023 16:21:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676737381; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jdsZMfmG13E3u0d8KfhRcr7kuPFXQEB/eoYUE0NxlrM=; b=NKRph8XInphSryufH7klO+i1TWD7SRHdWdYjE+OkLbCvvsu5F8KeVRcgD1OiCqOy+lMN8p PVCi8w1IIH3abENNnHwf6wCazsEDzCckI/hmF4/t9ogyHQ81RoV5J3wf+gZ5YyXvTbIT8y AqCB62Ak0X2QPqN0PTXHLmwMQT3ffSM= X-MC-Unique: zPgMR4XeN9-mExterN5Dqw-1 From: Sergio Lopez To: qemu-devel@nongnu.org Cc: Pavel Dovgalyuk , "Michael S. Tsirkin" , Gerd Hoffmann , Markus Armbruster , Paolo Bonzini , Eric Blake , Sergio Lopez Subject: [PATCH 3/4] ui: add helpers for virtio-multitouch events Date: Sat, 18 Feb 2023 17:22:15 +0100 Message-Id: <20230218162216.46944-4-slp@redhat.com> In-Reply-To: <20230218162216.46944-1-slp@redhat.com> References: <20230218162216.46944-1-slp@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=slp@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676737421171100003 Content-Type: text/plain; charset="utf-8" Add helpers for generating Multi-touch events from the UI backends that can be sent to the guest through a virtio-multitouch device. Signed-off-by: Sergio Lopez Reviewed-by: Marc-Andr=C3=A9 Lureau --- include/ui/input.h | 5 +++++ ui/input.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/ui/input.h b/include/ui/input.h index 2a3dffd417..c37251e1e9 100644 --- a/include/ui/input.h +++ b/include/ui/input.h @@ -64,6 +64,11 @@ int qemu_input_scale_axis(int value, 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); +void qemu_input_queue_mtt(QemuConsole *src, InputMultitouchType type, int = slot, + int tracking_id); +void qemu_input_queue_mtt_abs(QemuConsole *src, InputAxis axis, int value, + int min_in, int max_in, + int slot, int tracking_id); =20 void qemu_input_check_mode_change(void); void qemu_add_mouse_mode_change_notifier(Notifier *notify); diff --git a/ui/input.c b/ui/input.c index f788db20f7..34331b7b0b 100644 --- a/ui/input.c +++ b/ui/input.c @@ -547,6 +547,42 @@ void qemu_input_queue_abs(QemuConsole *src, InputAxis = axis, int value, qemu_input_event_send(src, &evt); } =20 +void qemu_input_queue_mtt(QemuConsole *src, InputMultitouchType type, + int slot, int tracking_id) +{ + InputMultitouchEvent mtt =3D { + .type =3D type, + .slot =3D slot, + .tracking_id =3D tracking_id, + }; + InputEvent evt =3D { + .type =3D INPUT_EVENT_KIND_MTT, + .u.mtt.data =3D &mtt, + }; + + qemu_input_event_send(src, &evt); +} + +void qemu_input_queue_mtt_abs(QemuConsole *src, InputAxis axis, int value, + int min_in, int max_in, int slot, int tracki= ng_id) +{ + InputMultitouchEvent mtt =3D { + .type =3D INPUT_MULTITOUCH_TYPE_DATA, + .slot =3D slot, + .tracking_id =3D tracking_id, + .axis =3D axis, + .value =3D qemu_input_scale_axis(value, min_in, max_in, + INPUT_EVENT_ABS_MIN, + INPUT_EVENT_ABS_MAX), + }; + InputEvent evt =3D { + .type =3D INPUT_EVENT_KIND_MTT, + .u.mtt.data =3D &mtt, + }; + + qemu_input_event_send(src, &evt); +} + void qemu_input_check_mode_change(void) { static int current_is_absolute; --=20 2.38.1 From nobody Sat May 18 22:54:10 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1676737412; cv=none; d=zohomail.com; s=zohoarc; b=f2DneiFzkEwIT6ymw5Crr+OD94ZKzcr9DJwnqdwhd4R86zu7tshFOabp0nr93KnZ4D+jjmkKUTfcVozfeiAuh8LWmmqrsWYxNNOoj1Rbpi0CVli0X4TYejFa+qhl9nN4wsyDTfSAFqz13yF5cyDvGRbekvt3EFMggWQCif2ZRTs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676737412; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=++qV7MlktFIh1RnTKADG5hOSuOpaBRC4UWhQKw6FTyU=; b=UhcdGpts4K0CW3v3YjK923CNwk+kv7HwRXNGGAj7hHHBJN2nnAdcZjNpUVz/3Ql5iYVlBA/Uw84o/FfraBehzwVpNpVweVFq+vtAYtRiYDv33D8W7lF0Veg2MR5pQw8wgScHNrhTGl25L8zCWJgQ4pGg7YIPAB8kFpxQosQCo5U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676737412797790.4912605360192; Sat, 18 Feb 2023 08:23:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pTPzQ-00034H-OE; Sat, 18 Feb 2023 11:23:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pTPzL-00033g-Dx for qemu-devel@nongnu.org; Sat, 18 Feb 2023 11:23:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pTPzJ-0002Yh-GY for qemu-devel@nongnu.org; Sat, 18 Feb 2023 11:23:03 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-577-lt2sZNfqMoKWBPcewM7A5g-1; Sat, 18 Feb 2023 11:21:17 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7C78929AA2C1; Sat, 18 Feb 2023 16:21:17 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.33.36.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id 279561731B; Sat, 18 Feb 2023 16:21:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676737381; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=++qV7MlktFIh1RnTKADG5hOSuOpaBRC4UWhQKw6FTyU=; b=a2VnK3Y453MqqW1ExedC7DRe6RsLnjHwlB0n+JpDWuP/tpWqnH6eePztYvbSkDLpyMmcQn gGH/kUJMjoY/moT+ya4iT9PKWUjF9FlMAmE5prR4LMWdf8kDMr5UNPoJg/l56lNYQUmyhg u+Bk7sZcGjPOvvBHCwiA3OitvJqlUMg= X-MC-Unique: lt2sZNfqMoKWBPcewM7A5g-1 From: Sergio Lopez To: qemu-devel@nongnu.org Cc: Pavel Dovgalyuk , "Michael S. Tsirkin" , Gerd Hoffmann , Markus Armbruster , Paolo Bonzini , Eric Blake , Sergio Lopez Subject: [PATCH 4/4] ui/gtk: enable backend to send multi-touch events Date: Sat, 18 Feb 2023 17:22:16 +0100 Message-Id: <20230218162216.46944-5-slp@redhat.com> In-Reply-To: <20230218162216.46944-1-slp@redhat.com> References: <20230218162216.46944-1-slp@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=slp@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676737415273100003 Content-Type: text/plain; charset="utf-8" GTK3 provides the infrastructure to receive and process multi-touch events through the "touch-event" signal and the GdkEventTouch type. Make use of it to transpose events from the host to the guest. This allows users of machines with hardware capable of receiving multi-touch events to run guests that can also receive those events and interpret them as gestures, when appropriate. An example of this in action can be seen here: https://fosstodon.org/@slp/109545849296546767 Signed-off-by: Sergio Lopez --- ui/gtk.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/ui/gtk.c b/ui/gtk.c index fd82e9b1ca..bf1e7f086d 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -130,6 +130,13 @@ typedef struct VCChardev VCChardev; DECLARE_INSTANCE_CHECKER(VCChardev, VC_CHARDEV, TYPE_CHARDEV_VC) =20 +struct touch_slot { + int x; + int y; + int tracking_id; +}; +static struct touch_slot touch_slots[INPUT_EVENT_SLOTS_MAX]; + bool gtk_use_gl_area; =20 static void gd_grab_pointer(VirtualConsole *vc, const char *reason); @@ -1058,6 +1065,74 @@ static gboolean gd_scroll_event(GtkWidget *widget, G= dkEventScroll *scroll, } =20 =20 +static gboolean gd_touch_event(GtkWidget *widget, GdkEventTouch *touch, + void *opaque) +{ + VirtualConsole *vc =3D opaque; + struct touch_slot *slot; + uint64_t num_slot =3D (uint64_t) touch->sequence; + int update; + int type =3D -1; + int i; + + if (num_slot >=3D INPUT_EVENT_SLOTS_MAX) { + return FALSE; + } + + slot =3D &touch_slots[num_slot]; + slot->x =3D touch->x; + slot->y =3D touch->y; + + switch (touch->type) { + case GDK_TOUCH_BEGIN: + type =3D INPUT_MULTITOUCH_TYPE_BEGIN; + slot->tracking_id =3D num_slot; + break; + case GDK_TOUCH_UPDATE: + type =3D INPUT_MULTITOUCH_TYPE_UPDATE; + break; + case GDK_TOUCH_END: + case GDK_TOUCH_CANCEL: + type =3D INPUT_MULTITOUCH_TYPE_END; + break; + default: + fprintf(stderr, "%s: unexpected touch event\n", __func__); + } + + for (i =3D 0; i < INPUT_EVENT_SLOTS_MAX; ++i) { + if (i =3D=3D num_slot) { + update =3D type; + } else { + update =3D INPUT_MULTITOUCH_TYPE_UPDATE; + } + + slot =3D &touch_slots[i]; + + if (slot->tracking_id =3D=3D -1) { + continue; + } + + if (update =3D=3D INPUT_MULTITOUCH_TYPE_END) { + slot->tracking_id =3D -1; + qemu_input_queue_mtt(vc->gfx.dcl.con, update, i, slot->trackin= g_id); + } else { + qemu_input_queue_mtt(vc->gfx.dcl.con, update, i, slot->trackin= g_id); + qemu_input_queue_btn(vc->gfx.dcl.con, INPUT_BUTTON_TOUCH, true= ); + qemu_input_queue_mtt_abs(vc->gfx.dcl.con, + INPUT_AXIS_X, (int) slot->x, + 0, surface_width(vc->gfx.ds), + i, slot->tracking_id); + qemu_input_queue_mtt_abs(vc->gfx.dcl.con, + INPUT_AXIS_Y, (int) slot->y, + 0, surface_height(vc->gfx.ds), + i, slot->tracking_id); + } + qemu_input_event_sync(); + } + + return TRUE; +} + static const guint16 *gd_get_keymap(size_t *maplen) { GdkDisplay *dpy =3D gdk_display_get_default(); @@ -1977,6 +2052,8 @@ static void gd_connect_vc_gfx_signals(VirtualConsole = *vc) G_CALLBACK(gd_key_event), vc); g_signal_connect(vc->gfx.drawing_area, "key-release-event", G_CALLBACK(gd_key_event), vc); + g_signal_connect(vc->gfx.drawing_area, "touch-event", + G_CALLBACK(gd_touch_event), vc); =20 g_signal_connect(vc->gfx.drawing_area, "enter-notify-event", G_CALLBACK(gd_enter_event), vc); @@ -2086,6 +2163,7 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, Vir= tualConsole *vc, GSList *group, GtkWidget *view_menu) { bool zoom_to_fit =3D false; + int i; =20 vc->label =3D qemu_console_get_label(con); vc->s =3D s; @@ -2133,6 +2211,7 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, Vir= tualConsole *vc, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_MOTION_MASK | + GDK_TOUCH_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_SCROLL_MASK | @@ -2168,6 +2247,11 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, Vi= rtualConsole *vc, s->free_scale =3D true; } =20 + for (i =3D 0; i < INPUT_EVENT_SLOTS_MAX; i++) { + struct touch_slot *slot =3D &touch_slots[i]; + slot->tracking_id =3D -1; + } + return group; } =20 --=20 2.38.1