clutter: Use brand new event to contain compressed motion information

Avoid overwriting ClutterEvent fields, and build a new ClutterEvent from
the previous information.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3153>
This commit is contained in:
Carlos Garnacho 2023-08-04 12:21:55 +02:00
parent 9dd2edac18
commit ded1a9b351

View File

@ -668,32 +668,44 @@ _clutter_stage_has_queued_events (ClutterStage *stage)
return priv->event_queue->length > 0; return priv->event_queue->length > 0;
} }
static void static ClutterEvent *
clutter_stage_compress_motion (ClutterStage *stage, clutter_stage_compress_motion (ClutterStage *stage,
ClutterEvent *event, ClutterEvent *event,
const ClutterEvent *to_discard) const ClutterEvent *to_discard)
{ {
double dx, dy; double dx, dy;
double dx_unaccel, dy_unaccel; double dx_unaccel, dy_unaccel;
double dx_constrained, dy_constrained;
double dst_dx = 0.0, dst_dy = 0.0; double dst_dx = 0.0, dst_dy = 0.0;
double dst_dx_unaccel = 0.0, dst_dy_unaccel = 0.0; double dst_dx_unaccel = 0.0, dst_dy_unaccel = 0.0;
double dst_dx_constrained = 0.0, dst_dy_constrained = 0.0;
graphene_point_t coords;
if (!clutter_event_get_relative_motion (to_discard, if (!clutter_event_get_relative_motion (to_discard,
&dx, &dy, &dx, &dy,
&dx_unaccel, &dy_unaccel, &dx_unaccel, &dy_unaccel,
NULL, NULL)) &dx_constrained, &dy_constrained))
return; return NULL;
clutter_event_get_relative_motion (event, clutter_event_get_relative_motion (event,
&dst_dx, &dst_dy, &dst_dx, &dst_dy,
&dst_dx_unaccel, &dst_dy_unaccel, &dst_dx_unaccel, &dst_dy_unaccel,
NULL, NULL); &dst_dx_constrained, &dst_dy_constrained);
event->motion.flags |= CLUTTER_EVENT_FLAG_RELATIVE_MOTION; clutter_event_get_position (event, &coords);
event->motion.dx = dx + dst_dx;
event->motion.dy = dy + dst_dy; return clutter_event_motion_new (CLUTTER_EVENT_FLAG_RELATIVE_MOTION,
event->motion.dx_unaccel = dx_unaccel + dst_dx_unaccel; clutter_event_get_time_us (event),
event->motion.dy_unaccel = dy_unaccel + dst_dy_unaccel; clutter_event_get_source_device (event),
clutter_event_get_device_tool (event),
clutter_event_get_state (event),
coords,
GRAPHENE_POINT_INIT (dx + dst_dx, dy + dst_dy),
GRAPHENE_POINT_INIT (dx_unaccel + dst_dx_unaccel,
dy_unaccel + dst_dy_unaccel),
GRAPHENE_POINT_INIT (dx_constrained + dst_dx_constrained,
dy_constrained + dst_dy_constrained),
NULL);
} }
CLUTTER_EXPORT void CLUTTER_EXPORT void
@ -754,7 +766,18 @@ _clutter_stage_process_queued_events (ClutterStage *stage)
(int) event->motion.y); (int) event->motion.y);
if (next_event->type == CLUTTER_MOTION) if (next_event->type == CLUTTER_MOTION)
clutter_stage_compress_motion (stage, next_event, event); {
ClutterEvent *new_event;
new_event =
clutter_stage_compress_motion (stage, next_event, event);
if (new_event)
{
/* Replace the next event with the rewritten one */
l->next->data = new_event;
clutter_event_free (next_event);
}
}
goto next_event; goto next_event;
} }