filter: add helper functions to create/destroy a delta smoothener
authorPeter Hutterer <peter.hutterer@who-t.net>
Tue, 22 Nov 2022 01:34:06 +0000 (11:34 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Tue, 17 Jan 2023 00:51:33 +0000 (10:51 +1000)
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
src/filter-private.h
src/filter-touchpad.c
src/filter-trackpoint.c
src/filter.c

index 470d103786dcb0bb060ee18894e886d799b62941..cee65e0b473291d89a8f3f9eb5f8f9fa48b400d7 100644 (file)
@@ -63,6 +63,22 @@ struct pointer_delta_smoothener {
        uint64_t value;
 };
 
+static inline struct pointer_delta_smoothener *
+pointer_delta_smoothener_create(uint64_t event_delta_smooth_threshold,
+                               uint64_t event_delta_smooth_value)
+{
+       struct pointer_delta_smoothener *s = zalloc(sizeof(*s));
+       s->threshold = event_delta_smooth_threshold;
+       s->value = event_delta_smooth_value;
+       return s;
+}
+
+static inline void
+pointer_delta_smoothener_destroy(struct pointer_delta_smoothener *smoothener)
+{
+       free(smoothener);
+}
+
 struct pointer_trackers {
        struct pointer_tracker *trackers;
        size_t ntrackers;
index cd51a7ea63217b3dd2466e1c557c014f71b0294b..c7e7ae9c14a027c1681ffa697a0cd28577efe154 100644 (file)
@@ -300,7 +300,6 @@ create_pointer_accelerator_filter_touchpad(int dpi,
        bool use_velocity_averaging)
 {
        struct touchpad_accelerator *filter;
-       struct pointer_delta_smoothener *smoothener;
 
        filter = zalloc(sizeof *filter);
        filter->last_velocity = 0.0;
@@ -312,11 +311,7 @@ create_pointer_accelerator_filter_touchpad(int dpi,
 
        filter->base.interface = &accelerator_interface_touchpad;
        filter->profile = touchpad_accel_profile_linear;
-
-       smoothener = zalloc(sizeof(*smoothener));
-       smoothener->threshold = event_delta_smooth_threshold,
-       smoothener->value = event_delta_smooth_value,
-       filter->trackers.smoothener = smoothener;
+       filter->trackers.smoothener = pointer_delta_smoothener_create(event_delta_smooth_threshold, event_delta_smooth_value);
 
        return &filter->base;
 }
index a46729b78a4b9770e33856a474bbaa8c7d056beb..742674639895ea3c2229f45ad79f2298d07d2318 100644 (file)
@@ -183,7 +183,6 @@ struct motion_filter *
 create_pointer_accelerator_filter_trackpoint(double multiplier, bool use_velocity_averaging)
 {
        struct trackpoint_accelerator *filter;
-       struct pointer_delta_smoothener *smoothener;
 
        assert(multiplier > 0.0);
 
@@ -208,11 +207,7 @@ create_pointer_accelerator_filter_trackpoint(double multiplier, bool use_velocit
        trackers_init(&filter->trackers, use_velocity_averaging ? 16 : 2);
 
        filter->base.interface = &accelerator_interface_trackpoint;
-
-       smoothener = zalloc(sizeof(*smoothener));
-       smoothener->threshold = ms2us(10);
-       smoothener->value = ms2us(10);
-       filter->trackers.smoothener = smoothener;
+       filter->trackers.smoothener = pointer_delta_smoothener_create(ms2us(10), ms2us(10));
 
        return &filter->base;
 }
index 7abd6653ee72d3ea5d5d204e314e1035bbfcb456..e39839a259e7466b1abe77fd2befd26b0343a7d0 100644 (file)
@@ -103,7 +103,7 @@ void
 trackers_free(struct pointer_trackers *trackers)
 {
        free(trackers->trackers);
-       free(trackers->smoothener);
+       pointer_delta_smoothener_destroy(trackers->smoothener);
 }
 
 void