[PATCH libinput 1/3] touchpad: convert two functions to use the device->phys helpers

Hans de Goede hdegoede at redhat.com
Wed Dec 14 08:46:11 UTC 2016


Hi,

On 14-12-16 08:36, Peter Hutterer wrote:
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

Series looks good to me:

Reviewed-by: Hans de Goede <hdegoede at redhat.com>

Regards,

Hans


> ---
>  src/evdev-mt-touchpad.c | 24 +++++++++++++-----------
>  src/evdev.h             | 27 +++++++++++++++++++++++++++
>  2 files changed, 40 insertions(+), 11 deletions(-)
>
> diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
> index 7bac8ec..26b65de 100644
> --- a/src/evdev-mt-touchpad.c
> +++ b/src/evdev-mt-touchpad.c
> @@ -478,18 +478,19 @@ tp_process_key(struct tp_dispatch *tp,
>  static void
>  tp_unpin_finger(const struct tp_dispatch *tp, struct tp_touch *t)
>  {
> -	double xdist, ydist;
> +	struct phys_coords mm;
> +	struct device_coords delta;
>
>  	if (!t->pinned.is_pinned)
>  		return;
>
> -	xdist = abs(t->point.x - t->pinned.center.x);
> -	xdist *= tp->buttons.motion_dist.x_scale_coeff;
> -	ydist = abs(t->point.y - t->pinned.center.y);
> -	ydist *= tp->buttons.motion_dist.y_scale_coeff;
> +	delta.x = abs(t->point.x - t->pinned.center.x);
> +	delta.y = abs(t->point.y - t->pinned.center.y);
> +
> +	mm = evdev_device_unit_delta_to_mm(tp->device, &delta);
>
>  	/* 1.5mm movement -> unpin */
> -	if (hypot(xdist, ydist) >= 1.5) {
> +	if (hypot(mm.x, mm.y) >= 1.5) {
>  		t->pinned.is_pinned = false;
>  		return;
>  	}
> @@ -962,8 +963,8 @@ tp_need_motion_history_reset(struct tp_dispatch *tp)
>  static bool
>  tp_detect_jumps(const struct tp_dispatch *tp, struct tp_touch *t)
>  {
> -	struct device_coords *last;
> -	double dx, dy;
> +	struct device_coords *last, delta;
> +	struct phys_coords mm;
>  	const int JUMP_THRESHOLD_MM = 20;
>
>  	/* We haven't seen pointer jumps on Wacom tablets yet, so exclude
> @@ -978,10 +979,11 @@ tp_detect_jumps(const struct tp_dispatch *tp, struct tp_touch *t)
>  	/* called before tp_motion_history_push, so offset 0 is the most
>  	 * recent coordinate */
>  	last = tp_motion_history_offset(t, 0);
> -	dx = 1.0 * abs(t->point.x - last->x) / tp->device->abs.absinfo_x->resolution;
> -	dy = 1.0 * abs(t->point.y - last->y) / tp->device->abs.absinfo_y->resolution;
> +	delta.x = abs(t->point.x - last->x);
> +	delta.y = abs(t->point.y - last->y);
> +	mm = evdev_device_unit_delta_to_mm(tp->device, &delta);
>
> -	return hypot(dx, dy) > JUMP_THRESHOLD_MM;
> +	return hypot(mm.x, mm.y) > JUMP_THRESHOLD_MM;
>  }
>
>  static void
> diff --git a/src/evdev.h b/src/evdev.h
> index 071b9ec..c07b09f 100644
> --- a/src/evdev.h
> +++ b/src/evdev.h
> @@ -596,6 +596,33 @@ evdev_libinput_context(const struct evdev_device *device)
>  }
>
>  /**
> + * Convert the pair of delta coordinates in device space to mm.
> + */
> +static inline struct phys_coords
> +evdev_device_unit_delta_to_mm(const struct evdev_device* device,
> +			      const struct device_coords *units)
> +{
> +	struct phys_coords mm = { 0,  0 };
> +	const struct input_absinfo *absx, *absy;
> +
> +	if (device->abs.absinfo_x == NULL ||
> +	    device->abs.absinfo_y == NULL) {
> +		log_bug_libinput(evdev_libinput_context(device),
> +				 "%s: is not an abs device\n",
> +				 device->devname);
> +		return mm;
> +	}
> +
> +	absx = device->abs.absinfo_x;
> +	absy = device->abs.absinfo_y;
> +
> +	mm.x = 1.0 * units->x/absx->resolution;
> +	mm.y = 1.0 * units->y/absy->resolution;
> +
> +	return mm;
> +}
> +
> +/**
>   * Convert the pair of coordinates in device space to mm. This takes the
>   * axis min into account, i.e. a unit of min is equivalent to 0 mm.
>   */
>


More information about the wayland-devel mailing list