[PATCH libinput 14/26] tablet: factor out setting axis bits on a tool

Peter Hutterer peter.hutterer at who-t.net
Mon Feb 23 22:21:17 PST 2015


No functional changes.

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

diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c
index fb1253b..dfea318 100644
--- a/src/evdev-tablet.c
+++ b/src/evdev-tablet.c
@@ -351,6 +351,48 @@ 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 = tool->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);
+		break;
+	default:
+		break;
+	}
+}
+
 static struct libinput_tool *
 tablet_get_tool(struct tablet_dispatch *tablet,
 		enum libinput_tool_type type,
@@ -397,43 +439,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
-		 * - 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 really report any of
-		 *   the extra axes except for rotation.
-		 * (as of writing this comment, rotation isn't supported, so you
-		 * won't see the mouse or art pen here)
-		 */
-		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);
-			break;
-		default:
-			break;
-		}
+		tool_set_bits(tablet, tool);
 
 		list_insert(tool_list, &tool->link);
 	}
-- 
2.1.0



More information about the wayland-devel mailing list