From f8a8b61171ca21057585cbec43cece7a2432d57b Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Thu, 15 Jun 2023 13:47:20 +0200 Subject: [PATCH 1/4] display-picture: Split guest absolute position into a helper Will be shared with touch events in the next commit --- lib/mks-display-picture.c | 74 +++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 22 deletions(-) diff --git a/lib/mks-display-picture.c b/lib/mks-display-picture.c index 3e88052..a4efb1b 100644 --- a/lib/mks-display-picture.c +++ b/lib/mks-display-picture.c @@ -173,6 +173,55 @@ mks_display_picture_mouse_release_cb (GObject *object, g_warning ("Mouse release failed: %s", error->message); } +static gboolean +mks_display_picture_event_get_guest_position (MksDisplayPicture *self, + GdkEvent *event, + double *guest_x, + double *guest_y) +{ + GdkPaintable *paintable; + GtkNative *native; + int guest_width, guest_height; + graphene_rect_t area; + graphene_point_t translated; + double translate_x, translate_y; + double x, y; + + g_assert (MKS_IS_DISPLAY_PICTURE (self)); + g_assert (GDK_IS_EVENT (event)); + + paintable = GDK_PAINTABLE (self->paintable); + native = gtk_widget_get_native (GTK_WIDGET (self)); + guest_width = gdk_paintable_get_intrinsic_width (paintable); + guest_height = gdk_paintable_get_intrinsic_height (paintable); + + area = GRAPHENE_RECT_INIT (0, 0, + gtk_widget_get_width (GTK_WIDGET (self)), + gtk_widget_get_height (GTK_WIDGET (self))); + gtk_native_get_surface_transform (native, &translate_x, &translate_y); + + if (gdk_event_get_position (event, &x, &y)) + { + x -= translate_x; + y -= translate_y; + + if (!gtk_widget_compute_point (GTK_WIDGET (native), + GTK_WIDGET (self), + &GRAPHENE_POINT_INIT (x, y), + &translated)) + return FALSE; + + *guest_x = floor (translated.x) / area.size.width * guest_width; + *guest_y = floor (translated.y) / area.size.height * guest_height; + + *guest_x = CLAMP (*guest_x, 0, guest_width); + *guest_y = CLAMP (*guest_y, 0, guest_width); + + return TRUE; + } + + return FALSE; +} static gboolean mks_display_picture_legacy_event_cb (MksDisplayPicture *self, @@ -183,7 +232,7 @@ mks_display_picture_legacy_event_cb (MksDisplayPicture *self, GdkEventType event_type; g_assert (MKS_IS_DISPLAY_PICTURE (self)); - g_assert (event != NULL); + g_assert (GDK_IS_EVENT (event)); g_assert (GTK_IS_EVENT_CONTROLLER_LEGACY (controller)); if (self->keyboard == NULL || self->mouse == NULL || self->paintable == NULL) @@ -215,28 +264,9 @@ mks_display_picture_legacy_event_cb (MksDisplayPicture *self, if (mks_mouse_get_is_absolute (self->mouse)) { - gdouble x, y; - - if (gdk_event_get_position (event, &x, &y)) + double guest_x, guest_y; + if (mks_display_picture_event_get_guest_position (self, event, &guest_x, &guest_y)) { - graphene_point_t translated; - double guest_x, guest_y; - - x -= translate_x; - y -= translate_y; - - if (!gtk_widget_compute_point (GTK_WIDGET (native), - GTK_WIDGET (self), - &GRAPHENE_POINT_INIT (x, y), - &translated)) - break; - - guest_x = floor (translated.x) / area.size.width * guest_width; - guest_y = floor (translated.y) / area.size.height * guest_height; - - guest_x = CLAMP (guest_x, 0, guest_width); - guest_y = CLAMP (guest_y, 0, guest_width); - mks_mouse_move_to (self->mouse, guest_x, guest_y, From c28a6f85e27ae992524ef1f04c2675b01cfef3a9 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Thu, 15 Jun 2023 13:48:55 +0200 Subject: [PATCH 2/4] device: Implement the new touch interface --- lib/dbus-display1.xml | 45 ++++- lib/libmks.h | 1 + lib/meson.build | 2 + lib/mks-display-picture-private.h | 3 + lib/mks-display-picture.c | 87 +++++++- lib/mks-display.c | 2 + lib/mks-init.c | 2 + lib/mks-screen.c | 20 ++ lib/mks-screen.h | 2 + lib/mks-touchable.c | 316 ++++++++++++++++++++++++++++++ lib/mks-touchable.h | 88 +++++++++ lib/mks-types.h | 1 + 12 files changed, 566 insertions(+), 3 deletions(-) create mode 100644 lib/mks-touchable.c create mode 100644 lib/mks-touchable.h diff --git a/lib/dbus-display1.xml b/lib/dbus-display1.xml index 28e498b..e8f2394 100644 --- a/lib/dbus-display1.xml +++ b/lib/dbus-display1.xml @@ -39,8 +39,9 @@ "Text" (see :dbus:prop:`Type` and other properties). Interactions with a console may be done with - :dbus:iface:`org.qemu.Display1.Keyboard` and - :dbus:iface:`org.qemu.Display1.Mouse` interfaces when available. + :dbus:iface:`org.qemu.Display1.Keyboard`, + :dbus:iface:`org.qemu.Display1.Mouse` and + :dbus:iface:`org.qemu.Display1.Touch` interfaces when available. --> + + + + + + + + + + + + +