tablet: add libinput_event_tablet_get_axis_delta_discrete()

Equivalent to the pointer axis function - it gets the mouse wheel clicks from
the tablet mouse.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Stephen Chandler Paul <thatslyude@gmail.com>
This commit is contained in:
Peter Hutterer 2015-02-20 14:34:31 +10:00
parent 57bba7f8a5
commit abc57105ae
6 changed files with 63 additions and 6 deletions

View file

@ -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));

View file

@ -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,

View file

@ -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,

View file

@ -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
*

View file

@ -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;

View file

@ -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);
}
}