[PATCH libinput 04/10] filter: add a configurable speed interface

Peter Hutterer peter.hutterer at who-t.net
Thu Sep 18 22:44:29 PDT 2014


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/filter-private.h |  3 +++
 src/filter.c         | 28 +++++++++++++++++++++++++++-
 src/filter.h         |  7 +++++++
 3 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/src/filter-private.h b/src/filter-private.h
index 283a747..dcce125 100644
--- a/src/filter-private.h
+++ b/src/filter-private.h
@@ -32,9 +32,12 @@ struct motion_filter_interface {
 		       struct motion_params *motion,
 		       void *data, uint64_t time);
 	void (*destroy)(struct motion_filter *filter);
+	bool (*set_speed)(struct motion_filter *filter,
+			  double speed);
 };
 
 struct motion_filter {
+	double speed; /* normalized [-1, 1] */
 	struct motion_filter_interface *interface;
 };
 
diff --git a/src/filter.c b/src/filter.c
index 5e627e1..327dbce 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -22,6 +22,7 @@
 
 #include "config.h"
 
+#include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
@@ -49,6 +50,19 @@ filter_destroy(struct motion_filter *filter)
 	filter->interface->destroy(filter);
 }
 
+bool
+filter_set_speed(struct motion_filter *filter,
+		 double speed)
+{
+	return filter->interface->set_speed(filter, speed);
+}
+
+double
+filter_get_speed(struct motion_filter *filter)
+{
+	return filter->speed;
+}
+
 /*
  * Default parameters for pointer acceleration profiles.
  */
@@ -237,9 +251,21 @@ accelerator_destroy(struct motion_filter *filter)
 	free(accel);
 }
 
+static bool
+accelerator_set_speed(struct motion_filter *filter,
+		      double speed)
+{
+	assert(speed >= -1.0 && speed <= 1.0);
+
+	filter->speed = speed;
+
+	return true;
+}
+
 struct motion_filter_interface accelerator_interface = {
 	accelerator_filter,
-	accelerator_destroy
+	accelerator_destroy,
+	accelerator_set_speed,
 };
 
 struct motion_filter *
diff --git a/src/filter.h b/src/filter.h
index b79f0e3..1f53e81 100644
--- a/src/filter.h
+++ b/src/filter.h
@@ -25,6 +25,7 @@
 
 #include "config.h"
 
+#include <stdbool.h>
 #include <stdint.h>
 
 struct motion_params {
@@ -40,6 +41,12 @@ filter_dispatch(struct motion_filter *filter,
 void
 filter_destroy(struct motion_filter *filter);
 
+bool
+filter_set_speed(struct motion_filter *filter,
+		 double speed);
+double
+filter_get_speed(struct motion_filter *filter);
+
 typedef double (*accel_profile_func_t)(struct motion_filter *filter,
 				       void *data,
 				       double velocity,
-- 
1.9.3



More information about the wayland-devel mailing list