[PATCH libinput 10/11] touchpad: Refactor tp_get_*_touches_delta

Peter Hutterer peter.hutterer at who-t.net
Sun Feb 22 19:02:18 PST 2015


On Wed, Feb 18, 2015 at 01:26:53PM +0100, Hans de Goede wrote:
> The two tp_get_*_touches_delta functions are almost identical, refactor
> them into one function.
> 
> Signed-off-by: Hans de Goede <hdegoede at redhat.com>
> ---

ACK to the basics, but I'd like to leave the two calls in place and make
them call into a static inline with the boolean argument.

i.d.
static inline
tp_get_touches_delta(...) {
..
}

void	
tp_get_average_touches_delta(..) {
    tp_get_touches_delta(..., true);
}

In the actual touchpad code, a call like
		tp_get_average_touches_delta(tp, &dx, &dy);
is a lot more expressive than a "true" or "false". Alternatively, pass an
enum in so it reads
		tp_get_touches_delta(tp, &dx, &dy, DELTA_AVERAGE);
		tp_get_touches_delta(tp, &dx, &dy, DELTA_COMBINE);

Cheers,
   Peter

>  src/evdev-mt-touchpad-gestures.c | 29 +++++------------------------
>  1 file changed, 5 insertions(+), 24 deletions(-)
> 
> diff --git a/src/evdev-mt-touchpad-gestures.c b/src/evdev-mt-touchpad-gestures.c
> index 8ebdf33..e429efe 100644
> --- a/src/evdev-mt-touchpad-gestures.c
> +++ b/src/evdev-mt-touchpad-gestures.c
> @@ -32,7 +32,7 @@
>  #define DEFAULT_GESTURE_SWITCH_TIMEOUT 100 /* ms */
>  
>  static void
> -tp_get_average_touches_delta(struct tp_dispatch *tp, double *dx, double *dy)
> +tp_get_touches_delta(struct tp_dispatch *tp, double *dx, double *dy, bool average)
>  {
>  	struct tp_touch *t;
>  	unsigned int i, nchanged = 0;
> @@ -53,7 +53,7 @@ tp_get_average_touches_delta(struct tp_dispatch *tp, double *dx, double *dy)
>  		}
>  	}
>  
> -	if (nchanged == 0)
> +	if (!average || nchanged == 0)
>  		return;
>  
>  	*dx /= nchanged;
> @@ -61,25 +61,6 @@ tp_get_average_touches_delta(struct tp_dispatch *tp, double *dx, double *dy)
>  }
>  
>  static void
> -tp_get_combined_touches_delta(struct tp_dispatch *tp, double *dx, double *dy)
> -{
> -	struct tp_touch *t;
> -	double tdx, tdy;
> -	unsigned int i;
> -
> -	for (i = 0; i < tp->real_touches; i++) {
> -		t = &tp->touches[i];
> -
> -		if (!tp_touch_active(tp, t) || !t->dirty)
> -			continue;
> -
> -		tp_get_delta(t, &tdx, &tdy);
> -		*dx += tdx;
> -		*dy += tdy;
> -	}
> -}
> -
> -static void
>  tp_gesture_start(struct tp_dispatch *tp, uint64_t time)
>  {
>  	if (tp->gesture.started)
> @@ -101,9 +82,9 @@ tp_gesture_post_pointer_motion(struct tp_dispatch *tp, uint64_t time)
>  
>  	/* When a clickpad is clicked, combine motion of all active touches */
>  	if (tp->buttons.is_clickpad && tp->buttons.state)
> -		tp_get_combined_touches_delta(tp, &dx, &dy);
> +		tp_get_touches_delta(tp, &dx, &dy, false);
>  	else
> -		tp_get_average_touches_delta(tp, &dx, &dy);
> +		tp_get_touches_delta(tp, &dx, &dy, true);
>  
>  	tp_filter_motion(tp, &dx, &dy, &dx_unaccel, &dy_unaccel, time);
>  
> @@ -118,7 +99,7 @@ tp_gesture_post_twofinger_scroll(struct tp_dispatch *tp, uint64_t time)
>  {
>  	double dx = 0, dy =0;
>  
> -	tp_get_average_touches_delta(tp, &dx, &dy);
> +	tp_get_touches_delta(tp, &dx, &dy, true);
>  	tp_filter_motion(tp, &dx, &dy, NULL, NULL, time);
>  
>  	if (dx == 0.0 && dy == 0.0)
> -- 
> 2.1.0
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
> 


More information about the wayland-devel mailing list