Commit 72121d6f authored by Peter Hutterer's avatar Peter Hutterer

tablet: reduce the pressure range by the offset

Previously, the pressure range was calculated from the axis total range. A
device with a pressure offset making the bottom 10% inaccessible would lose
10% of that range as non-accessible. Due to the implementation, this affected
the upper range of the device, so the top N percent became unaccessible. Which
may be why no-one's noticed this yet.
Signed-off-by: Peter Hutterer's avatarPeter Hutterer <peter.hutterer@who-t.net>
parent f97e361d
......@@ -354,9 +354,9 @@ static inline double
normalize_pressure(const struct input_absinfo *absinfo,
struct libinput_tablet_tool *tool)
{
double range = absinfo->maximum - absinfo->minimum;
int offset = tool->has_pressure_offset ?
tool->pressure_offset : absinfo->minimum;
double range = absinfo->maximum - offset;
double value = (absinfo->value - offset) / range;
return value;
......
......@@ -3567,6 +3567,7 @@ START_TEST(tablet_pressure_offset)
};
double pressure;
/* This activates the pressure thresholds */
litest_tablet_proximity_in(dev, 5, 100, axes);
litest_drain_events(li);
......@@ -3594,9 +3595,8 @@ START_TEST(tablet_pressure_offset)
pressure = libinput_event_tablet_tool_get_pressure(tev);
/* we can't actually get a real 0.0 because that would trigger a tip
* up. but it's close enough to zero that ck_assert_double_eq won't
* notice */
ck_assert_double_eq(pressure, 0.0);
up. but it's close enough to zero. */
ck_assert_double_lt(pressure, 0.01);
libinput_event_destroy(event);
litest_drain_events(li);
......@@ -3613,6 +3613,22 @@ START_TEST(tablet_pressure_offset)
ck_assert_double_lt(pressure, 0.015);
libinput_event_destroy(event);
/* Make sure we can reach the upper range too */
litest_axis_set_value(axes, ABS_PRESSURE, 100);
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);
pressure = libinput_event_tablet_tool_get_pressure(tev);
ck_assert_double_ge(pressure, 1.0);
libinput_event_destroy(event);
}
END_TEST
......@@ -3713,8 +3729,8 @@ START_TEST(tablet_pressure_offset_increase)
tev = litest_is_tablet_event(event,
LIBINPUT_EVENT_TABLET_TOOL_AXIS);
pressure = libinput_event_tablet_tool_get_pressure(tev);
/* Pressure should be around 10% */
ck_assert_double_eq_tol(pressure, 0.10, 0.01);
/* offset 20, value 30 leaves us with 12% of the remaining 90 range */
ck_assert_double_eq_tol(pressure, 0.12, 0.01);
libinput_event_destroy(event);
litest_drain_events(li);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment