summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac11
-rw-r--r--doc/Makefile.am1
-rw-r--r--doc/tablet-support.dox49
-rw-r--r--src/Makefile.am4
-rw-r--r--src/evdev-mt-touchpad.c1
-rw-r--r--src/evdev-tablet.c1125
-rw-r--r--src/evdev-tablet.h180
-rw-r--r--src/evdev.c23
-rw-r--r--src/evdev.h9
-rw-r--r--src/libinput-private.h40
-rw-r--r--src/libinput-util.h25
-rw-r--r--src/libinput.c389
-rw-r--r--src/libinput.h509
-rw-r--r--src/libinput.sym30
-rw-r--r--test/Makefile.am10
-rw-r--r--test/device.c39
-rw-r--r--test/litest-device-wacom-bamboo-tablet.c105
-rw-r--r--test/litest-device-wacom-cintiq-tablet.c137
-rw-r--r--test/litest-device-wacom-intuos-tablet.c141
-rw-r--r--test/litest-device-wacom-isdv4-tablet.c98
-rw-r--r--test/litest-device-waltop-tablet.c222
-rw-r--r--test/litest-int.h8
-rw-r--r--test/litest.c114
-rw-r--r--test/litest.h37
-rw-r--r--test/misc.c91
-rw-r--r--test/pointer.c8
-rw-r--r--test/tablet.c1778
-rw-r--r--test/valgrind.suppressions18
-rw-r--r--tools/event-debug.c255
-rw-r--r--tools/event-gui.c4
-rw-r--r--tools/libinput-list-devices.c3
31 files changed, 5441 insertions, 23 deletions
diff --git a/configure.ac b/configure.ac
index 6beafafe..fbba1a54 100644
--- a/configure.ac
+++ b/configure.ac
@@ -189,6 +189,16 @@ if test "x$build_tests" = "xyes"; then
AC_PATH_PROG(VALGRIND, [valgrind])
fi
+AC_ARG_ENABLE(libwacom,
+ AS_HELP_STRING([--enable-libwacom],
+ [Use libwacom for tablet identification (default=enabled)]),
+ [use_libwacom="$enableval"],
+ [use_libwacom="yes"])
+if test "x$use_libwacom" = "xyes"; then
+ PKG_CHECK_MODULES(LIBWACOM, [libwacom >= 0.12], [HAVE_LIBWACOM="yes"])
+ AC_DEFINE(HAVE_LIBWACOM, 1, [Build with libwacom])
+fi
+
AM_CONDITIONAL(HAVE_VALGRIND, [test "x$VALGRIND" != "x"])
AM_CONDITIONAL(BUILD_TESTS, [test "x$build_tests" = "xyes"])
AM_CONDITIONAL(BUILD_DOCS, [test "x$build_documentation" = "xyes"])
@@ -218,6 +228,7 @@ AC_MSG_RESULT([
Prefix ${prefix}
udev base dir ${UDEV_DIR}
+ libwacom enabled ${use_libwacom}
Build documentation ${build_documentation}
Build tests ${build_tests}
Tests use valgrind ${VALGRIND}
diff --git a/doc/Makefile.am b/doc/Makefile.am
index fe70f6a5..7a7c6cf1 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -23,6 +23,7 @@ header_files = \
$(srcdir)/scrolling.dox \
$(srcdir)/seats.dox \
$(srcdir)/t440-support.dox \
+ $(srcdir)/tablet-support.dox \
$(srcdir)/tapping.dox \
$(srcdir)/test-suite.dox \
$(srcdir)/tools.dox \
diff --git a/doc/tablet-support.dox b/doc/tablet-support.dox
new file mode 100644
index 00000000..fb8ea323
--- /dev/null
+++ b/doc/tablet-support.dox
@@ -0,0 +1,49 @@
+/**
+@page tablet-support Tablet support
+
+This page provides details about the graphics tablet
+support in libinput. Note that the term "tablet" in libinput refers to
+graphics tablets only (e.g. Wacom Intuos), not to tablet devices like the
+Apple iPad.
+
+@section fake-proximity Handling of proximity events
+
+libinput's @ref LIBINPUT_EVENT_TABLET_PROXIMITY events represent the
+physical proximity limits of the device. In some cases the caller should
+emulate proximity based on the distance events. For example, the Wacom mouse
+and lens cursor tools are usually used in relative mode, lying flat on the
+tablet. A user typically expects that lifting the tool off the tablet to a
+different location has the same effect as with a normal mouse. The proximity
+detection on Wacom tablets however extends further than the user may lift
+the mouse, i.e. the tool may not be lifted out of physical proximity.
+
+To enable normal use as a mouse it is recommended that the caller treats
+proximity separate from libinput's proximity events. There is no simple way
+to detect the proximity motion threshold, it is different on each tablet and
+differs between tools. The recommended algorithm is to remember the minimum
+distance value seen on the tool and assume a proximity out when the distance
+exceeds a threshold above this minimum value. In pseudo-code:
+
+@code
+const double threshold = ...;
+static double min;
+static bool in_proximity;
+
+double value;
+
+value = libinput_event_pointer_get_axis_value(device,
+ LIBINPUT_TABLET_AXIS_DISTANCE);
+
+if (value < min) {
+ min = value;
+ return;
+} else if (in_proximity &&
+ value > min + threshold) {
+ in_proximity = false;
+} else if (!in_proximity &&
+ value < min + threshold) {
+ in_proximity = true;
+}
+@endcode
+
+*/
diff --git a/src/Makefile.am b/src/Makefile.am
index 90bdc9a8..343e75c7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -18,6 +18,8 @@ libinput_la_SOURCES = \
evdev-mt-touchpad-buttons.c \
evdev-mt-touchpad-edge-scroll.c \
evdev-mt-touchpad-gestures.c \
+ evdev-tablet.c \
+ evdev-tablet.h \
filter.c \
filter.h \
filter-private.h \
@@ -32,12 +34,14 @@ libinput_la_SOURCES = \
libinput_la_LIBADD = $(MTDEV_LIBS) \
$(LIBUDEV_LIBS) \
$(LIBEVDEV_LIBS) \
+ $(LIBWACOM_LIBS) \
libinput-util.la
libinput_la_CFLAGS = -I$(top_srcdir)/include \
$(MTDEV_CFLAGS) \
$(LIBUDEV_CFLAGS) \
$(LIBEVDEV_CFLAGS) \
+ $(LIBWACOM_CFLAGS) \
$(GCC_CFLAGS)
EXTRA_libinput_la_DEPENDENCIES = $(srcdir)/libinput.sym
diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
index 8804658d..c90baeff 100644
--- a/src/evdev-mt-touchpad.c
+++ b/src/evdev-mt-touchpad.c
@@ -1415,6 +1415,7 @@ static struct evdev_dispatch_interface tp_interface = {
tp_interface_device_removed,
tp_interface_device_removed, /* device_suspended, treat as remove */
tp_interface_device_added, /* device_resumed, treat as add */
+ NULL, /* post_added */
};
static void
diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c
new file mode 100644
index 00000000..851d49da
--- /dev/null
+++ b/src/evdev-tablet.c
@@ -0,0 +1,1125 @@
+/*
+ * Copyright © 2014 Red Hat, Inc.
+ * Copyright © 2014 Stephen Chandler "Lyude" Paul
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission. The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+#include "config.h"
+#include "evdev-tablet.h"
+
+#include <assert.h>
+#include <stdbool.h>
+#include <string.h>
+
+#if HAVE_LIBWACOM
+#include <libwacom/libwacom.h>
+#endif
+
+#define tablet_set_status(tablet_,s_) (tablet_)->status |= (s_)
+#define tablet_unset_status(tablet_,s_) (tablet_)->status &= ~(s_)
+#define tablet_has_status(tablet_,s_) (!!((tablet_)->status & (s_)))
+
+static inline void
+tablet_get_pressed_buttons(struct tablet_dispatch *tablet,
+ unsigned char *buttons,
+ unsigned int buttons_len)
+{
+ size_t i;
+ const struct button_state *state = &tablet->button_state,
+ *prev_state = &tablet->prev_button_state;
+
+ assert(buttons_len <= ARRAY_LENGTH(state->stylus_buttons));
+
+ for (i = 0; i < buttons_len; i++)
+ buttons[i] = state->stylus_buttons[i] &
+ ~(prev_state->stylus_buttons[i]);
+}
+
+static inline void
+tablet_get_released_buttons(struct tablet_dispatch *tablet,
+ unsigned char *buttons,
+ unsigned int buttons_len)
+{
+ size_t i;
+ const struct button_state *state = &tablet->button_state,
+ *prev_state = &tablet->prev_button_state;
+
+ assert(buttons_len <= ARRAY_LENGTH(state->stylus_buttons));
+
+ for (i = 0; i < buttons_len; i++)
+ buttons[i] = prev_state->stylus_buttons[i] &
+ ~(state->stylus_buttons[i]);
+}
+
+static int
+tablet_device_has_axis(struct tablet_dispatch *tablet,
+ enum libinput_tablet_axis axis)
+{
+ struct libevdev *evdev = tablet->device->evdev;
+ bool has_axis = false;
+ unsigned int code;
+
+ if (axis == LIBINPUT_TABLET_AXIS_ROTATION_Z) {
+ has_axis = (libevdev_has_event_code(evdev,
+ EV_KEY,
+ BTN_TOOL_MOUSE) &&
+ libevdev_has_event_code(evdev,
+ EV_ABS,
+ ABS_TILT_X) &&
+ libevdev_has_event_code(evdev,
+ EV_ABS,
+ ABS_TILT_Y));
+ code = axis_to_evcode(axis);
+ has_axis |= libevdev_has_event_code(evdev,
+ EV_ABS,
+ code);
+ } else if (axis == LIBINPUT_TABLET_AXIS_REL_WHEEL) {
+ has_axis = libevdev_has_event_code(evdev,
+ EV_REL,
+ REL_WHEEL);
+ } else {
+ code = axis_to_evcode(axis);
+ has_axis = libevdev_has_event_code(evdev,
+ EV_ABS,
+ code);
+ }
+
+ return has_axis;
+}
+
+static void
+tablet_process_absolute(struct tablet_dispatch *tablet,
+ struct evdev_device *device,
+ struct input_event *e,
+ uint64_t time)
+{
+ enum libinput_tablet_axis axis;
+
+ switch (e->code) {
+ case ABS_X:
+ case ABS_Y:
+ case ABS_Z:
+ case ABS_PRESSURE:
+ case ABS_TILT_X:
+ case ABS_TILT_Y:
+ case ABS_DISTANCE:
+ case ABS_WHEEL:
+ axis = evcode_to_axis(e->code);
+ if (axis == LIBINPUT_TABLET_AXIS_NONE) {
+ log_bug_libinput(device->base.seat->libinput,
+ "Invalid ABS event code %#x\n",
+ e->code);
+ break;
+ }
+
+ set_bit(tablet->changed_axes, axis);
+ tablet_set_status(tablet, TABLET_AXES_UPDATED);
+ break;
+ /* tool_id is the identifier for the tool we can use in libwacom
+ * to identify it (if we have one anyway) */
+ case ABS_MISC:
+ tablet->current_tool_id = e->value;
+ break;
+ /* Intuos 3 strip data. Should only happen on the Pad device, not on
+ the Pen device. */
+ case ABS_RX:
+ case ABS_RY:
+ /* Only on the 4D mouse (Intuos2), obsolete */
+ case ABS_RZ:
+ /* Only on the 4D mouse (Intuos2), obsolete.
+ The 24HD sends ABS_THROTTLE on the Pad device for the second
+ wheel but we shouldn't get here on kernel >= 3.17.
+ */
+ case ABS_THROTTLE:
+ default:
+ log_info(device->base.seat->libinput,
+ "Unhandled ABS event code %#x\n", e->code);
+ break;
+ }
+}
+
+static void
+tablet_mark_all_axes_changed(struct tablet_dispatch *tablet,
+ struct evdev_device *device)
+{
+ enum libinput_tablet_axis a;
+
+ for (a = LIBINPUT_TABLET_AXIS_X; a <= LIBINPUT_TABLET_AXIS_MAX; a++) {
+ if (tablet_device_has_axis(tablet, a))
+ set_bit(tablet->changed_axes, a);
+ }
+
+ tablet_set_status(tablet, TABLET_AXES_UPDATED);
+}
+
+static void
+tablet_change_to_left_handed(struct evdev_device *device)
+{
+ struct tablet_dispatch *tablet =
+ (struct tablet_dispatch*)device->dispatch;
+
+ if (device->left_handed.enabled == device->left_handed.want_enabled)
+ return;
+
+ if (!tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY))
+ return;
+
+ device->left_handed.enabled = device->left_handed.want_enabled;
+}
+
+static void
+tablet_update_tool(struct tablet_dispatch *tablet,
+ struct evdev_device *device,
+ enum libinput_tool_type tool,
+ bool enabled)
+{
+ assert(tool != LIBINPUT_TOOL_NONE);
+
+ if (enabled) {
+ tablet->current_tool_type = tool;
+ tablet_mark_all_axes_changed(tablet, device);
+ tablet_set_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY);
+ tablet_unset_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY);
+ }
+ else if (!tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY))
+ tablet_set_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY);
+}
+
+static inline double
+normalize_pressure_dist_slider(const struct input_absinfo *absinfo)
+{
+ double range = absinfo->maximum - absinfo->minimum;
+ 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;
+ double value = (absinfo->value - absinfo->minimum) / range;
+
+ /* Map to the (-1, 1) range */
+ return (value * 2) - 1;
+}
+
+static inline int32_t
+invert_axis(const struct input_absinfo *absinfo)
+{
+ return absinfo->maximum - (absinfo->value - absinfo->minimum);
+}
+
+static void
+convert_tilt_to_rotation(struct tablet_dispatch *tablet)
+{
+ const int offset = 5;
+ double x, y;
+ double angle = 0.0;
+
+ /* Wacom Intuos 4, 5, Pro mouse calculates rotation from the x/y tilt
+ values. The device has a 175 degree CCW hardware offset but since we use
+ atan2 the effective offset is just 5 degrees.
+ */
+ x = tablet->axes[LIBINPUT_TABLET_AXIS_TILT_X];
+ y = tablet->axes[LIBINPUT_TABLET_AXIS_TILT_Y];
+ clear_bit(tablet->changed_axes, LIBINPUT_TABLET_AXIS_TILT_X);
+ clear_bit(tablet->changed_axes, LIBINPUT_TABLET_AXIS_TILT_Y);
+
+ /* atan2 is CCW, we want CW -> negate x */
+ if (x || y)
+ angle = ((180.0 * atan2(-x, y)) / M_PI);
+
+ angle = fmod(360 + angle - offset, 360);
+
+ tablet->axes[LIBINPUT_TABLET_AXIS_ROTATION_Z] = angle;
+ set_bit(tablet->changed_axes, LIBINPUT_TABLET_AXIS_ROTATION_Z);
+}
+
+static double
+convert_to_degrees(const struct input_absinfo *absinfo, double offset)
+{
+ /* range is [0, 360[, i.e. range + 1 */
+ double range = absinfo->maximum - absinfo->minimum + 1;
+ double value = (absinfo->value - absinfo->minimum) / range;
+
+ return fmod(value * 360.0 + offset, 360.0);
+}
+
+static inline double
+normalize_wheel(struct tablet_dispatch *tablet,
+ int value)
+{
+ struct evdev_device *device = tablet->device;
+
+ return value * device->scroll.wheel_click_angle;
+}
+
+static inline double
+guess_wheel_delta(double current, double old)
+{
+ double d1, d2, d3;
+
+ d1 = current - old;
+ d2 = (current + 360.0) - old;
+ d3 = current - (old + 360.0);
+
+ if (fabs(d2) < fabs(d1))
+ d1 = d2;
+
+ if (fabs(d3) < fabs(d1))
+ d1 = d3;
+
+ return d1;
+}
+
+static inline double
+get_delta(enum libinput_tablet_axis axis, double current, double old)
+{
+ double delta = 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_SLIDER:
+ case LIBINPUT_TABLET_AXIS_TILT_X:
+ case LIBINPUT_TABLET_AXIS_TILT_Y:
+ delta = current - old;
+ break;
+ case LIBINPUT_TABLET_AXIS_ROTATION_Z:
+ delta = guess_wheel_delta(current, old);
+ break;
+ default:
+ abort();
+ }
+ return delta;
+}
+
+static void
+tablet_check_notify_axes(struct tablet_dispatch *tablet,
+ struct evdev_device *device,
+ uint64_t time,
+ struct libinput_tool *tool)
+{
+ struct libinput_device *base = &device->base;
+ bool axis_update_needed = false;
+ 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++) {
+ const struct input_absinfo *absinfo;
+
+ if (!bit_is_set(tablet->changed_axes, a)) {
+ axes[a] = tablet->axes[a];
+ continue;
+ }
+
+ axis_update_needed = true;
+ oldval = tablet->axes[a];
+
+ /* ROTATION_Z is higher than TILT_X/Y so we know that the
+ tilt axes are already normalized and set */
+ if (a == LIBINPUT_TABLET_AXIS_ROTATION_Z &&
+ (tablet->current_tool_type == LIBINPUT_TOOL_MOUSE ||
+ tablet->current_tool_type == LIBINPUT_TOOL_LENS)) {
+ convert_tilt_to_rotation(tablet);
+ axes[LIBINPUT_TABLET_AXIS_TILT_X] = 0;
+ axes[LIBINPUT_TABLET_AXIS_TILT_Y] = 0;
+ axes[a] = tablet->axes[a];
+ deltas[a] = get_delta(a, tablet->axes[a], oldval);
+ continue;
+ } else if (a == LIBINPUT_TABLET_AXIS_REL_WHEEL) {
+ deltas_discrete[a] = tablet->deltas[a];
+ deltas[a] = normalize_wheel(tablet,
+ tablet->deltas[a]);
+ axes[a] = 0;
+ continue;
+ }
+
+ absinfo = libevdev_get_abs_info(device->evdev,
+ axis_to_evcode(a));
+
+ switch (a) {
+ case LIBINPUT_TABLET_AXIS_X:
+ case LIBINPUT_TABLET_AXIS_Y:
+ if (device->left_handed.enabled)
+ tablet->axes[a] = invert_axis(absinfo);
+ else
+ tablet->axes[a] = absinfo->value;
+ break;
+ case LIBINPUT_TABLET_AXIS_DISTANCE:
+ case LIBINPUT_TABLET_AXIS_PRESSURE:
+ case LIBINPUT_TABLET_AXIS_SLIDER:
+ tablet->axes[a] = normalize_pressure_dist_slider(absinfo);
+ break;
+ case LIBINPUT_TABLET_AXIS_TILT_X:
+ case LIBINPUT_TABLET_AXIS_TILT_Y:
+ tablet->axes[a] = normalize_tilt(absinfo);
+ break;
+ case LIBINPUT_TABLET_AXIS_ROTATION_Z:
+ /* artpen has 0 with buttons pointing east */
+ tablet->axes[a] = convert_to_degrees(absinfo, 90);
+ break;
+ default:
+ log_bug_libinput(device->base.seat->libinput,
+ "Invalid axis update: %d\n", a);
+ break;
+ }
+
+ axes[a] = tablet->axes[a];
+ deltas[a] = get_delta(a, tablet->axes[a], oldval);
+ }
+
+ /* We need to make sure that we check that the tool is not out of
+ * proximity before we send any axis updates. This is because many
+ * tablets will send axis events with incorrect values if the tablet
+ * tool is close enough so that the tablet can partially detect that
+ * it's there, but can't properly receive any data from the tool. */
+ if (axis_update_needed &&
+ !tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY) &&
+ !tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) {
+ if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY))
+ tablet_notify_proximity(&device->base,
+ time,
+ tool,
+ LIBINPUT_TOOL_PROXIMITY_IN,
+ tablet->changed_axes,
+ axes);
+ else
+ tablet_notify_axis(base,
+ time,
+ tool,
+ tablet->changed_axes,
+ axes,
+ deltas,
+ deltas_discrete);
+ }
+
+ memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes));
+}
+
+static void
+tablet_update_button(struct tablet_dispatch *tablet,
+ uint32_t evcode,
+ uint32_t enable)
+{
+ switch (evcode) {
+ case BTN_LEFT:
+ case BTN_RIGHT:
+ case BTN_MIDDLE:
+ case BTN_SIDE:
+ case BTN_EXTRA:
+ case BTN_FORWARD:
+ case BTN_BACK:
+ case BTN_TASK:
+ case BTN_TOUCH:
+ case BTN_STYLUS:
+ case BTN_STYLUS2:
+ break;
+ default:
+ log_info(tablet->device->base.seat->libinput,
+ "Unhandled button %s (%#x)\n",
+ libevdev_event_code_get_name(EV_KEY, evcode), evcode);
+ return;
+ }
+
+ if (enable) {
+ set_bit(tablet->button_state.stylus_buttons, evcode);
+ tablet_set_status(tablet, TABLET_BUTTONS_PRESSED);
+ } else {
+ clear_bit(tablet->button_state.stylus_buttons, evcode);
+ tablet_set_status(tablet, TABLET_BUTTONS_RELEASED);
+ }
+}
+
+static inline enum libinput_tool_type
+tablet_evcode_to_tool(int code)
+{
+ enum libinput_tool_type type;
+
+ switch (code) {
+ case BTN_TOOL_PEN: type = LIBINPUT_TOOL_PEN; break;
+ case BTN_TOOL_RUBBER: type = LIBINPUT_TOOL_ERASER; break;
+ case BTN_TOOL_BRUSH: type = LIBINPUT_TOOL_BRUSH; break;
+ case BTN_TOOL_PENCIL: type = LIBINPUT_TOOL_PENCIL; break;
+ case BTN_TOOL_AIRBRUSH: type = LIBINPUT_TOOL_AIRBRUSH; break;
+ case BTN_TOOL_FINGER: type = LIBINPUT_TOOL_FINGER; break;
+ case BTN_TOOL_MOUSE: type = LIBINPUT_TOOL_MOUSE; break;
+ case BTN_TOOL_LENS: type = LIBINPUT_TOOL_LENS; break;
+ default:
+ abort();
+ }
+
+ return type;
+}
+
+static void
+tablet_process_key(struct tablet_dispatch *tablet,
+ struct evdev_device *device,
+ struct input_event *e,
+ uint64_t time)
+{
+ switch (e->code) {
+ case BTN_TOOL_PEN:
+ case BTN_TOOL_RUBBER:
+ case BTN_TOOL_BRUSH:
+ case BTN_TOOL_PENCIL:
+ case BTN_TOOL_AIRBRUSH:
+ case BTN_TOOL_FINGER:
+ case BTN_TOOL_MOUSE:
+ case BTN_TOOL_LENS:
+ tablet_update_tool(tablet,
+ device,
+ tablet_evcode_to_tool(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_LEFT:
+ case BTN_RIGHT:
+ case BTN_MIDDLE:
+ case BTN_SIDE:
+ case BTN_EXTRA:
+ case BTN_FORWARD:
+ case BTN_BACK:
+ case BTN_TASK:
+ case BTN_STYLUS:
+ case BTN_STYLUS2:
+ default:
+ tablet_update_button(tablet, e->code, e->value);
+ break;
+ }
+}
+
+static void
+tablet_process_relative(struct tablet_dispatch *tablet,
+ struct evdev_device *device,
+ struct input_event *e,
+ uint64_t time)
+{
+ enum libinput_tablet_axis axis;
+
+ switch (e->code) {
+ case REL_WHEEL:
+ axis = rel_evcode_to_axis(e->code);
+ if (axis == LIBINPUT_TABLET_AXIS_NONE) {
+ log_bug_libinput(device->base.seat->libinput,
+ "Invalid ABS event code %#x\n",
+ e->code);
+ break;
+ }
+ set_bit(tablet->changed_axes, axis);
+ tablet->deltas[axis] = -1 * e->value;
+ tablet_set_status(tablet, TABLET_AXES_UPDATED);
+ break;
+ default:
+ log_info(tablet->device->base.seat->libinput,
+ "Unhandled relative axis %s (%#x)\n",
+ libevdev_event_code_get_name(EV_REL, e->code),
+ e->code);
+ return;
+ }
+}
+
+static void
+tablet_process_misc(struct tablet_dispatch *tablet,
+ struct evdev_device *device,
+ struct input_event *e,
+ uint64_t time)
+{
+ switch (e->code) {
+ case MSC_SERIAL:
+ if (e->value != -1)
+ tablet->current_tool_serial = e->value;
+
+ break;
+ default:
+ log_info(device->base.seat->libinput,
+ "Unhandled MSC event code %s (%#x)\n",
+ libevdev_event_code_get_name(EV_MSC, e->code),
+ e->code);
+ break;
+ }
+}
+
+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 inline void
+copy_button_cap(const struct tablet_dispatch *tablet,
+ struct libinput_tool *tool,
+ uint32_t button)
+{
+ struct libevdev *evdev = tablet->device->evdev;
+ if (libevdev_has_event_code(evdev, EV_KEY, button))
+ set_bit(tool->buttons, button);
+}
+
+static inline int
+tool_set_bits_from_libwacom(const struct tablet_dispatch *tablet,
+ struct libinput_tool *tool)
+{
+ int rc = 1;
+
+#if HAVE_LIBWACOM
+ struct libinput *libinput = tablet->device->base.seat->libinput;
+ WacomDeviceDatabase *db;
+ const WacomStylus *s = NULL;
+ int code;
+ WacomStylusType type;
+ WacomAxisTypeFlags axes;
+
+ db = libwacom_database_new();
+ if (!db) {
+ log_info(libinput,
+ "Failed to initialize libwacom context.\n");
+ goto out;
+ }
+ s = libwacom_stylus_get_for_id(db, tool->tool_id);
+ if (!s)
+ goto out;
+
+ type = libwacom_stylus_get_type(s);
+ if (type == WSTYLUS_PUCK) {
+ for (code = BTN_LEFT;
+ code < BTN_LEFT + libwacom_stylus_get_num_buttons(s);
+ code++)
+ copy_button_cap(tablet, tool, code);
+ } else {
+ if (libwacom_stylus_get_num_buttons(s) >= 2)
+ copy_button_cap(tablet, tool, BTN_STYLUS2);
+ if (libwacom_stylus_get_num_buttons(s) >= 1)
+ copy_button_cap(tablet, tool, BTN_STYLUS);
+ copy_button_cap(tablet, tool, BTN_TOUCH);
+ }
+
+ if (libwacom_stylus_has_wheel(s))
+ copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_REL_WHEEL);
+
+ axes = libwacom_stylus_get_axes(s);
+
+ if (axes & WACOM_AXIS_TYPE_TILT) {
+ /* tilt on the puck is converted to rotation */
+ if (type == WSTYLUS_PUCK) {
+ set_bit(tool->axis_caps,
+ LIBINPUT_TABLET_AXIS_ROTATION_Z);
+ } else {
+ copy_axis_cap(tablet,
+ tool,
+ LIBINPUT_TABLET_AXIS_TILT_X);
+ copy_axis_cap(tablet,
+ tool,
+ LIBINPUT_TABLET_AXIS_TILT_Y);
+ }
+ }
+ if (axes & WACOM_AXIS_TYPE_ROTATION_Z)
+ copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_ROTATION_Z);
+ if (axes & WACOM_AXIS_TYPE_DISTANCE)
+ copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_DISTANCE);
+ if (axes & WACOM_AXIS_TYPE_SLIDER)
+ copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_SLIDER);
+ if (axes & WACOM_AXIS_TYPE_PRESSURE)
+ copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_PRESSURE);
+
+ rc = 0;
+out:
+ if (db)
+ libwacom_database_destroy(db);
+#endif
+ return rc;
+}
+
+static void
+tool_set_bits(const struct tablet_dispatch *tablet,
+ struct libinput_tool *tool)
+{
+ enum libinput_tool_type type = tool->type;
+
+#if HAVE_LIBWACOM
+ if (tool_set_bits_from_libwacom(tablet, tool) == 0)
+ return;
+#endif
+ /* If we don't have libwacom, we simply copy any axis we have on the
+ tablet onto the tool. Except we know that mice only have rotation
+ anyway.
+ */
+ 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_SLIDER);
+ copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_ROTATION_Z);
+ break;
+ case LIBINPUT_TOOL_MOUSE:
+ case LIBINPUT_TOOL_LENS:
+ copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_ROTATION_Z);
+ copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_REL_WHEEL);
+ break;
+ default:
+ break;
+ }
+
+ /* If we don't have libwacom, copy all pen-related ones from the
+ tablet vs all mouse-related ones */
+ switch (type) {
+ case LIBINPUT_TOOL_PEN:
+ case LIBINPUT_TOOL_BRUSH:
+ case LIBINPUT_TOOL_AIRBRUSH:
+ case LIBINPUT_TOOL_PENCIL:
+ case LIBINPUT_TOOL_ERASER:
+ copy_button_cap(tablet, tool, BTN_STYLUS);
+ copy_button_cap(tablet, tool, BTN_STYLUS2);
+ copy_button_cap(tablet, tool, BTN_TOUCH);
+ break;
+ case LIBINPUT_TOOL_MOUSE:
+ case LIBINPUT_TOOL_LENS:
+ copy_button_cap(tablet, tool, BTN_LEFT);
+ copy_button_cap(tablet, tool, BTN_MIDDLE);
+ copy_button_cap(tablet, tool, BTN_RIGHT);
+ copy_button_cap(tablet, tool, BTN_SIDE);
+ copy_button_cap(tablet, tool, BTN_EXTRA);
+ break;
+ default:
+ break;
+ }
+}
+
+static struct libinput_tool *
+tablet_get_tool(struct tablet_dispatch *tablet,
+ enum libinput_tool_type type,
+ uint32_t tool_id,
+ uint32_t serial)
+{
+ struct libinput_tool *tool = NULL, *t;
+ struct list *tool_list;
+
+ if (serial) {
+ tool_list = &tablet->device->base.seat->libinput->tool_list;
+
+ /* Check if we already have the tool in our list of tools */
+ list_for_each(t, tool_list, link) {
+ if (type == t->type && serial == t->serial) {
+ tool = t;
+ break;
+ }
+ }
+ } else {
+ /* We can't guarantee that tools without serial numbers are
+ * unique, so we keep them local to the tablet that they come
+ * into proximity of instead of storing them in the global tool
+ * list */
+ tool_list = &tablet->tool_list;
+
+ /* Same as above, but don't bother checking the serial number */
+ list_for_each(t, tool_list, link) {
+ if (type == t->type) {
+ tool = t;
+ break;
+ }
+ }
+ }
+
+ /* If we didn't already have the new_tool in our list of tools,
+ * add it */
+ if (!tool) {
+ tool = zalloc(sizeof *tool);
+ *tool = (struct libinput_tool) {
+ .type = type,
+ .serial = serial,
+ .tool_id = tool_id,
+ .refcount = 1,
+ };
+
+ tool_set_bits(tablet, tool);
+
+ list_insert(tool_list, &tool->link);
+ }
+
+ return tool;
+}
+
+static void
+tablet_notify_button_mask(struct tablet_dispatch *tablet,
+ struct evdev_device *device,
+ uint64_t time,
+ struct libinput_tool *tool,
+ const unsigned char *buttons,
+ unsigned int buttons_len,
+ enum libinput_button_state state)
+{
+ struct libinput_device *base = &device->base;
+ size_t i;
+ size_t nbits = 8 * sizeof(buttons[0]) * buttons_len;
+
+ for (i = 0; i < nbits; i++) {
+ if (!bit_is_set(buttons, i))
+ continue;
+
+ tablet_notify_button(base,
+ time,
+ tool,
+ tablet->axes,
+ i,
+ state);
+ }
+}
+
+static void
+tablet_notify_buttons(struct tablet_dispatch *tablet,
+ struct evdev_device *device,
+ uint64_t time,
+ struct libinput_tool *tool,
+ enum libinput_button_state state)
+{
+ unsigned char buttons[ARRAY_LENGTH(tablet->button_state.stylus_buttons)];
+
+ if (state == LIBINPUT_BUTTON_STATE_PRESSED)
+ tablet_get_pressed_buttons(tablet, buttons, sizeof(buttons));
+ else
+ tablet_get_released_buttons(tablet,
+ buttons,
+ sizeof(buttons));
+
+ tablet_notify_button_mask(tablet,
+ device,
+ time,
+ tool,
+ buttons,
+ sizeof(buttons),
+ state);
+}
+
+static void
+sanitize_tablet_axes(struct tablet_dispatch *tablet)
+{
+ const struct input_absinfo *distance,
+ *pressure;
+
+ distance = libevdev_get_abs_info(tablet->device->evdev, ABS_DISTANCE);
+ pressure = libevdev_get_abs_info(tablet->device->evdev, ABS_PRESSURE);
+
+ /* Keep distance and pressure mutually exclusive */
+ if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_AXIS_DISTANCE) &&
+ distance->value > distance->minimum &&
+ pressure->value > pressure->minimum) {
+ clear_bit(tablet->changed_axes, LIBINPUT_TABLET_AXIS_DISTANCE);
+ tablet->axes[LIBINPUT_TABLET_AXIS_DISTANCE] = 0;
+ } else if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_AXIS_PRESSURE) &&
+ !tablet_has_status(tablet, TABLET_STYLUS_IN_CONTACT)) {
+ /* Make sure that the last axis value sent to the caller is a 0 */
+ if (tablet->axes[LIBINPUT_TABLET_AXIS_PRESSURE] == 0)
+ clear_bit(tablet->changed_axes,
+ LIBINPUT_TABLET_AXIS_PRESSURE);
+ else
+ tablet->axes[LIBINPUT_TABLET_AXIS_PRESSURE] = 0;
+ }
+
+ /* If we have a mouse/lens cursor and the tilt changed, the rotation
+ changed. Mark this, calculate the angle later */
+ if ((tablet->current_tool_type == LIBINPUT_TOOL_MOUSE ||
+ tablet->current_tool_type == LIBINPUT_TOOL_LENS) &&
+ (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_AXIS_TILT_X) ||
+ bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_AXIS_TILT_Y)))
+ set_bit(tablet->changed_axes, LIBINPUT_TABLET_AXIS_ROTATION_Z);
+}
+
+static void
+tablet_flush(struct tablet_dispatch *tablet,
+ struct evdev_device *device,
+ uint64_t time)
+{
+ struct libinput_tool *tool =
+ tablet_get_tool(tablet,
+ tablet->current_tool_type,
+ tablet->current_tool_id,
+ tablet->current_tool_serial);
+
+ if (tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY))
+ return;
+
+ if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) {
+ /* Release all stylus buttons */
+ memset(tablet->button_state.stylus_buttons,
+ 0,
+ sizeof(tablet->button_state.stylus_buttons));
+ tablet_set_status(tablet, TABLET_BUTTONS_RELEASED);
+ } else if (tablet_has_status(tablet, TABLET_AXES_UPDATED) ||
+ tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY)) {
+ sanitize_tablet_axes(tablet);
+ tablet_check_notify_axes(tablet, device, time, tool);
+
+ tablet_unset_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY);
+ tablet_unset_status(tablet, TABLET_AXES_UPDATED);
+ }
+
+ if (tablet_has_status(tablet, TABLET_BUTTONS_RELEASED)) {
+ tablet_notify_buttons(tablet,
+ device,
+ time,
+ tool,
+ LIBINPUT_BUTTON_STATE_RELEASED);
+ tablet_unset_status(tablet, TABLET_BUTTONS_RELEASED);
+ }
+
+ if (tablet_has_status(tablet, TABLET_BUTTONS_PRESSED)) {
+ tablet_notify_buttons(tablet,
+ device,
+ time,
+ tool,
+ LIBINPUT_BUTTON_STATE_PRESSED);
+ tablet_unset_status(tablet, TABLET_BUTTONS_PRESSED);
+ }
+
+ if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) {
+ memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes));
+ tablet_notify_proximity(&device->base,
+ time,
+ tool,
+ LIBINPUT_TOOL_PROXIMITY_OUT,
+ tablet->changed_axes,
+ tablet->axes);
+
+ tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY);
+ tablet_unset_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY);
+
+ tablet_change_to_left_handed(device);
+ }
+}
+
+static inline void
+tablet_reset_state(struct tablet_dispatch *tablet)
+{
+ /* Update state */
+ memcpy(&tablet->prev_button_state,
+ &tablet->button_state,
+ sizeof(tablet->button_state));
+}
+
+static void
+tablet_process(struct evdev_dispatch *dispatch,
+ struct evdev_device *device,
+ struct input_event *e,
+ uint64_t time)
+{
+ struct tablet_dispatch *tablet =
+ (struct tablet_dispatch *)dispatch;
+
+ switch (e->type) {
+ case EV_ABS:
+ tablet_process_absolute(tablet, device, e, time);
+ break;
+ case EV_REL:
+ tablet_process_relative(tablet, device, e, time);
+ break;
+ case EV_KEY:
+ tablet_process_key(tablet, device, e, time);
+ break;
+ case EV_MSC:
+ tablet_process_misc(tablet, device, e, time);
+ break;
+ case EV_SYN:
+ tablet_flush(tablet, device, time);
+ tablet_reset_state(tablet);
+ break;
+ default:
+ log_error(device->base.seat->libinput,
+ "Unexpected event type %s (%#x)\n",
+ libevdev_event_type_get_name(e->type),
+ e->type);
+ break;
+ }
+}
+
+static void
+tablet_destroy(struct evdev_dispatch *dispatch)
+{
+ struct tablet_dispatch *tablet =
+ (struct tablet_dispatch*)dispatch;
+ struct libinput_tool *tool, *tmp;
+
+ list_for_each_safe(tool, tmp, &tablet->tool_list, link) {
+ libinput_tool_unref(tool);
+ }
+
+ free(tablet);
+}
+
+static void
+tablet_check_initial_proximity(struct evdev_device *device,
+ struct evdev_dispatch *dispatch)
+{
+ bool tool_in_prox = false;
+ int code, state;
+ enum libinput_tool_type tool;
+ struct tablet_dispatch *tablet = (struct tablet_dispatch*)dispatch;
+
+ for (tool = LIBINPUT_TOOL_PEN; tool <= LIBINPUT_TOOL_MAX; tool++) {
+ code = tablet_tool_to_evcode(tool);
+
+ /* we only expect one tool to be in proximity at a time */
+ if (libevdev_fetch_event_value(device->evdev,
+ EV_KEY,
+ code,
+ &state) && state) {
+ tool_in_prox = true;
+ break;
+ }
+ }
+
+ if (!tool_in_prox)
+ return;
+
+ tablet_update_tool(tablet, device, tool, state);
+
+ tablet->current_tool_id =
+ libevdev_get_event_value(device->evdev,
+ EV_ABS,
+ ABS_MISC);
+ tablet->current_tool_serial =
+ libevdev_get_event_value(device->evdev,
+ EV_MSC,
+ MSC_SERIAL);
+
+ tablet_flush(tablet,
+ device,
+ libinput_now(device->base.seat->libinput));
+}
+
+static struct evdev_dispatch_interface tablet_interface = {
+ tablet_process,
+ NULL, /* suspend */
+ NULL, /* remove */
+ tablet_destroy,
+ NULL, /* device_added */
+ NULL, /* device_removed */
+ NULL, /* device_suspended */
+ NULL, /* device_resumed */
+ tablet_check_initial_proximity,
+};
+
+static int
+tablet_init(struct tablet_dispatch *tablet,
+ struct evdev_device *device)
+{
+ enum libinput_tablet_axis axis;
+
+ tablet->base.interface = &tablet_interface;
+ tablet->device = device;
+ tablet->status = TABLET_NONE;
+ tablet->current_tool_type = LIBINPUT_TOOL_NONE;
+ list_init(&tablet->tool_list);
+
+ for (axis = LIBINPUT_TABLET_AXIS_X;
+ axis <= LIBINPUT_TABLET_AXIS_MAX;
+ axis++) {
+ if (tablet_device_has_axis(tablet, axis))
+ set_bit(tablet->axis_caps, axis);
+ }
+
+ tablet_mark_all_axes_changed(tablet, device);
+
+ tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY);
+
+ return 0;
+}
+
+static void
+tablet_init_left_handed(struct evdev_device *device)
+{
+#if HAVE_LIBWACOM
+ struct libinput *libinput = device->base.seat->libinput;
+ WacomDeviceDatabase *db;
+ WacomDevice *d = NULL;
+ WacomError *error;
+ const char *devnode;
+
+ db = libwacom_database_new();
+ if (!db) {
+ log_info(libinput,
+ "Failed to initialize libwacom context.\n");
+ return;
+ }
+ error = libwacom_error_new();
+ devnode = udev_device_get_devnode(device->udev_device);
+
+ d = libwacom_new_from_path(db,
+ devnode,
+ WFALLBACK_NONE,
+ error);
+
+ if (d) {
+ if (libwacom_is_reversible(d))
+ evdev_init_left_handed(device,
+ tablet_change_to_left_handed);
+ } else if (libwacom_error_get_code(error) == WERROR_UNKNOWN_MODEL) {
+ log_info(libinput, "Tablet unknown to libwacom\n");
+ } else {
+ log_error(libinput,
+ "libwacom error: %s\n",
+ libwacom_error_get_message(error));
+ }
+
+ if (error)
+ libwacom_error_free(&error);
+ if (d)
+ libwacom_destroy(d);
+ libwacom_database_destroy(db);
+#endif
+}
+
+struct evdev_dispatch *
+evdev_tablet_create(struct evdev_device *device)
+{
+ struct tablet_dispatch *tablet;
+
+ tablet = zalloc(sizeof *tablet);
+ if (!tablet)
+ return NULL;
+
+ if (tablet_init(tablet, device) != 0) {
+ tablet_destroy(&tablet->base);
+ return NULL;
+ }
+
+ tablet_init_left_handed(device);
+
+ return &tablet->base;
+}
diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h
new file mode 100644
index 00000000..2ba08fae
--- /dev/null
+++ b/src/evdev-tablet.h
@@ -0,0 +1,180 @@
+/*
+ * Copyright © 2014 Red Hat, Inc.
+ * Copyright © 2014 Stephen Chandler "Lyude" Paul
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission. The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef EVDEV_TABLET_H
+#define EVDEV_TABLET_H
+
+#include "evdev.h"
+
+#define LIBINPUT_TABLET_AXIS_NONE 0
+#define LIBINPUT_TOOL_NONE 0
+#define LIBINPUT_TOOL_MAX LIBINPUT_TOOL_LENS
+
+enum tablet_status {
+ TABLET_NONE = 0,
+ TABLET_AXES_UPDATED = 1 << 0,
+ TABLET_BUTTONS_PRESSED = 1 << 1,
+ TABLET_BUTTONS_RELEASED = 1 << 2,
+ TABLET_STYLUS_IN_CONTACT = 1 << 3,
+ TABLET_TOOL_LEAVING_PROXIMITY = 1 << 4,
+ TABLET_TOOL_OUT_OF_PROXIMITY = 1 << 5,
+ TABLET_TOOL_ENTERING_PROXIMITY = 1 << 6
+};
+
+struct button_state {
+ unsigned char stylus_buttons[NCHARS(KEY_CNT)];
+};
+
+struct tablet_dispatch {
+ struct evdev_dispatch base;
+ struct evdev_device *device;
+ unsigned char status;
+ unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_AXIS_MAX + 1)];
+ double axes[LIBINPUT_TABLET_AXIS_MAX + 1];
+ double deltas[LIBINPUT_TABLET_AXIS_MAX + 1];
+ unsigned char axis_caps[NCHARS(LIBINPUT_TABLET_AXIS_MAX + 1)];
+
+ /* Only used for tablets that don't report serial numbers */
+ struct list tool_list;
+
+ struct button_state button_state;
+ struct button_state prev_button_state;
+
+ enum libinput_tool_type current_tool_type;
+ uint32_t current_tool_id;
+ uint32_t current_tool_serial;
+};
+
+static inline enum libinput_tablet_axis
+evcode_to_axis(const uint32_t evcode)
+{
+ enum libinput_tablet_axis axis;
+
+ switch (evcode) {
+ case ABS_X:
+ axis = LIBINPUT_TABLET_AXIS_X;
+ break;
+ case ABS_Y:
+ axis = LIBINPUT_TABLET_AXIS_Y;
+ break;
+ case ABS_Z:
+ axis = LIBINPUT_TABLET_AXIS_ROTATION_Z;
+ 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_X;
+ break;
+ case ABS_TILT_Y:
+ axis = LIBINPUT_TABLET_AXIS_TILT_Y;
+ break;
+ case ABS_WHEEL:
+ axis = LIBINPUT_TABLET_AXIS_SLIDER;
+ break;
+ default:
+ axis = LIBINPUT_TABLET_AXIS_NONE;
+ break;
+ }
+
+ return axis;
+}
+
+static inline enum libinput_tablet_axis
+rel_evcode_to_axis(const uint32_t evcode)
+{
+ enum libinput_tablet_axis axis;
+
+ switch (evcode) {
+ case REL_WHEEL:
+ axis = LIBINPUT_TABLET_AXIS_REL_WHEEL;
+ break;
+ default:
+ axis = LIBINPUT_TABLET_AXIS_NONE;
+ break;
+ }
+
+ return axis;
+}
+
+static inline uint32_t
+axis_to_evcode(const enum libinput_tablet_axis axis)
+{
+ uint32_t evcode;
+
+ switch (axis) {
+ case LIBINPUT_TABLET_AXIS_X:
+ evcode = ABS_X;
+ break;
+ case LIBINPUT_TABLET_AXIS_Y:
+ evcode = ABS_Y;
+ break;
+ case LIBINPUT_TABLET_AXIS_DISTANCE:
+ evcode = ABS_DISTANCE;
+ break;
+ case LIBINPUT_TABLET_AXIS_PRESSURE:
+ evcode = ABS_PRESSURE;
+ break;
+ case LIBINPUT_TABLET_AXIS_TILT_X:
+ evcode = ABS_TILT_X;
+ break;
+ case LIBINPUT_TABLET_AXIS_TILT_Y:
+ evcode = ABS_TILT_Y;
+ break;
+ case LIBINPUT_TABLET_AXIS_ROTATION_Z:
+ evcode = ABS_Z;
+ break;
+ case LIBINPUT_TABLET_AXIS_SLIDER:
+ evcode = ABS_WHEEL;
+ break;
+ default:
+ abort();
+ }
+
+ return evcode;
+}
+
+static inline int
+tablet_tool_to_evcode(enum libinput_tool_type type)
+{
+ int code;
+
+ switch (type) {
+ case LIBINPUT_TOOL_PEN: code = BTN_TOOL_PEN; break;
+ case LIBINPUT_TOOL_ERASER: code = BTN_TOOL_RUBBER; break;
+ case LIBINPUT_TOOL_BRUSH: code = BTN_TOOL_BRUSH; break;
+ case LIBINPUT_TOOL_PENCIL: code = BTN_TOOL_PENCIL; break;
+ case LIBINPUT_TOOL_AIRBRUSH: code = BTN_TOOL_AIRBRUSH; break;
+ case LIBINPUT_TOOL_FINGER: code = BTN_TOOL_FINGER; break;
+ case LIBINPUT_TOOL_MOUSE: code = BTN_TOOL_MOUSE; break;
+ case LIBINPUT_TOOL_LENS: code = BTN_TOOL_LENS; break;
+ default:
+ abort();
+ }
+
+ return code;
+}
+#endif
diff --git a/src/evdev.c b/src/evdev.c
index aef0456b..a3a72ef8 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -938,6 +938,7 @@ struct evdev_dispatch_interface fallback_interface = {
NULL, /* device_removed */
NULL, /* device_suspended */
NULL, /* device_resumed */
+ NULL, /* post_added */
};
static uint32_t
@@ -1959,6 +1960,7 @@ evdev_configure_device(struct evdev_device *device)
struct libevdev *evdev = device->evdev;
const char *devnode = udev_device_get_devnode(device->udev_device);
enum evdev_device_udev_tags udev_tags;
+ unsigned int tablet_tags;
udev_tags = evdev_device_get_udev_tags(device, device->udev_device);
@@ -2036,6 +2038,21 @@ evdev_configure_device(struct evdev_device *device)
}
}
+ /* libwacom assigns touchpad (or touchscreen) _and_ tablet to the
+ tablet touch bits, so make sure we don't initialize the tablet
+ interface for the touch device */
+ tablet_tags = EVDEV_UDEV_TAG_TABLET |
+ EVDEV_UDEV_TAG_TOUCHPAD |
+ EVDEV_UDEV_TAG_TOUCHSCREEN;
+ if ((udev_tags & tablet_tags) == EVDEV_UDEV_TAG_TABLET) {
+ device->dispatch = evdev_tablet_create(device);
+ device->seat_caps |= EVDEV_DEVICE_TABLET;
+ log_info(libinput,
+ "input device '%s', %s is a tablet\n",
+ device->devname, devnode);
+ return device->dispatch == NULL ? -1 : 0;
+ }
+
if (udev_tags & EVDEV_UDEV_TAG_TOUCHPAD) {
device->dispatch = evdev_mt_touchpad_create(device);
log_info(libinput,
@@ -2121,6 +2138,10 @@ evdev_notify_added_device(struct evdev_device *device)
}
notify_added_device(&device->base);
+
+ if (device->dispatch->interface->post_added)
+ device->dispatch->interface->post_added(device,
+ device->dispatch);
}
static bool
@@ -2397,6 +2418,8 @@ evdev_device_has_capability(struct evdev_device *device,
return !!(device->seat_caps & EVDEV_DEVICE_TOUCH);
case LIBINPUT_DEVICE_CAP_GESTURE:
return !!(device->seat_caps & EVDEV_DEVICE_GESTURE);
+ case LIBINPUT_DEVICE_CAP_TABLET:
+ return !!(device->seat_caps & EVDEV_DEVICE_TABLET);
default:
return 0;
}
diff --git a/src/evdev.h b/src/evdev.h
index e44a65de..1a02963b 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -60,6 +60,7 @@ enum evdev_device_seat_capability {
EVDEV_DEVICE_POINTER = (1 << 0),
EVDEV_DEVICE_KEYBOARD = (1 << 1),
EVDEV_DEVICE_TOUCH = (1 << 2),
+ EVDEV_DEVICE_TABLET = (1 << 3),
EVDEV_DEVICE_GESTURE = (1 << 5),
};
@@ -264,6 +265,11 @@ struct evdev_dispatch_interface {
/* A device was resumed */
void (*device_resumed)(struct evdev_device *device,
struct evdev_device *resumed_device);
+
+ /* Called immediately after the LIBINPUT_EVENT_DEVICE_ADDED event
+ * was sent */
+ void (*post_added)(struct evdev_device *device,
+ struct evdev_dispatch *dispatch);
};
struct evdev_dispatch {
@@ -290,6 +296,9 @@ evdev_touchpad_create(struct evdev_device *device);
struct evdev_dispatch *
evdev_mt_touchpad_create(struct evdev_device *device);
+struct evdev_dispatch *
+evdev_tablet_create(struct evdev_device *device);
+
void
evdev_tag_touchpad(struct evdev_device *device,
struct udev_device *udev_device);
diff --git a/src/libinput-private.h b/src/libinput-private.h
index e146c260..3d612221 100644
--- a/src/libinput-private.h
+++ b/src/libinput-private.h
@@ -33,6 +33,8 @@
#include "libinput.h"
#include "libinput-util.h"
+#define LIBINPUT_TABLET_AXIS_MAX LIBINPUT_TABLET_AXIS_REL_WHEEL
+
struct libinput_source;
/* A coordinate pair in device coordinates */
@@ -84,6 +86,8 @@ struct libinput {
size_t events_in;
size_t events_out;
+ struct list tool_list;
+
const struct libinput_interface *interface;
const struct libinput_interface_backend *interface_backend;
@@ -246,6 +250,17 @@ struct libinput_device {
struct libinput_device_config config;
};
+struct libinput_tool {
+ struct list link;
+ uint32_t serial;
+ uint32_t tool_id;
+ enum libinput_tool_type type;
+ unsigned char axis_caps[NCHARS(LIBINPUT_TABLET_AXIS_MAX + 1)];
+ unsigned char buttons[NCHARS(KEY_MAX) + 1];
+ int refcount;
+ void *user_data;
+};
+
struct libinput_event {
enum libinput_event_type type;
struct libinput_device *device;
@@ -444,6 +459,31 @@ void
touch_notify_frame(struct libinput_device *device,
uint64_t time);
+void
+tablet_notify_axis(struct libinput_device *device,
+ uint64_t time,
+ struct libinput_tool *tool,
+ unsigned char *changed_axes,
+ double *axes,
+ double *deltas,
+ double *deltas_discrete);
+
+void
+tablet_notify_proximity(struct libinput_device *device,
+ uint64_t time,
+ struct libinput_tool *tool,
+ enum libinput_tool_proximity_state state,
+ unsigned char *changed_axes,
+ double *axes);
+
+void
+tablet_notify_button(struct libinput_device *device,
+ uint64_t time,
+ struct libinput_tool *tool,
+ double *axes,
+ int32_t button,
+ enum libinput_button_state state);
+
static inline uint64_t
libinput_now(struct libinput *libinput)
{
diff --git a/src/libinput-util.h b/src/libinput-util.h
index ba253b57..53fe85fe 100644
--- a/src/libinput-util.h
+++ b/src/libinput-util.h
@@ -95,6 +95,8 @@ int list_empty(const struct list *list);
#define streq(s1, s2) (strcmp((s1), (s2)) == 0)
#define strneq(s1, s2, n) (strncmp((s1), (s2), (n)) == 0)
+#define NCHARS(x) ((size_t)(((x) + 7) / 8))
+
#ifdef DEBUG_TRACE
#define debug_trace(...) \
do { \
@@ -104,6 +106,7 @@ int list_empty(const struct list *list);
#else
#define debug_trace(...) { }
#endif
+
#define LIBINPUT_EXPORT __attribute__ ((visibility("default")))
static inline void *
@@ -112,6 +115,28 @@ zalloc(size_t size)
return calloc(1, size);
}
+/* This bitfield helper implementation is taken from from libevdev-util.h,
+ * except that it has been modified to work with arrays of unsigned chars
+ */
+
+static inline int
+bit_is_set(const unsigned char *array, int bit)
+{
+ return !!(array[bit / 8] & (1 << (bit % 8)));
+}
+
+static inline void
+set_bit(unsigned char *array, int bit)
+{
+ array[bit / 8] |= (1 << (bit % 8));
+}
+
+static inline void
+clear_bit(unsigned char *array, int bit)
+{
+ array[bit / 8] &= ~(1 << (bit % 8));
+}
+
static inline void
msleep(unsigned int ms)
{
diff --git a/src/libinput.c b/src/libinput.c
index f5c75b08..a51e76a9 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -125,6 +125,20 @@ struct libinput_event_gesture {
double angle;
};
+struct libinput_event_tablet {
+ struct libinput_event base;
+ uint32_t button;
+ enum libinput_button_state state;
+ uint32_t seat_button_count;
+ uint64_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;
+};
+
static void
libinput_default_log_func(struct libinput *libinput,
enum libinput_log_priority priority,
@@ -272,7 +286,6 @@ libinput_event_get_touch_event(struct libinput_event *event)
LIBINPUT_EVENT_TOUCH_MOTION,
LIBINPUT_EVENT_TOUCH_CANCEL,
LIBINPUT_EVENT_TOUCH_FRAME);
-
return (struct libinput_event_touch *) event;
}
@@ -292,6 +305,19 @@ libinput_event_get_gesture_event(struct libinput_event *event)
return (struct libinput_event_gesture *) event;
}
+LIBINPUT_EXPORT struct libinput_event_tablet *
+libinput_event_get_tablet_event(struct libinput_event *event)
+{
+ require_event_type(libinput_event_get_context(event),
+ event->type,
+ NULL,
+ LIBINPUT_EVENT_TABLET_AXIS,
+ LIBINPUT_EVENT_TABLET_PROXIMITY,
+ LIBINPUT_EVENT_TABLET_BUTTON);
+
+ return (struct libinput_event_tablet *) event;
+}
+
LIBINPUT_EXPORT struct libinput_event_device_notify *
libinput_event_get_device_notify_event(struct libinput_event *event)
{
@@ -884,6 +910,242 @@ libinput_event_gesture_get_angle_delta(struct libinput_event_gesture *event)
return event->angle;
}
+LIBINPUT_EXPORT int
+libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event,
+ enum libinput_tablet_axis axis)
+{
+ return (NCHARS(axis) <= sizeof(event->changed_axes)) ?
+ bit_is_set(event->changed_axes, axis) : 0;
+}
+
+LIBINPUT_EXPORT double
+libinput_event_tablet_get_axis_value(struct libinput_event_tablet *event,
+ enum libinput_tablet_axis axis)
+{
+ struct evdev_device *device =
+ (struct evdev_device *) event->base.device;
+
+ if (event->base.type != LIBINPUT_EVENT_TABLET_AXIS &&
+ event->base.type != LIBINPUT_EVENT_TABLET_PROXIMITY)
+ return 0;
+
+ switch(axis) {
+ case LIBINPUT_TABLET_AXIS_X:
+ return evdev_convert_to_mm(device->abs.absinfo_x,
+ event->axes[axis]);
+ case LIBINPUT_TABLET_AXIS_Y:
+ return evdev_convert_to_mm(device->abs.absinfo_y,
+ event->axes[axis]);
+ 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->axes[axis];
+ default:
+ return 0;
+ }
+}
+
+LIBINPUT_EXPORT double
+libinput_event_tablet_get_axis_delta(struct libinput_event_tablet *event,
+ enum libinput_tablet_axis axis)
+{
+ struct evdev_device *device =
+ (struct evdev_device *) event->base.device;
+
+ if (event->base.type != LIBINPUT_EVENT_TABLET_AXIS &&
+ event->base.type != LIBINPUT_EVENT_TABLET_PROXIMITY)
+ return 0;
+
+ switch(axis) {
+ case LIBINPUT_TABLET_AXIS_X:
+ return evdev_convert_to_mm(device->abs.absinfo_x,
+ event->deltas[axis]);
+ case LIBINPUT_TABLET_AXIS_Y:
+ return evdev_convert_to_mm(device->abs.absinfo_y,
+ event->deltas[axis]);
+ 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[axis];
+ default:
+ return 0;
+ }
+}
+
+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)
+{
+ struct evdev_device *device =
+ (struct evdev_device *) event->base.device;
+
+ if (event->base.type != LIBINPUT_EVENT_TABLET_AXIS)
+ return 0;
+
+ return evdev_device_transform_x(device,
+ event->axes[LIBINPUT_TABLET_AXIS_X],
+ width);
+}
+
+LIBINPUT_EXPORT double
+libinput_event_tablet_get_y_transformed(struct libinput_event_tablet *event,
+ uint32_t height)
+{
+ struct evdev_device *device =
+ (struct evdev_device *) event->base.device;
+
+ if (event->base.type != LIBINPUT_EVENT_TABLET_AXIS)
+ return 0;
+
+ return evdev_device_transform_y(device,
+ event->axes[LIBINPUT_TABLET_AXIS_Y],
+ height);
+}
+
+LIBINPUT_EXPORT struct libinput_tool *
+libinput_event_tablet_get_tool(struct libinput_event_tablet *event)
+{
+ return event->tool;
+}
+
+LIBINPUT_EXPORT enum libinput_tool_proximity_state
+libinput_event_tablet_get_proximity_state(struct libinput_event_tablet *event)
+{
+ return event->proximity_state;
+}
+
+LIBINPUT_EXPORT uint32_t
+libinput_event_tablet_get_time(struct libinput_event_tablet *event)
+{
+ return us2ms(event->time);
+}
+
+LIBINPUT_EXPORT uint64_t
+libinput_event_tablet_get_time_usec(struct libinput_event_tablet *event)
+{
+ return event->time;
+}
+
+LIBINPUT_EXPORT uint32_t
+libinput_event_tablet_get_button(struct libinput_event_tablet *event)
+{
+ return event->button;
+}
+
+LIBINPUT_EXPORT enum libinput_button_state
+libinput_event_tablet_get_button_state(struct libinput_event_tablet *event)
+{
+ return event->state;
+}
+
+LIBINPUT_EXPORT uint32_t
+libinput_event_tablet_get_seat_button_count(struct libinput_event_tablet *event)
+{
+ return event->seat_button_count;
+}
+
+LIBINPUT_EXPORT enum libinput_tool_type
+libinput_tool_get_type(struct libinput_tool *tool)
+{
+ return tool->type;
+}
+
+LIBINPUT_EXPORT uint32_t
+libinput_tool_get_tool_id(struct libinput_tool *tool)
+{
+ return tool->tool_id;
+}
+
+LIBINPUT_EXPORT uint32_t
+libinput_tool_get_serial(struct libinput_tool *tool)
+{
+ return tool->serial;
+}
+
+LIBINPUT_EXPORT int
+libinput_tool_has_axis(struct libinput_tool *tool,
+ enum libinput_tablet_axis axis)
+{
+ return bit_is_set(tool->axis_caps, axis);
+}
+
+LIBINPUT_EXPORT int
+libinput_tool_has_button(struct libinput_tool *tool,
+ uint32_t code)
+{
+ if (NCHARS(code) > sizeof(tool->buttons))
+ return 0;
+
+ return bit_is_set(tool->buttons, code);
+}
+
+LIBINPUT_EXPORT void
+libinput_tool_set_user_data(struct libinput_tool *tool,
+ void *user_data)
+{
+ tool->user_data = user_data;
+}
+
+LIBINPUT_EXPORT void *
+libinput_tool_get_user_data(struct libinput_tool *tool)
+{
+ return tool->user_data;
+}
+
+LIBINPUT_EXPORT struct libinput_tool *
+libinput_tool_ref(struct libinput_tool *tool)
+{
+ tool->refcount++;
+ return tool;
+}
+
+LIBINPUT_EXPORT struct libinput_tool *
+libinput_tool_unref(struct libinput_tool *tool)
+{
+ assert(tool->refcount > 0);
+
+ tool->refcount--;
+ if (tool->refcount > 0)
+ return tool;
+
+ list_remove(&tool->link);
+ free(tool);
+ return NULL;
+}
+
struct libinput_source *
libinput_add_fd(struct libinput *libinput,
int fd,
@@ -948,6 +1210,7 @@ libinput_init(struct libinput *libinput,
list_init(&libinput->source_destroy_list);
list_init(&libinput->seat_list);
list_init(&libinput->device_group_list);
+ list_init(&libinput->tool_list);
if (libinput_timer_subsys_init(libinput) != 0) {
free(libinput->events);
@@ -987,6 +1250,7 @@ libinput_unref(struct libinput *libinput)
struct libinput_event *event;
struct libinput_device *device, *next_device;
struct libinput_seat *seat, *next_seat;
+ struct libinput_tool *tool, *next_tool;
struct libinput_device_group *group, *next_group;
if (libinput == NULL)
@@ -1022,6 +1286,10 @@ libinput_unref(struct libinput *libinput)
libinput_device_group_destroy(group);
}
+ list_for_each_safe(tool, next_tool, &libinput->tool_list, link) {
+ libinput_tool_unref(tool);
+ }
+
libinput_timer_subsys_destroy(libinput);
libinput_drop_destroyed_sources(libinput);
close(libinput->epoll_fd);
@@ -1355,6 +1623,9 @@ device_has_cap(struct libinput_device *device,
case LIBINPUT_DEVICE_CAP_GESTURE:
capability = "CAP_GESTURE";
break;
+ case LIBINPUT_DEVICE_CAP_TABLET:
+ capability = "CAP_TABLET";
+ break;
}
log_bug_libinput(device->seat->libinput,
@@ -1611,6 +1882,109 @@ touch_notify_frame(struct libinput_device *device,
&touch_event->base);
}
+void
+tablet_notify_axis(struct libinput_device *device,
+ uint64_t time,
+ struct libinput_tool *tool,
+ unsigned char *changed_axes,
+ double *axes,
+ double *deltas,
+ double *deltas_discrete)
+{
+ struct libinput_event_tablet *axis_event;
+
+ axis_event = zalloc(sizeof *axis_event);
+ if (!axis_event)
+ return;
+
+ *axis_event = (struct libinput_event_tablet) {
+ .time = time,
+ .tool = tool,
+ };
+
+ memcpy(axis_event->changed_axes,
+ changed_axes,
+ 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,
+ LIBINPUT_EVENT_TABLET_AXIS,
+ &axis_event->base);
+}
+
+void
+tablet_notify_proximity(struct libinput_device *device,
+ uint64_t time,
+ struct libinput_tool *tool,
+ enum libinput_tool_proximity_state proximity_state,
+ unsigned char *changed_axes,
+ double *axes)
+{
+ struct libinput_event_tablet *proximity_event;
+
+ proximity_event = zalloc(sizeof *proximity_event);
+ if (!proximity_event)
+ return;
+
+ *proximity_event = (struct libinput_event_tablet) {
+ .time = time,
+ .tool = tool,
+ .proximity_state = proximity_state,
+ };
+ memcpy(proximity_event->axes,
+ axes,
+ sizeof(proximity_event->axes));
+ memcpy(proximity_event->changed_axes,
+ changed_axes,
+ sizeof(proximity_event->changed_axes));
+
+ /* deltas are always 0 on prox-in/out */
+
+ post_device_event(device,
+ time,
+ LIBINPUT_EVENT_TABLET_PROXIMITY,
+ &proximity_event->base);
+}
+
+void
+tablet_notify_button(struct libinput_device *device,
+ uint64_t time,
+ struct libinput_tool *tool,
+ double *axes,
+ int32_t button,
+ enum libinput_button_state state)
+{
+ struct libinput_event_tablet *button_event;
+ int32_t seat_button_count;
+
+ button_event = zalloc(sizeof *button_event);
+ if (!button_event)
+ return;
+
+ seat_button_count = update_seat_button_count(device->seat,
+ button,
+ state);
+
+ *button_event = (struct libinput_event_tablet) {
+ .time = time,
+ .tool = tool,
+ .button = button,
+ .state = state,
+ .seat_button_count = seat_button_count,
+ };
+ memcpy(button_event->axes, axes, sizeof(button_event->axes));
+
+ post_device_event(device,
+ time,
+ LIBINPUT_EVENT_TABLET_BUTTON,
+ &button_event->base);
+}
+
static void
gesture_notify(struct libinput_device *device,
uint64_t time,
@@ -1966,6 +2340,19 @@ libinput_event_gesture_get_base_event(struct libinput_event_gesture *event)
return &event->base;
}
+LIBINPUT_EXPORT struct libinput_event *
+libinput_event_tablet_get_base_event(struct libinput_event_tablet *event)
+{
+ require_event_type(libinput_event_get_context(&event->base),
+ event->base.type,
+ NULL,
+ LIBINPUT_EVENT_TABLET_AXIS,
+ LIBINPUT_EVENT_TABLET_PROXIMITY,
+ LIBINPUT_EVENT_TABLET_BUTTON);
+
+ return &event->base;
+}
+
LIBINPUT_EXPORT struct libinput_device_group *
libinput_device_group_ref(struct libinput_device_group *group)
{
diff --git a/src/libinput.h b/src/libinput.h
index 90574463..45a64377 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -58,6 +58,7 @@ enum libinput_device_capability {
LIBINPUT_DEVICE_CAP_KEYBOARD = 0,
LIBINPUT_DEVICE_CAP_POINTER = 1,
LIBINPUT_DEVICE_CAP_TOUCH = 2,
+ LIBINPUT_DEVICE_CAP_TABLET = 3,
LIBINPUT_DEVICE_CAP_GESTURE = 5,
};
@@ -134,6 +135,87 @@ enum libinput_pointer_axis_source {
};
/**
+ * @ingroup device
+ *
+ * Available axis types for a device. It must have the @ref
+ * LIBINPUT_DEVICE_CAP_TABLET capability.
+ */
+enum libinput_tablet_axis {
+ LIBINPUT_TABLET_AXIS_X = 1,
+ LIBINPUT_TABLET_AXIS_Y = 2,
+ LIBINPUT_TABLET_AXIS_DISTANCE = 3,
+ LIBINPUT_TABLET_AXIS_PRESSURE = 4,
+ LIBINPUT_TABLET_AXIS_TILT_X = 5,
+ LIBINPUT_TABLET_AXIS_TILT_Y = 6,
+ LIBINPUT_TABLET_AXIS_ROTATION_Z = 7,
+ LIBINPUT_TABLET_AXIS_SLIDER = 8,
+ LIBINPUT_TABLET_AXIS_REL_WHEEL = 9,
+};
+
+/**
+ * @ingroup device
+ *
+ * An object representing a tool being used by a device with the @ref
+ * LIBINPUT_DEVICE_CAP_TABLET capability.
+ *
+ * Tablet events generated by such a device are bound to a specific tool
+ * rather than coming from the device directly. Depending on the hardware it
+ * is possible to track the same physical tool across multiple
+ * struct libinput_device devices.
+ */
+struct libinput_tool;
+
+/**
+ * @ingroup device
+ *
+ * Available tool types for a device with the @ref
+ * LIBINPUT_DEVICE_CAP_TABLET capability. The tool type defines the default
+ * usage of the tool as advertised by the manufacturer. Multiple different
+ * physical tools may share the same tool type, e.g. a Wacom Classic Pen,
+ * Wacom Pro Pen and a Wacom Grip Pen are all of type @ref LIBINPUT_TOOL_PEN.
+ * Use libinput_tool_get_tool_id() to get a specific model where applicable.
+ *
+ * Note that on some device, the eraser tool is on the tail end of a pen
+ * device. On other devices, e.g. MS Surface 3, the eraser is the pen tip
+ * while a button is held down.
+ *
+ * @note The @ref libinput_tool_type can only describe the default physical
+ * type of the device. For devices with adjustible physical properties
+ * the tool type remains the same, i.e. putting a Wacom stroke nib into a
+ * classic pen leaves the tool type as @ref LIBINPUT_TOOL_PEN.
+ */
+enum libinput_tool_type {
+ LIBINPUT_TOOL_PEN = 1, /**< A generic pen */
+ LIBINPUT_TOOL_ERASER, /**< Eraser */
+ LIBINPUT_TOOL_BRUSH, /**< A paintbrush-like tool */
+ LIBINPUT_TOOL_PENCIL, /**< Physical drawing tool, e.g.
+ Wacom Inking Pen */
+ LIBINPUT_TOOL_AIRBRUSH, /**< An airbrush-like tool */
+ LIBINPUT_TOOL_FINGER, /**< Touch */
+ LIBINPUT_TOOL_MOUSE, /**< A mouse bound to the tablet */
+ LIBINPUT_TOOL_LENS, /**< A mouse tool with a lens */
+};
+
+/**
+ * @ingroup device
+ *
+ * The state of proximity for a tool on a device. The device must have the @ref
+ * LIBINPUT_DEVICE_CAP_TABLET capability.
+ *
+ * The proximity of a tool is a binary state signalling whether the tool is
+ * within detectable distance of the tablet device. A tool that is out of
+ * proximity cannot generate events.
+ *
+ * On some hardware a tool goes out of proximity when it ceases to touch the
+ * surface. On other hardware, the tool is still detectable within a short
+ * distance (a few cm) off the surface.
+ */
+enum libinput_tool_proximity_state {
+ LIBINPUT_TOOL_PROXIMITY_OUT = 0,
+ LIBINPUT_TOOL_PROXIMITY_IN = 1,
+};
+
+/**
* @ingroup base
*
* Event type for events returned by libinput_get_event().
@@ -179,6 +261,40 @@ enum libinput_event_type {
*/
LIBINPUT_EVENT_TOUCH_FRAME,
+ /**
+ * One or more axes have changed state on a device with the @ref
+ * LIBINPUT_DEVICE_CAP_TABLET capability. This event is only sent
+ * when the tool is in proximity, see @ref
+ * LIBINPUT_EVENT_TABLET_PROXIMITY for details.
+ */
+ LIBINPUT_EVENT_TABLET_AXIS = 600,
+ /**
+ * Signals that a tool has come in or out of proximity of a device with
+ * the @ref LIBINPUT_DEVICE_CAP_TABLET capability.
+ *
+ * Proximity events contain each of the current values for each axis,
+ * and these values may be extracted from them in the same way they are
+ * with @ref LIBINPUT_EVENT_TABLET_AXIS events.
+ *
+ * Some tools may always be in proximity. For these tools, events of
+ * type @ref LIBINPUT_TOOL_PROXIMITY_IN are sent only once after @ref
+ * LIBINPUT_EVENT_DEVICE_ADDED, and events of type @ref
+ * LIBINPUT_TOOL_PROXIMITY_OUT are sent only once before @ref
+ * LIBINPUT_EVENT_DEVICE_REMOVED.
+ *
+ * If the tool that comes into proximity supports x/y coordinates,
+ * libinput guarantees that both x and y are set in the proximity
+ * event.
+ *
+ * When a tool goes out of proximity, the value of every axis should be
+ * assumed to have an undefined state and any buttons that are currently held
+ * down on the stylus are marked as released. Button release events for
+ * each button that was held down on the stylus are sent before the
+ * proximity out event.
+ */
+ LIBINPUT_EVENT_TABLET_PROXIMITY,
+ LIBINPUT_EVENT_TABLET_BUTTON,
+
LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN = 800,
LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE,
LIBINPUT_EVENT_GESTURE_SWIPE_END,
@@ -274,6 +390,16 @@ struct libinput_event_pointer;
struct libinput_event_touch;
/**
+ * @ingroup event_tablet
+ * @struct libinput_event_tablet
+ *
+ * Tablet event representing an axis update, button press, or tool update. Valid
+ * event types for this event are @ref LIBINPUT_EVENT_TABLET_AXIS, @ref
+ * LIBINPUT_EVENT_TABLET_PROXIMITY and @ref LIBINPUT_EVENT_TABLET_BUTTON.
+ */
+struct libinput_event_tablet;
+
+/**
* @defgroup event Accessing and destruction of events
*/
@@ -369,8 +495,6 @@ struct libinput_event_touch *
libinput_event_get_touch_event(struct libinput_event *event);
/**
- * @ingroup event
- *
* Return the gesture event that is this input event. If the event type does
* not match the gesture event types, this function returns NULL.
*
@@ -384,6 +508,19 @@ libinput_event_get_gesture_event(struct libinput_event *event);
/**
* @ingroup event
*
+ * Return the tablet event that is this input event. If the event type does not
+ * match the tablet event types, this function returns NULL.
+ *
+ * The inverse of this function is libinput_event_tablet_get_base_event().
+ *
+ * @return A tablet event, or NULL for other events
+ */
+struct libinput_event_tablet *
+libinput_event_get_tablet_event(struct libinput_event *event);
+
+/**
+ * @ingroup event
+ *
* Return the device event that is this input event. If the event type does
* not match the device event types, this function returns NULL.
*
@@ -1170,6 +1307,374 @@ double
libinput_event_gesture_get_angle_delta(struct libinput_event_gesture *event);
/**
+ * @defgroup event_tablet Tablet events
+ *
+ * Events that come from tablet devices.
+ */
+
+/**
+ * @ingroup event_tablet
+ *
+ * @return The generic libinput_event of this event
+ */
+struct libinput_event *
+libinput_event_tablet_get_base_event(struct libinput_event_tablet *event);
+
+/**
+ * @ingroup event_tablet
+ *
+ * Checks if an axis was updated in this event or return 0 otherwise.
+ * For tablet events that are not of type @ref LIBINPUT_EVENT_TABLET_AXIS or
+ * type @ref LIBINPUT_EVENT_TABLET_PROXIMITY, this function returns 0.
+ *
+ * @note It is an application bug to call this function for events other than
+ * @ref LIBINPUT_EVENT_TABLET_AXIS and @ref LIBINPUT_EVENT_TABLET_PROXIMITY.
+ *
+ * @param event The libinput tablet event
+ * @param axis The axis to check for updates
+ * @return 1 if the axis was updated or 0 otherwise
+ */
+int
+libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event,
+ enum libinput_tablet_axis axis);
+
+/**
+ * @ingroup event_tablet
+ *
+ * Return the axis value of a given axis for a tablet. The interpretation of the
+ * value is dependent on the axis:
+ * - @ref LIBINPUT_TABLET_AXIS_X and @ref LIBINPUT_TABLET_AXIS_Y - the X and
+ * Y coordinates of the tablet tool, in mm from the top left corner of the
+ * tablet. Use libinput_event_tablet_get_x_transformed() and
+ * libinput_event_tablet_get_y_transformed() for transforming each
+ * respective axis value into a different coordinate space.
+ * - @ref LIBINPUT_TABLET_AXIS_DISTANCE - The distance from the tablet's
+ * sensor, normalized from 0 to 1
+ * - @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_X and @ref LIBINPUT_TABLET_AXIS_TILT_Y -
+ * normalized value between -1 and 1 that indicates the X or Y tilt of the
+ * tool
+ * - @ref LIBINPUT_TABLET_AXIS_ROTATION_Z - The z rotation of the tool in
+ * degrees, clockwise from the tool's logical neutral position. For the
+ * @ref LIBINPUT_TOOL_MOUSE and @ref LIBINPUT_TOOL_LENS tools the logical
+ * neutral position is pointing to the current logical north of the
+ * tablet. For the @ref LIBINPUT_TOOL_BRUSH tool, the logical neutral
+ * position is with the buttons pointing up.
+ * - @ref LIBINPUT_TABLET_AXIS_SLIDER - A slider on the tool, normalized
+ * from 0 to 1. e.g. the wheel-like tool on the Wacom Airbrush.
+ * - @ref LIBINPUT_TABLET_AXIS_REL_WHEEL - A relative wheel on the tool,
+ * similar or equivalent to a mouse wheel. The value is always 0, use
+ * libinput_event_tablet_get_axis_delta() instead.
+ *
+ * @note This function may be called for a specific axis even if
+ * libinput_event_tablet_axis_has_changed() returns 0 for that axis.
+ * libinput always includes all device axes in the event.
+ *
+ * If the event is of type @ref LIBINPUT_EVENT_TABLET_PROXIMITY and the
+ * event is a proximity out event, the value returned is the last known
+ * value of the tool before it left proximity.
+ *
+ * @param event The libinput tablet event
+ * @param axis The axis to retrieve the value of
+ * @return The current value of the the axis
+ */
+double
+libinput_event_tablet_get_axis_value(struct libinput_event_tablet *event,
+ enum libinput_tablet_axis axis);
+
+/**
+ * @ingroup event_tablet
+ *
+ * Return the delta for a given axis for a tablet. The interpretation of the
+ * value is axis-dependent:
+ * - @ref LIBINPUT_TABLET_AXIS_REL_WHEEL - A relative wheel on the tool,
+ * similar or equivalent to a mouse wheel. The value is a delta from the
+ * device's previous position, in degrees.
+ * For all other axes, see libinput_event_tablet_get_axis_value() for
+ * details.
+ *
+ * @param event The libinput tablet event
+ * @param axis The axis to retrieve the value of
+ * @return The delta to the previous axis value
+ */
+double
+libinput_event_tablet_get_axis_delta(struct libinput_event_tablet *event,
+ enum libinput_tablet_axis axis);
+
+/**
+ * @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.
+ *
+ * @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.
+ *
+ * @note This function may be called for a specific axis even if
+ * libinput_event_tablet_axis_has_changed() returns 0 for that axis.
+ * libinput always includes all device axes in the event.
+ *
+ * @param event The libinput tablet event
+ * @param width The current output screen width
+ * @return the current absolute x coordinate transformed to a screen coordinate
+ */
+double
+libinput_event_tablet_get_x_transformed(struct libinput_event_tablet *event,
+ uint32_t width);
+
+/**
+ * @ingroup event_tablet
+ *
+ * Return the current absolute y coordinate of the tablet event, transformed to
+ * screen coordinates.
+ *
+ * @note This function may be called for a specific axis even if
+ * libinput_event_tablet_axis_has_changed() returns 0 for that axis.
+ * libinput always includes all device axes in the event.
+ *
+ * @param event The libinput tablet event
+ * @param height The current output screen height
+ * @return the current absolute y coordinate transformed to a screen coordinate
+ */
+double
+libinput_event_tablet_get_y_transformed(struct libinput_event_tablet *event,
+ uint32_t height);
+
+/**
+ * @ingroup event_tablet
+ *
+ * Returns the tool that was in use during this event.
+ * By default, each tool will stay valid for as long as it is being used, and is
+ * destroyed when another tool comes into proximity. However, the lifetime of
+ * the tool may be extended by using libinput_tool_ref() to increment the
+ * reference count of the tool. This guarantees that whenever the tool comes
+ * back into proximity of the tablet, that the same structure will be used to
+ * represent the tool.
+ *
+ * @note On tablets where the serial number of tools is not reported, each tool
+ * cannot be guaranteed to be unique.
+ *
+ * @param event The libinput tablet event
+ * @return The new tool triggering this event
+ */
+struct libinput_tool *
+libinput_event_tablet_get_tool(struct libinput_event_tablet *event);
+
+/**
+ * @ingroup event_tablet
+ *
+ * Returns the new proximity state of a tool from a proximity event.
+ * Used to check whether or not a tool came in or out of proximity during an
+ * event of type @ref LIBINPUT_EVENT_TABLET_PROXIMITY.
+ *
+ * See @ref fake-proximity for recommendations on proximity handling.
+ *
+ * @param event The libinput tablet event
+ * @return The new proximity state of the tool from the event.
+ */
+enum libinput_tool_proximity_state
+libinput_event_tablet_get_proximity_state(struct libinput_event_tablet *event);
+
+/**
+ * @ingroup event_tablet
+ *
+ * Return the button that triggered this event.
+ * For tablet events that are not of type @ref LIBINPUT_EVENT_TABLET_BUTTON, this
+ * function returns 0.
+ *
+ * @note It is an application bug to call this function for events other than
+ * @ref LIBINPUT_EVENT_TABLET_BUTTON.
+ *
+ * @param event The libinput tablet event
+ * @return the button triggering this event
+ */
+uint32_t
+libinput_event_tablet_get_button(struct libinput_event_tablet *event);
+
+/**
+ * @ingroup event_tablet
+ *
+ * Return the button state of the event.
+ *
+ * @note It is an application bug to call this function for events other than
+ * @ref LIBINPUT_EVENT_TABLET_BUTTON.
+ *
+ * @param event The libinput tablet event
+ * @return the button state triggering this event
+ */
+enum libinput_button_state
+libinput_event_tablet_get_button_state(struct libinput_event_tablet *event);
+
+/**
+ * @ingroup event_tablet
+ *
+ * For the button of a @ref LIBINPUT_EVENT_TABLET_BUTTON event, return the total
+ * number of buttons pressed on all devices on the associated seat after the
+ * the event was triggered.
+ *
+ " @note It is an application bug to call this function for events other than
+ * @ref LIBINPUT_EVENT_TABLET_BUTTON. For other events, this function returns 0.
+ *
+ * @return the seat wide pressed button count for the key of this event
+ */
+uint32_t
+libinput_event_tablet_get_seat_button_count(struct libinput_event_tablet *event);
+
+/**
+ * @ingroup event_tablet
+ *
+ * @param event The libinput tablet event
+ * @return The event time for this event
+ */
+uint32_t
+libinput_event_tablet_get_time(struct libinput_event_tablet *event);
+
+/**
+ * @ingroup event_tablet
+ *
+ * @param event The libinput tablet event
+ * @return The event time for this event in microseconds
+ */
+uint64_t
+libinput_event_tablet_get_time_usec(struct libinput_event_tablet *event);
+
+/**
+ * @ingroup event_tablet
+ *
+ * Return the type of tool type for a tool object
+ *
+ * @param tool The libinput tool
+ * @return The tool type for this tool object
+ *
+ * @see libinput_tool_get_tool_id
+ */
+enum libinput_tool_type
+libinput_tool_get_type(struct libinput_tool *tool);
+
+/**
+ * @ingroup event_tablet
+ *
+ * Return the tool ID for a tool object. If nonzero, this number identifies
+ * the specific type of the tool with more precision than the type returned in
+ * libinput_tool_get_type(). Not all tablets support a tool ID.
+ *
+ * Tablets known to support tool IDs include the Wacom Intuos 3, 4, 5, Wacom
+ * Cintiq and Wacom Intuos Pro series.
+ *
+ * @param tool The libinput tool
+ * @return The tool ID for this tool object or 0 if none is provided
+ *
+ * @see libinput_tool_get_type
+ */
+uint32_t
+libinput_tool_get_tool_id(struct libinput_tool *tool);
+
+/**
+ * @ingroup event_tablet
+ *
+ * Increment the ref count of tool by one
+ *
+ * @param tool The tool to increment the ref count of
+ * @return The passed tool
+ */
+struct libinput_tool *
+libinput_tool_ref(struct libinput_tool *tool);
+
+/**
+ * @ingroup event_tablet
+ *
+ * Return whether or not a tablet tool supports the specified axis
+ *
+ * @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
+ */
+int
+libinput_tool_has_axis(struct libinput_tool *tool,
+ enum libinput_tablet_axis axis);
+
+/**
+ * @ingroup event_tablet
+ *
+ * Check if a tablet tool has a button with the
+ * passed-in code (see linux/input.h).
+ *
+ * @param tool A tablet tool
+ * @param code button code to check for
+ *
+ * @return 1 if the tool supports this button code, 0 if it does not
+ */
+int
+libinput_tool_has_button(struct libinput_tool *tool,
+ uint32_t code);
+
+/**
+ * @ingroup event_tablet
+ *
+ * Decrement the ref count of tool by one. When the ref count of tool reaches 0,
+ * the memory allocated for tool will be freed.
+ *
+ * @param tool The tool to decrement the ref count of
+ * @return NULL if the tool was destroyed otherwise the passed tool
+ */
+struct libinput_tool *
+libinput_tool_unref(struct libinput_tool *tool);
+
+/**
+ * @ingroup event_tablet
+ *
+ * Return the serial number of a tool
+ *
+ * @note Not all tablets report a serial number along with the type of tool
+ * being used. If the hardware does not provide a unique serial number, the
+ * serial number is always 0.
+ *
+ * @param tool The libinput tool
+ * @return The new tool serial triggering this event
+ */
+uint32_t
+libinput_tool_get_serial(struct libinput_tool *tool);
+
+/**
+ * @ingroup event_tablet
+ *
+ * Return the user data associated with a tool object.
+ *
+ * @param tool The libinput tool
+ * @return The user data associated with the tool object
+ */
+void *
+libinput_tool_get_user_data(struct libinput_tool *tool);
+
+/**
+ * @ingroup event_tablet
+ *
+ * Set the user data associated with a tool object.
+ *
+ * @param tool The libinput tool
+ * @param user_data The user data to associate with the tool object
+ */
+void
+libinput_tool_set_user_data(struct libinput_tool *tool,
+ void *user_data);
+
+/**
* @defgroup base Initialization and manipulation of libinput contexts
*/
diff --git a/src/libinput.sym b/src/libinput.sym
index 15203c8d..1c297c7f 100644
--- a/src/libinput.sym
+++ b/src/libinput.sym
@@ -124,6 +124,7 @@ global:
libinput_udev_assign_seat;
libinput_udev_create_context;
libinput_unref;
+
local:
*;
};
@@ -179,3 +180,32 @@ LIBINPUT_1.1 {
libinput_device_config_accel_get_default_profile;
libinput_device_config_accel_set_profile;
} LIBINPUT_0.21.0;
+
+/* tablet APIs, they are not part of any stable API promise yet.
+ * keep them separate */
+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_base_event;
+ libinput_event_tablet_get_button;
+ libinput_event_tablet_get_button_state;
+ libinput_event_tablet_get_proximity_state;
+ libinput_event_tablet_get_seat_button_count;
+ libinput_event_tablet_get_time;
+ libinput_event_tablet_get_tool;
+ libinput_event_tablet_get_x_transformed;
+ libinput_event_tablet_get_y_transformed;
+ libinput_event_tablet_get_time_usec;
+ libinput_tool_get_serial;
+ libinput_tool_get_tool_id;
+ libinput_tool_get_type;
+ libinput_tool_get_user_data;
+ libinput_tool_has_button;
+ libinput_tool_has_axis;
+ libinput_tool_ref;
+ libinput_tool_set_user_data;
+ libinput_tool_unref;
+} LIBINPUT_1.1;
diff --git a/test/Makefile.am b/test/Makefile.am
index cde93b36..70a5302f 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -37,8 +37,13 @@ liblitest_la_SOURCES = \
litest-device-synaptics-x1-carbon-3rd.c \
litest-device-trackpoint.c \
litest-device-touch-screen.c \
+ litest-device-wacom-bamboo-tablet.c \
+ litest-device-wacom-cintiq-tablet.c \
+ litest-device-wacom-intuos-tablet.c \
+ litest-device-wacom-isdv4-tablet.c \
litest-device-wacom-touch.c \
litest-device-wacom-intuos-finger.c \
+ litest-device-waltop-tablet.c \
litest-device-wheel-only.c \
litest-device-xen-virtual-pointer.c \
litest-device-vmware-virtual-usb-mouse.c \
@@ -57,6 +62,7 @@ run_tests = \
test-touchpad \
test-touchpad-tap \
test-touchpad-buttons \
+ test-tablet \
test-device \
test-gestures \
test-pointer \
@@ -101,6 +107,10 @@ test_log_SOURCES = log.c
test_log_LDADD = $(TEST_LIBS)
test_log_LDFLAGS = -no-install
+test_tablet_SOURCES = tablet.c
+test_tablet_LDADD = $(TEST_LIBS)
+test_tablet_LDFLAGS = -static
+
test_touchpad_SOURCES = touchpad.c
test_touchpad_LDADD = $(TEST_LIBS)
test_touchpad_LDFLAGS = -no-install
diff --git a/test/device.c b/test/device.c
index b7fa0e07..b829af73 100644
--- a/test/device.c
+++ b/test/device.c
@@ -1104,6 +1104,22 @@ START_TEST(device_udev_tag_synaptics_serial)
}
END_TEST
+START_TEST(device_udev_tag_wacom_tablet)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput_device *device = dev->libinput_device;
+ struct udev_device *d;
+ const char *prop;
+
+ d = libinput_device_get_udev_device(device);
+ prop = udev_device_get_property_value(d,
+ "ID_INPUT_TABLET");
+
+ ck_assert_notnull(prop);
+ udev_device_unref(d);
+}
+END_TEST
+
START_TEST(device_nonpointer_rel)
{
struct libevdev_uinput *uinput;
@@ -1260,16 +1276,16 @@ litest_setup_tests(void)
struct range abs_range = { 0, ABS_MISC };
struct range abs_mt_range = { ABS_MT_SLOT + 1, ABS_CNT };
- litest_add("device:sendevents", device_sendevents_config, LITEST_ANY, LITEST_TOUCHPAD);
- litest_add("device:sendevents", device_sendevents_config_invalid, LITEST_ANY, LITEST_ANY);
- litest_add("device:sendevents", device_sendevents_config_touchpad, LITEST_TOUCHPAD, LITEST_ANY);
- litest_add("device:sendevents", device_sendevents_config_touchpad_superset, LITEST_TOUCHPAD, LITEST_ANY);
- litest_add("device:sendevents", device_sendevents_config_default, LITEST_ANY, LITEST_ANY);
- litest_add("device:sendevents", device_disable, LITEST_RELATIVE, LITEST_ANY);
- litest_add("device:sendevents", device_disable_touchpad, LITEST_TOUCHPAD, LITEST_ANY);
- litest_add("device:sendevents", device_disable_events_pending, LITEST_RELATIVE, LITEST_TOUCHPAD);
- litest_add("device:sendevents", device_double_disable, LITEST_ANY, LITEST_ANY);
- litest_add("device:sendevents", device_double_enable, LITEST_ANY, LITEST_ANY);
+ litest_add("device:sendevents", device_sendevents_config, LITEST_ANY, LITEST_TOUCHPAD|LITEST_TABLET);
+ litest_add("device:sendevents", device_sendevents_config_invalid, LITEST_ANY, LITEST_TABLET);
+ litest_add("device:sendevents", device_sendevents_config_touchpad, LITEST_TOUCHPAD, LITEST_TABLET);
+ litest_add("device:sendevents", device_sendevents_config_touchpad_superset, LITEST_TOUCHPAD, LITEST_TABLET);
+ litest_add("device:sendevents", device_sendevents_config_default, LITEST_ANY, LITEST_TABLET);
+ litest_add("device:sendevents", device_disable, LITEST_RELATIVE, LITEST_TABLET);
+ litest_add("device:sendevents", device_disable_touchpad, LITEST_TOUCHPAD, LITEST_TABLET);
+ litest_add("device:sendevents", device_disable_events_pending, LITEST_RELATIVE, LITEST_TOUCHPAD|LITEST_TABLET);
+ litest_add("device:sendevents", device_double_disable, LITEST_ANY, LITEST_TABLET);
+ litest_add("device:sendevents", device_double_enable, LITEST_ANY, LITEST_TABLET);
litest_add_no_device("device:sendevents", device_reenable_syspath_changed);
litest_add_no_device("device:sendevents", device_reenable_device_removed);
litest_add_for_device("device:sendevents", device_disable_release_buttons, LITEST_MOUSE);
@@ -1296,13 +1312,14 @@ litest_setup_tests(void)
litest_add_no_device("device:invalid devices", abs_device_missing_res);
litest_add_no_device("device:invalid devices", abs_mt_device_missing_res);
- litest_add("device:wheel", device_wheel_only, LITEST_WHEEL, LITEST_RELATIVE|LITEST_ABSOLUTE);
+ litest_add("device:wheel", device_wheel_only, LITEST_WHEEL, LITEST_RELATIVE|LITEST_ABSOLUTE|LITEST_TABLET);
litest_add_no_device("device:accelerometer", device_accelerometer);
litest_add("device:udev tags", device_udev_tag_alps, LITEST_TOUCHPAD, LITEST_ANY);
litest_add("device:udev tags", device_udev_tag_wacom, LITEST_TOUCHPAD, LITEST_ANY);
litest_add("device:udev tags", device_udev_tag_apple, LITEST_TOUCHPAD, LITEST_ANY);
litest_add("device:udev tags", device_udev_tag_synaptics_serial, LITEST_TOUCHPAD, LITEST_ANY);
+ litest_add("device:udev tags", device_udev_tag_wacom_tablet, LITEST_TABLET, LITEST_ANY);
litest_add_no_device("device:invalid rel events", device_nonpointer_rel);
litest_add_no_device("device:invalid rel events", device_touchpad_rel);
diff --git a/test/litest-device-wacom-bamboo-tablet.c b/test/litest-device-wacom-bamboo-tablet.c
new file mode 100644
index 00000000..d21d4be0
--- /dev/null
+++ b/test/litest-device-wacom-bamboo-tablet.c
@@ -0,0 +1,105 @@
+/*
+ * Copyright © 2014 Red Hat, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "litest.h"
+#include "litest-int.h"
+
+static void litest_wacom_bamboo_tablet_setup(void)
+{
+ struct litest_device *d = litest_create_device(LITEST_WACOM_BAMBOO);
+ litest_set_current_device(d);
+}
+
+static struct input_event proximity_in[] = {
+ { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_DISTANCE, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 1 },
+ { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
+ { .type = -1, .code = -1 },
+};
+
+static struct input_event proximity_out[] = {
+ { .type = EV_ABS, .code = ABS_X, .value = 0 },
+ { .type = EV_ABS, .code = ABS_Y, .value = 0 },
+ { .type = EV_ABS, .code = ABS_DISTANCE, .value = 0 },
+ { .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 0 },
+ { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
+ { .type = -1, .code = -1 },
+};
+
+static struct input_event motion[] = {
+ { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_DISTANCE, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
+ { .type = -1, .code = -1 },
+};
+
+static struct litest_device_interface interface = {
+ .tablet_proximity_in_events = proximity_in,
+ .tablet_proximity_out_events = proximity_out,
+ .tablet_motion_events = motion,
+};
+
+static struct input_absinfo absinfo[] = {
+ { ABS_X, 0, 14720, 4, 0, 100 },
+ { ABS_Y, 0, 9200, 4, 0, 100 },
+ { ABS_PRESSURE, 0, 1023, 0, 0, 0 },
+ { ABS_DISTANCE, 0, 31, 0, 0, 0 },
+ { .value = -1 },
+};
+
+static struct input_id input_id = {
+ .bustype = 0x3,
+ .vendor = 0x56a,
+ .product = 0xde,
+ .version = 0x100,
+};
+
+static int events[] = {
+ EV_KEY, BTN_TOOL_PEN,
+ EV_KEY, BTN_TOOL_RUBBER,
+ EV_KEY, BTN_TOUCH,
+ EV_KEY, BTN_STYLUS,
+ EV_KEY, BTN_STYLUS2,
+ INPUT_PROP_MAX, INPUT_PROP_POINTER,
+ -1, -1,
+};
+
+struct litest_test_device litest_wacom_bamboo_tablet_device = {
+ .type = LITEST_WACOM_BAMBOO,
+ .features = LITEST_TABLET | LITEST_DISTANCE,
+ .shortname = "wacom-bamboo-tablet",
+ .setup = litest_wacom_bamboo_tablet_setup,
+ .interface = &interface,
+
+ .name = "Wacom Bamboo 16FG 4x5 Pen",
+ .id = &input_id,
+ .events = events,
+ .absinfo = absinfo,
+};
diff --git a/test/litest-device-wacom-cintiq-tablet.c b/test/litest-device-wacom-cintiq-tablet.c
new file mode 100644
index 00000000..0217f560
--- /dev/null
+++ b/test/litest-device-wacom-cintiq-tablet.c
@@ -0,0 +1,137 @@
+/*
+ * Copyright © 2014 Red Hat, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "litest.h"
+#include "litest-int.h"
+
+static void litest_wacom_cintiq_tablet_setup(void)
+{
+ struct litest_device *d = litest_create_device(LITEST_WACOM_CINTIQ);
+ litest_set_current_device(d);
+}
+
+static struct input_event proximity_in[] = {
+ { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_DISTANCE, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_TILT_X, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_TILT_Y, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_MISC, .value = 2083 },
+ { .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 },
+ { .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 1 },
+ { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
+ { .type = -1, .code = -1 },
+};
+
+static struct input_event proximity_out[] = {
+ { .type = EV_ABS, .code = ABS_X, .value = 0 },
+ { .type = EV_ABS, .code = ABS_Y, .value = 0 },
+ { .type = EV_ABS, .code = ABS_DISTANCE, .value = 0 },
+ { .type = EV_ABS, .code = ABS_TILT_X, .value = 0 },
+ { .type = EV_ABS, .code = ABS_TILT_Y, .value = 0 },
+ { .type = EV_ABS, .code = ABS_MISC, .value = 0 },
+ { .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 },
+ { .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 0 },
+ { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
+ { .type = -1, .code = -1 },
+};
+
+static struct input_event motion[] = {
+ { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_DISTANCE, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_TILT_X, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_TILT_Y, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_MSC, .code = MSC_SERIAL, .value = 297797542 },
+ { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
+ { .type = -1, .code = -1 },
+};
+
+static struct litest_device_interface interface = {
+ .tablet_proximity_in_events = proximity_in,
+ .tablet_proximity_out_events = proximity_out,
+ .tablet_motion_events = motion,
+};
+
+static struct input_absinfo absinfo[] = {
+ { ABS_X, 0, 53020, 4, 0, 200 },
+ { ABS_Y, 0, 33440, 4, 0, 200 },
+ { ABS_Z, -900, 899, 0, 0, 0 },
+ { ABS_RX, 0, 4096, 0, 0, 0 },
+ { ABS_RY, 0, 4096, 0, 0, 0 },
+ { ABS_WHEEL, 0, 1023, 0, 0, 0 },
+ { ABS_PRESSURE, 0, 1023, 0, 0, 0 },
+ { ABS_DISTANCE, 0, 63, 0, 0, 0 },
+ { ABS_TILT_X, 0, 127, 0, 0, 0 },
+ { ABS_TILT_Y, 0, 127, 0, 0, 0 },
+ { ABS_MISC, 0, 0, 0, 0, 0 },
+ { .value = -1 },
+};
+
+static struct input_id input_id = {
+ .bustype = 0x3,
+ .vendor = 0x56a,
+ .product = 0xc6,
+ .version = 0x113,
+};
+
+static int events[] = {
+ EV_KEY, BTN_0,
+ EV_KEY, BTN_1,
+ EV_KEY, BTN_2,
+ EV_KEY, BTN_3,
+ EV_KEY, BTN_4,
+ EV_KEY, BTN_5,
+ EV_KEY, BTN_6,
+ EV_KEY, BTN_7,
+ EV_KEY, BTN_8,
+ EV_KEY, BTN_9,
+ EV_KEY, BTN_TOOL_PEN,
+ EV_KEY, BTN_TOOL_RUBBER,
+ EV_KEY, BTN_TOOL_BRUSH,
+ EV_KEY, BTN_TOOL_PENCIL,
+ EV_KEY, BTN_TOOL_AIRBRUSH,
+ EV_KEY, BTN_TOUCH,
+ EV_KEY, BTN_STYLUS,
+ EV_KEY, BTN_STYLUS2,
+ EV_MSC, MSC_SERIAL,
+ INPUT_PROP_MAX, INPUT_PROP_DIRECT,
+ -1, -1,
+};
+
+struct litest_test_device litest_wacom_cintiq_tablet_device = {
+ .type = LITEST_WACOM_CINTIQ,
+ .features = LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_SERIAL,
+ .shortname = "wacom-cintiq-tablet",
+ .setup = litest_wacom_cintiq_tablet_setup,
+ .interface = &interface,
+
+ .name = "Wacom Cintiq 12WX",
+ .id = &input_id,
+ .events = events,
+ .absinfo = absinfo,
+};
diff --git a/test/litest-device-wacom-intuos-tablet.c b/test/litest-device-wacom-intuos-tablet.c
new file mode 100644
index 00000000..e0e1d44b
--- /dev/null
+++ b/test/litest-device-wacom-intuos-tablet.c
@@ -0,0 +1,141 @@
+/*
+ * Copyright © 2014 Red Hat, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "litest.h"
+#include "litest-int.h"
+
+static void litest_wacom_intuos_tablet_setup(void)
+{
+ struct litest_device *d = litest_create_device(LITEST_WACOM_INTUOS);
+ litest_set_current_device(d);
+}
+
+static struct input_event proximity_in[] = {
+ { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_DISTANCE, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_TILT_X, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_TILT_Y, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_MISC, .value = 1050626 },
+ { .type = EV_MSC, .code = MSC_SERIAL, .value = 578837976 },
+ { .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 1 },
+ { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
+ { .type = -1, .code = -1 },
+};
+
+static struct input_event proximity_out[] = {
+ { .type = EV_ABS, .code = ABS_X, .value = 0 },
+ { .type = EV_ABS, .code = ABS_Y, .value = 0 },
+ { .type = EV_ABS, .code = ABS_DISTANCE, .value = 0 },
+ { .type = EV_ABS, .code = ABS_TILT_X, .value = 0 },
+ { .type = EV_ABS, .code = ABS_TILT_Y, .value = 0 },
+ { .type = EV_ABS, .code = ABS_MISC, .value = 0 },
+ { .type = EV_MSC, .code = MSC_SERIAL, .value = 578837976 },
+ { .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 0 },
+ { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
+ { .type = -1, .code = -1 },
+};
+
+static struct input_event motion[] = {
+ { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_DISTANCE, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_TILT_X, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_TILT_Y, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_MSC, .code = MSC_SERIAL, .value = 578837976 },
+ { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
+ { .type = -1, .code = -1 },
+};
+static struct litest_device_interface interface = {
+ .tablet_proximity_in_events = proximity_in,
+ .tablet_proximity_out_events = proximity_out,
+ .tablet_motion_events = motion,
+};
+
+static struct input_absinfo absinfo[] = {
+ { ABS_X, 0, 44704, 4, 0, 200 },
+ { ABS_Y, 0, 27940, 4, 0, 200 },
+ { ABS_Z, -900, 899, 0, 0, 0 },
+ { ABS_THROTTLE, -1023, 1023, 0, 0, 0 },
+ { ABS_WHEEL, 0, 1023, 0, 0, 0 },
+ { ABS_PRESSURE, 0, 2047, 0, 0, 0 },
+ { ABS_DISTANCE, 0, 63, 0, 0, 0 },
+ { ABS_TILT_X, 0, 127, 0, 0, 0 },
+ { ABS_TILT_Y, 0, 127, 0, 0, 0 },
+ { ABS_MISC, 0, 0, 0, 0, 0 },
+ { .value = -1 },
+};
+
+static struct input_id input_id = {
+ .bustype = 0x3,
+ .vendor = 0x56a,
+ .product = 0x27,
+};
+
+static int events[] = {
+ EV_KEY, BTN_0,
+ EV_KEY, BTN_1,
+ EV_KEY, BTN_2,
+ EV_KEY, BTN_3,
+ EV_KEY, BTN_4,
+ EV_KEY, BTN_5,
+ EV_KEY, BTN_6,
+ EV_KEY, BTN_7,
+ EV_KEY, BTN_8,
+ EV_KEY, BTN_LEFT,
+ EV_KEY, BTN_RIGHT,
+ EV_KEY, BTN_MIDDLE,
+ EV_KEY, BTN_SIDE,
+ EV_KEY, BTN_EXTRA,
+ EV_KEY, BTN_TOOL_PEN,
+ EV_KEY, BTN_TOOL_RUBBER,
+ EV_KEY, BTN_TOOL_BRUSH,
+ EV_KEY, BTN_TOOL_PENCIL,
+ EV_KEY, BTN_TOOL_AIRBRUSH,
+ EV_KEY, BTN_TOOL_MOUSE,
+ EV_KEY, BTN_TOOL_LENS,
+ EV_KEY, BTN_TOUCH,
+ EV_KEY, BTN_STYLUS,
+ EV_KEY, BTN_STYLUS2,
+ EV_REL, REL_WHEEL,
+ EV_MSC, MSC_SERIAL,
+ INPUT_PROP_MAX, INPUT_PROP_POINTER,
+ -1, -1,
+};
+
+struct litest_test_device litest_wacom_intuos_tablet_device = {
+ .type = LITEST_WACOM_INTUOS,
+ .features = LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_SERIAL,
+ .shortname = "wacom-intuos-tablet",
+ .setup = litest_wacom_intuos_tablet_setup,
+ .interface = &interface,
+
+ .name = "Wacom Intuos5 touch M Pen",
+ .id = &input_id,
+ .events = events,
+ .absinfo = absinfo,
+};
diff --git a/test/litest-device-wacom-isdv4-tablet.c b/test/litest-device-wacom-isdv4-tablet.c
new file mode 100644
index 00000000..c9d40e77
--- /dev/null
+++ b/test/litest-device-wacom-isdv4-tablet.c
@@ -0,0 +1,98 @@
+/*
+ * Copyright © 2014 Red Hat, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "litest.h"
+#include "litest-int.h"
+
+static void litest_wacom_isdv4_tablet_setup(void)
+{
+ struct litest_device *d = litest_create_device(LITEST_WACOM_ISDV4);
+ litest_set_current_device(d);
+}
+
+static struct input_event proximity_in[] = {
+ { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 1 },
+ { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
+ { .type = -1, .code = -1 },
+};
+
+static struct input_event proximity_out[] = {
+ { .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 0 },
+ { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
+ { .type = -1, .code = -1 },
+};
+
+static struct input_event motion[] = {
+ { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
+ { .type = -1, .code = -1 },
+};
+
+static struct litest_device_interface interface = {
+ .tablet_proximity_in_events = proximity_in,
+ .tablet_proximity_out_events = proximity_out,
+ .tablet_motion_events = motion,
+};
+
+static struct input_absinfo absinfo[] = {
+ { ABS_X, 0, 27760, 4, 0, 100 },
+ { ABS_Y, 0, 15694, 4, 0, 100 },
+ { ABS_PRESSURE, 0, 255, 0, 0, 0 },
+ { .value = -1 },
+};
+
+static struct input_id input_id = {
+ .bustype = 0x3,
+ .vendor = 0x56a,
+ .product = 0xe6,
+};
+
+static int events[] = {
+ EV_KEY, BTN_TOOL_PEN,
+ EV_KEY, BTN_TOOL_RUBBER,
+ EV_KEY, BTN_TOUCH,
+ EV_KEY, BTN_STYLUS,
+ EV_KEY, BTN_STYLUS2,
+ INPUT_PROP_MAX, INPUT_PROP_DIRECT,
+ -1, -1,
+};
+
+struct litest_test_device litest_wacom_isdv4_tablet_device = {
+ .type = LITEST_WACOM_ISDV4,
+ .features = LITEST_TABLET,
+ .shortname = "wacom-isdv4-tablet",
+ .setup = litest_wacom_isdv4_tablet_setup,
+ .interface = &interface,
+
+ .name = "Wacom ISDv4 E6 Pen",
+ .id = &input_id,
+ .events = events,
+ .absinfo = absinfo,
+};
diff --git a/test/litest-device-waltop-tablet.c b/test/litest-device-waltop-tablet.c
new file mode 100644
index 00000000..93ec739d
--- /dev/null
+++ b/test/litest-device-waltop-tablet.c
@@ -0,0 +1,222 @@
+/*
+ * Copyright © 2014 Red Hat, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "litest.h"
+#include "litest-int.h"
+
+static void litest_waltop_tablet_setup(void)
+{
+ struct litest_device *d = litest_create_device(LITEST_WALTOP);
+ litest_set_current_device(d);
+}
+
+static struct input_event proximity_in[] = {
+ { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_TILT_X, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_TILT_Y, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 1 },
+ { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
+ { .type = -1, .code = -1 },
+};
+
+static struct input_event proximity_out[] = {
+ { .type = EV_ABS, .code = ABS_X, .value = 0 },
+ { .type = EV_ABS, .code = ABS_Y, .value = 0 },
+ { .type = EV_ABS, .code = ABS_TILT_X, .value = 0 },
+ { .type = EV_ABS, .code = ABS_TILT_Y, .value = 0 },
+ { .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 0 },
+ { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
+ { .type = -1, .code = -1 },
+};
+
+static struct input_event motion[] = {
+ { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_TILT_X, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_ABS, .code = ABS_TILT_Y, .value = LITEST_AUTO_ASSIGN },
+ { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
+ { .type = -1, .code = -1 },
+};
+static struct litest_device_interface interface = {
+ .tablet_proximity_in_events = proximity_in,
+ .tablet_proximity_out_events = proximity_out,
+ .tablet_motion_events = motion,
+};
+
+static struct input_absinfo absinfo[] = {
+ { ABS_X, 0, 32000, 0, 0, 0 },
+ { ABS_Y, 0, 32000, 0, 0, 0 },
+ { ABS_PRESSURE, 0, 2047, 0, 0, 0 },
+ { ABS_TILT_X, -127, 127, 0, 0, 0 },
+ { ABS_TILT_Y, -127, 127, 0, 0, 0 },
+ { .value = -1 },
+};
+
+static struct input_id input_id = {
+ .bustype = 0x3,
+ .vendor = 0x172f,
+ .product = 0x509,
+};
+
+static int events[] = {
+ EV_KEY, KEY_ESC,
+ EV_KEY, KEY_1,
+ EV_KEY, KEY_2,
+ EV_KEY, KEY_3,
+ EV_KEY, KEY_4,
+ EV_KEY, KEY_5,
+ EV_KEY, KEY_6,
+ EV_KEY, KEY_7,
+ EV_KEY, KEY_8,
+ EV_KEY, KEY_9,
+ EV_KEY, KEY_0,
+ EV_KEY, KEY_MINUS,
+ EV_KEY, KEY_EQUAL,
+ EV_KEY, KEY_BACKSPACE,
+ EV_KEY, KEY_TAB,
+ EV_KEY, KEY_Q,
+ EV_KEY, KEY_W,
+ EV_KEY, KEY_E,
+ EV_KEY, KEY_R,
+ EV_KEY, KEY_T,
+ EV_KEY, KEY_Y,
+ EV_KEY, KEY_U,
+ EV_KEY, KEY_I,
+ EV_KEY, KEY_O,
+ EV_KEY, KEY_P,
+ EV_KEY, KEY_LEFTBRACE,
+ EV_KEY, KEY_RIGHTBRACE,
+ EV_KEY, KEY_ENTER,
+ EV_KEY, KEY_LEFTCTRL,
+ EV_KEY, KEY_A,
+ EV_KEY, KEY_S,
+ EV_KEY, KEY_D,
+ EV_KEY, KEY_F,
+ EV_KEY, KEY_G,
+ EV_KEY, KEY_H,
+ EV_KEY, KEY_J,
+ EV_KEY, KEY_K,
+ EV_KEY, KEY_L,
+ EV_KEY, KEY_SEMICOLON,
+ EV_KEY, KEY_APOSTROPHE,
+ EV_KEY, KEY_GRAVE,
+ EV_KEY, KEY_LEFTSHIFT,
+ EV_KEY, KEY_BACKSLASH,
+ EV_KEY, KEY_Z,
+ EV_KEY, KEY_X,
+ EV_KEY, KEY_C,
+ EV_KEY, KEY_V,
+ EV_KEY, KEY_B,
+ EV_KEY, KEY_N,
+ EV_KEY, KEY_M,
+ EV_KEY, KEY_COMMA,
+ EV_KEY, KEY_DOT,
+ EV_KEY, KEY_SLASH,
+ EV_KEY, KEY_RIGHTSHIFT,
+ EV_KEY, KEY_KPASTERISK,
+ EV_KEY, KEY_LEFTALT,
+ EV_KEY, KEY_SPACE,
+ EV_KEY, KEY_CAPSLOCK,
+ EV_KEY, KEY_F1,
+ EV_KEY, KEY_F2,
+ EV_KEY, KEY_F3,
+ EV_KEY, KEY_F4,
+ EV_KEY, KEY_F5,
+ EV_KEY, KEY_F6,
+ EV_KEY, KEY_F7,
+ EV_KEY, KEY_F8,
+ EV_KEY, KEY_F9,
+ EV_KEY, KEY_F10,
+ EV_KEY, KEY_NUMLOCK,
+ EV_KEY, KEY_SCROLLLOCK,
+ EV_KEY, KEY_KP7,
+ EV_KEY, KEY_KP8,
+ EV_KEY, KEY_KP9,
+ EV_KEY, KEY_KPMINUS,
+ EV_KEY, KEY_KP4,
+ EV_KEY, KEY_KP5,
+ EV_KEY, KEY_KP6,
+ EV_KEY, KEY_KPPLUS,
+ EV_KEY, KEY_KP1,
+ EV_KEY, KEY_KP2,
+ EV_KEY, KEY_KP3,
+ EV_KEY, KEY_KP0,
+ EV_KEY, KEY_KPDOT,
+ EV_KEY, KEY_102ND,
+ EV_KEY, KEY_F11,
+ EV_KEY, KEY_F12,
+ EV_KEY, KEY_KPENTER,
+ EV_KEY, KEY_RIGHTCTRL,
+ EV_KEY, KEY_KPSLASH,
+ EV_KEY, KEY_SYSRQ,
+ EV_KEY, KEY_RIGHTALT,
+ EV_KEY, KEY_HOME,
+ EV_KEY, KEY_UP,
+ EV_KEY, KEY_PAGEUP,
+ EV_KEY, KEY_LEFT,
+ EV_KEY, KEY_RIGHT,
+ EV_KEY, KEY_END,
+ EV_KEY, KEY_DOWN,
+ EV_KEY, KEY_PAGEDOWN,
+ EV_KEY, KEY_INSERT,
+ EV_KEY, KEY_DELETE,
+ EV_KEY, KEY_MUTE,
+ EV_KEY, KEY_VOLUMEDOWN,
+ EV_KEY, KEY_VOLUMEUP,
+ EV_KEY, KEY_PAUSE,
+ EV_KEY, KEY_LEFTMETA,
+ EV_KEY, KEY_RIGHTMETA,
+ EV_KEY, KEY_COMPOSE,
+ EV_KEY, BTN_0,
+ EV_KEY, BTN_LEFT,
+ EV_KEY, BTN_RIGHT,
+ EV_KEY, BTN_MIDDLE,
+ EV_KEY, BTN_SIDE,
+ EV_KEY, BTN_EXTRA,
+ EV_KEY, BTN_TOOL_PEN,
+ EV_KEY, BTN_TOOL_RUBBER,
+ EV_KEY, BTN_TOUCH,
+ EV_KEY, BTN_STYLUS,
+ EV_REL, REL_HWHEEL,
+ EV_REL, REL_WHEEL,
+ EV_MSC, MSC_SERIAL,
+ -1, -1,
+};
+
+struct litest_test_device litest_waltop_tablet_device = {
+ .type = LITEST_WALTOP,
+ .features = LITEST_TABLET | LITEST_WHEEL,
+ .shortname = "waltop-tablet",
+ .setup = litest_waltop_tablet_setup,
+ .interface = &interface,
+
+ .name = " WALTOP Batteryless Tablet ", /* sic */
+ .id = &input_id,
+ .events = events,
+ .absinfo = absinfo,
+};
diff --git a/test/litest-int.h b/test/litest-int.h
index ffa30a74..8d0308b3 100644
--- a/test/litest-int.h
+++ b/test/litest-int.h
@@ -97,6 +97,14 @@ struct litest_device_interface {
struct input_event *touch_move_events;
struct input_event *touch_up_events;
+ /**
+ * Tablet events, LITEST_AUTO_ASSIGN is allowed on event values for
+ * ABS_X, ABS_Y, ABS_DISTANCE and ABS_PRESSURE.
+ */
+ struct input_event *tablet_proximity_in_events;
+ struct input_event *tablet_proximity_out_events;
+ struct input_event *tablet_motion_events;
+
int min[2]; /* x/y axis minimum */
int max[2]; /* x/y axis maximum */
};
diff --git a/test/litest.c b/test/litest.c
index bfa28f44..d10175ff 100644
--- a/test/litest.c
+++ b/test/litest.c
@@ -344,6 +344,10 @@ extern struct litest_test_device litest_trackpoint_device;
extern struct litest_test_device litest_bcm5974_device;
extern struct litest_test_device litest_mouse_device;
extern struct litest_test_device litest_wacom_touch_device;
+extern struct litest_test_device litest_wacom_bamboo_tablet_device;
+extern struct litest_test_device litest_wacom_cintiq_tablet_device;
+extern struct litest_test_device litest_wacom_intuos_tablet_device;
+extern struct litest_test_device litest_wacom_isdv4_tablet_device;
extern struct litest_test_device litest_alps_device;
extern struct litest_test_device litest_generic_singletouch_device;
extern struct litest_test_device litest_qemu_tablet_device;
@@ -365,6 +369,7 @@ extern struct litest_test_device litest_generic_multitouch_screen_device;
extern struct litest_test_device litest_nexus4_device;
extern struct litest_test_device litest_magicpad_device;
extern struct litest_test_device litest_elantech_touchpad_device;
+extern struct litest_test_device litest_waltop_tablet_device;
struct litest_test_device* devices[] = {
&litest_synaptics_clickpad_device,
@@ -375,6 +380,10 @@ struct litest_test_device* devices[] = {
&litest_bcm5974_device,
&litest_mouse_device,
&litest_wacom_touch_device,
+ &litest_wacom_bamboo_tablet_device,
+ &litest_wacom_cintiq_tablet_device,
+ &litest_wacom_intuos_tablet_device,
+ &litest_wacom_isdv4_tablet_device,
&litest_alps_device,
&litest_generic_singletouch_device,
&litest_qemu_tablet_device,
@@ -396,6 +405,7 @@ struct litest_test_device* devices[] = {
&litest_nexus4_device,
&litest_magicpad_device,
&litest_elantech_touchpad_device,
+ &litest_waltop_tablet_device,
NULL,
};
@@ -1474,6 +1484,80 @@ litest_touch_move_to(struct litest_device *d,
litest_touch_move(d, slot, x_to, y_to);
}
+static int
+auto_assign_tablet_value(struct litest_device *d,
+ const struct input_event *ev,
+ int x, int y,
+ struct axis_replacement *axes)
+{
+ int value = ev->value;
+
+ if (value != LITEST_AUTO_ASSIGN || ev->type != EV_ABS)
+ return value;
+
+ switch (ev->code) {
+ case ABS_X:
+ value = litest_scale(d, ABS_X, x);
+ break;
+ case ABS_Y:
+ value = litest_scale(d, ABS_Y, y);
+ break;
+ default:
+ axis_replacement_value(axes, ev->code, &value);
+ break;
+ }
+
+ return value;
+}
+
+static int
+tablet_ignore_event(const struct input_event *ev, int value)
+{
+ return value == -1 && (ev->code == ABS_PRESSURE || ev->code == ABS_DISTANCE);
+}
+
+void
+litest_tablet_proximity_in(struct litest_device *d, int x, int y, struct axis_replacement *axes)
+{
+ struct input_event *ev;
+
+ ev = d->interface->tablet_proximity_in_events;
+ while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) {
+ int value = auto_assign_tablet_value(d, ev, x, y, axes);
+ if (!tablet_ignore_event(ev, value))
+ litest_event(d, ev->type, ev->code, value);
+ ev++;
+ }
+}
+
+void
+litest_tablet_proximity_out(struct litest_device *d)
+{
+ struct input_event *ev;
+
+ ev = d->interface->tablet_proximity_out_events;
+ while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) {
+ int value = auto_assign_tablet_value(d, ev, -1, -1, NULL);
+ if (!tablet_ignore_event(ev, value))
+ litest_event(d, ev->type, ev->code, value);
+ ev++;
+ }
+}
+
+void
+litest_tablet_motion(struct litest_device *d, int x, int y, struct axis_replacement *axes)
+{
+ struct input_event *ev;
+
+ ev = d->interface->tablet_motion_events;
+ while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) {
+ int value = auto_assign_tablet_value(d, ev, x, y, axes);
+ if (!tablet_ignore_event(ev, value))
+ litest_event(d, ev->type, ev->code, value);
+ ev++;
+ }
+}
+
void
litest_touch_move_two_touches(struct litest_device *d,
double x0, double y0,
@@ -1797,6 +1881,15 @@ litest_event_type_str(struct libinput_event *event)
case LIBINPUT_EVENT_GESTURE_PINCH_END:
str = "GESTURE PINCH END";
break;
+ case LIBINPUT_EVENT_TABLET_AXIS:
+ str = "TABLET AXIS";
+ break;
+ case LIBINPUT_EVENT_TABLET_PROXIMITY:
+ str = "TABLET PROX";
+ break;
+ case LIBINPUT_EVENT_TABLET_BUTTON:
+ str = "TABLET BUTTON";
+ break;
}
return str;
}
@@ -2218,6 +2311,27 @@ litest_is_gesture_event(struct libinput_event *event,
}
void
+litest_assert_tablet_button_event(struct libinput *li, unsigned int button,
+ enum libinput_button_state state)
+{
+ struct libinput_event *event;
+ struct libinput_event_tablet *tev;
+ enum libinput_event_type type = LIBINPUT_EVENT_TABLET_BUTTON;
+
+ litest_wait_for_event(li);
+ event = libinput_get_event(li);
+
+ litest_assert_notnull(event);
+ litest_assert_int_eq(libinput_event_get_type(event), type);
+ tev = libinput_event_get_tablet_event(event);
+ litest_assert_int_eq(libinput_event_tablet_get_button(tev),
+ button);
+ litest_assert_int_eq(libinput_event_tablet_get_button_state(tev),
+ state);
+ libinput_event_destroy(event);
+}
+
+void
litest_assert_scroll(struct libinput *li,
enum libinput_pointer_axis axis,
int minimum_movement)
diff --git a/test/litest.h b/test/litest.h
index 8a4b33d1..bf165f07 100644
--- a/test/litest.h
+++ b/test/litest.h
@@ -142,6 +142,11 @@ enum litest_device_type {
LITEST_NEXUS4_TOUCH_SCREEN = -28,
LITEST_MAGIC_TRACKPAD = -29,
LITEST_ELANTECH_TOUCHPAD = -30,
+ LITEST_WACOM_BAMBOO = -31,
+ LITEST_WACOM_CINTIQ = -32,
+ LITEST_WACOM_INTUOS = -33,
+ LITEST_WACOM_ISDV4 = -34,
+ LITEST_WALTOP = -35,
};
enum litest_device_feature {
@@ -164,6 +169,9 @@ enum litest_device_feature {
LITEST_PROTOCOL_A = 1 << 14,
LITEST_HOVER = 1 << 15,
LITEST_ELLIPSE = 1 << 16,
+ LITEST_TABLET = 1 << 17,
+ LITEST_DISTANCE = 1 << 18,
+ LITEST_TOOL_SERIAL = 1 << 19,
};
struct litest_device {
@@ -332,6 +340,15 @@ void litest_touch_move_three_touches(struct litest_device *d,
double x2, double y2,
double dx, double dy,
int steps, int sleep_ms);
+
+void litest_tablet_proximity_in(struct litest_device *d,
+ int x, int y,
+ struct axis_replacement *axes);
+void litest_tablet_proximity_out(struct litest_device *d);
+void litest_tablet_motion(struct litest_device *d,
+ int x, int y,
+ struct axis_replacement *axes);
+
void litest_hover_start(struct litest_device *d,
unsigned int slot,
double x,
@@ -394,6 +411,9 @@ void litest_assert_scroll(struct libinput *li,
int minimum_movement);
void litest_assert_only_typed_events(struct libinput *li,
enum libinput_event_type type);
+void litest_assert_tablet_button_event(struct libinput *li,
+ unsigned int button,
+ enum libinput_button_state state);
struct libevdev_uinput * litest_create_uinput_device(const char *name,
struct input_id *id,
@@ -402,6 +422,23 @@ struct libevdev_uinput * litest_create_uinput_abs_device(const char *name,
struct input_id *id,
const struct input_absinfo *abs,
...);
+#define litest_assert_double_eq(a_, b_)\
+ ck_assert_int_eq((int)((a_) * 256), (int)((b_) * 256))
+
+#define litest_assert_double_ne(a_, b_)\
+ ck_assert_int_ne((int)((a_) * 256), (int)((b_) * 256))
+
+#define litest_assert_double_lt(a_, b_)\
+ ck_assert_int_lt((int)((a_) * 256), (int)((b_) * 256))
+
+#define litest_assert_double_le(a_, b_)\
+ ck_assert_int_le((int)((a_) * 256), (int)((b_) * 256))
+
+#define litest_assert_double_gt(a_, b_)\
+ ck_assert_int_gt((int)((a_) * 256), (int)((b_) * 256))
+
+#define litest_assert_double_ge(a_, b_)\
+ ck_assert_int_ge((int)((a_) * 256), (int)((b_) * 256))
void litest_timeout_tap(void);
void litest_timeout_tapndrag(void);
diff --git a/test/misc.c b/test/misc.c
index 89edb145..a0c459dc 100644
--- a/test/misc.c
+++ b/test/misc.c
@@ -31,6 +31,7 @@
#include <unistd.h>
#include "litest.h"
+#include "libinput-util.h"
static int open_restricted(const char *path, int flags, void *data)
{
@@ -132,6 +133,7 @@ START_TEST(event_conversion_device_notify)
ck_assert(libinput_event_get_keyboard_event(event) == NULL);
ck_assert(libinput_event_get_touch_event(event) == NULL);
ck_assert(libinput_event_get_gesture_event(event) == NULL);
+ ck_assert(libinput_event_get_tablet_event(event) == NULL);
litest_restore_log_handler(li);
}
@@ -187,6 +189,7 @@ START_TEST(event_conversion_pointer)
ck_assert(libinput_event_get_keyboard_event(event) == NULL);
ck_assert(libinput_event_get_touch_event(event) == NULL);
ck_assert(libinput_event_get_gesture_event(event) == NULL);
+ ck_assert(libinput_event_get_tablet_event(event) == NULL);
litest_restore_log_handler(li);
}
libinput_event_destroy(event);
@@ -236,6 +239,7 @@ START_TEST(event_conversion_pointer_abs)
ck_assert(libinput_event_get_keyboard_event(event) == NULL);
ck_assert(libinput_event_get_touch_event(event) == NULL);
ck_assert(libinput_event_get_gesture_event(event) == NULL);
+ ck_assert(libinput_event_get_tablet_event(event) == NULL);
litest_restore_log_handler(li);
}
libinput_event_destroy(event);
@@ -278,6 +282,7 @@ START_TEST(event_conversion_key)
ck_assert(libinput_event_get_pointer_event(event) == NULL);
ck_assert(libinput_event_get_touch_event(event) == NULL);
ck_assert(libinput_event_get_gesture_event(event) == NULL);
+ ck_assert(libinput_event_get_tablet_event(event) == NULL);
litest_restore_log_handler(li);
}
libinput_event_destroy(event);
@@ -327,6 +332,7 @@ START_TEST(event_conversion_touch)
ck_assert(libinput_event_get_pointer_event(event) == NULL);
ck_assert(libinput_event_get_keyboard_event(event) == NULL);
ck_assert(libinput_event_get_gesture_event(event) == NULL);
+ ck_assert(libinput_event_get_tablet_event(event) == NULL);
litest_restore_log_handler(li);
}
libinput_event_destroy(event);
@@ -384,6 +390,89 @@ START_TEST(event_conversion_gesture)
}
END_TEST
+START_TEST(event_conversion_tablet)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ struct libinput_event *event;
+ int events = 0;
+ struct axis_replacement axes[] = {
+ { ABS_DISTANCE, 10 },
+ { -1, -1 }
+ };
+
+ litest_tablet_proximity_in(dev, 50, 50, axes);
+ litest_tablet_motion(dev, 60, 50, axes);
+ litest_button_click(dev, BTN_STYLUS, true);
+ litest_button_click(dev, BTN_STYLUS, false);
+
+ libinput_dispatch(li);
+
+ while ((event = libinput_get_event(li))) {
+ enum libinput_event_type type;
+ type = libinput_event_get_type(event);
+
+ if (type >= LIBINPUT_EVENT_TABLET_AXIS &&
+ type <= LIBINPUT_EVENT_TABLET_BUTTON) {
+ struct libinput_event_tablet *t;
+ struct libinput_event *base;
+ t = libinput_event_get_tablet_event(event);
+ base = libinput_event_tablet_get_base_event(t);
+ ck_assert(event == base);
+
+ events++;
+
+ litest_disable_log_handler(li);
+ ck_assert(libinput_event_get_device_notify_event(event) == NULL);
+ ck_assert(libinput_event_get_pointer_event(event) == NULL);
+ ck_assert(libinput_event_get_keyboard_event(event) == NULL);
+ ck_assert(libinput_event_get_touch_event(event) == NULL);
+ litest_restore_log_handler(li);
+ }
+ libinput_event_destroy(event);
+ }
+
+ ck_assert_int_gt(events, 0);
+}
+END_TEST
+
+START_TEST(bitfield_helpers)
+{
+ /* This value has a bit set on all of the word boundaries we want to
+ * test: 0, 1, 7, 8, 31, 32, and 33
+ */
+ unsigned char read_bitfield[] = { 0x83, 0x1, 0x0, 0x80, 0x3 };
+ unsigned char write_bitfield[ARRAY_LENGTH(read_bitfield)];
+ size_t i;
+
+ /* Now check that the bitfield we wrote to came out to be the same as
+ * the bitfield we were writing from */
+ for (i = 0; i < ARRAY_LENGTH(read_bitfield) * 8; i++) {
+ switch (i) {
+ case 0:
+ case 1:
+ case 7:
+ case 8:
+ case 31:
+ case 32:
+ case 33:
+ ck_assert(bit_is_set(read_bitfield, i));
+ set_bit(write_bitfield, i);
+ break;
+ default:
+ ck_assert(!bit_is_set(read_bitfield, i));
+ clear_bit(write_bitfield, i);
+ break;
+ }
+ }
+
+ ck_assert_int_eq(memcmp(read_bitfield,
+ write_bitfield,
+ sizeof(read_bitfield)),
+ 0);
+}
+END_TEST
+
START_TEST(context_ref_counting)
{
struct libinput *li;
@@ -703,6 +792,8 @@ litest_setup_tests(void)
litest_add_for_device("events:conversion", event_conversion_key, LITEST_KEYBOARD);
litest_add_for_device("events:conversion", event_conversion_touch, LITEST_WACOM_TOUCH);
litest_add_for_device("events:conversion", event_conversion_gesture, LITEST_BCM5974);
+ litest_add_for_device("events:conversion", event_conversion_tablet, LITEST_WACOM_CINTIQ);
+ litest_add_no_device("bitfield_helpers", bitfield_helpers);
litest_add_no_device("context:refcount", context_ref_counting);
litest_add_no_device("config:status string", config_status_string);
diff --git a/test/pointer.c b/test/pointer.c
index e12034a0..97ff5ee9 100644
--- a/test/pointer.c
+++ b/test/pointer.c
@@ -1569,12 +1569,12 @@ litest_setup_tests(void)
litest_add("pointer:button", pointer_button, LITEST_BUTTON, LITEST_CLICKPAD);
litest_add_no_device("pointer:button", pointer_button_auto_release);
litest_add_no_device("pointer:button", pointer_seat_button_count);
- litest_add("pointer:scroll", pointer_scroll_wheel, LITEST_WHEEL, LITEST_ANY);
+ litest_add("pointer:scroll", pointer_scroll_wheel, LITEST_WHEEL, LITEST_TABLET);
litest_add("pointer:scroll", pointer_scroll_button, LITEST_RELATIVE|LITEST_BUTTON, LITEST_ANY);
litest_add("pointer:scroll", pointer_scroll_nowheel_defaults, LITEST_RELATIVE|LITEST_BUTTON, LITEST_WHEEL);
- litest_add("pointer:scroll", pointer_scroll_natural_defaults, LITEST_WHEEL, LITEST_ANY);
- litest_add("pointer:scroll", pointer_scroll_natural_enable_config, LITEST_WHEEL, LITEST_ANY);
- litest_add("pointer:scroll", pointer_scroll_natural_wheel, LITEST_WHEEL, LITEST_ANY);
+ litest_add("pointer:scroll", pointer_scroll_natural_defaults, LITEST_WHEEL, LITEST_TABLET);
+ litest_add("pointer:scroll", pointer_scroll_natural_enable_config, LITEST_WHEEL, LITEST_TABLET);
+ litest_add("pointer:scroll", pointer_scroll_natural_wheel, LITEST_WHEEL, LITEST_TABLET);
litest_add("pointer:calibration", pointer_no_calibration, LITEST_ANY, LITEST_TOUCH|LITEST_SINGLE_TOUCH|LITEST_ABSOLUTE|LITEST_PROTOCOL_A);
diff --git a/test/tablet.c b/test/tablet.c
new file mode 100644
index 00000000..d82c650c
--- /dev/null
+++ b/test/tablet.c
@@ -0,0 +1,1778 @@
+/*
+ * Copyright © 2014 Red Hat, Inc.
+ * Copyright © 2014 Stephen Chandler "Lyude" Paul
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission. The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <config.h>
+
+#include <check.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <libinput.h>
+#include <unistd.h>
+#include <stdbool.h>
+
+#include "libinput-util.h"
+#include "evdev-tablet.h"
+#include "litest.h"
+
+START_TEST(proximity_in_out)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ struct libinput_event_tablet *tablet_event;
+ struct libinput_event *event;
+ bool have_tool_update = false,
+ have_proximity_out = false;
+
+ struct axis_replacement axes[] = {
+ { ABS_DISTANCE, 10 },
+ { -1, -1 }
+ };
+
+ litest_drain_events(dev->libinput);
+
+ litest_tablet_proximity_in(dev, 10, 10, axes);
+ libinput_dispatch(li);
+
+ while ((event = libinput_get_event(li))) {
+ if (libinput_event_get_type(event) ==
+ LIBINPUT_EVENT_TABLET_PROXIMITY) {
+ struct libinput_tool * tool;
+
+ have_tool_update++;
+ tablet_event = libinput_event_get_tablet_event(event);
+ tool = libinput_event_tablet_get_tool(tablet_event);
+ ck_assert_int_eq(libinput_tool_get_type(tool),
+ LIBINPUT_TOOL_PEN);
+ }
+ libinput_event_destroy(event);
+ }
+ ck_assert(have_tool_update);
+
+ litest_tablet_proximity_out(dev);
+ libinput_dispatch(li);
+
+ while ((event = libinput_get_event(li))) {
+ if (libinput_event_get_type(event) ==
+ LIBINPUT_EVENT_TABLET_PROXIMITY) {
+ struct libinput_event_tablet *t =
+ libinput_event_get_tablet_event(event);
+
+ if (libinput_event_tablet_get_proximity_state(t) ==
+ LIBINPUT_TOOL_PROXIMITY_OUT)
+ have_proximity_out = true;
+ }
+
+ libinput_event_destroy(event);
+ }
+ ck_assert(have_proximity_out);
+
+ /* Proximity out must not emit axis events */
+ litest_tablet_proximity_out(dev);
+ libinput_dispatch(li);
+
+ while ((event = libinput_get_event(li))) {
+ enum libinput_event_type type = libinput_event_get_type(event);
+
+ ck_assert(type != LIBINPUT_EVENT_TABLET_AXIS);
+
+ libinput_event_destroy(event);
+ }
+}
+END_TEST
+
+START_TEST(proximity_out_clear_buttons)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ struct libinput_event_tablet *tablet_event;
+ struct libinput_event *event;
+ uint32_t button;
+
+ struct axis_replacement axes[] = {
+ { ABS_DISTANCE, 10 },
+ { -1, -1 }
+ };
+
+ litest_drain_events(dev->libinput);
+
+ /* Test that proximity out events send button releases for any currently
+ * pressed stylus buttons
+ */
+ for (button = BTN_TOUCH; button <= BTN_STYLUS2; button++) {
+ bool button_released = false;
+ uint32_t event_button;
+ enum libinput_button_state state;
+
+ if (!libevdev_has_event_code(dev->evdev, EV_KEY, button))
+ continue;
+
+ litest_tablet_proximity_in(dev, 10, 10, axes);
+ litest_event(dev, EV_KEY, button, 1);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+ litest_tablet_proximity_out(dev);
+
+ libinput_dispatch(li);
+
+ while ((event = libinput_get_event(li))) {
+ tablet_event = libinput_event_get_tablet_event(event);
+
+ if (libinput_event_get_type(event) ==
+ LIBINPUT_EVENT_TABLET_BUTTON) {
+
+ event_button = libinput_event_tablet_get_button(tablet_event);
+ state = libinput_event_tablet_get_button_state(tablet_event);
+
+ if (event_button == button &&
+ state == LIBINPUT_BUTTON_STATE_RELEASED)
+ button_released = true;
+ }
+
+ libinput_event_destroy(event);
+ }
+
+ ck_assert_msg(button_released,
+ "Button %s (%d) was not released.",
+ libevdev_event_code_get_name(EV_KEY, button),
+ event_button);
+ }
+}
+END_TEST
+
+START_TEST(proximity_has_axes)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ struct libinput_event_tablet *tablet_event;
+ struct libinput_event *event;
+ struct libinput_tool *tool;
+ double x, y,
+ distance;
+
+ struct axis_replacement axes[] = {
+ { ABS_DISTANCE, 10 },
+ { ABS_TILT_X, 10 },
+ { ABS_TILT_Y, 10 },
+ { -1, -1}
+ };
+
+ litest_drain_events(dev->libinput);
+
+ litest_tablet_proximity_in(dev, 10, 10, axes);
+
+ litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_PROXIMITY, -1);
+
+ event = libinput_get_event(li);
+
+ tablet_event = libinput_event_get_tablet_event(event);
+ tool = libinput_event_tablet_get_tool(tablet_event);
+
+ ck_assert(libinput_event_tablet_axis_has_changed(
+ tablet_event, LIBINPUT_TABLET_AXIS_X));
+ ck_assert(libinput_event_tablet_axis_has_changed(
+ tablet_event, LIBINPUT_TABLET_AXIS_Y));
+
+ x = libinput_event_tablet_get_axis_value(tablet_event,
+ LIBINPUT_TABLET_AXIS_X);
+ y = libinput_event_tablet_get_axis_value(tablet_event,
+ LIBINPUT_TABLET_AXIS_Y);
+
+ litest_assert_double_ne(x, 0);
+ litest_assert_double_ne(y, 0);
+
+ if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_DISTANCE)) {
+ ck_assert(libinput_event_tablet_axis_has_changed(
+ tablet_event,
+ LIBINPUT_TABLET_AXIS_DISTANCE));
+
+ distance = libinput_event_tablet_get_axis_value(
+ tablet_event,
+ LIBINPUT_TABLET_AXIS_DISTANCE);
+ litest_assert_double_ne(distance, 0);
+ }
+
+ if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_TILT_X) &&
+ libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_TILT_Y)) {
+ ck_assert(libinput_event_tablet_axis_has_changed(
+ tablet_event,
+ LIBINPUT_TABLET_AXIS_TILT_X));
+ ck_assert(libinput_event_tablet_axis_has_changed(
+ tablet_event,
+ LIBINPUT_TABLET_AXIS_TILT_Y));
+
+ x = libinput_event_tablet_get_axis_value(
+ tablet_event,
+ LIBINPUT_TABLET_AXIS_TILT_X);
+ y = libinput_event_tablet_get_axis_value(
+ tablet_event,
+ LIBINPUT_TABLET_AXIS_TILT_Y);
+
+ litest_assert_double_ne(x, 0);
+ litest_assert_double_ne(y, 0);
+ }
+
+ litest_assert_empty_queue(li);
+ libinput_event_destroy(event);
+
+ /* Make sure that the axes are still present on proximity out */
+ litest_tablet_proximity_out(dev);
+
+ litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_PROXIMITY, -1);
+ event = libinput_get_event(li);
+
+ tablet_event = libinput_event_get_tablet_event(event);
+ tool = libinput_event_tablet_get_tool(tablet_event);
+
+ ck_assert(!libinput_event_tablet_axis_has_changed(
+ tablet_event, LIBINPUT_TABLET_AXIS_X));
+ ck_assert(!libinput_event_tablet_axis_has_changed(
+ tablet_event, LIBINPUT_TABLET_AXIS_Y));
+
+ x = libinput_event_tablet_get_axis_value(tablet_event,
+ LIBINPUT_TABLET_AXIS_X);
+ y = libinput_event_tablet_get_axis_value(tablet_event,
+ LIBINPUT_TABLET_AXIS_Y);
+
+ litest_assert_double_ne(x, 0);
+ litest_assert_double_ne(y, 0);
+
+ if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_DISTANCE)) {
+ ck_assert(!libinput_event_tablet_axis_has_changed(
+ tablet_event,
+ LIBINPUT_TABLET_AXIS_DISTANCE));
+
+ distance = libinput_event_tablet_get_axis_value(
+ tablet_event,
+ LIBINPUT_TABLET_AXIS_DISTANCE);
+ litest_assert_double_ne(distance, 0);
+ }
+
+ if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_TILT_X) &&
+ libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_TILT_Y)) {
+ ck_assert(!libinput_event_tablet_axis_has_changed(
+ tablet_event,
+ LIBINPUT_TABLET_AXIS_TILT_X));
+ ck_assert(!libinput_event_tablet_axis_has_changed(
+ tablet_event,
+ LIBINPUT_TABLET_AXIS_TILT_Y));
+
+ x = libinput_event_tablet_get_axis_value(
+ tablet_event,
+ LIBINPUT_TABLET_AXIS_TILT_X);
+ y = libinput_event_tablet_get_axis_value(
+ tablet_event,
+ LIBINPUT_TABLET_AXIS_TILT_Y);
+
+ litest_assert_double_ne(x, 0);
+ litest_assert_double_ne(y, 0);
+ }
+
+ litest_assert_empty_queue(li);
+ libinput_event_destroy(event);
+}
+END_TEST
+
+START_TEST(motion)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ struct libinput_event_tablet *tablet_event;
+ struct libinput_event *event;
+ int test_x, test_y;
+ double last_reported_x = 0, last_reported_y = 0;
+ enum libinput_event_type type;
+ struct axis_replacement axes[] = {
+ { ABS_DISTANCE, 10 },
+ { -1, -1 }
+ };
+
+ litest_drain_events(li);
+
+ litest_tablet_proximity_in(dev, 5, 100, axes);
+ libinput_dispatch(li);
+
+ litest_wait_for_event_of_type(li,
+ LIBINPUT_EVENT_TABLET_PROXIMITY,
+ -1);
+
+ while ((event = libinput_get_event(li))) {
+ bool x_changed, y_changed;
+ double reported_x, reported_y;
+
+ tablet_event = libinput_event_get_tablet_event(event);
+ ck_assert_int_eq(libinput_event_get_type(event),
+ LIBINPUT_EVENT_TABLET_PROXIMITY);
+
+ x_changed = libinput_event_tablet_axis_has_changed(
+ tablet_event, LIBINPUT_TABLET_AXIS_X);
+ y_changed = libinput_event_tablet_axis_has_changed(
+ tablet_event, LIBINPUT_TABLET_AXIS_Y);
+
+ ck_assert(x_changed);
+ ck_assert(y_changed);
+
+ reported_x = libinput_event_tablet_get_axis_value(
+ tablet_event, LIBINPUT_TABLET_AXIS_X);
+ reported_y = libinput_event_tablet_get_axis_value(
+ tablet_event, LIBINPUT_TABLET_AXIS_Y);
+
+ litest_assert_double_lt(reported_x, reported_y);
+
+ last_reported_x = reported_x;
+ last_reported_y = reported_y;
+
+ libinput_event_destroy(event);
+ }
+
+ for (test_x = 10, test_y = 90;
+ test_x <= 100;
+ test_x += 10, test_y -= 10) {
+ bool x_changed, y_changed;
+ double reported_x, reported_y;
+
+ litest_tablet_motion(dev, test_x, test_y, axes);
+ libinput_dispatch(li);
+
+ while ((event = libinput_get_event(li))) {
+ tablet_event = libinput_event_get_tablet_event(event);
+ type = libinput_event_get_type(event);
+
+ if (type == LIBINPUT_EVENT_TABLET_AXIS) {
+ x_changed = libinput_event_tablet_axis_has_changed(
+ tablet_event, LIBINPUT_TABLET_AXIS_X);
+ y_changed = libinput_event_tablet_axis_has_changed(
+ tablet_event, LIBINPUT_TABLET_AXIS_Y);
+
+ ck_assert(x_changed);
+ ck_assert(y_changed);
+
+ reported_x = libinput_event_tablet_get_axis_value(
+ tablet_event, LIBINPUT_TABLET_AXIS_X);
+ reported_y = libinput_event_tablet_get_axis_value(
+ tablet_event, LIBINPUT_TABLET_AXIS_Y);
+
+ litest_assert_double_gt(reported_x,
+ last_reported_x);
+ litest_assert_double_lt(reported_y,
+ last_reported_y);
+
+ last_reported_x = reported_x;
+ last_reported_y = reported_y;
+ }
+
+ libinput_event_destroy(event);
+ }
+ }
+}
+END_TEST
+
+START_TEST(motion_delta)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ struct libinput_event_tablet *tablet_event;
+ struct libinput_event *event;
+ double x1, y1, x2, y2, dist1, dist2;
+ double delta;
+ struct axis_replacement axes[] = {
+ { ABS_DISTANCE, 10 },
+ { -1, -1 }
+ };
+
+ litest_drain_events(li);
+
+ litest_tablet_proximity_in(dev, 5, 100, axes);
+ libinput_dispatch(li);
+
+ litest_wait_for_event_of_type(li,
+ LIBINPUT_EVENT_TABLET_PROXIMITY,
+ -1);
+
+ event = libinput_get_event(li);
+ tablet_event = libinput_event_get_tablet_event(event);
+ x1 = libinput_event_tablet_get_axis_value(tablet_event,
+ LIBINPUT_TABLET_AXIS_X);
+ y1 = libinput_event_tablet_get_axis_value(tablet_event,
+ LIBINPUT_TABLET_AXIS_Y);
+ dist1 = libinput_event_tablet_get_axis_value(tablet_event,
+ LIBINPUT_TABLET_AXIS_DISTANCE);
+ libinput_event_destroy(event);
+
+ axes[0].value = 40;
+ litest_tablet_motion(dev, 40, 100, axes);
+
+ litest_wait_for_event_of_type(li,
+ LIBINPUT_EVENT_TABLET_AXIS,
+ -1);
+ event = libinput_get_event(li);
+ tablet_event = libinput_event_get_tablet_event(event);
+ x2 = libinput_event_tablet_get_axis_value(tablet_event,
+ LIBINPUT_TABLET_AXIS_X);
+ y2 = libinput_event_tablet_get_axis_value(tablet_event,
+ LIBINPUT_TABLET_AXIS_Y);
+ dist2 = libinput_event_tablet_get_axis_value(tablet_event,
+ LIBINPUT_TABLET_AXIS_DISTANCE);
+
+ delta = libinput_event_tablet_get_axis_delta(tablet_event,
+ LIBINPUT_TABLET_AXIS_X);
+ litest_assert_double_eq(delta, x2 - x1);
+ delta = libinput_event_tablet_get_axis_delta(tablet_event,
+ LIBINPUT_TABLET_AXIS_Y);
+ litest_assert_double_eq(delta, y2 - y1);
+ delta = libinput_event_tablet_get_axis_delta(tablet_event,
+ LIBINPUT_TABLET_AXIS_DISTANCE);
+ litest_assert_double_eq(delta, dist2 - dist1);
+
+ libinput_event_destroy(event);
+}
+END_TEST
+
+START_TEST(motion_delta_partial)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ struct libinput_event_tablet *tablet_event;
+ struct libinput_event *event;
+ double dx, dy, ddist;
+ struct axis_replacement axes[] = {
+ { ABS_DISTANCE, 10 },
+ { -1, -1 }
+ };
+
+ if (!libevdev_has_event_code(dev->evdev, EV_ABS, ABS_DISTANCE))
+ return;
+
+ litest_tablet_proximity_in(dev, 5, 100, axes);
+ litest_tablet_motion(dev, 40, 100, axes);
+ litest_drain_events(li);
+
+ axes[0].value = 40;
+ litest_tablet_motion(dev, 40, 100, axes);
+ litest_wait_for_event_of_type(li,
+ LIBINPUT_EVENT_TABLET_AXIS,
+ -1);
+ event = libinput_get_event(li);
+ tablet_event = libinput_event_get_tablet_event(event);
+
+ ck_assert(!libinput_event_tablet_axis_has_changed(tablet_event,
+ LIBINPUT_TABLET_AXIS_X));
+ dx = libinput_event_tablet_get_axis_delta(tablet_event,
+ LIBINPUT_TABLET_AXIS_X);
+ litest_assert_double_eq(dx, 0.0);
+
+ ck_assert(!libinput_event_tablet_axis_has_changed(tablet_event,
+ LIBINPUT_TABLET_AXIS_X));
+ dy = libinput_event_tablet_get_axis_delta(tablet_event,
+ LIBINPUT_TABLET_AXIS_Y);
+ litest_assert_double_eq(dy, 0.0);
+
+ ck_assert(libinput_event_tablet_axis_has_changed(tablet_event,
+ LIBINPUT_TABLET_AXIS_DISTANCE));
+ ddist = libinput_event_tablet_get_axis_delta(tablet_event,
+ LIBINPUT_TABLET_AXIS_DISTANCE);
+ ck_assert_double_gt(ddist, 0);
+
+ libinput_event_destroy(event);
+}
+END_TEST
+
+START_TEST(left_handed)
+{
+#if HAVE_LIBWACOM
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ struct libinput_event *event;
+ struct libinput_event_tablet *tablet_event;
+ double libinput_max_x, libinput_max_y;
+ double last_x = -1.0, last_y = -1.0;
+ struct axis_replacement axes[] = {
+ { ABS_DISTANCE, 10 },
+ { -1, -1 }
+ };
+
+ ck_assert(libinput_device_config_left_handed_is_available(dev->libinput_device));
+
+ libinput_device_get_size (dev->libinput_device,
+ &libinput_max_x,
+ &libinput_max_y);
+
+ /* Test that left-handed mode doesn't go into effect until the tool has
+ * left proximity of the tablet. In order to test this, we have to bring
+ * the tool into proximity and make sure libinput processes the
+ * proximity events so that it updates it's internal tablet state, and
+ * then try setting it to left-handed mode. */
+ litest_tablet_proximity_in(dev, 0, 100, axes);
+ libinput_dispatch(li);
+ libinput_device_config_left_handed_set(dev->libinput_device, 1);
+
+ litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_PROXIMITY, -1);
+
+ while ((event = libinput_get_event(li))) {
+ tablet_event = libinput_event_get_tablet_event(event);
+
+ last_x = libinput_event_tablet_get_axis_value(
+ tablet_event, LIBINPUT_TABLET_AXIS_X);
+ last_y = libinput_event_tablet_get_axis_value(
+ tablet_event, LIBINPUT_TABLET_AXIS_Y);
+
+ litest_assert_double_eq(last_x, 0);
+ litest_assert_double_eq(last_y, libinput_max_y);
+
+ libinput_event_destroy(event);
+ }
+
+ litest_tablet_motion(dev, 100, 0, axes);
+ litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_AXIS, -1);
+
+ while ((event = libinput_get_event(li))) {
+ double x, y;
+ tablet_event = libinput_event_get_tablet_event(event);
+
+ x = libinput_event_tablet_get_axis_value(
+ tablet_event, LIBINPUT_TABLET_AXIS_X);
+ y = libinput_event_tablet_get_axis_value(
+ tablet_event, LIBINPUT_TABLET_AXIS_Y);
+
+ litest_assert_double_eq(x, libinput_max_x);
+ litest_assert_double_eq(y, 0);
+
+ litest_assert_double_gt(x, last_x);
+ litest_assert_double_lt(y, last_y);
+
+ libinput_event_destroy(event);
+ }
+
+ litest_tablet_proximity_out(dev);
+ litest_drain_events(li);
+
+ /* Since we've drained the events and libinput's aware the tool is out
+ * of proximity, it should have finally transitioned into left-handed
+ * mode, so the axes should be inverted once we bring it back into
+ * proximity */
+ litest_tablet_proximity_in(dev, 0, 100, axes);
+
+ litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_PROXIMITY, -1);
+
+ while ((event = libinput_get_event(li))) {
+ tablet_event = libinput_event_get_tablet_event(event);
+
+ last_x = libinput_event_tablet_get_axis_value(
+ tablet_event, LIBINPUT_TABLET_AXIS_X);
+ last_y = libinput_event_tablet_get_axis_value(
+ tablet_event, LIBINPUT_TABLET_AXIS_Y);
+
+ litest_assert_double_eq(last_x, libinput_max_x);
+ litest_assert_double_eq(last_y, 0);
+
+ libinput_event_destroy(event);
+ }
+
+ litest_tablet_motion(dev, 100, 0, axes);
+ litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_AXIS, -1);
+
+ while ((event = libinput_get_event(li))) {
+ double x, y;
+ tablet_event = libinput_event_get_tablet_event(event);
+
+ x = libinput_event_tablet_get_axis_value(
+ tablet_event, LIBINPUT_TABLET_AXIS_X);
+ y = libinput_event_tablet_get_axis_value(
+ tablet_event, LIBINPUT_TABLET_AXIS_Y);
+
+ litest_assert_double_eq(x, 0);
+ litest_assert_double_eq(y, libinput_max_y);
+
+ litest_assert_double_lt(x, last_x);
+ litest_assert_double_gt(y, last_y);
+
+ libinput_event_destroy(event);
+ }
+#endif
+}
+END_TEST
+
+START_TEST(no_left_handed)
+{
+ struct litest_device *dev = litest_current_device();
+
+ ck_assert(!libinput_device_config_left_handed_is_available(dev->libinput_device));
+}
+END_TEST
+
+START_TEST(motion_event_state)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ struct libinput_event *event;
+ struct libinput_event_tablet *tablet_event;
+ int test_x, test_y;
+ double last_x, last_y;
+
+ struct axis_replacement axes[] = {
+ { ABS_DISTANCE, 10 },
+ { -1, -1 }
+ };
+
+ litest_drain_events(li);
+ litest_tablet_proximity_in(dev, 5, 100, axes);
+ litest_drain_events(li);
+
+ /* couple of events that go left/bottom to right/top */
+ for (test_x = 0, test_y = 100; test_x < 100; test_x += 10, test_y -= 10)
+ litest_tablet_motion(dev, test_x, test_y, axes);
+
+ libinput_dispatch(li);
+
+ while ((event = libinput_get_event(li))) {
+ if (libinput_event_get_type(event) == LIBINPUT_EVENT_TABLET_AXIS)
+ break;
+ libinput_event_destroy(event);
+ }
+
+ /* pop the first event off */
+ ck_assert_notnull(event);
+ tablet_event = libinput_event_get_tablet_event(event);
+ ck_assert_notnull(tablet_event);
+
+ last_x = libinput_event_tablet_get_axis_value(tablet_event,
+ LIBINPUT_TABLET_AXIS_X);
+ last_y = libinput_event_tablet_get_axis_value(tablet_event,
+ LIBINPUT_TABLET_AXIS_Y);
+
+ /* mark with a button event, then go back to bottom/left */
+ litest_event(dev, EV_KEY, BTN_STYLUS, 1);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+ for (test_x = 100, test_y = 0; test_x > 0; test_x -= 10, test_y += 10)
+ litest_tablet_motion(dev, test_x, test_y, axes);
+
+ libinput_event_destroy(event);
+ libinput_dispatch(li);
+ ck_assert_int_eq(libinput_next_event_type(li),
+ LIBINPUT_EVENT_TABLET_AXIS);
+
+ /* we expect all events up to the button event to go from
+ bottom/left to top/right */
+ while ((event = libinput_get_event(li))) {
+ double x, y;
+
+ if (libinput_event_get_type(event) != LIBINPUT_EVENT_TABLET_AXIS)
+ break;
+
+ tablet_event = libinput_event_get_tablet_event(event);
+ ck_assert_notnull(tablet_event);
+
+ x = libinput_event_tablet_get_axis_value(tablet_event,
+ LIBINPUT_TABLET_AXIS_X);
+ y = libinput_event_tablet_get_axis_value(tablet_event,
+ LIBINPUT_TABLET_AXIS_Y);
+
+ ck_assert(x > last_x);
+ ck_assert(y < last_y);
+
+ last_x = x;
+ last_y = y;
+ libinput_event_destroy(event);
+ }
+
+ ck_assert_int_eq(libinput_event_get_type(event),
+ LIBINPUT_EVENT_TABLET_BUTTON);
+ libinput_event_destroy(event);
+}
+END_TEST
+
+START_TEST(bad_distance_events)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ const struct input_absinfo *absinfo;
+ struct axis_replacement axes[] = {
+ { -1, -1 },
+ };
+
+ litest_tablet_proximity_in(dev, 10, 10, axes);
+ litest_tablet_proximity_out(dev);
+ litest_drain_events(dev->libinput);
+
+ absinfo = libevdev_get_abs_info(dev->evdev, ABS_DISTANCE);
+ ck_assert(absinfo != NULL);
+
+ litest_event(dev, EV_ABS, ABS_DISTANCE, absinfo->maximum);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+ litest_event(dev, EV_ABS, ABS_DISTANCE, absinfo->minimum);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+ litest_assert_empty_queue(li);
+}
+END_TEST
+
+START_TEST(normalization)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ struct libinput_event_tablet *tablet_event;
+ struct libinput_event *event;
+ double pressure,
+ tilt_vertical,
+ tilt_horizontal;
+ const struct input_absinfo *pressure_absinfo,
+ *tilt_vertical_absinfo,
+ *tilt_horizontal_absinfo;
+
+ litest_drain_events(dev->libinput);
+
+ pressure_absinfo = libevdev_get_abs_info(dev->evdev, ABS_PRESSURE);
+ tilt_vertical_absinfo = libevdev_get_abs_info(dev->evdev, ABS_TILT_X);
+ tilt_horizontal_absinfo = libevdev_get_abs_info(dev->evdev, ABS_TILT_Y);
+
+ /* Test minimum */
+ if (pressure_absinfo != NULL)
+ litest_event(dev,
+ EV_ABS,
+ ABS_PRESSURE,
+ pressure_absinfo->minimum);
+
+ if (tilt_vertical_absinfo != NULL)
+ litest_event(dev,
+ EV_ABS,
+ ABS_TILT_X,
+ tilt_vertical_absinfo->minimum);
+
+ if (tilt_horizontal_absinfo != NULL)
+ litest_event(dev,
+ EV_ABS,
+ ABS_TILT_Y,
+ tilt_horizontal_absinfo->minimum);
+
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+ libinput_dispatch(li);
+
+ while ((event = libinput_get_event(li))) {
+ if (libinput_event_get_type(event) == LIBINPUT_EVENT_TABLET_AXIS) {
+ tablet_event = libinput_event_get_tablet_event(event);
+
+ if (libinput_event_tablet_axis_has_changed(
+ tablet_event,
+ LIBINPUT_TABLET_AXIS_PRESSURE)) {
+ pressure = libinput_event_tablet_get_axis_value(
+ tablet_event, LIBINPUT_TABLET_AXIS_PRESSURE);
+
+ litest_assert_double_eq(pressure, 0);
+ }
+
+ if (libinput_event_tablet_axis_has_changed(
+ tablet_event,
+ LIBINPUT_TABLET_AXIS_TILT_X)) {
+ tilt_vertical =
+ libinput_event_tablet_get_axis_value(
+ tablet_event,
+ LIBINPUT_TABLET_AXIS_TILT_X);
+
+ litest_assert_double_eq(tilt_vertical, -1);
+ }
+
+ if (libinput_event_tablet_axis_has_changed(
+ tablet_event,
+ LIBINPUT_TABLET_AXIS_TILT_Y)) {
+ tilt_horizontal =
+ libinput_event_tablet_get_axis_value(
+ tablet_event,
+ LIBINPUT_TABLET_AXIS_TILT_Y);
+
+ litest_assert_double_eq(tilt_horizontal, -1);
+ }
+ }
+
+ libinput_event_destroy(event);
+ }
+
+ /* Test maximum */
+ if (pressure_absinfo != NULL)
+ litest_event(dev,
+ EV_ABS,
+ ABS_PRESSURE,
+ pressure_absinfo->maximum);
+
+ if (tilt_vertical_absinfo != NULL)
+ litest_event(dev,
+ EV_ABS,
+ ABS_TILT_X,
+ tilt_vertical_absinfo->maximum);
+
+ if (tilt_horizontal_absinfo != NULL)
+ litest_event(dev,
+ EV_ABS,
+ ABS_TILT_Y,
+ tilt_horizontal_absinfo->maximum);
+
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+ libinput_dispatch(li);
+
+ while ((event = libinput_get_event(li))) {
+ if (libinput_event_get_type(event) == LIBINPUT_EVENT_TABLET_AXIS) {
+ tablet_event = libinput_event_get_tablet_event(event);
+
+ if (libinput_event_tablet_axis_has_changed(
+ tablet_event,
+ LIBINPUT_TABLET_AXIS_PRESSURE)) {
+ pressure = libinput_event_tablet_get_axis_value(
+ tablet_event, LIBINPUT_TABLET_AXIS_PRESSURE);
+
+ litest_assert_double_eq(pressure, 1);
+ }
+
+ if (libinput_event_tablet_axis_has_changed(
+ tablet_event,
+ LIBINPUT_TABLET_AXIS_TILT_X)) {
+ tilt_vertical =
+ libinput_event_tablet_get_axis_value(
+ tablet_event,
+ LIBINPUT_TABLET_AXIS_TILT_X);
+
+ litest_assert_double_eq(tilt_vertical, 1);
+ }
+
+ if (libinput_event_tablet_axis_has_changed(
+ tablet_event,
+ LIBINPUT_TABLET_AXIS_TILT_Y)) {
+ tilt_horizontal =
+ libinput_event_tablet_get_axis_value(
+ tablet_event,
+ LIBINPUT_TABLET_AXIS_TILT_Y);
+
+ litest_assert_double_eq(tilt_horizontal, 1);
+ }
+ }
+
+ libinput_event_destroy(event);
+ }
+
+}
+END_TEST
+
+START_TEST(tool_serial)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ struct libinput_event_tablet *tablet_event;
+ struct libinput_event *event;
+ struct libinput_tool *tool;
+
+ litest_drain_events(li);
+
+ litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1);
+ litest_event(dev, EV_MSC, MSC_SERIAL, 1000);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+ litest_wait_for_event_of_type(li,
+ LIBINPUT_EVENT_TABLET_PROXIMITY,
+ -1);
+ event = libinput_get_event(li);
+ tablet_event = libinput_event_get_tablet_event(event);
+ tool = libinput_event_tablet_get_tool(tablet_event);
+ ck_assert_uint_eq(libinput_tool_get_serial(tool), 1000);
+ libinput_event_destroy(event);
+}
+END_TEST
+
+START_TEST(serial_changes_tool)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ struct libinput_event_tablet *tablet_event;
+ struct libinput_event *event;
+ struct libinput_tool *tool;
+
+ litest_drain_events(li);
+
+ litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1);
+ litest_event(dev, EV_MSC, MSC_SERIAL, 1000);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+ litest_event(dev, EV_KEY, BTN_TOOL_PEN, 0);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+ litest_drain_events(li);
+
+ litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1);
+ litest_event(dev, EV_MSC, MSC_SERIAL, 2000);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+ litest_wait_for_event_of_type(li,
+ LIBINPUT_EVENT_TABLET_PROXIMITY,
+ -1);
+ event = libinput_get_event(li);
+ tablet_event = libinput_event_get_tablet_event(event);
+ tool = libinput_event_tablet_get_tool(tablet_event);
+
+ ck_assert_uint_eq(libinput_tool_get_serial(tool), 2000);
+ libinput_event_destroy(event);
+}
+END_TEST
+
+START_TEST(invalid_serials)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ struct libinput_event *event;
+ struct libinput_event_tablet *tablet_event;
+ struct libinput_tool *tool;
+
+ litest_drain_events(li);
+
+ litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1);
+ litest_event(dev, EV_MSC, MSC_SERIAL, 1000);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+ litest_event(dev, EV_KEY, BTN_TOOL_PEN, 0);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+ litest_drain_events(li);
+
+ litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1);
+ litest_event(dev, EV_MSC, MSC_SERIAL, -1);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+ libinput_dispatch(li);
+ while ((event = libinput_get_event(li))) {
+ if (libinput_event_get_type(event) ==
+ LIBINPUT_EVENT_TABLET_PROXIMITY) {
+ tablet_event = libinput_event_get_tablet_event(event);
+ tool = libinput_event_tablet_get_tool(tablet_event);
+
+ ck_assert_uint_eq(libinput_tool_get_serial(tool), 1000);
+ }
+
+ libinput_event_destroy(event);
+ }
+}
+END_TEST
+
+START_TEST(tool_ref)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ struct libinput_event_tablet *tablet_event;
+ struct libinput_event *event;
+ struct libinput_tool *tool;
+
+ litest_drain_events(li);
+
+ litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1);
+ litest_event(dev, EV_MSC, MSC_SERIAL, 1000);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+ litest_wait_for_event_of_type(li,
+ LIBINPUT_EVENT_TABLET_PROXIMITY,
+ -1);
+ event = libinput_get_event(li);
+ tablet_event = libinput_event_get_tablet_event(event);
+ tool = libinput_event_tablet_get_tool(tablet_event);
+
+ ck_assert_notnull(tool);
+ ck_assert(tool == libinput_tool_ref(tool));
+ ck_assert(tool == libinput_tool_unref(tool));
+ ck_assert(libinput_tool_unref(tool) == NULL);
+
+ libinput_event_destroy(event);
+}
+END_TEST
+
+START_TEST(pad_buttons_ignored)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ struct libinput_event *event;
+ struct axis_replacement axes[] = {
+ { ABS_DISTANCE, 10 },
+ { -1, -1 }
+ };
+ int button;
+
+ litest_drain_events(li);
+
+ for (button = BTN_0; button < BTN_MOUSE; button++) {
+ litest_event(dev, EV_KEY, button, 1);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+ litest_event(dev, EV_KEY, button, 0);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+ libinput_dispatch(li);
+ }
+
+ while ((event = libinput_get_event(li))) {
+ ck_assert_int_ne(libinput_event_get_type(event),
+ LIBINPUT_EVENT_TABLET_BUTTON);
+ libinput_event_destroy(event);
+ libinput_dispatch(li);
+ }
+
+ /* same thing while in prox */
+ litest_tablet_proximity_in(dev, 10, 10, axes);
+ for (button = BTN_0; button < BTN_MOUSE; button++) {
+ litest_event(dev, EV_KEY, button, 1);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+ litest_event(dev, EV_KEY, button, 0);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+ libinput_dispatch(li);
+ }
+ litest_tablet_proximity_out(dev);
+
+ libinput_dispatch(li);
+ while ((event = libinput_get_event(li))) {
+ ck_assert_int_ne(libinput_event_get_type(event),
+ LIBINPUT_EVENT_TABLET_BUTTON);
+ libinput_event_destroy(event);
+ libinput_dispatch(li);
+ }
+}
+END_TEST
+
+START_TEST(tools_with_serials)
+{
+ struct libinput *li = litest_create_context();
+ struct litest_device *dev[2];
+ struct libinput_tool *tool[2] = {0};
+ struct libinput_event *event;
+ int i;
+
+ for (i = 0; i < 2; i++) {
+ dev[i] = litest_add_device_with_overrides(li,
+ LITEST_WACOM_INTUOS,
+ NULL,
+ NULL,
+ NULL,
+ NULL);
+ /* WARNING: this test fails if UI_GET_SYSNAME isn't
+ * available or isn't used by libevdev (1.3, commit 2ff45c73).
+ * Put a sleep(1) here and that usually fixes it.
+ */
+
+ litest_event(dev[i], EV_KEY, BTN_TOOL_PEN, 1);
+ litest_event(dev[i], EV_MSC, MSC_SERIAL, 100);
+ litest_event(dev[i], EV_SYN, SYN_REPORT, 0);
+
+ libinput_dispatch(li);
+ while ((event = libinput_get_event(li))) {
+ if (libinput_event_get_type(event) ==
+ LIBINPUT_EVENT_TABLET_PROXIMITY) {
+ struct libinput_event_tablet *t =
+ libinput_event_get_tablet_event(event);
+
+ tool[i] = libinput_event_tablet_get_tool(t);
+ }
+
+ libinput_event_destroy(event);
+ }
+ }
+
+ /* We should get the same object for both devices */
+ ck_assert_notnull(tool[0]);
+ ck_assert_notnull(tool[1]);
+ ck_assert_ptr_eq(tool[0], tool[1]);
+
+ litest_delete_device(dev[0]);
+ litest_delete_device(dev[1]);
+ libinput_unref(li);
+}
+END_TEST
+
+START_TEST(tools_without_serials)
+{
+ struct libinput *li = litest_create_context();
+ struct litest_device *dev[2];
+ struct libinput_tool *tool[2] = {0};
+ struct libinput_event *event;
+ int i;
+
+ for (i = 0; i < 2; i++) {
+ dev[i] = litest_add_device_with_overrides(li,
+ LITEST_WACOM_ISDV4,
+ NULL,
+ NULL,
+ NULL,
+ NULL);
+
+ /* WARNING: this test fails if UI_GET_SYSNAME isn't
+ * available or isn't used by libevdev (1.3, commit 2ff45c73).
+ * Put a sleep(1) here and that usually fixes it.
+ */
+
+ litest_event(dev[i], EV_KEY, BTN_TOOL_PEN, 1);
+ litest_event(dev[i], EV_SYN, SYN_REPORT, 0);
+
+ libinput_dispatch(li);
+ while ((event = libinput_get_event(li))) {
+ if (libinput_event_get_type(event) ==
+ LIBINPUT_EVENT_TABLET_PROXIMITY) {
+ struct libinput_event_tablet *t =
+ libinput_event_get_tablet_event(event);
+
+ tool[i] = libinput_event_tablet_get_tool(t);
+ }
+
+ libinput_event_destroy(event);
+ }
+ }
+
+ /* We should get different tool objects for each device */
+ ck_assert_notnull(tool[0]);
+ ck_assert_notnull(tool[1]);
+ ck_assert_ptr_ne(tool[0], tool[1]);
+
+ litest_delete_device(dev[0]);
+ litest_delete_device(dev[1]);
+ libinput_unref(li);
+}
+END_TEST
+
+START_TEST(tool_capabilities)
+{
+ struct libinput *li = litest_create_context();
+ struct litest_device *intuos;
+ struct litest_device *bamboo;
+ struct libinput_event *event;
+ struct libinput_event_tablet *t;
+ struct libinput_tool *tool;
+
+ /* The axis capabilities of a tool can differ depending on the type of
+ * tablet the tool is being used with */
+ bamboo = litest_add_device(li, LITEST_WACOM_BAMBOO);
+ intuos = litest_add_device(li, LITEST_WACOM_INTUOS);
+
+ litest_event(bamboo, EV_KEY, BTN_TOOL_PEN, 1);
+ litest_event(bamboo, EV_SYN, SYN_REPORT, 0);
+
+ libinput_dispatch(li);
+
+ litest_wait_for_event_of_type(li,
+ LIBINPUT_EVENT_TABLET_PROXIMITY,
+ -1);
+
+ event = libinput_get_event(li);
+ t = libinput_event_get_tablet_event(event);
+ tool = libinput_event_tablet_get_tool(t);
+
+ ck_assert(libinput_tool_has_axis(tool,
+ LIBINPUT_TABLET_AXIS_PRESSURE));
+ ck_assert(libinput_tool_has_axis(tool,
+ LIBINPUT_TABLET_AXIS_DISTANCE));
+ ck_assert(!libinput_tool_has_axis(tool,
+ LIBINPUT_TABLET_AXIS_TILT_X));
+ ck_assert(!libinput_tool_has_axis(tool,
+ LIBINPUT_TABLET_AXIS_TILT_Y));
+
+ libinput_event_destroy(event);
+ litest_assert_empty_queue(li);
+
+ litest_event(intuos, EV_KEY, BTN_TOOL_PEN, 1);
+ litest_event(intuos, EV_SYN, SYN_REPORT, 0);
+
+ litest_wait_for_event_of_type(li,
+ LIBINPUT_EVENT_TABLET_PROXIMITY,
+ -1);
+
+ event = libinput_get_event(li);
+ t = libinput_event_get_tablet_event(event);
+ tool = libinput_event_tablet_get_tool(t);
+
+ ck_assert(libinput_tool_has_axis(tool,
+ LIBINPUT_TABLET_AXIS_PRESSURE));
+ ck_assert(libinput_tool_has_axis(tool,
+ LIBINPUT_TABLET_AXIS_DISTANCE));
+ ck_assert(libinput_tool_has_axis(tool,
+ LIBINPUT_TABLET_AXIS_TILT_X));
+ ck_assert(libinput_tool_has_axis(tool,
+ LIBINPUT_TABLET_AXIS_TILT_Y));
+
+ libinput_event_destroy(event);
+ litest_assert_empty_queue(li);
+
+ litest_delete_device(bamboo);
+ litest_delete_device(intuos);
+ libinput_unref(li);
+}
+END_TEST
+
+START_TEST(tool_in_prox_before_start)
+{
+ struct libinput *li;
+ struct litest_device *dev = litest_current_device();
+ struct libinput_event *event;
+ struct axis_replacement axes[] = {
+ { ABS_DISTANCE, 10 },
+ { ABS_TILT_X, 0 },
+ { ABS_TILT_Y, 0 },
+ { -1, -1 }
+ };
+ const char *devnode;
+
+ litest_tablet_proximity_in(dev, 10, 10, axes);
+
+ /* for simplicity, we create a new litest context */
+ devnode = libevdev_uinput_get_devnode(dev->uinput);
+ li = litest_create_context();
+ libinput_path_add_device(li, devnode);
+
+ litest_wait_for_event_of_type(li,
+ LIBINPUT_EVENT_DEVICE_ADDED,
+ -1);
+ event = libinput_get_event(li);
+ libinput_event_destroy(event);
+
+ litest_wait_for_event_of_type(li,
+ LIBINPUT_EVENT_TABLET_PROXIMITY,
+ -1);
+ event = libinput_get_event(li);
+ libinput_event_destroy(event);
+ litest_assert_empty_queue(li);
+
+ litest_tablet_motion(dev, 10, 20, axes);
+ litest_tablet_motion(dev, 30, 40, axes);
+
+ litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_AXIS);
+ litest_assert_empty_queue(li);
+ litest_event(dev, EV_KEY, BTN_STYLUS, 1);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+ litest_event(dev, EV_KEY, BTN_STYLUS, 1);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+ litest_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_BUTTON);
+ litest_tablet_proximity_out(dev);
+
+ litest_wait_for_event_of_type(li,
+ LIBINPUT_EVENT_TABLET_PROXIMITY,
+ -1);
+ libinput_unref(li);
+}
+END_TEST
+
+START_TEST(mouse_tool)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ struct libinput_event *event;
+ struct libinput_event_tablet *tev;
+ struct libinput_tool *tool;
+
+ if (!libevdev_has_event_code(dev->evdev,
+ EV_KEY,
+ BTN_TOOL_MOUSE))
+ return;
+
+ litest_drain_events(li);
+
+ litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 1);
+ litest_event(dev, EV_MSC, MSC_SERIAL, 1000);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+ litest_wait_for_event_of_type(li,
+ LIBINPUT_EVENT_TABLET_PROXIMITY,
+ -1);
+ event = libinput_get_event(li);
+ tev = libinput_event_get_tablet_event(event);
+ tool = libinput_event_tablet_get_tool(tev);
+ ck_assert_notnull(tool);
+ ck_assert_int_eq(libinput_tool_get_type(tool),
+ LIBINPUT_TOOL_MOUSE);
+
+ libinput_event_destroy(event);
+}
+END_TEST
+
+START_TEST(mouse_buttons)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ struct libinput_event *event;
+ struct libinput_event_tablet *tev;
+ struct libinput_tool *tool;
+ int code;
+
+ if (!libevdev_has_event_code(dev->evdev,
+ EV_KEY,
+ BTN_TOOL_MOUSE))
+ return;
+
+ litest_drain_events(li);
+
+ litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 1);
+ litest_event(dev, EV_ABS, ABS_MISC, 0x806); /* 5-button mouse tool_id */
+ litest_event(dev, EV_MSC, MSC_SERIAL, 1000);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+ litest_wait_for_event_of_type(li,
+ LIBINPUT_EVENT_TABLET_PROXIMITY,
+ -1);
+ event = libinput_get_event(li);
+ tev = libinput_event_get_tablet_event(event);
+ tool = libinput_event_tablet_get_tool(tev);
+ ck_assert_notnull(tool);
+ libinput_tool_ref(tool);
+
+ libinput_event_destroy(event);
+
+ for (code = BTN_LEFT; code <= BTN_TASK; code++) {
+ bool has_button = libevdev_has_event_code(dev->evdev,
+ EV_KEY,
+ code);
+ ck_assert_int_eq(!!has_button,
+ !!libinput_tool_has_button(tool, code));
+
+ if (!has_button)
+ continue;
+
+ litest_event(dev, EV_KEY, code, 1);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+ libinput_dispatch(li);
+ litest_event(dev, EV_KEY, code, 0);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+ libinput_dispatch(li);
+
+ litest_assert_tablet_button_event(li,
+ code,
+ LIBINPUT_BUTTON_STATE_PRESSED);
+ litest_assert_tablet_button_event(li,
+ code,
+ LIBINPUT_BUTTON_STATE_RELEASED);
+ }
+
+ libinput_tool_unref(tool);
+}
+END_TEST
+
+START_TEST(mouse_rotation)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ struct libinput_event *event;
+ struct libinput_event_tablet *tev;
+ int angle;
+ int tilt_center_x, tilt_center_y;
+ const struct input_absinfo *abs;
+ double val, old_val = 0;
+
+ struct axis_replacement axes[] = {
+ { ABS_DISTANCE, 10 },
+ { ABS_TILT_X, 0 },
+ { ABS_TILT_Y, 0 },
+ { -1, -1 }
+ };
+
+ if (!libevdev_has_event_code(dev->evdev,
+ EV_KEY,
+ BTN_TOOL_MOUSE))
+ return;
+
+ abs = libevdev_get_abs_info(dev->evdev, ABS_TILT_X);
+ ck_assert_notnull(abs);
+ tilt_center_x = (abs->maximum - abs->minimum + 1) / 2;
+
+ abs = libevdev_get_abs_info(dev->evdev, ABS_TILT_Y);
+ ck_assert_notnull(abs);
+ tilt_center_y = (abs->maximum - abs->minimum + 1) / 2;
+
+ litest_drain_events(li);
+
+ litest_push_event_frame(dev);
+ litest_tablet_proximity_in(dev, 10, 10, axes);
+ litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 1);
+ litest_pop_event_frame(dev);
+
+ litest_drain_events(li);
+
+ /* cos/sin are 90 degrees offset from the north-is-zero that
+ libinput uses. 175 is the CCW offset in the mouse HW */
+ for (angle = 5; angle < 360; angle += 5) {
+ double a = (angle - 90 - 175)/180.0 * M_PI;
+ int x, y;
+
+ x = cos(a) * 20 + tilt_center_x;
+ y = sin(a) * 20 + tilt_center_y;
+
+ litest_event(dev, EV_ABS, ABS_TILT_X, x);
+ litest_event(dev, EV_ABS, ABS_TILT_Y, y);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+ litest_wait_for_event_of_type(li,
+ LIBINPUT_EVENT_TABLET_AXIS,
+ -1);
+ event = libinput_get_event(li);
+ tev = libinput_event_get_tablet_event(event);
+ ck_assert(libinput_event_tablet_axis_has_changed(tev,
+ LIBINPUT_TABLET_AXIS_ROTATION_Z));
+ val = libinput_event_tablet_get_axis_value(tev,
+ LIBINPUT_TABLET_AXIS_ROTATION_Z);
+
+ /* rounding error galore, we can't test for anything more
+ precise than these */
+ litest_assert_double_lt(val, 360.0);
+ litest_assert_double_gt(val, old_val);
+ litest_assert_double_lt(val, angle + 5);
+
+ old_val = val;
+ libinput_event_destroy(event);
+ litest_assert_empty_queue(li);
+ }
+}
+END_TEST
+
+START_TEST(mouse_wheel)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ struct libinput_event *event;
+ struct libinput_event_tablet *tev;
+ struct libinput_tool *tool;
+ const struct input_absinfo *abs;
+ double val;
+ int i;
+
+ if (!libevdev_has_event_code(dev->evdev,
+ EV_REL,
+ REL_WHEEL))
+ return;
+
+ litest_drain_events(li);
+
+ litest_event(dev, EV_KEY, BTN_TOOL_MOUSE, 1);
+ litest_event(dev, EV_ABS, ABS_MISC, 0x806); /* 5-button mouse tool_id */
+ litest_event(dev, EV_MSC, MSC_SERIAL, 1000);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+ litest_wait_for_event_of_type(li,
+ LIBINPUT_EVENT_TABLET_PROXIMITY,
+ -1);
+ event = libinput_get_event(li);
+ tev = libinput_event_get_tablet_event(event);
+ tool = libinput_event_tablet_get_tool(tev);
+ ck_assert_notnull(tool);
+ libinput_tool_ref(tool);
+
+ libinput_event_destroy(event);
+
+ ck_assert(libinput_tool_has_axis(tool,
+ LIBINPUT_TABLET_AXIS_REL_WHEEL));
+
+ for (i = 0; i < 3; i++) {
+ litest_event(dev, EV_REL, REL_WHEEL, -1);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+ litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_AXIS, -1);
+
+ event = libinput_get_event(li);
+ tev = libinput_event_get_tablet_event(event);
+ ck_assert(libinput_event_tablet_axis_has_changed(tev,
+ LIBINPUT_TABLET_AXIS_REL_WHEEL));
+ val = libinput_event_tablet_get_axis_value(tev,
+ LIBINPUT_TABLET_AXIS_REL_WHEEL);
+ ck_assert_int_eq(val, 0);
+
+ 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_REL_WHEEL);
+ ck_assert_int_eq(val, 1);
+
+ libinput_event_destroy(event);
+
+ litest_assert_empty_queue(li);
+ }
+
+ for (i = 2; i < 5; i++) {
+ /* send x/y events to make sure we reset the wheel */
+ abs = libevdev_get_abs_info(dev->evdev, ABS_X);
+ litest_event(dev, EV_ABS, ABS_X, (abs->maximum - abs->minimum)/i);
+ abs = libevdev_get_abs_info(dev->evdev, ABS_Y);
+ litest_event(dev, EV_ABS, ABS_Y, (abs->maximum - abs->minimum)/i);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+ litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_AXIS, -1);
+
+ event = libinput_get_event(li);
+ tev = libinput_event_get_tablet_event(event);
+ ck_assert(!libinput_event_tablet_axis_has_changed(tev,
+ LIBINPUT_TABLET_AXIS_REL_WHEEL));
+ val = libinput_event_tablet_get_axis_value(tev,
+ LIBINPUT_TABLET_AXIS_REL_WHEEL);
+ ck_assert_int_eq(val, 0);
+
+ val = libinput_event_tablet_get_axis_delta(tev,
+ LIBINPUT_TABLET_AXIS_REL_WHEEL);
+ ck_assert_int_eq(val, 0);
+
+ val = libinput_event_tablet_get_axis_delta_discrete(tev,
+ LIBINPUT_TABLET_AXIS_ROTATION_Z);
+ ck_assert_int_eq(val, 0);
+
+ libinput_event_destroy(event);
+
+ litest_assert_empty_queue(li);
+ }
+
+ libinput_tool_unref(tool);
+}
+END_TEST
+
+START_TEST(airbrush_tool)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ struct libinput_event *event;
+ struct libinput_event_tablet *tev;
+ struct libinput_tool *tool;
+
+ if (!libevdev_has_event_code(dev->evdev,
+ EV_KEY,
+ BTN_TOOL_AIRBRUSH))
+ return;
+
+ litest_drain_events(li);
+
+ litest_event(dev, EV_KEY, BTN_TOOL_AIRBRUSH, 1);
+ litest_event(dev, EV_MSC, MSC_SERIAL, 1000);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+ litest_wait_for_event_of_type(li,
+ LIBINPUT_EVENT_TABLET_PROXIMITY,
+ -1);
+ event = libinput_get_event(li);
+ tev = libinput_event_get_tablet_event(event);
+ tool = libinput_event_tablet_get_tool(tev);
+ ck_assert_notnull(tool);
+ ck_assert_int_eq(libinput_tool_get_type(tool),
+ LIBINPUT_TOOL_AIRBRUSH);
+
+ libinput_event_destroy(event);
+}
+END_TEST
+
+START_TEST(airbrush_wheel)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ struct libinput_event *event;
+ struct libinput_event_tablet *tev;
+ const struct input_absinfo *abs;
+ double val;
+ double scale;
+ int v;
+
+ if (!libevdev_has_event_code(dev->evdev,
+ EV_KEY,
+ BTN_TOOL_AIRBRUSH))
+ return;
+
+ litest_drain_events(li);
+
+ abs = libevdev_get_abs_info(dev->evdev, ABS_WHEEL);
+ ck_assert_notnull(abs);
+
+ litest_event(dev, EV_KEY, BTN_TOOL_AIRBRUSH, 1);
+ litest_event(dev, EV_MSC, MSC_SERIAL, 1000);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+ /* start with non-zero */
+ litest_event(dev, EV_ABS, ABS_WHEEL, 10);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+ litest_drain_events(li);
+
+ scale = abs->maximum - abs->minimum;
+ for (v = abs->minimum; v < abs->maximum; v += 8) {
+ litest_event(dev, EV_ABS, ABS_WHEEL, v);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+ litest_wait_for_event_of_type(li,
+ LIBINPUT_EVENT_TABLET_AXIS,
+ -1);
+ event = libinput_get_event(li);
+ tev = libinput_event_get_tablet_event(event);
+ ck_assert(libinput_event_tablet_axis_has_changed(tev,
+ LIBINPUT_TABLET_AXIS_SLIDER));
+ val = libinput_event_tablet_get_axis_value(tev,
+ LIBINPUT_TABLET_AXIS_SLIDER);
+
+ ck_assert_int_eq(val, (v - abs->minimum)/scale);
+ libinput_event_destroy(event);
+ litest_assert_empty_queue(li);
+ }
+}
+END_TEST
+
+START_TEST(artpen_tool)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ struct libinput_event *event;
+ struct libinput_event_tablet *tev;
+ struct libinput_tool *tool;
+
+ if (!libevdev_has_event_code(dev->evdev,
+ EV_ABS,
+ ABS_Z))
+ return;
+
+ litest_drain_events(li);
+
+ litest_event(dev, EV_KEY, BTN_TOOL_PEN, 1);
+ litest_event(dev, EV_ABS, ABS_MISC, 0x804); /* Art Pen */
+ litest_event(dev, EV_MSC, MSC_SERIAL, 1000);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+ litest_wait_for_event_of_type(li,
+ LIBINPUT_EVENT_TABLET_PROXIMITY,
+ -1);
+ event = libinput_get_event(li);
+ tev = libinput_event_get_tablet_event(event);
+ tool = libinput_event_tablet_get_tool(tev);
+ ck_assert_notnull(tool);
+ ck_assert_int_eq(libinput_tool_get_type(tool),
+ LIBINPUT_TOOL_PEN);
+ ck_assert(libinput_tool_has_axis(tool,
+ LIBINPUT_TABLET_AXIS_ROTATION_Z));
+
+ libinput_event_destroy(event);
+}
+END_TEST
+
+START_TEST(artpen_rotation)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ struct libinput_event *event;
+ struct libinput_event_tablet *tev;
+ const struct input_absinfo *abs;
+ double val;
+ double scale;
+ int angle;
+
+ if (!libevdev_has_event_code(dev->evdev,
+ EV_ABS,
+ ABS_Z))
+ return;
+
+ litest_drain_events(li);
+
+ abs = libevdev_get_abs_info(dev->evdev, ABS_Z);
+ ck_assert_notnull(abs);
+ scale = (abs->maximum - abs->minimum + 1)/360.0;
+
+ litest_event(dev, EV_KEY, BTN_TOOL_BRUSH, 1);
+ litest_event(dev, EV_ABS, ABS_MISC, 0x804); /* Art Pen */
+ litest_event(dev, EV_MSC, MSC_SERIAL, 1000);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+ litest_event(dev, EV_ABS, ABS_Z, abs->minimum);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+ litest_drain_events(li);
+
+ for (angle = 8; angle < 360; angle += 8) {
+ int a = angle * scale + abs->minimum;
+
+ litest_event(dev, EV_ABS, ABS_Z, a);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+
+ litest_wait_for_event_of_type(li,
+ LIBINPUT_EVENT_TABLET_AXIS,
+ -1);
+ event = libinput_get_event(li);
+ tev = libinput_event_get_tablet_event(event);
+ ck_assert(libinput_event_tablet_axis_has_changed(tev,
+ LIBINPUT_TABLET_AXIS_ROTATION_Z));
+ val = libinput_event_tablet_get_axis_value(tev,
+ LIBINPUT_TABLET_AXIS_ROTATION_Z);
+
+ /* artpen has a 90 deg offset cw */
+ ck_assert_int_eq(round(val), (angle + 90) % 360);
+
+ val = libinput_event_tablet_get_axis_delta(tev,
+ LIBINPUT_TABLET_AXIS_ROTATION_Z);
+ ck_assert_int_eq(val, 8);
+
+ libinput_event_destroy(event);
+ litest_assert_empty_queue(li);
+
+ }
+}
+END_TEST
+
+START_TEST(tablet_time_usec)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ struct libinput_event *event;
+ struct libinput_event_tablet *tev;
+ struct axis_replacement axes[] = {
+ { ABS_DISTANCE, 10 },
+ { -1, -1 }
+ };
+
+ litest_drain_events(li);
+
+ litest_tablet_proximity_in(dev, 5, 100, axes);
+ libinput_dispatch(li);
+
+ litest_wait_for_event_of_type(li,
+ LIBINPUT_EVENT_TABLET_PROXIMITY,
+ -1);
+ event = libinput_get_event(li);
+ tev = libinput_event_get_tablet_event(event);
+ ck_assert_int_eq(libinput_event_tablet_get_time(tev),
+ libinput_event_tablet_get_time_usec(tev) / 1000);
+ libinput_event_destroy(event);
+}
+END_TEST
+
+void
+litest_setup_tests(void)
+{
+ litest_add("tablet:tool", tool_ref, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY);
+ litest_add_no_device("tablet:tool", tool_capabilities);
+ litest_add("tablet:tool", tool_in_prox_before_start, LITEST_TABLET, LITEST_ANY);
+ litest_add("tablet:tool_serial", tool_serial, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY);
+ litest_add("tablet:tool_serial", serial_changes_tool, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY);
+ litest_add("tablet:tool_serial", invalid_serials, LITEST_TABLET | LITEST_TOOL_SERIAL, LITEST_ANY);
+ litest_add_no_device("tablet:tool_serial", tools_with_serials);
+ litest_add_no_device("tablet:tool_serial", tools_without_serials);
+ litest_add("tablet:proximity", proximity_out_clear_buttons, LITEST_TABLET, LITEST_ANY);
+ litest_add("tablet:proximity", proximity_in_out, LITEST_TABLET, LITEST_ANY);
+ litest_add("tablet:proximity", proximity_has_axes, LITEST_TABLET, LITEST_ANY);
+ litest_add("tablet:proximity", bad_distance_events, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY);
+ litest_add("tablet:motion", motion, LITEST_TABLET, LITEST_ANY);
+ litest_add("tablet:motion", motion_delta, LITEST_TABLET, LITEST_ANY);
+ litest_add("tablet:motion", motion_delta_partial, LITEST_TABLET, LITEST_ANY);
+ litest_add("tablet:motion", motion_event_state, LITEST_TABLET, LITEST_ANY);
+ litest_add_for_device("tablet:left_handed", left_handed, LITEST_WACOM_INTUOS);
+ litest_add_for_device("tablet:left_handed", no_left_handed, LITEST_WACOM_CINTIQ);
+ litest_add("tablet:normalization", normalization, LITEST_TABLET, LITEST_ANY);
+ litest_add("tablet:pad", pad_buttons_ignored, LITEST_TABLET, LITEST_ANY);
+ litest_add("tablet:mouse", mouse_tool, LITEST_TABLET, LITEST_ANY);
+ litest_add("tablet:mouse", mouse_buttons, LITEST_TABLET, LITEST_ANY);
+ litest_add("tablet:mouse", mouse_rotation, LITEST_TABLET, LITEST_ANY);
+ litest_add("tablet:mouse", mouse_wheel, LITEST_TABLET, LITEST_WHEEL);
+ litest_add("tablet:airbrush", airbrush_tool, LITEST_TABLET, LITEST_ANY);
+ litest_add("tablet:airbrush", airbrush_wheel, LITEST_TABLET, LITEST_ANY);
+ litest_add("tablet:artpen", artpen_tool, LITEST_TABLET, LITEST_ANY);
+ litest_add("tablet:artpen", artpen_rotation, LITEST_TABLET, LITEST_ANY);
+
+ litest_add("tablet:time", tablet_time_usec, LITEST_TABLET, LITEST_ANY);
+}
diff --git a/test/valgrind.suppressions b/test/valgrind.suppressions
index 50b5c58a..b7f43499 100644
--- a/test/valgrind.suppressions
+++ b/test/valgrind.suppressions
@@ -14,6 +14,24 @@
fun:mtdev_put_event
}
{
+ <g_type_register_static>
+ Memcheck:Leak
+ ...
+ fun:g_type_register_static
+}
+{
+ <g_type_register_static>
+ Memcheck:Leak
+ ...
+ fun:g_type_register_fundamental
+}
+{
+ <g_type_register_static>
+ Memcheck:Leak
+ ...
+ fun:g_malloc0
+}
+{
libunwind:msync_uninitialized_bytes
Memcheck:Param
msync(start)
diff --git a/tools/event-debug.c b/tools/event-debug.c
index 1ac00864..3e315beb 100644
--- a/tools/event-debug.c
+++ b/tools/event-debug.c
@@ -108,9 +108,18 @@ print_event_header(struct libinput_event *ev)
case LIBINPUT_EVENT_GESTURE_PINCH_END:
type = "GESTURE_PINCH_END";
break;
+ case LIBINPUT_EVENT_TABLET_AXIS:
+ type = "TABLET_AXIS";
+ break;
+ case LIBINPUT_EVENT_TABLET_PROXIMITY:
+ type = "TABLET_PROXIMITY";
+ break;
+ case LIBINPUT_EVENT_TABLET_BUTTON:
+ type = "TABLET_BUTTON";
+ break;
}
- printf("%-7s %s ", libinput_device_get_sysname(dev), type);
+ printf("%-7s %-16s ", libinput_device_get_sysname(dev), type);
}
static void
@@ -156,6 +165,9 @@ print_device_notify(struct libinput_event *ev)
if (libinput_device_has_capability(dev,
LIBINPUT_DEVICE_CAP_GESTURE))
printf("g");
+ if (libinput_device_has_capability(dev,
+ LIBINPUT_DEVICE_CAP_TABLET))
+ printf("T");
if (libinput_device_get_size(dev, &w, &h) == 0)
printf("\tsize %.2f/%.2fmm", w, h);
@@ -251,7 +263,7 @@ print_absmotion_event(struct libinput_event *ev)
}
static void
-print_button_event(struct libinput_event *ev)
+print_pointer_button_event(struct libinput_event *ev)
{
struct libinput_event_pointer *p = libinput_event_get_pointer_event(ev);
enum libinput_button_state state;
@@ -266,7 +278,22 @@ print_button_event(struct libinput_event *ev)
}
static void
-print_axis_event(struct libinput_event *ev)
+print_tablet_button_event(struct libinput_event *ev)
+{
+ struct libinput_event_tablet *p = libinput_event_get_tablet_event(ev);
+ enum libinput_button_state state;
+
+ print_event_time(libinput_event_tablet_get_time(p));
+
+ state = libinput_event_tablet_get_button_state(p);
+ printf("%3d %s, seat count: %u\n",
+ libinput_event_tablet_get_button(p),
+ state == LIBINPUT_BUTTON_STATE_PRESSED ? "pressed" : "released",
+ libinput_event_tablet_get_seat_button_count(p));
+}
+
+static void
+print_pointer_axis_event(struct libinput_event *ev)
{
struct libinput_event_pointer *p = libinput_event_get_pointer_event(ev);
double v = 0, h = 0;
@@ -283,6 +310,124 @@ print_axis_event(struct libinput_event *ev)
printf("vert %.2f horiz %.2f\n", v, h);
}
+static const char*
+tablet_axis_changed_sym(struct libinput_event_tablet *t,
+ enum libinput_tablet_axis axis)
+{
+ if (libinput_event_tablet_axis_has_changed(t, axis))
+ return "*";
+ else
+ return "";
+}
+
+static void
+print_tablet_axes(struct libinput_event_tablet *t)
+{
+ struct libinput_tool *tool = libinput_event_tablet_get_tool(t);
+ double x, y, dx, dy;
+ double dist, pressure;
+ double rotation, slider, wheel;
+ double delta;
+
+ x = libinput_event_tablet_get_axis_value(t, LIBINPUT_TABLET_AXIS_X);
+ y = libinput_event_tablet_get_axis_value(t, LIBINPUT_TABLET_AXIS_Y);
+ dx = libinput_event_tablet_get_axis_delta(t, LIBINPUT_TABLET_AXIS_X);
+ dy = libinput_event_tablet_get_axis_delta(t, LIBINPUT_TABLET_AXIS_Y);
+ printf("\t%.2f%s/%.2f%s (%.2f/%.2f)",
+ x, tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_X),
+ y, tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_Y),
+ dx, dy);
+
+ if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_TILT_X) ||
+ libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_TILT_Y)) {
+ x = libinput_event_tablet_get_axis_value(t,
+ LIBINPUT_TABLET_AXIS_TILT_X);
+ y = libinput_event_tablet_get_axis_value(t,
+ LIBINPUT_TABLET_AXIS_TILT_Y);
+ dx = libinput_event_tablet_get_axis_delta(t,
+ LIBINPUT_TABLET_AXIS_TILT_X);
+ dy = libinput_event_tablet_get_axis_delta(t,
+ LIBINPUT_TABLET_AXIS_TILT_Y);
+ printf("\ttilt: %.2f%s/%.2f%s (%.2f/%.2f)",
+ x, tablet_axis_changed_sym(t,
+ LIBINPUT_TABLET_AXIS_TILT_X),
+ y, tablet_axis_changed_sym(t,
+ LIBINPUT_TABLET_AXIS_TILT_Y),
+ dx, dy);
+ }
+
+ if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_DISTANCE) ||
+ libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_PRESSURE)) {
+ dist = libinput_event_tablet_get_axis_value(t,
+ LIBINPUT_TABLET_AXIS_DISTANCE);
+ pressure = libinput_event_tablet_get_axis_value(t,
+ LIBINPUT_TABLET_AXIS_PRESSURE);
+ if (dist) {
+ delta = libinput_event_tablet_get_axis_delta(t,
+ LIBINPUT_TABLET_AXIS_DISTANCE);
+ printf("\tdistance: %.2f%s (%.2f)",
+ dist,
+ tablet_axis_changed_sym(t,
+ LIBINPUT_TABLET_AXIS_DISTANCE),
+ delta);
+ } else {
+ delta = libinput_event_tablet_get_axis_delta(t,
+ LIBINPUT_TABLET_AXIS_PRESSURE);
+ printf("\tpressure: %.2f%s (%.2f)",
+ pressure,
+ tablet_axis_changed_sym(t,
+ LIBINPUT_TABLET_AXIS_PRESSURE),
+ delta);
+ }
+ }
+
+ if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_ROTATION_Z)) {
+ rotation = libinput_event_tablet_get_axis_value(t,
+ LIBINPUT_TABLET_AXIS_ROTATION_Z);
+ delta = libinput_event_tablet_get_axis_delta(t,
+ LIBINPUT_TABLET_AXIS_ROTATION_Z);
+ printf("\trotation: %.2f%s (%.2f)",
+ rotation,
+ tablet_axis_changed_sym(t,
+ LIBINPUT_TABLET_AXIS_ROTATION_Z),
+ delta);
+ }
+
+ if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_SLIDER)) {
+ slider = libinput_event_tablet_get_axis_value(t,
+ LIBINPUT_TABLET_AXIS_SLIDER);
+ delta = libinput_event_tablet_get_axis_delta(t,
+ LIBINPUT_TABLET_AXIS_SLIDER);
+ printf("\tslider: %.2f%s (%.2f)",
+ slider,
+ tablet_axis_changed_sym(t,
+ LIBINPUT_TABLET_AXIS_SLIDER),
+ delta);
+ }
+
+ 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_discrete(t,
+ LIBINPUT_TABLET_AXIS_REL_WHEEL);
+ printf("\twheel: %.2f%s (%d)",
+ wheel,
+ tablet_axis_changed_sym(t,
+ LIBINPUT_TABLET_AXIS_REL_WHEEL),
+ (int)delta);
+ }
+}
+
+static void
+print_tablet_axis_event(struct libinput_event *ev)
+{
+ struct libinput_event_tablet *t = libinput_event_get_tablet_event(ev);
+
+ print_event_time(libinput_event_tablet_get_time(t));
+ print_tablet_axes(t);
+ printf("\n");
+}
+
static void
print_touch_event_without_coords(struct libinput_event *ev)
{
@@ -293,6 +438,97 @@ print_touch_event_without_coords(struct libinput_event *ev)
}
static void
+print_proximity_event(struct libinput_event *ev)
+{
+ struct libinput_event_tablet *t = libinput_event_get_tablet_event(ev);
+ struct libinput_tool *tool = libinput_event_tablet_get_tool(t);
+ enum libinput_tool_proximity_state state;
+ const char *tool_str,
+ *state_str;
+
+ switch (libinput_tool_get_type(tool)) {
+ case LIBINPUT_TOOL_PEN:
+ tool_str = "pen";
+ break;
+ case LIBINPUT_TOOL_ERASER:
+ tool_str = "eraser";
+ break;
+ case LIBINPUT_TOOL_BRUSH:
+ tool_str = "brush";
+ break;
+ case LIBINPUT_TOOL_PENCIL:
+ tool_str = "pencil";
+ break;
+ case LIBINPUT_TOOL_AIRBRUSH:
+ tool_str = "airbrush";
+ break;
+ case LIBINPUT_TOOL_FINGER:
+ tool_str = "finger";
+ break;
+ case LIBINPUT_TOOL_MOUSE:
+ tool_str = "mouse";
+ break;
+ case LIBINPUT_TOOL_LENS:
+ tool_str = "lens";
+ break;
+ default:
+ abort();
+ }
+
+ state = libinput_event_tablet_get_proximity_state(t);
+
+ print_event_time(libinput_event_tablet_get_time(t));
+
+ if (state == LIBINPUT_TOOL_PROXIMITY_IN) {
+ print_tablet_axes(t);
+ state_str = "proximity-in";
+ } else if (state == LIBINPUT_TOOL_PROXIMITY_OUT) {
+ state_str = "proximity-out";
+ printf("\t");
+ } else {
+ abort();
+ }
+
+ printf("\t%s (%#x) %s",
+ tool_str, libinput_tool_get_serial(tool), state_str);
+
+ printf("\taxes:");
+ if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_DISTANCE))
+ printf("d");
+ if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_PRESSURE))
+ printf("p");
+ if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_TILT_X) ||
+ libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_TILT_Y))
+ printf("t");
+ if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_ROTATION_Z))
+ printf("r");
+ if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_SLIDER))
+ printf("s");
+ if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_REL_WHEEL))
+ printf("w");
+
+ printf("\tbtn:");
+ if (libinput_tool_has_button(tool, BTN_TOUCH))
+ printf("T");
+ if (libinput_tool_has_button(tool, BTN_STYLUS))
+ printf("S");
+ if (libinput_tool_has_button(tool, BTN_STYLUS2))
+ printf("S2");
+ if (libinput_tool_has_button(tool, BTN_LEFT))
+ printf("L");
+ if (libinput_tool_has_button(tool, BTN_MIDDLE))
+ printf("M");
+ if (libinput_tool_has_button(tool, BTN_RIGHT))
+ printf("R");
+ if (libinput_tool_has_button(tool, BTN_SIDE))
+ printf("Sd");
+ if (libinput_tool_has_button(tool, BTN_EXTRA))
+ printf("Ex");
+
+ printf("\n");
+}
+
+static void
print_touch_event_with_coords(struct libinput_event *ev)
{
struct libinput_event_touch *t = libinput_event_get_touch_event(ev);
@@ -383,10 +619,10 @@ handle_and_print_events(struct libinput *li)
print_absmotion_event(ev);
break;
case LIBINPUT_EVENT_POINTER_BUTTON:
- print_button_event(ev);
+ print_pointer_button_event(ev);
break;
case LIBINPUT_EVENT_POINTER_AXIS:
- print_axis_event(ev);
+ print_pointer_axis_event(ev);
break;
case LIBINPUT_EVENT_TOUCH_DOWN:
print_touch_event_with_coords(ev);
@@ -421,6 +657,15 @@ handle_and_print_events(struct libinput *li)
case LIBINPUT_EVENT_GESTURE_PINCH_END:
print_gesture_event_without_coords(ev);
break;
+ case LIBINPUT_EVENT_TABLET_AXIS:
+ print_tablet_axis_event(ev);
+ break;
+ case LIBINPUT_EVENT_TABLET_PROXIMITY:
+ print_proximity_event(ev);
+ break;
+ case LIBINPUT_EVENT_TABLET_BUTTON:
+ print_tablet_button_event(ev);
+ break;
}
libinput_event_destroy(ev);
diff --git a/tools/event-gui.c b/tools/event-gui.c
index 0b0e9d71..19324a3d 100644
--- a/tools/event-gui.c
+++ b/tools/event-gui.c
@@ -606,6 +606,10 @@ handle_event_libinput(GIOChannel *source, GIOCondition condition, gpointer data)
case LIBINPUT_EVENT_GESTURE_PINCH_END:
handle_event_pinch(ev, w);
break;
+ case LIBINPUT_EVENT_TABLET_AXIS:
+ case LIBINPUT_EVENT_TABLET_PROXIMITY:
+ case LIBINPUT_EVENT_TABLET_BUTTON:
+ break;
}
libinput_event_destroy(ev);
diff --git a/tools/libinput-list-devices.c b/tools/libinput-list-devices.c
index 21685d9b..d9f71bd8 100644
--- a/tools/libinput-list-devices.c
+++ b/tools/libinput-list-devices.c
@@ -257,6 +257,9 @@ print_device_notify(struct libinput_event *ev)
if (libinput_device_has_capability(dev,
LIBINPUT_DEVICE_CAP_TOUCH))
printf("touch");
+ if (libinput_device_has_capability(dev,
+ LIBINPUT_DEVICE_CAP_TABLET))
+ printf("tablet");
printf("\n");
printf("Tap-to-click: %s\n", tap_default(dev));