mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-02-19 01:40:49 +01:00
Add a delta_coords type and use it were applicable
tp_normalize_coords is one of the last functions taking separate x, y values rather a coordinate pair, this commit cleans this up. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
61721e446a
commit
fe93145f86
5 changed files with 46 additions and 30 deletions
|
|
@ -313,7 +313,6 @@ tp_edge_scroll_post_events(struct tp_dispatch *tp, uint64_t time)
|
|||
struct tp_touch *t;
|
||||
enum libinput_pointer_axis axis;
|
||||
double *delta;
|
||||
double initial_dx, initial_dy;
|
||||
struct normalized_coords normalized;
|
||||
const struct normalized_coords zero = { 0.0, 0.0 };
|
||||
const struct discrete_coords zero_discrete = { 0.0, 0.0 };
|
||||
|
|
@ -361,12 +360,9 @@ tp_edge_scroll_post_events(struct tp_dispatch *tp, uint64_t time)
|
|||
t->scroll.edge_state);
|
||||
break;
|
||||
case EDGE_SCROLL_TOUCH_STATE_EDGE_NEW:
|
||||
initial_dx = t->point.x - t->scroll.initial.x;
|
||||
initial_dy = t->point.y - t->scroll.initial.y;
|
||||
tp_normalize_delta(tp,
|
||||
initial_dx,
|
||||
initial_dy,
|
||||
&normalized);
|
||||
normalized = tp_normalize_delta(tp,
|
||||
device_delta(t->point,
|
||||
t->scroll.initial));
|
||||
if (fabs(*delta) < DEFAULT_SCROLL_THRESHOLD)
|
||||
normalized = zero;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -531,12 +531,11 @@ tp_tap_exceeds_motion_threshold(struct tp_dispatch *tp,
|
|||
struct tp_touch *t)
|
||||
{
|
||||
int threshold = DEFAULT_TAP_MOVE_THRESHOLD;
|
||||
double dx, dy;
|
||||
struct normalized_coords normalized;
|
||||
|
||||
dx = abs(t->tap.initial.x - t->point.x);
|
||||
dy = abs(t->tap.initial.y - t->point.y);
|
||||
tp_normalize_delta(tp, dx, dy, &normalized);
|
||||
normalized = tp_normalize_delta(tp,
|
||||
device_delta(t->point,
|
||||
t->tap.initial));
|
||||
|
||||
return normalized.x * normalized.x + normalized.y * normalized.y
|
||||
> threshold * threshold;
|
||||
|
|
|
|||
|
|
@ -261,23 +261,22 @@ tp_estimate_delta(int x0, int x1, int x2, int x3)
|
|||
struct normalized_coords
|
||||
tp_get_delta(struct tp_touch *t)
|
||||
{
|
||||
double dx, dy; /* in device coords */
|
||||
struct normalized_coords normalized = { 0.0, 0.0 };
|
||||
struct delta_coords delta;
|
||||
const struct normalized_coords zero = { 0.0, 0.0 };
|
||||
|
||||
if (t->history.count < TOUCHPAD_MIN_SAMPLES)
|
||||
return normalized;
|
||||
return zero;
|
||||
|
||||
dx = tp_estimate_delta(tp_motion_history_offset(t, 0)->x,
|
||||
tp_motion_history_offset(t, 1)->x,
|
||||
tp_motion_history_offset(t, 2)->x,
|
||||
tp_motion_history_offset(t, 3)->x);
|
||||
dy = tp_estimate_delta(tp_motion_history_offset(t, 0)->y,
|
||||
tp_motion_history_offset(t, 1)->y,
|
||||
tp_motion_history_offset(t, 2)->y,
|
||||
tp_motion_history_offset(t, 3)->y);
|
||||
tp_normalize_delta(t->tp, dx, dy, &normalized);
|
||||
delta.dx = tp_estimate_delta(tp_motion_history_offset(t, 0)->x,
|
||||
tp_motion_history_offset(t, 1)->x,
|
||||
tp_motion_history_offset(t, 2)->x,
|
||||
tp_motion_history_offset(t, 3)->x);
|
||||
delta.dy = tp_estimate_delta(tp_motion_history_offset(t, 0)->y,
|
||||
tp_motion_history_offset(t, 1)->y,
|
||||
tp_motion_history_offset(t, 2)->y,
|
||||
tp_motion_history_offset(t, 3)->y);
|
||||
|
||||
return normalized;
|
||||
return tp_normalize_delta(t->tp, delta);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -274,13 +274,15 @@ struct tp_dispatch {
|
|||
#define tp_for_each_touch(_tp, _t) \
|
||||
for (unsigned int _i = 0; _i < (_tp)->ntouches && (_t = &(_tp)->touches[_i]); _i++)
|
||||
|
||||
static inline void
|
||||
tp_normalize_delta(struct tp_dispatch *tp,
|
||||
double dx, double dy,
|
||||
struct normalized_coords *normalized)
|
||||
static inline struct normalized_coords
|
||||
tp_normalize_delta(struct tp_dispatch *tp, struct delta_coords delta)
|
||||
{
|
||||
normalized->x = dx * tp->accel.x_scale_coeff;
|
||||
normalized->y = dy * tp->accel.y_scale_coeff;
|
||||
struct normalized_coords normalized;
|
||||
|
||||
normalized.x = delta.dx * tp->accel.x_scale_coeff;
|
||||
normalized.y = delta.dy * tp->accel.y_scale_coeff;
|
||||
|
||||
return normalized;
|
||||
}
|
||||
|
||||
struct normalized_coords
|
||||
|
|
|
|||
|
|
@ -37,6 +37,14 @@ struct device_coords {
|
|||
int x, y;
|
||||
};
|
||||
|
||||
/*
|
||||
* A delta between 2 device coordinates,
|
||||
* may be non-discrete because of averaging.
|
||||
*/
|
||||
struct delta_coords {
|
||||
double dx, dy;
|
||||
};
|
||||
|
||||
/* A dpi-normalized coordinate pair */
|
||||
struct normalized_coords {
|
||||
double x, y;
|
||||
|
|
@ -353,4 +361,16 @@ libinput_now(struct libinput *libinput)
|
|||
|
||||
return ts.tv_sec * 1000ULL + ts.tv_nsec / 1000000;
|
||||
}
|
||||
|
||||
static inline struct delta_coords
|
||||
device_delta(struct device_coords a, struct device_coords b)
|
||||
{
|
||||
struct delta_coords delta;
|
||||
|
||||
delta.dx = a.x - b.x;
|
||||
delta.dy = a.y - b.y;
|
||||
|
||||
return delta;
|
||||
}
|
||||
|
||||
#endif /* LIBINPUT_PRIVATE_H */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue