[PATCH libinput 3/5] tablet: rename libinput_tablet_tool_has_axis into an axis-specific API set

Peter Hutterer peter.hutterer at who-t.net
Sun Dec 13 18:00:12 PST 2015


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 at who-t.net>
---
 src/libinput.c      | 41 +++++++++++++++++++++++++++++++---
 src/libinput.h      | 63 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 src/libinput.sym    |  7 +++++-
 test/tablet.c       | 43 ++++++++++++------------------------
 tools/event-debug.c | 26 ++++++++++------------
 5 files changed, 128 insertions(+), 52 deletions(-)

diff --git a/src/libinput.c b/src/libinput.c
index 27fe297..2f797dc 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 1503152..7403a76 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -1853,15 +1853,68 @@ libinput_tablet_tool_ref(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 ba4c537..da98ac5 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 7e674ed..0e2d657 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(
@@ -1659,14 +1656,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);
@@ -1682,14 +1674,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);
@@ -1954,8 +1941,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);
@@ -2124,8 +2110,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 6489546..b4e62f4 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:");
-- 
2.5.0



More information about the wayland-devel mailing list