qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Sergio Lopez <slp@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@gmail.com>
Cc: qemu-devel@nongnu.org, Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Gerd Hoffmann <kraxel@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Eric Blake <eblake@redhat.com>
Subject: Re: [PATCH 4/4] ui/gtk: enable backend to send multi-touch events
Date: Thu, 16 Mar 2023 13:21:28 +0100	[thread overview]
Message-ID: <20230316122128.fwhl2dsu5uyomgwf@mhamilton> (raw)
In-Reply-To: <CAJ+F1C+An6Mbi0DdXVQ2z-VjEUZDkBGVwzo633N_Eeqr53CdHA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 6928 bytes --]

On Sun, Feb 19, 2023 at 12:28:22PM +0400, Marc-André Lureau wrote:
> Hi Sergio
> 
> On Sat, Feb 18, 2023 at 8:23 PM Sergio Lopez <slp@redhat.com> wrote:
> >
> > 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 <slp@redhat.com>
> 
> > ---
> >  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)
> >
> > +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,74 @@ 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 = (uint64_t) touch->sequence;
> 
> Perhaps use GPOINTER_TO_UINT?

Yes, this looks better.

> > +    int update;
> > +    int type = -1;
> > +    int i;
> > +
> > +    if (num_slot >= INPUT_EVENT_SLOTS_MAX) {
> > +        return FALSE;
> > +    }
> 
> Hmm, a pointer < INPUT_EVENT_SLOTS_MAX ?
> 
> This seems to work because the wayland GDK backend uses presumably
> evdev slot id + 1.. We may want to have some slot id mapping, or at
> least report some warning for discarded events.

It's weird, but it's definitely not a real pointer either. GDK is basically
wrapping up the MT event slot in touch->sequence, which is a pointer:

gdk/wayland/gdkdevice-wayland.c:297:
#define GDK_SLOT_TO_EVENT_SEQUENCE(s) ((GdkEventSequence *) GUINT_TO_POINTER((s) + 1))

gdk/wayland/gdkdevice-wayland.c:2434:
  event->touch.sequence = GDK_SLOT_TO_EVENT_SEQUENCE (touch->id);

I think it makes sense to convert it the other way around here. In v2, I also
added a warning in case num_slot >= INPUT_EVENT_SLOTS_MAX.

> > +
> > +    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);
> > +        } 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);
> > +        }
> > +        qemu_input_event_sync();
> 
> Shouldn't you sync at the end of the loop? (otherwise you get several
> SYN_REPORT, no?)

You're right, fixed in v2.

Thanks!
Sergio.

> > +    }
> > +
> > +    return TRUE;
> > +}
> > +
> >  static const guint16 *gd_get_keymap(size_t *maplen)
> >  {
> >      GdkDisplay *dpy = 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);
> >
> >          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, 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 +2211,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 +2247,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;
> >  }
> >
> > --
> > 2.38.1
> >
> >
> 
> 
> -- 
> Marc-André Lureau
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      reply	other threads:[~2023-03-16 12:20 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-18 16:22 [PATCH 0/4] Implement virtio-multitouch and enable GTK3 to use it Sergio Lopez
2023-02-18 16:22 ` [PATCH 1/4] virtio-input: generalize virtio_input_key_config() Sergio Lopez
2023-02-19  8:07   ` Marc-André Lureau
2023-02-18 16:22 ` [PATCH 2/4] virtio-input: add a virtio-mulitouch device Sergio Lopez
2023-02-19  8:06   ` Marc-André Lureau
2023-02-21 11:57   ` Pavel Dovgalyuk
2023-02-18 16:22 ` [PATCH 3/4] ui: add helpers for virtio-multitouch events Sergio Lopez
2023-02-19  8:07   ` Marc-André Lureau
2023-02-18 16:22 ` [PATCH 4/4] ui/gtk: enable backend to send multi-touch events Sergio Lopez
2023-02-19  8:28   ` Marc-André Lureau
2023-03-16 12:21     ` Sergio Lopez [this message]

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=20230316122128.fwhl2dsu5uyomgwf@mhamilton \
    --to=slp@redhat.com \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=marcandre.lureau@gmail.com \
    --cc=mst@redhat.com \
    --cc=pavel.dovgaluk@ispras.ru \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).