Skip to content

gdk3: Interpolate scroll events to screen refresh, part 1 of 4

Yariv requested to merge yarivb/gtk:gdk-3-event-interpolation-part-1 into gtk-3-24

TLDR

This is the first part in an MR series aimed at solving jitter in animation based on continuous input. See #2025 for details about the issue, and !1117 for a general description of the solution.

Continued in !1560

What it does

Add accessors to GdkEvent for getting and setting the interpolated properties of precise scroll events. Additionally gdk_event_set_time() and gdk_event_set_state() are 'backported' from git master.

In this MR the accessors are mostly just skeletons. For a more complete example see https://gitlab.gnome.org/yarivb/gtk/-/blob/gdk-3-touchscreen-interpolation/gdk/gdkevents.c#L1307 which includes support for more event types.

Rational

GdkEventHistory, the new event history container (see !1560), queries the GdkEvents that it holds for the values of properties that have to be resampled. It then synthesizes a new GdkEvent with these interpolated values. In order to do that in a generic way, each supported event type returns an opaque array of floating-point values on which GdkEventHistory operates.

"Absolute" and "Relative" interpolated properties

The event properties subject to interpolation usually carry information about the position of the input device. There are 2 kinds of these properties, "Absolute" and "Relative". "Absolute" ones hold values which are absolute in nature, for example the x, y position of a finger on a touchscreen or the scale of a touchpad pinch event. "Relative" ones hold a delta from the previous position. These include the delta_x, delta_y values of smooth scroll events, dx, dy of touchpad swipe events etc.

Each of the 2 kinds has its own accessors. This is because they are handled in a slightly different way. Absolute properties can be directly interpolated. Relative properties, on the other hand, have to be converted to absolute ones first by accumulating the deltas. These accumulated values are interpolated, then converted back to relative values.

Edited by Yariv

Merge request reports