[PATCH libinput 12/15] tablet: factor out setting axis bits on a tool

Peter Hutterer peter.hutterer at who-t.net
Tue Feb 17 21:45:13 PST 2015


No functional changes.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/evdev-tablet.c | 100 +++++++++++++++++++++++++----------------------------
 1 file changed, 48 insertions(+), 52 deletions(-)

diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c
index 81cb99e..46eb665 100644
--- a/src/evdev-tablet.c
+++ b/src/evdev-tablet.c
@@ -392,6 +392,53 @@ tablet_process_misc(struct tablet_dispatch *tablet,
 	}
 }
 
+static inline void
+copy_axis_cap(const struct tablet_dispatch *tablet,
+	      struct libinput_tool *tool,
+	      enum libinput_tablet_axis axis)
+{
+	if (bit_is_set(tablet->axis_caps, axis))
+		set_bit(tool->axis_caps, axis);
+}
+
+static void
+tool_set_bits(const struct tablet_dispatch *tablet,
+	      struct libinput_tool *tool,
+	      enum libinput_tool_type type)
+{
+	/* Determine the axis capabilities of the tool. Here's a break
+	 * down of the heuristics used here:
+	 * - The Wacom art pen supports all of the extra axes, along
+	 *   with rotation
+	 * - The Wacom airbrush supports a wheel with a ~90 deg
+	 *   range.
+	 * - All of normal pens and the airbrush support all of the
+	 *   extra axes if the tablet can report them
+	 * - All of the mouse-like devices don't report any of
+	 *   the extra axes except for rotation (calculated from tilt x/y).
+	 */
+	switch (type) {
+	case LIBINPUT_TOOL_PEN:
+	case LIBINPUT_TOOL_ERASER:
+	case LIBINPUT_TOOL_PENCIL:
+	case LIBINPUT_TOOL_BRUSH:
+	case LIBINPUT_TOOL_AIRBRUSH:
+		copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_PRESSURE);
+		copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_DISTANCE);
+		copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_TILT_X);
+		copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_TILT_Y);
+		copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_ROTATION_Z);
+		copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_SLIDER);
+		break;
+	case LIBINPUT_TOOL_MOUSE:
+	case LIBINPUT_TOOL_LENS:
+		copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_ROTATION_Z);
+		break;
+	default:
+		break;
+	}
+}
+
 static struct libinput_tool *
 tablet_get_tool(struct tablet_dispatch *tablet,
 		enum libinput_tool_type type,
@@ -436,58 +483,7 @@ tablet_get_tool(struct tablet_dispatch *tablet,
 			.refcount = 1,
 		};
 
-		/* Determine the axis capabilities of the tool. Here's a break
-		 * down of the heuristics used here:
-		 * - The Wacom art pen supports all of the extra axes, along
-		 *   with rotation
-		 * - The Wacom airbrush supports a wheel with a ~90 deg
-		 *   range.
-		 * - All of normal pens and the airbrush support all of the
-		 *   extra axes if the tablet can report them
-		 * - All of the mouse-like devices don't report any of
-		 *   the extra axes except for rotation (calculated from tilt x/y).
-		 */
-		switch (type) {
-		case LIBINPUT_TOOL_PEN:
-		case LIBINPUT_TOOL_ERASER:
-		case LIBINPUT_TOOL_PENCIL:
-		case LIBINPUT_TOOL_BRUSH:
-		case LIBINPUT_TOOL_AIRBRUSH:
-			if (bit_is_set(tablet->axis_caps,
-				       LIBINPUT_TABLET_AXIS_PRESSURE))
-				set_bit(tool->axis_caps,
-					LIBINPUT_TABLET_AXIS_PRESSURE);
-			if (bit_is_set(tablet->axis_caps,
-				       LIBINPUT_TABLET_AXIS_DISTANCE))
-				set_bit(tool->axis_caps,
-					LIBINPUT_TABLET_AXIS_DISTANCE);
-			if (bit_is_set(tablet->axis_caps,
-				       LIBINPUT_TABLET_AXIS_TILT_X))
-				set_bit(tool->axis_caps,
-					LIBINPUT_TABLET_AXIS_TILT_X);
-			if (bit_is_set(tablet->axis_caps,
-				       LIBINPUT_TABLET_AXIS_TILT_Y))
-				set_bit(tool->axis_caps,
-					LIBINPUT_TABLET_AXIS_TILT_Y);
-			if (bit_is_set(tablet->axis_caps,
-				       LIBINPUT_TABLET_AXIS_ROTATION_Z))
-				set_bit(tool->axis_caps,
-					LIBINPUT_TABLET_AXIS_ROTATION_Z);
-			if (bit_is_set(tablet->axis_caps,
-				       LIBINPUT_TABLET_AXIS_SLIDER))
-				set_bit(tool->axis_caps,
-					LIBINPUT_TABLET_AXIS_SLIDER);
-			break;
-		case LIBINPUT_TOOL_MOUSE:
-		case LIBINPUT_TOOL_LENS:
-			if (bit_is_set(tablet->axis_caps,
-				       LIBINPUT_TABLET_AXIS_ROTATION_Z))
-				set_bit(tool->axis_caps,
-					LIBINPUT_TABLET_AXIS_ROTATION_Z);
-			break;
-		default:
-			break;
-		}
+		tool_set_bits(tablet, tool, type);
 
 		list_insert(tool_list, &tool->link);
 	}
-- 
2.1.0



More information about the wayland-devel mailing list