The previous approach to pointer acceleration was to initialize the same
motion filter behavior but a different acceleration profile depending on the
hardware (the profile converts a speed to a multiplier for input deltas).

To be more flexible for hardware-specifics, change this into a set of specific
pointer acceleration init functions. This patch has no effective functional
changes, they're still all the same.

The acceleration functions are kept for direct access by the ptraccel-debug
tool.

Signed-off-by: Peter Hutterer <[email protected]>
---
 src/evdev-mt-touchpad.c | 10 ++++----
 src/evdev.c             | 18 +++++++-------
 src/evdev.h             |  2 +-
 src/filter.c            | 62 +++++++++++++++++++++++++++++++++++++++++++++----
 src/filter.h            | 14 +++++++++--
 tools/ptraccel-debug.c  |  3 +--
 6 files changed, 86 insertions(+), 23 deletions(-)

diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
index a683d9a..f48aa26 100644
--- a/src/evdev-mt-touchpad.c
+++ b/src/evdev-mt-touchpad.c
@@ -1510,7 +1510,7 @@ static int
 tp_init_accel(struct tp_dispatch *tp, double diagonal)
 {
        int res_x, res_y;
-       accel_profile_func_t profile;
+       struct motion_filter *filter;
 
        res_x = tp->device->abs.absinfo_x->resolution;
        res_y = tp->device->abs.absinfo_y->resolution;
@@ -1526,14 +1526,14 @@ tp_init_accel(struct tp_dispatch *tp, double diagonal)
        tp->accel.y_scale_coeff = (DEFAULT_MOUSE_DPI/25.4) / res_y;
 
        if (tp->device->model_flags & EVDEV_MODEL_LENOVO_X230)
-               profile = touchpad_lenovo_x230_accel_profile;
+               filter = 
create_pointer_accelerator_filter_lenovo_x230(tp->device->dpi);
        else
-               profile = touchpad_accel_profile_linear;
+               filter = 
create_pointer_accelerator_filter_touchpad(tp->device->dpi);
 
-       if (evdev_device_init_pointer_acceleration(tp->device, profile) == -1)
+       if (!filter)
                return -1;
 
-       return 0;
+       return evdev_device_init_pointer_acceleration(tp->device, filter);
 }
 
 static uint32_t
diff --git a/src/evdev.c b/src/evdev.c
index 17c2604..bb31724 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -1408,12 +1408,9 @@ evdev_accel_config_get_default_speed(struct 
libinput_device *device)
 
 int
 evdev_device_init_pointer_acceleration(struct evdev_device *device,
-                                      accel_profile_func_t profile)
+                                      struct motion_filter *filter)
 {
-       device->pointer.filter = create_pointer_accelerator_filter(profile,
-                                                                  device->dpi);
-       if (!device->pointer.filter)
-               return -1;
+       device->pointer.filter = filter;
 
        device->pointer.config.available = evdev_accel_config_available;
        device->pointer.config.set_speed = evdev_accel_config_set_speed;
@@ -1862,14 +1859,17 @@ evdev_configure_mt_device(struct evdev_device *device)
 static inline int
 evdev_init_accel(struct evdev_device *device)
 {
-       accel_profile_func_t profile;
+       struct motion_filter *filter;
 
        if (device->dpi < DEFAULT_MOUSE_DPI)
-               profile = pointer_accel_profile_linear_low_dpi;
+               filter = 
create_pointer_accelerator_filter_linear_low_dpi(device->dpi);
        else
-               profile = pointer_accel_profile_linear;
+               filter = create_pointer_accelerator_filter_linear(device->dpi);
 
-       return evdev_device_init_pointer_acceleration(device, profile);
+       if (!filter)
+               return -1;
+
+       return evdev_device_init_pointer_acceleration(device, filter);
 }
 
 static int
diff --git a/src/evdev.h b/src/evdev.h
index be5df0d..42404fc 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -280,7 +280,7 @@ evdev_device_create(struct libinput_seat *seat,
 
 int
 evdev_device_init_pointer_acceleration(struct evdev_device *device,
-                                      accel_profile_func_t profile);
+                                      struct motion_filter *filter);
 
 struct evdev_dispatch *
 evdev_touchpad_create(struct evdev_device *device);
diff --git a/src/filter.c b/src/filter.c
index bc73d50..828d6b6 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -549,9 +549,8 @@ struct motion_filter_interface accelerator_interface = {
        accelerator_set_speed,
 };
 
-struct motion_filter *
-create_pointer_accelerator_filter(accel_profile_func_t profile,
-                                 int dpi)
+static struct pointer_accelerator *
+create_default_filter(int dpi)
 {
        struct pointer_accelerator *filter;
 
@@ -561,7 +560,6 @@ create_pointer_accelerator_filter(accel_profile_func_t 
profile,
 
        filter->base.interface = &accelerator_interface;
 
-       filter->profile = profile;
        filter->last_velocity = 0.0;
 
        filter->trackers =
@@ -574,5 +572,61 @@ create_pointer_accelerator_filter(accel_profile_func_t 
profile,
 
        filter->dpi_factor = dpi/(double)DEFAULT_MOUSE_DPI;
 
+       return filter;
+}
+
+struct motion_filter *
+create_pointer_accelerator_filter_linear(int dpi)
+{
+       struct pointer_accelerator *filter;
+
+       filter = create_default_filter(dpi);
+       if (!filter)
+               return NULL;
+
+       filter->profile = pointer_accel_profile_linear;
+
+       return &filter->base;
+}
+
+struct motion_filter *
+create_pointer_accelerator_filter_linear_low_dpi(int dpi)
+{
+       struct pointer_accelerator *filter;
+
+       filter = create_default_filter(dpi);
+       if (!filter)
+               return NULL;
+
+       filter->profile = pointer_accel_profile_linear_low_dpi;
+
+       return &filter->base;
+}
+
+struct motion_filter *
+create_pointer_accelerator_filter_touchpad(int dpi)
+{
+       struct pointer_accelerator *filter;
+
+       filter = create_default_filter(dpi);
+       if (!filter)
+               return NULL;
+
+       filter->profile = touchpad_accel_profile_linear;
+
+       return &filter->base;
+}
+
+struct motion_filter *
+create_pointer_accelerator_filter_lenovo_x230(int dpi)
+{
+       struct pointer_accelerator *filter;
+
+       filter = create_default_filter(dpi);
+       if (!filter)
+               return NULL;
+
+       filter->profile = touchpad_lenovo_x230_accel_profile;
+
        return &filter->base;
 }
diff --git a/src/filter.h b/src/filter.h
index 617fab1..76fc147 100644
--- a/src/filter.h
+++ b/src/filter.h
@@ -57,9 +57,19 @@ typedef double (*accel_profile_func_t)(struct motion_filter 
*filter,
                                       double velocity,
                                       uint64_t time);
 
+/* Pointer acceleration types */
+
 struct motion_filter *
-create_pointer_accelerator_filter(accel_profile_func_t filter,
-                                 int dpi);
+create_pointer_accelerator_filter_linear(int dpi);
+
+struct motion_filter *
+create_pointer_accelerator_filter_linear_low_dpi(int dpi);
+
+struct motion_filter *
+create_pointer_accelerator_filter_touchpad(int dpi);
+
+struct motion_filter *
+create_pointer_accelerator_filter_lenovo_x230(int dpi);
 
 /*
  * Pointer acceleration profiles.
diff --git a/tools/ptraccel-debug.c b/tools/ptraccel-debug.c
index b0867db..077da59 100644
--- a/tools/ptraccel-debug.c
+++ b/tools/ptraccel-debug.c
@@ -272,8 +272,7 @@ main(int argc, char **argv)
                }
        }
 
-       filter = create_pointer_accelerator_filter(pointer_accel_profile_linear,
-                                                  dpi);
+       filter = create_pointer_accelerator_filter_linear(dpi);
        assert(filter != NULL);
        filter_set_speed(filter, speed);
 
-- 
2.4.3

_______________________________________________
wayland-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to