mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-05-08 12:28:10 +02:00
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:
parent
57bba7f8a5
commit
abc57105ae
6 changed files with 63 additions and 6 deletions
|
|
@ -317,6 +317,7 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet,
|
||||||
int a;
|
int a;
|
||||||
double axes[LIBINPUT_TABLET_AXIS_MAX + 1] = {0};
|
double axes[LIBINPUT_TABLET_AXIS_MAX + 1] = {0};
|
||||||
double deltas[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;
|
double oldval;
|
||||||
|
|
||||||
for (a = LIBINPUT_TABLET_AXIS_X; a <= LIBINPUT_TABLET_AXIS_MAX; a++) {
|
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);
|
deltas[a] = get_delta(a, tablet->axes[a], oldval);
|
||||||
continue;
|
continue;
|
||||||
} else if (a == LIBINPUT_TABLET_AXIS_REL_WHEEL) {
|
} else if (a == LIBINPUT_TABLET_AXIS_REL_WHEEL) {
|
||||||
|
deltas_discrete[a] = tablet->deltas[a];
|
||||||
deltas[a] = normalize_wheel(tablet,
|
deltas[a] = normalize_wheel(tablet,
|
||||||
tablet->deltas[a]);
|
tablet->deltas[a]);
|
||||||
axes[a] = 0;
|
axes[a] = 0;
|
||||||
|
|
@ -403,7 +405,8 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet,
|
||||||
tool,
|
tool,
|
||||||
tablet->changed_axes,
|
tablet->changed_axes,
|
||||||
axes,
|
axes,
|
||||||
deltas);
|
deltas,
|
||||||
|
deltas_discrete);
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes));
|
memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes));
|
||||||
|
|
|
||||||
|
|
@ -350,7 +350,8 @@ tablet_notify_axis(struct libinput_device *device,
|
||||||
struct libinput_tool *tool,
|
struct libinput_tool *tool,
|
||||||
unsigned char *changed_axes,
|
unsigned char *changed_axes,
|
||||||
double *axes,
|
double *axes,
|
||||||
double *deltas);
|
double *deltas,
|
||||||
|
double *deltas_discrete);
|
||||||
|
|
||||||
void
|
void
|
||||||
tablet_notify_proximity(struct libinput_device *device,
|
tablet_notify_proximity(struct libinput_device *device,
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,7 @@ struct libinput_event_tablet {
|
||||||
uint32_t time;
|
uint32_t time;
|
||||||
double axes[LIBINPUT_TABLET_AXIS_MAX + 1];
|
double axes[LIBINPUT_TABLET_AXIS_MAX + 1];
|
||||||
double deltas[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)];
|
unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_AXIS_MAX + 1)];
|
||||||
struct libinput_tool *tool;
|
struct libinput_tool *tool;
|
||||||
enum libinput_tool_proximity_state proximity_state;
|
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_EXPORT double
|
||||||
libinput_event_tablet_get_x_transformed(struct libinput_event_tablet *event,
|
libinput_event_tablet_get_x_transformed(struct libinput_event_tablet *event,
|
||||||
uint32_t width)
|
uint32_t width)
|
||||||
|
|
@ -1433,7 +1459,8 @@ tablet_notify_axis(struct libinput_device *device,
|
||||||
struct libinput_tool *tool,
|
struct libinput_tool *tool,
|
||||||
unsigned char *changed_axes,
|
unsigned char *changed_axes,
|
||||||
double *axes,
|
double *axes,
|
||||||
double *deltas)
|
double *deltas,
|
||||||
|
double *deltas_discrete)
|
||||||
{
|
{
|
||||||
struct libinput_event_tablet *axis_event;
|
struct libinput_event_tablet *axis_event;
|
||||||
|
|
||||||
|
|
@ -1451,6 +1478,9 @@ tablet_notify_axis(struct libinput_device *device,
|
||||||
sizeof(axis_event->changed_axes));
|
sizeof(axis_event->changed_axes));
|
||||||
memcpy(axis_event->axes, axes, sizeof(axis_event->axes));
|
memcpy(axis_event->axes, axes, sizeof(axis_event->axes));
|
||||||
memcpy(axis_event->deltas, deltas, sizeof(axis_event->deltas));
|
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,
|
post_device_event(device,
|
||||||
time,
|
time,
|
||||||
|
|
|
||||||
|
|
@ -1100,6 +1100,28 @@ double
|
||||||
libinput_event_tablet_get_axis_delta(struct libinput_event_tablet *event,
|
libinput_event_tablet_get_axis_delta(struct libinput_event_tablet *event,
|
||||||
enum libinput_tablet_axis axis);
|
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
|
* @ingroup event_tablet
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -147,6 +147,7 @@ LIBINPUT_TABLET_SUPPORT {
|
||||||
libinput_event_get_tablet_event;
|
libinput_event_get_tablet_event;
|
||||||
libinput_event_tablet_axis_has_changed;
|
libinput_event_tablet_axis_has_changed;
|
||||||
libinput_event_tablet_get_axis_delta;
|
libinput_event_tablet_get_axis_delta;
|
||||||
|
libinput_event_tablet_get_axis_delta_discrete;
|
||||||
libinput_event_tablet_get_axis_value;
|
libinput_event_tablet_get_axis_value;
|
||||||
libinput_event_tablet_get_button;
|
libinput_event_tablet_get_button;
|
||||||
libinput_event_tablet_get_button_state;
|
libinput_event_tablet_get_button_state;
|
||||||
|
|
|
||||||
|
|
@ -375,13 +375,13 @@ print_tablet_axes(struct libinput_event_tablet *t)
|
||||||
if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_REL_WHEEL)) {
|
if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_REL_WHEEL)) {
|
||||||
wheel = libinput_event_tablet_get_axis_value(t,
|
wheel = libinput_event_tablet_get_axis_value(t,
|
||||||
LIBINPUT_TABLET_AXIS_REL_WHEEL);
|
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);
|
LIBINPUT_TABLET_AXIS_REL_WHEEL);
|
||||||
printf("\twheel: %.2f%s (%.2f)",
|
printf("\twheel: %.2f%s (%d)",
|
||||||
wheel,
|
wheel,
|
||||||
tablet_axis_changed_sym(t,
|
tablet_axis_changed_sym(t,
|
||||||
LIBINPUT_TABLET_AXIS_REL_WHEEL),
|
LIBINPUT_TABLET_AXIS_REL_WHEEL),
|
||||||
delta);
|
(int)delta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue