[PATCH libinput 4/5] tablet: reduce event deltas to only apply to the wheel
Peter Hutterer
peter.hutterer at who-t.net
Sun Dec 13 18:00:13 PST 2015
Part of the big revamp to get rid of libinput_tablet_tool_axis and
replace it with a set of axis-specific APIs.
Only the rel wheel has true delta events, everything else is a delta
calculated by libinput based on the previous position. Since we supply that
position to the callers anyway, they can determinte that delta themselves
where needed.
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
src/libinput.c | 47 +++------------------
src/libinput.h | 37 +++++++---------
src/libinput.sym | 4 +-
test/tablet.c | 119 ++--------------------------------------------------
tools/event-debug.c | 57 ++++++++-----------------
5 files changed, 43 insertions(+), 221 deletions(-)
diff --git a/src/libinput.c b/src/libinput.c
index 2f797dc..b1bced0 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -1138,12 +1138,8 @@ libinput_event_tablet_tool_get_slider_position(struct libinput_event_tablet_tool
}
LIBINPUT_EXPORT double
-libinput_event_tablet_tool_get_axis_delta(struct libinput_event_tablet_tool *event,
- enum libinput_tablet_tool_axis axis)
+libinput_event_tablet_tool_get_wheel_delta(struct libinput_event_tablet_tool *event)
{
- struct evdev_device *device =
- (struct evdev_device *) event->base.device;
-
require_event_type(libinput_event_get_context(&event->base),
event->base.type,
0,
@@ -1151,30 +1147,12 @@ libinput_event_tablet_tool_get_axis_delta(struct libinput_event_tablet_tool *eve
LIBINPUT_EVENT_TABLET_TOOL_TIP,
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY);
- switch(axis) {
- case LIBINPUT_TABLET_TOOL_AXIS_X:
- return evdev_convert_to_mm(device->abs.absinfo_x,
- event->deltas[axis]);
- case LIBINPUT_TABLET_TOOL_AXIS_Y:
- return evdev_convert_to_mm(device->abs.absinfo_y,
- event->deltas[axis]);
- case LIBINPUT_TABLET_TOOL_AXIS_DISTANCE:
- case LIBINPUT_TABLET_TOOL_AXIS_PRESSURE:
- case LIBINPUT_TABLET_TOOL_AXIS_TILT_X:
- case LIBINPUT_TABLET_TOOL_AXIS_TILT_Y:
- case LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z:
- case LIBINPUT_TABLET_TOOL_AXIS_SLIDER:
- case LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL:
- return event->deltas[axis];
- default:
- return 0;
- }
+ return event->deltas[LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL];
}
-LIBINPUT_EXPORT double
-libinput_event_tablet_tool_get_axis_delta_discrete(
- struct libinput_event_tablet_tool *event,
- enum libinput_tablet_tool_axis axis)
+LIBINPUT_EXPORT int
+libinput_event_tablet_tool_get_wheel_delta_discrete(
+ struct libinput_event_tablet_tool *event)
{
require_event_type(libinput_event_get_context(&event->base),
event->base.type,
@@ -1183,20 +1161,7 @@ libinput_event_tablet_tool_get_axis_delta_discrete(
LIBINPUT_EVENT_TABLET_TOOL_TIP,
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY);
- switch(axis) {
- case LIBINPUT_TABLET_TOOL_AXIS_X:
- case LIBINPUT_TABLET_TOOL_AXIS_Y:
- case LIBINPUT_TABLET_TOOL_AXIS_DISTANCE:
- case LIBINPUT_TABLET_TOOL_AXIS_PRESSURE:
- case LIBINPUT_TABLET_TOOL_AXIS_TILT_X:
- case LIBINPUT_TABLET_TOOL_AXIS_TILT_Y:
- case LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z:
- case LIBINPUT_TABLET_TOOL_AXIS_SLIDER:
- case LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL:
- return event->deltas_discrete[axis];
- default:
- return 0;
- }
+ return event->deltas_discrete[LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL];
}
LIBINPUT_EXPORT double
diff --git a/src/libinput.h b/src/libinput.h
index 7403a76..786f869 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -1626,39 +1626,30 @@ libinput_event_tablet_tool_get_slider_position(struct libinput_event_tablet_tool
/**
* @ingroup event_tablet
*
- * Return the delta for a given axis for a tablet. The interpretation of the
- * value is axis-dependent:
- * - @ref LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL - A relative wheel on the tool,
- * similar or equivalent to a mouse wheel. The value is a delta from the
- * device's previous position, in degrees.
- * For all other axes, see libinput_event_tablet_tool_get_axis_value() for
- * details.
+ * Return the delta for the wheel in degrees.
*
* @param event The libinput tablet event
- * @param axis The axis to retrieve the value of
- * @return The delta to the previous axis value
+ * @return The delta of the wheel, in degrees, compared to the last event
+ *
+ * @see libinput_event_tablet_tool_get_wheel_delta_discrete
*/
double
-libinput_event_tablet_tool_get_axis_delta(struct libinput_event_tablet_tool *event,
- enum libinput_tablet_tool_axis axis);
+libinput_event_tablet_tool_get_wheel_delta(
+ struct libinput_event_tablet_tool *event);
/**
* @ingroup event_tablet
*
- * Return the delta for a given axis for a tablet in discrete steps.
- * How a value translates into a discrete step depends on the axis:
- * - @ref LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL - the returned value is the number
- * of physical mouse wheel clicks.
- * For all other axes, this function returns 0.
- *
+ * Return the delta for the wheel in discrete steps (e.g. wheel clicks).
+
* @param event The libinput tablet event
- * @param axis The axis to retrieve the value of
- * @return The delta to the previous axis value in discrete steps
+ * @return The delta of the wheel, in discrete steps, compared to the last event
+ *
+ * @see libinput_event_tablet_tool_get_wheel_delta_discrete
*/
-double
-libinput_event_tablet_tool_get_axis_delta_discrete(
- struct libinput_event_tablet_tool *event,
- enum libinput_tablet_tool_axis axis);
+int
+libinput_event_tablet_tool_get_wheel_delta_discrete(
+ struct libinput_event_tablet_tool *event);
/**
* @ingroup event_tablet
diff --git a/src/libinput.sym b/src/libinput.sym
index da98ac5..ddfe81d 100644
--- a/src/libinput.sym
+++ b/src/libinput.sym
@@ -202,8 +202,8 @@ LIBINPUT_TABLET_SUPPORT {
libinput_event_tablet_tool_get_tilt_y;
libinput_event_tablet_tool_get_rotation;
libinput_event_tablet_tool_get_slider_position;
- libinput_event_tablet_tool_get_axis_delta;
- libinput_event_tablet_tool_get_axis_delta_discrete;
+ libinput_event_tablet_tool_get_wheel_delta;
+ libinput_event_tablet_tool_get_wheel_delta_discrete;
libinput_event_tablet_tool_get_base_event;
libinput_event_tablet_tool_get_button;
libinput_event_tablet_tool_get_button_state;
diff --git a/test/tablet.c b/test/tablet.c
index 0e2d657..6f9cd3d 100644
--- a/test/tablet.c
+++ b/test/tablet.c
@@ -903,107 +903,6 @@ START_TEST(motion)
}
END_TEST
-START_TEST(motion_delta)
-{
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_event_tablet_tool *tablet_event;
- struct libinput_event *event;
- double x1, y1, x2, y2, dist1, dist2;
- double delta;
- struct axis_replacement axes[] = {
- { ABS_DISTANCE, 10 },
- { -1, -1 }
- };
-
- litest_drain_events(li);
-
- litest_tablet_proximity_in(dev, 5, 100, axes);
- libinput_dispatch(li);
-
- litest_wait_for_event_of_type(li,
- LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY,
- -1);
-
- event = libinput_get_event(li);
- tablet_event = libinput_event_get_tablet_tool_event(event);
- x1 = libinput_event_tablet_tool_get_x(tablet_event);
- y1 = libinput_event_tablet_tool_get_y(tablet_event);
- dist1 = libinput_event_tablet_tool_get_distance(tablet_event);
- libinput_event_destroy(event);
-
- axes[0].value = 40;
- litest_tablet_motion(dev, 40, 100, axes);
-
- litest_wait_for_event_of_type(li,
- LIBINPUT_EVENT_TABLET_TOOL_AXIS,
- -1);
- event = libinput_get_event(li);
- tablet_event = libinput_event_get_tablet_tool_event(event);
- x2 = libinput_event_tablet_tool_get_x(tablet_event);
- y2 = libinput_event_tablet_tool_get_y(tablet_event);
- dist2 = libinput_event_tablet_tool_get_distance(tablet_event);
-
- delta = libinput_event_tablet_tool_get_axis_delta(tablet_event,
- LIBINPUT_TABLET_TOOL_AXIS_X);
- litest_assert_double_eq(delta, x2 - x1);
- delta = libinput_event_tablet_tool_get_axis_delta(tablet_event,
- LIBINPUT_TABLET_TOOL_AXIS_Y);
- litest_assert_double_eq(delta, y2 - y1);
- delta = libinput_event_tablet_tool_get_axis_delta(tablet_event,
- LIBINPUT_TABLET_TOOL_AXIS_DISTANCE);
- litest_assert_double_eq(delta, dist2 - dist1);
-
- libinput_event_destroy(event);
-}
-END_TEST
-
-START_TEST(motion_delta_partial)
-{
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_event_tablet_tool *tablet_event;
- struct libinput_event *event;
- double dx, dy, ddist;
- struct axis_replacement axes[] = {
- { ABS_DISTANCE, 10 },
- { -1, -1 }
- };
-
- if (!libevdev_has_event_code(dev->evdev, EV_ABS, ABS_DISTANCE))
- return;
-
- litest_tablet_proximity_in(dev, 5, 100, axes);
- litest_tablet_motion(dev, 40, 100, axes);
- litest_drain_events(li);
-
- axes[0].value = 40;
- litest_tablet_motion(dev, 40, 100, axes);
- litest_wait_for_event_of_type(li,
- LIBINPUT_EVENT_TABLET_TOOL_AXIS,
- -1);
- event = libinput_get_event(li);
- tablet_event = libinput_event_get_tablet_tool_event(event);
-
- ck_assert(!libinput_event_tablet_tool_x_has_changed(tablet_event));
- dx = libinput_event_tablet_tool_get_axis_delta(tablet_event,
- LIBINPUT_TABLET_TOOL_AXIS_X);
- litest_assert_double_eq(dx, 0.0);
-
- ck_assert(!libinput_event_tablet_tool_y_has_changed(tablet_event));
- dy = libinput_event_tablet_tool_get_axis_delta(tablet_event,
- LIBINPUT_TABLET_TOOL_AXIS_Y);
- litest_assert_double_eq(dy, 0.0);
-
- ck_assert(libinput_event_tablet_tool_distance_has_changed(tablet_event));
- ddist = libinput_event_tablet_tool_get_axis_delta(tablet_event,
- LIBINPUT_TABLET_TOOL_AXIS_DISTANCE);
- ck_assert_double_gt(ddist, 0);
-
- libinput_event_destroy(event);
-}
-END_TEST
-
START_TEST(left_handed)
{
#if HAVE_LIBWACOM
@@ -1953,12 +1852,10 @@ START_TEST(mouse_wheel)
tev = libinput_event_get_tablet_tool_event(event);
ck_assert(libinput_event_tablet_tool_wheel_has_changed(tev));
- val = libinput_event_tablet_tool_get_axis_delta(tev,
- LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL);
+ val = libinput_event_tablet_tool_get_wheel_delta(tev);
ck_assert_int_eq(val, 15);
- val = libinput_event_tablet_tool_get_axis_delta_discrete(tev,
- LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL);
+ val = libinput_event_tablet_tool_get_wheel_delta_discrete(tev);
ck_assert_int_eq(val, 1);
libinput_event_destroy(event);
@@ -1980,12 +1877,10 @@ START_TEST(mouse_wheel)
tev = libinput_event_get_tablet_tool_event(event);
ck_assert(!libinput_event_tablet_tool_wheel_has_changed(tev));
- val = libinput_event_tablet_tool_get_axis_delta(tev,
- LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL);
+ val = libinput_event_tablet_tool_get_wheel_delta(tev);
ck_assert_int_eq(val, 0);
- val = libinput_event_tablet_tool_get_axis_delta_discrete(tev,
- LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL);
+ val = libinput_event_tablet_tool_get_wheel_delta_discrete(tev);
ck_assert_int_eq(val, 0);
libinput_event_destroy(event);
@@ -2165,10 +2060,6 @@ START_TEST(artpen_rotation)
/* artpen has a 90 deg offset cw */
ck_assert_int_eq(round(val), (angle + 90) % 360);
- val = libinput_event_tablet_tool_get_axis_delta(tev,
- LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z);
- ck_assert_int_eq(val, 8);
-
libinput_event_destroy(event);
litest_assert_empty_queue(li);
@@ -2460,8 +2351,6 @@ litest_setup_tests(void)
litest_add("tablet:tip", tip_state_axis, LITEST_TABLET, LITEST_ANY);
litest_add("tablet:tip", tip_state_button, LITEST_TABLET, LITEST_ANY);
litest_add("tablet:motion", motion, LITEST_TABLET, LITEST_ANY);
- litest_add("tablet:motion", motion_delta, LITEST_TABLET, LITEST_ANY);
- litest_add("tablet:motion", motion_delta_partial, LITEST_TABLET, LITEST_ANY);
litest_add("tablet:motion", motion_event_state, LITEST_TABLET, LITEST_ANY);
litest_add_for_device("tablet:left_handed", left_handed, LITEST_WACOM_INTUOS);
litest_add_for_device("tablet:left_handed", no_left_handed, LITEST_WACOM_CINTIQ);
diff --git a/tools/event-debug.c b/tools/event-debug.c
index b4e62f4..ddebc13 100644
--- a/tools/event-debug.c
+++ b/tools/event-debug.c
@@ -336,7 +336,7 @@ static void
print_tablet_axes(struct libinput_event_tablet_tool *t)
{
struct libinput_tablet_tool *tool = libinput_event_tablet_tool_get_tool(t);
- double x, y, dx, dy;
+ double x, y;
double dist, pressure;
double rotation, slider, wheel;
double delta;
@@ -346,68 +346,45 @@ print_tablet_axes(struct libinput_event_tablet_tool *t)
x = libinput_event_tablet_tool_get_x(t);
y = libinput_event_tablet_tool_get_x(t);
- dx = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_X);
- dy = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_Y);
- printf("\t%.2f%s/%.2f%s (%.2f/%.2f)",
+ printf("\t%.2f%s/%.2f%s",
x, changed_sym(t, x),
- y, changed_sym(t, y),
- dx, dy);
+ y, changed_sym(t, y));
if (libinput_tablet_tool_has_tilt(tool)) {
x = libinput_event_tablet_tool_get_tilt_x(t);
y = libinput_event_tablet_tool_get_tilt_y(t);
- dx = libinput_event_tablet_tool_get_axis_delta(t,
- LIBINPUT_TABLET_TOOL_AXIS_TILT_X);
- dy = libinput_event_tablet_tool_get_axis_delta(t,
- LIBINPUT_TABLET_TOOL_AXIS_TILT_Y);
- printf("\ttilt: %.2f%s/%.2f%s (%.2f/%.2f)",
+ printf("\ttilt: %.2f%s/%.2f%s",
x, changed_sym(t, tilt_x),
- y, changed_sym(t, tilt_y),
- dx, dy);
+ y, changed_sym(t, tilt_y));
}
if (libinput_tablet_tool_has_distance(tool) ||
libinput_tablet_tool_has_pressure(tool)) {
dist = libinput_event_tablet_tool_get_distance(t);
pressure = libinput_event_tablet_tool_get_pressure(t);
- if (dist) {
- delta = libinput_event_tablet_tool_get_axis_delta(t,
- LIBINPUT_TABLET_TOOL_AXIS_DISTANCE);
- printf("\tdistance: %.2f%s (%.2f)",
- dist, changed_sym(t, distance),
- delta);
- } else {
- delta = libinput_event_tablet_tool_get_axis_delta(t,
- LIBINPUT_TABLET_TOOL_AXIS_PRESSURE);
- printf("\tpressure: %.2f%s (%.2f)",
- pressure, changed_sym(t, pressure),
- delta);
- }
+ if (dist)
+ printf("\tdistance: %.2f%s",
+ dist, changed_sym(t, distance));
+ else
+ printf("\tpressure: %.2f%s",
+ pressure, changed_sym(t, pressure));
}
if (libinput_tablet_tool_has_rotation(tool)) {
rotation = libinput_event_tablet_tool_get_rotation(t);
- delta = libinput_event_tablet_tool_get_axis_delta(t,
- LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z);
- printf("\trotation: %.2f%s (%.2f)",
- rotation, changed_sym(t, rotation),
- delta);
+ printf("\trotation: %.2f%s",
+ rotation, changed_sym(t, rotation));
}
if (libinput_tablet_tool_has_slider(tool)) {
slider = libinput_event_tablet_tool_get_slider_position(t);
- delta = libinput_event_tablet_tool_get_axis_delta(t,
- LIBINPUT_TABLET_TOOL_AXIS_SLIDER);
- printf("\tslider: %.2f%s (%.2f)",
- slider, changed_sym(t, slider),
- delta);
+ printf("\tslider: %.2f%s",
+ slider, changed_sym(t, slider));
}
if (libinput_tablet_tool_has_wheel(tool)) {
- wheel = libinput_event_tablet_tool_get_axis_delta(t,
- LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL);
- delta = libinput_event_tablet_tool_get_axis_delta_discrete(t,
- LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL);
+ wheel = libinput_event_tablet_tool_get_wheel_delta(t);
+ delta = libinput_event_tablet_tool_get_wheel_delta_discrete(t);
printf("\twheel: %.2f%s (%d)",
wheel, changed_sym(t, wheel),
(int)delta);
--
2.5.0
More information about the wayland-devel
mailing list