[PATCH libinput] tablet: fix distance normalization range after 25a9f39

Jason Gerecke killertofu at gmail.com
Wed Apr 27 16:31:50 UTC 2016


On Mon, Apr 25, 2016 at 7:22 PM, Peter Hutterer
<peter.hutterer at who-t.net> wrote:
> 25a9f39 changed the range to [-1, 1] but that's incorrect for the distance
> values. Split the normalization up into two functions and make sure our
> distance range is correct.
>
> https://bugs.freedesktop.org/show_bug.cgi?id=95074
>
> And while we're at it, sneak in a test for pressure ranges too.
>
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

Looks good to me --
Reviewed-by: Jason Gerecke <jason.gerecke at wacom.com>

Jason
---
Now instead of four in the eights place /
you’ve got three, ‘Cause you added one  /
(That is to say, eight) to the two,     /
But you can’t take seven from three,    /
So you look at the sixty-fours....

> ---
>  src/evdev-tablet.c | 15 +++++++++---
>  test/tablet.c      | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 80 insertions(+), 3 deletions(-)
>
> diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c
> index 5262230..4e8b920 100644
> --- a/src/evdev-tablet.c
> +++ b/src/evdev-tablet.c
> @@ -231,7 +231,7 @@ tablet_update_tool(struct tablet_dispatch *tablet,
>  }
>
>  static inline double
> -normalize_dist_slider(const struct input_absinfo *absinfo)
> +normalize_slider(const struct input_absinfo *absinfo)
>  {
>         double range = absinfo->maximum - absinfo->minimum;
>         double value = (absinfo->value - absinfo->minimum) / range;
> @@ -240,6 +240,15 @@ normalize_dist_slider(const struct input_absinfo *absinfo)
>  }
>
>  static inline double
> +normalize_distance(const struct input_absinfo *absinfo)
> +{
> +       double range = absinfo->maximum - absinfo->minimum;
> +       double value = (absinfo->value - absinfo->minimum) / range;
> +
> +       return value;
> +}
> +
> +static inline double
>  normalize_pressure(const struct input_absinfo *absinfo,
>                    struct libinput_tablet_tool *tool)
>  {
> @@ -420,7 +429,7 @@ tablet_handle_distance(struct tablet_dispatch *tablet,
>         if (bit_is_set(tablet->changed_axes,
>                        LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) {
>                 absinfo = libevdev_get_abs_info(device->evdev, ABS_DISTANCE);
> -               tablet->axes.distance = normalize_dist_slider(absinfo);
> +               tablet->axes.distance = normalize_distance(absinfo);
>         }
>
>         return tablet->axes.distance;
> @@ -435,7 +444,7 @@ tablet_handle_slider(struct tablet_dispatch *tablet,
>         if (bit_is_set(tablet->changed_axes,
>                        LIBINPUT_TABLET_TOOL_AXIS_SLIDER)) {
>                 absinfo = libevdev_get_abs_info(device->evdev, ABS_WHEEL);
> -               tablet->axes.slider = normalize_dist_slider(absinfo);
> +               tablet->axes.slider = normalize_slider(absinfo);
>         }
>
>         return tablet->axes.slider;
> diff --git a/test/tablet.c b/test/tablet.c
> index a44f63b..e30705b 100644
> --- a/test/tablet.c
> +++ b/test/tablet.c
> @@ -3106,6 +3106,39 @@ static void pressure_threshold_warning(struct libinput *libinput,
>                 (*warning_triggered)++;
>  }
>
> +START_TEST(tablet_pressure_range)
> +{
> +       struct litest_device *dev = litest_current_device();
> +       struct libinput *li = dev->libinput;
> +       struct libinput_event *event;
> +       struct libinput_event_tablet_tool *tev;
> +       struct axis_replacement axes[] = {
> +               { ABS_DISTANCE, 0 },
> +               { ABS_PRESSURE, 10 },
> +               { -1, -1 },
> +       };
> +       int pressure;
> +       double p;
> +
> +       litest_tablet_proximity_in(dev, 5, 100, axes);
> +       litest_drain_events(li);
> +       libinput_dispatch(li);
> +
> +       for (pressure = 1; pressure <= 100; pressure += 10) {
> +               litest_axis_set_value(axes, ABS_PRESSURE, pressure);
> +               litest_tablet_motion(dev, 70, 70, axes);
> +               libinput_dispatch(li);
> +
> +               event = libinput_get_event(li);
> +               tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS);
> +               p = libinput_event_tablet_tool_get_pressure(tev);
> +               ck_assert_double_ge(p, 0.0);
> +               ck_assert_double_le(p, 1.0);
> +               libinput_event_destroy(event);
> +       }
> +}
> +END_TEST
> +
>  START_TEST(tablet_pressure_offset_exceed_threshold)
>  {
>         struct litest_device *dev = litest_current_device();
> @@ -3212,6 +3245,39 @@ START_TEST(tablet_pressure_offset_none_for_small_distance)
>  }
>  END_TEST
>
> +START_TEST(tablet_distance_range)
> +{
> +       struct litest_device *dev = litest_current_device();
> +       struct libinput *li = dev->libinput;
> +       struct libinput_event *event;
> +       struct libinput_event_tablet_tool *tev;
> +       struct axis_replacement axes[] = {
> +               { ABS_DISTANCE, 20 },
> +               { ABS_PRESSURE, 0 },
> +               { -1, -1 },
> +       };
> +       int distance;
> +       double dist;
> +
> +       litest_tablet_proximity_in(dev, 5, 100, axes);
> +       litest_drain_events(li);
> +       libinput_dispatch(li);
> +
> +       for (distance = 0; distance <= 100; distance += 10) {
> +               litest_axis_set_value(axes, ABS_DISTANCE, distance);
> +               litest_tablet_motion(dev, 70, 70, axes);
> +               libinput_dispatch(li);
> +
> +               event = libinput_get_event(li);
> +               tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS);
> +               dist = libinput_event_tablet_tool_get_distance(tev);
> +               ck_assert_double_ge(dist, 0.0);
> +               ck_assert_double_le(dist, 1.0);
> +               libinput_event_destroy(event);
> +       }
> +}
> +END_TEST
> +
>  START_TEST(tilt_available)
>  {
>         struct litest_device *dev = litest_current_device();
> @@ -3672,12 +3738,14 @@ litest_setup_tests(void)
>         litest_add("tablet:calibration", tablet_calibration_set_matrix, LITEST_TABLET, LITEST_ANY);
>         litest_add("tablet:calibration", tablet_calibration_set_matrix_delta, LITEST_TABLET, LITEST_ANY);
>
> +       litest_add_for_device("tablet:pressure", tablet_pressure_range, LITEST_WACOM_INTUOS);
>         litest_add_for_device("tablet:pressure", tablet_pressure_offset, LITEST_WACOM_INTUOS);
>         litest_add_for_device("tablet:pressure", tablet_pressure_offset_decrease, LITEST_WACOM_INTUOS);
>         litest_add_for_device("tablet:pressure", tablet_pressure_offset_increase, LITEST_WACOM_INTUOS);
>         litest_add_for_device("tablet:pressure", tablet_pressure_offset_exceed_threshold, LITEST_WACOM_INTUOS);
>         litest_add_for_device("tablet:pressure", tablet_pressure_offset_none_for_zero_distance, LITEST_WACOM_INTUOS);
>         litest_add_for_device("tablet:pressure", tablet_pressure_offset_none_for_small_distance, LITEST_WACOM_INTUOS);
> +       litest_add_for_device("tablet:distance", tablet_distance_range, LITEST_WACOM_INTUOS);
>
>         litest_add("tablet:relative", relative_no_profile, LITEST_TABLET, LITEST_ANY);
>         litest_add("tablet:relative", relative_no_delta_prox_in, LITEST_TABLET, LITEST_ANY);
> --
> 2.7.4
>


More information about the wayland-devel mailing list