backends: Unify touch sequence to slot conversion

We had code in both backends that sort of independently associated
sequences to slots. Make both transform slots to sequences the same
way, so they may share the implementation convert those back to slots.

This helper now lives in Clutter API.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1623>
This commit is contained in:
Carlos Garnacho 2020-12-08 12:51:56 +01:00 committed by Marge Bot
parent 9f5c453fc7
commit eaa04ecee5
10 changed files with 18 additions and 37 deletions

View File

@ -2134,3 +2134,11 @@ clutter_event_get_event_code (const ClutterEvent *event)
return 0; return 0;
} }
int32_t
clutter_event_sequence_get_slot (const ClutterEventSequence *sequence)
{
g_return_val_if_fail (sequence != NULL, -1);
return GPOINTER_TO_INT (sequence) - 1;
}

View File

@ -788,6 +788,9 @@ gboolean clutter_event_get_pad_event_details (const Clut
CLUTTER_EXPORT CLUTTER_EXPORT
uint32_t clutter_event_get_event_code (const ClutterEvent *event); uint32_t clutter_event_get_event_code (const ClutterEvent *event);
CLUTTER_EXPORT
int32_t clutter_event_sequence_get_slot (const ClutterEventSequence *sequence);
G_END_DECLS G_END_DECLS
#endif /* __CLUTTER_EVENT_H__ */ #endif /* __CLUTTER_EVENT_H__ */

View File

@ -154,23 +154,3 @@ meta_event_native_get_relative_motion (const ClutterEvent *event,
else else
return FALSE; return FALSE;
} }
/**
* meta_event_native_sequence_get_slot:
* @sequence: a #ClutterEventSequence
*
* Retrieves the touch slot triggered by this @sequence
*
* Returns: the libinput touch slot.
*
* Since: 1.20
* Stability: unstable
**/
int32_t
meta_event_native_sequence_get_slot (const ClutterEventSequence *sequence)
{
if (!sequence)
return -1;
return GPOINTER_TO_INT (sequence) - 1;
}

View File

@ -42,6 +42,4 @@ gboolean meta_event_native_get_relative_motion (const ClutterEvent *eve
double *dx_unaccel, double *dx_unaccel,
double *dy_unaccel); double *dy_unaccel);
int32_t meta_event_native_sequence_get_slot (const ClutterEventSequence *sequence);
#endif /* META_EVENT_NATIVE_H */ #endif /* META_EVENT_NATIVE_H */

View File

@ -2890,7 +2890,7 @@ meta_seat_impl_query_state (MetaSeatImpl *seat_impl,
MetaTouchState *touch_state; MetaTouchState *touch_state;
int slot; int slot;
slot = meta_event_native_sequence_get_slot (sequence); slot = clutter_event_sequence_get_slot (sequence);
touch_state = meta_seat_impl_lookup_touch_state_in_impl (seat_impl, slot); touch_state = meta_seat_impl_lookup_touch_state_in_impl (seat_impl, slot);
if (!touch_state) if (!touch_state)
goto out; goto out;

View File

@ -691,7 +691,7 @@ meta_backend_x11_finish_touch_sequence (MetaBackend *backend,
XIAllowTouchEvents (priv->xdisplay, XIAllowTouchEvents (priv->xdisplay,
META_VIRTUAL_CORE_POINTER_ID, META_VIRTUAL_CORE_POINTER_ID,
meta_x11_event_sequence_get_touch_detail (sequence), clutter_event_sequence_get_slot (sequence),
DefaultRootWindow (priv->xdisplay), event_mode); DefaultRootWindow (priv->xdisplay), event_mode);
if (state == META_SEQUENCE_REJECTED) if (state == META_SEQUENCE_REJECTED)

View File

@ -113,11 +113,3 @@ out:
return result; return result;
} }
guint
meta_x11_event_sequence_get_touch_detail (const ClutterEventSequence *sequence)
{
g_return_val_if_fail (sequence != NULL, 0);
return GPOINTER_TO_UINT (sequence);
}

View File

@ -28,8 +28,6 @@
#include "clutter/x11/clutter-x11.h" #include "clutter/x11/clutter-x11.h"
guint meta_x11_event_sequence_get_touch_detail (const ClutterEventSequence *sequence);
ClutterX11FilterReturn meta_x11_handle_event (XEvent *xevent); ClutterX11FilterReturn meta_x11_handle_event (XEvent *xevent);
#endif /* META_EVENT_X11_H */ #endif /* META_EVENT_X11_H */

View File

@ -2213,7 +2213,8 @@ meta_seat_x11_translate_event (MetaSeatX11 *seat,
GUINT_TO_POINTER (xev->detail)); GUINT_TO_POINTER (xev->detail));
} }
event->touch.sequence = GUINT_TO_POINTER (xev->detail); /* "NULL" sequences are special cased in clutter */
event->touch.sequence = GINT_TO_POINTER (MAX (1, xev->detail + 1));
if (xev->flags & XITouchEmulatingPointer) if (xev->flags & XITouchEmulatingPointer)
_clutter_event_set_pointer_emulated (event, TRUE); _clutter_event_set_pointer_emulated (event, TRUE);
@ -2242,7 +2243,8 @@ meta_seat_x11_translate_event (MetaSeatX11 *seat,
event->touch.type = event->type = CLUTTER_TOUCH_UPDATE; event->touch.type = event->type = CLUTTER_TOUCH_UPDATE;
event->touch.stage = stage; event->touch.stage = stage;
event->touch.time = xev->time; event->touch.time = xev->time;
event->touch.sequence = GUINT_TO_POINTER (xev->detail); /* "NULL" sequences are special cased in clutter */
event->touch.sequence = GINT_TO_POINTER (MAX (1, xev->detail + 1));
translate_coords (stage_x11, xev->event_x, xev->event_y, &event->touch.x, &event->touch.y); translate_coords (stage_x11, xev->event_x, xev->event_y, &event->touch.x, &event->touch.y);
clutter_event_set_source_device (event, source_device); clutter_event_set_source_device (event, source_device);

View File

@ -188,7 +188,7 @@ touch_get_info (MetaWaylandTouch *touch,
if (!touch_info && create) if (!touch_info && create)
{ {
touch_info = g_new0 (MetaWaylandTouchInfo, 1); touch_info = g_new0 (MetaWaylandTouchInfo, 1);
touch_info->slot = meta_event_native_sequence_get_slot (sequence); touch_info->slot = clutter_event_sequence_get_slot (sequence);
g_hash_table_insert (touch->touches, sequence, touch_info); g_hash_table_insert (touch->touches, sequence, touch_info);
} }