filter: add helper functions to create/destroy a delta smoothener

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2022-11-22 11:34:06 +10:00
parent 1d7172488d
commit d199c6d8c1
4 changed files with 19 additions and 13 deletions

View 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;

View 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;
}

View 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;
}

View 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