[PATCH libinput 11/23] tablet: Report and normalize distance, pressure, and tilt axes

Stephen Chandler Paul thatslyude at gmail.com
Thu Jun 12 20:28:32 PDT 2014


Report the values for the distance, pressure, and tilt axes. Pressure is
normalized to a range of 0 to 1, and tilt is normalized to a range of -1 to 1.

Based off the patch originally written by Carlos Garnacho

Signed-off-by: Stephen Chandler Paul <thatslyude at gmail.com>
---
 src/evdev-tablet.c | 35 +++++++++++++++++++++++++++++++++++
 src/evdev-tablet.h | 15 ++++++++++++++-
 src/libinput.h     | 14 +++++++++++++-
 3 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c
index 5143759..8cb7d64 100644
--- a/src/evdev-tablet.c
+++ b/src/evdev-tablet.c
@@ -53,6 +53,10 @@ tablet_process_absolute(struct tablet_dispatch *tablet,
 	switch (e->code) {
 	case ABS_X:
 	case ABS_Y:
+	case ABS_PRESSURE:
+	case ABS_TILT_X:
+	case ABS_TILT_Y:
+	case ABS_DISTANCE:
 		axis = evcode_to_axis(e->code);
 		if (axis == LIBINPUT_TABLET_AXIS_NONE) {
 			log_bug_libinput("Invalid ABS event code %#x\n",
@@ -87,6 +91,23 @@ tablet_update_tool(struct tablet_dispatch *tablet,
 		tablet_set_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY);
 }
 
+static inline double
+normalize_pressure(const struct input_absinfo * absinfo) {
+	double range = absinfo->maximum - absinfo->minimum + 1;
+	double value = (absinfo->value + absinfo->minimum) / range;
+
+	return value;
+}
+
+static inline double
+normalize_tilt(const struct input_absinfo * absinfo) {
+	double range = absinfo->maximum - absinfo->minimum + 1;
+	double value = (absinfo->value + absinfo->minimum) / range;
+
+	/* Map to the (-1, 1) range */
+	return (value * 2) - 1;
+}
+
 static void
 tablet_notify_axes(struct tablet_dispatch *tablet,
 		   struct evdev_device *device,
@@ -103,8 +124,16 @@ tablet_notify_axes(struct tablet_dispatch *tablet,
 		switch (a) {
 		case LIBINPUT_TABLET_AXIS_X:
 		case LIBINPUT_TABLET_AXIS_Y:
+		case LIBINPUT_TABLET_AXIS_DISTANCE:
 			tablet->axes[a] = tablet->absinfo[a]->value;
 			break;
+		case LIBINPUT_TABLET_AXIS_PRESSURE:
+			tablet->axes[a] = normalize_pressure(tablet->absinfo[a]);
+			break;
+		case LIBINPUT_TABLET_AXIS_TILT_VERTICAL:
+		case LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL:
+			tablet->axes[a] = normalize_tilt(tablet->absinfo[a]);
+			break;
 		default:
 			log_bug_libinput("Invalid axis update: %d\n", a);
 			break;
@@ -169,6 +198,12 @@ tablet_process_key(struct tablet_dispatch *tablet,
 		tablet_update_tool(tablet, e->code, e->value);
 		break;
 	case BTN_TOUCH:
+		if (e->value)
+			tablet_set_status(tablet, TABLET_STYLUS_IN_CONTACT);
+		else
+			tablet_unset_status(tablet, TABLET_STYLUS_IN_CONTACT);
+
+		/* Fall through */
 	case BTN_STYLUS:
 	case BTN_STYLUS2:
 	default:
diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h
index f309173..ffcf33c 100644
--- a/src/evdev-tablet.h
+++ b/src/evdev-tablet.h
@@ -33,7 +33,8 @@ enum tablet_status {
 	TABLET_TOOL_UPDATED = 1 << 1,
 	TABLET_TOOL_LEAVING_PROXIMITY = 1 << 2,
 	TABLET_BUTTONS_PRESSED = 1 << 3,
-	TABLET_BUTTONS_RELEASED = 1 << 4
+	TABLET_BUTTONS_RELEASED = 1 << 4,
+	TABLET_STYLUS_IN_CONTACT = 1 << 5
 };
 
 struct button_state {
@@ -68,6 +69,18 @@ evcode_to_axis(const uint32_t evcode)
 	case ABS_Y:
 		axis = LIBINPUT_TABLET_AXIS_Y;
 		break;
+	case ABS_DISTANCE:
+		axis = LIBINPUT_TABLET_AXIS_DISTANCE;
+		break;
+	case ABS_PRESSURE:
+		axis = LIBINPUT_TABLET_AXIS_PRESSURE;
+		break;
+	case ABS_TILT_X:
+		axis = LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL;
+		break;
+	case ABS_TILT_Y:
+		axis = LIBINPUT_TABLET_AXIS_TILT_VERTICAL;
+		break;
 	default:
 		axis = LIBINPUT_TABLET_AXIS_NONE;
 		break;
diff --git a/src/libinput.h b/src/libinput.h
index 64f460c..8e57499 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -179,7 +179,11 @@ enum libinput_tablet_axis {
 	LIBINPUT_TABLET_AXIS_NONE = -1,
 	LIBINPUT_TABLET_AXIS_X = 0,
 	LIBINPUT_TABLET_AXIS_Y = 1,
-	LIBINPUT_TABLET_AXIS_CNT = LIBINPUT_TABLET_AXIS_Y + 1
+	LIBINPUT_TABLET_AXIS_DISTANCE = 2,
+	LIBINPUT_TABLET_AXIS_PRESSURE = 3,
+	LIBINPUT_TABLET_AXIS_TILT_VERTICAL = 4,
+	LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL = 5,
+	LIBINPUT_TABLET_AXIS_CNT = LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL + 1
 };
 
 /**
@@ -865,6 +869,14 @@ libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event,
  *   however libinput provides libinput_event_tablet_get_x_transformed() and
  *   libinput_event_tablet_get_y_transformed() for transforming each respective
  *   axis value.
+ * - @ref LIBINPUT_TABLET_AXIS_DISTANCE - Approximately how many millimeters
+ *   away from the tablet's sensor the tool is
+ * - @ref LIBINPUT_TABLET_AXIS_PRESSURE - The current pressure being applied on
+ *   the tool in use, normalized from 0 to 1
+ * - @ref LIBINPUT_TABLET_AXIS_TILT_VERTICAL and @ref
+ *   LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL - normalized value between -1 and 1
+ *   that indicates the tilt vertical or horizontal tilt of the tool
+ *   respectively
  *
  * For tablet events that are not of type @ref LIBINPUT_EVENT_TABLET_AXIS, this
  * function returns 0.
-- 
1.8.5.5



More information about the wayland-devel mailing list