mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-26 19:10:06 +01:00
tablet: fix distance normalization range after 25a9f39
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@who-t.net>
Reviewed-by: Jason Gerecke <jason.gerecke@wacom.com>
This commit is contained in:
parent
248912f1ef
commit
4552d686f8
2 changed files with 80 additions and 3 deletions
|
|
@ -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;
|
||||
|
|
@ -239,6 +239,15 @@ normalize_dist_slider(const struct input_absinfo *absinfo)
|
|||
return value * 2 - 1;
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue