diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index f5cd63fe..45242025 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -317,6 +317,7 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, int a; double axes[LIBINPUT_TABLET_AXIS_MAX + 1] = {0}; double deltas[LIBINPUT_TABLET_AXIS_MAX + 1] = {0}; + double deltas_discrete[LIBINPUT_TABLET_AXIS_MAX + 1] = {0}; double oldval; for (a = LIBINPUT_TABLET_AXIS_X; a <= LIBINPUT_TABLET_AXIS_MAX; a++) { @@ -342,6 +343,7 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, deltas[a] = get_delta(a, tablet->axes[a], oldval); continue; } else if (a == LIBINPUT_TABLET_AXIS_REL_WHEEL) { + deltas_discrete[a] = tablet->deltas[a]; deltas[a] = normalize_wheel(tablet, tablet->deltas[a]); axes[a] = 0; @@ -403,7 +405,8 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, tool, tablet->changed_axes, axes, - deltas); + deltas, + deltas_discrete); } memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes)); diff --git a/src/libinput-private.h b/src/libinput-private.h index 3a4e4a5a..1c2a3290 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -350,7 +350,8 @@ tablet_notify_axis(struct libinput_device *device, struct libinput_tool *tool, unsigned char *changed_axes, double *axes, - double *deltas); + double *deltas, + double *deltas_discrete); void tablet_notify_proximity(struct libinput_device *device, diff --git a/src/libinput.c b/src/libinput.c index 71271827..d693ef65 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -87,6 +87,7 @@ struct libinput_event_tablet { uint32_t time; double axes[LIBINPUT_TABLET_AXIS_MAX + 1]; double deltas[LIBINPUT_TABLET_AXIS_MAX + 1]; + double deltas_discrete[LIBINPUT_TABLET_AXIS_MAX + 1]; unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_AXIS_MAX + 1)]; struct libinput_tool *tool; enum libinput_tool_proximity_state proximity_state; @@ -625,6 +626,31 @@ libinput_event_tablet_get_axis_delta(struct libinput_event_tablet *event, } } +LIBINPUT_EXPORT double +libinput_event_tablet_get_axis_delta_discrete( + struct libinput_event_tablet *event, + enum libinput_tablet_axis axis) +{ + if (event->base.type != LIBINPUT_EVENT_TABLET_AXIS && + event->base.type != LIBINPUT_EVENT_TABLET_PROXIMITY) + return 0; + + switch(axis) { + case LIBINPUT_TABLET_AXIS_X: + case LIBINPUT_TABLET_AXIS_Y: + case LIBINPUT_TABLET_AXIS_DISTANCE: + case LIBINPUT_TABLET_AXIS_PRESSURE: + case LIBINPUT_TABLET_AXIS_TILT_X: + case LIBINPUT_TABLET_AXIS_TILT_Y: + case LIBINPUT_TABLET_AXIS_ROTATION_Z: + case LIBINPUT_TABLET_AXIS_SLIDER: + case LIBINPUT_TABLET_AXIS_REL_WHEEL: + return event->deltas_discrete[axis]; + default: + return 0; + } +} + LIBINPUT_EXPORT double libinput_event_tablet_get_x_transformed(struct libinput_event_tablet *event, uint32_t width) @@ -1433,7 +1459,8 @@ tablet_notify_axis(struct libinput_device *device, struct libinput_tool *tool, unsigned char *changed_axes, double *axes, - double *deltas) + double *deltas, + double *deltas_discrete) { struct libinput_event_tablet *axis_event; @@ -1451,6 +1478,9 @@ tablet_notify_axis(struct libinput_device *device, sizeof(axis_event->changed_axes)); memcpy(axis_event->axes, axes, sizeof(axis_event->axes)); memcpy(axis_event->deltas, deltas, sizeof(axis_event->deltas)); + memcpy(axis_event->deltas_discrete, + deltas_discrete, + sizeof(axis_event->deltas_discrete)); post_device_event(device, time, diff --git a/src/libinput.h b/src/libinput.h index 60fdfb01..17be1797 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1100,6 +1100,28 @@ double libinput_event_tablet_get_axis_delta(struct libinput_event_tablet *event, enum libinput_tablet_axis axis); +/** + * @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_AXIS_REL_WHEEL - the returned value is the number + * of physical mouse wheel clicks. + * For all other axes, this function returns 0. + * + * @note The delta is *not* the delta to the previous event, but the delta + * to the previous axis state, i.e. the delta to the last event that + * libinput_event_tablet_axis_has_changed() returned true for this axis. + * + * @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 + */ +double +libinput_event_tablet_get_axis_delta_discrete( + struct libinput_event_tablet *event, + enum libinput_tablet_axis axis); + /** * @ingroup event_tablet * diff --git a/src/libinput.sym b/src/libinput.sym index cb94d60b..62ea6960 100644 --- a/src/libinput.sym +++ b/src/libinput.sym @@ -147,6 +147,7 @@ LIBINPUT_TABLET_SUPPORT { libinput_event_get_tablet_event; libinput_event_tablet_axis_has_changed; libinput_event_tablet_get_axis_delta; + libinput_event_tablet_get_axis_delta_discrete; libinput_event_tablet_get_axis_value; libinput_event_tablet_get_button; libinput_event_tablet_get_button_state; diff --git a/tools/event-debug.c b/tools/event-debug.c index 7b68d96b..226a70ca 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -375,13 +375,13 @@ print_tablet_axes(struct libinput_event_tablet *t) if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_REL_WHEEL)) { wheel = libinput_event_tablet_get_axis_value(t, LIBINPUT_TABLET_AXIS_REL_WHEEL); - delta = libinput_event_tablet_get_axis_delta(t, + delta = libinput_event_tablet_get_axis_delta_discrete(t, LIBINPUT_TABLET_AXIS_REL_WHEEL); - printf("\twheel: %.2f%s (%.2f)", + printf("\twheel: %.2f%s (%d)", wheel, tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_REL_WHEEL), - delta); + (int)delta); } }