gesturestylus: Only add histroy element if translation succeeded

Instead of always doing it and then undoing it if the translation does
not succeed.
This commit is contained in:
Timm Bäder 2020-12-25 10:07:43 +01:00
parent e336fe2bf8
commit 71efa96ef2

View File

@ -344,24 +344,22 @@ gtk_gesture_stylus_get_backlog (GtkGestureStylus *gesture,
controller_widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
for (i = 0; i < n_coords; i++)
{
GdkTimeCoord *time_coord = &history[i];
const GdkTimeCoord *time_coord = &history[i];
graphene_point_t p;
g_array_append_val (backlog_array, *time_coord);
time_coord = &g_array_index (backlog_array, GdkTimeCoord, backlog_array->len - 1);
if (gtk_widget_compute_point (event_widget, controller_widget,
&GRAPHENE_POINT_INIT (time_coord->axes[GDK_AXIS_X] - surf_x,
time_coord->axes[GDK_AXIS_Y] - surf_y),
&p))
{
time_coord->axes[GDK_AXIS_X] = p.x;
time_coord->axes[GDK_AXIS_Y] = p.y;
GdkTimeCoord translated_coord = *time_coord;
translated_coord.axes[GDK_AXIS_X] = p.x;
translated_coord.axes[GDK_AXIS_Y] = p.y;
g_array_append_val (backlog_array, translated_coord);
}
else
{
g_array_set_size (backlog_array, backlog_array->len - 1);
}
}
}
*n_elems = backlog_array->len;
*backlog = (GdkTimeCoord *) g_array_free (backlog_array, FALSE);