display: Expose a helper for retriving guest position

When running an Android VM with GL support, Android somehow enforces
support for only touch events making it difficult to work with QEMU +
Android for devolpement / demo purposes without a touch screen.

This helper is useful for being able to emulate motion / click
events as touch ones
This commit is contained in:
Bilal Elmoussaoui 2023-06-19 23:57:55 +02:00
parent 3aee839269
commit af8d90d1b5
4 changed files with 41 additions and 2 deletions

View File

@ -45,5 +45,9 @@ void mks_display_picture_set_keyboard (MksDisplayPicture *self,
MksTouchable *mks_display_picture_get_touchable (MksDisplayPicture *self); MksTouchable *mks_display_picture_get_touchable (MksDisplayPicture *self);
void mks_display_picture_set_touchable (MksDisplayPicture *self, void mks_display_picture_set_touchable (MksDisplayPicture *self,
MksTouchable *touchable); MksTouchable *touchable);
gboolean
mks_display_picture_event_get_guest_position (MksDisplayPicture *self,
GdkEvent *event,
double *guest_x,
double *guest_y);
G_END_DECLS G_END_DECLS

View File

@ -193,7 +193,7 @@ mks_display_picture_mouse_release_cb (GObject *object,
g_debug ("Mouse release failed: %s", error->message); g_debug ("Mouse release failed: %s", error->message);
} }
static gboolean gboolean
mks_display_picture_event_get_guest_position (MksDisplayPicture *self, mks_display_picture_event_get_guest_position (MksDisplayPicture *self,
GdkEvent *event, GdkEvent *event,
double *guest_x, double *guest_x,

View File

@ -569,3 +569,32 @@ mks_display_set_ungrab_trigger (MksDisplay *self,
MKS_EXIT; MKS_EXIT;
} }
/**
* mks_display_get_event_position_in_guest:
* @self: a #MksDisplay
* @event: A #GdkEvent
* @guest_x: (out): Guest's X position
* @guest_y: (out): Guest's Y position
*
* Retrieve the (`guest_x`, `guest_y`) position
* where the `event` happened.
*
* Could be useful for implementing touch support emulation.
*
* Returns: Whether the event has an associated position
*/
gboolean
mks_display_get_event_position_in_guest (MksDisplay *self,
GdkEvent *event,
double *guest_x,
double *guest_y)
{
MksDisplayPrivate *priv = mks_display_get_instance_private (self);
g_return_val_if_fail (MKS_IS_DISPLAY (self), FALSE);
g_return_val_if_fail (GDK_IS_EVENT (event), FALSE);
return mks_display_picture_event_get_guest_position (priv->picture, event,
guest_x, guest_y);
}

View File

@ -58,4 +58,10 @@ gboolean mks_display_get_auto_resize (MksDisplay *self);
MKS_AVAILABLE_IN_ALL MKS_AVAILABLE_IN_ALL
void mks_display_set_auto_resize (MksDisplay *self, void mks_display_set_auto_resize (MksDisplay *self,
gboolean auto_resize); gboolean auto_resize);
MKS_AVAILABLE_IN_ALL
gboolean
mks_display_get_event_position_in_guest (MksDisplay *self,
GdkEvent *event,
double *guest_x,
double *guest_y);
G_END_DECLS G_END_DECLS