Commit e5a33086 authored by Peter Hutterer's avatar Peter Hutterer

tablet: rename axis_get_value into an axis-specific API set

Second part of the big revamp to get rid of libinput_tablet_tool_axis and
replace it with a set of axis-specific APIs.

Note that this commit drops the ability to get the absolute value from a
relative wheel. The previous API always returned 0 for this case, it is not
needed anymore.
Signed-off-by: Peter Hutterer's avatarPeter Hutterer <peter.hutterer@who-t.net>
Acked-by: default avatarHans de Goede <hdegoede@redhat.com>
Reviewed-by: default avatarLyude <cpaul@redhat.com>
parent 5c9c4810
......@@ -1047,7 +1047,7 @@ libinput_event_tablet_tool_wheel_has_changed(
LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL);
}
LIBINPUT_EXPORT double
static double
libinput_event_tablet_tool_get_axis_value(struct libinput_event_tablet_tool *event,
enum libinput_tablet_tool_axis axis)
{
......@@ -1081,6 +1081,62 @@ libinput_event_tablet_tool_get_axis_value(struct libinput_event_tablet_tool *eve
}
}
LIBINPUT_EXPORT double
libinput_event_tablet_tool_get_x(struct libinput_event_tablet_tool *event)
{
return libinput_event_tablet_tool_get_axis_value(event,
LIBINPUT_TABLET_TOOL_AXIS_X);
}
LIBINPUT_EXPORT double
libinput_event_tablet_tool_get_y(struct libinput_event_tablet_tool *event)
{
return libinput_event_tablet_tool_get_axis_value(event,
LIBINPUT_TABLET_TOOL_AXIS_Y);
}
LIBINPUT_EXPORT double
libinput_event_tablet_tool_get_pressure(struct libinput_event_tablet_tool *event)
{
return libinput_event_tablet_tool_get_axis_value(event,
LIBINPUT_TABLET_TOOL_AXIS_PRESSURE);
}
LIBINPUT_EXPORT double
libinput_event_tablet_tool_get_distance(struct libinput_event_tablet_tool *event)
{
return libinput_event_tablet_tool_get_axis_value(event,
LIBINPUT_TABLET_TOOL_AXIS_DISTANCE);
}
LIBINPUT_EXPORT double
libinput_event_tablet_tool_get_tilt_x(struct libinput_event_tablet_tool *event)
{
return libinput_event_tablet_tool_get_axis_value(event,
LIBINPUT_TABLET_TOOL_AXIS_TILT_X);
}
LIBINPUT_EXPORT double
libinput_event_tablet_tool_get_tilt_y(struct libinput_event_tablet_tool *event)
{
return libinput_event_tablet_tool_get_axis_value(event,
LIBINPUT_TABLET_TOOL_AXIS_TILT_Y);
}
LIBINPUT_EXPORT double
libinput_event_tablet_tool_get_rotation(struct libinput_event_tablet_tool *event)
{
return libinput_event_tablet_tool_get_axis_value(event,
LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z);
}
LIBINPUT_EXPORT double
libinput_event_tablet_tool_get_slider_position(struct libinput_event_tablet_tool *event)
{
return libinput_event_tablet_tool_get_axis_value(event,
LIBINPUT_TABLET_TOOL_AXIS_SLIDER);
}
LIBINPUT_EXPORT double
libinput_event_tablet_tool_get_axis_delta(struct libinput_event_tablet_tool *event,
enum libinput_tablet_tool_axis axis)
......
......@@ -1520,47 +1520,122 @@ libinput_event_tablet_tool_wheel_has_changed(
/**
* @ingroup event_tablet
*
* Return the axis value of a given axis for a tablet. The interpretation of the
* value is dependent on the axis:
* - @ref LIBINPUT_TABLET_TOOL_AXIS_X and @ref LIBINPUT_TABLET_TOOL_AXIS_Y - the X and
* Y coordinates of the tablet tool, in mm from the top left corner of the
* tablet. Use libinput_event_tablet_tool_get_x_transformed() and
* libinput_event_tablet_tool_get_y_transformed() for transforming each
* respective axis value into a different coordinate space.
* - @ref LIBINPUT_TABLET_TOOL_AXIS_DISTANCE - The distance from the tablet's
* sensor, normalized from 0 to 1
* - @ref LIBINPUT_TABLET_TOOL_AXIS_PRESSURE - The current pressure being applied on
* the tool in use, normalized from 0 to 1
* - @ref LIBINPUT_TABLET_TOOL_AXIS_TILT_X and @ref LIBINPUT_TABLET_TOOL_AXIS_TILT_Y -
* normalized value between -1 and 1 that indicates the X or Y tilt of the
* tool
* - @ref LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z - The z rotation of the tool in
* degrees, clockwise from the tool's logical neutral position. For the
* @ref LIBINPUT_TABLET_TOOL_TYPE_MOUSE and @ref LIBINPUT_TABLET_TOOL_TYPE_LENS tools
* the logical neutral position is pointing to the current logical north
* of the tablet. For the @ref LIBINPUT_TABLET_TOOL_TYPE_BRUSH tool, the logical
* neutral position is with the buttons pointing up.
* - @ref LIBINPUT_TABLET_TOOL_AXIS_SLIDER - A slider on the tool, normalized
* from 0 to 1. e.g. the wheel-like tool on the Wacom Airbrush.
* - @ref LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL - A relative wheel on the tool,
* similar or equivalent to a mouse wheel. The value is always 0, use
* libinput_event_tablet_tool_get_axis_delta() instead.
* Returns the X coordinate of tablet tool, in mm from the top left corner
* of the tablet in its current logical orientation. Use
* libinput_event_tablet_tool_get_x_transformed() for transforming the axis
* value into a different coordinate space.
*
* @note This function may be called for a specific axis even if
* libinput_event_tablet_tool_*_has_changed() returns 0 for that axis.
* libinput always includes all device axes in the event.
* @param event The libinput tablet event
* @return The current value of the the axis
*/
double
libinput_event_tablet_tool_get_x(struct libinput_event_tablet_tool *event);
/**
* @ingroup event_tablet
*
* If the event is of type @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY and the
* event is a proximity out event, the value returned is the last known
* value of the tool before it left proximity.
* Returns the Y coordinate of tablet tool, in mm from the top left corner
* of the tablet in its current logical orientation. Use
* libinput_event_tablet_tool_get_y_transformed() for transforming the axis
* value into a different coordinate space.
*
* @param event The libinput tablet event
* @param axis The axis to retrieve the value of
* @return The current value of the the axis
*/
double
libinput_event_tablet_tool_get_axis_value(struct libinput_event_tablet_tool *event,
enum libinput_tablet_tool_axis axis);
libinput_event_tablet_tool_get_y(struct libinput_event_tablet_tool *event);
/**
* @ingroup event_tablet
*
* Returns the current pressure being applied on the tool in use, normalized
* to the range [0, 1].
*
* If this axis does not exist on the device, this function returns 0.
*
* @param event The libinput tablet event
* @return The current value of the the axis
*/
double
libinput_event_tablet_tool_get_pressure(struct libinput_event_tablet_tool *event);
/**
* @ingroup event_tablet
*
* Returns the current distance from the tablet's sensor, normalized to the
* range [0, 1].
*
* If this axis does not exist on the device, this function returns 0.
*
* @param event The libinput tablet event
* @return The current value of the the axis
*/
double
libinput_event_tablet_tool_get_distance(struct libinput_event_tablet_tool *event);
/**
* @ingroup event_tablet
*
* Returns the current tilt along the X axis of the tablet's current logical
* orientation, normalized to the range [-1, 1].
*
* If this axis does not exist on the device, this function returns 0.
*
* @param event The libinput tablet event
* @return The current value of the the axis
*/
double
libinput_event_tablet_tool_get_tilt_x(struct libinput_event_tablet_tool *event);
/**
* @ingroup event_tablet
*
* Returns the current tilt along the Y axis of the tablet's current logical
* orientation, normalized to the range [-1, 1].
*
* If this axis does not exist on the device, this function returns 0.
*
* @param event The libinput tablet event
* @return The current value of the the axis
*/
double
libinput_event_tablet_tool_get_tilt_y(struct libinput_event_tablet_tool *event);
/**
* @ingroup event_tablet
*
* Returns the current z rotation of the tool in degrees, clockwise from the
* tool's logical neutral position.
*
* For tools of type @ref LIBINPUT_TABLET_TOOL_TYPE_MOUSE and @ref
* LIBINPUT_TABLET_TOOL_TYPE_LENS the logical neutral position is
* pointing to the current logical north of the tablet. For tools of type @ref
* LIBINPUT_TABLET_TOOL_TYPE_BRUSH, the logical neutral position is with the
* buttons pointing up.
*
* If this axis does not exist on the device, this function returns 0.
*
* @param event The libinput tablet event
* @return The current value of the the axis
*/
double
libinput_event_tablet_tool_get_rotation(struct libinput_event_tablet_tool *event);
/**
* @ingroup event_tablet
*
* Returns the current position of the slider on the tool, normalized to the
* range [-1, 1]. The logical zero is the neutral position of the slider, or
* the logical center of the axis. This axis is available on e.g. the Wacom
* Airbrush.
*
* If this axis does not exist on the device, this function returns 0.
*
* @param event The libinput tablet event
* @return The current value of the the axis
*/
double
libinput_event_tablet_tool_get_slider_position(struct libinput_event_tablet_tool *event);
/**
* @ingroup event_tablet
......
......@@ -194,9 +194,16 @@ LIBINPUT_TABLET_SUPPORT {
libinput_event_tablet_tool_tilt_y_has_changed;
libinput_event_tablet_tool_wheel_has_changed;
libinput_event_tablet_tool_slider_has_changed;
libinput_event_tablet_tool_get_x;
libinput_event_tablet_tool_get_y;
libinput_event_tablet_tool_get_pressure;
libinput_event_tablet_tool_get_distance;
libinput_event_tablet_tool_get_tilt_x;
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_axis_value;
libinput_event_tablet_tool_get_base_event;
libinput_event_tablet_tool_get_button;
libinput_event_tablet_tool_get_button_state;
......
This diff is collapsed.
......@@ -344,8 +344,8 @@ print_tablet_axes(struct libinput_event_tablet_tool *t)
#define changed_sym(ev, ax) \
(libinput_event_tablet_tool_##ax##_has_changed(ev) ? "*" : "")
x = libinput_event_tablet_tool_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_X);
y = libinput_event_tablet_tool_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_Y);
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)",
......@@ -355,10 +355,8 @@ print_tablet_axes(struct libinput_event_tablet_tool *t)
if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) ||
libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) {
x = libinput_event_tablet_tool_get_axis_value(t,
LIBINPUT_TABLET_TOOL_AXIS_TILT_X);
y = libinput_event_tablet_tool_get_axis_value(t,
LIBINPUT_TABLET_TOOL_AXIS_TILT_Y);
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,
......@@ -371,10 +369,8 @@ print_tablet_axes(struct libinput_event_tablet_tool *t)
if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE) ||
libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) {
dist = libinput_event_tablet_tool_get_axis_value(t,
LIBINPUT_TABLET_TOOL_AXIS_DISTANCE);
pressure = libinput_event_tablet_tool_get_axis_value(t,
LIBINPUT_TABLET_TOOL_AXIS_PRESSURE);
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);
......@@ -391,8 +387,7 @@ print_tablet_axes(struct libinput_event_tablet_tool *t)
}
if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)) {
rotation = libinput_event_tablet_tool_get_axis_value(t,
LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z);
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)",
......@@ -401,8 +396,7 @@ print_tablet_axes(struct libinput_event_tablet_tool *t)
}
if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_SLIDER)) {
slider = libinput_event_tablet_tool_get_axis_value(t,
LIBINPUT_TABLET_TOOL_AXIS_SLIDER);
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)",
......
......@@ -624,14 +624,10 @@ handle_event_tablet(struct libinput_event *ev, struct window *w)
w->width);
w->tool.y = libinput_event_tablet_tool_get_y_transformed(t,
w->height);
w->tool.pressure = libinput_event_tablet_tool_get_axis_value(t,
LIBINPUT_TABLET_TOOL_AXIS_PRESSURE);
w->tool.distance = libinput_event_tablet_tool_get_axis_value(t,
LIBINPUT_TABLET_TOOL_AXIS_DISTANCE);
w->tool.tilt_x = libinput_event_tablet_tool_get_axis_value(t,
LIBINPUT_TABLET_TOOL_AXIS_TILT_X);
w->tool.tilt_y = libinput_event_tablet_tool_get_axis_value(t,
LIBINPUT_TABLET_TOOL_AXIS_TILT_Y);
w->tool.pressure = libinput_event_tablet_tool_get_pressure(t);
w->tool.distance = libinput_event_tablet_tool_get_distance(t);
w->tool.tilt_x = libinput_event_tablet_tool_get_tilt_x(t);
w->tool.tilt_y = libinput_event_tablet_tool_get_tilt_y(t);
break;
case LIBINPUT_EVENT_TABLET_TOOL_TIP:
x = libinput_event_tablet_tool_get_x_transformed(t, w->width);
......
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