From patchwork Thu Mar 16 12:06:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sergio Lopez Pascual X-Patchwork-Id: 13177463 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9281BC6FD1F for ; Thu, 16 Mar 2023 12:07:30 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pcmMK-0002lT-3F; Thu, 16 Mar 2023 08:05:28 -0400 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 1pcmMH-0002jS-K0 for qemu-devel@nongnu.org; Thu, 16 Mar 2023 08:05:25 -0400 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 1pcmMF-0002pb-PE for qemu-devel@nongnu.org; Thu, 16 Mar 2023 08:05:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678968322; 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=BFXEqi3+afrhJ6fKwOMxcErtjjrlJEkqPpu5/+P9lp4=; b=Vn5BUPlxHMu2qHt+alvkOxovZ1J8FZ/dskWetO0Ylihpd6Dh5Nz/vfeOVWlkn8OcfF0ugJ pTitzhsAk7+tVLLFY2dFSzrdNKFO8ZFXzlKE4zT/8FGha6T2AsC8Z7P36ngKlXi+L6SBDA vnZ84BYfk862dHBSfu2SbAuQ3eV2b1M= 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-176--elP1ARMODmbaDirN3Hf8Q-1; Thu, 16 Mar 2023 08:05:19 -0400 X-MC-Unique: -elP1ARMODmbaDirN3Hf8Q-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2A6921C06EEE; Thu, 16 Mar 2023 12:05:19 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.33.36.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 97757140EBF4; Thu, 16 Mar 2023 12:05:17 +0000 (UTC) From: Sergio Lopez To: qemu-devel@nongnu.org Cc: Eric Blake , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Pavel Dovgalyuk , "Michael S. Tsirkin" , Markus Armbruster , Gerd Hoffmann , Paolo Bonzini , Sergio Lopez Subject: [PATCH v2 6/6] ui/gtk: enable backend to send multi-touch events Date: Thu, 16 Mar 2023 13:06:24 +0100 Message-Id: <20230316120624.46410-7-slp@redhat.com> In-Reply-To: <20230316120624.46410-1-slp@redhat.com> References: <20230316120624.46410-1-slp@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 Reviewed-by: Marc-André Lureau --- ui/gtk.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/ui/gtk.c b/ui/gtk.c index fd82e9b1ca..3a667bfba6 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) +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; static void gd_grab_pointer(VirtualConsole *vc, const char *reason); @@ -1058,6 +1065,82 @@ static gboolean gd_scroll_event(GtkWidget *widget, GdkEventScroll *scroll, } +static gboolean gd_touch_event(GtkWidget *widget, GdkEventTouch *touch, + void *opaque) +{ + VirtualConsole *vc = opaque; + struct touch_slot *slot; + uint64_t num_slot = GPOINTER_TO_UINT(touch->sequence); + bool needs_sync = false; + int update; + int type = -1; + int i; + + if (num_slot >= INPUT_EVENT_SLOTS_MAX) { + fprintf(stderr, "%s: unexpected touch slot number: %ld >= %d\n", + __func__, num_slot, INPUT_EVENT_SLOTS_MAX); + return FALSE; + } + + slot = &touch_slots[num_slot]; + slot->x = touch->x; + slot->y = touch->y; + + switch (touch->type) { + case GDK_TOUCH_BEGIN: + type = INPUT_MULTITOUCH_TYPE_BEGIN; + slot->tracking_id = num_slot; + break; + case GDK_TOUCH_UPDATE: + type = INPUT_MULTITOUCH_TYPE_UPDATE; + break; + case GDK_TOUCH_END: + case GDK_TOUCH_CANCEL: + type = INPUT_MULTITOUCH_TYPE_END; + break; + default: + fprintf(stderr, "%s: unexpected touch event\n", __func__); + } + + for (i = 0; i < INPUT_EVENT_SLOTS_MAX; ++i) { + if (i == num_slot) { + update = type; + } else { + update = INPUT_MULTITOUCH_TYPE_UPDATE; + } + + slot = &touch_slots[i]; + + if (slot->tracking_id == -1) { + continue; + } + + if (update == INPUT_MULTITOUCH_TYPE_END) { + slot->tracking_id = -1; + qemu_input_queue_mtt(vc->gfx.dcl.con, update, i, slot->tracking_id); + needs_sync = true; + } else { + qemu_input_queue_mtt(vc->gfx.dcl.con, update, i, slot->tracking_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); + needs_sync = true; + } + } + + if (needs_sync) { + qemu_input_event_sync(); + } + + return TRUE; +} + static const guint16 *gd_get_keymap(size_t *maplen) { GdkDisplay *dpy = gdk_display_get_default(); @@ -1977,6 +2060,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); g_signal_connect(vc->gfx.drawing_area, "enter-notify-event", G_CALLBACK(gd_enter_event), vc); @@ -2086,6 +2171,7 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc, GSList *group, GtkWidget *view_menu) { bool zoom_to_fit = false; + int i; vc->label = qemu_console_get_label(con); vc->s = s; @@ -2133,6 +2219,7 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *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 +2255,11 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc, s->free_scale = true; } + for (i = 0; i < INPUT_EVENT_SLOTS_MAX; i++) { + struct touch_slot *slot = &touch_slots[i]; + slot->tracking_id = -1; + } + return group; }