[PATCH libinput 06/23] filter: add helper function to reset and free trackers

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


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/filter-private.h |  5 +++++
 src/filter.c         | 43 +++++++++++++++++++++++++++++--------------
 2 files changed, 34 insertions(+), 14 deletions(-)

diff --git a/src/filter-private.h b/src/filter-private.h
index ec87a849..10be823b 100644
--- a/src/filter-private.h
+++ b/src/filter-private.h
@@ -73,6 +73,11 @@ struct pointer_trackers {
 
 void init_trackers(struct pointer_trackers *trackers,
 		   size_t ntrackers);
+void free_trackers(struct pointer_trackers *trackers);
+
+void
+reset_trackers(struct pointer_trackers *trackers,
+	       uint64_t time);
 void
 feed_trackers(struct pointer_trackers *trackers,
 	      const struct device_float_coords *delta,
diff --git a/src/filter.c b/src/filter.c
index 3670c38f..d2106868 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -188,6 +188,33 @@ init_trackers(struct pointer_trackers *trackers,
 	trackers->smoothener = NULL;
 }
 
+void
+free_trackers(struct pointer_trackers *trackers)
+{
+	free(trackers->trackers);
+	free(trackers->smoothener);
+}
+
+void
+reset_trackers(struct pointer_trackers *trackers,
+	       uint64_t time)
+{
+	unsigned int offset;
+	struct pointer_tracker *tracker;
+
+	for (offset = 1; offset < trackers->ntrackers; offset++) {
+		tracker = tracker_by_offset(trackers, offset);
+		tracker->time = 0;
+		tracker->dir = 0;
+		tracker->delta.x = 0;
+		tracker->delta.y = 0;
+	}
+
+	tracker = tracker_by_offset(trackers, 0);
+	tracker->time = time;
+	tracker->dir = UNDEFINED_DIRECTION;
+}
+
 void
 feed_trackers(struct pointer_trackers *trackers,
 	      const struct device_float_coords *delta,
@@ -622,20 +649,8 @@ accelerator_restart(struct motion_filter *filter,
 {
 	struct pointer_accelerator *accel =
 		(struct pointer_accelerator *) filter;
-	unsigned int offset;
-	struct pointer_tracker *tracker;
 
-	for (offset = 1; offset < accel->trackers.ntrackers; offset++) {
-		tracker = tracker_by_offset(&accel->trackers, offset);
-		tracker->time = 0;
-		tracker->dir = 0;
-		tracker->delta.x = 0;
-		tracker->delta.y = 0;
-	}
-
-	tracker = tracker_by_offset(&accel->trackers, 0);
-	tracker->time = time;
-	tracker->dir = UNDEFINED_DIRECTION;
+	reset_trackers(&accel->trackers, time);
 }
 
 static void
@@ -644,7 +659,7 @@ accelerator_destroy(struct motion_filter *filter)
 	struct pointer_accelerator *accel =
 		(struct pointer_accelerator *) filter;
 
-	free(accel->trackers.trackers);
+	free_trackers(&accel->trackers);
 	free(accel);
 }
 
-- 
2.14.3



More information about the wayland-devel mailing list