[PATCH libinput 5/6] filter: add a "filter_constant" hook to the filter interface

Peter Hutterer peter.hutterer at who-t.net
Mon Aug 17 16:20:33 PDT 2015


For when we need to apply some transformation to the data but it shouldn't be
acceleration. Example use are touchpad coordinates, even when not
accelerating, we still want to apply the magic slowdown.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
Not happy with this but the only other option here was to move the magic
slowdown into the touch code before the acceleration filters. That would
'break' the unaccelerated motion delta otherwise.

 src/filter-private.h |  4 ++++
 src/filter.c         | 20 ++++++++++++++++++++
 src/filter.h         | 22 ++++++++++++++++++++++
 3 files changed, 46 insertions(+)

diff --git a/src/filter-private.h b/src/filter-private.h
index f5e8b7f..eaf84ed 100644
--- a/src/filter-private.h
+++ b/src/filter-private.h
@@ -33,6 +33,10 @@ struct motion_filter_interface {
 			   struct motion_filter *filter,
 			   const struct normalized_coords *unaccelerated,
 			   void *data, uint64_t time);
+	struct normalized_coords (*filter_constant)(
+			   struct motion_filter *filter,
+			   const struct normalized_coords *unaccelerated,
+			   void *data, uint64_t time);
 	void (*restart)(struct motion_filter *filter,
 			void *data,
 			uint64_t time);
diff --git a/src/filter.c b/src/filter.c
index f92b9fd..674b439 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -64,6 +64,14 @@ filter_dispatch(struct motion_filter *filter,
 	return filter->interface->filter(filter, unaccelerated, data, time);
 }
 
+struct normalized_coords
+filter_dispatch_constant(struct motion_filter *filter,
+			 const struct normalized_coords *unaccelerated,
+			 void *data, uint64_t time)
+{
+	return filter->interface->filter_constant(filter, unaccelerated, data, time);
+}
+
 void
 filter_restart(struct motion_filter *filter,
 	       void *data, uint64_t time)
@@ -320,6 +328,14 @@ accelerator_filter(struct motion_filter *filter,
 }
 
 static struct normalized_coords
+accelerator_filter_noop(struct motion_filter *filter,
+			const struct normalized_coords *unaccelerated,
+			void *data, uint64_t time)
+{
+	return *unaccelerated;
+}
+
+static struct normalized_coords
 accelerator_filter_low_dpi(struct motion_filter *filter,
 			   const struct normalized_coords *unaccelerated,
 			   void *data, uint64_t time)
@@ -673,6 +689,7 @@ trackpoint_accel_profile(struct motion_filter *filter,
 
 struct motion_filter_interface accelerator_interface = {
 	.filter = accelerator_filter,
+	.filter_constant = accelerator_filter_noop,
 	.restart = accelerator_restart,
 	.destroy = accelerator_destroy,
 	.set_speed = accelerator_set_speed,
@@ -719,6 +736,7 @@ create_pointer_accelerator_filter_linear(int dpi)
 
 struct motion_filter_interface accelerator_interface_low_dpi = {
 	.filter = accelerator_filter_low_dpi,
+	.filter_constant = accelerator_filter_noop,
 	.restart = accelerator_restart,
 	.destroy = accelerator_destroy,
 	.set_speed = accelerator_set_speed,
@@ -756,6 +774,7 @@ create_pointer_accelerator_filter_touchpad(int dpi)
 
 struct motion_filter_interface accelerator_interface_x230 = {
 	.filter = accelerator_filter_x230,
+	.filter_constant = accelerator_filter_noop,
 	.restart = accelerator_restart,
 	.destroy = accelerator_destroy,
 	.set_speed = accelerator_set_speed,
@@ -793,6 +812,7 @@ create_pointer_accelerator_filter_lenovo_x230(int dpi)
 
 struct motion_filter_interface accelerator_interface_trackpoint = {
 	.filter = accelerator_filter_trackpoint,
+	.filter_constant = accelerator_filter_noop,
 	.restart = accelerator_restart,
 	.destroy = accelerator_destroy,
 	.set_speed = accelerator_set_speed,
diff --git a/src/filter.h b/src/filter.h
index fd36da4..c8ade07 100644
--- a/src/filter.h
+++ b/src/filter.h
@@ -34,11 +34,33 @@
 
 struct motion_filter;
 
+/**
+ * Accelerate the given coordinates.
+ * Takes a set of unaccelerated deltas and accelerates them based on the
+ * current and previous motion.
+ *
+ * This is a superset of filter_dispatch_constant()
+ *
+ * @see filter_dispatch_constant
+ */
 struct normalized_coords
 filter_dispatch(struct motion_filter *filter,
 		const struct normalized_coords *unaccelerated,
 		void *data, uint64_t time);
 
+/**
+ * Apply constant motion filters, but no acceleration.
+ *
+ * Takes a set of unaccelerated deltas and applies any constant filters to
+ * it but does not accelerate the delta in the conventional sense.
+ *
+ * @see filter_dispatch
+ */
+struct normalized_coords
+filter_dispatch_constant(struct motion_filter *filter,
+			 const struct normalized_coords *unaccelerated,
+			 void *data, uint64_t time);
+
 void
 filter_restart(struct motion_filter *filter,
 	       void *data, uint64_t time);
-- 
2.4.3



More information about the wayland-devel mailing list