diff --git a/src/libinput.c b/src/libinput.c index 27fe297e..2f797dcb 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1359,10 +1359,45 @@ libinput_tablet_tool_get_serial(struct libinput_tablet_tool *tool) } LIBINPUT_EXPORT int -libinput_tablet_tool_has_axis(struct libinput_tablet_tool *tool, - enum libinput_tablet_tool_axis axis) +libinput_tablet_tool_has_pressure(struct libinput_tablet_tool *tool) { - 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 diff --git a/src/libinput.h b/src/libinput.h index 12a31336..01e23cb3 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1880,15 +1880,68 @@ libinput_tablet_tool_unref(struct libinput_tablet_tool *tool); /** * @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 axis The axis to check for support - * @return Whether or not the axis is supported + * @return Nonzero if the axis is available, zero otherwise. */ int -libinput_tablet_tool_has_axis(struct libinput_tablet_tool *tool, - enum libinput_tablet_tool_axis axis); +libinput_tablet_tool_has_pressure(struct libinput_tablet_tool *tool); + +/** + * @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 diff --git a/src/libinput.sym b/src/libinput.sym index ba4c537a..da98ac5c 100644 --- a/src/libinput.sym +++ b/src/libinput.sym @@ -219,8 +219,13 @@ LIBINPUT_TABLET_SUPPORT { libinput_tablet_tool_get_tool_id; libinput_tablet_tool_get_type; 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_axis; libinput_tablet_tool_ref; libinput_tablet_tool_set_user_data; libinput_tablet_tool_unref; diff --git a/test/tablet.c b/test/tablet.c index 795a14c9..bc97538d 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -722,7 +722,7 @@ START_TEST(proximity_has_axes) litest_assert_double_ne(x, 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( tablet_event)); @@ -730,8 +730,7 @@ START_TEST(proximity_has_axes) litest_assert_double_ne(distance, 0); } - 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)) { + if (libinput_tablet_tool_has_tilt(tool)) { ck_assert(libinput_event_tablet_tool_tilt_x_has_changed( tablet_event)); 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_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( tablet_event); - 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)) { + if (libinput_tablet_tool_has_tilt(tool)) { last_tx = libinput_event_tablet_tool_get_tilt_x(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(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( tablet_event)); @@ -795,8 +793,7 @@ START_TEST(proximity_has_axes) litest_assert_double_eq(distance, last_distance); } - 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)) { + if (libinput_tablet_tool_has_tilt(tool)) { ck_assert(!libinput_event_tablet_tool_tilt_x_has_changed( tablet_event)); 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); tool = libinput_event_tablet_tool_get_tool(t); - ck_assert(libinput_tablet_tool_has_axis(tool, - LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)); - ck_assert(libinput_tablet_tool_has_axis(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)); + ck_assert(libinput_tablet_tool_has_pressure(tool)); + ck_assert(libinput_tablet_tool_has_distance(tool)); + ck_assert(!libinput_tablet_tool_has_tilt(tool)); libinput_event_destroy(event); litest_assert_empty_queue(li); @@ -1674,14 +1666,9 @@ START_TEST(tool_capabilities) t = libinput_event_get_tablet_tool_event(event); tool = libinput_event_tablet_tool_get_tool(t); - ck_assert(libinput_tablet_tool_has_axis(tool, - LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)); - ck_assert(libinput_tablet_tool_has_axis(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)); + ck_assert(libinput_tablet_tool_has_pressure(tool)); + ck_assert(libinput_tablet_tool_has_distance(tool)); + ck_assert(libinput_tablet_tool_has_tilt(tool)); libinput_event_destroy(event); litest_assert_empty_queue(li); @@ -1946,8 +1933,7 @@ START_TEST(mouse_wheel) libinput_event_destroy(event); - ck_assert(libinput_tablet_tool_has_axis(tool, - LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL)); + ck_assert(libinput_tablet_tool_has_wheel(tool)); for (i = 0; i < 3; i++) { litest_event(dev, EV_REL, REL_WHEEL, -1); @@ -2116,8 +2102,7 @@ START_TEST(artpen_tool) ck_assert_notnull(tool); ck_assert_int_eq(libinput_tablet_tool_get_type(tool), LIBINPUT_TABLET_TOOL_TYPE_PEN); - ck_assert(libinput_tablet_tool_has_axis(tool, - LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)); + ck_assert(libinput_tablet_tool_has_rotation(tool)); libinput_event_destroy(event); } diff --git a/tools/event-debug.c b/tools/event-debug.c index 6489546f..b4e62f4f 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -353,8 +353,7 @@ print_tablet_axes(struct libinput_event_tablet_tool *t) y, changed_sym(t, y), dx, dy); - 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)) { + if (libinput_tablet_tool_has_tilt(tool)) { 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, @@ -367,8 +366,8 @@ print_tablet_axes(struct libinput_event_tablet_tool *t) dx, dy); } - if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE) || - libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) { + if (libinput_tablet_tool_has_distance(tool) || + libinput_tablet_tool_has_pressure(tool)) { dist = libinput_event_tablet_tool_get_distance(t); pressure = libinput_event_tablet_tool_get_pressure(t); 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); delta = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); @@ -395,7 +394,7 @@ print_tablet_axes(struct libinput_event_tablet_tool *t) 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); delta = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_SLIDER); @@ -404,7 +403,7 @@ print_tablet_axes(struct libinput_event_tablet_tool *t) 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, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); delta = libinput_event_tablet_tool_get_axis_delta_discrete(t, @@ -490,18 +489,17 @@ print_proximity_event(struct libinput_event *ev) state_str); printf("\taxes:"); - if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) + if (libinput_tablet_tool_has_distance(tool)) printf("d"); - if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) + if (libinput_tablet_tool_has_pressure(tool)) printf("p"); - 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)) + if (libinput_tablet_tool_has_tilt(tool)) printf("t"); - if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)) + if (libinput_tablet_tool_has_rotation(tool)) printf("r"); - if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_SLIDER)) + if (libinput_tablet_tool_has_slider(tool)) 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("\tbtn:");