tablet: rename libinput_tablet_tool_has_axis into an axis-specific API set

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 check whether a tablet has an x or
y axis. If it doesn't, libinput won't initialize the tablet anyway so this was
superfluous already.

Likewise with the tilt axes - either we have x and y tilt or we have neither,
so separate checks for tilt_x and tilt_y is unnecessary.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Lyude <cpaul@redhat.com>
This commit is contained in:
Peter Hutterer 2015-12-14 10:06:56 +10:00
parent e5a33086bc
commit 828ca69c77
5 changed files with 128 additions and 52 deletions

View file

@ -1359,10 +1359,45 @@ libinput_tablet_tool_get_serial(struct libinput_tablet_tool *tool)
} }
LIBINPUT_EXPORT int LIBINPUT_EXPORT int
libinput_tablet_tool_has_axis(struct libinput_tablet_tool *tool, libinput_tablet_tool_has_pressure(struct libinput_tablet_tool *tool)
enum libinput_tablet_tool_axis axis)
{ {
return bit_is_set(tool->axis_caps, axis); return bit_is_set(tool->axis_caps,
LIBINPUT_TABLET_TOOL_AXIS_PRESSURE);
}
LIBINPUT_EXPORT int
libinput_tablet_tool_has_distance(struct libinput_tablet_tool *tool)
{
return bit_is_set(tool->axis_caps,
LIBINPUT_TABLET_TOOL_AXIS_DISTANCE);
}
LIBINPUT_EXPORT int
libinput_tablet_tool_has_tilt(struct libinput_tablet_tool *tool)
{
return bit_is_set(tool->axis_caps,
LIBINPUT_TABLET_TOOL_AXIS_TILT_X);
}
LIBINPUT_EXPORT int
libinput_tablet_tool_has_rotation(struct libinput_tablet_tool *tool)
{
return bit_is_set(tool->axis_caps,
LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z);
}
LIBINPUT_EXPORT int
libinput_tablet_tool_has_slider(struct libinput_tablet_tool *tool)
{
return bit_is_set(tool->axis_caps,
LIBINPUT_TABLET_TOOL_AXIS_SLIDER);
}
LIBINPUT_EXPORT int
libinput_tablet_tool_has_wheel(struct libinput_tablet_tool *tool)
{
return bit_is_set(tool->axis_caps,
LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL);
} }
LIBINPUT_EXPORT int LIBINPUT_EXPORT int

View file

@ -1880,15 +1880,68 @@ libinput_tablet_tool_unref(struct libinput_tablet_tool *tool);
/** /**
* @ingroup event_tablet * @ingroup event_tablet
* *
* Return whether or not a tablet tool supports the specified axis * Return whether the tablet tool supports pressure.
* *
* @param tool The tool to check the axis capabilities of * @param tool The tool to check the axis capabilities of
* @param axis The axis to check for support * @return Nonzero if the axis is available, zero otherwise.
* @return Whether or not the axis is supported
*/ */
int int
libinput_tablet_tool_has_axis(struct libinput_tablet_tool *tool, libinput_tablet_tool_has_pressure(struct libinput_tablet_tool *tool);
enum libinput_tablet_tool_axis axis);
/**
* @ingroup event_tablet
*
* Return whether the tablet tool supports distance.
*
* @param tool The tool to check the axis capabilities of
* @return Nonzero if the axis is available, zero otherwise.
*/
int
libinput_tablet_tool_has_distance(struct libinput_tablet_tool *tool);
/**
* @ingroup event_tablet
*
* Return whether the tablet tool supports tilt.
*
* @param tool The tool to check the axis capabilities of
* @return Nonzero if the axis is available, zero otherwise.
*/
int
libinput_tablet_tool_has_tilt(struct libinput_tablet_tool *tool);
/**
* @ingroup event_tablet
*
* Return whether the tablet tool supports z-rotation.
*
* @param tool The tool to check the axis capabilities of
* @return Nonzero if the axis is available, zero otherwise.
*/
int
libinput_tablet_tool_has_rotation(struct libinput_tablet_tool *tool);
/**
* @ingroup event_tablet
*
* Return whether the tablet tool has a slider axis.
*
* @param tool The tool to check the axis capabilities of
* @return Nonzero if the axis is available, zero otherwise.
*/
int
libinput_tablet_tool_has_slider(struct libinput_tablet_tool *tool);
/**
* @ingroup event_tablet
*
* Return whether the tablet tool has a relative wheel.
*
* @param tool The tool to check the axis capabilities of
* @return Nonzero if the axis is available, zero otherwise.
*/
int
libinput_tablet_tool_has_wheel(struct libinput_tablet_tool *tool);
/** /**
* @ingroup event_tablet * @ingroup event_tablet

View file

@ -219,8 +219,13 @@ LIBINPUT_TABLET_SUPPORT {
libinput_tablet_tool_get_tool_id; libinput_tablet_tool_get_tool_id;
libinput_tablet_tool_get_type; libinput_tablet_tool_get_type;
libinput_tablet_tool_get_user_data; libinput_tablet_tool_get_user_data;
libinput_tablet_tool_has_pressure;
libinput_tablet_tool_has_distance;
libinput_tablet_tool_has_rotation;
libinput_tablet_tool_has_tilt;
libinput_tablet_tool_has_wheel;
libinput_tablet_tool_has_slider;
libinput_tablet_tool_has_button; libinput_tablet_tool_has_button;
libinput_tablet_tool_has_axis;
libinput_tablet_tool_ref; libinput_tablet_tool_ref;
libinput_tablet_tool_set_user_data; libinput_tablet_tool_set_user_data;
libinput_tablet_tool_unref; libinput_tablet_tool_unref;

View file

@ -722,7 +722,7 @@ START_TEST(proximity_has_axes)
litest_assert_double_ne(x, 0); litest_assert_double_ne(x, 0);
litest_assert_double_ne(y, 0); litest_assert_double_ne(y, 0);
if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) { if (libinput_tablet_tool_has_distance(tool)) {
ck_assert(libinput_event_tablet_tool_distance_has_changed( ck_assert(libinput_event_tablet_tool_distance_has_changed(
tablet_event)); tablet_event));
@ -730,8 +730,7 @@ START_TEST(proximity_has_axes)
litest_assert_double_ne(distance, 0); litest_assert_double_ne(distance, 0);
} }
if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) && if (libinput_tablet_tool_has_tilt(tool)) {
libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) {
ck_assert(libinput_event_tablet_tool_tilt_x_has_changed( ck_assert(libinput_event_tablet_tool_tilt_x_has_changed(
tablet_event)); tablet_event));
ck_assert(libinput_event_tablet_tool_tilt_y_has_changed( ck_assert(libinput_event_tablet_tool_tilt_y_has_changed(
@ -758,11 +757,10 @@ START_TEST(proximity_has_axes)
last_x = libinput_event_tablet_tool_get_x(tablet_event); last_x = libinput_event_tablet_tool_get_x(tablet_event);
last_y = libinput_event_tablet_tool_get_y(tablet_event); last_y = libinput_event_tablet_tool_get_y(tablet_event);
if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) if (libinput_tablet_tool_has_distance(tool))
last_distance = libinput_event_tablet_tool_get_distance( last_distance = libinput_event_tablet_tool_get_distance(
tablet_event); tablet_event);
if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) && if (libinput_tablet_tool_has_tilt(tool)) {
libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) {
last_tx = libinput_event_tablet_tool_get_tilt_x(tablet_event); last_tx = libinput_event_tablet_tool_get_tilt_x(tablet_event);
last_ty = libinput_event_tablet_tool_get_tilt_y(tablet_event); last_ty = libinput_event_tablet_tool_get_tilt_y(tablet_event);
} }
@ -786,7 +784,7 @@ START_TEST(proximity_has_axes)
litest_assert_double_eq(x, last_x); litest_assert_double_eq(x, last_x);
litest_assert_double_eq(y, last_y); litest_assert_double_eq(y, last_y);
if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) { if (libinput_tablet_tool_has_distance(tool)) {
ck_assert(!libinput_event_tablet_tool_distance_has_changed( ck_assert(!libinput_event_tablet_tool_distance_has_changed(
tablet_event)); tablet_event));
@ -795,8 +793,7 @@ START_TEST(proximity_has_axes)
litest_assert_double_eq(distance, last_distance); litest_assert_double_eq(distance, last_distance);
} }
if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) && if (libinput_tablet_tool_has_tilt(tool)) {
libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) {
ck_assert(!libinput_event_tablet_tool_tilt_x_has_changed( ck_assert(!libinput_event_tablet_tool_tilt_x_has_changed(
tablet_event)); tablet_event));
ck_assert(!libinput_event_tablet_tool_tilt_y_has_changed( ck_assert(!libinput_event_tablet_tool_tilt_y_has_changed(
@ -1651,14 +1648,9 @@ START_TEST(tool_capabilities)
t = libinput_event_get_tablet_tool_event(event); t = libinput_event_get_tablet_tool_event(event);
tool = libinput_event_tablet_tool_get_tool(t); tool = libinput_event_tablet_tool_get_tool(t);
ck_assert(libinput_tablet_tool_has_axis(tool, ck_assert(libinput_tablet_tool_has_pressure(tool));
LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)); ck_assert(libinput_tablet_tool_has_distance(tool));
ck_assert(libinput_tablet_tool_has_axis(tool, ck_assert(!libinput_tablet_tool_has_tilt(tool));
LIBINPUT_TABLET_TOOL_AXIS_DISTANCE));
ck_assert(!libinput_tablet_tool_has_axis(tool,
LIBINPUT_TABLET_TOOL_AXIS_TILT_X));
ck_assert(!libinput_tablet_tool_has_axis(tool,
LIBINPUT_TABLET_TOOL_AXIS_TILT_Y));
libinput_event_destroy(event); libinput_event_destroy(event);
litest_assert_empty_queue(li); litest_assert_empty_queue(li);
@ -1674,14 +1666,9 @@ START_TEST(tool_capabilities)
t = libinput_event_get_tablet_tool_event(event); t = libinput_event_get_tablet_tool_event(event);
tool = libinput_event_tablet_tool_get_tool(t); tool = libinput_event_tablet_tool_get_tool(t);
ck_assert(libinput_tablet_tool_has_axis(tool, ck_assert(libinput_tablet_tool_has_pressure(tool));
LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)); ck_assert(libinput_tablet_tool_has_distance(tool));
ck_assert(libinput_tablet_tool_has_axis(tool, ck_assert(libinput_tablet_tool_has_tilt(tool));
LIBINPUT_TABLET_TOOL_AXIS_DISTANCE));
ck_assert(libinput_tablet_tool_has_axis(tool,
LIBINPUT_TABLET_TOOL_AXIS_TILT_X));
ck_assert(libinput_tablet_tool_has_axis(tool,
LIBINPUT_TABLET_TOOL_AXIS_TILT_Y));
libinput_event_destroy(event); libinput_event_destroy(event);
litest_assert_empty_queue(li); litest_assert_empty_queue(li);
@ -1946,8 +1933,7 @@ START_TEST(mouse_wheel)
libinput_event_destroy(event); libinput_event_destroy(event);
ck_assert(libinput_tablet_tool_has_axis(tool, ck_assert(libinput_tablet_tool_has_wheel(tool));
LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL));
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
litest_event(dev, EV_REL, REL_WHEEL, -1); litest_event(dev, EV_REL, REL_WHEEL, -1);
@ -2116,8 +2102,7 @@ START_TEST(artpen_tool)
ck_assert_notnull(tool); ck_assert_notnull(tool);
ck_assert_int_eq(libinput_tablet_tool_get_type(tool), ck_assert_int_eq(libinput_tablet_tool_get_type(tool),
LIBINPUT_TABLET_TOOL_TYPE_PEN); LIBINPUT_TABLET_TOOL_TYPE_PEN);
ck_assert(libinput_tablet_tool_has_axis(tool, ck_assert(libinput_tablet_tool_has_rotation(tool));
LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z));
libinput_event_destroy(event); libinput_event_destroy(event);
} }

View file

@ -353,8 +353,7 @@ print_tablet_axes(struct libinput_event_tablet_tool *t)
y, changed_sym(t, y), y, changed_sym(t, y),
dx, dy); dx, dy);
if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) || if (libinput_tablet_tool_has_tilt(tool)) {
libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) {
x = libinput_event_tablet_tool_get_tilt_x(t); x = libinput_event_tablet_tool_get_tilt_x(t);
y = libinput_event_tablet_tool_get_tilt_y(t); y = libinput_event_tablet_tool_get_tilt_y(t);
dx = libinput_event_tablet_tool_get_axis_delta(t, dx = libinput_event_tablet_tool_get_axis_delta(t,
@ -367,8 +366,8 @@ print_tablet_axes(struct libinput_event_tablet_tool *t)
dx, dy); dx, dy);
} }
if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE) || if (libinput_tablet_tool_has_distance(tool) ||
libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) { libinput_tablet_tool_has_pressure(tool)) {
dist = libinput_event_tablet_tool_get_distance(t); dist = libinput_event_tablet_tool_get_distance(t);
pressure = libinput_event_tablet_tool_get_pressure(t); pressure = libinput_event_tablet_tool_get_pressure(t);
if (dist) { if (dist) {
@ -386,7 +385,7 @@ print_tablet_axes(struct libinput_event_tablet_tool *t)
} }
} }
if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)) { if (libinput_tablet_tool_has_rotation(tool)) {
rotation = libinput_event_tablet_tool_get_rotation(t); rotation = libinput_event_tablet_tool_get_rotation(t);
delta = libinput_event_tablet_tool_get_axis_delta(t, delta = libinput_event_tablet_tool_get_axis_delta(t,
LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z);
@ -395,7 +394,7 @@ print_tablet_axes(struct libinput_event_tablet_tool *t)
delta); delta);
} }
if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_SLIDER)) { if (libinput_tablet_tool_has_slider(tool)) {
slider = libinput_event_tablet_tool_get_slider_position(t); slider = libinput_event_tablet_tool_get_slider_position(t);
delta = libinput_event_tablet_tool_get_axis_delta(t, delta = libinput_event_tablet_tool_get_axis_delta(t,
LIBINPUT_TABLET_TOOL_AXIS_SLIDER); LIBINPUT_TABLET_TOOL_AXIS_SLIDER);
@ -404,7 +403,7 @@ print_tablet_axes(struct libinput_event_tablet_tool *t)
delta); delta);
} }
if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL)) { if (libinput_tablet_tool_has_wheel(tool)) {
wheel = libinput_event_tablet_tool_get_axis_delta(t, wheel = libinput_event_tablet_tool_get_axis_delta(t,
LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL);
delta = libinput_event_tablet_tool_get_axis_delta_discrete(t, delta = libinput_event_tablet_tool_get_axis_delta_discrete(t,
@ -490,18 +489,17 @@ print_proximity_event(struct libinput_event *ev)
state_str); state_str);
printf("\taxes:"); printf("\taxes:");
if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) if (libinput_tablet_tool_has_distance(tool))
printf("d"); printf("d");
if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) if (libinput_tablet_tool_has_pressure(tool))
printf("p"); printf("p");
if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) || if (libinput_tablet_tool_has_tilt(tool))
libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y))
printf("t"); printf("t");
if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)) if (libinput_tablet_tool_has_rotation(tool))
printf("r"); printf("r");
if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_SLIDER)) if (libinput_tablet_tool_has_slider(tool))
printf("s"); printf("s");
if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL)) if (libinput_tablet_tool_has_wheel(tool))
printf("w"); printf("w");
printf("\tbtn:"); printf("\tbtn:");