[PATCH libinput 26/26] tablet: add libinput_event_tablet_get_axis_delta_discrete()

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


Equivalent to the pointer axis function - it gets the mouse wheel clicks from
the tablet mouse.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/evdev-tablet.c     |  5 ++++-
 src/libinput-private.h |  3 ++-
 src/libinput.c         | 32 +++++++++++++++++++++++++++++++-
 src/libinput.h         | 22 ++++++++++++++++++++++
 src/libinput.sym       |  1 +
 test/tablet.c          |  5 +++++
 tools/event-debug.c    |  6 +++---
 7 files changed, 68 insertions(+), 6 deletions(-)

diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c
index 2f828df..76d4bf0 100644
--- a/src/evdev-tablet.c
+++ b/src/evdev-tablet.c
@@ -317,6 +317,7 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet,
 	int a;
 	double axes[LIBINPUT_TABLET_AXIS_MAX + 1] = {0};
 	double deltas[LIBINPUT_TABLET_AXIS_MAX + 1] = {0};
+	double deltas_discrete[LIBINPUT_TABLET_AXIS_MAX + 1] = {0};
 	double oldval;
 
 	for (a = LIBINPUT_TABLET_AXIS_X; a <= LIBINPUT_TABLET_AXIS_MAX; a++) {
@@ -342,6 +343,7 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet,
 			deltas[a] = get_delta(a, tablet->axes[a], oldval);
 			continue;
 		} else if (a == LIBINPUT_TABLET_AXIS_REL_WHEEL) {
+			deltas_discrete[a] = tablet->deltas[a];
 			tablet->axes[a] = normalize_wheel(tablet,
 							  tablet->deltas[a]);
 			axes[a] = 0;
@@ -403,7 +405,8 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet,
 					   tool,
 					   tablet->changed_axes,
 					   axes,
-					   deltas);
+					   deltas,
+					   deltas_discrete);
 	}
 
 	memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes));
diff --git a/src/libinput-private.h b/src/libinput-private.h
index 3a4e4a5..1c2a329 100644
--- a/src/libinput-private.h
+++ b/src/libinput-private.h
@@ -350,7 +350,8 @@ tablet_notify_axis(struct libinput_device *device,
 		   struct libinput_tool *tool,
 		   unsigned char *changed_axes,
 		   double *axes,
-		   double *deltas);
+		   double *deltas,
+		   double *deltas_discrete);
 
 void
 tablet_notify_proximity(struct libinput_device *device,
diff --git a/src/libinput.c b/src/libinput.c
index 7127182..d693ef6 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -87,6 +87,7 @@ struct libinput_event_tablet {
 	uint32_t time;
 	double axes[LIBINPUT_TABLET_AXIS_MAX + 1];
 	double deltas[LIBINPUT_TABLET_AXIS_MAX + 1];
+	double deltas_discrete[LIBINPUT_TABLET_AXIS_MAX + 1];
 	unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_AXIS_MAX + 1)];
 	struct libinput_tool *tool;
 	enum libinput_tool_proximity_state proximity_state;
@@ -626,6 +627,31 @@ libinput_event_tablet_get_axis_delta(struct libinput_event_tablet *event,
 }
 
 LIBINPUT_EXPORT double
+libinput_event_tablet_get_axis_delta_discrete(
+				      struct libinput_event_tablet *event,
+				      enum libinput_tablet_axis axis)
+{
+	if (event->base.type != LIBINPUT_EVENT_TABLET_AXIS &&
+	    event->base.type != LIBINPUT_EVENT_TABLET_PROXIMITY)
+		return 0;
+
+	switch(axis) {
+		case LIBINPUT_TABLET_AXIS_X:
+		case LIBINPUT_TABLET_AXIS_Y:
+		case LIBINPUT_TABLET_AXIS_DISTANCE:
+		case LIBINPUT_TABLET_AXIS_PRESSURE:
+		case LIBINPUT_TABLET_AXIS_TILT_X:
+		case LIBINPUT_TABLET_AXIS_TILT_Y:
+		case LIBINPUT_TABLET_AXIS_ROTATION_Z:
+		case LIBINPUT_TABLET_AXIS_SLIDER:
+		case LIBINPUT_TABLET_AXIS_REL_WHEEL:
+			return event->deltas_discrete[axis];
+		default:
+			return 0;
+	}
+}
+
+LIBINPUT_EXPORT double
 libinput_event_tablet_get_x_transformed(struct libinput_event_tablet *event,
 					uint32_t width)
 {
@@ -1433,7 +1459,8 @@ tablet_notify_axis(struct libinput_device *device,
 		   struct libinput_tool *tool,
 		   unsigned char *changed_axes,
 		   double *axes,
-		   double *deltas)
+		   double *deltas,
+		   double *deltas_discrete)
 {
 	struct libinput_event_tablet *axis_event;
 
@@ -1451,6 +1478,9 @@ tablet_notify_axis(struct libinput_device *device,
 	       sizeof(axis_event->changed_axes));
 	memcpy(axis_event->axes, axes, sizeof(axis_event->axes));
 	memcpy(axis_event->deltas, deltas, sizeof(axis_event->deltas));
+	memcpy(axis_event->deltas_discrete,
+	       deltas_discrete,
+	       sizeof(axis_event->deltas_discrete));
 
 	post_device_event(device,
 			  time,
diff --git a/src/libinput.h b/src/libinput.h
index 1c8a0a4..3b3cf60 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -1103,6 +1103,28 @@ libinput_event_tablet_get_axis_delta(struct libinput_event_tablet *event,
 /**
  * @ingroup event_tablet
  *
+ * Return the delta for a given axis for a tablet in discrete steps.
+ * How a value translates into a discrete step depends on the axis:
+ * - @ref LIBINPUT_TABLET_AXIS_REL_WHEEL - the returned value is the number
+ * of physical mouse wheel clicks.
+ * For all other axes, this function returns 0.
+ *
+ * @note The delta is *not* the delta to the previous event, but the delta
+ * to the previous axis state, i.e. the delta to the last event that
+ * libinput_event_tablet_axis_has_changed() returned true for this axis.
+ *
+ * @param event The libinput tablet event
+ * @param axis The axis to retrieve the value of
+ * @return The delta to the previous axis value in discrete steps
+ */
+double
+libinput_event_tablet_get_axis_delta_discrete(
+				      struct libinput_event_tablet *event,
+				      enum libinput_tablet_axis axis);
+
+/**
+ * @ingroup event_tablet
+ *
  * Return the current absolute x coordinate of the tablet event, transformed to
  * screen coordinates.
  *
diff --git a/src/libinput.sym b/src/libinput.sym
index cb94d60..62ea696 100644
--- a/src/libinput.sym
+++ b/src/libinput.sym
@@ -147,6 +147,7 @@ LIBINPUT_TABLET_SUPPORT {
 	libinput_event_get_tablet_event;
 	libinput_event_tablet_axis_has_changed;
 	libinput_event_tablet_get_axis_delta;
+	libinput_event_tablet_get_axis_delta_discrete;
 	libinput_event_tablet_get_axis_value;
 	libinput_event_tablet_get_button;
 	libinput_event_tablet_get_button_state;
diff --git a/test/tablet.c b/test/tablet.c
index daf73e8..90a67dc 100644
--- a/test/tablet.c
+++ b/test/tablet.c
@@ -1385,6 +1385,11 @@ START_TEST(mouse_wheel)
 	val = libinput_event_tablet_get_axis_delta(tev,
 					LIBINPUT_TABLET_AXIS_REL_WHEEL);
 	ck_assert_int_eq(val, 15);
+
+	val = libinput_event_tablet_get_axis_delta_discrete(tev,
+					LIBINPUT_TABLET_AXIS_ROTATION_Z);
+	ck_assert_int_eq(val, -1);
+
 	libinput_event_destroy(event);
 
 	libinput_tool_unref(tool);
diff --git a/tools/event-debug.c b/tools/event-debug.c
index 7b68d96..226a70c 100644
--- a/tools/event-debug.c
+++ b/tools/event-debug.c
@@ -375,13 +375,13 @@ print_tablet_axes(struct libinput_event_tablet *t)
 	if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_REL_WHEEL)) {
 		wheel = libinput_event_tablet_get_axis_value(t,
 					LIBINPUT_TABLET_AXIS_REL_WHEEL);
-		delta = libinput_event_tablet_get_axis_delta(t,
+		delta = libinput_event_tablet_get_axis_delta_discrete(t,
 					LIBINPUT_TABLET_AXIS_REL_WHEEL);
-		printf("\twheel: %.2f%s (%.2f)",
+		printf("\twheel: %.2f%s (%d)",
 		       wheel,
 		       tablet_axis_changed_sym(t,
 				       LIBINPUT_TABLET_AXIS_REL_WHEEL),
-		       delta);
+		       (int)delta);
 	}
 }
 
-- 
2.1.0



More information about the wayland-devel mailing list