[PATCH libinput 20/23] filter: duplicate the pointer_accelerator struct into the bits that use it

Peter Hutterer peter.hutterer at who-t.net
Thu Apr 12 06:34:46 UTC 2018


Yeah, it's duplication. But this way it's also separation and we can't
accidentally use the wrong struct.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/filter-low-dpi.c  | 49 +++++++++++++++++++++++++++++++++----------------
 src/filter-mouse.c    | 17 +++++++++++++++++
 src/filter-private.h  | 17 -----------------
 src/filter-touchpad.c | 49 +++++++++++++++++++++++++++++++++----------------
 4 files changed, 83 insertions(+), 49 deletions(-)

diff --git a/src/filter-low-dpi.c b/src/filter-low-dpi.c
index e239b81a..6b017afb 100644
--- a/src/filter-low-dpi.c
+++ b/src/filter-low-dpi.c
@@ -45,6 +45,23 @@
 #define DEFAULT_ACCELERATION 2.0		/* unitless factor */
 #define DEFAULT_INCLINE 1.1			/* unitless factor */
 
+struct pointer_accelerator_low_dpi {
+	struct motion_filter base;
+
+	accel_profile_func_t profile;
+
+	double velocity;	/* units/us */
+	double last_velocity;	/* units/us */
+
+	struct pointer_trackers trackers;
+
+	double threshold;	/* units/us */
+	double accel;		/* unitless factor */
+	double incline;		/* incline of the function */
+
+	int dpi;
+};
+
 /**
  * Custom acceleration function for mice < 1000dpi.
  * At slow motion, a single device unit causes a one-pixel movement.
@@ -61,8 +78,8 @@ pointer_accel_profile_linear_low_dpi(struct motion_filter *filter,
 				     double speed_in, /* in device units (units/us) */
 				     uint64_t time)
 {
-	struct pointer_accelerator *accel_filter =
-		(struct pointer_accelerator *)filter;
+	struct pointer_accelerator_low_dpi *accel_filter =
+		(struct pointer_accelerator_low_dpi *)filter;
 
 	double max_accel = accel_filter->accel; /* unitless factor */
 	double threshold = accel_filter->threshold; /* units/us */
@@ -89,7 +106,7 @@ pointer_accel_profile_linear_low_dpi(struct motion_filter *filter,
 }
 
 static inline double
-calculate_acceleration_factor(struct pointer_accelerator *accel,
+calculate_acceleration_factor(struct pointer_accelerator_low_dpi *accel,
 			      const struct device_float_coords *unaccelerated,
 			      void *data,
 			      uint64_t time)
@@ -115,8 +132,8 @@ accelerator_filter_generic(struct motion_filter *filter,
 			   const struct device_float_coords *unaccelerated,
 			   void *data, uint64_t time)
 {
-	struct pointer_accelerator *accel =
-		(struct pointer_accelerator *) filter;
+	struct pointer_accelerator_low_dpi *accel =
+		(struct pointer_accelerator_low_dpi *) filter;
 	double accel_value; /* unitless factor */
 	struct device_float_coords accelerated;
 
@@ -154,8 +171,8 @@ accelerator_filter_noop(struct motion_filter *filter,
 			const struct device_float_coords *unaccelerated,
 			void *data, uint64_t time)
 {
-	struct pointer_accelerator *accel =
-		(struct pointer_accelerator *) filter;
+	struct pointer_accelerator_low_dpi *accel =
+		(struct pointer_accelerator_low_dpi *) filter;
 
 	return normalize_for_dpi(unaccelerated, accel->dpi);
 }
@@ -165,8 +182,8 @@ accelerator_restart(struct motion_filter *filter,
 		    void *data,
 		    uint64_t time)
 {
-	struct pointer_accelerator *accel =
-		(struct pointer_accelerator *) filter;
+	struct pointer_accelerator_low_dpi *accel =
+		(struct pointer_accelerator_low_dpi *) filter;
 
 	trackers_reset(&accel->trackers, time);
 }
@@ -174,8 +191,8 @@ accelerator_restart(struct motion_filter *filter,
 static void
 accelerator_destroy(struct motion_filter *filter)
 {
-	struct pointer_accelerator *accel =
-		(struct pointer_accelerator *) filter;
+	struct pointer_accelerator_low_dpi *accel =
+		(struct pointer_accelerator_low_dpi *) filter;
 
 	trackers_free(&accel->trackers);
 	free(accel);
@@ -185,8 +202,8 @@ static bool
 accelerator_set_speed(struct motion_filter *filter,
 		      double speed_adjustment)
 {
-	struct pointer_accelerator *accel_filter =
-		(struct pointer_accelerator *)filter;
+	struct pointer_accelerator_low_dpi *accel_filter =
+		(struct pointer_accelerator_low_dpi *)filter;
 
 	assert(speed_adjustment >= -1.0 && speed_adjustment <= 1.0);
 
@@ -218,10 +235,10 @@ struct motion_filter_interface accelerator_interface_low_dpi = {
 	.set_speed = accelerator_set_speed,
 };
 
-static struct pointer_accelerator *
+static struct pointer_accelerator_low_dpi *
 create_default_filter(int dpi)
 {
-	struct pointer_accelerator *filter;
+	struct pointer_accelerator_low_dpi *filter;
 
 	filter = zalloc(sizeof *filter);
 	filter->last_velocity = 0.0;
@@ -239,7 +256,7 @@ create_default_filter(int dpi)
 struct motion_filter *
 create_pointer_accelerator_filter_linear_low_dpi(int dpi)
 {
-	struct pointer_accelerator *filter;
+	struct pointer_accelerator_low_dpi *filter;
 
 	filter = create_default_filter(dpi);
 	if (!filter)
diff --git a/src/filter-mouse.c b/src/filter-mouse.c
index 1a050368..37444869 100644
--- a/src/filter-mouse.c
+++ b/src/filter-mouse.c
@@ -45,6 +45,23 @@
 #define DEFAULT_ACCELERATION 2.0		/* unitless factor */
 #define DEFAULT_INCLINE 1.1			/* unitless factor */
 
+struct pointer_accelerator {
+	struct motion_filter base;
+
+	accel_profile_func_t profile;
+
+	double velocity;	/* units/us */
+	double last_velocity;	/* units/us */
+
+	struct pointer_trackers trackers;
+
+	double threshold;	/* units/us */
+	double accel;		/* unitless factor */
+	double incline;		/* incline of the function */
+
+	int dpi;
+};
+
 /**
  * Calculate the acceleration factor for the given delta with the timestamp.
  *
diff --git a/src/filter-private.h b/src/filter-private.h
index 7fa1378c..fa2fea40 100644
--- a/src/filter-private.h
+++ b/src/filter-private.h
@@ -71,23 +71,6 @@ struct pointer_trackers {
 	struct pointer_delta_smoothener *smoothener;
 };
 
-struct pointer_accelerator {
-	struct motion_filter base;
-
-	accel_profile_func_t profile;
-
-	double velocity;	/* units/us */
-	double last_velocity;	/* units/us */
-
-	struct pointer_trackers trackers;
-
-	double threshold;	/* units/us */
-	double accel;		/* unitless factor */
-	double incline;		/* incline of the function */
-
-	int dpi;
-};
-
 void trackers_init(struct pointer_trackers *trackers);
 void trackers_free(struct pointer_trackers *trackers);
 
diff --git a/src/filter-touchpad.c b/src/filter-touchpad.c
index 146bac86..8b40b6e7 100644
--- a/src/filter-touchpad.c
+++ b/src/filter-touchpad.c
@@ -48,6 +48,23 @@
 #define TOUCHPAD_ACCELERATION 9.0		/* unitless factor */
 #define TOUCHPAD_INCLINE 0.011			/* unitless factor */
 
+struct touchpad_accelerator {
+	struct motion_filter base;
+
+	accel_profile_func_t profile;
+
+	double velocity;	/* units/us */
+	double last_velocity;	/* units/us */
+
+	struct pointer_trackers trackers;
+
+	double threshold;	/* units/us */
+	double accel;		/* unitless factor */
+	double incline;		/* incline of the function */
+
+	int dpi;
+};
+
 /**
  * Calculate the acceleration factor for the given delta with the timestamp.
  *
@@ -59,7 +76,7 @@
  * @return A unitless acceleration factor, to be applied to the delta
  */
 static inline double
-calculate_acceleration_factor(struct pointer_accelerator *accel,
+calculate_acceleration_factor(struct touchpad_accelerator *accel,
 			      const struct device_float_coords *unaccelerated,
 			      void *data,
 			      uint64_t time)
@@ -97,8 +114,8 @@ accelerator_filter_generic(struct motion_filter *filter,
 			   const struct device_float_coords *unaccelerated,
 			   void *data, uint64_t time)
 {
-	struct pointer_accelerator *accel =
-		(struct pointer_accelerator *) filter;
+	struct touchpad_accelerator *accel =
+		(struct touchpad_accelerator *) filter;
 	double accel_value; /* unitless factor */
 	struct device_float_coords accelerated;
 
@@ -118,8 +135,8 @@ accelerator_filter_post_normalized(struct motion_filter *filter,
 				   const struct device_float_coords *unaccelerated,
 				   void *data, uint64_t time)
 {
-	struct pointer_accelerator *accel =
-		(struct pointer_accelerator *) filter;
+	struct touchpad_accelerator *accel =
+		(struct touchpad_accelerator *) filter;
 	struct device_float_coords accelerated;
 
 	/* Accelerate for device units, normalize afterwards */
@@ -134,8 +151,8 @@ static bool
 touchpad_accelerator_set_speed(struct motion_filter *filter,
 		      double speed_adjustment)
 {
-	struct pointer_accelerator *accel_filter =
-		(struct pointer_accelerator *)filter;
+	struct touchpad_accelerator *accel_filter =
+		(struct touchpad_accelerator *)filter;
 
 	assert(speed_adjustment >= -1.0 && speed_adjustment <= 1.0);
 
@@ -157,8 +174,8 @@ touchpad_constant_filter(struct motion_filter *filter,
 			 const struct device_float_coords *unaccelerated,
 			 void *data, uint64_t time)
 {
-	struct pointer_accelerator *accel =
-		(struct pointer_accelerator *)filter;
+	struct touchpad_accelerator *accel =
+		(struct touchpad_accelerator *)filter;
 	struct normalized_coords normalized;
 
 	normalized = normalize_for_dpi(unaccelerated, accel->dpi);
@@ -173,8 +190,8 @@ touchpad_accelerator_restart(struct motion_filter *filter,
 			     void *data,
 			     uint64_t time)
 {
-	struct pointer_accelerator *accel =
-		(struct pointer_accelerator *) filter;
+	struct touchpad_accelerator *accel =
+		(struct touchpad_accelerator *) filter;
 
 	trackers_reset(&accel->trackers, time);
 }
@@ -182,8 +199,8 @@ touchpad_accelerator_restart(struct motion_filter *filter,
 static void
 touchpad_accelerator_destroy(struct motion_filter *filter)
 {
-	struct pointer_accelerator *accel =
-		(struct pointer_accelerator *) filter;
+	struct touchpad_accelerator *accel =
+		(struct touchpad_accelerator *) filter;
 
 	trackers_free(&accel->trackers);
 	free(accel);
@@ -195,8 +212,8 @@ touchpad_accel_profile_linear(struct motion_filter *filter,
 			      double speed_in, /* in device units/µs */
 			      uint64_t time)
 {
-	struct pointer_accelerator *accel_filter =
-		(struct pointer_accelerator *)filter;
+	struct touchpad_accelerator *accel_filter =
+		(struct touchpad_accelerator *)filter;
 	const double max_accel = accel_filter->accel; /* unitless factor */
 	const double threshold = accel_filter->threshold; /* units/us */
 	const double incline = accel_filter->incline;
@@ -281,7 +298,7 @@ create_pointer_accelerator_filter_touchpad(int dpi,
 	uint64_t event_delta_smooth_threshold,
 	uint64_t event_delta_smooth_value)
 {
-	struct pointer_accelerator *filter;
+	struct touchpad_accelerator *filter;
 	struct pointer_delta_smoothener *smoothener;
 
 	filter = zalloc(sizeof *filter);
-- 
2.14.3



More information about the wayland-devel mailing list