From 812ea542e7023c4a16c02a0c2264fb873d34abe4 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Wed, 21 May 2014 21:52:57 -0400 Subject: [PATCH 001/255] Add bitfield helper functions from libdevdev-util.h and some tests Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/libinput-util.h | 22 ++++++++++++++++++++++ test/misc.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/src/libinput-util.h b/src/libinput-util.h index 11c4f5c2..4488fbff 100644 --- a/src/libinput-util.h +++ b/src/libinput-util.h @@ -84,4 +84,26 @@ 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)); +} + #endif /* LIBINPUT_UTIL_H */ diff --git a/test/misc.c b/test/misc.c index 133bdb60..9ff31753 100644 --- a/test/misc.c +++ b/test/misc.c @@ -29,6 +29,7 @@ #include #include "litest.h" +#include "libinput-util.h" static int open_restricted(const char *path, int flags, void *data) { @@ -371,12 +372,50 @@ START_TEST(event_conversion_touch) } 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 + int main (int argc, char **argv) { litest_add_no_device("events:conversion", event_conversion_device_notify); litest_add_no_device("events:conversion", event_conversion_pointer); litest_add_no_device("events:conversion", event_conversion_pointer_abs); litest_add_no_device("events:conversion", event_conversion_key); litest_add_no_device("events:conversion", event_conversion_touch); + litest_add_no_device("bitfield_helpers", bitfield_helpers); return litest_run(argc, argv); } From 53affdc9bbdd3907f3eb3c62030c089e34340c0d Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Mon, 21 Apr 2014 19:11:17 +0200 Subject: [PATCH 002/255] Add LIBINPUT_DEVICE_CAP_TABLET libinput_device_capability value This capability flag would be enabled when events are driven through a stylus, ie. on a tablet. Signed-off-by: Carlos Garnacho Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev.c | 2 ++ src/evdev.h | 3 ++- src/libinput.h | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/evdev.c b/src/evdev.c index 51ad5e31..03f52e42 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -840,6 +840,8 @@ evdev_device_has_capability(struct evdev_device *device, return !!(device->seat_caps & EVDEV_DEVICE_KEYBOARD); case LIBINPUT_DEVICE_CAP_TOUCH: return !!(device->seat_caps & EVDEV_DEVICE_TOUCH); + 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 d057010b..bcb7e79d 100644 --- a/src/evdev.h +++ b/src/evdev.h @@ -45,7 +45,8 @@ enum evdev_event_type { enum evdev_device_seat_capability { EVDEV_DEVICE_POINTER = (1 << 0), EVDEV_DEVICE_KEYBOARD = (1 << 1), - EVDEV_DEVICE_TOUCH = (1 << 2) + EVDEV_DEVICE_TOUCH = (1 << 2), + EVDEV_DEVICE_TABLET = (1 << 3), }; struct mt_slot { diff --git a/src/libinput.h b/src/libinput.h index 54c96e58..d6f25885 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -121,7 +121,8 @@ enum libinput_log_priority { enum libinput_device_capability { LIBINPUT_DEVICE_CAP_KEYBOARD = 0, LIBINPUT_DEVICE_CAP_POINTER = 1, - LIBINPUT_DEVICE_CAP_TOUCH = 2 + LIBINPUT_DEVICE_CAP_TOUCH = 2, + LIBINPUT_DEVICE_CAP_TABLET = 3 }; /** From 9357166114159b16078ee18c9b64a527270abca8 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Thu, 5 Jun 2014 23:20:36 -0400 Subject: [PATCH 003/255] evdev: Add basic support for tablet devices These devices set the LIBINPUT_DEVICE_CAP_TABLET flag, and emit a lot more axis information then mice and touchpads. As such, tablet events are in a whole new group of events that is separate from everything else. In this commit, only X and Y axes are reported in libinput. Based off the patch originally written by Carlos Garnacho Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/Makefile.am | 2 + src/evdev-tablet.c | 181 +++++++++++++++++++++++++++++++++++++++++ src/evdev-tablet.h | 82 +++++++++++++++++++ src/evdev.c | 8 ++ src/evdev.h | 3 + src/libinput-private.h | 6 ++ src/libinput-util.h | 2 + src/libinput.c | 109 +++++++++++++++++++++++++ src/libinput.h | 121 ++++++++++++++++++++++++++- 9 files changed, 513 insertions(+), 1 deletion(-) create mode 100644 src/evdev-tablet.c create mode 100644 src/evdev-tablet.h diff --git a/src/Makefile.am b/src/Makefile.am index bf561845..b880a699 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -11,6 +11,8 @@ libinput_la_SOURCES = \ libinput-util.h \ evdev.c \ evdev.h \ + evdev-tablet.c \ + evdev-tablet.h \ evdev-mt-touchpad.c \ evdev-mt-touchpad.h \ evdev-mt-touchpad-tap.c \ diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c new file mode 100644 index 00000000..a12b6709 --- /dev/null +++ b/src/evdev-tablet.c @@ -0,0 +1,181 @@ +/* + * 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 +#include +#include + +#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 void +tablet_process_absolute(struct tablet_dispatch *tablet, + struct evdev_device *device, + struct input_event *e, + uint32_t time) +{ + enum libinput_tablet_axis axis; + + switch (e->code) { + case ABS_X: + case ABS_Y: + axis = evcode_to_axis(e->code); + if (axis == LIBINPUT_TABLET_AXIS_NONE) { + log_bug_libinput("Invalid ABS event code %#x\n", + e->code); + break; + } + + set_bit(tablet->changed_axes, axis); + tablet_set_status(tablet, TABLET_AXES_UPDATED); + break; + default: + log_info("Unhandled ABS event code %#x\n", e->code); + break; + } +} + +static void +tablet_check_notify_axes(struct tablet_dispatch *tablet, + struct evdev_device *device, + uint32_t time) +{ + struct libinput_device *base = &device->base; + bool axis_update_needed = false; + int a; + + for (a = 0; a < LIBINPUT_TABLET_AXIS_CNT; a++) { + const struct input_absinfo *absinfo; + + if (!bit_is_set(tablet->changed_axes, a)) + continue; + + absinfo = libevdev_get_abs_info(device->evdev, + axis_to_evcode(a)); + + switch (a) { + case LIBINPUT_TABLET_AXIS_X: + case LIBINPUT_TABLET_AXIS_Y: + tablet->axes[a] = absinfo->value; + break; + default: + log_bug_libinput("Invalid axis update: %d\n", a); + break; + } + + axis_update_needed = true; + } + + if (axis_update_needed) { + tablet_notify_axis(base, time, tablet->changed_axes, tablet->axes); + memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes)); + } +} + +static void +tablet_flush(struct tablet_dispatch *tablet, + struct evdev_device *device, + uint32_t time) +{ + if (tablet_has_status(tablet, TABLET_AXES_UPDATED)) { + tablet_check_notify_axes(tablet, device, time); + tablet_unset_status(tablet, TABLET_AXES_UPDATED); + } +} + +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_SYN: + tablet_flush(tablet, device, time); + break; + default: + log_error("Unexpected event type %#x\n", e->type); + break; + } +} + +static void +tablet_destroy(struct evdev_dispatch *dispatch) +{ + struct tablet_dispatch *tablet = + (struct tablet_dispatch*)dispatch; + + free(tablet); +} + +static struct evdev_dispatch_interface tablet_interface = { + tablet_process, + tablet_destroy +}; + +static int +tablet_init(struct tablet_dispatch *tablet, + struct evdev_device *device) +{ + enum libinput_tablet_axis a; + + tablet->base.interface = &tablet_interface; + tablet->device = device; + tablet->status = TABLET_NONE; + + /* Mark any axes the tablet has as changed */ + for (a = 0; a < LIBINPUT_TABLET_AXIS_CNT; a++) { + if (libevdev_has_event_code(device->evdev, + EV_ABS, + axis_to_evcode(a))) + set_bit(tablet->changed_axes, a); + } + + return 0; +} + +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; + } + + return &tablet->base; +} diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h new file mode 100644 index 00000000..551bcafd --- /dev/null +++ b/src/evdev-tablet.h @@ -0,0 +1,82 @@ +/* + * 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" + +enum tablet_status { + TABLET_NONE = 0, + TABLET_AXES_UPDATED = 1 << 0 +}; + +struct tablet_dispatch { + struct evdev_dispatch base; + struct evdev_device *device; + unsigned char status; + unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_AXIS_CNT)]; + double axes[LIBINPUT_TABLET_AXIS_CNT]; +}; + +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; + 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; + default: + abort(); + } + + return evcode; +} + +#endif diff --git a/src/evdev.c b/src/evdev.c index 03f52e42..597977c4 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -672,7 +672,15 @@ evdev_configure_device(struct evdev_device *device) device->dispatch = evdev_mt_touchpad_create(device); log_info("input device '%s', %s is a touchpad\n", device->devname, device->devnode); + } else if (!libevdev_has_event_code(device->evdev, EV_KEY, BTN_TOOL_FINGER) && + libevdev_has_event_code(device->evdev, EV_KEY, BTN_TOOL_PEN) && + has_abs) { + device->dispatch = evdev_tablet_create(device); + device->seat_caps |= EVDEV_DEVICE_TABLET; + log_info("input device '%s', %s is a tablet\n", + device->devname, device->devnode); } + for (i = KEY_ESC; i < KEY_MAX; i++) { if (i >= BTN_MISC && i < KEY_OK) continue; diff --git a/src/evdev.h b/src/evdev.h index bcb7e79d..1164b7c0 100644 --- a/src/evdev.h +++ b/src/evdev.h @@ -127,6 +127,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_device_proces_event(struct libinput_event *event); diff --git a/src/libinput-private.h b/src/libinput-private.h index f0bda1f8..f6ba51ca 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -194,6 +194,12 @@ touch_notify_touch_up(struct libinput_device *device, int32_t slot, int32_t seat_slot); +void +tablet_notify_axis(struct libinput_device *device, + uint32_t time, + unsigned char *changed_axes, + double *axes); + void touch_notify_frame(struct libinput_device *device, uint32_t time); diff --git a/src/libinput-util.h b/src/libinput-util.h index 4488fbff..a1d6616e 100644 --- a/src/libinput-util.h +++ b/src/libinput-util.h @@ -76,6 +76,8 @@ int list_empty(const struct list *list); #define min(a, b) (((a) < (b)) ? (a) : (b)) #define max(a, b) (((a) > (b)) ? (a) : (b)) +#define NCHARS(x) ((size_t)(((x) + 7) / 8)) + #define LIBINPUT_EXPORT __attribute__ ((visibility("default"))) static inline void * diff --git a/src/libinput.c b/src/libinput.c index 5b10a10a..96dda717 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -80,6 +80,13 @@ struct libinput_event_touch { double y; }; +struct libinput_event_tablet { + struct libinput_event base; + uint32_t time; + double *axes; + unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_AXIS_CNT)]; +}; + static void libinput_default_log_func(enum libinput_log_priority priority, void *data, @@ -191,6 +198,7 @@ libinput_event_get_pointer_event(struct libinput_event *event) case LIBINPUT_EVENT_TOUCH_MOTION: case LIBINPUT_EVENT_TOUCH_CANCEL: case LIBINPUT_EVENT_TOUCH_FRAME: + case LIBINPUT_EVENT_TABLET_AXIS: break; } @@ -217,6 +225,7 @@ libinput_event_get_keyboard_event(struct libinput_event *event) case LIBINPUT_EVENT_TOUCH_MOTION: case LIBINPUT_EVENT_TOUCH_CANCEL: case LIBINPUT_EVENT_TOUCH_FRAME: + case LIBINPUT_EVENT_TABLET_AXIS: break; } @@ -243,6 +252,34 @@ libinput_event_get_touch_event(struct libinput_event *event) case LIBINPUT_EVENT_TOUCH_CANCEL: case LIBINPUT_EVENT_TOUCH_FRAME: return (struct libinput_event_touch *) event; + case LIBINPUT_EVENT_TABLET_AXIS: + break; + } + + return NULL; +} + +LIBINPUT_EXPORT struct libinput_event_tablet * +libinput_event_get_tablet_event(struct libinput_event *event) +{ + switch (event->type) { + case LIBINPUT_EVENT_NONE: + abort(); /* not used as actual event type */ + case LIBINPUT_EVENT_DEVICE_ADDED: + case LIBINPUT_EVENT_DEVICE_REMOVED: + case LIBINPUT_EVENT_KEYBOARD_KEY: + case LIBINPUT_EVENT_POINTER_MOTION: + case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: + case LIBINPUT_EVENT_POINTER_BUTTON: + case LIBINPUT_EVENT_POINTER_AXIS: + case LIBINPUT_EVENT_TOUCH_DOWN: + case LIBINPUT_EVENT_TOUCH_UP: + case LIBINPUT_EVENT_TOUCH_MOTION: + case LIBINPUT_EVENT_TOUCH_CANCEL: + case LIBINPUT_EVENT_TOUCH_FRAME: + break; + case LIBINPUT_EVENT_TABLET_AXIS: + return (struct libinput_event_tablet *) event; } return NULL; @@ -267,6 +304,7 @@ libinput_event_get_device_notify_event(struct libinput_event *event) case LIBINPUT_EVENT_TOUCH_MOTION: case LIBINPUT_EVENT_TOUCH_CANCEL: case LIBINPUT_EVENT_TOUCH_FRAME: + case LIBINPUT_EVENT_TABLET_AXIS: break; } @@ -431,6 +469,52 @@ libinput_event_touch_get_y(struct libinput_event_touch *event) return event->y; } +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) +{ + return (axis >= 0 && axis < LIBINPUT_TABLET_AXIS_CNT) ? + event->axes[axis] : 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; + + 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; + + return evdev_device_transform_y(device, + event->axes[LIBINPUT_TABLET_AXIS_Y], + height); +} + +LIBINPUT_EXPORT uint32_t +libinput_event_tablet_get_time(struct libinput_event_tablet *event) +{ + return event->time; +} + struct libinput_source * libinput_add_fd(struct libinput *libinput, int fd, @@ -1021,6 +1105,31 @@ touch_notify_frame(struct libinput_device *device, &touch_event->base); } +void +tablet_notify_axis(struct libinput_device *device, + uint32_t time, + unsigned char *changed_axes, + double *axes) +{ + struct libinput_event_tablet *axis_event; + + axis_event = zalloc(sizeof *axis_event); + if (!axis_event) + return; + + *axis_event = (struct libinput_event_tablet) { + .time = time, + .axes = axes, + }; + + memcpy(&axis_event->changed_axes, + changed_axes, + sizeof(axis_event->changed_axes)); + + post_device_event(device, + LIBINPUT_EVENT_TABLET_AXIS, + &axis_event->base); +} static void libinput_post_event(struct libinput *libinput, diff --git a/src/libinput.h b/src/libinput.h index d6f25885..123d778f 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -169,6 +169,19 @@ enum libinput_pointer_axis { LIBINPUT_POINTER_AXIS_HORIZONTAL_SCROLL = 1 }; +/** + * @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_NONE = -1, + LIBINPUT_TABLET_AXIS_X = 0, + LIBINPUT_TABLET_AXIS_Y = 1, + LIBINPUT_TABLET_AXIS_CNT = LIBINPUT_TABLET_AXIS_Y + 1 +}; + /** * @ingroup base * @@ -213,7 +226,9 @@ enum libinput_event_type { * Signals the end of a set of touchpoints at one device sample * time. This event has no coordinate information attached. */ - LIBINPUT_EVENT_TOUCH_FRAME + LIBINPUT_EVENT_TOUCH_FRAME, + + LIBINPUT_EVENT_TABLET_AXIS = 600 }; struct libinput; @@ -237,6 +252,15 @@ 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. + */ +struct libinput_event_tablet; + /** * @defgroup event Accessing and destruction of events */ @@ -327,6 +351,19 @@ libinput_event_get_keyboard_event(struct libinput_event *event); struct libinput_event_touch * libinput_event_get_touch_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 touch event, or NULL for other events + */ +struct libinput_event_tablet * +libinput_event_get_tablet_event(struct libinput_event *event); + /** * @ingroup event * @@ -755,6 +792,88 @@ libinput_event_touch_get_y_transformed(struct libinput_event_touch *event, struct libinput_event * libinput_event_touch_get_base_event(struct libinput_event_touch *event); +/** + * @defgroup event_tablet Tablet events + * + * Events that come from tablet devices. + */ + +/** + * @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, + * this function returns 0. + * + * @note It is an application bug to call this function for events other than + * @ref LIBINPUT_EVENT_TABLET_AXIS. + * + * @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 raw X and + * Y coordinates of the tablet tool. By default these are not transformed, + * however libinput provides libinput_event_tablet_get_x_transformed() and + * libinput_event_tablet_get_y_transformed() for transforming each respective + * axis value. + * + * For tablet events that are not of type @ref LIBINPUT_EVENT_TABLET_AXIS, this + * function returns 0. + * + * @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 current absolute x coordinate of the tablet event, transformed to + * screen coordinates. + * + * @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. + * + * @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 + * + * @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); + /** * @defgroup base Initialization and manipulation of libinput contexts */ From 88421c75837e81b339391cabab1a7af4fd2f03ef Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Thu, 5 Jun 2014 23:35:24 -0400 Subject: [PATCH 004/255] tools: handle TABLET_EVENT_AXIS in event-debug Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Reviewed-by: Hans de Goede --- tools/event-debug.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/tools/event-debug.c b/tools/event-debug.c index 864f77ed..fc5738d3 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -215,6 +215,9 @@ print_event_header(struct libinput_event *ev) case LIBINPUT_EVENT_TOUCH_FRAME: type = "TOUCH_FRAME"; break; + case LIBINPUT_EVENT_TABLET_AXIS: + type = "TABLET_AXIS"; + break; } printf("%-7s %s ", libinput_device_get_sysname(dev), type); @@ -291,7 +294,7 @@ print_button_event(struct libinput_event *ev) } static void -print_axis_event(struct libinput_event *ev) +print_pointer_axis_event(struct libinput_event *ev) { struct libinput_event_pointer *p = libinput_event_get_pointer_event(ev); enum libinput_pointer_axis axis = libinput_event_pointer_get_axis(p); @@ -314,6 +317,35 @@ print_axis_event(struct libinput_event *ev) printf("%s %.2f\n", ax, val); } +static void +print_tablet_axis_event(struct libinput_event *ev) +{ + struct libinput_event_tablet *t = libinput_event_get_tablet_event(ev); + int a; + + print_event_time(libinput_event_tablet_get_time(t)); + printf("\n"); + + for (a = 0; a <= LIBINPUT_TABLET_AXIS_CNT; a++) { + const char *ax; + double val; + + if (!libinput_event_tablet_axis_has_changed(t, a)) + continue; + + switch (a) { + case LIBINPUT_TABLET_AXIS_X: + ax = "x"; + break; + case LIBINPUT_TABLET_AXIS_Y: + ax = "y"; + break; + } + val = libinput_event_tablet_get_axis_value(t, a); + printf("\t%s = %.2f\n", ax, val); + } +} + static void print_touch_event_without_coords(struct libinput_event *ev) { @@ -368,7 +400,7 @@ handle_and_print_events(struct libinput *li) print_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); @@ -385,6 +417,9 @@ handle_and_print_events(struct libinput *li) case LIBINPUT_EVENT_TOUCH_FRAME: print_touch_event_without_coords(ev); break; + case LIBINPUT_EVENT_TABLET_AXIS: + print_tablet_axis_event(ev); + break; } libinput_event_destroy(ev); From 3a65184287553114d8fb780ef2711ad1beac9cb5 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Tue, 10 Jun 2014 16:44:02 -0400 Subject: [PATCH 005/255] Add the libinput_tool object This will be used to represent a tool in use on a drawing tablet. Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/libinput-private.h | 7 ++++ src/libinput.c | 29 +++++++++++++++++ src/libinput.h | 73 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+) diff --git a/src/libinput-private.h b/src/libinput-private.h index f6ba51ca..83906f5b 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -85,6 +85,13 @@ struct libinput_device { int refcount; }; +struct libinput_tool { + struct list link; + uint32_t serial; + enum libinput_tool_type type; + int refcount; +}; + typedef void (*libinput_source_dispatch_t)(void *data); diff --git a/src/libinput.c b/src/libinput.c index 96dda717..5e6ba93c 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -515,6 +515,35 @@ libinput_event_tablet_get_time(struct libinput_event_tablet *event) return event->time; } +LIBINPUT_EXPORT enum libinput_tool_type +libinput_tool_get_type(struct libinput_tool *tool) +{ + return tool->type; +} + +LIBINPUT_EXPORT uint32_t +libinput_tool_get_serial(struct libinput_tool *tool) +{ + return tool->serial; +} + +LIBINPUT_EXPORT void +libinput_tool_ref(struct libinput_tool *tool) +{ + tool->refcount++; +} + +LIBINPUT_EXPORT void +libinput_tool_unref(struct libinput_tool *tool) +{ + assert(tool->refcount > 0); + + if (--tool->refcount == 0) { + list_remove(&tool->link); + free(tool); + } +} + struct libinput_source * libinput_add_fd(struct libinput *libinput, int fd, diff --git a/src/libinput.h b/src/libinput.h index 123d778f..0bd24c2e 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -182,6 +182,32 @@ enum libinput_tablet_axis { LIBINPUT_TABLET_AXIS_CNT = LIBINPUT_TABLET_AXIS_Y + 1 }; +/** + * @ingroup device + * + * An object representing a tool being used by the device. It must have the @ref + * LIBINPUT_DEVICE_CAP_TABLET capability. + */ +struct libinput_tool; + +/** + * @ingroup device + * + * Available tool types for a device. It must have the @ref + * LIBINPUT_DEVICE_CAP_TABLET capability. + */ +enum libinput_tool_type { + LIBINPUT_TOOL_NONE = -1, + LIBINPUT_TOOL_PEN = 0x140, /* Matches BTN_TOOL_PEN */ + LIBINPUT_TOOL_ERASER, + LIBINPUT_TOOL_BRUSH, + LIBINPUT_TOOL_PENCIL, + LIBINPUT_TOOL_AIRBRUSH, + LIBINPUT_TOOL_FINGER, + LIBINPUT_TOOL_MOUSE, + LIBINPUT_TOOL_LENS +}; + /** * @ingroup base * @@ -874,6 +900,53 @@ libinput_event_tablet_get_y_transformed(struct libinput_event_tablet *event, uint32_t libinput_event_tablet_get_time(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 + */ +enum libinput_tool_type +libinput_tool_get_type(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 + */ +void +libinput_tool_ref(struct libinput_tool *tool); + +/** + * @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 + */ +void +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); + /** * @defgroup base Initialization and manipulation of libinput contexts */ From e5212e2080ea4196b0f81a888a6603db975d8e0b Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Tue, 10 Jun 2014 16:48:19 -0400 Subject: [PATCH 006/255] Emit LIBINPUT_TABLET_EVENT_TOOL_UPDATE events on tool changes Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 99 ++++++++++++++++++++++++++++++++++++++++++ src/evdev-tablet.h | 6 ++- src/libinput-private.h | 7 +++ src/libinput.c | 39 +++++++++++++++++ src/libinput.h | 35 ++++++++++++++- 5 files changed, 183 insertions(+), 3 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index a12b6709..da86b057 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -58,6 +58,19 @@ tablet_process_absolute(struct tablet_dispatch *tablet, } } +static void +tablet_update_tool(struct tablet_dispatch *tablet, + enum libinput_tool_type tool, + bool enabled) +{ + assert(tool != LIBINPUT_TOOL_NONE); + + if (enabled && tool != tablet->current_tool_type) { + tablet->current_tool_type = tool; + tablet_set_status(tablet, TABLET_TOOL_UPDATED); + } +} + static void tablet_check_notify_axes(struct tablet_dispatch *tablet, struct evdev_device *device, @@ -95,11 +108,90 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, } } +static void +tablet_process_key(struct tablet_dispatch *tablet, + struct evdev_device *device, + struct input_event *e, + uint32_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: + /* These codes have an equivalent libinput_tool value */ + tablet_update_tool(tablet, e->code, e->value); + break; + default: + break; + } +} + +static void +tablet_process_misc(struct tablet_dispatch *tablet, + struct evdev_device *device, + struct input_event *e, + uint32_t time) +{ + switch (e->code) { + case MSC_SERIAL: + if (e->value != (signed)tablet->current_tool_serial && + e->value != -1) { + tablet->current_tool_serial = e->value; + tablet_set_status(tablet, TABLET_TOOL_UPDATED); + } + break; + default: + log_info("Unhandled MSC event code %#x\n", e->code); + break; + } +} + +static void +tablet_notify_tool(struct tablet_dispatch *tablet, + struct evdev_device *device, + uint32_t time) +{ + struct libinput_device *base = &device->base; + struct libinput_tool *tool; + struct libinput_tool *new_tool = NULL; + + /* Check if we already have the tool in our list of tools */ + list_for_each(tool, &base->seat->libinput->tool_list, link) { + if (tablet->current_tool_type == tool->type && + tablet->current_tool_serial == tool->serial) { + new_tool = tool; + break; + } + } + + /* If we didn't already have the tool in our list of tools, add it */ + if (new_tool == NULL) { + new_tool = zalloc(sizeof *new_tool); + *new_tool = (struct libinput_tool) { + .type = tablet->current_tool_type, + .serial = tablet->current_tool_serial, + .refcount = 1, + }; + + list_insert(&base->seat->libinput->tool_list, &new_tool->link); + } + + tablet_notify_tool_update(base, time, new_tool); +} + static void tablet_flush(struct tablet_dispatch *tablet, struct evdev_device *device, uint32_t time) { + if (tablet_has_status(tablet, TABLET_TOOL_UPDATED)) + tablet_notify_tool(tablet, device, time); + if (tablet_has_status(tablet, TABLET_AXES_UPDATED)) { tablet_check_notify_axes(tablet, device, time); tablet_unset_status(tablet, TABLET_AXES_UPDATED); @@ -119,6 +211,12 @@ tablet_process(struct evdev_dispatch *dispatch, case EV_ABS: tablet_process_absolute(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); break; @@ -151,6 +249,7 @@ tablet_init(struct tablet_dispatch *tablet, tablet->base.interface = &tablet_interface; tablet->device = device; tablet->status = TABLET_NONE; + tablet->current_tool_type = LIBINPUT_TOOL_NONE; /* Mark any axes the tablet has as changed */ for (a = 0; a < LIBINPUT_TABLET_AXIS_CNT; a++) { diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index 551bcafd..28b7a63e 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -29,7 +29,8 @@ enum tablet_status { TABLET_NONE = 0, - TABLET_AXES_UPDATED = 1 << 0 + TABLET_AXES_UPDATED = 1 << 0, + TABLET_TOOL_UPDATED = 1 << 1 }; struct tablet_dispatch { @@ -38,6 +39,9 @@ struct tablet_dispatch { unsigned char status; unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_AXIS_CNT)]; double axes[LIBINPUT_TABLET_AXIS_CNT]; + + enum libinput_tool_type current_tool_type; + uint32_t current_tool_serial; }; static inline enum libinput_tablet_axis diff --git a/src/libinput-private.h b/src/libinput-private.h index 83906f5b..532ce298 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -54,6 +54,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; void *user_data; @@ -207,6 +209,11 @@ tablet_notify_axis(struct libinput_device *device, unsigned char *changed_axes, double *axes); +void +tablet_notify_tool_update(struct libinput_device *device, + uint32_t time, + struct libinput_tool *tool); + void touch_notify_frame(struct libinput_device *device, uint32_t time); diff --git a/src/libinput.c b/src/libinput.c index 5e6ba93c..c7505c02 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -85,6 +85,7 @@ struct libinput_event_tablet { uint32_t time; double *axes; unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_AXIS_CNT)]; + struct libinput_tool *tool; }; static void @@ -199,6 +200,7 @@ libinput_event_get_pointer_event(struct libinput_event *event) case LIBINPUT_EVENT_TOUCH_CANCEL: case LIBINPUT_EVENT_TOUCH_FRAME: case LIBINPUT_EVENT_TABLET_AXIS: + case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: break; } @@ -226,6 +228,7 @@ libinput_event_get_keyboard_event(struct libinput_event *event) case LIBINPUT_EVENT_TOUCH_CANCEL: case LIBINPUT_EVENT_TOUCH_FRAME: case LIBINPUT_EVENT_TABLET_AXIS: + case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: break; } @@ -253,6 +256,7 @@ libinput_event_get_touch_event(struct libinput_event *event) case LIBINPUT_EVENT_TOUCH_FRAME: return (struct libinput_event_touch *) event; case LIBINPUT_EVENT_TABLET_AXIS: + case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: break; } @@ -279,6 +283,7 @@ libinput_event_get_tablet_event(struct libinput_event *event) case LIBINPUT_EVENT_TOUCH_FRAME: break; case LIBINPUT_EVENT_TABLET_AXIS: + case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: return (struct libinput_event_tablet *) event; } @@ -305,6 +310,7 @@ libinput_event_get_device_notify_event(struct libinput_event *event) case LIBINPUT_EVENT_TOUCH_CANCEL: case LIBINPUT_EVENT_TOUCH_FRAME: case LIBINPUT_EVENT_TABLET_AXIS: + case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: break; } @@ -509,6 +515,12 @@ libinput_event_tablet_get_y_transformed(struct libinput_event_tablet *event, height); } +LIBINPUT_EXPORT struct libinput_tool * +libinput_event_tablet_get_tool(struct libinput_event_tablet *event) +{ + return event->tool; +} + LIBINPUT_EXPORT uint32_t libinput_event_tablet_get_time(struct libinput_event_tablet *event) { @@ -605,6 +617,7 @@ libinput_init(struct libinput *libinput, libinput->user_data = user_data; list_init(&libinput->source_destroy_list); list_init(&libinput->seat_list); + list_init(&libinput->tool_list); if (libinput_timer_subsys_init(libinput) != 0) { free(libinput->events); @@ -637,6 +650,7 @@ libinput_destroy(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; if (libinput == NULL) return; @@ -659,6 +673,10 @@ libinput_destroy(struct libinput *libinput) libinput_seat_destroy(seat); } + 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); @@ -1160,6 +1178,27 @@ tablet_notify_axis(struct libinput_device *device, &axis_event->base); } +void +tablet_notify_tool_update(struct libinput_device *device, + uint32_t time, + struct libinput_tool *tool) +{ + struct libinput_event_tablet *tool_update_event; + + tool_update_event = zalloc(sizeof *tool_update_event); + if (!tool_update_event) + return; + + *tool_update_event = (struct libinput_event_tablet) { + .time = time, + .tool = tool, + }; + + post_device_event(device, + LIBINPUT_EVENT_TABLET_TOOL_UPDATE, + &tool_update_event->base); +} + static void libinput_post_event(struct libinput *libinput, struct libinput_event *event) diff --git a/src/libinput.h b/src/libinput.h index 0bd24c2e..2f272e7a 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -254,7 +254,12 @@ enum libinput_event_type { */ LIBINPUT_EVENT_TOUCH_FRAME, - LIBINPUT_EVENT_TABLET_AXIS = 600 + LIBINPUT_EVENT_TABLET_AXIS = 600, + /** + * Signals that a device with the @ref LIBINPUT_DEVICE_CAP_TABLET + * capability has changed its tool. + */ + LIBINPUT_EVENT_TABLET_TOOL_UPDATE }; struct libinput; @@ -283,7 +288,8 @@ struct libinput_event_touch; * @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. + * event types for this event are @ref LIBINPUT_EVENT_TABLET_AXIS, and + * @ref LIBINPUT_EVENT_TABLET_TOOL_UPDATE. */ struct libinput_event_tablet; @@ -891,6 +897,31 @@ libinput_event_tablet_get_x_transformed(struct libinput_event_tablet *event, double libinput_event_tablet_get_y_transformed(struct libinput_event_tablet *event, uint32_t height); + +/** + * @ingroup event_tablet + * + * Return the new tool in use for this event. + * For tablet events that are not of type @ref + * LIBINPUT_EVENT_TABLET_TOOL_UPDATE, this function returns NULL. By default, + * the lifetime of each tool is bound to the lifetime of the event, so the tool + * will be destroyed when the event is destroyed. However, the lifetime of the + * tool may be extended by using libinput_tool_ref() to increment the reference + * count of the tool. Whenever libinput detects that the tool is in proximity of + * any tablet that's connected, it will return the same libinput_tool object. + * + * @note It is an application bug to call this function for events other than + * @ref LIBINPUT_EVENT_TABLET_TOOL_UPDATE. + * + * @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 * From 535c2cab2c6d19f864b60f3bf93fb667bdab5a6b Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Sun, 8 Jun 2014 19:27:45 -0400 Subject: [PATCH 007/255] tools: handle LIBINPUT_TABLET_EVENT_TOOL_UPDATE in event-debug Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Reviewed-by: Hans de Goede --- tools/event-debug.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tools/event-debug.c b/tools/event-debug.c index fc5738d3..c1a73bd1 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -218,6 +218,9 @@ print_event_header(struct libinput_event *ev) case LIBINPUT_EVENT_TABLET_AXIS: type = "TABLET_AXIS"; break; + case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: + type = "TABLET_TOOL_UPDATE"; + break; } printf("%-7s %s ", libinput_device_get_sysname(dev), type); @@ -355,6 +358,50 @@ print_touch_event_without_coords(struct libinput_event *ev) printf("\n"); } +static void +print_tool_update_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); + const char *tool_str; + + switch (libinput_tool_get_type(tool)) { + case LIBINPUT_TOOL_NONE: + tool_str = "none"; + break; + 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(); + } + + print_event_time(libinput_event_tablet_get_time(t)); + printf("%s (%#x)", tool_str, libinput_tool_get_serial(tool)); + printf("\n"); +} + static void print_touch_event_with_coords(struct libinput_event *ev) { @@ -420,6 +467,9 @@ handle_and_print_events(struct libinput *li) case LIBINPUT_EVENT_TABLET_AXIS: print_tablet_axis_event(ev); break; + case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: + print_tool_update_event(ev); + break; } libinput_event_destroy(ev); From 5fa892a88efecd7aa1bb1077d8e9696fdbdc2366 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Fri, 6 Jun 2014 16:35:33 -0400 Subject: [PATCH 008/255] Emit LIBINPUT_EVENT_TABLET_PROXIMITY_OUT when tool leaves proximity This event is just used to notify the caller when the tool's no longer in proximity. When an event like this occurs, everything from evdev up until the next EV_SYN event is discarded along with any events that occured since the last EV_SYN event. This also silences any tool update events where the tool type is changed to LIBINPUT_TOOL_NONE, so we don't end up filling the tool list with a bunch of tools that aren't actually tools. Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 26 ++++++++++++++++++++++---- src/evdev-tablet.h | 3 ++- src/libinput-private.h | 4 ++++ src/libinput.c | 24 ++++++++++++++++++++++++ src/libinput.h | 16 +++++++++++++--- 5 files changed, 65 insertions(+), 8 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index da86b057..a00aed1d 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -69,6 +69,8 @@ tablet_update_tool(struct tablet_dispatch *tablet, tablet->current_tool_type = tool; tablet_set_status(tablet, TABLET_TOOL_UPDATED); } + else if (!enabled) + tablet_set_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY); } static void @@ -189,12 +191,28 @@ tablet_flush(struct tablet_dispatch *tablet, struct evdev_device *device, uint32_t time) { - if (tablet_has_status(tablet, TABLET_TOOL_UPDATED)) - tablet_notify_tool(tablet, device, time); + if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) { + /* FIXME: This behavior is not ideal and this memset should be + * removed */ + memset(&tablet->changed_axes, 0, sizeof(tablet->changed_axes)); + memset(&tablet->axes, 0, sizeof(tablet->axes)); - if (tablet_has_status(tablet, TABLET_AXES_UPDATED)) { - tablet_check_notify_axes(tablet, device, time); tablet_unset_status(tablet, TABLET_AXES_UPDATED); + } else { + if (tablet_has_status(tablet, TABLET_TOOL_UPDATED)) { + tablet_notify_tool(tablet, device, time); + tablet_unset_status(tablet, TABLET_TOOL_UPDATED); + } + + if (tablet_has_status(tablet, TABLET_AXES_UPDATED)) { + tablet_check_notify_axes(tablet, device, time); + tablet_unset_status(tablet, TABLET_AXES_UPDATED); + } + } + + if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) { + tablet_notify_proximity_out(&device->base, time); + tablet_unset_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY); } } diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index 28b7a63e..ee6b3333 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -30,7 +30,8 @@ enum tablet_status { TABLET_NONE = 0, TABLET_AXES_UPDATED = 1 << 0, - TABLET_TOOL_UPDATED = 1 << 1 + TABLET_TOOL_UPDATED = 1 << 1, + TABLET_TOOL_LEAVING_PROXIMITY = 1 << 2 }; struct tablet_dispatch { diff --git a/src/libinput-private.h b/src/libinput-private.h index 532ce298..3830bd9a 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -214,6 +214,10 @@ tablet_notify_tool_update(struct libinput_device *device, uint32_t time, struct libinput_tool *tool); +void +tablet_notify_proximity_out(struct libinput_device *device, + uint32_t time); + void touch_notify_frame(struct libinput_device *device, uint32_t time); diff --git a/src/libinput.c b/src/libinput.c index c7505c02..4b399e11 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -201,6 +201,7 @@ libinput_event_get_pointer_event(struct libinput_event *event) case LIBINPUT_EVENT_TOUCH_FRAME: case LIBINPUT_EVENT_TABLET_AXIS: case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: + case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: break; } @@ -229,6 +230,7 @@ libinput_event_get_keyboard_event(struct libinput_event *event) case LIBINPUT_EVENT_TOUCH_FRAME: case LIBINPUT_EVENT_TABLET_AXIS: case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: + case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: break; } @@ -257,6 +259,7 @@ libinput_event_get_touch_event(struct libinput_event *event) return (struct libinput_event_touch *) event; case LIBINPUT_EVENT_TABLET_AXIS: case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: + case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: break; } @@ -284,6 +287,7 @@ libinput_event_get_tablet_event(struct libinput_event *event) break; case LIBINPUT_EVENT_TABLET_AXIS: case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: + case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: return (struct libinput_event_tablet *) event; } @@ -311,6 +315,7 @@ libinput_event_get_device_notify_event(struct libinput_event *event) case LIBINPUT_EVENT_TOUCH_FRAME: case LIBINPUT_EVENT_TABLET_AXIS: case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: + case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: break; } @@ -1199,6 +1204,25 @@ tablet_notify_tool_update(struct libinput_device *device, &tool_update_event->base); } +void +tablet_notify_proximity_out(struct libinput_device *device, + uint32_t time) +{ + struct libinput_event_tablet *proximity_out_update_event; + + proximity_out_update_event = zalloc(sizeof *proximity_out_update_event); + if (!proximity_out_update_event) + return; + + *proximity_out_update_event = (struct libinput_event_tablet) { + .time = time + }; + + post_device_event(device, + LIBINPUT_EVENT_TABLET_PROXIMITY_OUT, + &proximity_out_update_event->base); +} + static void libinput_post_event(struct libinput *libinput, struct libinput_event *event) diff --git a/src/libinput.h b/src/libinput.h index 2f272e7a..9cb33a7d 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -259,7 +259,17 @@ enum libinput_event_type { * Signals that a device with the @ref LIBINPUT_DEVICE_CAP_TABLET * capability has changed its tool. */ - LIBINPUT_EVENT_TABLET_TOOL_UPDATE + LIBINPUT_EVENT_TABLET_TOOL_UPDATE, + /** + * Signals that a device with the @ref LIBINPUT_DEVICE_CAP_TABLET + * capability has detected that there is no longer a tool in use. When + * this happens, the value of every axis should be assumed to have a + * value of 0 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 initial proximity out + * event. + */ + LIBINPUT_EVENT_TABLET_PROXIMITY_OUT }; struct libinput; @@ -288,8 +298,8 @@ struct libinput_event_touch; * @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, and - * @ref LIBINPUT_EVENT_TABLET_TOOL_UPDATE. + * event types for this event are @ref LIBINPUT_EVENT_TABLET_AXIS, @ref + * LIBINPUT_EVENT_TABLET_TOOL_UPDATE and @ref LIBINPUT_EVENT_TABLET_TOOL_UPDATE. */ struct libinput_event_tablet; From e5f7ec9d53efd8110a0589653b0c291c16e16b6c Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Tue, 10 Jun 2014 23:03:46 -0400 Subject: [PATCH 009/255] tools: Handle LIBINPUT_EVENT_TABLET_PROXIMITY_OUT in event-debug Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Reviewed-by: Hans de Goede --- tools/event-debug.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tools/event-debug.c b/tools/event-debug.c index c1a73bd1..90cdd642 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -221,6 +221,9 @@ print_event_header(struct libinput_event *ev) case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: type = "TABLET_TOOL_UPDATE"; break; + case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: + type = "TABLET_PROXIMITY_OUT"; + break; } printf("%-7s %s ", libinput_device_get_sysname(dev), type); @@ -402,6 +405,14 @@ print_tool_update_event(struct libinput_event *ev) printf("\n"); } +static void +print_proximity_out_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)); + printf("\n"); +} + static void print_touch_event_with_coords(struct libinput_event *ev) { @@ -470,6 +481,9 @@ handle_and_print_events(struct libinput *li) case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: print_tool_update_event(ev); break; + case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: + print_proximity_out_event(ev); + break; } libinput_event_destroy(ev); From 5561e4502d791b80c49eac956922ae1aa9c7d73d Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Tue, 10 Jun 2014 23:14:41 -0400 Subject: [PATCH 010/255] tablet: Handle button-events Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 113 +++++++++++++++++++++++++++++++++++++++++ src/evdev-tablet.h | 12 ++++- src/libinput-private.h | 5 ++ src/libinput.c | 55 ++++++++++++++++++++ src/libinput.h | 51 ++++++++++++++++++- 5 files changed, 233 insertions(+), 3 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index a00aed1d..872556a9 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -31,6 +31,11 @@ #define tablet_unset_status(tablet_,s_) ((tablet_)->status &= ~(s_)) #define tablet_has_status(tablet_,s_) (!!((tablet_)->status & (s_))) +#define tablet_get_pressed_buttons(tablet_,field_) \ + ((tablet_)->button_state.field_ & ~((tablet_)->prev_button_state.field_)) +#define tablet_get_released_buttons(tablet_,field_) \ + ((tablet_)->prev_button_state.field_ & ~((tablet_)->button_state.field_)) + static void tablet_process_absolute(struct tablet_dispatch *tablet, struct evdev_device *device, @@ -110,6 +115,37 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, } } +static void +tablet_update_button(struct tablet_dispatch *tablet, + uint32_t evcode, + uint32_t enable) +{ + uint32_t button, *flags; + + /* XXX: This really depends on the expected buttons fitting in the mask */ + if (evcode >= BTN_MISC && evcode <= BTN_TASK) { + flags = &tablet->button_state.pad_buttons; + button = evcode - BTN_MISC; + } else if (evcode >= BTN_TOUCH && evcode <= BTN_STYLUS2) { + flags = &tablet->button_state.stylus_buttons; + button = evcode - BTN_TOUCH; + } else { + log_info("Unhandled button %s (%#x)\n", + libevdev_event_code_get_name(EV_KEY, evcode), evcode); + return; + } + + if (enable) { + (*flags) |= 1 << button; + tablet_set_status(tablet, TABLET_BUTTONS_PRESSED); + } else { + (*flags) &= ~(1 << button); + tablet_set_status(tablet, TABLET_BUTTONS_RELEASED); + } + + assert(button < 32); +} + static void tablet_process_key(struct tablet_dispatch *tablet, struct evdev_device *device, @@ -128,7 +164,11 @@ tablet_process_key(struct tablet_dispatch *tablet, /* These codes have an equivalent libinput_tool value */ tablet_update_tool(tablet, e->code, e->value); break; + case BTN_TOUCH: + case BTN_STYLUS: + case BTN_STYLUS2: default: + tablet_update_button(tablet, e->code, e->value); break; } } @@ -186,12 +226,68 @@ tablet_notify_tool(struct tablet_dispatch *tablet, tablet_notify_tool_update(base, time, new_tool); } +static void +tablet_notify_button_mask(struct tablet_dispatch *tablet, + struct evdev_device *device, + uint32_t time, + uint32_t buttons, + uint32_t button_base, + enum libinput_button_state state) +{ + struct libinput_device *base = &device->base; + int32_t num_button = 0; + + while (buttons) { + int enabled; + + num_button++; + enabled = (buttons & 1); + buttons >>= 1; + + if (!enabled) + continue; + + tablet_notify_button(base, + time, + num_button + button_base - 1, + state); + } +} + +static void +tablet_notify_buttons(struct tablet_dispatch *tablet, + struct evdev_device *device, + uint32_t time, + enum libinput_button_state state) +{ + uint32_t pad_buttons, stylus_buttons; + + if (state == LIBINPUT_BUTTON_STATE_PRESSED) { + pad_buttons = tablet_get_pressed_buttons(tablet, pad_buttons); + stylus_buttons = + tablet_get_pressed_buttons(tablet, stylus_buttons); + } else { + pad_buttons = tablet_get_released_buttons(tablet, pad_buttons); + stylus_buttons = + tablet_get_released_buttons(tablet, stylus_buttons); + } + + tablet_notify_button_mask(tablet, device, time, + pad_buttons, BTN_MISC, state); + tablet_notify_button_mask(tablet, device, time, + stylus_buttons, BTN_TOUCH, state); +} + static void tablet_flush(struct tablet_dispatch *tablet, struct evdev_device *device, uint32_t time) { if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) { + /* Release all stylus buttons */ + tablet->button_state.stylus_buttons = 0; + tablet_set_status(tablet, TABLET_BUTTONS_RELEASED); + /* FIXME: This behavior is not ideal and this memset should be * removed */ memset(&tablet->changed_axes, 0, sizeof(tablet->changed_axes)); @@ -210,10 +306,27 @@ tablet_flush(struct tablet_dispatch *tablet, } } + if (tablet_has_status(tablet, TABLET_BUTTONS_RELEASED)) { + tablet_notify_buttons(tablet, device, time, + 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, + LIBINPUT_BUTTON_STATE_PRESSED); + tablet_unset_status(tablet, TABLET_BUTTONS_PRESSED); + } + if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) { tablet_notify_proximity_out(&device->base, time); tablet_unset_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY); } + + /* Update state */ + memcpy(&tablet->prev_button_state, + &tablet->button_state, + sizeof(tablet->button_state)); } static void diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index ee6b3333..4498425f 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -31,7 +31,14 @@ enum tablet_status { TABLET_NONE = 0, TABLET_AXES_UPDATED = 1 << 0, TABLET_TOOL_UPDATED = 1 << 1, - TABLET_TOOL_LEAVING_PROXIMITY = 1 << 2 + TABLET_TOOL_LEAVING_PROXIMITY = 1 << 2, + TABLET_BUTTONS_PRESSED = 1 << 3, + TABLET_BUTTONS_RELEASED = 1 << 4 +}; + +struct button_state { + uint32_t pad_buttons; /* bitmask of evcode - BTN_MISC */ + uint32_t stylus_buttons; /* bitmask of evcode - BTN_TOUCH */ }; struct tablet_dispatch { @@ -41,6 +48,9 @@ struct tablet_dispatch { unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_AXIS_CNT)]; double axes[LIBINPUT_TABLET_AXIS_CNT]; + struct button_state button_state; + struct button_state prev_button_state; + enum libinput_tool_type current_tool_type; uint32_t current_tool_serial; }; diff --git a/src/libinput-private.h b/src/libinput-private.h index 3830bd9a..3630f74d 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -219,6 +219,11 @@ tablet_notify_proximity_out(struct libinput_device *device, uint32_t time); void +tablet_notify_button(struct libinput_device *device, + uint32_t time, + int32_t button, + enum libinput_button_state state); +void touch_notify_frame(struct libinput_device *device, uint32_t time); #endif /* LIBINPUT_PRIVATE_H */ diff --git a/src/libinput.c b/src/libinput.c index 4b399e11..1ac62a87 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -82,6 +82,9 @@ struct libinput_event_touch { struct libinput_event_tablet { struct libinput_event base; + uint32_t button; + enum libinput_button_state state; + uint32_t seat_button_count; uint32_t time; double *axes; unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_AXIS_CNT)]; @@ -202,6 +205,7 @@ libinput_event_get_pointer_event(struct libinput_event *event) case LIBINPUT_EVENT_TABLET_AXIS: case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: + case LIBINPUT_EVENT_TABLET_BUTTON: break; } @@ -231,6 +235,7 @@ libinput_event_get_keyboard_event(struct libinput_event *event) case LIBINPUT_EVENT_TABLET_AXIS: case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: + case LIBINPUT_EVENT_TABLET_BUTTON: break; } @@ -260,6 +265,7 @@ libinput_event_get_touch_event(struct libinput_event *event) case LIBINPUT_EVENT_TABLET_AXIS: case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: + case LIBINPUT_EVENT_TABLET_BUTTON: break; } @@ -288,6 +294,7 @@ libinput_event_get_tablet_event(struct libinput_event *event) case LIBINPUT_EVENT_TABLET_AXIS: case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: + case LIBINPUT_EVENT_TABLET_BUTTON: return (struct libinput_event_tablet *) event; } @@ -316,6 +323,7 @@ libinput_event_get_device_notify_event(struct libinput_event *event) case LIBINPUT_EVENT_TABLET_AXIS: case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: + case LIBINPUT_EVENT_TABLET_BUTTON: break; } @@ -532,6 +540,24 @@ libinput_event_tablet_get_time(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) { @@ -1223,6 +1249,35 @@ tablet_notify_proximity_out(struct libinput_device *device, &proximity_out_update_event->base); } +void +tablet_notify_button(struct libinput_device *device, + uint32_t time, + 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, + .button = button, + .state = state, + .seat_button_count = seat_button_count, + }; + + post_device_event(device, + LIBINPUT_EVENT_TABLET_BUTTON, + &button_event->base); +} + static void libinput_post_event(struct libinput *libinput, struct libinput_event *event) diff --git a/src/libinput.h b/src/libinput.h index 9cb33a7d..b4272b2c 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -269,7 +269,8 @@ enum libinput_event_type { * was held down on the stylus are sent before the initial proximity out * event. */ - LIBINPUT_EVENT_TABLET_PROXIMITY_OUT + LIBINPUT_EVENT_TABLET_PROXIMITY_OUT, + LIBINPUT_EVENT_TABLET_BUTTON }; struct libinput; @@ -299,7 +300,8 @@ struct libinput_event_touch; * * 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_TOOL_UPDATE and @ref LIBINPUT_EVENT_TABLET_TOOL_UPDATE. + * LIBINPUT_EVENT_TABLET_TOOL_UPDATE, @ref LIBINPUT_EVENT_TABLET_TOOL_UPDATE and + * @ref LIBINPUT_EVENT_TABLET_BUTTON. */ struct libinput_event_tablet; @@ -932,6 +934,51 @@ libinput_event_tablet_get_y_transformed(struct libinput_event_tablet *event, struct libinput_tool * libinput_event_tablet_get_tool(struct libinput_event_tablet *event); +/** + * @ingroup event_tablet + * + * Return the button that triggered this event. + * For tablet events that are not of type LIBINPUT_EVENT_TABLET_BUTTON, this + * function returns 0. + * + * @note It is an application bug to call this function for events other than + * 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 + * 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 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 + * 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 * From b2629dc8a10509890de3cc78b5dff04bf94901f7 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Fri, 6 Jun 2014 18:32:12 -0400 Subject: [PATCH 011/255] tools: handle tablet button events in event-debug Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Reviewed-by: Hans de Goede --- tools/event-debug.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/tools/event-debug.c b/tools/event-debug.c index 90cdd642..13b86a48 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -224,6 +224,9 @@ print_event_header(struct libinput_event *ev) case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: type = "TABLET_PROXIMITY_OUT"; break; + case LIBINPUT_EVENT_TABLET_BUTTON: + type = "TABLET_BUTTON"; + break; } printf("%-7s %s ", libinput_device_get_sysname(dev), type); @@ -285,7 +288,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; @@ -299,6 +302,21 @@ print_button_event(struct libinput_event *ev) libinput_event_pointer_get_seat_button_count(p)); } +static void +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) { @@ -455,7 +473,7 @@ 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_pointer_axis_event(ev); @@ -484,6 +502,9 @@ handle_and_print_events(struct libinput *li) case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: print_proximity_out_event(ev); break; + case LIBINPUT_EVENT_TABLET_BUTTON: + print_tablet_button_event(ev); + break; } libinput_event_destroy(ev); From 8f572b6fd191108d2950dbdb3798f22b3bcc805e Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Fri, 6 Jun 2014 20:31:38 -0400 Subject: [PATCH 012/255] tablet: Report and normalize distance, pressure, and tilt axes Report the values for the distance, pressure, and tilt axes. Pressure is normalized to a range of 0 to 1, and tilt is normalized to a range of -1 to 1. Based off the patch originally written by Carlos Garnacho Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 35 +++++++++++++++++++++++++++++++++++ src/evdev-tablet.h | 27 ++++++++++++++++++++++++++- src/libinput.h | 14 +++++++++++++- 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 872556a9..aa9d2cbd 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -47,6 +47,10 @@ tablet_process_absolute(struct tablet_dispatch *tablet, switch (e->code) { case ABS_X: case ABS_Y: + case ABS_PRESSURE: + case ABS_TILT_X: + case ABS_TILT_Y: + case ABS_DISTANCE: axis = evcode_to_axis(e->code); if (axis == LIBINPUT_TABLET_AXIS_NONE) { log_bug_libinput("Invalid ABS event code %#x\n", @@ -78,6 +82,23 @@ tablet_update_tool(struct tablet_dispatch *tablet, tablet_set_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY); } +static inline double +normalize_pressure(const struct input_absinfo * absinfo) { + double range = absinfo->maximum - absinfo->minimum + 1; + double value = (absinfo->value + absinfo->minimum) / range; + + return value; +} + +static inline double +normalize_tilt(const struct input_absinfo * absinfo) { + double range = absinfo->maximum - absinfo->minimum + 1; + double value = (absinfo->value + absinfo->minimum) / range; + + /* Map to the (-1, 1) range */ + return (value * 2) - 1; +} + static void tablet_check_notify_axes(struct tablet_dispatch *tablet, struct evdev_device *device, @@ -99,8 +120,16 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, switch (a) { case LIBINPUT_TABLET_AXIS_X: case LIBINPUT_TABLET_AXIS_Y: + case LIBINPUT_TABLET_AXIS_DISTANCE: tablet->axes[a] = absinfo->value; break; + case LIBINPUT_TABLET_AXIS_PRESSURE: + tablet->axes[a] = normalize_pressure(absinfo); + break; + case LIBINPUT_TABLET_AXIS_TILT_VERTICAL: + case LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL: + tablet->axes[a] = normalize_tilt(absinfo); + break; default: log_bug_libinput("Invalid axis update: %d\n", a); break; @@ -165,6 +194,12 @@ tablet_process_key(struct tablet_dispatch *tablet, tablet_update_tool(tablet, e->code, e->value); break; case BTN_TOUCH: + if (e->value) + tablet_set_status(tablet, TABLET_STYLUS_IN_CONTACT); + else + tablet_unset_status(tablet, TABLET_STYLUS_IN_CONTACT); + + /* Fall through */ case BTN_STYLUS: case BTN_STYLUS2: default: diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index 4498425f..679050b0 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -33,7 +33,8 @@ enum tablet_status { TABLET_TOOL_UPDATED = 1 << 1, TABLET_TOOL_LEAVING_PROXIMITY = 1 << 2, TABLET_BUTTONS_PRESSED = 1 << 3, - TABLET_BUTTONS_RELEASED = 1 << 4 + TABLET_BUTTONS_RELEASED = 1 << 4, + TABLET_STYLUS_IN_CONTACT = 1 << 5 }; struct button_state { @@ -67,6 +68,18 @@ evcode_to_axis(const uint32_t evcode) case ABS_Y: axis = LIBINPUT_TABLET_AXIS_Y; break; + case ABS_DISTANCE: + axis = LIBINPUT_TABLET_AXIS_DISTANCE; + break; + case ABS_PRESSURE: + axis = LIBINPUT_TABLET_AXIS_PRESSURE; + break; + case ABS_TILT_X: + axis = LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL; + break; + case ABS_TILT_Y: + axis = LIBINPUT_TABLET_AXIS_TILT_VERTICAL; + break; default: axis = LIBINPUT_TABLET_AXIS_NONE; break; @@ -87,6 +100,18 @@ axis_to_evcode(const enum libinput_tablet_axis axis) 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_VERTICAL: + evcode = ABS_TILT_X; + break; + case LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL: + evcode = ABS_TILT_Y; + break; default: abort(); } diff --git a/src/libinput.h b/src/libinput.h index b4272b2c..ca00bdcd 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -179,7 +179,11 @@ enum libinput_tablet_axis { LIBINPUT_TABLET_AXIS_NONE = -1, LIBINPUT_TABLET_AXIS_X = 0, LIBINPUT_TABLET_AXIS_Y = 1, - LIBINPUT_TABLET_AXIS_CNT = LIBINPUT_TABLET_AXIS_Y + 1 + LIBINPUT_TABLET_AXIS_DISTANCE = 2, + LIBINPUT_TABLET_AXIS_PRESSURE = 3, + LIBINPUT_TABLET_AXIS_TILT_VERTICAL = 4, + LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL = 5, + LIBINPUT_TABLET_AXIS_CNT = LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL + 1 }; /** @@ -870,6 +874,14 @@ libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, * however libinput provides libinput_event_tablet_get_x_transformed() and * libinput_event_tablet_get_y_transformed() for transforming each respective * axis value. + * - @ref LIBINPUT_TABLET_AXIS_DISTANCE - Approximately how many millimeters + * away from the tablet's sensor the tool is + * - @ref LIBINPUT_TABLET_AXIS_PRESSURE - The current pressure being applied on + * the tool in use, normalized from 0 to 1 + * - @ref LIBINPUT_TABLET_AXIS_TILT_VERTICAL and @ref + * LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL - normalized value between -1 and 1 + * that indicates the tilt vertical or horizontal tilt of the tool + * respectively * * For tablet events that are not of type @ref LIBINPUT_EVENT_TABLET_AXIS, this * function returns 0. From 4e4ff21e319c8eece8a4df8df29de800b58af34f Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Thu, 12 Jun 2014 18:46:26 -0400 Subject: [PATCH 013/255] Sanitize distance and pressure axes before reporting their values This commit changes two things with the way distance and pressure axes are reported: 1. Distance and pressure are made mutually exclusive. When there is a distance event and a pressure event and the tool is in contact with the tablet, only the pressure change will be reported. When the tool is not in contact and both a distance and pressure change are received, only the distance update will be received. 2. Bad distance events are not reported to the caller. There is a certain distance a tool can be from the tablet where the tablet recongnizes that a tool appeared, but the tool doesn't send any useful information to the tablet. When this happens, the distance will update to it's minimum or maximum value, and no other axis updates will be sent. Since this can give a caller the impression that the tool is within a useful proximity of the tablet, we filter out any distance events with a value of maximum or minimum when the tool is not within useful proximity of the tablet. Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 34 ++++++++++++++++++++++++++++++++++ src/evdev-tablet.h | 3 ++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index aa9d2cbd..1bd94441 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -50,6 +50,9 @@ tablet_process_absolute(struct tablet_dispatch *tablet, case ABS_PRESSURE: case ABS_TILT_X: case ABS_TILT_Y: + tablet_unset_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY); + + /* Fall through */ case ABS_DISTANCE: axis = evcode_to_axis(e->code); if (axis == LIBINPUT_TABLET_AXIS_NONE) { @@ -313,6 +316,35 @@ tablet_notify_buttons(struct tablet_dispatch *tablet, stylus_buttons, BTN_TOUCH, 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. In addition, filter + * out invalid distance events that can occur when the tablet tool is + * close enough for the tablet to detect that's something's there, but + * not close enough for it to actually receive data from the tool + * properly + */ + if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_AXIS_DISTANCE) && + ((distance->value > distance->minimum && + pressure->value > pressure->minimum) || + (tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY) && + (distance->value <= distance->minimum || + distance->value >= distance->maximum)))) { + 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)) { + clear_bit(tablet->changed_axes, LIBINPUT_TABLET_AXIS_PRESSURE); + } +} + static void tablet_flush(struct tablet_dispatch *tablet, struct evdev_device *device, @@ -336,6 +368,7 @@ tablet_flush(struct tablet_dispatch *tablet, } if (tablet_has_status(tablet, TABLET_AXES_UPDATED)) { + sanitize_tablet_axes(tablet); tablet_check_notify_axes(tablet, device, time); tablet_unset_status(tablet, TABLET_AXES_UPDATED); } @@ -355,6 +388,7 @@ tablet_flush(struct tablet_dispatch *tablet, if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) { tablet_notify_proximity_out(&device->base, time); + tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY); tablet_unset_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY); } diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index 679050b0..bc2939d7 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -34,7 +34,8 @@ enum tablet_status { TABLET_TOOL_LEAVING_PROXIMITY = 1 << 2, TABLET_BUTTONS_PRESSED = 1 << 3, TABLET_BUTTONS_RELEASED = 1 << 4, - TABLET_STYLUS_IN_CONTACT = 1 << 5 + TABLET_STYLUS_IN_CONTACT = 1 << 5, + TABLET_TOOL_OUT_OF_PROXIMITY = 1 << 6 }; struct button_state { From 6d0fceb225c0b0335feb2edb37556540904e0cbe Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Fri, 6 Jun 2014 20:33:47 -0400 Subject: [PATCH 014/255] tools: Handle pressure, tilt, and distance in event-debug Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Reviewed-by: Hans de Goede --- tools/event-debug.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/event-debug.c b/tools/event-debug.c index 13b86a48..9a5ece2e 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -364,6 +364,18 @@ print_tablet_axis_event(struct libinput_event *ev) case LIBINPUT_TABLET_AXIS_Y: ax = "y"; break; + case LIBINPUT_TABLET_AXIS_DISTANCE: + ax = "distance"; + break; + case LIBINPUT_TABLET_AXIS_PRESSURE: + ax = "pressure"; + break; + case LIBINPUT_TABLET_AXIS_TILT_VERTICAL: + ax = "ytilt"; + break; + case LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL: + ax = "xtilt"; + break; } val = libinput_event_tablet_get_axis_value(t, a); printf("\t%s = %.2f\n", ax, val); From 204d1d7514fa2620edfcaa191b58620b35a8965d Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Mon, 21 Apr 2014 19:11:27 +0200 Subject: [PATCH 015/255] test: Add infrastructure for testing tablet events. no vfuncs are used, only input_event arrays. Signed-off-by: Carlos Garnacho Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Reviewed-by: Hans de Goede --- test/litest-int.h | 8 +++++ test/litest.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++ test/litest.h | 13 +++++++ 3 files changed, 110 insertions(+) diff --git a/test/litest-int.h b/test/litest-int.h index 19e6e68d..e64f8b85 100644 --- a/test/litest-int.h +++ b/test/litest-int.h @@ -88,6 +88,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]; int max[2]; }; diff --git a/test/litest.c b/test/litest.c index 0a9cc72d..f7287072 100644 --- a/test/litest.c +++ b/test/litest.c @@ -695,6 +695,95 @@ litest_touch_move_to(struct litest_device *d, litest_touch_move(d, slot, x_to, y_to); } +static int32_t +axis_replacement_value(struct axis_replacement *axes, + int32_t evcode) +{ + struct axis_replacement *axis = axes; + + while (axis->evcode != -1) { + if (axis->evcode == evcode) + return axis->value; + axis++; + } + + return -1; +} + +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: + value = axis_replacement_value(axes, ev->code); + 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_button_click(struct litest_device *d, unsigned int button, bool is_press) { diff --git a/test/litest.h b/test/litest.h index 3e75dd58..ac8f4497 100644 --- a/test/litest.h +++ b/test/litest.h @@ -58,6 +58,8 @@ enum litest_device_feature { LITEST_SINGLE_TOUCH = 1 << 7, LITEST_APPLE_CLICKPAD = 1 << 8, LITEST_TOPBUTTONPAD = 1 << 9, + LITEST_TABLET = 1 << 10, + LITEST_DISTANCE = 1 << 11, }; struct litest_device { @@ -70,6 +72,10 @@ struct litest_device { }; struct libinput *litest_create_context(void); +struct axis_replacement { + int32_t evcode; + int32_t value; +}; void litest_add(const char *name, void *func, enum litest_device_feature required_feature, @@ -119,6 +125,13 @@ void litest_touch_move_to(struct litest_device *d, int x_from, int y_from, int x_to, int y_to, int steps); +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_button_click(struct litest_device *d, unsigned int button, bool is_press); From 9d96286a44f90091638fc7f1242530da60849188 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Wed, 11 Jun 2014 20:16:04 -0400 Subject: [PATCH 016/255] test: Add litest_assert_double_*() macros Converts two doubles to 24.8 fixed-width integers so assertions can be made with doubles in tests Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer --- test/litest.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/litest.h b/test/litest.h index ac8f4497..843c9fb6 100644 --- a/test/litest.h +++ b/test/litest.h @@ -148,6 +148,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)) #ifndef ck_assert_notnull #define ck_assert_notnull(ptr) ck_assert_ptr_ne(ptr, NULL) From f43a9b2c76b8c61d4750f56c54566f8155871032 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Mon, 21 Apr 2014 19:11:28 +0200 Subject: [PATCH 017/255] test: Add Wacom Bamboo 16FG 4x5 Pen device definition Signed-off-by: Carlos Garnacho Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Reviewed-by: Hans de Goede --- test/Makefile.am | 1 + test/litest-wacom-bamboo-tablet.c | 105 ++++++++++++++++++++++++++++++ test/litest.c | 2 + test/litest.h | 1 + 4 files changed, 109 insertions(+) create mode 100644 test/litest-wacom-bamboo-tablet.c diff --git a/test/Makefile.am b/test/Makefile.am index b5dc33c5..8ab1f88d 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -21,6 +21,7 @@ liblitest_la_SOURCES = \ litest-synaptics-st.c \ litest-synaptics-t440.c \ litest-trackpoint.c \ + litest-wacom-bamboo-tablet.c \ litest-wacom-touch.c \ litest.c diff --git a/test/litest-wacom-bamboo-tablet.c b/test/litest-wacom-bamboo-tablet.c new file mode 100644 index 00000000..d21d4be0 --- /dev/null +++ b/test/litest-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.c b/test/litest.c index f7287072..db9abd44 100644 --- a/test/litest.c +++ b/test/litest.c @@ -83,6 +83,7 @@ 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; struct litest_test_device* devices[] = { &litest_synaptics_clickpad_device, @@ -93,6 +94,7 @@ struct litest_test_device* devices[] = { &litest_bcm5974_device, &litest_mouse_device, &litest_wacom_touch_device, + &litest_wacom_bamboo_tablet_device, NULL, }; diff --git a/test/litest.h b/test/litest.h index 843c9fb6..cbfa55fa 100644 --- a/test/litest.h +++ b/test/litest.h @@ -43,6 +43,7 @@ enum litest_device_type { LITEST_TRACKPOINT, LITEST_MOUSE, LITEST_WACOM_TOUCH, + LITEST_WACOM_BAMBOO, }; enum litest_device_feature { From 20343ab41cc44b4021b695cf6659b380b0f0f136 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Mon, 21 Apr 2014 19:11:29 +0200 Subject: [PATCH 018/255] test: Add Wacom Cintiq 12WX device definition Signed-off-by: Carlos Garnacho Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Reviewed-by: Hans de Goede --- test/Makefile.am | 1 + test/litest-wacom-cintiq-tablet.c | 137 ++++++++++++++++++++++++++++++ test/litest.c | 2 + test/litest.h | 1 + 4 files changed, 141 insertions(+) create mode 100644 test/litest-wacom-cintiq-tablet.c diff --git a/test/Makefile.am b/test/Makefile.am index 8ab1f88d..7f3099e9 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -22,6 +22,7 @@ liblitest_la_SOURCES = \ litest-synaptics-t440.c \ litest-trackpoint.c \ litest-wacom-bamboo-tablet.c \ + litest-wacom-cintiq-tablet.c \ litest-wacom-touch.c \ litest.c diff --git a/test/litest-wacom-cintiq-tablet.c b/test/litest-wacom-cintiq-tablet.c new file mode 100644 index 00000000..93cd2a8b --- /dev/null +++ b/test/litest-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, + .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.c b/test/litest.c index db9abd44..4ae53796 100644 --- a/test/litest.c +++ b/test/litest.c @@ -84,6 +84,7 @@ 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; struct litest_test_device* devices[] = { &litest_synaptics_clickpad_device, @@ -95,6 +96,7 @@ struct litest_test_device* devices[] = { &litest_mouse_device, &litest_wacom_touch_device, &litest_wacom_bamboo_tablet_device, + &litest_wacom_cintiq_tablet_device, NULL, }; diff --git a/test/litest.h b/test/litest.h index cbfa55fa..0b960bb4 100644 --- a/test/litest.h +++ b/test/litest.h @@ -44,6 +44,7 @@ enum litest_device_type { LITEST_MOUSE, LITEST_WACOM_TOUCH, LITEST_WACOM_BAMBOO, + LITEST_WACOM_CINTIQ, }; enum litest_device_feature { From c5736b7a9bc56c91c6364382adb643c1026bee52 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Mon, 21 Apr 2014 19:11:30 +0200 Subject: [PATCH 019/255] test: Add Wacom Intuos5 touch M Pen device definition Signed-off-by: Carlos Garnacho Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Reviewed-by: Hans de Goede --- test/Makefile.am | 1 + test/litest-wacom-intuos-tablet.c | 135 ++++++++++++++++++++++++++++++ test/litest.c | 2 + test/litest.h | 1 + 4 files changed, 139 insertions(+) create mode 100644 test/litest-wacom-intuos-tablet.c diff --git a/test/Makefile.am b/test/Makefile.am index 7f3099e9..1d11cf67 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -23,6 +23,7 @@ liblitest_la_SOURCES = \ litest-trackpoint.c \ litest-wacom-bamboo-tablet.c \ litest-wacom-cintiq-tablet.c \ + litest-wacom-intuos-tablet.c \ litest-wacom-touch.c \ litest.c diff --git a/test/litest-wacom-intuos-tablet.c b/test/litest-wacom-intuos-tablet.c new file mode 100644 index 00000000..0cbb632c --- /dev/null +++ b/test/litest-wacom-intuos-tablet.c @@ -0,0 +1,135 @@ +/* + * 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_TOUCH, + EV_KEY, BTN_STYLUS, + EV_KEY, BTN_STYLUS2, + 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, + .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.c b/test/litest.c index 4ae53796..bdeaf932 100644 --- a/test/litest.c +++ b/test/litest.c @@ -85,6 +85,7 @@ 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; struct litest_test_device* devices[] = { &litest_synaptics_clickpad_device, @@ -97,6 +98,7 @@ struct litest_test_device* devices[] = { &litest_wacom_touch_device, &litest_wacom_bamboo_tablet_device, &litest_wacom_cintiq_tablet_device, + &litest_wacom_intuos_tablet_device, NULL, }; diff --git a/test/litest.h b/test/litest.h index 0b960bb4..ea19a7ec 100644 --- a/test/litest.h +++ b/test/litest.h @@ -45,6 +45,7 @@ enum litest_device_type { LITEST_WACOM_TOUCH, LITEST_WACOM_BAMBOO, LITEST_WACOM_CINTIQ, + LITEST_WACOM_INTUOS, }; enum litest_device_feature { From 0716580fc2b01a542174bc5d10dd2f31b98433ad Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Mon, 21 Apr 2014 19:11:31 +0200 Subject: [PATCH 020/255] test: Add Wacom ISDv4 E6 Pen device definition Signed-off-by: Carlos Garnacho Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Reviewed-by: Hans de Goede --- test/Makefile.am | 1 + test/litest-wacom-isdv4-tablet.c | 98 ++++++++++++++++++++++++++++++++ test/litest.c | 2 + test/litest.h | 1 + 4 files changed, 102 insertions(+) create mode 100644 test/litest-wacom-isdv4-tablet.c diff --git a/test/Makefile.am b/test/Makefile.am index 1d11cf67..b6b3a511 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -24,6 +24,7 @@ liblitest_la_SOURCES = \ litest-wacom-bamboo-tablet.c \ litest-wacom-cintiq-tablet.c \ litest-wacom-intuos-tablet.c \ + litest-wacom-isdv4-tablet.c \ litest-wacom-touch.c \ litest.c diff --git a/test/litest-wacom-isdv4-tablet.c b/test/litest-wacom-isdv4-tablet.c new file mode 100644 index 00000000..c9d40e77 --- /dev/null +++ b/test/litest-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.c b/test/litest.c index bdeaf932..fae8b162 100644 --- a/test/litest.c +++ b/test/litest.c @@ -86,6 +86,7 @@ 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; struct litest_test_device* devices[] = { &litest_synaptics_clickpad_device, @@ -99,6 +100,7 @@ struct litest_test_device* devices[] = { &litest_wacom_bamboo_tablet_device, &litest_wacom_cintiq_tablet_device, &litest_wacom_intuos_tablet_device, + &litest_wacom_isdv4_tablet_device, NULL, }; diff --git a/test/litest.h b/test/litest.h index ea19a7ec..59048050 100644 --- a/test/litest.h +++ b/test/litest.h @@ -46,6 +46,7 @@ enum litest_device_type { LITEST_WACOM_BAMBOO, LITEST_WACOM_CINTIQ, LITEST_WACOM_INTUOS, + LITEST_WACOM_ISDV4, }; enum litest_device_feature { From a152ece99f37c62318aac54f737d758aec569124 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Sat, 7 Jun 2014 17:35:41 -0400 Subject: [PATCH 021/255] test: Add proximity tests This tests to make sure proximity events actually work, that they don't output cooirdinate events after they occur, and that they make sure to release all of the buttons and clear the values of all the axes Based off the patch originally written by Carlos Garnacho Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Reviewed-by: Hans de Goede --- test/Makefile.am | 6 ++ test/tablet.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100644 test/tablet.c diff --git a/test/Makefile.am b/test/Makefile.am index b6b3a511..0b86d350 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -34,6 +34,7 @@ run_tests = \ test-pointer \ test-touch \ test-log \ + test-tablet \ test-touchpad \ test-misc \ test-keyboard @@ -68,6 +69,11 @@ test_log_SOURCES = log.c test_log_LDADD = $(TEST_LIBS) test_log_LDFLAGS = -static +test_tablet_SOURCES = tablet.c +test_tablet_CFLAGS = $(AM_CPPFLAGS) +test_tablet_LDADD = $(TEST_LIBS) +test_tablet_LDFLAGS = -static + test_touchpad_SOURCES = touchpad.c test_touchpad_LDADD = $(TEST_LIBS) test_touchpad_LDFLAGS = -static diff --git a/test/tablet.c b/test/tablet.c new file mode 100644 index 00000000..b4c9c470 --- /dev/null +++ b/test/tablet.c @@ -0,0 +1,158 @@ +/* + * 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 + +#include +#include +#include +#include +#include +#include + +#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_TOOL_UPDATE) { + 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_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; + + 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 %d was not released.", + event_button); + } +} +END_TEST + +int +main(int argc, char **argv) +{ + litest_add("tablet:proximity", proximity_out_clear_buttons, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:proximity", proximity_in_out, LITEST_TABLET, LITEST_ANY); + + return litest_run(argc, argv); +} From 49cdfd2a06179d7cb56733097ad8a0ff9ed3e77e Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Thu, 12 Jun 2014 22:52:28 -0400 Subject: [PATCH 022/255] test: Add motion event test for tablets Based off the patch originally written by Carlos Garnacho Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Reviewed-by: Hans de Goede --- test/tablet.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/test/tablet.c b/test/tablet.c index b4c9c470..591fa4b8 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -148,11 +148,103 @@ START_TEST(proximity_out_clear_buttons) } 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, last_reported_y; + 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); + + 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) { + bool x_changed, y_changed; + double reported_x, reported_y; + + 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_proximity_in(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 + int main(int argc, char **argv) { 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:motion", motion, LITEST_TABLET, LITEST_ANY); return litest_run(argc, argv); } From 92a7810a2e6a3c36b860a341a2a60aec3f8c8f16 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Wed, 11 Jun 2014 21:25:37 -0400 Subject: [PATCH 023/255] test: Add test for bad distance events There's a special distance on wacom tablets where the stylus is close enough to be (sort of) recongnized by the tablet, but not close enough to send any useful data. When the pen's in this distance, it will send a distance event with the value absinfo->maximum or absinfo->minimum, but no other events. Since that gives the caller the false impression that the tablet is actually in useful proximity of the tablet, we want to make sure we filter out any events like this. Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Reviewed-by: Hans de Goede --- test/tablet.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/test/tablet.c b/test/tablet.c index 591fa4b8..a4809f89 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -239,11 +239,54 @@ START_TEST(motion) } END_TEST +START_TEST(bad_distance_events) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event_tablet *tablet_event; + struct libinput_event *event; + bool bad_distance_event_received = false, + axis_has_changed; + enum libinput_event_type type; + const struct input_absinfo *absinfo; + + litest_drain_events(dev->libinput); + + 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); + + /* We shouldn't be able to see any of the bad distance events that got + * sent + */ + while ((event = libinput_get_event(li))) { + tablet_event = libinput_event_get_tablet_event(event); + type = libinput_event_get_type(event); + axis_has_changed = libinput_event_tablet_axis_has_changed( + tablet_event, LIBINPUT_TABLET_AXIS_DISTANCE); + + if (type == LIBINPUT_EVENT_TABLET_AXIS && axis_has_changed) + bad_distance_event_received = true; + + libinput_event_destroy(event); + } + ck_assert(!bad_distance_event_received); +} +END_TEST + int main(int argc, char **argv) { 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", bad_distance_events, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY); litest_add("tablet:motion", motion, LITEST_TABLET, LITEST_ANY); return litest_run(argc, argv); From 413d6ccfc7e32f7a7b746b2e063c529a3e0e8532 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Wed, 11 Jun 2014 22:03:55 -0400 Subject: [PATCH 024/255] test: Add tests for normalization Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Reviewed-by: Hans de Goede --- test/tablet.c | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) diff --git a/test/tablet.c b/test/tablet.c index a4809f89..11219148 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -281,6 +281,152 @@ START_TEST(bad_distance_events) } 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_VERTICAL)) { + tilt_vertical = + libinput_event_tablet_get_axis_value( + tablet_event, + LIBINPUT_TABLET_AXIS_TILT_VERTICAL); + + litest_assert_double_eq(tilt_vertical, -1); + } + + if (libinput_event_tablet_axis_has_changed( + tablet_event, + LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL)) { + tilt_horizontal = + libinput_event_tablet_get_axis_value( + tablet_event, + LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL); + + 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 + 1); + + if (tilt_horizontal_absinfo != NULL) + litest_event(dev, + EV_ABS, + ABS_TILT_Y, + tilt_horizontal_absinfo->maximum + 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_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_VERTICAL)) { + tilt_vertical = + libinput_event_tablet_get_axis_value( + tablet_event, + LIBINPUT_TABLET_AXIS_TILT_VERTICAL); + + litest_assert_double_eq(tilt_vertical, 1); + } + + if (libinput_event_tablet_axis_has_changed( + tablet_event, + LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL)) { + tilt_horizontal = + libinput_event_tablet_get_axis_value( + tablet_event, + LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL); + + litest_assert_double_eq(tilt_horizontal, 1); + } + } + + libinput_event_destroy(event); + } + +} +END_TEST + int main(int argc, char **argv) { @@ -288,6 +434,7 @@ main(int argc, char **argv) litest_add("tablet:proximity", proximity_in_out, 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:normalization", normalization, LITEST_TABLET, LITEST_ANY); return litest_run(argc, argv); } From f86c89c5c86ff13dad2198ac1f8f5ce38d7774da Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 17 Jun 2014 14:10:46 +1000 Subject: [PATCH 025/255] tablet: check the button range before we use it Signed-off-by: Peter Hutterer Reviewed-by: Stephen Chandler Paul --- src/evdev-tablet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 1bd94441..e64fd83f 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -167,6 +167,8 @@ tablet_update_button(struct tablet_dispatch *tablet, return; } + assert(button < 32); + if (enable) { (*flags) |= 1 << button; tablet_set_status(tablet, TABLET_BUTTONS_PRESSED); @@ -174,8 +176,6 @@ tablet_update_button(struct tablet_dispatch *tablet, (*flags) &= ~(1 << button); tablet_set_status(tablet, TABLET_BUTTONS_RELEASED); } - - assert(button < 32); } static void From ee8fb790b06194324f4b49249657d7559e973240 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 17 Jun 2014 14:11:40 +1000 Subject: [PATCH 026/255] tablet: rename flags to mask This is a simple button mask, use that naming. Signed-off-by: Peter Hutterer Reviewed-by: Stephen Chandler Paul --- src/evdev-tablet.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index e64fd83f..0d37e582 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -152,14 +152,14 @@ tablet_update_button(struct tablet_dispatch *tablet, uint32_t evcode, uint32_t enable) { - uint32_t button, *flags; + uint32_t button, *mask; /* XXX: This really depends on the expected buttons fitting in the mask */ if (evcode >= BTN_MISC && evcode <= BTN_TASK) { - flags = &tablet->button_state.pad_buttons; + mask = &tablet->button_state.pad_buttons; button = evcode - BTN_MISC; } else if (evcode >= BTN_TOUCH && evcode <= BTN_STYLUS2) { - flags = &tablet->button_state.stylus_buttons; + mask = &tablet->button_state.stylus_buttons; button = evcode - BTN_TOUCH; } else { log_info("Unhandled button %s (%#x)\n", @@ -170,10 +170,10 @@ tablet_update_button(struct tablet_dispatch *tablet, assert(button < 32); if (enable) { - (*flags) |= 1 << button; + (*mask) |= 1 << button; tablet_set_status(tablet, TABLET_BUTTONS_PRESSED); } else { - (*flags) &= ~(1 << button); + (*mask) &= ~(1 << button); tablet_set_status(tablet, TABLET_BUTTONS_RELEASED); } } From f64a85c981a56deb2fdf7d5e6fe3b9d9c895fd71 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 17 Jun 2014 14:13:01 +1000 Subject: [PATCH 027/255] tablet: use "int32_t", not "signed" stdint is a lot nicer, and safer once we're in the habit. Signed-off-by: Peter Hutterer Reviewed-by: Stephen Chandler Paul --- src/evdev-tablet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 0d37e582..5596e13e 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -219,7 +219,7 @@ tablet_process_misc(struct tablet_dispatch *tablet, { switch (e->code) { case MSC_SERIAL: - if (e->value != (signed)tablet->current_tool_serial && + if (e->value != (int32_t)tablet->current_tool_serial && e->value != -1) { tablet->current_tool_serial = e->value; tablet_set_status(tablet, TABLET_TOOL_UPDATED); From 0f70e2b3096d3d11c150561b4def391df71e7645 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 17 Jun 2014 16:29:17 +1000 Subject: [PATCH 028/255] tablet: print invalid evdev types/codes as string for debugging purposes Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 5596e13e..11122c40 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -226,7 +226,9 @@ tablet_process_misc(struct tablet_dispatch *tablet, } break; default: - log_info("Unhandled MSC event code %#x\n", e->code); + log_info("Unhandled MSC event code %s (%#x)\n", + libevdev_event_code_get_name(EV_MSC, e->code), + e->code); break; } } @@ -421,7 +423,9 @@ tablet_process(struct evdev_dispatch *dispatch, tablet_flush(tablet, device, time); break; default: - log_error("Unexpected event type %#x\n", e->type); + log_error("Unexpected event type %s (%#x)\n", + libevdev_event_type_get_name(e->type), + e->type); break; } } From 584ef1dbf5750cd96da17b10613a4bbac3b9a6f9 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Tue, 17 Jun 2014 18:03:26 -0400 Subject: [PATCH 029/255] tablet: remove parentheses around tablet_(un)set_status Having parantheses around tablet_has_status() is completely appropriate, but not for setting/unsetting a status. There's no legitimate reason we'd ever be checking the return value of tablet_(un)set_status() since it already stores it's result in a variable. As such, having it expand with parantheses around it means that if it's accidentally used in a conditional instead of tablet_has_status() our compiler won't throw any sort of warning. And the subtle differences between tablet_has_status() and tablet_set_status() are very easy to miss when trying to debug this. Removing the parantheses causes gcc to warn if the function is used as a conditional unintentionally. Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 11122c40..3b82e917 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -27,8 +27,8 @@ #include #include -#define tablet_set_status(tablet_,s_) ((tablet_)->status |= (s_)) -#define tablet_unset_status(tablet_,s_) ((tablet_)->status &= ~(s_)) +#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_))) #define tablet_get_pressed_buttons(tablet_,field_) \ From 8f9730872d6b0ad19615bd5bf77de72c6a4a1ed9 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 17 Jun 2014 13:58:35 +1000 Subject: [PATCH 030/255] tools: print tablet axis debugging on one line Print all axes on the same line, with a * for those that changed. This makes changes on axes a lot more obvious than when broken up per line. Signed-off-by: Peter Hutterer --- tools/event-debug.c | 65 +++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/tools/event-debug.c b/tools/event-debug.c index 9a5ece2e..b8cbd292 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -341,45 +341,46 @@ print_pointer_axis_event(struct libinput_event *ev) printf("%s %.2f\n", ax, val); } +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_axis_event(struct libinput_event *ev) { struct libinput_event_tablet *t = libinput_event_get_tablet_event(ev); - int a; + double x, y; + double dist, pressure; print_event_time(libinput_event_tablet_get_time(t)); + + x = libinput_event_tablet_get_axis_value(t, LIBINPUT_TABLET_AXIS_X); + y = libinput_event_tablet_get_axis_value(t, LIBINPUT_TABLET_AXIS_Y); + printf("\t%.2f%s/%.2f%s", + x, tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_X), + y, tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_Y)); + + x = libinput_event_tablet_get_axis_value(t, LIBINPUT_TABLET_AXIS_TILT_VERTICAL); + y = libinput_event_tablet_get_axis_value(t, LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL); + printf("\ttilt: %.2f%s/%.2f%s ", + x, tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_TILT_VERTICAL), + y, tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL)); + + 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) + printf("distance: %.2f%s", + dist, tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_DISTANCE)); + else + printf("pressure: %.2f%s", + pressure, tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_PRESSURE)); printf("\n"); - - for (a = 0; a <= LIBINPUT_TABLET_AXIS_CNT; a++) { - const char *ax; - double val; - - if (!libinput_event_tablet_axis_has_changed(t, a)) - continue; - - switch (a) { - case LIBINPUT_TABLET_AXIS_X: - ax = "x"; - break; - case LIBINPUT_TABLET_AXIS_Y: - ax = "y"; - break; - case LIBINPUT_TABLET_AXIS_DISTANCE: - ax = "distance"; - break; - case LIBINPUT_TABLET_AXIS_PRESSURE: - ax = "pressure"; - break; - case LIBINPUT_TABLET_AXIS_TILT_VERTICAL: - ax = "ytilt"; - break; - case LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL: - ax = "xtilt"; - break; - } - val = libinput_event_tablet_get_axis_value(t, a); - printf("\t%s = %.2f\n", ax, val); - } } static void From 563268fa9fe0170a9a9da2ca831c25ea4b1208c1 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Tue, 17 Jun 2014 21:17:58 -0400 Subject: [PATCH 031/255] tablet: Clear pressure axis when tool loses contact with the tablet Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 3b82e917..bde3b473 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -343,7 +343,12 @@ sanitize_tablet_axes(struct tablet_dispatch *tablet) 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)) { - clear_bit(tablet->changed_axes, LIBINPUT_TABLET_AXIS_PRESSURE); + /* 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; } } From 39b43c70588a3dd19e3a9a1e481fd8c7f694fc4f Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Thu, 19 Jun 2014 01:18:06 -0400 Subject: [PATCH 032/255] evdev: Continue updating axes internally when tool leaves proximity Axis changes are now still processed by libinput regardless of whether or not the tool is in proximity, however we refrain from reporting them unless the tool is in proximity. This stops bad distance events from being reported without needing a huge mess of conditional statements in sanitize_axes(). The tool is now counted as back in proximity when a tool update is received instead of when an axis update is received. Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 67 ++++++++++++++++++++-------------------------- src/evdev-tablet.h | 9 +++---- 2 files changed, 33 insertions(+), 43 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index bde3b473..760b9545 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -50,9 +50,6 @@ tablet_process_absolute(struct tablet_dispatch *tablet, case ABS_PRESSURE: case ABS_TILT_X: case ABS_TILT_Y: - tablet_unset_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY); - - /* Fall through */ case ABS_DISTANCE: axis = evcode_to_axis(e->code); if (axis == LIBINPUT_TABLET_AXIS_NONE) { @@ -77,12 +74,15 @@ tablet_update_tool(struct tablet_dispatch *tablet, { assert(tool != LIBINPUT_TOOL_NONE); - if (enabled && tool != tablet->current_tool_type) { - tablet->current_tool_type = tool; - tablet_set_status(tablet, TABLET_TOOL_UPDATED); + if (enabled) { + if (tool != tablet->current_tool_type) { + tablet->current_tool_type = tool; + tablet_set_status(tablet, TABLET_TOOL_UPDATED); + } + tablet_unset_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY); } - else if (!enabled) - tablet_set_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY); + else + tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY); } static inline double @@ -141,10 +141,14 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, axis_update_needed = true; } - if (axis_update_needed) { - tablet_notify_axis(base, time, tablet->changed_axes, tablet->axes); - memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes)); - } + if (axis_update_needed && + !tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY)) + tablet_notify_axis(base, + time, + tablet->changed_axes, + tablet->axes); + + memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes)); } static void @@ -223,6 +227,8 @@ tablet_process_misc(struct tablet_dispatch *tablet, e->value != -1) { tablet->current_tool_serial = e->value; tablet_set_status(tablet, TABLET_TOOL_UPDATED); + tablet_unset_status(tablet, + TABLET_TOOL_OUT_OF_PROXIMITY); } break; default: @@ -334,11 +340,8 @@ sanitize_tablet_axes(struct tablet_dispatch *tablet) * properly */ if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_AXIS_DISTANCE) && - ((distance->value > distance->minimum && - pressure->value > pressure->minimum) || - (tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY) && - (distance->value <= distance->minimum || - distance->value >= distance->maximum)))) { + 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) && @@ -357,28 +360,19 @@ tablet_flush(struct tablet_dispatch *tablet, struct evdev_device *device, uint32_t time) { - if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) { + if (tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY)) { /* Release all stylus buttons */ tablet->button_state.stylus_buttons = 0; tablet_set_status(tablet, TABLET_BUTTONS_RELEASED); + } else if (tablet_has_status(tablet, TABLET_TOOL_UPDATED)) { + tablet_notify_tool(tablet, device, time); + tablet_unset_status(tablet, TABLET_TOOL_UPDATED); + } - /* FIXME: This behavior is not ideal and this memset should be - * removed */ - memset(&tablet->changed_axes, 0, sizeof(tablet->changed_axes)); - memset(&tablet->axes, 0, sizeof(tablet->axes)); - + if (tablet_has_status(tablet, TABLET_AXES_UPDATED)) { + sanitize_tablet_axes(tablet); + tablet_check_notify_axes(tablet, device, time); tablet_unset_status(tablet, TABLET_AXES_UPDATED); - } else { - if (tablet_has_status(tablet, TABLET_TOOL_UPDATED)) { - tablet_notify_tool(tablet, device, time); - tablet_unset_status(tablet, TABLET_TOOL_UPDATED); - } - - if (tablet_has_status(tablet, TABLET_AXES_UPDATED)) { - sanitize_tablet_axes(tablet); - tablet_check_notify_axes(tablet, device, time); - tablet_unset_status(tablet, TABLET_AXES_UPDATED); - } } if (tablet_has_status(tablet, TABLET_BUTTONS_RELEASED)) { @@ -393,11 +387,8 @@ tablet_flush(struct tablet_dispatch *tablet, tablet_unset_status(tablet, TABLET_BUTTONS_PRESSED); } - if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) { + if (tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY)) tablet_notify_proximity_out(&device->base, time); - tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY); - tablet_unset_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY); - } /* Update state */ memcpy(&tablet->prev_button_state, diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index bc2939d7..9beba7bb 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -31,11 +31,10 @@ enum tablet_status { TABLET_NONE = 0, TABLET_AXES_UPDATED = 1 << 0, TABLET_TOOL_UPDATED = 1 << 1, - TABLET_TOOL_LEAVING_PROXIMITY = 1 << 2, - TABLET_BUTTONS_PRESSED = 1 << 3, - TABLET_BUTTONS_RELEASED = 1 << 4, - TABLET_STYLUS_IN_CONTACT = 1 << 5, - TABLET_TOOL_OUT_OF_PROXIMITY = 1 << 6 + TABLET_BUTTONS_PRESSED = 1 << 2, + TABLET_BUTTONS_RELEASED = 1 << 3, + TABLET_STYLUS_IN_CONTACT = 1 << 4, + TABLET_TOOL_OUT_OF_PROXIMITY = 1 << 5 }; struct button_state { From 2fed26aa1187fa9b9f5bc282c9a6a2058c871712 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Thu, 19 Jun 2014 01:18:07 -0400 Subject: [PATCH 033/255] evdev: Add tablet_mark_all_axes_changed() Occasionally all the axes that are valid for a device need to be marked as updated for the caller's sake. Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 760b9545..52499fd4 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -67,6 +67,22 @@ tablet_process_absolute(struct tablet_dispatch *tablet, } } +static void +tablet_mark_all_axes_changed(struct tablet_dispatch *tablet, + struct evdev_device *device) +{ + enum libinput_tablet_axis a; + + for (a = 0; a < LIBINPUT_TABLET_AXIS_CNT; a++) { + if (libevdev_has_event_code(device->evdev, + EV_ABS, + axis_to_evcode(a))) + set_bit(tablet->changed_axes, a); + } + + tablet_set_status(tablet, TABLET_AXES_UPDATED); +} + static void tablet_update_tool(struct tablet_dispatch *tablet, enum libinput_tool_type tool, @@ -444,20 +460,12 @@ static int tablet_init(struct tablet_dispatch *tablet, struct evdev_device *device) { - enum libinput_tablet_axis a; - tablet->base.interface = &tablet_interface; tablet->device = device; tablet->status = TABLET_NONE; tablet->current_tool_type = LIBINPUT_TOOL_NONE; - /* Mark any axes the tablet has as changed */ - for (a = 0; a < LIBINPUT_TABLET_AXIS_CNT; a++) { - if (libevdev_has_event_code(device->evdev, - EV_ABS, - axis_to_evcode(a))) - set_bit(tablet->changed_axes, a); - } + tablet_mark_all_axes_changed(tablet, device); return 0; } From 04915ced724808ce4ae2c4d34c99950dd8584818 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Thu, 19 Jun 2014 01:18:08 -0400 Subject: [PATCH 034/255] evdev: Update all axes when the tool comes back into proximity Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 52499fd4..4efb36c7 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -85,6 +85,7 @@ tablet_mark_all_axes_changed(struct tablet_dispatch *tablet, static void tablet_update_tool(struct tablet_dispatch *tablet, + struct evdev_device *device, enum libinput_tool_type tool, bool enabled) { @@ -95,6 +96,7 @@ tablet_update_tool(struct tablet_dispatch *tablet, tablet->current_tool_type = tool; tablet_set_status(tablet, TABLET_TOOL_UPDATED); } + tablet_mark_all_axes_changed(tablet, device); tablet_unset_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY); } else @@ -214,7 +216,7 @@ tablet_process_key(struct tablet_dispatch *tablet, case BTN_TOOL_MOUSE: case BTN_TOOL_LENS: /* These codes have an equivalent libinput_tool value */ - tablet_update_tool(tablet, e->code, e->value); + tablet_update_tool(tablet, device, e->code, e->value); break; case BTN_TOUCH: if (e->value) From d8f2c1b11bc4a66e5fbcecfaee0937372980a057 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Thu, 19 Jun 2014 01:18:09 -0400 Subject: [PATCH 035/255] test: Add tests for serial numbers on tools These tests make sure that any tablets with the capability to report a tool's serial number do so properly, that the tool changes when another tool of the same type with a different serial number is used, and that libinput doesn't change the current tool when -1 is reported as the serial number (-1 is used for special purposes by the linuxwacom driver). Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- test/litest-wacom-cintiq-tablet.c | 2 +- test/litest-wacom-intuos-tablet.c | 2 +- test/litest.h | 1 + test/tablet.c | 113 ++++++++++++++++++++++++++++++ 4 files changed, 116 insertions(+), 2 deletions(-) diff --git a/test/litest-wacom-cintiq-tablet.c b/test/litest-wacom-cintiq-tablet.c index 93cd2a8b..0217f560 100644 --- a/test/litest-wacom-cintiq-tablet.c +++ b/test/litest-wacom-cintiq-tablet.c @@ -125,7 +125,7 @@ static int events[] = { struct litest_test_device litest_wacom_cintiq_tablet_device = { .type = LITEST_WACOM_CINTIQ, - .features = LITEST_TABLET | LITEST_DISTANCE, + .features = LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_SERIAL, .shortname = "wacom-cintiq-tablet", .setup = litest_wacom_cintiq_tablet_setup, .interface = &interface, diff --git a/test/litest-wacom-intuos-tablet.c b/test/litest-wacom-intuos-tablet.c index 0cbb632c..e30d6066 100644 --- a/test/litest-wacom-intuos-tablet.c +++ b/test/litest-wacom-intuos-tablet.c @@ -123,7 +123,7 @@ static int events[] = { struct litest_test_device litest_wacom_intuos_tablet_device = { .type = LITEST_WACOM_INTUOS, - .features = LITEST_TABLET | LITEST_DISTANCE, + .features = LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_SERIAL, .shortname = "wacom-intuos-tablet", .setup = litest_wacom_intuos_tablet_setup, .interface = &interface, diff --git a/test/litest.h b/test/litest.h index 59048050..9e159a34 100644 --- a/test/litest.h +++ b/test/litest.h @@ -64,6 +64,7 @@ enum litest_device_feature { LITEST_TOPBUTTONPAD = 1 << 9, LITEST_TABLET = 1 << 10, LITEST_DISTANCE = 1 << 11, + LITEST_TOOL_SERIAL = 1 << 12, }; struct litest_device { diff --git a/test/tablet.c b/test/tablet.c index 11219148..3bfbb6a6 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -427,9 +427,122 @@ START_TEST(normalization) } 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); + + libinput_dispatch(li); + while ((event = libinput_get_event(li))) { + if (libinput_event_get_type(event) == + LIBINPUT_EVENT_TABLET_TOOL_UPDATE) { + 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; + bool tool_updated = false; + + 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_drain_events(li); + + litest_event(dev, EV_MSC, MSC_SERIAL, 2000); + 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_TOOL_UPDATE) { + 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); + tool_updated = true; + } + + libinput_event_destroy(event); + } + ck_assert(tool_updated); +} +END_TEST + +START_TEST(invalid_serials) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + bool tool_updated = false; + + 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_drain_events(li); + + 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_TOOL_UPDATE) + tool_updated = true; + + libinput_event_destroy(event); + } + ck_assert(!tool_updated); + + /* Make sure libinput doesn't report a tool update when the serial + * number goes back from -1 to what it was previously */ + litest_event(dev, EV_MSC, MSC_SERIAL, 1000); + 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_TOOL_UPDATE) + tool_updated = true; + + libinput_event_destroy(event); + } + ck_assert(!tool_updated); +} +END_TEST + int main(int argc, char **argv) { + 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("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", bad_distance_events, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY); From 797b4b4e5accec9d27104864b24f461afc32b270 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 17 Jun 2014 15:23:13 +1000 Subject: [PATCH 036/255] tablet: provide x/y by default in mm off the top/left corner Given that tablets may not have the same x/y resolution, raw or normalized values are mostly meaningless and likely to be handled the wrong way. Providing x/y in mm is the only constant, meaningful value. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 3 +++ src/libinput.h | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 4efb36c7..09bb454f 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -141,6 +141,9 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, switch (a) { case LIBINPUT_TABLET_AXIS_X: case LIBINPUT_TABLET_AXIS_Y: + tablet->axes[a] = evdev_convert_to_mm(absinfo, + absinfo->value); + break; case LIBINPUT_TABLET_AXIS_DISTANCE: tablet->axes[a] = absinfo->value; break; diff --git a/src/libinput.h b/src/libinput.h index 04f40fa8..ada68296 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -861,11 +861,11 @@ libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, * * 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 raw X and - * Y coordinates of the tablet tool. By default these are not transformed, - * however libinput provides libinput_event_tablet_get_x_transformed() and - * libinput_event_tablet_get_y_transformed() for transforming each respective - * axis value. + * - @ref LIBINPUT_TABLET_AXIS_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. * - @ref LIBINPUT_TABLET_AXIS_DISTANCE - Approximately how many millimeters * away from the tablet's sensor the tool is * - @ref LIBINPUT_TABLET_AXIS_PRESSURE - The current pressure being applied on From 6fd00f74d46ac838a48510470a1cf42f42a658e1 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 18 Jun 2014 11:23:58 +1000 Subject: [PATCH 037/255] tablet: normalize the distance to 0..1 The actual data provided by current tablets is not anywhere close to accurate. While it'd be nice to have this in mm, this is unlikely to happen anytime soon. Use the same 0..1 normalized range as pressure has. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 6 ++---- src/libinput.h | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 09bb454f..e87d2522 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -104,7 +104,7 @@ tablet_update_tool(struct tablet_dispatch *tablet, } static inline double -normalize_pressure(const struct input_absinfo * absinfo) { +normalize_pressure_or_dist(const struct input_absinfo * absinfo) { double range = absinfo->maximum - absinfo->minimum + 1; double value = (absinfo->value + absinfo->minimum) / range; @@ -145,10 +145,8 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, absinfo->value); break; case LIBINPUT_TABLET_AXIS_DISTANCE: - tablet->axes[a] = absinfo->value; - break; case LIBINPUT_TABLET_AXIS_PRESSURE: - tablet->axes[a] = normalize_pressure(absinfo); + tablet->axes[a] = normalize_pressure_or_dist(absinfo); break; case LIBINPUT_TABLET_AXIS_TILT_VERTICAL: case LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL: diff --git a/src/libinput.h b/src/libinput.h index ada68296..0a914569 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -866,8 +866,8 @@ libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, * tablet. Use libinput_event_tablet_get_x_transformed() and * libinput_event_tablet_get_y_transformed() for transforming each * respective axis value. - * - @ref LIBINPUT_TABLET_AXIS_DISTANCE - Approximately how many millimeters - * away from the tablet's sensor the tool is + * - @ref LIBINPUT_TABLET_AXIS_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_VERTICAL and @ref From 52cc0ef25a08cbed2098a3506d412836c8de3e12 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 20 Jun 2014 14:51:28 +1000 Subject: [PATCH 038/255] tablet: ignore pad buttons We've got big plans for handling pad buttons, and the interface will likely be different for those. Meanwhile, discard any pad button events so no-one can get too used to them. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 14 ++++--------- src/evdev-tablet.h | 1 - test/tablet.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 11 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index e87d2522..48f49fee 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -179,8 +179,7 @@ tablet_update_button(struct tablet_dispatch *tablet, /* XXX: This really depends on the expected buttons fitting in the mask */ if (evcode >= BTN_MISC && evcode <= BTN_TASK) { - mask = &tablet->button_state.pad_buttons; - button = evcode - BTN_MISC; + return; } else if (evcode >= BTN_TOUCH && evcode <= BTN_STYLUS2) { mask = &tablet->button_state.stylus_buttons; button = evcode - BTN_TOUCH; @@ -325,20 +324,15 @@ tablet_notify_buttons(struct tablet_dispatch *tablet, uint32_t time, enum libinput_button_state state) { - uint32_t pad_buttons, stylus_buttons; + uint32_t stylus_buttons; - if (state == LIBINPUT_BUTTON_STATE_PRESSED) { - pad_buttons = tablet_get_pressed_buttons(tablet, pad_buttons); + if (state == LIBINPUT_BUTTON_STATE_PRESSED) stylus_buttons = tablet_get_pressed_buttons(tablet, stylus_buttons); - } else { - pad_buttons = tablet_get_released_buttons(tablet, pad_buttons); + else stylus_buttons = tablet_get_released_buttons(tablet, stylus_buttons); - } - tablet_notify_button_mask(tablet, device, time, - pad_buttons, BTN_MISC, state); tablet_notify_button_mask(tablet, device, time, stylus_buttons, BTN_TOUCH, state); } diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index 9beba7bb..504b0931 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -38,7 +38,6 @@ enum tablet_status { }; struct button_state { - uint32_t pad_buttons; /* bitmask of evcode - BTN_MISC */ uint32_t stylus_buttons; /* bitmask of evcode - BTN_TOUCH */ }; diff --git a/test/tablet.c b/test/tablet.c index 3bfbb6a6..6fb44659 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -537,6 +537,55 @@ START_TEST(invalid_serials) } 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, + 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, + LIBINPUT_EVENT_TABLET_BUTTON); + libinput_event_destroy(event); + libinput_dispatch(li); + } +} +END_TEST + int main(int argc, char **argv) { @@ -548,6 +597,7 @@ main(int argc, char **argv) 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:normalization", normalization, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:pad", pad_buttons_ignored, LITEST_TABLET, LITEST_ANY); return litest_run(argc, argv); } From ef34fee2a37cd6babdd55b4fd3a0cef9b1fea927 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 25 Jun 2014 14:45:08 +1000 Subject: [PATCH 039/255] tools: explicitly ignore tablet event codes in the event-gui For now anyway, silences the compiler warnings. Signed-off-by: Peter Hutterer --- tools/event-gui.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/event-gui.c b/tools/event-gui.c index d65a8d15..b184a426 100644 --- a/tools/event-gui.c +++ b/tools/event-gui.c @@ -375,6 +375,11 @@ handle_event_libinput(GIOChannel *source, GIOCondition condition, gpointer data) return FALSE; } break; + case LIBINPUT_EVENT_TABLET_AXIS: + case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: + case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: + case LIBINPUT_EVENT_TABLET_BUTTON: + break; } libinput_event_destroy(ev); From 152d60d7c3e63e0a77756a4c011be7acaf374736 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 25 Jun 2014 15:01:07 +1000 Subject: [PATCH 040/255] evdev: fix a broken log message for per-context logging Somehow escaped the fixes in 8302b0b7e30624099058ac7dea63f3eb655bc7dd Signed-off-by: Peter Hutterer --- src/evdev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/evdev.c b/src/evdev.c index 1aee4848..6fc4ecfb 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -708,7 +708,8 @@ evdev_configure_device(struct evdev_device *device) has_abs) { device->dispatch = evdev_tablet_create(device); device->seat_caps |= EVDEV_DEVICE_TABLET; - log_info("input device '%s', %s is a tablet\n", + log_info(libinput, + "input device '%s', %s is a tablet\n", device->devname, device->devnode); } From 1219b399de4d8b4611eeb5e12b70e532bb064230 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 24 Jun 2014 14:36:37 +1000 Subject: [PATCH 041/255] Add a couple missing @ref tags Signed-off-by: Peter Hutterer --- src/libinput.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libinput.h b/src/libinput.h index 3e0b8754..38b6610f 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -943,11 +943,11 @@ libinput_event_tablet_get_tool(struct libinput_event_tablet *event); * @ingroup event_tablet * * Return the button that triggered this event. - * For tablet events that are not of type LIBINPUT_EVENT_TABLET_BUTTON, this + * 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 - * LIBINPUT_EVENT_TABLET_BUTTON. + * @ref LIBINPUT_EVENT_TABLET_BUTTON. * * @param event The libinput tablet event * @return the button triggering this event @@ -961,7 +961,7 @@ libinput_event_tablet_get_button(struct libinput_event_tablet *event); * Return the button state of the event. * * @note It is an application bug to call this function for events other than - * LIBINPUT_EVENT_TABLET_BUTTON. + * @ref LIBINPUT_EVENT_TABLET_BUTTON. * * @param event The libinput tablet event * @return the button state triggering this event @@ -972,12 +972,12 @@ libinput_event_tablet_get_button_state(struct libinput_event_tablet *event); /** * @ingroup event_tablet * - * For the button of a LIBINPUT_EVENT_TABLET_BUTTON event, return the total + * 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 - * LIBINPUT_EVENT_TABLET_BUTTON. For other events, this function returns 0. + * @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 */ From b1869eae76413c7e389ca192ff6f82b777c907b4 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 24 Jun 2014 15:10:34 +1000 Subject: [PATCH 042/255] tablet: always return 0 for axis values on non-axis events Signed-off-by: Peter Hutterer --- src/libinput.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/libinput.c b/src/libinput.c index 8010bc6e..e72ad8b5 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -504,6 +504,9 @@ LIBINPUT_EXPORT double libinput_event_tablet_get_axis_value(struct libinput_event_tablet *event, enum libinput_tablet_axis axis) { + if (event->base.type != LIBINPUT_EVENT_TABLET_AXIS) + return 0; + return (axis >= 0 && axis < LIBINPUT_TABLET_AXIS_CNT) ? event->axes[axis] : 0; } @@ -515,6 +518,9 @@ libinput_event_tablet_get_x_transformed(struct libinput_event_tablet *event, 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); @@ -527,6 +533,9 @@ libinput_event_tablet_get_y_transformed(struct libinput_event_tablet *event, 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); From 50b47aa8f9fc3f5f221ffa464fa0dcd5bd15caa4 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Wed, 25 Jun 2014 02:30:17 -0400 Subject: [PATCH 043/255] tablet: Fix warnings in test/tablet.c Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- test/tablet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/tablet.c b/test/tablet.c index 6fb44659..adecdaba 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -559,7 +559,7 @@ START_TEST(pad_buttons_ignored) } while ((event = libinput_get_event(li))) { - ck_assert_int_ne(libinput_event_get_type, + ck_assert_int_ne(libinput_event_get_type(event), LIBINPUT_EVENT_TABLET_BUTTON); libinput_event_destroy(event); libinput_dispatch(li); @@ -578,7 +578,7 @@ START_TEST(pad_buttons_ignored) libinput_dispatch(li); while ((event = libinput_get_event(li))) { - ck_assert_int_ne(libinput_event_get_type, + ck_assert_int_ne(libinput_event_get_type(event), LIBINPUT_EVENT_TABLET_BUTTON); libinput_event_destroy(event); libinput_dispatch(li); From cf5ba7056fe38b357e625ac802b66a0144429a00 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 27 Jun 2014 09:19:03 +1000 Subject: [PATCH 044/255] Fix address for memcpy() If we ever change to a dynamic array, this would've been buggy. Signed-off-by: Peter Hutterer --- src/libinput.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libinput.c b/src/libinput.c index e72ad8b5..7cd15b64 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1240,7 +1240,7 @@ tablet_notify_axis(struct libinput_device *device, .axes = axes, }; - memcpy(&axis_event->changed_axes, + memcpy(axis_event->changed_axes, changed_axes, sizeof(axis_event->changed_axes)); From 9a2f2ab46b5bc14708eb4dd288b4d6eec2189df9 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 27 Jun 2014 11:05:30 +1000 Subject: [PATCH 045/255] Update libinput_tool_ref/unref() to return the tool object For consistency with the other ref/unref funtions, see 13e9a1d7449d3b5db1dc7d9cf3aa6187911ee08c Signed-off-by: Peter Hutterer --- src/libinput.c | 16 ++++++++++------ src/libinput.h | 6 ++++-- test/tablet.c | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/src/libinput.c b/src/libinput.c index 7cd15b64..65c5b4e8 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -583,21 +583,25 @@ libinput_tool_get_serial(struct libinput_tool *tool) return tool->serial; } -LIBINPUT_EXPORT void +LIBINPUT_EXPORT struct libinput_tool * libinput_tool_ref(struct libinput_tool *tool) { tool->refcount++; + return tool; } -LIBINPUT_EXPORT void +LIBINPUT_EXPORT struct libinput_tool * libinput_tool_unref(struct libinput_tool *tool) { assert(tool->refcount > 0); - if (--tool->refcount == 0) { - list_remove(&tool->link); - free(tool); - } + tool->refcount--; + if (tool->refcount > 0) + return tool; + + list_remove(&tool->link); + free(tool); + return NULL; } struct libinput_source * diff --git a/src/libinput.h b/src/libinput.h index 38b6610f..8909e6f9 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1010,8 +1010,9 @@ libinput_tool_get_type(struct libinput_tool *tool); * Increment the ref count of tool by one * * @param tool The tool to increment the ref count of + * @return The passed tool */ -void +struct libinput_tool * libinput_tool_ref(struct libinput_tool *tool); /** @@ -1021,8 +1022,9 @@ libinput_tool_ref(struct libinput_tool *tool); * 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 */ -void +struct libinput_tool * libinput_tool_unref(struct libinput_tool *tool); /** diff --git a/test/tablet.c b/test/tablet.c index adecdaba..1786375f 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -537,6 +537,42 @@ START_TEST(invalid_serials) } 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); + + libinput_dispatch(li); + while ((event = libinput_get_event(li))) { + if (libinput_event_get_type(event) == + LIBINPUT_EVENT_TABLET_TOOL_UPDATE) { + break; + } + libinput_event_destroy(event); + } + + 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(); @@ -589,6 +625,7 @@ END_TEST int main(int argc, char **argv) { + litest_add("tablet:tool", tool_ref, LITEST_TABLET | LITEST_TOOL_SERIAL, 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); From 62a0995d19272362d0a2ac2378a74b327c02a454 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Thu, 26 Jun 2014 18:02:48 -0400 Subject: [PATCH 046/255] tablet: Stop redundant proximity-out events from being reported Because bad distance events still trigger calls to tablet_flush(), tablet_flush() will see that the tablet is out of proximity and assume it's an appropriate time to send a proximity-out event, even when we've already sent one. This results in multiple proximity-out events being sent in a row instead of just one. In addition, the bad distance events test has been modified to pick up on this. We shouldn't be receiving /any/ events when we get false distance events from evdev anyway. Signed-off-by: Stephen Chandler Paul Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 12 ++++++++---- src/evdev-tablet.h | 3 ++- test/tablet.c | 27 +++++---------------------- 3 files changed, 15 insertions(+), 27 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index a6acca41..584b49ee 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -102,7 +102,7 @@ tablet_update_tool(struct tablet_dispatch *tablet, tablet_unset_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY); } else - tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY); + tablet_set_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY); } static inline double @@ -164,7 +164,8 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, } if (axis_update_needed && - !tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY)) + !tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY) && + !tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) tablet_notify_axis(base, time, tablet->changed_axes, @@ -378,7 +379,7 @@ tablet_flush(struct tablet_dispatch *tablet, struct evdev_device *device, uint32_t time) { - if (tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY)) { + if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) { /* Release all stylus buttons */ tablet->button_state.stylus_buttons = 0; tablet_set_status(tablet, TABLET_BUTTONS_RELEASED); @@ -405,8 +406,11 @@ tablet_flush(struct tablet_dispatch *tablet, tablet_unset_status(tablet, TABLET_BUTTONS_PRESSED); } - if (tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY)) + if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) { tablet_notify_proximity_out(&device->base, time); + tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY); + tablet_unset_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY); + } /* Update state */ memcpy(&tablet->prev_button_state, diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index 504b0931..89cf2240 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -34,7 +34,8 @@ enum tablet_status { TABLET_BUTTONS_PRESSED = 1 << 2, TABLET_BUTTONS_RELEASED = 1 << 3, TABLET_STYLUS_IN_CONTACT = 1 << 4, - TABLET_TOOL_OUT_OF_PROXIMITY = 1 << 5 + TABLET_TOOL_LEAVING_PROXIMITY = 1 << 5, + TABLET_TOOL_OUT_OF_PROXIMITY = 1 << 6 }; struct button_state { diff --git a/test/tablet.c b/test/tablet.c index 1786375f..0846e748 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -243,15 +243,12 @@ START_TEST(bad_distance_events) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; - struct libinput_event_tablet *tablet_event; - struct libinput_event *event; - bool bad_distance_event_received = false, - axis_has_changed; - enum libinput_event_type type; const struct input_absinfo *absinfo; + struct axis_replacement axes[] = { + { -1, -1 }, + }; - litest_drain_events(dev->libinput); - + litest_tablet_proximity_in(dev, 10, 10, axes); litest_tablet_proximity_out(dev); litest_drain_events(dev->libinput); @@ -263,21 +260,7 @@ START_TEST(bad_distance_events) litest_event(dev, EV_ABS, ABS_DISTANCE, absinfo->minimum); litest_event(dev, EV_SYN, SYN_REPORT, 0); - /* We shouldn't be able to see any of the bad distance events that got - * sent - */ - while ((event = libinput_get_event(li))) { - tablet_event = libinput_event_get_tablet_event(event); - type = libinput_event_get_type(event); - axis_has_changed = libinput_event_tablet_axis_has_changed( - tablet_event, LIBINPUT_TABLET_AXIS_DISTANCE); - - if (type == LIBINPUT_EVENT_TABLET_AXIS && axis_has_changed) - bad_distance_event_received = true; - - libinput_event_destroy(event); - } - ck_assert(!bad_distance_event_received); + litest_assert_empty_queue(li); } END_TEST From e18f7132898483436fe8b44547beecac78e9bcfa Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Thu, 26 Jun 2014 21:31:50 -0400 Subject: [PATCH 047/255] tablet: Remove tablet_notify_tool() and add tablet_get_tool() Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 584b49ee..83620108 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -263,37 +263,35 @@ tablet_process_misc(struct tablet_dispatch *tablet, } } -static void -tablet_notify_tool(struct tablet_dispatch *tablet, - struct evdev_device *device, - uint32_t time) +static struct libinput_tool * +tablet_get_tool(struct libinput *li, + enum libinput_tool_type type, + uint32_t serial) { - struct libinput_device *base = &device->base; - struct libinput_tool *tool; - struct libinput_tool *new_tool = NULL; + struct libinput_tool *tool = NULL, *t; /* Check if we already have the tool in our list of tools */ - list_for_each(tool, &base->seat->libinput->tool_list, link) { - if (tablet->current_tool_type == tool->type && - tablet->current_tool_serial == tool->serial) { - new_tool = tool; + list_for_each(t, &li->tool_list, link) { + if (type == t->type && serial == t->serial) { + tool = t; break; } } - /* If we didn't already have the tool in our list of tools, add it */ - if (new_tool == NULL) { - new_tool = zalloc(sizeof *new_tool); - *new_tool = (struct libinput_tool) { - .type = tablet->current_tool_type, - .serial = tablet->current_tool_serial, + /* 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, .refcount = 1, }; - list_insert(&base->seat->libinput->tool_list, &new_tool->link); + list_insert(&li->tool_list, &tool->link); } - tablet_notify_tool_update(base, time, new_tool); + return tool; } static void @@ -379,12 +377,17 @@ tablet_flush(struct tablet_dispatch *tablet, struct evdev_device *device, uint32_t time) { + struct libinput_tool *tool = + tablet_get_tool(device->base.seat->libinput, + tablet->current_tool_type, + tablet->current_tool_serial); + if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) { /* Release all stylus buttons */ tablet->button_state.stylus_buttons = 0; tablet_set_status(tablet, TABLET_BUTTONS_RELEASED); } else if (tablet_has_status(tablet, TABLET_TOOL_UPDATED)) { - tablet_notify_tool(tablet, device, time); + tablet_notify_tool_update(&device->base, time, tool); tablet_unset_status(tablet, TABLET_TOOL_UPDATED); } From 8b1b988fd806e47b57277e632578749f54e6bc30 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Thu, 26 Jun 2014 21:31:51 -0400 Subject: [PATCH 048/255] tablet: Replace tool-update with proximity-in A proximity-in event is something we want, especially since the current drafted wayland spec has a proximity-in event. Adding this also makes our events more consistent. And since we can just report the current tool in use with proximity-in events, we can get rid of the tool-update event. Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 9 ++++----- src/evdev-tablet.h | 3 ++- src/libinput-private.h | 6 +++--- src/libinput.c | 28 ++++++++++++++-------------- src/libinput.h | 27 ++++++++++++++------------- test/tablet.c | 42 ++++++++++++++++++------------------------ tools/event-debug.c | 10 +++++----- tools/event-gui.c | 2 +- 8 files changed, 61 insertions(+), 66 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 83620108..e6595bc4 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -99,6 +99,7 @@ tablet_update_tool(struct tablet_dispatch *tablet, tablet_set_status(tablet, TABLET_TOOL_UPDATED); } 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 @@ -250,8 +251,6 @@ tablet_process_misc(struct tablet_dispatch *tablet, e->value != -1) { tablet->current_tool_serial = e->value; tablet_set_status(tablet, TABLET_TOOL_UPDATED); - tablet_unset_status(tablet, - TABLET_TOOL_OUT_OF_PROXIMITY); } break; default: @@ -386,9 +385,9 @@ tablet_flush(struct tablet_dispatch *tablet, /* Release all stylus buttons */ tablet->button_state.stylus_buttons = 0; tablet_set_status(tablet, TABLET_BUTTONS_RELEASED); - } else if (tablet_has_status(tablet, TABLET_TOOL_UPDATED)) { - tablet_notify_tool_update(&device->base, time, tool); - tablet_unset_status(tablet, TABLET_TOOL_UPDATED); + } else if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY)) { + tablet_notify_proximity_in(&device->base, time, tool); + tablet_unset_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY); } if (tablet_has_status(tablet, TABLET_AXES_UPDATED)) { diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index 89cf2240..e6e66d74 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -35,7 +35,8 @@ enum tablet_status { TABLET_BUTTONS_RELEASED = 1 << 3, TABLET_STYLUS_IN_CONTACT = 1 << 4, TABLET_TOOL_LEAVING_PROXIMITY = 1 << 5, - TABLET_TOOL_OUT_OF_PROXIMITY = 1 << 6 + TABLET_TOOL_OUT_OF_PROXIMITY = 1 << 6, + TABLET_TOOL_ENTERING_PROXIMITY = 1 << 7 }; struct button_state { diff --git a/src/libinput-private.h b/src/libinput-private.h index db78cca1..e59fe129 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -218,9 +218,9 @@ tablet_notify_axis(struct libinput_device *device, double *axes); void -tablet_notify_tool_update(struct libinput_device *device, - uint32_t time, - struct libinput_tool *tool); +tablet_notify_proximity_in(struct libinput_device *device, + uint32_t time, + struct libinput_tool *tool); void tablet_notify_proximity_out(struct libinput_device *device, diff --git a/src/libinput.c b/src/libinput.c index 65c5b4e8..f054c0d7 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -195,7 +195,7 @@ libinput_event_get_pointer_event(struct libinput_event *event) case LIBINPUT_EVENT_TOUCH_CANCEL: case LIBINPUT_EVENT_TOUCH_FRAME: case LIBINPUT_EVENT_TABLET_AXIS: - case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: + case LIBINPUT_EVENT_TABLET_PROXIMITY_IN: case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: case LIBINPUT_EVENT_TABLET_BUTTON: break; @@ -225,7 +225,7 @@ libinput_event_get_keyboard_event(struct libinput_event *event) case LIBINPUT_EVENT_TOUCH_CANCEL: case LIBINPUT_EVENT_TOUCH_FRAME: case LIBINPUT_EVENT_TABLET_AXIS: - case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: + case LIBINPUT_EVENT_TABLET_PROXIMITY_IN: case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: case LIBINPUT_EVENT_TABLET_BUTTON: break; @@ -255,7 +255,7 @@ libinput_event_get_touch_event(struct libinput_event *event) case LIBINPUT_EVENT_TOUCH_FRAME: return (struct libinput_event_touch *) event; case LIBINPUT_EVENT_TABLET_AXIS: - case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: + case LIBINPUT_EVENT_TABLET_PROXIMITY_IN: case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: case LIBINPUT_EVENT_TABLET_BUTTON: break; @@ -284,7 +284,7 @@ libinput_event_get_tablet_event(struct libinput_event *event) case LIBINPUT_EVENT_TOUCH_FRAME: break; case LIBINPUT_EVENT_TABLET_AXIS: - case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: + case LIBINPUT_EVENT_TABLET_PROXIMITY_IN: case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: case LIBINPUT_EVENT_TABLET_BUTTON: return (struct libinput_event_tablet *) event; @@ -313,7 +313,7 @@ libinput_event_get_device_notify_event(struct libinput_event *event) case LIBINPUT_EVENT_TOUCH_CANCEL: case LIBINPUT_EVENT_TOUCH_FRAME: case LIBINPUT_EVENT_TABLET_AXIS: - case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: + case LIBINPUT_EVENT_TABLET_PROXIMITY_IN: case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: case LIBINPUT_EVENT_TABLET_BUTTON: break; @@ -1254,24 +1254,24 @@ tablet_notify_axis(struct libinput_device *device, } void -tablet_notify_tool_update(struct libinput_device *device, - uint32_t time, - struct libinput_tool *tool) +tablet_notify_proximity_in(struct libinput_device *device, + uint32_t time, + struct libinput_tool *tool) { - struct libinput_event_tablet *tool_update_event; + struct libinput_event_tablet *proximity_in_event; - tool_update_event = zalloc(sizeof *tool_update_event); - if (!tool_update_event) + proximity_in_event = zalloc(sizeof *proximity_in_event); + if (!proximity_in_event) return; - *tool_update_event = (struct libinput_event_tablet) { + *proximity_in_event = (struct libinput_event_tablet) { .time = time, .tool = tool, }; post_device_event(device, - LIBINPUT_EVENT_TABLET_TOOL_UPDATE, - &tool_update_event->base); + LIBINPUT_EVENT_TABLET_PROXIMITY_IN, + &proximity_in_event->base); } void diff --git a/src/libinput.h b/src/libinput.h index 8909e6f9..cfd27d61 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -261,10 +261,10 @@ enum libinput_event_type { LIBINPUT_EVENT_TABLET_AXIS = 600, /** - * Signals that a device with the @ref LIBINPUT_DEVICE_CAP_TABLET - * capability has changed its tool. + * Signals that a tool has come into proximity of a device with the @ref + * LIBINPUT_DEVICE_CAP_TABLET capability. */ - LIBINPUT_EVENT_TABLET_TOOL_UPDATE, + LIBINPUT_EVENT_TABLET_PROXIMITY_IN, /** * Signals that a device with the @ref LIBINPUT_DEVICE_CAP_TABLET * capability has detected that there is no longer a tool in use. When @@ -305,8 +305,8 @@ struct libinput_event_touch; * * 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_TOOL_UPDATE, @ref LIBINPUT_EVENT_TABLET_TOOL_UPDATE and - * @ref LIBINPUT_EVENT_TABLET_BUTTON. + * LIBINPUT_EVENT_TABLET_PROXIMITY_IN, @ref LIBINPUT_EVENT_TABLET_PROXIMITY_IN + * and @ref LIBINPUT_EVENT_TABLET_BUTTON. */ struct libinput_event_tablet; @@ -918,17 +918,18 @@ libinput_event_tablet_get_y_transformed(struct libinput_event_tablet *event, /** * @ingroup event_tablet * - * Return the new tool in use for this event. + * Returns the tool that came into proximity for this event. * For tablet events that are not of type @ref - * LIBINPUT_EVENT_TABLET_TOOL_UPDATE, this function returns NULL. By default, - * the lifetime of each tool is bound to the lifetime of the event, so the tool - * will be destroyed when the event is destroyed. However, the lifetime of the - * tool may be extended by using libinput_tool_ref() to increment the reference - * count of the tool. Whenever libinput detects that the tool is in proximity of - * any tablet that's connected, it will return the same libinput_tool object. + * LIBINPUT_EVENT_TABLET_PROXIMITY_IN, this function returns NULL. By default, + * the lifetime of 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 It is an application bug to call this function for events other than - * @ref LIBINPUT_EVENT_TABLET_TOOL_UPDATE. + * @ref LIBINPUT_EVENT_TABLET_PROXIMITY_IN. * * @note On tablets where the serial number of tools is not reported, each tool * cannot be guaranteed to be unique. diff --git a/test/tablet.c b/test/tablet.c index 0846e748..0e92c36c 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -55,7 +55,7 @@ START_TEST(proximity_in_out) while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_TOOL_UPDATE) { + LIBINPUT_EVENT_TABLET_PROXIMITY_IN) { struct libinput_tool * tool; have_tool_update++; @@ -427,7 +427,7 @@ START_TEST(tool_serial) libinput_dispatch(li); while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_TOOL_UPDATE) { + LIBINPUT_EVENT_TABLET_PROXIMITY_IN) { tablet_event = libinput_event_get_tablet_event(event); tool = libinput_event_tablet_get_tool(tablet_event); @@ -453,16 +453,18 @@ START_TEST(serial_changes_tool) 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); libinput_dispatch(li); while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_TOOL_UPDATE) { + LIBINPUT_EVENT_TABLET_PROXIMITY_IN) { tablet_event = libinput_event_get_tablet_event(event); tool = libinput_event_tablet_get_tool(tablet_event); @@ -481,42 +483,34 @@ START_TEST(invalid_serials) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; - bool tool_updated = false; + 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_TOOL_UPDATE) - tool_updated = true; + LIBINPUT_EVENT_TABLET_PROXIMITY_IN) { + 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); } - ck_assert(!tool_updated); - - /* Make sure libinput doesn't report a tool update when the serial - * number goes back from -1 to what it was previously */ - litest_event(dev, EV_MSC, MSC_SERIAL, 1000); - 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_TOOL_UPDATE) - tool_updated = true; - - libinput_event_destroy(event); - } - ck_assert(!tool_updated); } END_TEST @@ -537,7 +531,7 @@ START_TEST(tool_ref) libinput_dispatch(li); while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_TOOL_UPDATE) { + LIBINPUT_EVENT_TABLET_PROXIMITY_IN) { break; } libinput_event_destroy(event); diff --git a/tools/event-debug.c b/tools/event-debug.c index 299587bb..5c6a0623 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -243,8 +243,8 @@ print_event_header(struct libinput_event *ev) case LIBINPUT_EVENT_TABLET_AXIS: type = "TABLET_AXIS"; break; - case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: - type = "TABLET_TOOL_UPDATE"; + case LIBINPUT_EVENT_TABLET_PROXIMITY_IN: + type = "TABLET_PROXIMITY_IN"; break; case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: type = "TABLET_PROXIMITY_OUT"; @@ -424,7 +424,7 @@ print_touch_event_without_coords(struct libinput_event *ev) } static void -print_tool_update_event(struct libinput_event *ev) +print_proximity_in_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); @@ -543,8 +543,8 @@ handle_and_print_events(struct libinput *li) case LIBINPUT_EVENT_TABLET_AXIS: print_tablet_axis_event(ev); break; - case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: - print_tool_update_event(ev); + case LIBINPUT_EVENT_TABLET_PROXIMITY_IN: + print_proximity_in_event(ev); break; case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: print_proximity_out_event(ev); diff --git a/tools/event-gui.c b/tools/event-gui.c index b184a426..7bc38281 100644 --- a/tools/event-gui.c +++ b/tools/event-gui.c @@ -376,7 +376,7 @@ handle_event_libinput(GIOChannel *source, GIOCondition condition, gpointer data) } break; case LIBINPUT_EVENT_TABLET_AXIS: - case LIBINPUT_EVENT_TABLET_TOOL_UPDATE: + case LIBINPUT_EVENT_TABLET_PROXIMITY_IN: case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: case LIBINPUT_EVENT_TABLET_BUTTON: break; From bcbf9f95fdf7a72628b26f8ef5e90872083e6916 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Thu, 26 Jun 2014 21:31:52 -0400 Subject: [PATCH 049/255] tablet: Include tool with all events Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 41 ++++++++++++++++++++++++++--------------- src/evdev-tablet.h | 13 ++++++------- src/libinput-private.h | 5 ++++- src/libinput.c | 10 ++++++++-- src/libinput.h | 19 +++++++------------ 5 files changed, 51 insertions(+), 37 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index e6595bc4..710e391e 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -94,10 +94,7 @@ tablet_update_tool(struct tablet_dispatch *tablet, assert(tool != LIBINPUT_TOOL_NONE); if (enabled) { - if (tool != tablet->current_tool_type) { - tablet->current_tool_type = tool; - tablet_set_status(tablet, TABLET_TOOL_UPDATED); - } + 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); @@ -126,7 +123,8 @@ normalize_tilt(const struct input_absinfo * absinfo) { static void tablet_check_notify_axes(struct tablet_dispatch *tablet, struct evdev_device *device, - uint32_t time) + uint32_t time, + struct libinput_tool *tool) { struct libinput_device *base = &device->base; bool axis_update_needed = false; @@ -169,6 +167,7 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, !tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) tablet_notify_axis(base, time, + tool, tablet->changed_axes, tablet->axes); @@ -247,11 +246,9 @@ tablet_process_misc(struct tablet_dispatch *tablet, { switch (e->code) { case MSC_SERIAL: - if (e->value != (int32_t)tablet->current_tool_serial && - e->value != -1) { + if (e->value != -1) tablet->current_tool_serial = e->value; - tablet_set_status(tablet, TABLET_TOOL_UPDATED); - } + break; default: log_info(device->base.seat->libinput, @@ -297,6 +294,7 @@ static void tablet_notify_button_mask(struct tablet_dispatch *tablet, struct evdev_device *device, uint32_t time, + struct libinput_tool *tool, uint32_t buttons, uint32_t button_base, enum libinput_button_state state) @@ -316,6 +314,7 @@ tablet_notify_button_mask(struct tablet_dispatch *tablet, tablet_notify_button(base, time, + tool, num_button + button_base - 1, state); } @@ -325,6 +324,7 @@ static void tablet_notify_buttons(struct tablet_dispatch *tablet, struct evdev_device *device, uint32_t time, + struct libinput_tool *tool, enum libinput_button_state state) { uint32_t stylus_buttons; @@ -336,8 +336,13 @@ tablet_notify_buttons(struct tablet_dispatch *tablet, stylus_buttons = tablet_get_released_buttons(tablet, stylus_buttons); - tablet_notify_button_mask(tablet, device, time, - stylus_buttons, BTN_TOUCH, state); + tablet_notify_button_mask(tablet, + device, + time, + tool, + stylus_buttons, + BTN_TOUCH, + state); } static void @@ -392,24 +397,30 @@ tablet_flush(struct tablet_dispatch *tablet, if (tablet_has_status(tablet, TABLET_AXES_UPDATED)) { sanitize_tablet_axes(tablet); - tablet_check_notify_axes(tablet, device, time); + tablet_check_notify_axes(tablet, device, time, tool); tablet_unset_status(tablet, TABLET_AXES_UPDATED); } if (tablet_has_status(tablet, TABLET_BUTTONS_RELEASED)) { - tablet_notify_buttons(tablet, device, time, + 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, + 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)) { - tablet_notify_proximity_out(&device->base, time); + tablet_notify_proximity_out(&device->base, time, tool); tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY); tablet_unset_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY); } diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index e6e66d74..4de4ceca 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -30,13 +30,12 @@ enum tablet_status { TABLET_NONE = 0, TABLET_AXES_UPDATED = 1 << 0, - TABLET_TOOL_UPDATED = 1 << 1, - TABLET_BUTTONS_PRESSED = 1 << 2, - TABLET_BUTTONS_RELEASED = 1 << 3, - TABLET_STYLUS_IN_CONTACT = 1 << 4, - TABLET_TOOL_LEAVING_PROXIMITY = 1 << 5, - TABLET_TOOL_OUT_OF_PROXIMITY = 1 << 6, - TABLET_TOOL_ENTERING_PROXIMITY = 1 << 7 + 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 { diff --git a/src/libinput-private.h b/src/libinput-private.h index e59fe129..a396d783 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -214,6 +214,7 @@ touch_notify_touch_up(struct libinput_device *device, void tablet_notify_axis(struct libinput_device *device, uint32_t time, + struct libinput_tool *tool, unsigned char *changed_axes, double *axes); @@ -224,11 +225,13 @@ tablet_notify_proximity_in(struct libinput_device *device, void tablet_notify_proximity_out(struct libinput_device *device, - uint32_t time); + uint32_t time, + struct libinput_tool *tool); void tablet_notify_button(struct libinput_device *device, uint32_t time, + struct libinput_tool *tool, int32_t button, enum libinput_button_state state); void diff --git a/src/libinput.c b/src/libinput.c index f054c0d7..7d9d6a0f 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1230,6 +1230,7 @@ touch_notify_frame(struct libinput_device *device, void tablet_notify_axis(struct libinput_device *device, uint32_t time, + struct libinput_tool *tool, unsigned char *changed_axes, double *axes) { @@ -1241,6 +1242,7 @@ tablet_notify_axis(struct libinput_device *device, *axis_event = (struct libinput_event_tablet) { .time = time, + .tool = tool, .axes = axes, }; @@ -1276,7 +1278,8 @@ tablet_notify_proximity_in(struct libinput_device *device, void tablet_notify_proximity_out(struct libinput_device *device, - uint32_t time) + uint32_t time, + struct libinput_tool *tool) { struct libinput_event_tablet *proximity_out_update_event; @@ -1285,7 +1288,8 @@ tablet_notify_proximity_out(struct libinput_device *device, return; *proximity_out_update_event = (struct libinput_event_tablet) { - .time = time + .time = time, + .tool = tool, }; post_device_event(device, @@ -1296,6 +1300,7 @@ tablet_notify_proximity_out(struct libinput_device *device, void tablet_notify_button(struct libinput_device *device, uint32_t time, + struct libinput_tool *tool, int32_t button, enum libinput_button_state state) { @@ -1312,6 +1317,7 @@ tablet_notify_button(struct libinput_device *device, *button_event = (struct libinput_event_tablet) { .time = time, + .tool = tool, .button = button, .state = state, .seat_button_count = seat_button_count, diff --git a/src/libinput.h b/src/libinput.h index cfd27d61..37edac53 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -918,18 +918,13 @@ libinput_event_tablet_get_y_transformed(struct libinput_event_tablet *event, /** * @ingroup event_tablet * - * Returns the tool that came into proximity for this event. - * For tablet events that are not of type @ref - * LIBINPUT_EVENT_TABLET_PROXIMITY_IN, this function returns NULL. By default, - * the lifetime of 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 It is an application bug to call this function for events other than - * @ref LIBINPUT_EVENT_TABLET_PROXIMITY_IN. + * 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. From 7fbb08e0ca7a4565bd8262e6b7e1fce57fd511e8 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 26 Jun 2014 21:31:53 -0400 Subject: [PATCH 050/255] tablet: copy the axis state into the tablet event The tablet state updates with each event during libinput_dispatch(), but the state in the event must reflect the state at the time of the event. Signed-off-by: Peter Hutterer Signed-off-by: Stephen Chandler Paul --- src/libinput.c | 4 +-- test/tablet.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 2 deletions(-) diff --git a/src/libinput.c b/src/libinput.c index 7d9d6a0f..ecbe33fc 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -86,7 +86,7 @@ struct libinput_event_tablet { enum libinput_button_state state; uint32_t seat_button_count; uint32_t time; - double *axes; + double axes[LIBINPUT_TABLET_AXIS_CNT]; unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_AXIS_CNT)]; struct libinput_tool *tool; }; @@ -1243,12 +1243,12 @@ tablet_notify_axis(struct libinput_device *device, *axis_event = (struct libinput_event_tablet) { .time = time, .tool = tool, - .axes = axes, }; memcpy(axis_event->changed_axes, changed_axes, sizeof(axis_event->changed_axes)); + memcpy(axis_event->axes, axes, sizeof(axis_event->axes)); post_device_event(device, LIBINPUT_EVENT_TABLET_AXIS, diff --git a/test/tablet.c b/test/tablet.c index 0e92c36c..70690743 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -239,6 +239,88 @@ START_TEST(motion) } 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_proximity_in(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_proximity_in(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(); @@ -610,6 +692,7 @@ main(int argc, char **argv) litest_add("tablet:proximity", proximity_in_out, 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_event_state, LITEST_TABLET, LITEST_ANY); litest_add("tablet:normalization", normalization, LITEST_TABLET, LITEST_ANY); litest_add("tablet:pad", pad_buttons_ignored, LITEST_TABLET, LITEST_ANY); From 521bd2f11211124fea8d8314c70a9fcd86a1f9df Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Thu, 26 Jun 2014 21:31:54 -0400 Subject: [PATCH 051/255] tablet: Include axes with all events Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 11 +++++++++-- src/libinput-private.h | 7 +++++-- src/libinput.c | 14 ++++++++++++-- src/libinput.h | 3 --- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 710e391e..051c3b48 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -315,6 +315,7 @@ tablet_notify_button_mask(struct tablet_dispatch *tablet, tablet_notify_button(base, time, tool, + tablet->axes, num_button + button_base - 1, state); } @@ -391,7 +392,10 @@ tablet_flush(struct tablet_dispatch *tablet, tablet->button_state.stylus_buttons = 0; tablet_set_status(tablet, TABLET_BUTTONS_RELEASED); } else if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY)) { - tablet_notify_proximity_in(&device->base, time, tool); + tablet_notify_proximity_in(&device->base, + time, + tool, + tablet->axes); tablet_unset_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY); } @@ -420,7 +424,10 @@ tablet_flush(struct tablet_dispatch *tablet, } if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) { - tablet_notify_proximity_out(&device->base, time, tool); + tablet_notify_proximity_out(&device->base, + time, + tool, + tablet->axes); tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY); tablet_unset_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY); } diff --git a/src/libinput-private.h b/src/libinput-private.h index a396d783..dbdf5e6d 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -221,17 +221,20 @@ tablet_notify_axis(struct libinput_device *device, void tablet_notify_proximity_in(struct libinput_device *device, uint32_t time, - struct libinput_tool *tool); + struct libinput_tool *tool, + double *axes); void tablet_notify_proximity_out(struct libinput_device *device, uint32_t time, - struct libinput_tool *tool); + struct libinput_tool *tool, + double *axes); void tablet_notify_button(struct libinput_device *device, uint32_t time, struct libinput_tool *tool, + double *axes, int32_t button, enum libinput_button_state state); void diff --git a/src/libinput.c b/src/libinput.c index ecbe33fc..5d26bc91 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1258,7 +1258,8 @@ tablet_notify_axis(struct libinput_device *device, void tablet_notify_proximity_in(struct libinput_device *device, uint32_t time, - struct libinput_tool *tool) + struct libinput_tool *tool, + double *axes) { struct libinput_event_tablet *proximity_in_event; @@ -1270,6 +1271,9 @@ tablet_notify_proximity_in(struct libinput_device *device, .time = time, .tool = tool, }; + memcpy(proximity_in_event->axes, + axes, + sizeof(proximity_in_event->axes)); post_device_event(device, LIBINPUT_EVENT_TABLET_PROXIMITY_IN, @@ -1279,7 +1283,8 @@ tablet_notify_proximity_in(struct libinput_device *device, void tablet_notify_proximity_out(struct libinput_device *device, uint32_t time, - struct libinput_tool *tool) + struct libinput_tool *tool, + double *axes) { struct libinput_event_tablet *proximity_out_update_event; @@ -1291,6 +1296,9 @@ tablet_notify_proximity_out(struct libinput_device *device, .time = time, .tool = tool, }; + memcpy(proximity_out_update_event->axes, + axes, + sizeof(proximity_out_update_event->axes)); post_device_event(device, LIBINPUT_EVENT_TABLET_PROXIMITY_OUT, @@ -1301,6 +1309,7 @@ void tablet_notify_button(struct libinput_device *device, uint32_t time, struct libinput_tool *tool, + double *axes, int32_t button, enum libinput_button_state state) { @@ -1322,6 +1331,7 @@ tablet_notify_button(struct libinput_device *device, .state = state, .seat_button_count = seat_button_count, }; + memcpy(button_event->axes, axes, sizeof(button_event->axes)); post_device_event(device, LIBINPUT_EVENT_TABLET_BUTTON, diff --git a/src/libinput.h b/src/libinput.h index 37edac53..fa87094f 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -876,9 +876,6 @@ libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, * that indicates the tilt vertical or horizontal tilt of the tool * respectively * - * For tablet events that are not of type @ref LIBINPUT_EVENT_TABLET_AXIS, this - * function returns 0. - * * @param event The libinput tablet event * @param axis The axis to retrieve the value of * @return The current value of the the axis From 43356a297960bd4c5f955771796e9b50d7d47b87 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Wed, 9 Jul 2014 01:14:48 -0400 Subject: [PATCH 052/255] tablet: Rename TILT_VERTICAL and TILT_HORIZONTAL to TILT_X and TILT_Y Since the orientation of the tablet can potentially change, this naming scheme makes a lot more sense then VERTICAL and HORIZONTAL does since they don't reflect the actual physical movement. Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 4 ++-- src/evdev-tablet.h | 8 ++++---- src/libinput.h | 13 ++++++------- test/tablet.c | 16 ++++++++-------- tools/event-debug.c | 8 ++++---- 5 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 051c3b48..d1ad4bb0 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -149,8 +149,8 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, case LIBINPUT_TABLET_AXIS_PRESSURE: tablet->axes[a] = normalize_pressure_or_dist(absinfo); break; - case LIBINPUT_TABLET_AXIS_TILT_VERTICAL: - case LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL: + case LIBINPUT_TABLET_AXIS_TILT_X: + case LIBINPUT_TABLET_AXIS_TILT_Y: tablet->axes[a] = normalize_tilt(absinfo); break; default: diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index 4de4ceca..74447bd9 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -75,10 +75,10 @@ evcode_to_axis(const uint32_t evcode) axis = LIBINPUT_TABLET_AXIS_PRESSURE; break; case ABS_TILT_X: - axis = LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL; + axis = LIBINPUT_TABLET_AXIS_TILT_Y; break; case ABS_TILT_Y: - axis = LIBINPUT_TABLET_AXIS_TILT_VERTICAL; + axis = LIBINPUT_TABLET_AXIS_TILT_X; break; default: axis = LIBINPUT_TABLET_AXIS_NONE; @@ -106,10 +106,10 @@ axis_to_evcode(const enum libinput_tablet_axis axis) case LIBINPUT_TABLET_AXIS_PRESSURE: evcode = ABS_PRESSURE; break; - case LIBINPUT_TABLET_AXIS_TILT_VERTICAL: + case LIBINPUT_TABLET_AXIS_TILT_X: evcode = ABS_TILT_X; break; - case LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL: + case LIBINPUT_TABLET_AXIS_TILT_Y: evcode = ABS_TILT_Y; break; default: diff --git a/src/libinput.h b/src/libinput.h index fa87094f..14e533e7 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -182,9 +182,9 @@ enum libinput_tablet_axis { LIBINPUT_TABLET_AXIS_Y = 1, LIBINPUT_TABLET_AXIS_DISTANCE = 2, LIBINPUT_TABLET_AXIS_PRESSURE = 3, - LIBINPUT_TABLET_AXIS_TILT_VERTICAL = 4, - LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL = 5, - LIBINPUT_TABLET_AXIS_CNT = LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL + 1 + LIBINPUT_TABLET_AXIS_TILT_X = 4, + LIBINPUT_TABLET_AXIS_TILT_Y = 5, + LIBINPUT_TABLET_AXIS_CNT = LIBINPUT_TABLET_AXIS_TILT_Y + 1 }; /** @@ -871,10 +871,9 @@ libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, * 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_VERTICAL and @ref - * LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL - normalized value between -1 and 1 - * that indicates the tilt vertical or horizontal tilt of the tool - * respectively + * - @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 * * @param event The libinput tablet event * @param axis The axis to retrieve the value of diff --git a/test/tablet.c b/test/tablet.c index 70690743..0cd6357c 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -403,22 +403,22 @@ START_TEST(normalization) if (libinput_event_tablet_axis_has_changed( tablet_event, - LIBINPUT_TABLET_AXIS_TILT_VERTICAL)) { + LIBINPUT_TABLET_AXIS_TILT_X)) { tilt_vertical = libinput_event_tablet_get_axis_value( tablet_event, - LIBINPUT_TABLET_AXIS_TILT_VERTICAL); + 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_HORIZONTAL)) { + LIBINPUT_TABLET_AXIS_TILT_Y)) { tilt_horizontal = libinput_event_tablet_get_axis_value( tablet_event, - LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL); + LIBINPUT_TABLET_AXIS_TILT_Y); litest_assert_double_eq(tilt_horizontal, -1); } @@ -465,22 +465,22 @@ START_TEST(normalization) if (libinput_event_tablet_axis_has_changed( tablet_event, - LIBINPUT_TABLET_AXIS_TILT_VERTICAL)) { + LIBINPUT_TABLET_AXIS_TILT_X)) { tilt_vertical = libinput_event_tablet_get_axis_value( tablet_event, - LIBINPUT_TABLET_AXIS_TILT_VERTICAL); + 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_HORIZONTAL)) { + LIBINPUT_TABLET_AXIS_TILT_Y)) { tilt_horizontal = libinput_event_tablet_get_axis_value( tablet_event, - LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL); + LIBINPUT_TABLET_AXIS_TILT_Y); litest_assert_double_eq(tilt_horizontal, 1); } diff --git a/tools/event-debug.c b/tools/event-debug.c index 5c6a0623..acf9d815 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -397,11 +397,11 @@ print_tablet_axis_event(struct libinput_event *ev) x, tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_X), y, tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_Y)); - x = libinput_event_tablet_get_axis_value(t, LIBINPUT_TABLET_AXIS_TILT_VERTICAL); - y = libinput_event_tablet_get_axis_value(t, LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL); + 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); printf("\ttilt: %.2f%s/%.2f%s ", - x, tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_TILT_VERTICAL), - y, tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_TILT_HORIZONTAL)); + x, tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_TILT_X), + y, tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_TILT_Y)); dist = libinput_event_tablet_get_axis_value(t, LIBINPUT_TABLET_AXIS_DISTANCE); pressure = libinput_event_tablet_get_axis_value(t, LIBINPUT_TABLET_AXIS_PRESSURE); From 7444926b29b3346a6c4862bb09667ea42ef9be97 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Thu, 10 Jul 2014 15:10:12 -0400 Subject: [PATCH 053/255] tablet: Don't swap X and Y in evcode_to_axis() Signed-off-by: Stephen Chandler Paul Signed-off-by: Peter Hutterer --- src/evdev-tablet.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index 74447bd9..1b53d201 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -75,10 +75,10 @@ evcode_to_axis(const uint32_t evcode) axis = LIBINPUT_TABLET_AXIS_PRESSURE; break; case ABS_TILT_X: - axis = LIBINPUT_TABLET_AXIS_TILT_Y; + axis = LIBINPUT_TABLET_AXIS_TILT_X; break; case ABS_TILT_Y: - axis = LIBINPUT_TABLET_AXIS_TILT_X; + axis = LIBINPUT_TABLET_AXIS_TILT_Y; break; default: axis = LIBINPUT_TABLET_AXIS_NONE; From 2de220f3dd671c773ef0f674e2050279291a5872 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 25 Jun 2014 15:37:33 +1000 Subject: [PATCH 054/255] test: add missing BTN_TOOL_ settings to Wacom I5 Signed-off-by: Peter Hutterer --- test/litest-wacom-intuos-tablet.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/litest-wacom-intuos-tablet.c b/test/litest-wacom-intuos-tablet.c index e30d6066..2d95ad14 100644 --- a/test/litest-wacom-intuos-tablet.c +++ b/test/litest-wacom-intuos-tablet.c @@ -113,6 +113,11 @@ static int events[] = { 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, From 78b474ee37ed01910244838a809d2c3e1fec0c66 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Sun, 20 Jul 2014 22:20:41 -0400 Subject: [PATCH 055/255] tablet: fix get_x_transformed() and get_y_transformed() Because the values for each axis were stored in struct tablet_dispatch in millimeters, coordinates were not being translated properly to screen coordinates. This stores the values internally as raw coordinates, and only translates them to millimeters if the client asks for it. Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 3 +-- src/libinput.c | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index d1ad4bb0..31dd8d7c 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -142,8 +142,7 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, switch (a) { case LIBINPUT_TABLET_AXIS_X: case LIBINPUT_TABLET_AXIS_Y: - tablet->axes[a] = evdev_convert_to_mm(absinfo, - absinfo->value); + tablet->axes[a] = absinfo->value; break; case LIBINPUT_TABLET_AXIS_DISTANCE: case LIBINPUT_TABLET_AXIS_PRESSURE: diff --git a/src/libinput.c b/src/libinput.c index e013f490..9aa7cbcf 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -504,11 +504,27 @@ 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) return 0; - return (axis >= 0 && axis < LIBINPUT_TABLET_AXIS_CNT) ? - event->axes[axis] : 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: + return event->axes[axis]; + default: + return 0; + } } LIBINPUT_EXPORT double From 11e0558f917984f1b5e36722851d2f29ef1968f0 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Tue, 5 Aug 2014 17:49:39 -0400 Subject: [PATCH 056/255] tablet: Add libinput_tool_get/set_user_data() Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/libinput-private.h | 1 + src/libinput.c | 13 +++++++++++++ src/libinput.h | 23 +++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/src/libinput-private.h b/src/libinput-private.h index 6ec36376..81875644 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -109,6 +109,7 @@ struct libinput_tool { uint32_t serial; enum libinput_tool_type type; int refcount; + void *user_data; }; typedef void (*libinput_source_dispatch_t)(void *data); diff --git a/src/libinput.c b/src/libinput.c index 9aa7cbcf..68187d8c 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -599,6 +599,19 @@ libinput_tool_get_serial(struct libinput_tool *tool) return tool->serial; } +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) { diff --git a/src/libinput.h b/src/libinput.h index a9ad379a..1d4952b0 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1034,6 +1034,29 @@ libinput_tool_unref(struct libinput_tool *tool); 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 */ From 142cc66880a806fcd6667eeda30ed41769765379 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Thu, 7 Aug 2014 19:00:52 -0400 Subject: [PATCH 057/255] tablet: Use separate tool objects for tools without serials With tablets that don't support serial numbers, we can't guarantee that the tool objects are unique. Because of this, this can give clients the false impression that a tool without a serial number is being shared between tablets when it very well might not be. So we keep tools without serial numbers in a list that's local to the tablet they belong to, and keep tools with serials in a list that's global within the libinput context. Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 41 +++++++++++++++++---- src/evdev-tablet.h | 3 ++ test/tablet.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+), 8 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 31dd8d7c..15f0663b 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -259,17 +259,36 @@ tablet_process_misc(struct tablet_dispatch *tablet, } static struct libinput_tool * -tablet_get_tool(struct libinput *li, +tablet_get_tool(struct tablet_dispatch *tablet, enum libinput_tool_type type, uint32_t serial) { struct libinput_tool *tool = NULL, *t; + struct list *tool_list; - /* Check if we already have the tool in our list of tools */ - list_for_each(t, &li->tool_list, link) { - if (type == t->type && serial == t->serial) { - tool = t; - break; + 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; + } } } @@ -283,7 +302,7 @@ tablet_get_tool(struct libinput *li, .refcount = 1, }; - list_insert(&li->tool_list, &tool->link); + list_insert(tool_list, &tool->link); } return tool; @@ -382,7 +401,7 @@ tablet_flush(struct tablet_dispatch *tablet, uint32_t time) { struct libinput_tool *tool = - tablet_get_tool(device->base.seat->libinput, + tablet_get_tool(tablet, tablet->current_tool_type, tablet->current_tool_serial); @@ -473,6 +492,11 @@ 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); } @@ -490,6 +514,7 @@ tablet_init(struct tablet_dispatch *tablet, tablet->device = device; tablet->status = TABLET_NONE; tablet->current_tool_type = LIBINPUT_TOOL_NONE; + list_init(&tablet->tool_list); tablet_mark_all_axes_changed(tablet, device); diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index 1b53d201..adc3aa4a 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -49,6 +49,9 @@ struct tablet_dispatch { unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_AXIS_CNT)]; double axes[LIBINPUT_TABLET_AXIS_CNT]; + /* 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; diff --git a/test/tablet.c b/test/tablet.c index 0cd6357c..3617a8be 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -681,6 +681,95 @@ START_TEST(pad_buttons_ignored) } 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); + + 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_IN) { + 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); + + 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_IN) { + 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 + int main(int argc, char **argv) { @@ -688,6 +777,8 @@ main(int argc, char **argv) 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", bad_distance_events, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY); From a0c9f1224e26731ae1393c625cf262a11d49db89 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Thu, 7 Aug 2014 22:02:22 -0400 Subject: [PATCH 058/255] tablet: Add libinput_tool_has_axis() and tests Because the axes that tool reports can change depending on the tool in use, we want to be able to provide functionality to determine which axes each tool can support. Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 47 ++++++++++++++++++++++++++ src/evdev-tablet.h | 1 + src/libinput-private.h | 1 + src/libinput.c | 7 ++++ src/libinput.h | 13 ++++++++ test/tablet.c | 76 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 145 insertions(+) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 15f0663b..a63b734a 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -302,6 +302,44 @@ tablet_get_tool(struct tablet_dispatch *tablet, .refcount = 1, }; + /* Determine the axis capabilities of the tool. Here's a break + * down of the heuristics used here: + * - The Wacom art pen supports all of the extra axes, along + * with rotation + * - All of normal pens and the airbrush support all of the + * extra axes if the tablet can report them + * - All of the mouse like devices don't really report any of + * the extra axes except for rotation. + * (as of writing this comment, rotation isn't supported, so you + * won't see the mouse or art pen here) + */ + switch (type) { + case LIBINPUT_TOOL_PEN: + case LIBINPUT_TOOL_ERASER: + case LIBINPUT_TOOL_PENCIL: + case LIBINPUT_TOOL_BRUSH: + case LIBINPUT_TOOL_AIRBRUSH: + if (bit_is_set(tablet->axis_caps, + LIBINPUT_TABLET_AXIS_PRESSURE)) + set_bit(tool->axis_caps, + LIBINPUT_TABLET_AXIS_PRESSURE); + if (bit_is_set(tablet->axis_caps, + LIBINPUT_TABLET_AXIS_DISTANCE)) + set_bit(tool->axis_caps, + LIBINPUT_TABLET_AXIS_DISTANCE); + if (bit_is_set(tablet->axis_caps, + LIBINPUT_TABLET_AXIS_TILT_X)) + set_bit(tool->axis_caps, + LIBINPUT_TABLET_AXIS_TILT_X); + if (bit_is_set(tablet->axis_caps, + LIBINPUT_TABLET_AXIS_TILT_Y)) + set_bit(tool->axis_caps, + LIBINPUT_TABLET_AXIS_TILT_Y); + break; + default: + break; + } + list_insert(tool_list, &tool->link); } @@ -510,12 +548,21 @@ 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 = 0; axis < LIBINPUT_TABLET_AXIS_CNT; axis++) { + if (libevdev_has_event_code(device->evdev, + EV_ABS, + axis_to_evcode(axis))) + set_bit(tablet->axis_caps, axis); + } + tablet_mark_all_axes_changed(tablet, device); return 0; diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index adc3aa4a..cb375771 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -48,6 +48,7 @@ struct tablet_dispatch { unsigned char status; unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_AXIS_CNT)]; double axes[LIBINPUT_TABLET_AXIS_CNT]; + unsigned char axis_caps[NCHARS(LIBINPUT_TABLET_AXIS_CNT)]; /* Only used for tablets that don't report serial numbers */ struct list tool_list; diff --git a/src/libinput-private.h b/src/libinput-private.h index 81875644..369bb8f3 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -108,6 +108,7 @@ struct libinput_tool { struct list link; uint32_t serial; enum libinput_tool_type type; + unsigned char axis_caps[NCHARS(LIBINPUT_TABLET_AXIS_CNT)]; int refcount; void *user_data; }; diff --git a/src/libinput.c b/src/libinput.c index 68187d8c..e52527be 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -599,6 +599,13 @@ 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 void libinput_tool_set_user_data(struct libinput_tool *tool, void *user_data) diff --git a/src/libinput.h b/src/libinput.h index 1d4952b0..ed56c0bb 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1007,6 +1007,19 @@ libinput_tool_get_type(struct libinput_tool *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 * diff --git a/test/tablet.c b/test/tablet.c index 3617a8be..e1fb60d2 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -770,10 +770,86 @@ START_TEST(tools_without_serials) } END_TEST +START_TEST(tool_capabilities) +{ + struct libinput *li = litest_create_context(); + struct litest_device *intuos; + struct litest_device *bamboo; + struct libinput_event *event; + + /* The axis capabilities of a tool can differ depending on the type of + * tablet the tool is being used with */ + bamboo = litest_create_device_with_overrides(LITEST_WACOM_BAMBOO, + NULL, + NULL, + NULL, + NULL); + intuos = litest_create_device_with_overrides(LITEST_WACOM_INTUOS, + NULL, + NULL, + NULL, + NULL); + + litest_event(bamboo, EV_KEY, BTN_TOOL_PEN, 1); + litest_event(bamboo, EV_SYN, SYN_REPORT, 0); + + libinput_dispatch(li); + while ((event = libinput_get_event(li))) { + if (libinput_event_get_type(event) == + LIBINPUT_EVENT_TABLET_PROXIMITY_IN) { + struct libinput_event_tablet *t = + libinput_event_get_tablet_event(event); + struct libinput_tool *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_event(intuos, EV_KEY, BTN_TOOL_PEN, 1); + litest_event(intuos, EV_SYN, SYN_REPORT, 0); + + while ((event = libinput_get_event(li))) { + if (libinput_event_get_type(event) == + LIBINPUT_EVENT_TABLET_PROXIMITY_IN) { + struct libinput_event_tablet *t = + libinput_event_get_tablet_event(event); + struct libinput_tool *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_delete_device(bamboo); + litest_delete_device(intuos); + libinput_unref(li); +} +END_TEST + int main(int argc, char **argv) { 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_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); From cd5c9dce3b700f442b7bb051439737281e3fce62 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 22 Sep 2014 15:48:22 +1000 Subject: [PATCH 059/255] test: put two warnings into the tablet tests These tests rely on libevdev doing the right thing, which it only does when it uses the UI_GET_SYSNAME ioctl. Signed-off-by: Peter Hutterer --- test/tablet.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/tablet.c b/test/tablet.c index e1fb60d2..6d98bebd 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -696,6 +696,10 @@ START_TEST(tools_with_serials) 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); @@ -742,6 +746,11 @@ START_TEST(tools_without_serials) 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); From 297cbe48086fac152bbcadc59deedf5c6eac7bde Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Wed, 8 Oct 2014 14:53:21 -0700 Subject: [PATCH 060/255] Fix normalization functions We need to *subtract*, not *add* the minimum to determine the range-effective value. For example: if (min, current, max) is (100, 100, 1000) then the normalized value would be 0.0, not 0.2. Signed-off-by: Jason Gerecke Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index a63b734a..ff5f7373 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -106,7 +106,7 @@ tablet_update_tool(struct tablet_dispatch *tablet, static inline double normalize_pressure_or_dist(const struct input_absinfo * absinfo) { double range = absinfo->maximum - absinfo->minimum + 1; - double value = (absinfo->value + absinfo->minimum) / range; + double value = (absinfo->value - absinfo->minimum) / range; return value; } @@ -114,7 +114,7 @@ normalize_pressure_or_dist(const struct input_absinfo * absinfo) { static inline double normalize_tilt(const struct input_absinfo * absinfo) { double range = absinfo->maximum - absinfo->minimum + 1; - double value = (absinfo->value + absinfo->minimum) / range; + double value = (absinfo->value - absinfo->minimum) / range; /* Map to the (-1, 1) range */ return (value * 2) - 1; From 1809baa59ed96fbefda04257d0d52eb71fa9e95b Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 8 Dec 2014 12:36:51 +1000 Subject: [PATCH 061/255] tablet: initialize all unused dispatch callbacks to NULL evdev-tablet.c:545:1: warning: missing initializer for field 'device_added' of 'struct evdev_dispatch_interface' [-Wmissing-field-initializers] and similar Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index ff5f7373..6f18f9a0 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -541,7 +541,12 @@ tablet_destroy(struct evdev_dispatch *dispatch) static struct evdev_dispatch_interface tablet_interface = { tablet_process, - tablet_destroy + tablet_destroy, + NULL, /* device_added */ + NULL, /* device_removed */ + NULL, /* device_suspended */ + NULL, /* device_resumed */ + NULL, /* tag_device */ }; static int From a5d80f02f6d63f3cc757a965654ef061f0a972e1 Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Fri, 5 Dec 2014 15:13:34 -0800 Subject: [PATCH 062/255] Remove spurious addition from range normalization calculation The presence of a "+1" in the range calculation prevents the normalization functions from returning a value of "1.0" when absinfo->value has reached its maximum. Signed-off-by: Jason Gerecke Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 4 ++-- test/tablet.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 6f18f9a0..4f1bc768 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -105,7 +105,7 @@ tablet_update_tool(struct tablet_dispatch *tablet, static inline double normalize_pressure_or_dist(const struct input_absinfo * absinfo) { - double range = absinfo->maximum - absinfo->minimum + 1; + double range = absinfo->maximum - absinfo->minimum; double value = (absinfo->value - absinfo->minimum) / range; return value; @@ -113,7 +113,7 @@ normalize_pressure_or_dist(const struct input_absinfo * absinfo) { static inline double normalize_tilt(const struct input_absinfo * absinfo) { - double range = absinfo->maximum - absinfo->minimum + 1; + double range = absinfo->maximum - absinfo->minimum; double value = (absinfo->value - absinfo->minimum) / range; /* Map to the (-1, 1) range */ diff --git a/test/tablet.c b/test/tablet.c index 6d98bebd..367c4db4 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -438,13 +438,13 @@ START_TEST(normalization) litest_event(dev, EV_ABS, ABS_TILT_X, - tilt_vertical_absinfo->maximum + 1); + tilt_vertical_absinfo->maximum); if (tilt_horizontal_absinfo != NULL) litest_event(dev, EV_ABS, ABS_TILT_Y, - tilt_horizontal_absinfo->maximum + 1); + tilt_horizontal_absinfo->maximum); litest_event(dev, EV_SYN, SYN_REPORT, 0); From 9c9524d9e8086336e068161fc5ae803ba7b81dfa Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 8 Dec 2014 13:43:33 +1000 Subject: [PATCH 063/255] Drop LIBINPUT_TABLET_AXIS_CNT from the public API Avoid mismatches in what the caller expects vs what libinput actually provides when building against newer/older versions of libinput. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/libinput-private.h | 2 ++ src/libinput.h | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libinput-private.h b/src/libinput-private.h index 85267761..49232f9e 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -30,6 +30,8 @@ #include "libinput.h" #include "libinput-util.h" +#define LIBINPUT_TABLET_AXIS_CNT LIBINPUT_TABLET_AXIS_TILT_Y + 1 + struct libinput_source; struct libinput_interface_backend { diff --git a/src/libinput.h b/src/libinput.h index 78bb9eff..d59435da 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -277,7 +277,6 @@ enum libinput_tablet_axis { LIBINPUT_TABLET_AXIS_PRESSURE = 3, LIBINPUT_TABLET_AXIS_TILT_X = 4, LIBINPUT_TABLET_AXIS_TILT_Y = 5, - LIBINPUT_TABLET_AXIS_CNT = LIBINPUT_TABLET_AXIS_TILT_Y + 1 }; /** From 56004ba34bb9cdde1d95d36532be283d61bf86d7 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Mon, 19 Jan 2015 20:54:45 -0500 Subject: [PATCH 064/255] evdev.c: Return from evdev_configure_device() after configuring a device as a tablet As it turns out upon detecting a tablet in evdev_configure_device(), there isn't any call to return to escape the function once we've finished configuring the tablet. As a result, the code continues running and ends up reconfiguring the device as a pointer, resulting in strange behavior such as left-handed mode being enabled by default. Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/evdev.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/evdev.c b/src/evdev.c index 939d266c..defd0042 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -1448,6 +1448,7 @@ evdev_configure_device(struct evdev_device *device) log_info(libinput, "input device '%s', %s is a tablet\n", device->devname, devnode); + return device->dispatch == NULL ? -1 : 0; } for (i = 0; i < KEY_MAX; i++) { From 810601581cc1e67e41aec139bd2a80f190aec709 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 20 Jan 2015 15:32:07 +1000 Subject: [PATCH 065/255] Move the tablet functions to the 0.9.0 symbol table Signed-off-by: Peter Hutterer --- src/libinput.sym | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/libinput.sym b/src/libinput.sym index e49f0f34..b1dbba32 100644 --- a/src/libinput.sym +++ b/src/libinput.sym @@ -117,6 +117,17 @@ global: libinput_udev_create_context; libinput_unref; +local: + *; +}; + +LIBINPUT_0.9.0 { +global: + libinput_device_config_click_get_default_method; + libinput_device_config_click_get_method; + libinput_device_config_click_get_methods; + libinput_device_config_click_set_method; + /* tablet APIs, they are not part of any stable API promise yet. * keep them separate */ libinput_event_get_tablet_event; @@ -136,14 +147,4 @@ global: libinput_tool_ref; libinput_tool_set_user_data; libinput_tool_unref; -local: - *; -}; - -LIBINPUT_0.9.0 { -global: - libinput_device_config_click_get_default_method; - libinput_device_config_click_get_method; - libinput_device_config_click_get_methods; - libinput_device_config_click_set_method; } LIBINPUT_0.8.0; From cd17ee44aeeddf21f9cb39a32b675e0ec9f4825d Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 20 Jan 2015 14:13:48 +1000 Subject: [PATCH 066/255] Fix a copy/paste error Signed-off-by: Peter Hutterer --- src/libinput.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libinput.h b/src/libinput.h index 50db7e56..0cdda00d 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -427,7 +427,7 @@ libinput_event_get_touch_event(struct libinput_event *event); * * The inverse of this function is libinput_event_tablet_get_base_event(). * - * @return A touch event, or NULL for other events + * @return A tablet event, or NULL for other events */ struct libinput_event_tablet * libinput_event_get_tablet_event(struct libinput_event *event); From f571ccc8293d71a719b8967d74a79b64025a7d0a Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 10 Feb 2015 11:07:30 +1000 Subject: [PATCH 067/255] test: force the motion test to be axis events only Ignore anything before the TABLET_AXIS event but make sure we get at least one axis event after the proximity event. After that, in the second loop change to use tablet_motion, it's confusing to use tablet_proximity_in here (though it technically works since we never go out of prox). Signed-off-by: Peter Hutterer --- test/tablet.c | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/test/tablet.c b/test/tablet.c index 367c4db4..cf39597c 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -167,32 +167,36 @@ START_TEST(motion) litest_tablet_proximity_in(dev, 5, 100, axes); libinput_dispatch(li); + litest_wait_for_event_of_type(li, + LIBINPUT_EVENT_TABLET_AXIS, + -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); - type = libinput_event_get_type(event); + ck_assert_int_eq(libinput_event_get_type(event), + LIBINPUT_EVENT_TABLET_AXIS); - if (type == LIBINPUT_EVENT_TABLET_AXIS) { - bool x_changed, y_changed; - double reported_x, reported_y; - 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); + 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); + 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); + 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); + litest_assert_double_lt(reported_x, reported_y); - last_reported_x = reported_x; - last_reported_y = reported_y; - } + last_reported_x = reported_x; + last_reported_y = reported_y; libinput_event_destroy(event); } @@ -203,7 +207,7 @@ START_TEST(motion) bool x_changed, y_changed; double reported_x, reported_y; - litest_tablet_proximity_in(dev, test_x, test_y, axes); + litest_tablet_motion(dev, test_x, test_y, axes); libinput_dispatch(li); while ((event = libinput_get_event(li))) { From b9e4638b9d68a4893b1c5682dd5ea28a569becc3 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 10 Feb 2015 11:15:04 +1000 Subject: [PATCH 068/255] test: fix a compiler warning about uninitialized variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flow is so this cannot be unset, we'd abort if we never get an event. The compiler doesn't know that though. In file included from tablet.c:35:0: tablet.c: In function ‘motion’: litest.h:202:45: warning: ‘last_reported_y’ may be used uninitialized in this function [-Wmaybe-uninitialized] ck_assert_int_lt((int)(a_ * 256), (int)(b_ * 256)) ^ tablet.c:158:26: note: ‘last_reported_y’ was declared here double last_reported_x, last_reported_y; ^ In file included from tablet.c:35:0: litest.h:208:45: warning: ‘last_reported_x’ may be used uninitialized in this function [-Wmaybe-uninitialized] ck_assert_int_gt((int)(a_ * 256), (int)(b_ * 256)) ^ tablet.c:158:9: note: ‘last_reported_x’ was declared here double last_reported_x, last_reported_y; Signed-off-by: Peter Hutterer --- test/tablet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tablet.c b/test/tablet.c index cf39597c..c38302af 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -155,7 +155,7 @@ START_TEST(motion) struct libinput_event_tablet *tablet_event; struct libinput_event *event; int test_x, test_y; - double last_reported_x, last_reported_y; + double last_reported_x = 0, last_reported_y = 0; enum libinput_event_type type; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, From 90918f77e64ad136f19b0ea04d89c70dedab62d6 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 10 Feb 2015 15:25:57 +1000 Subject: [PATCH 069/255] tools: print the tablet capability as 'T' in event-debug Signed-off-by: Peter Hutterer --- tools/event-debug.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/event-debug.c b/tools/event-debug.c index ad64f4be..1ca53c4a 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -152,6 +152,9 @@ print_device_notify(struct libinput_event *ev) if (libinput_device_has_capability(dev, LIBINPUT_DEVICE_CAP_TOUCH)) printf("t"); + 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); From b9cdba6bd1727610ae5d160cc6375f4e6f50c477 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 10 Feb 2015 16:13:51 +1000 Subject: [PATCH 070/255] Clarify proximity handling for tools always in proximity No real effect on the code, but make clear what's going to happen. Signed-off-by: Peter Hutterer --- src/libinput.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/libinput.h b/src/libinput.h index ff49bb2f..8b93bf36 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -222,6 +222,16 @@ enum libinput_event_type { /** * Signals that a tool has come into proximity of a device with the @ref * LIBINPUT_DEVICE_CAP_TABLET capability. + * + * Some tools may always be in proximity. For these tools, the @ref + * LIBINPUT_EVENT_TABLET_PROXIMITY_IN is sent only once after @ref + * LIBINPUT_EVENT_DEVICE_ADDED, and likewise the @ref + * LIBINPUT_EVENT_TABLET_PROXIMITY_OUT is 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. */ LIBINPUT_EVENT_TABLET_PROXIMITY_IN, /** @@ -232,6 +242,12 @@ enum libinput_event_type { * are marked as released. Button release events for each button that * was held down on the stylus are sent before the initial proximity out * event. + * + * Some tools may always be in proximity. For these tools, the @ref + * LIBINPUT_EVENT_TABLET_PROXIMITY_IN is sent only once after @ref + * LIBINPUT_EVENT_DEVICE_ADDED, and likewise the @ref + * LIBINPUT_EVENT_TABLET_PROXIMITY_OUT is sent only once before @ref + * LIBINPUT_EVENT_DEVICE_REMOVED. */ LIBINPUT_EVENT_TABLET_PROXIMITY_OUT, LIBINPUT_EVENT_TABLET_BUTTON From 145663d0a212bff62724ecf45b575654df4d1477 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Sun, 15 Feb 2015 19:06:34 -0500 Subject: [PATCH 071/255] tablet: Remove leftover-comment Signed-off-by: Stephen Chandler Paul Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index f80d642d..fe09efcf 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -411,12 +411,7 @@ sanitize_tablet_axes(struct tablet_dispatch *tablet) 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. In addition, filter - * out invalid distance events that can occur when the tablet tool is - * close enough for the tablet to detect that's something's there, but - * not close enough for it to actually receive data from the tool - * properly - */ + /* 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) { From a98d4831b6e172ad1b68dbf8de2c970c40a39a2f Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Mon, 16 Feb 2015 22:48:39 -0500 Subject: [PATCH 072/255] tablet: Set the tool as out of proximity by default when we initialize a tablet We should be able to set the tablet to left-handed mode immediately when it's connected to the system. Since left-handed mode won't activate until the tool is out of proximity however, we have to make sure that upon initially connecting the tablet, we set the tool to be out of proximity (it may as well be anyway, since we haven't processed any proximity in events from evdev just yet) Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index fe09efcf..3d8363cc 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -566,6 +566,8 @@ tablet_init(struct tablet_dispatch *tablet, tablet_mark_all_axes_changed(tablet, device); + tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY); + return 0; } From 1751688cc86850e61ed031c504edb32314e58968 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Mon, 16 Feb 2015 22:48:40 -0500 Subject: [PATCH 073/255] tablet: Add a left handed mode and tests On the majority of Wacom tablets, the buttons are on the left side, opposite of the side where the palm is meant to rest. Because of this, it's impossible to use the tablet with your left hand (comfortably, anyway) unless you flip it over, in which case the coordinates need to be inverted for it to match up with the screen properly. This is where left handed mode comes in. When enabled, it reverses all the coordinates so that the tablet may be rotated, and the palm rest on the tablet moved over to the left side. Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 30 +++++++++++- test/tablet.c | 114 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+), 1 deletion(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 3d8363cc..f99fd12c 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -85,6 +85,21 @@ tablet_mark_all_axes_changed(struct tablet_dispatch *tablet, 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, @@ -120,6 +135,12 @@ normalize_tilt(const struct input_absinfo * absinfo) { return (value * 2) - 1; } +static inline int32_t +invert_axis(const struct input_absinfo *absinfo) +{ + return absinfo->maximum - (absinfo->value - absinfo->minimum); +} + static void tablet_check_notify_axes(struct tablet_dispatch *tablet, struct evdev_device *device, @@ -142,7 +163,10 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, switch (a) { case LIBINPUT_TABLET_AXIS_X: case LIBINPUT_TABLET_AXIS_Y: - tablet->axes[a] = absinfo->value; + 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: @@ -481,6 +505,8 @@ tablet_flush(struct tablet_dispatch *tablet, 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); } /* Update state */ @@ -585,5 +611,7 @@ evdev_tablet_create(struct evdev_device *device) return NULL; } + evdev_init_left_handed(device, tablet_change_to_left_handed); + return &tablet->base; } diff --git a/test/tablet.c b/test/tablet.c index c38302af..922915fc 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -243,6 +243,119 @@ START_TEST(motion) } END_TEST +START_TEST(left_handed) +{ + 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, last_y; + 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_AXIS, -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_AXIS, -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); + } +} +END_TEST + START_TEST(motion_event_state) { struct litest_device *dev = litest_current_device(); @@ -873,6 +986,7 @@ main(int argc, char **argv) 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_event_state, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:left_handed", left_handed, LITEST_TABLET, LITEST_ANY); litest_add("tablet:normalization", normalization, LITEST_TABLET, LITEST_ANY); litest_add("tablet:pad", pad_buttons_ignored, LITEST_TABLET, LITEST_ANY); From 06f424afb7bdf6ee3d71bb9db895a1efa29b81e1 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Mon, 16 Feb 2015 22:48:41 -0500 Subject: [PATCH 074/255] tablet: Make note of filtering out events while the tool is out of proximity This is in reference to an issue I discovered during the GSoC where I found that there is a grey area with the tablet tool and the tablet itself, where the tablet will pick up the presence of a tool, but won't get any useful information from it. When this happens, tablets have a habit of sending distance events with incorrect values in them. As such, it's a good idea not to forward any axis events from evdev until we know that the tool is within usable proximity. Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index f99fd12c..6887307b 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -185,6 +185,11 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, axis_update_needed = true; } + /* 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)) From c7948e3bb5ee81513e02399bba3e814602065dcf Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Mon, 16 Feb 2015 22:48:42 -0500 Subject: [PATCH 075/255] tablet: Merge PROXIMITY_IN and PROXIMITY_OUT into a single event There isn't much purpose in having proximity in and out as different events, combining them into one single event is more consistent with the rest of the API, and means less code for clients to have to work with. Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 18 +++++----- src/libinput-private.h | 15 +++------ src/libinput.c | 74 +++++++++++++++--------------------------- src/libinput.h | 61 ++++++++++++++++++++-------------- src/libinput.sym | 1 + test/litest.c | 7 ++-- test/tablet.c | 28 +++++++++------- tools/event-debug.c | 36 ++++++++++---------- tools/event-gui.c | 3 +- 9 files changed, 116 insertions(+), 127 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 6887307b..af2f25c6 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -472,10 +472,11 @@ tablet_flush(struct tablet_dispatch *tablet, tablet->button_state.stylus_buttons = 0; tablet_set_status(tablet, TABLET_BUTTONS_RELEASED); } else if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY)) { - tablet_notify_proximity_in(&device->base, - time, - tool, - tablet->axes); + tablet_notify_proximity(&device->base, + time, + tool, + LIBINPUT_TOOL_PROXIMITY_IN, + tablet->axes); tablet_unset_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY); } @@ -504,10 +505,11 @@ tablet_flush(struct tablet_dispatch *tablet, } if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) { - tablet_notify_proximity_out(&device->base, - time, - tool, - tablet->axes); + tablet_notify_proximity(&device->base, + time, + tool, + LIBINPUT_TOOL_PROXIMITY_OUT, + tablet->axes); tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY); tablet_unset_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY); diff --git a/src/libinput-private.h b/src/libinput-private.h index 7b4a0d6e..415aac46 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -350,16 +350,11 @@ tablet_notify_axis(struct libinput_device *device, double *axes); void -tablet_notify_proximity_in(struct libinput_device *device, - uint32_t time, - struct libinput_tool *tool, - double *axes); - -void -tablet_notify_proximity_out(struct libinput_device *device, - uint32_t time, - struct libinput_tool *tool, - double *axes); +tablet_notify_proximity(struct libinput_device *device, + uint32_t time, + struct libinput_tool *tool, + enum libinput_tool_proximity_state state, + double *axes); void tablet_notify_button(struct libinput_device *device, diff --git a/src/libinput.c b/src/libinput.c index 5e7514b2..38c2fd79 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -88,6 +88,7 @@ struct libinput_event_tablet { double axes[LIBINPUT_TABLET_AXIS_CNT]; unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_AXIS_CNT)]; struct libinput_tool *tool; + enum libinput_tool_proximity_state proximity_state; }; static void @@ -194,8 +195,7 @@ libinput_event_get_pointer_event(struct libinput_event *event) case LIBINPUT_EVENT_TOUCH_CANCEL: case LIBINPUT_EVENT_TOUCH_FRAME: case LIBINPUT_EVENT_TABLET_AXIS: - case LIBINPUT_EVENT_TABLET_PROXIMITY_IN: - case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: + case LIBINPUT_EVENT_TABLET_PROXIMITY: case LIBINPUT_EVENT_TABLET_BUTTON: break; } @@ -224,8 +224,7 @@ libinput_event_get_keyboard_event(struct libinput_event *event) case LIBINPUT_EVENT_TOUCH_CANCEL: case LIBINPUT_EVENT_TOUCH_FRAME: case LIBINPUT_EVENT_TABLET_AXIS: - case LIBINPUT_EVENT_TABLET_PROXIMITY_IN: - case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: + case LIBINPUT_EVENT_TABLET_PROXIMITY: case LIBINPUT_EVENT_TABLET_BUTTON: break; } @@ -254,8 +253,7 @@ libinput_event_get_touch_event(struct libinput_event *event) case LIBINPUT_EVENT_TOUCH_FRAME: return (struct libinput_event_touch *) event; case LIBINPUT_EVENT_TABLET_AXIS: - case LIBINPUT_EVENT_TABLET_PROXIMITY_IN: - case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: + case LIBINPUT_EVENT_TABLET_PROXIMITY: case LIBINPUT_EVENT_TABLET_BUTTON: break; } @@ -283,8 +281,7 @@ libinput_event_get_tablet_event(struct libinput_event *event) case LIBINPUT_EVENT_TOUCH_FRAME: break; case LIBINPUT_EVENT_TABLET_AXIS: - case LIBINPUT_EVENT_TABLET_PROXIMITY_IN: - case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: + case LIBINPUT_EVENT_TABLET_PROXIMITY: case LIBINPUT_EVENT_TABLET_BUTTON: return (struct libinput_event_tablet *) event; } @@ -312,8 +309,7 @@ libinput_event_get_device_notify_event(struct libinput_event *event) case LIBINPUT_EVENT_TOUCH_CANCEL: case LIBINPUT_EVENT_TOUCH_FRAME: case LIBINPUT_EVENT_TABLET_AXIS: - case LIBINPUT_EVENT_TABLET_PROXIMITY_IN: - case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: + case LIBINPUT_EVENT_TABLET_PROXIMITY: case LIBINPUT_EVENT_TABLET_BUTTON: break; } @@ -629,6 +625,12 @@ 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) { @@ -1403,55 +1405,31 @@ tablet_notify_axis(struct libinput_device *device, } void -tablet_notify_proximity_in(struct libinput_device *device, - uint32_t time, - struct libinput_tool *tool, - double *axes) +tablet_notify_proximity(struct libinput_device *device, + uint32_t time, + struct libinput_tool *tool, + enum libinput_tool_proximity_state proximity_state, + double *axes) { - struct libinput_event_tablet *proximity_in_event; + struct libinput_event_tablet *proximity_event; - proximity_in_event = zalloc(sizeof *proximity_in_event); - if (!proximity_in_event) + proximity_event = zalloc(sizeof *proximity_event); + if (!proximity_event) return; - *proximity_in_event = (struct libinput_event_tablet) { + *proximity_event = (struct libinput_event_tablet) { .time = time, .tool = tool, + .proximity_state = proximity_state, }; - memcpy(proximity_in_event->axes, + memcpy(proximity_event->axes, axes, - sizeof(proximity_in_event->axes)); + sizeof(proximity_event->axes)); post_device_event(device, time, - LIBINPUT_EVENT_TABLET_PROXIMITY_IN, - &proximity_in_event->base); -} - -void -tablet_notify_proximity_out(struct libinput_device *device, - uint32_t time, - struct libinput_tool *tool, - double *axes) -{ - struct libinput_event_tablet *proximity_out_update_event; - - proximity_out_update_event = zalloc(sizeof *proximity_out_update_event); - if (!proximity_out_update_event) - return; - - *proximity_out_update_event = (struct libinput_event_tablet) { - .time = time, - .tool = tool, - }; - memcpy(proximity_out_update_event->axes, - axes, - sizeof(proximity_out_update_event->axes)); - - post_device_event(device, - time, - LIBINPUT_EVENT_TABLET_PROXIMITY_OUT, - &proximity_out_update_event->base); + LIBINPUT_EVENT_TABLET_PROXIMITY, + &proximity_event->base); } void diff --git a/src/libinput.h b/src/libinput.h index 8b93bf36..5904d8b7 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -172,6 +172,17 @@ enum libinput_tool_type { LIBINPUT_TOOL_LENS }; +/** + * @ingroup device + * + * The state of proximity for a tool on a device. The device must have the @ref + * LIBINPUT_DEVICE_CAP_TABLET capability. + */ +enum libinput_tool_proximity_state { + LIBINPUT_TOOL_PROXIMITY_OUT = 0, + LIBINPUT_TOOL_PROXIMITY_IN = 1, +}; + /** * @ingroup base * @@ -220,36 +231,26 @@ enum libinput_event_type { LIBINPUT_EVENT_TABLET_AXIS = 600, /** - * Signals that a tool has come into proximity of a device with the @ref - * LIBINPUT_DEVICE_CAP_TABLET capability. + * Signals that a tool has come in or out of proximity of a device with + * the @ref LIBINPUT_DEVICE_CAP_TABLET capability. * - * Some tools may always be in proximity. For these tools, the @ref - * LIBINPUT_EVENT_TABLET_PROXIMITY_IN is sent only once after @ref - * LIBINPUT_EVENT_DEVICE_ADDED, and likewise the @ref - * LIBINPUT_EVENT_TABLET_PROXIMITY_OUT is sent only once before @ref + * Some tools may always be in proximity. For these tools, events with + * state @ref LIBINPUT_TOOL_PROXIMITY_IN are sent only once after @ref + * LIBINPUT_EVENT_DEVICE_ADDED, and likewise events with state @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. - */ - LIBINPUT_EVENT_TABLET_PROXIMITY_IN, - /** - * Signals that a device with the @ref LIBINPUT_DEVICE_CAP_TABLET - * capability has detected that there is no longer a tool in use. When - * this happens, the value of every axis should be assumed to have a - * value of 0 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 initial proximity out - * event. * - * Some tools may always be in proximity. For these tools, the @ref - * LIBINPUT_EVENT_TABLET_PROXIMITY_IN is sent only once after @ref - * LIBINPUT_EVENT_DEVICE_ADDED, and likewise the @ref - * LIBINPUT_EVENT_TABLET_PROXIMITY_OUT is sent only once before @ref - * LIBINPUT_EVENT_DEVICE_REMOVED. + * When a tool goes out of proximity, the value of every axis should be + * assumed to have a value of 0 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 + * initial proximity out event. */ - LIBINPUT_EVENT_TABLET_PROXIMITY_OUT, + LIBINPUT_EVENT_TABLET_PROXIMITY, LIBINPUT_EVENT_TABLET_BUTTON }; @@ -345,8 +346,7 @@ struct libinput_event_touch; * * 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_IN, @ref LIBINPUT_EVENT_TABLET_PROXIMITY_IN - * and @ref LIBINPUT_EVENT_TABLET_BUTTON. + * LIBINPUT_EVENT_TABLET_PROXIMITY and @ref LIBINPUT_EVENT_TABLET_BUTTON. */ struct libinput_event_tablet; @@ -1092,6 +1092,19 @@ libinput_event_tablet_get_y_transformed(struct libinput_event_tablet *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. + * + * @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 * diff --git a/src/libinput.sym b/src/libinput.sym index d235e186..f9ccd98f 100644 --- a/src/libinput.sym +++ b/src/libinput.sym @@ -134,6 +134,7 @@ global: libinput_event_tablet_get_axis_value; 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; diff --git a/test/litest.c b/test/litest.c index 73228b47..199c0a17 100644 --- a/test/litest.c +++ b/test/litest.c @@ -1152,11 +1152,8 @@ litest_event_type_str(struct libinput_event *event) case LIBINPUT_EVENT_TABLET_AXIS: str = "TABLET AXIS"; break; - case LIBINPUT_EVENT_TABLET_PROXIMITY_IN: - str = "TABLET PROX IN"; - break; - case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: - str = "TABLET PROX OUT"; + case LIBINPUT_EVENT_TABLET_PROXIMITY: + str = "TABLET PROX"; break; case LIBINPUT_EVENT_TABLET_BUTTON: str = "TABLET BUTTON"; diff --git a/test/tablet.c b/test/tablet.c index 922915fc..94ed3cb9 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -55,7 +55,7 @@ START_TEST(proximity_in_out) while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_PROXIMITY_IN) { + LIBINPUT_EVENT_TABLET_PROXIMITY) { struct libinput_tool * tool; have_tool_update++; @@ -73,8 +73,14 @@ START_TEST(proximity_in_out) while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_PROXIMITY_OUT) - have_proximity_out = true; + 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); } @@ -626,7 +632,7 @@ START_TEST(tool_serial) libinput_dispatch(li); while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_PROXIMITY_IN) { + LIBINPUT_EVENT_TABLET_PROXIMITY) { tablet_event = libinput_event_get_tablet_event(event); tool = libinput_event_tablet_get_tool(tablet_event); @@ -663,7 +669,7 @@ START_TEST(serial_changes_tool) libinput_dispatch(li); while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_PROXIMITY_IN) { + LIBINPUT_EVENT_TABLET_PROXIMITY) { tablet_event = libinput_event_get_tablet_event(event); tool = libinput_event_tablet_get_tool(tablet_event); @@ -701,7 +707,7 @@ START_TEST(invalid_serials) libinput_dispatch(li); while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_PROXIMITY_IN) { + LIBINPUT_EVENT_TABLET_PROXIMITY) { tablet_event = libinput_event_get_tablet_event(event); tool = libinput_event_tablet_get_tool(tablet_event); @@ -730,7 +736,7 @@ START_TEST(tool_ref) libinput_dispatch(li); while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_PROXIMITY_IN) { + LIBINPUT_EVENT_TABLET_PROXIMITY) { break; } libinput_event_destroy(event); @@ -825,7 +831,7 @@ START_TEST(tools_with_serials) libinput_dispatch(li); while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_PROXIMITY_IN) { + LIBINPUT_EVENT_TABLET_PROXIMITY) { struct libinput_event_tablet *t = libinput_event_get_tablet_event(event); @@ -874,7 +880,7 @@ START_TEST(tools_without_serials) libinput_dispatch(li); while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_PROXIMITY_IN) { + LIBINPUT_EVENT_TABLET_PROXIMITY) { struct libinput_event_tablet *t = libinput_event_get_tablet_event(event); @@ -922,7 +928,7 @@ START_TEST(tool_capabilities) libinput_dispatch(li); while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_PROXIMITY_IN) { + LIBINPUT_EVENT_TABLET_PROXIMITY) { struct libinput_event_tablet *t = libinput_event_get_tablet_event(event); struct libinput_tool *tool = @@ -946,7 +952,7 @@ START_TEST(tool_capabilities) while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_PROXIMITY_IN) { + LIBINPUT_EVENT_TABLET_PROXIMITY) { struct libinput_event_tablet *t = libinput_event_get_tablet_event(event); struct libinput_tool *tool = diff --git a/tools/event-debug.c b/tools/event-debug.c index 1ca53c4a..32ccc795 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -109,11 +109,8 @@ print_event_header(struct libinput_event *ev) case LIBINPUT_EVENT_TABLET_AXIS: type = "TABLET_AXIS"; break; - case LIBINPUT_EVENT_TABLET_PROXIMITY_IN: - type = "TABLET_PROXIMITY_IN"; - break; - case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: - type = "TABLET_PROXIMITY_OUT"; + case LIBINPUT_EVENT_TABLET_PROXIMITY: + type = "TABLET_PROXIMITY"; break; case LIBINPUT_EVENT_TABLET_BUTTON: type = "TABLET_BUTTON"; @@ -321,11 +318,13 @@ print_touch_event_without_coords(struct libinput_event *ev) } static void -print_proximity_in_event(struct libinput_event *ev) +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); - const char *tool_str; + enum libinput_tool_proximity_state state; + const char *tool_str, + *state_str; switch (libinput_tool_get_type(tool)) { case LIBINPUT_TOOL_NONE: @@ -359,16 +358,18 @@ print_proximity_in_event(struct libinput_event *ev) abort(); } - print_event_time(libinput_event_tablet_get_time(t)); - printf("%s (%#x)", tool_str, libinput_tool_get_serial(tool)); - printf("\n"); -} + state = libinput_event_tablet_get_proximity_state(t); -static void -print_proximity_out_event(struct libinput_event *ev) { - struct libinput_event_tablet *t = libinput_event_get_tablet_event(ev); + if (state == LIBINPUT_TOOL_PROXIMITY_IN) + state_str = "proximity-in"; + else if (state == LIBINPUT_TOOL_PROXIMITY_OUT) + state_str = "proximity-out"; + else + abort(); print_event_time(libinput_event_tablet_get_time(t)); + printf("%s (%#x) %s", + tool_str, libinput_tool_get_serial(tool), state_str); printf("\n"); } @@ -442,11 +443,8 @@ handle_and_print_events(struct libinput *li) case LIBINPUT_EVENT_TABLET_AXIS: print_tablet_axis_event(ev); break; - case LIBINPUT_EVENT_TABLET_PROXIMITY_IN: - print_proximity_in_event(ev); - break; - case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: - print_proximity_out_event(ev); + case LIBINPUT_EVENT_TABLET_PROXIMITY: + print_proximity_event(ev); break; case LIBINPUT_EVENT_TABLET_BUTTON: print_tablet_button_event(ev); diff --git a/tools/event-gui.c b/tools/event-gui.c index 1857a2ef..063624f3 100644 --- a/tools/event-gui.c +++ b/tools/event-gui.c @@ -471,8 +471,7 @@ handle_event_libinput(GIOChannel *source, GIOCondition condition, gpointer data) } break; case LIBINPUT_EVENT_TABLET_AXIS: - case LIBINPUT_EVENT_TABLET_PROXIMITY_IN: - case LIBINPUT_EVENT_TABLET_PROXIMITY_OUT: + case LIBINPUT_EVENT_TABLET_PROXIMITY: case LIBINPUT_EVENT_TABLET_BUTTON: break; } From 3aeae35a600691412ba8bee45cab049b14e98234 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Mon, 16 Feb 2015 22:48:43 -0500 Subject: [PATCH 076/255] event-debug: Increase spacing after the event-type TABLET_PROXIMITY events cause many terminals to push every column to the right by one additional tab, this just increases the space after the event type so that everything lines up again. Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- tools/event-debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/event-debug.c b/tools/event-debug.c index 32ccc795..a2f7261e 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -117,7 +117,7 @@ print_event_header(struct libinput_event *ev) break; } - printf("%-7s %s ", libinput_device_get_sysname(dev), type); + printf("%-7s %-16s ", libinput_device_get_sysname(dev), type); } static void From b5d6be3cd6c8be65f4e631330446e3dd242072de Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Mon, 16 Feb 2015 22:48:44 -0500 Subject: [PATCH 077/255] tablet: Include starting values of axes in proximity events Having a motion event that's sent right after the original proximity event just to give the values of each axis is somewhat redundant. Since we already include the values of each axis with each type of event, we may as well use the proximity event to give the client the starting values for each axis on the tablet. Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 38 ++++++++++++++++++++++---------------- src/libinput-private.h | 1 + src/libinput.c | 7 ++++++- src/libinput.h | 10 +++++++--- test/tablet.c | 8 ++++---- tools/event-debug.c | 41 ++++++++++++++++++++++++++++++++++------- 6 files changed, 74 insertions(+), 31 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index af2f25c6..acab5a15 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -192,12 +192,21 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, * 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)) - tablet_notify_axis(base, - time, - tool, - tablet->changed_axes, - tablet->axes); + !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, + tablet->axes); + else + tablet_notify_axis(base, + time, + tool, + tablet->changed_axes, + tablet->axes); + } memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes)); } @@ -471,18 +480,12 @@ tablet_flush(struct tablet_dispatch *tablet, /* Release all stylus buttons */ tablet->button_state.stylus_buttons = 0; tablet_set_status(tablet, TABLET_BUTTONS_RELEASED); - } else if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY)) { - tablet_notify_proximity(&device->base, - time, - tool, - LIBINPUT_TOOL_PROXIMITY_IN, - tablet->axes); - tablet_unset_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY); - } - - if (tablet_has_status(tablet, TABLET_AXES_UPDATED)) { + } 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); } @@ -509,9 +512,12 @@ tablet_flush(struct tablet_dispatch *tablet, 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); + memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes)); tablet_change_to_left_handed(device); } diff --git a/src/libinput-private.h b/src/libinput-private.h index 415aac46..33ce2db7 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -354,6 +354,7 @@ tablet_notify_proximity(struct libinput_device *device, uint32_t time, struct libinput_tool *tool, enum libinput_tool_proximity_state state, + unsigned char *changed_axes, double *axes); void diff --git a/src/libinput.c b/src/libinput.c index 38c2fd79..aac6183d 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -569,7 +569,8 @@ libinput_event_tablet_get_axis_value(struct libinput_event_tablet *event, struct evdev_device *device = (struct evdev_device *) event->base.device; - if (event->base.type != LIBINPUT_EVENT_TABLET_AXIS) + if (event->base.type != LIBINPUT_EVENT_TABLET_AXIS && + event->base.type != LIBINPUT_EVENT_TABLET_PROXIMITY) return 0; switch(axis) { @@ -1409,6 +1410,7 @@ tablet_notify_proximity(struct libinput_device *device, uint32_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; @@ -1425,6 +1427,9 @@ tablet_notify_proximity(struct libinput_device *device, memcpy(proximity_event->axes, axes, sizeof(proximity_event->axes)); + memcpy(proximity_event->changed_axes, + changed_axes, + sizeof(proximity_event->changed_axes)); post_device_event(device, time, diff --git a/src/libinput.h b/src/libinput.h index 5904d8b7..197c09e5 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -234,6 +234,10 @@ enum libinput_event_type { * 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 with * state @ref LIBINPUT_TOOL_PROXIMITY_IN are sent only once after @ref * LIBINPUT_EVENT_DEVICE_ADDED, and likewise events with state @ref @@ -1004,11 +1008,11 @@ libinput_event_touch_get_base_event(struct libinput_event_touch *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, - * this function returns 0. + * 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. + * @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 diff --git a/test/tablet.c b/test/tablet.c index 94ed3cb9..036d701a 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -174,7 +174,7 @@ START_TEST(motion) libinput_dispatch(li); litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_AXIS, + LIBINPUT_EVENT_TABLET_PROXIMITY, -1); while ((event = libinput_get_event(li))) { @@ -183,7 +183,7 @@ START_TEST(motion) tablet_event = libinput_event_get_tablet_event(event); ck_assert_int_eq(libinput_event_get_type(event), - LIBINPUT_EVENT_TABLET_AXIS); + LIBINPUT_EVENT_TABLET_PROXIMITY); x_changed = libinput_event_tablet_axis_has_changed( @@ -277,7 +277,7 @@ START_TEST(left_handed) libinput_dispatch(li); libinput_device_config_left_handed_set(dev->libinput_device, 1); - litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_AXIS, -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); @@ -323,7 +323,7 @@ START_TEST(left_handed) * proximity */ litest_tablet_proximity_in(dev, 0, 100, axes); - litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_AXIS, -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); diff --git a/tools/event-debug.c b/tools/event-debug.c index a2f7261e..9f44cf61 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -325,6 +325,8 @@ print_proximity_event(struct libinput_event *ev) enum libinput_tool_proximity_state state; const char *tool_str, *state_str; + double x, y; + double dist, pressure; switch (libinput_tool_get_type(tool)) { case LIBINPUT_TOOL_NONE: @@ -360,14 +362,39 @@ print_proximity_event(struct libinput_event *ev) state = libinput_event_tablet_get_proximity_state(t); - if (state == LIBINPUT_TOOL_PROXIMITY_IN) - state_str = "proximity-in"; - else if (state == LIBINPUT_TOOL_PROXIMITY_OUT) - state_str = "proximity-out"; - else - abort(); - print_event_time(libinput_event_tablet_get_time(t)); + + if (state == LIBINPUT_TOOL_PROXIMITY_IN) { + x = libinput_event_tablet_get_axis_value( + t, LIBINPUT_TABLET_AXIS_X); + y = libinput_event_tablet_get_axis_value( + t, LIBINPUT_TABLET_AXIS_Y); + printf("\t%.2f/%.2f", x, 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); + printf("\ttilt: %.2f/%.2f ", x, y); + + 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) + printf("\tdistance: %.2f ", dist); + else + printf("\tpressure: %.2f ", pressure); + + state_str = "proximity-in"; + } else if (state == LIBINPUT_TOOL_PROXIMITY_OUT) { + state_str = "proximity-out"; + printf("\t"); + } else { + abort(); + } + printf("%s (%#x) %s", tool_str, libinput_tool_get_serial(tool), state_str); printf("\n"); From 657f6a9b7767e21f8f075a870eed526ec19fcd7a Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Mon, 16 Feb 2015 22:48:45 -0500 Subject: [PATCH 078/255] tablet: Update motion_event_state test to use litest_tablet_motion() Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- test/tablet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/tablet.c b/test/tablet.c index 036d701a..27249fcb 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -382,7 +382,7 @@ START_TEST(motion_event_state) /* 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_proximity_in(dev, test_x, test_y, axes); + litest_tablet_motion(dev, test_x, test_y, axes); libinput_dispatch(li); @@ -407,7 +407,7 @@ START_TEST(motion_event_state) 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_proximity_in(dev, test_x, test_y, axes); + litest_tablet_motion(dev, test_x, test_y, axes); libinput_event_destroy(event); libinput_dispatch(li); From 6e7beeb347b3835f6afbdd17d6f686e55d78ed54 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Mon, 16 Feb 2015 22:48:46 -0500 Subject: [PATCH 079/255] tablet: Add tests for axes on proximity events Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- test/tablet.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/test/tablet.c b/test/tablet.c index 27249fcb..043f78c5 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -154,6 +154,82 @@ START_TEST(proximity_out_clear_buttons) } 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); + + while ((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); + } + + libinput_event_destroy(event); + } +} +END_TEST + START_TEST(motion) { struct litest_device *dev = litest_current_device(); @@ -989,6 +1065,7 @@ main(int argc, char **argv) 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_event_state, LITEST_TABLET, LITEST_ANY); From 162a39e318df8ded54abfffe444712c317a8df4d Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 16 Feb 2015 14:19:21 +1000 Subject: [PATCH 080/255] Move the tablet APIs into the right library version Signed-off-by: Peter Hutterer --- src/libinput.sym | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/libinput.sym b/src/libinput.sym index f9ccd98f..307dff3b 100644 --- a/src/libinput.sym +++ b/src/libinput.sym @@ -126,6 +126,14 @@ global: libinput_device_config_click_get_method; libinput_device_config_click_get_methods; libinput_device_config_click_set_method; +} LIBINPUT_0.8.0; + +LIBINPUT_0.11.0 { + libinput_device_get_device_group; + libinput_device_group_get_user_data; + libinput_device_group_ref; + libinput_device_group_set_user_data; + libinput_device_group_unref; /* tablet APIs, they are not part of any stable API promise yet. * keep them separate */ @@ -147,12 +155,4 @@ global: libinput_tool_ref; libinput_tool_set_user_data; libinput_tool_unref; -} LIBINPUT_0.8.0; - -LIBINPUT_0.11.0 { - libinput_device_get_device_group; - libinput_device_group_get_user_data; - libinput_device_group_ref; - libinput_device_group_set_user_data; - libinput_device_group_unref; } LIBINPUT_0.9.0; From 1c3de35abb5b5b085a9cbcf84419b8bf112b8a2f Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 10 Feb 2015 11:29:34 +1000 Subject: [PATCH 081/255] tablet: drop LIBINPUT_TABLET_AXIS_NONE from the API This constant isn't used in the public API, let's drop it. To make it easier to use it internally and avoid accidental boolean comparisions with axes, bump all real axes up to start at 1. Internally that means we drop the AXIS_CNT since it'd be misleading and instead use MAX or MAX + 1 everywhere. Signed-off-by: Peter Hutterer Reviewed-by: Benjamin Tissoires --- src/evdev-tablet.c | 8 +++++--- src/evdev-tablet.h | 8 +++++--- src/libinput-private.h | 4 ++-- src/libinput.c | 4 ++-- src/libinput.h | 13 ++++++------- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index acab5a15..4a0d4b24 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -75,7 +75,7 @@ tablet_mark_all_axes_changed(struct tablet_dispatch *tablet, { enum libinput_tablet_axis a; - for (a = 0; a < LIBINPUT_TABLET_AXIS_CNT; a++) { + for (a = LIBINPUT_TABLET_AXIS_X; a <= LIBINPUT_TABLET_AXIS_MAX; a++) { if (libevdev_has_event_code(device->evdev, EV_ABS, axis_to_evcode(a))) @@ -151,7 +151,7 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, bool axis_update_needed = false; int a; - for (a = 0; a < LIBINPUT_TABLET_AXIS_CNT; a++) { + 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)) @@ -596,7 +596,9 @@ tablet_init(struct tablet_dispatch *tablet, tablet->current_tool_type = LIBINPUT_TOOL_NONE; list_init(&tablet->tool_list); - for (axis = 0; axis < LIBINPUT_TABLET_AXIS_CNT; axis++) { + for (axis = LIBINPUT_TABLET_AXIS_X; + axis <= LIBINPUT_TABLET_AXIS_MAX; + axis++) { if (libevdev_has_event_code(device->evdev, EV_ABS, axis_to_evcode(axis))) diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index cb375771..4f354171 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -27,6 +27,8 @@ #include "evdev.h" +#define LIBINPUT_TABLET_AXIS_NONE 0 + enum tablet_status { TABLET_NONE = 0, TABLET_AXES_UPDATED = 1 << 0, @@ -46,9 +48,9 @@ struct tablet_dispatch { struct evdev_dispatch base; struct evdev_device *device; unsigned char status; - unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_AXIS_CNT)]; - double axes[LIBINPUT_TABLET_AXIS_CNT]; - unsigned char axis_caps[NCHARS(LIBINPUT_TABLET_AXIS_CNT)]; + unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_AXIS_MAX + 1)]; + double axes[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; diff --git a/src/libinput-private.h b/src/libinput-private.h index 33ce2db7..bc1e0c10 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -30,7 +30,7 @@ #include "libinput.h" #include "libinput-util.h" -#define LIBINPUT_TABLET_AXIS_CNT LIBINPUT_TABLET_AXIS_TILT_Y + 1 +#define LIBINPUT_TABLET_AXIS_MAX LIBINPUT_TABLET_AXIS_TILT_Y struct libinput_source; @@ -188,7 +188,7 @@ struct libinput_tool { struct list link; uint32_t serial; enum libinput_tool_type type; - unsigned char axis_caps[NCHARS(LIBINPUT_TABLET_AXIS_CNT)]; + unsigned char axis_caps[NCHARS(LIBINPUT_TABLET_AXIS_MAX + 1)]; int refcount; void *user_data; }; diff --git a/src/libinput.c b/src/libinput.c index aac6183d..b300d74e 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -85,8 +85,8 @@ struct libinput_event_tablet { enum libinput_button_state state; uint32_t seat_button_count; uint32_t time; - double axes[LIBINPUT_TABLET_AXIS_CNT]; - unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_AXIS_CNT)]; + double axes[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; }; diff --git a/src/libinput.h b/src/libinput.h index 197c09e5..402877a9 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -137,13 +137,12 @@ enum libinput_pointer_axis_source { * LIBINPUT_DEVICE_CAP_TABLET capability. */ enum libinput_tablet_axis { - LIBINPUT_TABLET_AXIS_NONE = -1, - LIBINPUT_TABLET_AXIS_X = 0, - LIBINPUT_TABLET_AXIS_Y = 1, - LIBINPUT_TABLET_AXIS_DISTANCE = 2, - LIBINPUT_TABLET_AXIS_PRESSURE = 3, - LIBINPUT_TABLET_AXIS_TILT_X = 4, - LIBINPUT_TABLET_AXIS_TILT_Y = 5, + 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, }; /** From 898e93cd9a6f9efe2dafecb2ea5f58014e0514e0 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 16 Feb 2015 14:30:13 +1000 Subject: [PATCH 082/255] tablet: spell out that we always include all values This behavior is intended and to save the caller from having to buffer all values. Signed-off-by: Peter Hutterer --- src/libinput.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/libinput.h b/src/libinput.h index 402877a9..a4413b67 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1039,6 +1039,10 @@ libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, * normalized value between -1 and 1 that indicates the X or Y tilt of the * tool * + * @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 axis The axis to retrieve the value of * @return The current value of the the axis @@ -1053,6 +1057,10 @@ libinput_event_tablet_get_axis_value(struct libinput_event_tablet *event, * 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 @@ -1067,6 +1075,10 @@ libinput_event_tablet_get_x_transformed(struct libinput_event_tablet *event, * 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 From f3ac8d03feddf78f90e26c94969c61bd982cf460 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Thu, 19 Feb 2015 11:51:54 +1000 Subject: [PATCH 083/255] tablet: mark all axes as unchanged before the proximity out event When the tablet goes out of proximity we provide the last-known axis status (which was sent in a previous axis event anyway), make sure the changed_axis bitfield is unset for all axes though. Signed-off-by: Stephen Chandler Paul Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 4a0d4b24..eccbcc9c 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -508,6 +508,7 @@ tablet_flush(struct tablet_dispatch *tablet, } 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, @@ -517,7 +518,6 @@ tablet_flush(struct tablet_dispatch *tablet, tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY); tablet_unset_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY); - memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes)); tablet_change_to_left_handed(device); } From 1d8de3885399abb778e73bbb65832367cc9c8f50 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 19 Feb 2015 11:59:59 +1000 Subject: [PATCH 084/255] Revert "tablet: Add tests for axes on proximity events" mea culpa, I merged a patch that wasn't ready yet (despite me saying I wouldn't merge it). Updated patch coming up next commit. This reverts commit 6e7beeb347b3835f6afbdd17d6f686e55d78ed54. --- test/tablet.c | 77 --------------------------------------------------- 1 file changed, 77 deletions(-) diff --git a/test/tablet.c b/test/tablet.c index 043f78c5..27249fcb 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -154,82 +154,6 @@ START_TEST(proximity_out_clear_buttons) } 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); - - while ((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); - } - - libinput_event_destroy(event); - } -} -END_TEST - START_TEST(motion) { struct litest_device *dev = litest_current_device(); @@ -1065,7 +989,6 @@ main(int argc, char **argv) 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_event_state, LITEST_TABLET, LITEST_ANY); From 9871848b53a36b0bcbec9fadfe5a1f09bbc6f3e1 Mon Sep 17 00:00:00 2001 From: Stephen Chandler Paul Date: Wed, 18 Feb 2015 01:43:21 -0500 Subject: [PATCH 085/255] tablet: Add tests for axes on proximity events --- test/tablet.c | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/test/tablet.c b/test/tablet.c index 27249fcb..debda837 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -154,6 +154,139 @@ START_TEST(proximity_out_clear_buttons) } 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(); @@ -989,6 +1122,7 @@ main(int argc, char **argv) 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_event_state, LITEST_TABLET, LITEST_ANY); From 15974106a67bf354328c3370023bc912321dfd6c Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 19 Feb 2015 11:38:04 +1000 Subject: [PATCH 086/255] cosmetic: drop double empty lines Signed-off-by: Peter Hutterer --- src/evdev-tablet.h | 1 - test/tablet.c | 2 -- 2 files changed, 3 deletions(-) diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index 4f354171..df6e17f5 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -21,7 +21,6 @@ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ - #ifndef EVDEV_TABLET_H #define EVDEV_TABLET_H diff --git a/test/tablet.c b/test/tablet.c index debda837..77d8ecd2 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -318,7 +318,6 @@ START_TEST(motion) 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( @@ -887,7 +886,6 @@ START_TEST(tool_ref) } END_TEST - START_TEST(pad_buttons_ignored) { struct litest_device *dev = litest_current_device(); From c1e567e4fab67d3f25d81748c8d64c93440a544f Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 17 Feb 2015 08:17:37 +1000 Subject: [PATCH 087/255] test: fix two tablet tests The serial test was broken, it succeeded even if we never got an event. The second test was fine, but complicated. Make it use some of the newer litest features. Signed-off-by: Peter Hutterer Reviewed-by: Benjamin Tissoires Reviewed-by: Stephen Chandler Paul --- test/tablet.c | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/test/tablet.c b/test/tablet.c index 77d8ecd2..f003bd9c 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -761,18 +761,14 @@ START_TEST(tool_serial) litest_event(dev, EV_MSC, MSC_SERIAL, 1000); 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); - } + 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 @@ -783,7 +779,6 @@ START_TEST(serial_changes_tool) struct libinput_event_tablet *tablet_event; struct libinput_event *event; struct libinput_tool *tool; - bool tool_updated = false; litest_drain_events(li); @@ -798,20 +793,15 @@ START_TEST(serial_changes_tool) litest_event(dev, EV_MSC, MSC_SERIAL, 2000); 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); + 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); - tool_updated = true; - } - - libinput_event_destroy(event); - } - ck_assert(tool_updated); + ck_assert_uint_eq(libinput_tool_get_serial(tool), 2000); + libinput_event_destroy(event); } END_TEST From 6df8c70c3b39ef76bc71f43b162f73bb653cebc4 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 17 Feb 2015 08:22:24 +1000 Subject: [PATCH 088/255] test: replace a while loop with a litest helper Signed-off-by: Peter Hutterer Reviewed-by: Benjamin Tissoires Reviewed-by: Stephen Chandler Paul --- test/tablet.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/test/tablet.c b/test/tablet.c index f003bd9c..dc5402f9 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -855,15 +855,10 @@ START_TEST(tool_ref) litest_event(dev, EV_MSC, MSC_SERIAL, 1000); 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) { - break; - } - libinput_event_destroy(event); - } - + 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); From c23fb36eb12c442d4f4f7d01bbbeacf018aa9744 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 17 Feb 2015 10:44:58 +1000 Subject: [PATCH 089/255] test: fix double comparison macros args needs to be within () to ensure correct calculation Signed-off-by: Peter Hutterer Reviewed-by: Stephen Chandler Paul --- test/litest.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/litest.h b/test/litest.h index 4553c878..9345d9c2 100644 --- a/test/litest.h +++ b/test/litest.h @@ -195,22 +195,22 @@ struct libevdev_uinput * litest_create_uinput_abs_device(const char *name, const struct input_absinfo *abs, ...); #define litest_assert_double_eq(a_, b_)\ - ck_assert_int_eq((int)(a_ * 256), (int)(b_ * 256)) + 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)) + 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)) + 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)) + 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)) + 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)) + ck_assert_int_ge((int)((a_) * 256), (int)((b_) * 256)) void litest_timeout_tap(void); void litest_timeout_softbuttons(void); From 328834907786923d8e16283f1c0b469e3d91a0c5 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 19 Feb 2015 17:39:11 +1000 Subject: [PATCH 090/255] test: add litest_assert_tablet_button_event() Does what it says on the box. or at least in the manual inside the box. Signed-off-by: Peter Hutterer Reviewed-by: Benjamin Tissoires Reviewed-by: Stephen Chandler Paul --- test/litest.c | 21 +++++++++++++++++++++ test/litest.h | 3 +++ 2 files changed, 24 insertions(+) diff --git a/test/litest.c b/test/litest.c index 05ed2b23..6d4bfdbc 100644 --- a/test/litest.c +++ b/test/litest.c @@ -1404,6 +1404,27 @@ litest_assert_button_event(struct libinput *li, unsigned int button, libinput_event_destroy(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; + + litest_wait_for_event(li); + event = libinput_get_event(li); + + ck_assert(event != NULL); + ck_assert_int_eq(libinput_event_get_type(event), + LIBINPUT_EVENT_TABLET_BUTTON); + tev = libinput_event_get_tablet_event(event); + ck_assert_int_eq(libinput_event_tablet_get_button(tev), + button); + ck_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, diff --git a/test/litest.h b/test/litest.h index 9345d9c2..40b3910e 100644 --- a/test/litest.h +++ b/test/litest.h @@ -186,6 +186,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, From d0805e41d2117b932b67394585d2f8040c83371f Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 17 Feb 2015 12:24:04 +1000 Subject: [PATCH 091/255] tablet: fix two coding style issues Signed-off-by: Peter Hutterer Reviewed-by: Benjamin Tissoires Reviewed-by: Stephen Chandler Paul --- src/evdev-tablet.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index eccbcc9c..e994de4d 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -119,7 +119,8 @@ tablet_update_tool(struct tablet_dispatch *tablet, } static inline double -normalize_pressure_or_dist(const struct input_absinfo * absinfo) { +normalize_pressure_or_dist(const struct input_absinfo *absinfo) +{ double range = absinfo->maximum - absinfo->minimum; double value = (absinfo->value - absinfo->minimum) / range; @@ -127,7 +128,8 @@ normalize_pressure_or_dist(const struct input_absinfo * absinfo) { } static inline double -normalize_tilt(const struct input_absinfo * absinfo) { +normalize_tilt(const struct input_absinfo *absinfo) +{ double range = absinfo->maximum - absinfo->minimum; double value = (absinfo->value - absinfo->minimum) / range; From 585c30e01e568a89424d49bbb431cdd09cb7e72d Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 19 Feb 2015 10:59:46 +1000 Subject: [PATCH 092/255] tablet: drop LIBINPUT_TOOL_NONE from the public API This is only used internally. Signed-off-by: Peter Hutterer Reviewed-by: Benjamin Tissoires Reviewed-by: Stephen Chandler Paul --- src/evdev-tablet.h | 1 + src/libinput.h | 1 - tools/event-debug.c | 3 --- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index df6e17f5..eee69047 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -27,6 +27,7 @@ #include "evdev.h" #define LIBINPUT_TABLET_AXIS_NONE 0 +#define LIBINPUT_TOOL_NONE 0 enum tablet_status { TABLET_NONE = 0, diff --git a/src/libinput.h b/src/libinput.h index 2c454a7e..3cb02b92 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -159,7 +159,6 @@ struct libinput_tool; * LIBINPUT_DEVICE_CAP_TABLET capability. */ enum libinput_tool_type { - LIBINPUT_TOOL_NONE = -1, LIBINPUT_TOOL_PEN = 0x140, /* Matches BTN_TOOL_PEN */ LIBINPUT_TOOL_ERASER, LIBINPUT_TOOL_BRUSH, diff --git a/tools/event-debug.c b/tools/event-debug.c index f74344ef..09f208c3 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -340,9 +340,6 @@ print_proximity_event(struct libinput_event *ev) double dist, pressure; switch (libinput_tool_get_type(tool)) { - case LIBINPUT_TOOL_NONE: - tool_str = "none"; - break; case LIBINPUT_TOOL_PEN: tool_str = "pen"; break; From 5146bd00fd5613c7e10b3ced4bf5d26b9d78a69e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 19 Feb 2015 11:00:27 +1000 Subject: [PATCH 093/255] tablet: de-couple tool enum values from linux/input.h There's no real reason to keep them in sync but it has drawbacks when we start introducing tools that the kernel doesn't have (and can't easily add due to range constraints). Signed-off-by: Peter Hutterer Reviewed-by: Benjamin Tissoires Reviewed-by: Stephen Chandler Paul --- src/evdev-tablet.c | 27 +++++++++++++++++++++++++-- src/libinput.h | 2 +- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index e994de4d..013038b7 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -244,6 +244,27 @@ tablet_update_button(struct tablet_dispatch *tablet, } } +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, @@ -259,8 +280,10 @@ tablet_process_key(struct tablet_dispatch *tablet, case BTN_TOOL_FINGER: case BTN_TOOL_MOUSE: case BTN_TOOL_LENS: - /* These codes have an equivalent libinput_tool value */ - tablet_update_tool(tablet, device, e->code, e->value); + tablet_update_tool(tablet, + device, + tablet_evcode_to_tool(e->code), + e->value); break; case BTN_TOUCH: if (e->value) diff --git a/src/libinput.h b/src/libinput.h index 3cb02b92..7e1e5fdf 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -159,7 +159,7 @@ struct libinput_tool; * LIBINPUT_DEVICE_CAP_TABLET capability. */ enum libinput_tool_type { - LIBINPUT_TOOL_PEN = 0x140, /* Matches BTN_TOOL_PEN */ + LIBINPUT_TOOL_PEN = 1, LIBINPUT_TOOL_ERASER, LIBINPUT_TOOL_BRUSH, LIBINPUT_TOOL_PENCIL, From 9ba09f5b551537fbb37989b999662deeb6d4671d Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 24 Feb 2015 11:10:23 +1000 Subject: [PATCH 094/255] tablet: document what the tool type means It's a rough guide only, but still precise enough to make some decisions. Signed-off-by: Peter Hutterer Reviewed-by: Stephen Chandler Paul --- src/libinput.h | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/libinput.h b/src/libinput.h index 7e1e5fdf..7dae9238 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -156,17 +156,30 @@ struct libinput_tool; * @ingroup device * * Available tool types for a device. It must have the @ref - * LIBINPUT_DEVICE_CAP_TABLET capability. + * 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 LIBINPUT_TOOL_PEN. + * + * 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, - LIBINPUT_TOOL_ERASER, - LIBINPUT_TOOL_BRUSH, - LIBINPUT_TOOL_PENCIL, - LIBINPUT_TOOL_AIRBRUSH, - LIBINPUT_TOOL_FINGER, - LIBINPUT_TOOL_MOUSE, - LIBINPUT_TOOL_LENS + 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 */ }; /** From 9088138c800284f612854e2a29b3cf319853dcc5 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 19 Feb 2015 14:56:34 +1000 Subject: [PATCH 095/255] tablet: add libinput_tool_get_tool_id() The tool ID on wacom tablets is what really defines the tool, so one can differ between say an Intuos Grip Pen, Art Pen or Classic Pen. They're all BTN_TOOL_PEN in the kernel driver. Signed-off-by: Peter Hutterer Reviewed-by: Benjamin Tissoires Reviewed-by: Stephen Chandler Paul --- src/evdev-tablet.c | 8 ++++++++ src/evdev-tablet.h | 1 + src/libinput-private.h | 1 + src/libinput.c | 6 ++++++ src/libinput.h | 21 +++++++++++++++++++++ src/libinput.sym | 1 + 6 files changed, 38 insertions(+) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 013038b7..479d6800 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -62,6 +62,11 @@ tablet_process_absolute(struct tablet_dispatch *tablet, 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; default: log_info(device->base.seat->libinput, "Unhandled ABS event code %#x\n", e->code); @@ -324,6 +329,7 @@ tablet_process_misc(struct tablet_dispatch *tablet, 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; @@ -362,6 +368,7 @@ tablet_get_tool(struct tablet_dispatch *tablet, *tool = (struct libinput_tool) { .type = type, .serial = serial, + .tool_id = tool_id, .refcount = 1, }; @@ -499,6 +506,7 @@ tablet_flush(struct tablet_dispatch *tablet, 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_LEAVING_PROXIMITY)) { diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index eee69047..6226d63b 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -59,6 +59,7 @@ struct tablet_dispatch { struct button_state prev_button_state; enum libinput_tool_type current_tool_type; + uint32_t current_tool_id; uint32_t current_tool_serial; }; diff --git a/src/libinput-private.h b/src/libinput-private.h index f6c4dccc..b2dc4069 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -188,6 +188,7 @@ struct libinput_device { 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)]; int refcount; diff --git a/src/libinput.c b/src/libinput.c index 1abd1637..b165c59b 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -662,6 +662,12 @@ 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) { diff --git a/src/libinput.h b/src/libinput.h index 7dae9238..bf3b40cf 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -160,6 +160,7 @@ struct libinput_tool; * 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 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 @@ -1192,10 +1193,30 @@ libinput_event_tablet_get_time(struct libinput_event_tablet *event); * * @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 * diff --git a/src/libinput.sym b/src/libinput.sym index e4b76c64..dbd4d0f5 100644 --- a/src/libinput.sym +++ b/src/libinput.sym @@ -153,6 +153,7 @@ LIBINPUT_0.12.0 { libinput_event_tablet_get_x_transformed; libinput_event_tablet_get_y_transformed; libinput_tool_get_serial; + libinput_tool_get_tool_id; libinput_tool_get_type; libinput_tool_get_user_data; libinput_tool_has_axis; From 1e912b460ae54c5768c5985305f545ce0f6c47f7 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 18 Feb 2015 10:51:39 +1000 Subject: [PATCH 096/255] Keep the tablet APIs in a separate symbol version block I keep having to move them around after merging from master and often I'm late with it too. It's a lot easier to just have to update the dependency in a single line, and causes less conflicts too. Signed-off-by: Peter Hutterer Reviewed-by: Benjamin Tissoires Reviewed-by: Stephen Chandler Paul --- src/libinput.sym | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libinput.sym b/src/libinput.sym index dbd4d0f5..5561478a 100644 --- a/src/libinput.sym +++ b/src/libinput.sym @@ -139,8 +139,11 @@ LIBINPUT_0.11.0 { } LIBINPUT_0.9.0; LIBINPUT_0.12.0 { - /* tablet APIs, they are not part of any stable API promise yet. - * keep them separate */ +} LIBINPUT_0.11.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_value; @@ -160,4 +163,4 @@ LIBINPUT_0.12.0 { libinput_tool_ref; libinput_tool_set_user_data; libinput_tool_unref; -} LIBINPUT_0.11.0; +} LIBINPUT_0.12.0; From 9c62daf1d801d95eadca2b702567ee57f0b793c6 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 19 Feb 2015 12:56:43 +1000 Subject: [PATCH 097/255] tablet: use libwacom to identify tablets for left-handedness A tablet hotplug event is rare and not a time-critical event, so we load the database on tablet init and throw it away again. Signed-off-by: Peter Hutterer Reviewed-by: Stephen Chandler Paul --- configure.ac | 11 ++++++++++ src/Makefile.am | 2 ++ src/evdev-tablet.c | 45 +++++++++++++++++++++++++++++++++++++- test/tablet.c | 13 ++++++++++- test/valgrind.suppressions | 18 +++++++++++++++ 5 files changed, 87 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 1a4eb3af..c09dc4e5 100644 --- a/configure.ac +++ b/configure.ac @@ -165,6 +165,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], [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"]) @@ -186,6 +196,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/src/Makefile.am b/src/Makefile.am index 2442794a..e807e236 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,12 +31,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-tablet.c b/src/evdev-tablet.c index 479d6800..14fb44f3 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -27,6 +27,10 @@ #include #include +#if HAVE_LIBWACOM +#include +#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_))) @@ -645,6 +649,45 @@ tablet_init(struct tablet_dispatch *tablet, 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; + int vid, pid; + + vid = evdev_device_get_id_vendor(device); + pid = evdev_device_get_id_product(device); + + db = libwacom_database_new(); + if (!db) + return; + error = libwacom_error_new(); + d = libwacom_new_from_usbid(db, vid, pid, 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) { @@ -659,7 +702,7 @@ evdev_tablet_create(struct evdev_device *device) return NULL; } - evdev_init_left_handed(device, tablet_change_to_left_handed); + tablet_init_left_handed(device); return &tablet->base; } diff --git a/test/tablet.c b/test/tablet.c index dc5402f9..096c9b26 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -383,6 +383,7 @@ 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; @@ -491,6 +492,15 @@ START_TEST(left_handed) 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 @@ -1109,7 +1119,8 @@ main(int argc, char **argv) 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_event_state, LITEST_TABLET, LITEST_ANY); - litest_add("tablet:left_handed", left_handed, 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); diff --git a/test/valgrind.suppressions b/test/valgrind.suppressions index 3ba7f292..fc9251a7 100644 --- a/test/valgrind.suppressions +++ b/test/valgrind.suppressions @@ -7,3 +7,21 @@ fun:litest_run fun:main } +{ + + Memcheck:Leak + ... + fun:g_type_register_static +} +{ + + Memcheck:Leak + ... + fun:g_type_register_fundamental +} +{ + + Memcheck:Leak + ... + fun:g_malloc0 +} From d43f92b464dc7158b76eec9f29e3f31d03c155ba Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 16 Feb 2015 15:05:00 +1000 Subject: [PATCH 098/255] tablet: explicitly ignore ABS_THROTTLE, ABS_RX, ABS_RY, and ABS_RZ ABS_THROTTLE: Tablets still advertise this axis but the mouse itself isn't available anymore. The Pad sends the second wheel as ABS_THROTTLE but that's a task for the buttonset interface. Explanation of what the throttle did on page http://101.wacom.com/productsupport/manual/Intuos2UsersManual.pdf ABS_RX/ABS_RY: These only happen on the Intuos3 device and only on the Pad device (kernel >= 3.17) ABS_RZ: The 4D mouse for the Intuos2, obsolete. No functional changes, this is to clarify why we're only handling a subset of codes. Signed-off-by: Peter Hutterer Reviewed-by: Benjamin Tissoires Reviewed-by: Stephen Chandler Paul --- src/evdev-tablet.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 14fb44f3..820473f0 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -71,6 +71,17 @@ tablet_process_absolute(struct tablet_dispatch *tablet, 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); From 8f56a7ea937338b54532b8375de1d650e1ee685c Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 16 Feb 2015 16:25:39 +1000 Subject: [PATCH 099/255] tablet: factor out checking a device for axes This gets more complicated for axes that aren't a 1:1 relationship with event codes. Signed-off-by: Peter Hutterer Reviewed-by: Benjamin Tissoires Reviewed-by: Stephen Chandler Paul --- src/evdev-tablet.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 820473f0..fb1253b1 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -40,6 +40,18 @@ #define tablet_get_released_buttons(tablet_,field_) \ ((tablet_)->prev_button_state.field_ & ~((tablet_)->button_state.field_)) +static int +tablet_device_has_axis(struct tablet_dispatch *tablet, + enum libinput_tablet_axis axis) +{ + unsigned int code; + + code = axis_to_evcode(axis); + return libevdev_has_event_code(tablet->device->evdev, + EV_ABS, + code); +} + static void tablet_process_absolute(struct tablet_dispatch *tablet, struct evdev_device *device, @@ -96,9 +108,7 @@ tablet_mark_all_axes_changed(struct tablet_dispatch *tablet, enum libinput_tablet_axis a; for (a = LIBINPUT_TABLET_AXIS_X; a <= LIBINPUT_TABLET_AXIS_MAX; a++) { - if (libevdev_has_event_code(device->evdev, - EV_ABS, - axis_to_evcode(a))) + if (tablet_device_has_axis(tablet, a)) set_bit(tablet->changed_axes, a); } @@ -647,9 +657,7 @@ tablet_init(struct tablet_dispatch *tablet, for (axis = LIBINPUT_TABLET_AXIS_X; axis <= LIBINPUT_TABLET_AXIS_MAX; axis++) { - if (libevdev_has_event_code(device->evdev, - EV_ABS, - axis_to_evcode(axis))) + if (tablet_device_has_axis(tablet, axis)) set_bit(tablet->axis_caps, axis); } From 5cac5248fcba68e9d10eab052478c4570557f760 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 18 Feb 2015 12:03:34 +1000 Subject: [PATCH 100/255] tablet: factor out setting axis bits on a tool No functional changes. Signed-off-by: Peter Hutterer Reviewed-by: Benjamin Tissoires Reviewed-by: Stephen Chandler Paul --- src/evdev-tablet.c | 80 +++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 37 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index fb1253b1..dfea318b 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -351,6 +351,48 @@ tablet_process_misc(struct tablet_dispatch *tablet, } } +static inline void +copy_axis_cap(const struct tablet_dispatch *tablet, + struct libinput_tool *tool, + enum libinput_tablet_axis axis) +{ + if (bit_is_set(tablet->axis_caps, axis)) + set_bit(tool->axis_caps, axis); +} + +static void +tool_set_bits(const struct tablet_dispatch *tablet, + struct libinput_tool *tool) +{ + enum libinput_tool_type type = tool->type; + + /* Determine the axis capabilities of the tool. Here's a break + * down of the heuristics used here: + * - The Wacom art pen supports all of the extra axes, along + * with rotation + * - The Wacom airbrush supports a wheel with a ~90 deg + * range. + * - All of normal pens and the airbrush support all of the + * extra axes if the tablet can report them + * - All of the mouse-like devices don't report any of + * the extra axes except for rotation (calculated from tilt x/y). + */ + switch (type) { + case LIBINPUT_TOOL_PEN: + case LIBINPUT_TOOL_ERASER: + case LIBINPUT_TOOL_PENCIL: + case LIBINPUT_TOOL_BRUSH: + case LIBINPUT_TOOL_AIRBRUSH: + copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_PRESSURE); + copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_DISTANCE); + copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_TILT_X); + copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_TILT_Y); + break; + default: + break; + } +} + static struct libinput_tool * tablet_get_tool(struct tablet_dispatch *tablet, enum libinput_tool_type type, @@ -397,43 +439,7 @@ tablet_get_tool(struct tablet_dispatch *tablet, .refcount = 1, }; - /* Determine the axis capabilities of the tool. Here's a break - * down of the heuristics used here: - * - The Wacom art pen supports all of the extra axes, along - * with rotation - * - All of normal pens and the airbrush support all of the - * extra axes if the tablet can report them - * - All of the mouse like devices don't really report any of - * the extra axes except for rotation. - * (as of writing this comment, rotation isn't supported, so you - * won't see the mouse or art pen here) - */ - switch (type) { - case LIBINPUT_TOOL_PEN: - case LIBINPUT_TOOL_ERASER: - case LIBINPUT_TOOL_PENCIL: - case LIBINPUT_TOOL_BRUSH: - case LIBINPUT_TOOL_AIRBRUSH: - if (bit_is_set(tablet->axis_caps, - LIBINPUT_TABLET_AXIS_PRESSURE)) - set_bit(tool->axis_caps, - LIBINPUT_TABLET_AXIS_PRESSURE); - if (bit_is_set(tablet->axis_caps, - LIBINPUT_TABLET_AXIS_DISTANCE)) - set_bit(tool->axis_caps, - LIBINPUT_TABLET_AXIS_DISTANCE); - if (bit_is_set(tablet->axis_caps, - LIBINPUT_TABLET_AXIS_TILT_X)) - set_bit(tool->axis_caps, - LIBINPUT_TABLET_AXIS_TILT_X); - if (bit_is_set(tablet->axis_caps, - LIBINPUT_TABLET_AXIS_TILT_Y)) - set_bit(tool->axis_caps, - LIBINPUT_TABLET_AXIS_TILT_Y); - break; - default: - break; - } + tool_set_bits(tablet, tool); list_insert(tool_list, &tool->link); } From 733fef5a673a1e873aea0de099d4499dc88d884a Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 19 Feb 2015 15:46:29 +1000 Subject: [PATCH 101/255] tablet: expand the button mask to allow for BTN_LEFT, RIGHT, MIDDLE Expand the mask to fit KEY_CNT buttons, the mouse has LMR buttons and a few more, trying to squash the range is more error-prone than having the full key range instead. Signed-off-by: Peter Hutterer Reviewed-by: Stephen Chandler Paul --- src/evdev-tablet.c | 83 ++++++++++++++++++++++++++++------------------ src/evdev-tablet.h | 2 +- 2 files changed, 52 insertions(+), 33 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index dfea318b..f98362d4 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -35,10 +35,37 @@ #define tablet_unset_status(tablet_,s_) (tablet_)->status &= ~(s_) #define tablet_has_status(tablet_,s_) (!!((tablet_)->status & (s_))) -#define tablet_get_pressed_buttons(tablet_,field_) \ - ((tablet_)->button_state.field_ & ~((tablet_)->prev_button_state.field_)) -#define tablet_get_released_buttons(tablet_,field_) \ - ((tablet_)->prev_button_state.field_ & ~((tablet_)->button_state.field_)) +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, @@ -248,14 +275,11 @@ tablet_update_button(struct tablet_dispatch *tablet, uint32_t evcode, uint32_t enable) { - uint32_t button, *mask; - /* XXX: This really depends on the expected buttons fitting in the mask */ if (evcode >= BTN_MISC && evcode <= BTN_TASK) { return; } else if (evcode >= BTN_TOUCH && evcode <= BTN_STYLUS2) { - mask = &tablet->button_state.stylus_buttons; - button = evcode - BTN_TOUCH; + /* noop */ } else { log_info(tablet->device->base.seat->libinput, "Unhandled button %s (%#x)\n", @@ -263,13 +287,11 @@ tablet_update_button(struct tablet_dispatch *tablet, return; } - assert(button < 32); - if (enable) { - (*mask) |= 1 << button; + set_bit(tablet->button_state.stylus_buttons, evcode); tablet_set_status(tablet, TABLET_BUTTONS_PRESSED); } else { - (*mask) &= ~(1 << button); + clear_bit(tablet->button_state.stylus_buttons, evcode); tablet_set_status(tablet, TABLET_BUTTONS_RELEASED); } } @@ -452,28 +474,23 @@ tablet_notify_button_mask(struct tablet_dispatch *tablet, struct evdev_device *device, uint32_t time, struct libinput_tool *tool, - uint32_t buttons, - uint32_t button_base, + const unsigned char *buttons, + unsigned int buttons_len, enum libinput_button_state state) { struct libinput_device *base = &device->base; - int32_t num_button = 0; + size_t i; + size_t nbits = 8 * sizeof(buttons[0]) * buttons_len; - while (buttons) { - int enabled; - - num_button++; - enabled = (buttons & 1); - buttons >>= 1; - - if (!enabled) + for (i = 0; i < nbits; i++) { + if (!bit_is_set(buttons, i)) continue; tablet_notify_button(base, time, tool, tablet->axes, - num_button + button_base - 1, + i, state); } } @@ -485,21 +502,21 @@ tablet_notify_buttons(struct tablet_dispatch *tablet, struct libinput_tool *tool, enum libinput_button_state state) { - uint32_t stylus_buttons; + unsigned char buttons[ARRAY_LENGTH(tablet->button_state.stylus_buttons)]; if (state == LIBINPUT_BUTTON_STATE_PRESSED) - stylus_buttons = - tablet_get_pressed_buttons(tablet, stylus_buttons); + tablet_get_pressed_buttons(tablet, buttons, sizeof(buttons)); else - stylus_buttons = - tablet_get_released_buttons(tablet, stylus_buttons); + tablet_get_released_buttons(tablet, + buttons, + sizeof(buttons)); tablet_notify_button_mask(tablet, device, time, tool, - stylus_buttons, - BTN_TOUCH, + buttons, + sizeof(buttons), state); } @@ -542,7 +559,9 @@ tablet_flush(struct tablet_dispatch *tablet, if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) { /* Release all stylus buttons */ - tablet->button_state.stylus_buttons = 0; + 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)) { diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index 6226d63b..d2806b4d 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -41,7 +41,7 @@ enum tablet_status { }; struct button_state { - uint32_t stylus_buttons; /* bitmask of evcode - BTN_TOUCH */ + unsigned char stylus_buttons[NCHARS(KEY_CNT)]; }; struct tablet_dispatch { From 9be6b3e86410132bc91620c2820343bf6b934a7d Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 18 Feb 2015 13:53:31 +1000 Subject: [PATCH 102/255] tablet: add support for libinput_tool_has_button libwacom can tell us how many buttons we have per stylus, so we map those into BTN_STYLUS and BTN_STYLUS2. BTN_TOUCH is set on all styli. Signed-off-by: Peter Hutterer Reviewed-by: Stephen Chandler Paul --- src/evdev-tablet.c | 73 ++++++++++++++++++++++++++++++++++++++++++ src/libinput-private.h | 1 + src/libinput.c | 10 ++++++ src/libinput.h | 15 +++++++++ src/libinput.sym | 1 + 5 files changed, 100 insertions(+) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index f98362d4..ce750ef0 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -382,6 +382,51 @@ copy_axis_cap(const struct tablet_dispatch *tablet, 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 void +tool_set_bits_from_libwacom(const struct tablet_dispatch *tablet, + struct libinput_tool *tool) +{ +#if HAVE_LIBWACOM + WacomDeviceDatabase *db; + const WacomStylus *s = NULL; + int code; + + db = libwacom_database_new(); + if (!db) + goto out; + s = libwacom_stylus_get_for_id(db, tool->tool_id); + if (!s) + goto out; + + if (libwacom_stylus_get_type(s) == 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); + } + +out: + if (db) + libwacom_database_destroy(db); +#endif +} + static void tool_set_bits(const struct tablet_dispatch *tablet, struct libinput_tool *tool) @@ -413,6 +458,34 @@ tool_set_bits(const struct tablet_dispatch *tablet, default: break; } + +#if HAVE_LIBWACOM + tool_set_bits_from_libwacom(tablet, tool); +#else + /* 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; + } +#endif } static struct libinput_tool * diff --git a/src/libinput-private.h b/src/libinput-private.h index b2dc4069..9f326554 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -191,6 +191,7 @@ struct libinput_tool { 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; }; diff --git a/src/libinput.c b/src/libinput.c index b165c59b..5ed3ffc2 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -681,6 +681,16 @@ libinput_tool_has_axis(struct libinput_tool *tool, 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) diff --git a/src/libinput.h b/src/libinput.h index bf3b40cf..241b2b44 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1241,6 +1241,21 @@ 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 * diff --git a/src/libinput.sym b/src/libinput.sym index 5561478a..e6742266 100644 --- a/src/libinput.sym +++ b/src/libinput.sym @@ -159,6 +159,7 @@ LIBINPUT_TABLET_SUPPORT { 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; From 7d6253247978612c8624e1d4552f2df09ca9edf2 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 19 Feb 2015 17:18:58 +1000 Subject: [PATCH 103/255] tablet: handle mouse-buttons from a tool Signed-off-by: Peter Hutterer Reviewed-by: Benjamin Tissoires Reviewed-by: Stephen Chandler Paul --- src/evdev-tablet.c | 28 +++++++++++--- test/tablet.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 6 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index ce750ef0..a20b7247 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -275,12 +275,20 @@ tablet_update_button(struct tablet_dispatch *tablet, uint32_t evcode, uint32_t enable) { - - if (evcode >= BTN_MISC && evcode <= BTN_TASK) { - return; - } else if (evcode >= BTN_TOUCH && evcode <= BTN_STYLUS2) { - /* noop */ - } else { + 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); @@ -344,6 +352,14 @@ tablet_process_key(struct tablet_dispatch *tablet, 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: diff --git a/test/tablet.c b/test/tablet.c index 096c9b26..9c3d76d7 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -1103,6 +1103,100 @@ START_TEST(tool_capabilities) } 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 + int main(int argc, char **argv) { @@ -1123,6 +1217,8 @@ main(int argc, char **argv) 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); return litest_run(argc, argv); } From cbce0d03b000ddaa84fe3f6bf4a300b22fa8e9ce Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 19 Feb 2015 18:04:27 +1000 Subject: [PATCH 104/255] tablet: rely on libwacom to give us the right tablet axes Signed-off-by: Peter Hutterer Reviewed-by: Stephen Chandler Paul --- src/evdev-tablet.c | 49 +++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index a20b7247..c502c213 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -408,14 +408,17 @@ copy_button_cap(const struct tablet_dispatch *tablet, set_bit(tool->buttons, button); } -static void +static inline int tool_set_bits_from_libwacom(const struct tablet_dispatch *tablet, struct libinput_tool *tool) { + int rc = 1; + #if HAVE_LIBWACOM WacomDeviceDatabase *db; const WacomStylus *s = NULL; int code; + WacomStylusType type; db = libwacom_database_new(); if (!db) @@ -424,7 +427,8 @@ tool_set_bits_from_libwacom(const struct tablet_dispatch *tablet, if (!s) goto out; - if (libwacom_stylus_get_type(s) == WSTYLUS_PUCK) { + type = libwacom_stylus_get_type(s); + if (type == WSTYLUS_PUCK) { for (code = BTN_LEFT; code < BTN_LEFT + libwacom_stylus_get_num_buttons(s); code++) @@ -437,10 +441,30 @@ tool_set_bits_from_libwacom(const struct tablet_dispatch *tablet, copy_button_cap(tablet, tool, BTN_TOUCH); } + /* Eventually we want libwacom to tell us each axis on each device + separately. */ + switch(type) { + case WSTYLUS_AIRBRUSH: + case WSTYLUS_MARKER: + case WSTYLUS_GENERAL: + case WSTYLUS_INKING: + case WSTYLUS_CLASSIC: + case WSTYLUS_STROKE: + copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_PRESSURE); + copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_DISTANCE); + copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_TILT_X); + copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_TILT_Y); + break; + default: + break; + } + + rc = 0; out: if (db) libwacom_database_destroy(db); #endif + return rc; } static void @@ -449,16 +473,13 @@ tool_set_bits(const struct tablet_dispatch *tablet, { enum libinput_tool_type type = tool->type; - /* Determine the axis capabilities of the tool. Here's a break - * down of the heuristics used here: - * - The Wacom art pen supports all of the extra axes, along - * with rotation - * - The Wacom airbrush supports a wheel with a ~90 deg - * range. - * - All of normal pens and the airbrush support all of the - * extra axes if the tablet can report them - * - All of the mouse-like devices don't report any of - * the extra axes except for rotation (calculated from tilt x/y). +#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: @@ -475,9 +496,6 @@ tool_set_bits(const struct tablet_dispatch *tablet, break; } -#if HAVE_LIBWACOM - tool_set_bits_from_libwacom(tablet, tool); -#else /* If we don't have libwacom, copy all pen-related ones from the tablet vs all mouse-related ones */ switch (type) { @@ -501,7 +519,6 @@ tool_set_bits(const struct tablet_dispatch *tablet, default: break; } -#endif } static struct libinput_tool * From 8edae426e369b876813c224f619135fca5cba2e5 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 16 Feb 2015 15:19:44 +1000 Subject: [PATCH 105/255] tablet: support z-rotation for the mouse/lens tool Needs to be calculated from the x/y tilt values, the mouse has a fixed offset of 175 degrees counterclockwise. Signed-off-by: Peter Hutterer Reviewed-by: Benjamin Tissoires Reviewed-by: Stephen Chandler Paul --- src/evdev-tablet.c | 88 ++++++++++++++++++++++++++++++++++++++---- src/libinput-private.h | 2 +- src/libinput.c | 1 + src/libinput.h | 6 +++ test/tablet.c | 77 ++++++++++++++++++++++++++++++++++++ tools/event-debug.c | 8 ++++ 6 files changed, 173 insertions(+), 9 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index c502c213..bfdbcc4a 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -71,12 +71,25 @@ 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; - code = axis_to_evcode(axis); - return libevdev_has_event_code(tablet->device->evdev, - EV_ABS, - code); + if (axis == LIBINPUT_TABLET_AXIS_ROTATION_Z) { + has_axis = (libevdev_has_event_code(evdev, + EV_ABS, + ABS_TILT_X) && + libevdev_has_event_code(evdev, + EV_ABS, + ABS_TILT_Y)); + } else { + code = axis_to_evcode(axis); + has_axis = libevdev_has_event_code(evdev, + EV_ABS, + code); + } + + return has_axis; } static void @@ -200,6 +213,32 @@ 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 void tablet_check_notify_axes(struct tablet_dispatch *tablet, struct evdev_device *device, @@ -209,12 +248,30 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, struct libinput_device *base = &device->base; bool axis_update_needed = false; int a; + double axes[LIBINPUT_TABLET_AXIS_MAX + 1] = {0}; 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)) + if (!bit_is_set(tablet->changed_axes, a)) { + axes[a] = tablet->axes[a]; continue; + } + + axis_update_needed = true; + + /* 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) { + if (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]; + } + continue; + } absinfo = libevdev_get_abs_info(device->evdev, axis_to_evcode(a)); @@ -241,7 +298,7 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, break; } - axis_update_needed = true; + axes[a] = tablet->axes[a]; } /* We need to make sure that we check that the tool is not out of @@ -258,13 +315,13 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, tool, LIBINPUT_TOOL_PROXIMITY_IN, tablet->changed_axes, - tablet->axes); + axes); else tablet_notify_axis(base, time, tool, tablet->changed_axes, - tablet->axes); + axes); } memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes)); @@ -455,6 +512,9 @@ tool_set_bits_from_libwacom(const struct tablet_dispatch *tablet, copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_TILT_X); copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_TILT_Y); break; + case WSTYLUS_PUCK: + copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_ROTATION_Z); + break; default: break; } @@ -492,6 +552,10 @@ tool_set_bits(const struct tablet_dispatch *tablet, copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_TILT_X); copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_TILT_Y); break; + case LIBINPUT_TOOL_MOUSE: + case LIBINPUT_TOOL_LENS: + copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_ROTATION_Z); + break; default: break; } @@ -650,6 +714,14 @@ sanitize_tablet_axes(struct tablet_dispatch *tablet) 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 diff --git a/src/libinput-private.h b/src/libinput-private.h index 9f326554..20d9e43b 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -30,7 +30,7 @@ #include "libinput.h" #include "libinput-util.h" -#define LIBINPUT_TABLET_AXIS_MAX LIBINPUT_TABLET_AXIS_TILT_Y +#define LIBINPUT_TABLET_AXIS_MAX LIBINPUT_TABLET_AXIS_ROTATION_Z struct libinput_source; diff --git a/src/libinput.c b/src/libinput.c index 5ed3ffc2..87ddc69c 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -584,6 +584,7 @@ libinput_event_tablet_get_axis_value(struct libinput_event_tablet *event, case LIBINPUT_TABLET_AXIS_PRESSURE: case LIBINPUT_TABLET_AXIS_TILT_X: case LIBINPUT_TABLET_AXIS_TILT_Y: + case LIBINPUT_TABLET_AXIS_ROTATION_Z: return event->axes[axis]; default: return 0; diff --git a/src/libinput.h b/src/libinput.h index 241b2b44..bbefc38f 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -142,6 +142,7 @@ enum libinput_tablet_axis { LIBINPUT_TABLET_AXIS_PRESSURE = 4, LIBINPUT_TABLET_AXIS_TILT_X = 5, LIBINPUT_TABLET_AXIS_TILT_Y = 6, + LIBINPUT_TABLET_AXIS_ROTATION_Z = 7, }; /** @@ -1050,6 +1051,11 @@ libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, * - @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. * * @note This function may be called for a specific axis even if * libinput_event_tablet_axis_has_changed() returns 0 for that axis. diff --git a/test/tablet.c b/test/tablet.c index 9c3d76d7..6eca5c42 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -1197,6 +1197,82 @@ START_TEST(mouse_buttons) } 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 + int main(int argc, char **argv) { @@ -1219,6 +1295,7 @@ main(int argc, char **argv) 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); return litest_run(argc, argv); } diff --git a/tools/event-debug.c b/tools/event-debug.c index 09f208c3..3503143e 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -293,6 +293,7 @@ print_tablet_axis_event(struct libinput_event *ev) struct libinput_event_tablet *t = libinput_event_get_tablet_event(ev); double x, y; double dist, pressure; + double rotation; print_event_time(libinput_event_tablet_get_time(t)); @@ -316,6 +317,13 @@ print_tablet_axis_event(struct libinput_event *ev) else printf("pressure: %.2f%s", pressure, tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_PRESSURE)); + + rotation = libinput_event_tablet_get_axis_value(t, + LIBINPUT_TABLET_AXIS_ROTATION_Z); + printf(" rotation: %.2f%s", + rotation, + tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_ROTATION_Z)); + printf("\n"); } From 0d87dd81213906680a1e18c527581df2bc75e8f5 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 17 Feb 2015 13:04:06 +1000 Subject: [PATCH 106/255] tablet: support airbrush wheel as slider The little wheel isn't a full wheel, it has a ~90 degree rotation angle with a range of 1024 values. To avoid confusion with "wheel" elsewhere in the API name it slider. Signed-off-by: Peter Hutterer Reviewed-by: Stephen Chandler Paul --- src/evdev-tablet.c | 9 ++++- src/evdev-tablet.h | 6 +++ src/libinput-private.h | 2 +- src/libinput.c | 1 + src/libinput.h | 3 ++ test/tablet.c | 88 ++++++++++++++++++++++++++++++++++++++++++ tools/event-debug.c | 8 +++- 7 files changed, 113 insertions(+), 4 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index bfdbcc4a..0e92ee47 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -107,6 +107,7 @@ tablet_process_absolute(struct tablet_dispatch *tablet, 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, @@ -189,7 +190,7 @@ tablet_update_tool(struct tablet_dispatch *tablet, } static inline double -normalize_pressure_or_dist(const struct input_absinfo *absinfo) +normalize_pressure_dist_slider(const struct input_absinfo *absinfo) { double range = absinfo->maximum - absinfo->minimum; double value = (absinfo->value - absinfo->minimum) / range; @@ -286,7 +287,8 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, break; case LIBINPUT_TABLET_AXIS_DISTANCE: case LIBINPUT_TABLET_AXIS_PRESSURE: - tablet->axes[a] = normalize_pressure_or_dist(absinfo); + 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: @@ -502,6 +504,8 @@ tool_set_bits_from_libwacom(const struct tablet_dispatch *tablet, separately. */ switch(type) { case WSTYLUS_AIRBRUSH: + copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_SLIDER); + /* fall-through */ case WSTYLUS_MARKER: case WSTYLUS_GENERAL: case WSTYLUS_INKING: @@ -551,6 +555,7 @@ tool_set_bits(const struct tablet_dispatch *tablet, 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); break; case LIBINPUT_TOOL_MOUSE: case LIBINPUT_TOOL_LENS: diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index d2806b4d..d86bf9e6 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -87,6 +87,9 @@ evcode_to_axis(const uint32_t evcode) 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; @@ -119,6 +122,9 @@ axis_to_evcode(const enum libinput_tablet_axis axis) case LIBINPUT_TABLET_AXIS_TILT_Y: evcode = ABS_TILT_Y; break; + case LIBINPUT_TABLET_AXIS_SLIDER: + evcode = ABS_WHEEL; + break; default: abort(); } diff --git a/src/libinput-private.h b/src/libinput-private.h index 20d9e43b..84e5aaaa 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -30,7 +30,7 @@ #include "libinput.h" #include "libinput-util.h" -#define LIBINPUT_TABLET_AXIS_MAX LIBINPUT_TABLET_AXIS_ROTATION_Z +#define LIBINPUT_TABLET_AXIS_MAX LIBINPUT_TABLET_AXIS_SLIDER struct libinput_source; diff --git a/src/libinput.c b/src/libinput.c index 87ddc69c..9df3d484 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -585,6 +585,7 @@ libinput_event_tablet_get_axis_value(struct libinput_event_tablet *event, case LIBINPUT_TABLET_AXIS_TILT_X: case LIBINPUT_TABLET_AXIS_TILT_Y: case LIBINPUT_TABLET_AXIS_ROTATION_Z: + case LIBINPUT_TABLET_AXIS_SLIDER: return event->axes[axis]; default: return 0; diff --git a/src/libinput.h b/src/libinput.h index bbefc38f..a74b651a 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -143,6 +143,7 @@ enum libinput_tablet_axis { LIBINPUT_TABLET_AXIS_TILT_X = 5, LIBINPUT_TABLET_AXIS_TILT_Y = 6, LIBINPUT_TABLET_AXIS_ROTATION_Z = 7, + LIBINPUT_TABLET_AXIS_SLIDER = 8, }; /** @@ -1056,6 +1057,8 @@ libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, * @ref LIBINPUT_TOOL_MOUSE and @ref LIBINPUT_TOOL_LENS tools the logical * neutral position is pointing to the current logical north of the * tablet. + * - @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. * * @note This function may be called for a specific axis even if * libinput_event_tablet_axis_has_changed() returns 0 for that axis. diff --git a/test/tablet.c b/test/tablet.c index 6eca5c42..fef4fc50 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -1273,6 +1273,92 @@ START_TEST(mouse_rotation) } 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 + int main(int argc, char **argv) { @@ -1296,6 +1382,8 @@ main(int argc, char **argv) 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:airbrush", airbrush_tool, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:airbrush", airbrush_wheel, LITEST_TABLET, LITEST_ANY); return litest_run(argc, argv); } diff --git a/tools/event-debug.c b/tools/event-debug.c index 3503143e..e3f7baa1 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -293,7 +293,7 @@ print_tablet_axis_event(struct libinput_event *ev) struct libinput_event_tablet *t = libinput_event_get_tablet_event(ev); double x, y; double dist, pressure; - double rotation; + double rotation, slider; print_event_time(libinput_event_tablet_get_time(t)); @@ -324,6 +324,12 @@ print_tablet_axis_event(struct libinput_event *ev) rotation, tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_ROTATION_Z)); + slider = libinput_event_tablet_get_axis_value(t, + LIBINPUT_TABLET_AXIS_SLIDER); + printf(" slider: %.2f%s", + slider, + tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_SLIDER)); + printf("\n"); } From 3407226804e8235d632f93a03cae467aae9bc03e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 18 Feb 2015 11:40:55 +1000 Subject: [PATCH 107/255] tablet: support artpen rotation Signed-off-by: Peter Hutterer Reviewed-by: Stephen Chandler Paul --- src/evdev-tablet.c | 35 +++++++++++++---- src/evdev-tablet.h | 6 +++ src/libinput.h | 3 +- test/tablet.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 130 insertions(+), 9 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 0e92ee47..db3f1768 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -103,6 +103,7 @@ tablet_process_absolute(struct tablet_dispatch *tablet, switch (e->code) { case ABS_X: case ABS_Y: + case ABS_Z: case ABS_PRESSURE: case ABS_TILT_X: case ABS_TILT_Y: @@ -240,6 +241,16 @@ convert_tilt_to_rotation(struct tablet_dispatch *tablet) 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 void tablet_check_notify_axes(struct tablet_dispatch *tablet, struct evdev_device *device, @@ -263,14 +274,13 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, /* 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) { - if (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]; - } + 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]; continue; } @@ -294,6 +304,10 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, 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); @@ -507,6 +521,10 @@ tool_set_bits_from_libwacom(const struct tablet_dispatch *tablet, copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_SLIDER); /* fall-through */ case WSTYLUS_MARKER: + if (type == WSTYLUS_MARKER) + copy_axis_cap(tablet, tool, + LIBINPUT_TABLET_AXIS_ROTATION_Z); + /* fallthrough */ case WSTYLUS_GENERAL: case WSTYLUS_INKING: case WSTYLUS_CLASSIC: @@ -556,6 +574,7 @@ tool_set_bits(const struct tablet_dispatch *tablet, 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: diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index d86bf9e6..7c472cfc 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -75,6 +75,9 @@ evcode_to_axis(const uint32_t evcode) 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; @@ -122,6 +125,9 @@ axis_to_evcode(const enum libinput_tablet_axis axis) 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; diff --git a/src/libinput.h b/src/libinput.h index a74b651a..502253c6 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1056,7 +1056,8 @@ libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, * 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. + * 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. * diff --git a/test/tablet.c b/test/tablet.c index fef4fc50..afc654eb 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -1359,6 +1359,99 @@ START_TEST(airbrush_wheel) } 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); + + 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); + + /* start with non-zero */ + litest_event(dev, EV_ABS, ABS_Z, 10); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + + litest_drain_events(li); + + scale = (abs->maximum - abs->minimum + 1)/360.0; + for (angle = 0; 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); + libinput_event_destroy(event); + litest_assert_empty_queue(li); + } +} +END_TEST + int main(int argc, char **argv) { @@ -1384,6 +1477,8 @@ main(int argc, char **argv) litest_add("tablet:mouse", mouse_rotation, LITEST_TABLET, LITEST_ANY); 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); return litest_run(argc, argv); } From 0af9aeba8c4793b970634fb4b59c3c85d56f08b6 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 18 Feb 2015 13:17:13 +1000 Subject: [PATCH 108/255] tools: print tool capabilities on proximity Signed-off-by: Peter Hutterer Reviewed-by: Benjamin Tissoires Reviewed-by: Stephen Chandler Paul --- tools/event-debug.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tools/event-debug.c b/tools/event-debug.c index e3f7baa1..225e12fe 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -419,6 +419,38 @@ print_proximity_event(struct libinput_event *ev) printf("%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"); + + 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"); } From ec8b703c9c92ba02b58126bfdaab1a5a3e98128b Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 17 Feb 2015 15:23:41 +1000 Subject: [PATCH 109/255] tools: only print the tablet axes we have on the tool Split out the actual axis printing into a helper function and call that from the main tablet proximity/axis print functions. Signed-off-by: Peter Hutterer Reviewed-by: Benjamin Tissoires Reviewed-by: Stephen Chandler Paul --- tools/event-debug.c | 106 +++++++++++++++++++++++--------------------- 1 file changed, 56 insertions(+), 50 deletions(-) diff --git a/tools/event-debug.c b/tools/event-debug.c index 225e12fe..94a90ec1 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -288,48 +288,77 @@ tablet_axis_changed_sym(struct libinput_event_tablet *t, } static void -print_tablet_axis_event(struct libinput_event *ev) +print_tablet_axes(struct libinput_event_tablet *t) { - struct libinput_event_tablet *t = libinput_event_get_tablet_event(ev); + struct libinput_tool *tool = libinput_event_tablet_get_tool(t); double x, y; double dist, pressure; double rotation, slider; - print_event_time(libinput_event_tablet_get_time(t)); - x = libinput_event_tablet_get_axis_value(t, LIBINPUT_TABLET_AXIS_X); y = libinput_event_tablet_get_axis_value(t, LIBINPUT_TABLET_AXIS_Y); printf("\t%.2f%s/%.2f%s", x, tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_X), y, tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_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); - printf("\ttilt: %.2f%s/%.2f%s ", - x, tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_TILT_X), - y, tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_TILT_Y)); + 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); + printf("\ttilt: %.2f%s/%.2f%s ", + x, tablet_axis_changed_sym(t, + LIBINPUT_TABLET_AXIS_TILT_X), + y, tablet_axis_changed_sym(t, + LIBINPUT_TABLET_AXIS_TILT_Y)); + } - 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) - printf("distance: %.2f%s", - dist, tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_DISTANCE)); - else - printf("pressure: %.2f%s", - pressure, tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_PRESSURE)); + 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) { + printf("\tdistance: %.2f%s", + dist, + tablet_axis_changed_sym(t, + LIBINPUT_TABLET_AXIS_DISTANCE)); + } else { + printf("\tpressure: %.2f%s", + pressure, + tablet_axis_changed_sym(t, + LIBINPUT_TABLET_AXIS_PRESSURE)); + } + } - rotation = libinput_event_tablet_get_axis_value(t, + if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_ROTATION_Z)) { + rotation = libinput_event_tablet_get_axis_value(t, LIBINPUT_TABLET_AXIS_ROTATION_Z); - printf(" rotation: %.2f%s", - rotation, - tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_ROTATION_Z)); + printf("\trotation: %.2f%s", + rotation, + tablet_axis_changed_sym(t, + LIBINPUT_TABLET_AXIS_ROTATION_Z)); + } - slider = libinput_event_tablet_get_axis_value(t, + if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_SLIDER)) { + slider = libinput_event_tablet_get_axis_value(t, LIBINPUT_TABLET_AXIS_SLIDER); - printf(" slider: %.2f%s", - slider, - tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_SLIDER)); + printf("\tslider: %.2f%s", + slider, + tablet_axis_changed_sym(t, + LIBINPUT_TABLET_AXIS_SLIDER)); + } +} +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"); } @@ -350,8 +379,6 @@ print_proximity_event(struct libinput_event *ev) enum libinput_tool_proximity_state state; const char *tool_str, *state_str; - double x, y; - double dist, pressure; switch (libinput_tool_get_type(tool)) { case LIBINPUT_TOOL_PEN: @@ -387,28 +414,7 @@ print_proximity_event(struct libinput_event *ev) print_event_time(libinput_event_tablet_get_time(t)); if (state == LIBINPUT_TOOL_PROXIMITY_IN) { - x = libinput_event_tablet_get_axis_value( - t, LIBINPUT_TABLET_AXIS_X); - y = libinput_event_tablet_get_axis_value( - t, LIBINPUT_TABLET_AXIS_Y); - printf("\t%.2f/%.2f", x, 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); - printf("\ttilt: %.2f/%.2f ", x, y); - - 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) - printf("\tdistance: %.2f ", dist); - else - printf("\tpressure: %.2f ", pressure); - + print_tablet_axes(t); state_str = "proximity-in"; } else if (state == LIBINPUT_TOOL_PROXIMITY_OUT) { state_str = "proximity-out"; @@ -417,7 +423,7 @@ print_proximity_event(struct libinput_event *ev) abort(); } - printf("%s (%#x) %s", + printf("\t%s (%#x) %s", tool_str, libinput_tool_get_serial(tool), state_str); printf("\taxes:"); From 71c2cd26ccf4bdb1b064dd3acb4c4e8ec43124b7 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 20 Feb 2015 11:41:06 +1000 Subject: [PATCH 110/255] tablet: support the rel wheel on the mouse device Providing a relative axis in the axis_get_value() is inconsistent with the other axes, this will be fixed in a follow-up commit. Signed-off-by: Peter Hutterer Reviewed-by: Benjamin Tissoires Reviewed-by: Stephen Chandler Paul --- src/evdev-tablet.c | 56 ++++++++++++++++++++++++++++++++++++++++++ src/evdev-tablet.h | 18 ++++++++++++++ src/libinput-private.h | 2 +- src/libinput.c | 1 + src/libinput.h | 4 +++ tools/event-debug.c | 11 ++++++++- 6 files changed, 90 insertions(+), 2 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index db3f1768..8de6fc43 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -82,6 +82,10 @@ tablet_device_has_axis(struct tablet_dispatch *tablet, libevdev_has_event_code(evdev, EV_ABS, ABS_TILT_Y)); + } 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, @@ -251,6 +255,15 @@ convert_to_degrees(const struct input_absinfo *absinfo, double offset) 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 void tablet_check_notify_axes(struct tablet_dispatch *tablet, struct evdev_device *device, @@ -282,6 +295,11 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, axes[LIBINPUT_TABLET_AXIS_TILT_Y] = 0; axes[a] = tablet->axes[a]; continue; + } else if (a == LIBINPUT_TABLET_AXIS_REL_WHEEL) { + tablet->axes[a] = normalize_wheel(tablet, + tablet->deltas[a]); + axes[a] = tablet->axes[a]; + continue; } absinfo = libevdev_get_abs_info(device->evdev, @@ -441,6 +459,35 @@ tablet_process_key(struct tablet_dispatch *tablet, } } +static void +tablet_process_relative(struct tablet_dispatch *tablet, + struct evdev_device *device, + struct input_event *e, + uint32_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, @@ -536,6 +583,11 @@ tool_set_bits_from_libwacom(const struct tablet_dispatch *tablet, break; case WSTYLUS_PUCK: copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_ROTATION_Z); + /* lens cursors don't have a wheel */ + if (!libwacom_stylus_has_lens(s)) + copy_axis_cap(tablet, + tool, + LIBINPUT_TABLET_AXIS_REL_WHEEL); break; default: break; @@ -579,6 +631,7 @@ tool_set_bits(const struct tablet_dispatch *tablet, 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; @@ -826,6 +879,9 @@ tablet_process(struct evdev_dispatch *dispatch, 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; diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index 7c472cfc..ea103b0d 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -50,6 +50,7 @@ struct tablet_dispatch { 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 */ @@ -101,6 +102,23 @@ evcode_to_axis(const uint32_t evcode) 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) { diff --git a/src/libinput-private.h b/src/libinput-private.h index 84e5aaaa..071204ef 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -30,7 +30,7 @@ #include "libinput.h" #include "libinput-util.h" -#define LIBINPUT_TABLET_AXIS_MAX LIBINPUT_TABLET_AXIS_SLIDER +#define LIBINPUT_TABLET_AXIS_MAX LIBINPUT_TABLET_AXIS_REL_WHEEL struct libinput_source; diff --git a/src/libinput.c b/src/libinput.c index 9df3d484..2640321e 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -586,6 +586,7 @@ libinput_event_tablet_get_axis_value(struct libinput_event_tablet *event, 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; diff --git a/src/libinput.h b/src/libinput.h index 502253c6..a22f8bc7 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -144,6 +144,7 @@ enum libinput_tablet_axis { LIBINPUT_TABLET_AXIS_TILT_Y = 6, LIBINPUT_TABLET_AXIS_ROTATION_Z = 7, LIBINPUT_TABLET_AXIS_SLIDER = 8, + LIBINPUT_TABLET_AXIS_REL_WHEEL = 9, }; /** @@ -1060,6 +1061,9 @@ libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, * 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 a delta from the + * device's previous position, in degrees. * * @note This function may be called for a specific axis even if * libinput_event_tablet_axis_has_changed() returns 0 for that axis. diff --git a/tools/event-debug.c b/tools/event-debug.c index 94a90ec1..09edac09 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -293,7 +293,7 @@ print_tablet_axes(struct libinput_event_tablet *t) struct libinput_tool *tool = libinput_event_tablet_get_tool(t); double x, y; double dist, pressure; - double rotation, slider; + double rotation, slider, wheel; x = libinput_event_tablet_get_axis_value(t, LIBINPUT_TABLET_AXIS_X); y = libinput_event_tablet_get_axis_value(t, LIBINPUT_TABLET_AXIS_Y); @@ -350,6 +350,15 @@ print_tablet_axes(struct libinput_event_tablet *t) tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_SLIDER)); } + + if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_REL_WHEEL)) { + wheel = libinput_event_tablet_get_axis_value(t, + LIBINPUT_TABLET_AXIS_REL_WHEEL); + printf("\twheel: %.2f%s", + wheel, + tablet_axis_changed_sym(t, + LIBINPUT_TABLET_AXIS_REL_WHEEL)); + } } static void From 57bba7f8a516b98b0eb87bda2759f89521768a37 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 20 Feb 2015 12:03:52 +1000 Subject: [PATCH 111/255] tablet: add libinput_tablet_get_axis_delta() Signed-off-by: Peter Hutterer Reviewed-by: Stephen Chandler Paul --- src/evdev-tablet.c | 56 ++++++++++++++++++++++++++++--- src/libinput-private.h | 3 +- src/libinput.c | 38 ++++++++++++++++++++- src/libinput.h | 27 +++++++++++++-- src/libinput.sym | 1 + test/tablet.c | 75 +++++++++++++++++++++++++++++++++++++++--- tools/event-debug.c | 54 +++++++++++++++++++++--------- 7 files changed, 227 insertions(+), 27 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 8de6fc43..f5cd63fe 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -264,6 +264,48 @@ normalize_wheel(struct tablet_dispatch *tablet, 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, @@ -274,6 +316,8 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, bool axis_update_needed = false; int a; double axes[LIBINPUT_TABLET_AXIS_MAX + 1] = {0}; + double deltas[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; @@ -284,6 +328,7 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, } 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 */ @@ -294,11 +339,12 @@ tablet_check_notify_axes(struct tablet_dispatch *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) { - tablet->axes[a] = normalize_wheel(tablet, - tablet->deltas[a]); - axes[a] = tablet->axes[a]; + deltas[a] = normalize_wheel(tablet, + tablet->deltas[a]); + axes[a] = 0; continue; } @@ -333,6 +379,7 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, } 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 @@ -355,7 +402,8 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, time, tool, tablet->changed_axes, - axes); + axes, + deltas); } memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes)); diff --git a/src/libinput-private.h b/src/libinput-private.h index 071204ef..3a4e4a5a 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -349,7 +349,8 @@ tablet_notify_axis(struct libinput_device *device, uint32_t time, struct libinput_tool *tool, unsigned char *changed_axes, - double *axes); + double *axes, + double *deltas); void tablet_notify_proximity(struct libinput_device *device, diff --git a/src/libinput.c b/src/libinput.c index 2640321e..71271827 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -86,6 +86,7 @@ struct libinput_event_tablet { uint32_t seat_button_count; uint32_t time; double axes[LIBINPUT_TABLET_AXIS_MAX + 1]; + double deltas[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; @@ -593,6 +594,37 @@ libinput_event_tablet_get_axis_value(struct libinput_event_tablet *event, } } +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_x_transformed(struct libinput_event_tablet *event, uint32_t width) @@ -1400,7 +1432,8 @@ tablet_notify_axis(struct libinput_device *device, uint32_t time, struct libinput_tool *tool, unsigned char *changed_axes, - double *axes) + double *axes, + double *deltas) { struct libinput_event_tablet *axis_event; @@ -1417,6 +1450,7 @@ tablet_notify_axis(struct libinput_device *device, 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)); post_device_event(device, time, @@ -1450,6 +1484,8 @@ tablet_notify_proximity(struct libinput_device *device, changed_axes, sizeof(proximity_event->changed_axes)); + /* deltas are always 0 on prox-in/out */ + post_device_event(device, time, LIBINPUT_EVENT_TABLET_PROXIMITY, diff --git a/src/libinput.h b/src/libinput.h index a22f8bc7..60fdfb01 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1062,8 +1062,8 @@ libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, * - @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 a delta from the - * device's previous position, in degrees. + * 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. @@ -1077,6 +1077,29 @@ 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. + * + * @note The delta is *not* the delta to the previous event, but the delta + * to the previous axis state, i.e. the delta to the last event that + * libinput_event_tablet_axis_has_changed() returned true for this axis. + * + * @param event The libinput tablet event + * @param axis The axis to retrieve the value of + * @return The delta to the previous axis value + */ +double +libinput_event_tablet_get_axis_delta(struct libinput_event_tablet *event, + enum libinput_tablet_axis axis); + /** * @ingroup event_tablet * diff --git a/src/libinput.sym b/src/libinput.sym index e6742266..cb94d60b 100644 --- a/src/libinput.sym +++ b/src/libinput.sym @@ -146,6 +146,7 @@ LIBINPUT_0.12.0 { 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_value; libinput_event_tablet_get_button; libinput_event_tablet_get_button_state; diff --git a/test/tablet.c b/test/tablet.c index afc654eb..1eb91c69 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -381,6 +381,67 @@ START_TEST(motion) } 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(left_handed) { #if HAVE_LIBWACOM @@ -1415,20 +1476,19 @@ START_TEST(artpen_rotation) 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); - /* start with non-zero */ - litest_event(dev, EV_ABS, ABS_Z, 10); + litest_event(dev, EV_ABS, ABS_Z, abs->minimum); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_drain_events(li); - scale = (abs->maximum - abs->minimum + 1)/360.0; - for (angle = 0; angle < 360; angle += 8) { + for (angle = 8; angle < 360; angle += 8) { int a = angle * scale + abs->minimum; litest_event(dev, EV_ABS, ABS_Z, a); @@ -1446,8 +1506,14 @@ START_TEST(artpen_rotation) /* 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 @@ -1467,6 +1533,7 @@ main(int argc, char **argv) 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_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); diff --git a/tools/event-debug.c b/tools/event-debug.c index 09edac09..7b68d96b 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -291,15 +291,19 @@ static void print_tablet_axes(struct libinput_event_tablet *t) { struct libinput_tool *tool = libinput_event_tablet_get_tool(t); - double x, y; + 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); - printf("\t%.2f%s/%.2f%s", + 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)); + 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)) { @@ -307,11 +311,16 @@ print_tablet_axes(struct libinput_event_tablet *t) LIBINPUT_TABLET_AXIS_TILT_X); y = libinput_event_tablet_get_axis_value(t, LIBINPUT_TABLET_AXIS_TILT_Y); - printf("\ttilt: %.2f%s/%.2f%s ", + 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)); + LIBINPUT_TABLET_AXIS_TILT_Y), + dx, dy); } if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_DISTANCE) || @@ -321,43 +330,58 @@ print_tablet_axes(struct libinput_event_tablet *t) pressure = libinput_event_tablet_get_axis_value(t, LIBINPUT_TABLET_AXIS_PRESSURE); if (dist) { - printf("\tdistance: %.2f%s", + 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)); + LIBINPUT_TABLET_AXIS_DISTANCE), + delta); } else { - printf("\tpressure: %.2f%s", + 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)); + 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); - printf("\trotation: %.2f%s", + 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)); + 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); - printf("\tslider: %.2f%s", + 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)); + 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); - printf("\twheel: %.2f%s", + delta = libinput_event_tablet_get_axis_delta(t, + LIBINPUT_TABLET_AXIS_REL_WHEEL); + printf("\twheel: %.2f%s (%.2f)", wheel, tablet_axis_changed_sym(t, - LIBINPUT_TABLET_AXIS_REL_WHEEL)); + LIBINPUT_TABLET_AXIS_REL_WHEEL), + delta); } } From abc57105aeddaefdab72d7c30d37cebe2b35194e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 20 Feb 2015 14:34:31 +1000 Subject: [PATCH 112/255] tablet: add libinput_event_tablet_get_axis_delta_discrete() Equivalent to the pointer axis function - it gets the mouse wheel clicks from the tablet mouse. Signed-off-by: Peter Hutterer Reviewed-by: Stephen Chandler Paul --- src/evdev-tablet.c | 5 ++++- src/libinput-private.h | 3 ++- src/libinput.c | 32 +++++++++++++++++++++++++++++++- src/libinput.h | 22 ++++++++++++++++++++++ src/libinput.sym | 1 + tools/event-debug.c | 6 +++--- 6 files changed, 63 insertions(+), 6 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index f5cd63fe..45242025 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -317,6 +317,7 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, int a; double axes[LIBINPUT_TABLET_AXIS_MAX + 1] = {0}; double deltas[LIBINPUT_TABLET_AXIS_MAX + 1] = {0}; + double deltas_discrete[LIBINPUT_TABLET_AXIS_MAX + 1] = {0}; double oldval; for (a = LIBINPUT_TABLET_AXIS_X; a <= LIBINPUT_TABLET_AXIS_MAX; a++) { @@ -342,6 +343,7 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, deltas[a] = get_delta(a, tablet->axes[a], oldval); continue; } else if (a == LIBINPUT_TABLET_AXIS_REL_WHEEL) { + deltas_discrete[a] = tablet->deltas[a]; deltas[a] = normalize_wheel(tablet, tablet->deltas[a]); axes[a] = 0; @@ -403,7 +405,8 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, tool, tablet->changed_axes, axes, - deltas); + deltas, + deltas_discrete); } memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes)); diff --git a/src/libinput-private.h b/src/libinput-private.h index 3a4e4a5a..1c2a3290 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -350,7 +350,8 @@ tablet_notify_axis(struct libinput_device *device, struct libinput_tool *tool, unsigned char *changed_axes, double *axes, - double *deltas); + double *deltas, + double *deltas_discrete); void tablet_notify_proximity(struct libinput_device *device, diff --git a/src/libinput.c b/src/libinput.c index 71271827..d693ef65 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -87,6 +87,7 @@ struct libinput_event_tablet { uint32_t time; double axes[LIBINPUT_TABLET_AXIS_MAX + 1]; double deltas[LIBINPUT_TABLET_AXIS_MAX + 1]; + double deltas_discrete[LIBINPUT_TABLET_AXIS_MAX + 1]; unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_AXIS_MAX + 1)]; struct libinput_tool *tool; enum libinput_tool_proximity_state proximity_state; @@ -625,6 +626,31 @@ libinput_event_tablet_get_axis_delta(struct libinput_event_tablet *event, } } +LIBINPUT_EXPORT double +libinput_event_tablet_get_axis_delta_discrete( + struct libinput_event_tablet *event, + enum libinput_tablet_axis axis) +{ + if (event->base.type != LIBINPUT_EVENT_TABLET_AXIS && + event->base.type != LIBINPUT_EVENT_TABLET_PROXIMITY) + return 0; + + switch(axis) { + case LIBINPUT_TABLET_AXIS_X: + case LIBINPUT_TABLET_AXIS_Y: + case LIBINPUT_TABLET_AXIS_DISTANCE: + case LIBINPUT_TABLET_AXIS_PRESSURE: + case LIBINPUT_TABLET_AXIS_TILT_X: + case LIBINPUT_TABLET_AXIS_TILT_Y: + case LIBINPUT_TABLET_AXIS_ROTATION_Z: + case LIBINPUT_TABLET_AXIS_SLIDER: + case LIBINPUT_TABLET_AXIS_REL_WHEEL: + return event->deltas_discrete[axis]; + default: + return 0; + } +} + LIBINPUT_EXPORT double libinput_event_tablet_get_x_transformed(struct libinput_event_tablet *event, uint32_t width) @@ -1433,7 +1459,8 @@ tablet_notify_axis(struct libinput_device *device, struct libinput_tool *tool, unsigned char *changed_axes, double *axes, - double *deltas) + double *deltas, + double *deltas_discrete) { struct libinput_event_tablet *axis_event; @@ -1451,6 +1478,9 @@ tablet_notify_axis(struct libinput_device *device, sizeof(axis_event->changed_axes)); memcpy(axis_event->axes, axes, sizeof(axis_event->axes)); memcpy(axis_event->deltas, deltas, sizeof(axis_event->deltas)); + memcpy(axis_event->deltas_discrete, + deltas_discrete, + sizeof(axis_event->deltas_discrete)); post_device_event(device, time, diff --git a/src/libinput.h b/src/libinput.h index 60fdfb01..17be1797 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1100,6 +1100,28 @@ 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. + * + * @note The delta is *not* the delta to the previous event, but the delta + * to the previous axis state, i.e. the delta to the last event that + * libinput_event_tablet_axis_has_changed() returned true for this axis. + * + * @param event The libinput tablet event + * @param axis The axis to retrieve the value of + * @return The delta to the previous axis value in discrete steps + */ +double +libinput_event_tablet_get_axis_delta_discrete( + struct libinput_event_tablet *event, + enum libinput_tablet_axis axis); + /** * @ingroup event_tablet * diff --git a/src/libinput.sym b/src/libinput.sym index cb94d60b..62ea6960 100644 --- a/src/libinput.sym +++ b/src/libinput.sym @@ -147,6 +147,7 @@ LIBINPUT_TABLET_SUPPORT { libinput_event_get_tablet_event; libinput_event_tablet_axis_has_changed; libinput_event_tablet_get_axis_delta; + libinput_event_tablet_get_axis_delta_discrete; libinput_event_tablet_get_axis_value; libinput_event_tablet_get_button; libinput_event_tablet_get_button_state; diff --git a/tools/event-debug.c b/tools/event-debug.c index 7b68d96b..226a70ca 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -375,13 +375,13 @@ print_tablet_axes(struct libinput_event_tablet *t) if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_REL_WHEEL)) { wheel = libinput_event_tablet_get_axis_value(t, LIBINPUT_TABLET_AXIS_REL_WHEEL); - delta = libinput_event_tablet_get_axis_delta(t, + delta = libinput_event_tablet_get_axis_delta_discrete(t, LIBINPUT_TABLET_AXIS_REL_WHEEL); - printf("\twheel: %.2f%s (%.2f)", + printf("\twheel: %.2f%s (%d)", wheel, tablet_axis_changed_sym(t, LIBINPUT_TABLET_AXIS_REL_WHEEL), - delta); + (int)delta); } } From b7a19079bfae44ee8385e65f6b12db09c9aa152e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 26 Feb 2015 11:42:19 +1000 Subject: [PATCH 113/255] test: add REL_WHEEL to intuos tablet Signed-off-by: Peter Hutterer --- test/litest-wacom-intuos-tablet.c | 1 + 1 file changed, 1 insertion(+) diff --git a/test/litest-wacom-intuos-tablet.c b/test/litest-wacom-intuos-tablet.c index 2d95ad14..e0e1d44b 100644 --- a/test/litest-wacom-intuos-tablet.c +++ b/test/litest-wacom-intuos-tablet.c @@ -121,6 +121,7 @@ static int events[] = { 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, From 3370e6733620c41f70e87340de7a5316259e6c4e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 26 Feb 2015 13:14:25 +1000 Subject: [PATCH 114/255] test: add tablet wheel test Signed-off-by: Peter Hutterer --- test/tablet.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/test/tablet.c b/test/tablet.c index 1eb91c69..519b067b 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -1334,6 +1334,105 @@ START_TEST(mouse_rotation) } 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(); @@ -1542,6 +1641,7 @@ main(int argc, char **argv) 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_ANY); 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); From 9787638daa8b1b94a8afad02135d40d33b6b29dc Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 2 Mar 2015 16:43:32 +1000 Subject: [PATCH 115/255] cosmetic: add missing empty line Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 45242025..b39df500 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -517,6 +517,7 @@ tablet_process_relative(struct tablet_dispatch *tablet, uint32_t time) { enum libinput_tablet_axis axis; + switch (e->code) { case REL_WHEEL: axis = rel_evcode_to_axis(e->code); From b69f9cdfabaa05cf5f55a9b5f32ad599a4bb73e1 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 26 Feb 2015 13:41:19 +1000 Subject: [PATCH 116/255] tablet: fix tool capability test The devices were never added to the libinput context we were checking, and the while loop would quietly ignore not getting any events. Signed-off-by: Peter Hutterer --- test/tablet.c | 85 +++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 46 deletions(-) diff --git a/test/tablet.c b/test/tablet.c index 519b067b..d7486cb9 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -1095,68 +1095,61 @@ START_TEST(tool_capabilities) 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_create_device_with_overrides(LITEST_WACOM_BAMBOO, - NULL, - NULL, - NULL, - NULL); - intuos = litest_create_device_with_overrides(LITEST_WACOM_INTUOS, - NULL, - NULL, - NULL, - NULL); + 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); - 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); - struct libinput_tool *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)); - } + litest_wait_for_event_of_type(li, + LIBINPUT_EVENT_TABLET_PROXIMITY, + -1); - libinput_event_destroy(event); - } + 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); - 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); - struct libinput_tool *tool = - libinput_event_tablet_get_tool(t); + litest_wait_for_event_of_type(li, + LIBINPUT_EVENT_TABLET_PROXIMITY, + -1); - 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)); - } + event = libinput_get_event(li); + t = libinput_event_get_tablet_event(event); + tool = libinput_event_tablet_get_tool(t); - libinput_event_destroy(event); - } + 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); From be13b84f7064ec81db536d5e4e9b11f06644c3af Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 2 Mar 2015 17:04:49 +1000 Subject: [PATCH 117/255] doc: add missing @ref tag Signed-off-by: Peter Hutterer --- src/libinput.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libinput.h b/src/libinput.h index 06207fd7..204f4909 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -162,7 +162,7 @@ struct libinput_tool; * 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 LIBINPUT_TOOL_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 From 5adde65d6be8f46278fd2ba605712b2312aeb5ad Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 2 Mar 2015 16:46:19 +1000 Subject: [PATCH 118/255] tablet: warn if the libwacom context fails to initalize Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index b39df500..9b8b77ee 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -587,14 +587,18 @@ tool_set_bits_from_libwacom(const struct tablet_dispatch *tablet, int rc = 1; #if HAVE_LIBWACOM + struct libinput *libinput = tablet->device->base.seat->libinput; WacomDeviceDatabase *db; const WacomStylus *s = NULL; int code; WacomStylusType type; db = libwacom_database_new(); - if (!db) + 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; @@ -1017,8 +1021,11 @@ tablet_init_left_handed(struct evdev_device *device) pid = evdev_device_get_id_product(device); db = libwacom_database_new(); - if (!db) + if (!db) { + log_info(libinput, + "Failed to initialize libwacom context.\n"); return; + } error = libwacom_error_new(); d = libwacom_new_from_usbid(db, vid, pid, error); From bd6d42782936d1f0a4d3b5c4063935b2382ce67a Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 2 Mar 2015 17:22:44 +1000 Subject: [PATCH 119/255] tools: record the start time before doing anything with libinput Otherwise events generated by libinput during init will have a negative time offset. Signed-off-by: Peter Hutterer --- tools/event-debug.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/event-debug.c b/tools/event-debug.c index 226a70ca..bf23bfb4 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -619,6 +619,9 @@ main(int argc, char **argv) struct libinput *li; struct timespec tp; + clock_gettime(CLOCK_MONOTONIC, &tp); + start_time = tp.tv_sec * 1000 + tp.tv_nsec / 1000000; + tools_init_options(&options); if (tools_parse_args(argc, argv, &options)) @@ -628,9 +631,6 @@ main(int argc, char **argv) if (!li) return 1; - clock_gettime(CLOCK_MONOTONIC, &tp); - start_time = tp.tv_sec * 1000 + tp.tv_nsec / 1000000; - mainloop(li); libinput_unref(li); From 411f95b17fc82d02b91a006371396b1d54db45ad Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 26 Feb 2015 13:55:08 +1000 Subject: [PATCH 120/255] tablet: sync tools already in proximity at startup If a tool is in proximity when we init, send a proximity event immediately. This is only partially reliable due to the current kernel behavior: * if the tool comes into proximity when there is no evdev client, the device won't send any events and must be lifted out-of-proximity first. Patch is in the works, see https://patchwork.kernel.org/patch/5924611/ * before 3.19, if the tool was in proximity (with an evdev client attached), but goes out of proximity and back in with no client connected, we get an immediate proximity out event from the kernel once we connect to the device and no further events after that. See kernel commit b905811a49bcd6e6726ce5bbb591f57aaddfd3be Otherwise, things work as expected. The above should be fixed in the kernel anyway. Note that this changes the order of events during a udev seat init, before we had all DEVICE_ADDED events in a row, now the proximity event may be interspersed. Reported-by: Jason Gerecke Signed-off-by: Peter Hutterer Acked-by: Benjamin Tissoires --- src/evdev-mt-touchpad.c | 1 + src/evdev-tablet.c | 52 +++++++++++++++++++++++++++++++++++++++- src/evdev-tablet.h | 21 ++++++++++++++++ src/evdev.c | 5 ++++ src/evdev.h | 5 ++++ test/tablet.c | 53 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 136 insertions(+), 1 deletion(-) diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index b90d84c5..b3a8b08c 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -897,6 +897,7 @@ static struct evdev_dispatch_interface tp_interface = { tp_device_removed, /* device_suspended, treat as remove */ tp_device_added, /* device_resumed, treat as add */ tp_tag_device, + NULL, /* post_added */ }; static void diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 9b8b77ee..8c11409e 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -190,7 +190,7 @@ tablet_update_tool(struct tablet_dispatch *tablet, tablet_set_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY); tablet_unset_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY); } - else + else if (!tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY)) tablet_set_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY); } @@ -868,6 +868,9 @@ tablet_flush(struct tablet_dispatch *tablet, 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, @@ -915,7 +918,11 @@ tablet_flush(struct tablet_dispatch *tablet, 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, @@ -946,6 +953,7 @@ tablet_process(struct evdev_dispatch *dispatch, break; case EV_SYN: tablet_flush(tablet, device, time); + tablet_reset_state(tablet); break; default: log_error(device->base.seat->libinput, @@ -970,6 +978,47 @@ tablet_destroy(struct evdev_dispatch *dispatch) 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, /* remove */ @@ -979,6 +1028,7 @@ static struct evdev_dispatch_interface tablet_interface = { NULL, /* device_suspended */ NULL, /* device_resumed */ NULL, /* tag_device */ + tablet_check_initial_proximity, }; static int diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index ea103b0d..2ba08fae 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -28,6 +28,7 @@ #define LIBINPUT_TABLET_AXIS_NONE 0 #define LIBINPUT_TOOL_NONE 0 +#define LIBINPUT_TOOL_MAX LIBINPUT_TOOL_LENS enum tablet_status { TABLET_NONE = 0, @@ -156,4 +157,24 @@ axis_to_evcode(const enum libinput_tablet_axis axis) 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 b90ea7c7..2c4d1f15 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -803,6 +803,7 @@ struct evdev_dispatch_interface fallback_interface = { NULL, /* device_suspended */ NULL, /* device_resumed */ fallback_tag_device, + NULL, /* post_added */ }; static uint32_t @@ -1592,6 +1593,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 int diff --git a/src/evdev.h b/src/evdev.h index 74696751..26f321ef 100644 --- a/src/evdev.h +++ b/src/evdev.h @@ -196,6 +196,11 @@ struct evdev_dispatch_interface { /* Tag device with one of EVDEV_TAG */ void (*tag_device)(struct evdev_device *device, struct udev_device *udev_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 { diff --git a/test/tablet.c b/test/tablet.c index d7486cb9..ba61e0e0 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -1157,6 +1157,58 @@ START_TEST(tool_capabilities) } 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(); @@ -1615,6 +1667,7 @@ main(int argc, char **argv) { 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); From 3dc370cf63acf4e7d2f80163fbeace1071b85934 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 2 Mar 2015 16:57:00 +1000 Subject: [PATCH 121/255] tablet: copy distance axis for the mouse/lens cursor devices Signed-off-by: Peter Hutterer Reviewed-by: Benjamin Tissoires --- src/evdev-tablet.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 8c11409e..3e3924ca 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -639,6 +639,7 @@ tool_set_bits_from_libwacom(const struct tablet_dispatch *tablet, break; case WSTYLUS_PUCK: copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_ROTATION_Z); + copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_DISTANCE); /* lens cursors don't have a wheel */ if (!libwacom_stylus_has_lens(s)) copy_axis_cap(tablet, From 0021600ab93d25ed43d9037cfae5c3e23f44fbfe Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 5 Mar 2015 14:14:07 +1000 Subject: [PATCH 122/255] doc: document recommended handling of fake proximity events in the caller Fake proximity events are context dependent and libinput doesn't have access to the context. For example, fake proximity on the Wacom mouse is only required in relative mode - but whether to use relative or absolute events is decided in the caller. Document what the recommended approach is since it's a bit quirky and leave it at that. Signed-off-by: Peter Hutterer Reviewed-by: Benjamin Tissoires --- doc/Makefile.am | 1 + doc/tablet-support.dox | 49 ++++++++++++++++++++++++++++++++++++++++++ src/libinput.h | 2 ++ 3 files changed, 52 insertions(+) create mode 100644 doc/tablet-support.dox diff --git a/doc/Makefile.am b/doc/Makefile.am index f66b47f1..271960e3 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -15,6 +15,7 @@ header_files = \ $(srcdir)/scrolling.dox \ $(srcdir)/seats.dox \ $(srcdir)/t440-support.dox \ + $(srcdir)/tablet-support.dox \ $(srcdir)/tapping.dox diagram_files = \ 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/libinput.h b/src/libinput.h index 204f4909..416aa589 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1185,6 +1185,8 @@ libinput_event_tablet_get_tool(struct libinput_event_tablet *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. */ From ea0a04dd6ef07cae2c73cd08379f295a95b32ff2 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 12 Mar 2015 14:56:51 +1000 Subject: [PATCH 123/255] Move touch_notify_frame declaration back to the touch_notify group Signed-off-by: Peter Hutterer --- src/libinput-private.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libinput-private.h b/src/libinput-private.h index 1c2a3290..d385e6e1 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -344,6 +344,10 @@ touch_notify_touch_up(struct libinput_device *device, int32_t slot, int32_t seat_slot); +void +touch_notify_frame(struct libinput_device *device, + uint64_t time); + void tablet_notify_axis(struct libinput_device *device, uint32_t time, @@ -368,9 +372,6 @@ tablet_notify_button(struct libinput_device *device, double *axes, int32_t button, enum libinput_button_state state); -void -touch_notify_frame(struct libinput_device *device, - uint64_t time); static inline uint64_t libinput_now(struct libinput *libinput) From 10ca39cf80698cedf92c38fc49a1f9784d2ab385 Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Fri, 27 Mar 2015 15:34:54 -0700 Subject: [PATCH 124/255] evdev: Do not mark tablet touchscreens as tablets Devices like the Cintiq 24HDT are marked with both ID_INPUT_TABLET and ID_INPUT_TOUCHSCREEN in udev. Be sure that we don't try to use such a device as a tablet. Signed-off-by: Jason Gerecke Reviewed-by: Benjamin Tissoires Signed-off-by: Peter Hutterer --- src/evdev.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/evdev.c b/src/evdev.c index 0c85230e..c0351983 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -1538,6 +1538,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); @@ -1609,11 +1610,13 @@ evdev_configure_device(struct evdev_device *device) } } - /* libwacom assigns touchpad _and_ tablet to the tablet touch bits, - so make sure we don't initialize the tablet interface for the - touch device */ - if ((udev_tags & (EVDEV_UDEV_TAG_TABLET|EVDEV_UDEV_TAG_TOUCHPAD)) == - EVDEV_UDEV_TAG_TABLET) { + /* 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, From 22b42fe1bf8ea6ad7b871e998a15b6f5dd38b235 Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Wed, 1 Apr 2015 14:01:01 -0700 Subject: [PATCH 125/255] tools: List relative wheel among axis capabilities Signed-off-by: Jason Gerecke Signed-off-by: Peter Hutterer --- tools/event-debug.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/event-debug.c b/tools/event-debug.c index d2ac4159..e8e49cd7 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -480,6 +480,8 @@ print_proximity_event(struct libinput_event *ev) 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)) From 8d471b7612b05199205f7a0d5ea4107c3ac2ee7e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 26 May 2015 10:39:57 +1000 Subject: [PATCH 126/255] Handle tablet capability in device_has_cap Signed-off-by: Peter Hutterer --- src/libinput.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libinput.c b/src/libinput.c index 61e2b6b2..16751281 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1345,6 +1345,9 @@ device_has_cap(struct libinput_device *device, case LIBINPUT_DEVICE_CAP_TOUCH: capability = "CAP_TOUCH"; break; + case LIBINPUT_DEVICE_CAP_TABLET: + capability = "CAP_TABLET"; + break; } log_bug_libinput(device->seat->libinput, From b5408ec115a766ac4db49627f74c175e47da6803 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 27 May 2015 11:36:34 +1000 Subject: [PATCH 127/255] tablet: add missing libinput_event_tablet_get_base_event Signed-off-by: Peter Hutterer --- src/libinput.c | 13 +++++++++++++ src/libinput.h | 8 ++++++++ src/libinput.sym | 1 + 3 files changed, 22 insertions(+) diff --git a/src/libinput.c b/src/libinput.c index 16751281..fd607d1f 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1972,6 +1972,19 @@ libinput_event_touch_get_base_event(struct libinput_event_touch *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 5bda5fe7..b08e9d62 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1044,6 +1044,14 @@ libinput_event_touch_get_base_event(struct libinput_event_touch *event); * 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 * diff --git a/src/libinput.sym b/src/libinput.sym index 1ad6eef4..6d21877d 100644 --- a/src/libinput.sym +++ b/src/libinput.sym @@ -150,6 +150,7 @@ LIBINPUT_TABLET_SUPPORT { 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; From b2a345e25d379ff83abc16a1bc3d8ad94d9f2e4c Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 27 May 2015 11:28:52 +1000 Subject: [PATCH 128/255] test: add tablet conversion checks Signed-off-by: Peter Hutterer --- test/misc.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/test/misc.c b/test/misc.c index 39683c80..7c0483ab 100644 --- a/test/misc.c +++ b/test/misc.c @@ -131,6 +131,7 @@ START_TEST(event_conversion_device_notify) 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); + ck_assert(libinput_event_get_tablet_event(event) == NULL); litest_restore_log_handler(li); } @@ -185,6 +186,7 @@ START_TEST(event_conversion_pointer) ck_assert(libinput_event_get_device_notify_event(event) == NULL); ck_assert(libinput_event_get_keyboard_event(event) == NULL); ck_assert(libinput_event_get_touch_event(event) == NULL); + ck_assert(libinput_event_get_tablet_event(event) == NULL); litest_restore_log_handler(li); } libinput_event_destroy(event); @@ -233,6 +235,7 @@ START_TEST(event_conversion_pointer_abs) ck_assert(libinput_event_get_device_notify_event(event) == NULL); ck_assert(libinput_event_get_keyboard_event(event) == NULL); ck_assert(libinput_event_get_touch_event(event) == NULL); + ck_assert(libinput_event_get_tablet_event(event) == NULL); litest_restore_log_handler(li); } libinput_event_destroy(event); @@ -274,6 +277,7 @@ START_TEST(event_conversion_key) ck_assert(libinput_event_get_device_notify_event(event) == NULL); ck_assert(libinput_event_get_pointer_event(event) == NULL); ck_assert(libinput_event_get_touch_event(event) == NULL); + ck_assert(libinput_event_get_tablet_event(event) == NULL); litest_restore_log_handler(li); } libinput_event_destroy(event); @@ -322,6 +326,7 @@ START_TEST(event_conversion_touch) 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_tablet_event(event) == NULL); litest_restore_log_handler(li); } libinput_event_destroy(event); @@ -331,6 +336,52 @@ START_TEST(event_conversion_touch) } 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 @@ -630,6 +681,7 @@ litest_setup_tests(void) litest_add_for_device("events:conversion", event_conversion_pointer_abs, LITEST_XEN_VIRTUAL_POINTER); 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_tablet, LITEST_WACOM_CINTIQ); litest_add_no_device("bitfield_helpers", bitfield_helpers); litest_add_no_device("context:refcount", context_ref_counting); From e5fe164bcf1cd77a1023f2270d8087df190e0e14 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 29 Jun 2015 14:13:05 +1000 Subject: [PATCH 129/255] tools - list-devices: print "tablet" capability Signed-off-by: Peter Hutterer --- tools/libinput-list-devices.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/libinput-list-devices.c b/tools/libinput-list-devices.c index 6d162e2f..d64aafca 100644 --- a/tools/libinput-list-devices.c +++ b/tools/libinput-list-devices.c @@ -225,6 +225,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)); From 2776581d0807ab9d75ad6969f76a18158564ea16 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 29 Jun 2015 14:20:20 +1000 Subject: [PATCH 130/255] tablet: fix check for rotation axis Only the cursor tool has rotation encoded as tilt, so if we don't have the mouse tool we don't have rotation. We still need to check for ABS_Z separately though. Crashes Waltop tablets that have tilt x/y but no cursor/lens tool. We'd thus never hit the rotation-z condition in tablet_check_notify_axes() and eventually try to dereference a non-existing ABS_Z axis. https://bugs.freedesktop.org/show_bug.cgi?id=90885 Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index a0ce5091..093c79f6 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -77,11 +77,18 @@ tablet_device_has_axis(struct tablet_dispatch *tablet, 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, From 9b174fc9d872910870e6058a0ac6c2a00b584173 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 29 Jun 2015 15:09:23 +1000 Subject: [PATCH 131/255] test: use the litest macros in the tablet button check Signed-off-by: Peter Hutterer --- test/litest.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/litest.c b/test/litest.c index 253b0018..eb9e544c 100644 --- a/test/litest.c +++ b/test/litest.c @@ -2130,18 +2130,18 @@ litest_assert_tablet_button_event(struct libinput *li, unsigned int button, { 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); - ck_assert(event != NULL); - ck_assert_int_eq(libinput_event_get_type(event), - LIBINPUT_EVENT_TABLET_BUTTON); + litest_assert_notnull(event); + litest_assert_int_eq(libinput_event_get_type(event), type); tev = libinput_event_get_tablet_event(event); - ck_assert_int_eq(libinput_event_tablet_get_button(tev), - button); - ck_assert_int_eq(libinput_event_tablet_get_button_state(tev), - state); + 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); } From 6af06769adc58748a4cbe0e3f9f13b91b0db15d3 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 29 Jun 2015 15:24:06 +1000 Subject: [PATCH 132/255] test: skip testing tablet buttons that don't exist on the device Signed-off-by: Peter Hutterer --- test/tablet.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/tablet.c b/test/tablet.c index a4bf6b2b..a5bf5a15 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -123,6 +123,9 @@ START_TEST(proximity_out_clear_buttons) 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); From 6d4dd289791c07035b4f4232fce0fbddbb01d1fc Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 29 Jun 2015 15:24:25 +1000 Subject: [PATCH 133/255] test: print the missing button's name on test failure Signed-off-by: Peter Hutterer --- test/tablet.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/tablet.c b/test/tablet.c index a5bf5a15..48e58c32 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -151,7 +151,8 @@ START_TEST(proximity_out_clear_buttons) } ck_assert_msg(button_released, - "Button %d was not released.", + "Button %s (%d) was not released.", + libevdev_event_code_get_name(EV_KEY, button), event_button); } } From ac009c2c201ab77912b1b4cd4c7ef07c792e1282 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 29 Jun 2015 14:42:11 +1000 Subject: [PATCH 134/255] test: add a waltop tablet test device Quite similar to wacom tablets but the evdev protocol differs - no serials for example and only two tools. The device has a wheel, but it's not apparently part of the stylus like on the wacom tablets. And it has a bunch of keys. Signed-off-by: Peter Hutterer --- test/Makefile.am | 1 + test/device.c | 2 +- test/litest-waltop-tablet.c | 222 ++++++++++++++++++++++++++++++++++++ test/litest.c | 2 + test/litest.h | 1 + test/tablet.c | 2 +- 6 files changed, 228 insertions(+), 2 deletions(-) create mode 100644 test/litest-waltop-tablet.c diff --git a/test/Makefile.am b/test/Makefile.am index f1330e72..dda37617 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -38,6 +38,7 @@ liblitest_la_SOURCES = \ litest-wacom-isdv4-tablet.c \ litest-wacom-touch.c \ litest-wacom-intuos-finger.c \ + litest-waltop-tablet.c \ litest-wheel-only.c \ litest-xen-virtual-pointer.c \ litest-vmware-virtual-usb-mouse.c \ diff --git a/test/device.c b/test/device.c index 71ffeb41..1751d48c 100644 --- a/test/device.c +++ b/test/device.c @@ -988,5 +988,5 @@ 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); } diff --git a/test/litest-waltop-tablet.c b/test/litest-waltop-tablet.c new file mode 100644 index 00000000..93ec739d --- /dev/null +++ b/test/litest-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.c b/test/litest.c index eb9e544c..ea73d6ee 100644 --- a/test/litest.c +++ b/test/litest.c @@ -356,6 +356,7 @@ extern struct litest_test_device litest_ms_surface_cover_device; extern struct litest_test_device litest_logitech_trackball_device; extern struct litest_test_device litest_atmel_hover_device; extern struct litest_test_device litest_alps_dualpoint_device; +extern struct litest_test_device litest_waltop_tablet_device; struct litest_test_device* devices[] = { &litest_synaptics_clickpad_device, @@ -386,6 +387,7 @@ struct litest_test_device* devices[] = { &litest_logitech_trackball_device, &litest_atmel_hover_device, &litest_alps_dualpoint_device, + &litest_waltop_tablet_device, NULL, }; diff --git a/test/litest.h b/test/litest.h index 4f65208c..8daa69c0 100644 --- a/test/litest.h +++ b/test/litest.h @@ -141,6 +141,7 @@ enum litest_device_type { LITEST_WACOM_CINTIQ = -27, LITEST_WACOM_INTUOS = -28, LITEST_WACOM_ISDV4 = -29, + LITEST_WALTOP = -30, }; enum litest_device_feature { diff --git a/test/tablet.c b/test/tablet.c index 48e58c32..59e6c7ca 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -1691,7 +1691,7 @@ litest_setup_tests(void) 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_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); From 0e23bc45d97f12a409e35b7826a29c1b81f93aac Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 29 Jun 2015 16:03:24 +1000 Subject: [PATCH 135/255] test: disable pointer wheel tests on tablets Not implemented yet, not even for tablets with true wheels. Signed-off-by: Peter Hutterer --- test/pointer.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/pointer.c b/test/pointer.c index 688b6b0b..836964dc 100644 --- a/test/pointer.c +++ b/test/pointer.c @@ -1354,12 +1354,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); From be5c7d7176820c4518ea7f9ae445ba6ff04877ad Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 10 Mar 2015 12:40:14 +1000 Subject: [PATCH 136/255] tablet: rely on libwacom for the list of axis capabilities Signed-off-by: Peter Hutterer Reviewed-by: Benjamin Tissoires --- configure.ac | 2 +- src/evdev-tablet.c | 54 +++++++++++++++++++++------------------------- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/configure.ac b/configure.ac index 3defe293..66d64c87 100644 --- a/configure.ac +++ b/configure.ac @@ -186,7 +186,7 @@ AC_ARG_ENABLE(libwacom, [use_libwacom="$enableval"], [use_libwacom="yes"]) if test "x$use_libwacom" = "xyes"; then - PKG_CHECK_MODULES(LIBWACOM, [libwacom], [HAVE_LIBWACOM="yes"]) + PKG_CHECK_MODULES(LIBWACOM, [libwacom >= 0.12], [HAVE_LIBWACOM="yes"]) AC_DEFINE(HAVE_LIBWACOM, 1, [Build with libwacom]) fi diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 093c79f6..3ddca742 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -599,6 +599,7 @@ tool_set_bits_from_libwacom(const struct tablet_dispatch *tablet, const WacomStylus *s = NULL; int code; WacomStylusType type; + WacomAxisTypeFlags axes; db = libwacom_database_new(); if (!db) { @@ -624,38 +625,33 @@ tool_set_bits_from_libwacom(const struct tablet_dispatch *tablet, copy_button_cap(tablet, tool, BTN_TOUCH); } - /* Eventually we want libwacom to tell us each axis on each device - separately. */ - switch(type) { - case WSTYLUS_AIRBRUSH: - copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_SLIDER); - /* fall-through */ - case WSTYLUS_MARKER: - if (type == WSTYLUS_MARKER) - copy_axis_cap(tablet, tool, - LIBINPUT_TABLET_AXIS_ROTATION_Z); - /* fallthrough */ - case WSTYLUS_GENERAL: - case WSTYLUS_INKING: - case WSTYLUS_CLASSIC: - case WSTYLUS_STROKE: - copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_PRESSURE); - copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_DISTANCE); - copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_TILT_X); - copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_TILT_Y); - break; - case WSTYLUS_PUCK: - copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_ROTATION_Z); - copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_DISTANCE); - /* lens cursors don't have a wheel */ - if (!libwacom_stylus_has_lens(s)) + 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_REL_WHEEL); - break; - default: - break; + 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: From b45fe45b1c9df7c3cb8f59030e39dfeb4f0bdfd3 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 10 Mar 2015 14:14:20 +1000 Subject: [PATCH 137/255] tablet: use libwacom_new_from_path() to handle more tablets Some tablets cannot be differentiated by pid/vid alone, use the device path instead - that gives libwacom the ability to extract the information required to handle the device (libwacom doesn't open the path, it just reads through the sysfs entry of the device). Signed-off-by: Peter Hutterer Reviewed-by: Benjamin Tissoires --- src/evdev-tablet.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 3ddca742..2904fbbc 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -1069,10 +1069,7 @@ tablet_init_left_handed(struct evdev_device *device) WacomDeviceDatabase *db; WacomDevice *d = NULL; WacomError *error; - int vid, pid; - - vid = evdev_device_get_id_vendor(device); - pid = evdev_device_get_id_product(device); + const char *devnode; db = libwacom_database_new(); if (!db) { @@ -1081,7 +1078,12 @@ tablet_init_left_handed(struct evdev_device *device) return; } error = libwacom_error_new(); - d = libwacom_new_from_usbid(db, vid, pid, error); + 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)) From e14d1a08a49667c1bfe04f45946fb77040b02e12 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 9 Jul 2015 14:11:17 +1000 Subject: [PATCH 138/255] doc: improve the tablet documentation Signed-off-by: Peter Hutterer --- src/libinput.h | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/src/libinput.h b/src/libinput.h index bb24c959..9a377f8b 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -155,15 +155,20 @@ enum libinput_tablet_axis { /** * @ingroup device * - * An object representing a tool being used by the device. It must have the @ref + * 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. It must have the @ref + * 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, @@ -196,6 +201,14 @@ enum libinput_tool_type { * * 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, @@ -248,6 +261,12 @@ 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 @@ -257,9 +276,9 @@ enum libinput_event_type { * 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 with - * state @ref LIBINPUT_TOOL_PROXIMITY_IN are sent only once after @ref - * LIBINPUT_EVENT_DEVICE_ADDED, and likewise events with state @ref + * 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. * @@ -268,10 +287,10 @@ enum libinput_event_type { * event. * * When a tool goes out of proximity, the value of every axis should be - * assumed to have a value of 0 and any buttons that are currently held + * 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 - * initial proximity out event. + * proximity out event. */ LIBINPUT_EVENT_TABLET_PROXIMITY, LIBINPUT_EVENT_TABLET_BUTTON, @@ -1292,7 +1311,7 @@ libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, * 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. + * 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 @@ -1316,6 +1335,10 @@ libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, * 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 From d195a96212bd292cb49007c282f1b3ca5b96215f Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 9 Jul 2015 14:17:56 +1000 Subject: [PATCH 139/255] doc: drop a confusing note This note doesn't add anything, the delta to the last changed is the same as the delta to the last event, otherwise it'd be 0. Signed-off-by: Peter Hutterer --- src/libinput.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/libinput.h b/src/libinput.h index 9a377f8b..9c2f5062 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1358,10 +1358,6 @@ libinput_event_tablet_get_axis_value(struct libinput_event_tablet *event, * For all other axes, see libinput_event_tablet_get_axis_value() for * details. * - * @note The delta is *not* the delta to the previous event, but the delta - * to the previous axis state, i.e. the delta to the last event that - * libinput_event_tablet_axis_has_changed() returned true for this axis. - * * @param event The libinput tablet event * @param axis The axis to retrieve the value of * @return The delta to the previous axis value @@ -1379,10 +1375,6 @@ libinput_event_tablet_get_axis_delta(struct libinput_event_tablet *event, * of physical mouse wheel clicks. * For all other axes, this function returns 0. * - * @note The delta is *not* the delta to the previous event, but the delta - * to the previous axis state, i.e. the delta to the last event that - * libinput_event_tablet_axis_has_changed() returned true for this axis. - * * @param event The libinput tablet event * @param axis The axis to retrieve the value of * @return The delta to the previous axis value in discrete steps From bfce05db05265a7ebac5d050a8ff1beb7e81543d Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 9 Jul 2015 15:46:20 +1000 Subject: [PATCH 140/255] test: add test for partial tablet deltas Signed-off-by: Peter Hutterer --- test/tablet.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/test/tablet.c b/test/tablet.c index 59e6c7ca..dac15069 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -446,6 +446,55 @@ START_TEST(motion_delta) } 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 @@ -1683,6 +1732,7 @@ litest_setup_tests(void) 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); From dc334a13c9910273a1d63911bdbe8c1db661dc7b Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 14 Jul 2015 13:13:34 +1000 Subject: [PATCH 141/255] test: fix compiler warning about tablet test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit test.h:421:49: warning: ‘last_y’ may be used uninitialized in this function [-Wmaybe-uninitialized] Cannot actually happen, if we don't get into the while loop where we initialize it, we would assert. Signed-off-by: Peter Hutterer --- test/tablet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tablet.c b/test/tablet.c index dac15069..3de28b34 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -503,7 +503,7 @@ START_TEST(left_handed) struct libinput_event *event; struct libinput_event_tablet *tablet_event; double libinput_max_x, libinput_max_y; - double last_x, last_y; + double last_x = -1.0, last_y = -1.0; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { -1, -1 } From e32d94dc1b423493ff4207603adab9ecd3b886b1 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 14 Jul 2015 14:36:51 +1000 Subject: [PATCH 142/255] test: add test for udev ID_INPUT_TABLET tagging We rely on libwacom for some of these tags, make sure it works as expected. Signed-off-by: Peter Hutterer --- test/device.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/device.c b/test/device.c index f2651366..58bf9b7c 100644 --- a/test/device.c +++ b/test/device.c @@ -1008,6 +1008,23 @@ START_TEST(device_udev_tag_apple) udev_device_unref(d); } 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 + void litest_setup_tests(void) { @@ -1054,4 +1071,5 @@ litest_setup_tests(void) 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_wacom_tablet, LITEST_TABLET, LITEST_ANY); } From 1b952ee87d9ac92b986ffd98e50fcc390ea3a7e6 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 4 Aug 2015 12:37:40 +1000 Subject: [PATCH 143/255] tablet: add get_time_usec() for tablets, switch to usec Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 16 ++++++++-------- src/libinput-private.h | 6 +++--- src/libinput.c | 14 ++++++++++---- src/libinput.h | 9 +++++++++ src/libinput.sym | 1 + 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 2904fbbc..851d49da 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -107,7 +107,7 @@ static void tablet_process_absolute(struct tablet_dispatch *tablet, struct evdev_device *device, struct input_event *e, - uint32_t time) + uint64_t time) { enum libinput_tablet_axis axis; @@ -316,7 +316,7 @@ get_delta(enum libinput_tablet_axis axis, double current, double old) static void tablet_check_notify_axes(struct tablet_dispatch *tablet, struct evdev_device *device, - uint32_t time, + uint64_t time, struct libinput_tool *tool) { struct libinput_device *base = &device->base; @@ -478,7 +478,7 @@ static void tablet_process_key(struct tablet_dispatch *tablet, struct evdev_device *device, struct input_event *e, - uint32_t time) + uint64_t time) { switch (e->code) { case BTN_TOOL_PEN: @@ -521,7 +521,7 @@ static void tablet_process_relative(struct tablet_dispatch *tablet, struct evdev_device *device, struct input_event *e, - uint32_t time) + uint64_t time) { enum libinput_tablet_axis axis; @@ -551,7 +551,7 @@ static void tablet_process_misc(struct tablet_dispatch *tablet, struct evdev_device *device, struct input_event *e, - uint32_t time) + uint64_t time) { switch (e->code) { case MSC_SERIAL: @@ -779,7 +779,7 @@ tablet_get_tool(struct tablet_dispatch *tablet, static void tablet_notify_button_mask(struct tablet_dispatch *tablet, struct evdev_device *device, - uint32_t time, + uint64_t time, struct libinput_tool *tool, const unsigned char *buttons, unsigned int buttons_len, @@ -805,7 +805,7 @@ tablet_notify_button_mask(struct tablet_dispatch *tablet, static void tablet_notify_buttons(struct tablet_dispatch *tablet, struct evdev_device *device, - uint32_t time, + uint64_t time, struct libinput_tool *tool, enum libinput_button_state state) { @@ -864,7 +864,7 @@ sanitize_tablet_axes(struct tablet_dispatch *tablet) static void tablet_flush(struct tablet_dispatch *tablet, struct evdev_device *device, - uint32_t time) + uint64_t time) { struct libinput_tool *tool = tablet_get_tool(tablet, diff --git a/src/libinput-private.h b/src/libinput-private.h index 69ed26e3..d9ba7d29 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -432,7 +432,7 @@ touch_notify_frame(struct libinput_device *device, void tablet_notify_axis(struct libinput_device *device, - uint32_t time, + uint64_t time, struct libinput_tool *tool, unsigned char *changed_axes, double *axes, @@ -441,7 +441,7 @@ tablet_notify_axis(struct libinput_device *device, void tablet_notify_proximity(struct libinput_device *device, - uint32_t time, + uint64_t time, struct libinput_tool *tool, enum libinput_tool_proximity_state state, unsigned char *changed_axes, @@ -449,7 +449,7 @@ tablet_notify_proximity(struct libinput_device *device, void tablet_notify_button(struct libinput_device *device, - uint32_t time, + uint64_t time, struct libinput_tool *tool, double *axes, int32_t button, diff --git a/src/libinput.c b/src/libinput.c index 3557b8fd..46578fe9 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -130,7 +130,7 @@ struct libinput_event_tablet { uint32_t button; enum libinput_button_state state; uint32_t seat_button_count; - uint32_t time; + 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]; @@ -1021,6 +1021,12 @@ libinput_event_tablet_get_proximity_state(struct libinput_event_tablet *event) 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; } @@ -1841,7 +1847,7 @@ touch_notify_frame(struct libinput_device *device, void tablet_notify_axis(struct libinput_device *device, - uint32_t time, + uint64_t time, struct libinput_tool *tool, unsigned char *changed_axes, double *axes, @@ -1876,7 +1882,7 @@ tablet_notify_axis(struct libinput_device *device, void tablet_notify_proximity(struct libinput_device *device, - uint32_t time, + uint64_t time, struct libinput_tool *tool, enum libinput_tool_proximity_state proximity_state, unsigned char *changed_axes, @@ -1910,7 +1916,7 @@ tablet_notify_proximity(struct libinput_device *device, void tablet_notify_button(struct libinput_device *device, - uint32_t time, + uint64_t time, struct libinput_tool *tool, double *axes, int32_t button, diff --git a/src/libinput.h b/src/libinput.h index 212ee351..d9834557 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1541,6 +1541,15 @@ libinput_event_tablet_get_seat_button_count(struct libinput_event_tablet *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 * diff --git a/src/libinput.sym b/src/libinput.sym index 15295474..84800241 100644 --- a/src/libinput.sym +++ b/src/libinput.sym @@ -191,6 +191,7 @@ LIBINPUT_TABLET_SUPPORT { 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; From 4968053025316520875f3395c037866c84144e21 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 12 Aug 2015 15:50:38 +1000 Subject: [PATCH 144/255] test: add test for the tablet usec API Signed-off-by: Peter Hutterer --- test/tablet.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/tablet.c b/test/tablet.c index 3de28b34..d82c650c 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -1715,6 +1715,33 @@ START_TEST(artpen_rotation) } 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) { @@ -1746,4 +1773,6 @@ litest_setup_tests(void) 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); } From 4edcd79372a46b49374f88db236b23872ea9363a Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 5 Nov 2015 13:16:58 +1000 Subject: [PATCH 145/255] tablet: widen the serial type to uint64_t Internally we still use uint32_t because that's all we get from evdev. But eventually we'll have 64 bit serials. Signed-off-by: Peter Hutterer Reviewed-by: Jason Gerecke --- src/libinput.c | 2 +- src/libinput.h | 2 +- tools/event-debug.c | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libinput.c b/src/libinput.c index a51e76a9..65dd0d93 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1089,7 +1089,7 @@ libinput_tool_get_tool_id(struct libinput_tool *tool) return tool->tool_id; } -LIBINPUT_EXPORT uint32_t +LIBINPUT_EXPORT uint64_t libinput_tool_get_serial(struct libinput_tool *tool) { return tool->serial; diff --git a/src/libinput.h b/src/libinput.h index 45a64377..3b797a43 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1648,7 +1648,7 @@ libinput_tool_unref(struct libinput_tool *tool); * @param tool The libinput tool * @return The new tool serial triggering this event */ -uint32_t +uint64_t libinput_tool_get_serial(struct libinput_tool *tool); /** diff --git a/tools/event-debug.c b/tools/event-debug.c index 3e315beb..29c0e56a 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -23,6 +23,7 @@ #define _GNU_SOURCE #include +#include #include #include #include @@ -489,7 +490,7 @@ print_proximity_event(struct libinput_event *ev) abort(); } - printf("\t%s (%#x) %s", + printf("\t%s (%#" PRIx64 ") %s", tool_str, libinput_tool_get_serial(tool), state_str); printf("\taxes:"); From 19812f599e989cba444a3d34d5d3118f829140ac Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 5 Nov 2015 14:33:58 +1000 Subject: [PATCH 146/255] tablet: use require_event_type instead of direct type check Signed-off-by: Peter Hutterer Reviewed-by: Jason Gerecke --- src/libinput.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/libinput.c b/src/libinput.c index 65dd0d93..c1f27006 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -925,9 +925,11 @@ libinput_event_tablet_get_axis_value(struct libinput_event_tablet *event, 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; + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_AXIS, + LIBINPUT_EVENT_TABLET_PROXIMITY); switch(axis) { case LIBINPUT_TABLET_AXIS_X: @@ -956,9 +958,11 @@ libinput_event_tablet_get_axis_delta(struct libinput_event_tablet *event, 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; + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_AXIS, + LIBINPUT_EVENT_TABLET_PROXIMITY); switch(axis) { case LIBINPUT_TABLET_AXIS_X: @@ -985,9 +989,11 @@ 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; + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_AXIS, + LIBINPUT_EVENT_TABLET_PROXIMITY); switch(axis) { case LIBINPUT_TABLET_AXIS_X: @@ -1012,8 +1018,10 @@ libinput_event_tablet_get_x_transformed(struct libinput_event_tablet *event, struct evdev_device *device = (struct evdev_device *) event->base.device; - if (event->base.type != LIBINPUT_EVENT_TABLET_AXIS) - return 0; + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_AXIS); return evdev_device_transform_x(device, event->axes[LIBINPUT_TABLET_AXIS_X], @@ -1027,8 +1035,10 @@ libinput_event_tablet_get_y_transformed(struct libinput_event_tablet *event, struct evdev_device *device = (struct evdev_device *) event->base.device; - if (event->base.type != LIBINPUT_EVENT_TABLET_AXIS) - return 0; + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_AXIS); return evdev_device_transform_y(device, event->axes[LIBINPUT_TABLET_AXIS_Y], From 548ad08909a6ef69241c93b6a76707dba20403e2 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 5 Nov 2015 14:35:00 +1000 Subject: [PATCH 147/255] tablet: restrict tablet_axis_has_changed to axis/proximity events Signed-off-by: Peter Hutterer Reviewed-by: Jason Gerecke --- src/libinput.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libinput.c b/src/libinput.c index c1f27006..e384d8df 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -914,6 +914,12 @@ LIBINPUT_EXPORT int libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, enum libinput_tablet_axis axis) { + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_AXIS, + LIBINPUT_EVENT_TABLET_PROXIMITY); + return (NCHARS(axis) <= sizeof(event->changed_axes)) ? bit_is_set(event->changed_axes, axis) : 0; } From 4ae64a3436669f5524ef1f92698a9bd2e060fc0c Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 5 Nov 2015 14:35:52 +1000 Subject: [PATCH 148/255] tablet: allow tablet_get_x/y_transformed for proximity events as well Signed-off-by: Peter Hutterer Reviewed-by: Jason Gerecke --- src/libinput.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libinput.c b/src/libinput.c index e384d8df..a05148f5 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1027,7 +1027,8 @@ libinput_event_tablet_get_x_transformed(struct libinput_event_tablet *event, require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, - LIBINPUT_EVENT_TABLET_AXIS); + LIBINPUT_EVENT_TABLET_AXIS, + LIBINPUT_EVENT_TABLET_PROXIMITY); return evdev_device_transform_x(device, event->axes[LIBINPUT_TABLET_AXIS_X], @@ -1044,7 +1045,8 @@ libinput_event_tablet_get_y_transformed(struct libinput_event_tablet *event, require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, - LIBINPUT_EVENT_TABLET_AXIS); + LIBINPUT_EVENT_TABLET_AXIS, + LIBINPUT_EVENT_TABLET_PROXIMITY); return evdev_device_transform_y(device, event->axes[LIBINPUT_TABLET_AXIS_Y], From 9d07f8af40e2229dfff2caa562b374a99f06fb75 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 5 Nov 2015 14:37:29 +1000 Subject: [PATCH 149/255] tools: add tablet support to event-gui Signed-off-by: Peter Hutterer Reviewed-by: Jason Gerecke --- tools/event-gui.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/tools/event-gui.c b/tools/event-gui.c index 19324a3d..c07213f9 100644 --- a/tools/event-gui.c +++ b/tools/event-gui.c @@ -85,6 +85,14 @@ struct window { double x, y; } pinch; + struct { + double x, y; + double x_in, y_in; + double pressure; + double distance; + double tilt_x, tilt_y; + } tool; + struct libinput_device *devices[50]; }; @@ -216,6 +224,27 @@ draw(GtkWidget *widget, cairo_t *cr, gpointer data) cairo_stroke(cr); cairo_restore(cr); + /* tablet tool, square for prox-in location */ + cairo_save(cr); + cairo_set_source_rgb(cr, .8, .8, .8); + if (w->tool.x_in && w->tool.y_in) { + cairo_rectangle(cr, w->tool.x_in - 15, w->tool.y_in - 15, 30, 30); + cairo_stroke(cr); + cairo_restore(cr); + cairo_save(cr); + } + + if (w->tool.pressure) + cairo_set_source_rgb(cr, .8, .8, .2); + + cairo_translate(cr, w->tool.x, w->tool.y); + cairo_scale(cr, 1.0 + w->tool.tilt_x, 1.0 + w->tool.tilt_y); + cairo_arc(cr, 0, 0, + 1 + 10 * max(w->tool.pressure, w->tool.distance), + 0, 2 * M_PI); + cairo_fill(cr); + cairo_restore(cr); + return TRUE; } @@ -551,6 +580,45 @@ handle_event_pinch(struct libinput_event *ev, struct window *w) } } +static void +handle_event_tablet(struct libinput_event *ev, struct window *w) +{ + struct libinput_event_tablet *t = libinput_event_get_tablet_event(ev); + + switch (libinput_event_get_type(ev)) { + case LIBINPUT_EVENT_TABLET_PROXIMITY: + if (libinput_event_tablet_get_proximity_state(t) == + LIBINPUT_TOOL_PROXIMITY_OUT) { + w->tool.x_in = 0; + w->tool.y_in = 0; + } else { + w->tool.x_in = libinput_event_tablet_get_x_transformed(t, + w->width); + w->tool.y_in = libinput_event_tablet_get_y_transformed(t, + w->height); + } + break; + case LIBINPUT_EVENT_TABLET_AXIS: + w->tool.x = libinput_event_tablet_get_x_transformed(t, + w->width); + w->tool.y = libinput_event_tablet_get_y_transformed(t, + w->height); + w->tool.pressure = libinput_event_tablet_get_axis_value(t, + LIBINPUT_TABLET_AXIS_PRESSURE); + w->tool.distance = libinput_event_tablet_get_axis_value(t, + LIBINPUT_TABLET_AXIS_DISTANCE); + w->tool.tilt_x = libinput_event_tablet_get_axis_value(t, + LIBINPUT_TABLET_AXIS_TILT_X); + w->tool.tilt_y = libinput_event_tablet_get_axis_value(t, + LIBINPUT_TABLET_AXIS_TILT_Y); + break; + case LIBINPUT_EVENT_TABLET_BUTTON: + break; + default: + abort(); + } +} + static gboolean handle_event_libinput(GIOChannel *source, GIOCondition condition, gpointer data) { @@ -609,6 +677,7 @@ handle_event_libinput(GIOChannel *source, GIOCondition condition, gpointer data) case LIBINPUT_EVENT_TABLET_AXIS: case LIBINPUT_EVENT_TABLET_PROXIMITY: case LIBINPUT_EVENT_TABLET_BUTTON: + handle_event_tablet(ev, w); break; } From 87926e4ab6885aefd9e029df1c5fa0a6c33e29f2 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 6 Nov 2015 14:50:34 +1000 Subject: [PATCH 150/255] tablet: rename all tool types to LIBINPUT_TOOL_TYPE_* Signed-off-by: Peter Hutterer Reviewed-by: Jason Gerecke --- src/evdev-tablet.c | 54 ++++++++++++++++++++++----------------------- src/evdev-tablet.h | 18 +++++++-------- src/libinput.h | 29 ++++++++++++------------ test/tablet.c | 8 +++---- tools/event-debug.c | 16 +++++++------- 5 files changed, 63 insertions(+), 62 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 851d49da..04cd0829 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -341,8 +341,8 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, /* 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)) { + (tablet->current_tool_type == LIBINPUT_TOOL_TYPE_MOUSE || + tablet->current_tool_type == LIBINPUT_TOOL_TYPE_LENS)) { convert_tilt_to_rotation(tablet); axes[LIBINPUT_TABLET_AXIS_TILT_X] = 0; axes[LIBINPUT_TABLET_AXIS_TILT_Y] = 0; @@ -459,14 +459,14 @@ 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; + case BTN_TOOL_PEN: type = LIBINPUT_TOOL_TYPE_PEN; break; + case BTN_TOOL_RUBBER: type = LIBINPUT_TOOL_TYPE_ERASER; break; + case BTN_TOOL_BRUSH: type = LIBINPUT_TOOL_TYPE_BRUSH; break; + case BTN_TOOL_PENCIL: type = LIBINPUT_TOOL_TYPE_PENCIL; break; + case BTN_TOOL_AIRBRUSH: type = LIBINPUT_TOOL_TYPE_AIRBRUSH; break; + case BTN_TOOL_FINGER: type = LIBINPUT_TOOL_TYPE_FINGER; break; + case BTN_TOOL_MOUSE: type = LIBINPUT_TOOL_TYPE_MOUSE; break; + case BTN_TOOL_LENS: type = LIBINPUT_TOOL_TYPE_LENS; break; default: abort(); } @@ -676,11 +676,11 @@ tool_set_bits(const struct tablet_dispatch *tablet, anyway. */ switch (type) { - case LIBINPUT_TOOL_PEN: - case LIBINPUT_TOOL_ERASER: - case LIBINPUT_TOOL_PENCIL: - case LIBINPUT_TOOL_BRUSH: - case LIBINPUT_TOOL_AIRBRUSH: + case LIBINPUT_TOOL_TYPE_PEN: + case LIBINPUT_TOOL_TYPE_ERASER: + case LIBINPUT_TOOL_TYPE_PENCIL: + case LIBINPUT_TOOL_TYPE_BRUSH: + case LIBINPUT_TOOL_TYPE_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); @@ -688,8 +688,8 @@ tool_set_bits(const struct tablet_dispatch *tablet, 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: + case LIBINPUT_TOOL_TYPE_MOUSE: + case LIBINPUT_TOOL_TYPE_LENS: copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_ROTATION_Z); copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_REL_WHEEL); break; @@ -700,17 +700,17 @@ tool_set_bits(const struct tablet_dispatch *tablet, /* 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: + case LIBINPUT_TOOL_TYPE_PEN: + case LIBINPUT_TOOL_TYPE_BRUSH: + case LIBINPUT_TOOL_TYPE_AIRBRUSH: + case LIBINPUT_TOOL_TYPE_PENCIL: + case LIBINPUT_TOOL_TYPE_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: + case LIBINPUT_TOOL_TYPE_MOUSE: + case LIBINPUT_TOOL_TYPE_LENS: copy_button_cap(tablet, tool, BTN_LEFT); copy_button_cap(tablet, tool, BTN_MIDDLE); copy_button_cap(tablet, tool, BTN_RIGHT); @@ -854,8 +854,8 @@ sanitize_tablet_axes(struct tablet_dispatch *tablet) /* 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) && + if ((tablet->current_tool_type == LIBINPUT_TOOL_TYPE_MOUSE || + tablet->current_tool_type == LIBINPUT_TOOL_TYPE_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); @@ -991,7 +991,7 @@ tablet_check_initial_proximity(struct evdev_device *device, enum libinput_tool_type tool; struct tablet_dispatch *tablet = (struct tablet_dispatch*)dispatch; - for (tool = LIBINPUT_TOOL_PEN; tool <= LIBINPUT_TOOL_MAX; tool++) { + for (tool = LIBINPUT_TOOL_TYPE_PEN; tool <= LIBINPUT_TOOL_TYPE_MAX; tool++) { code = tablet_tool_to_evcode(tool); /* we only expect one tool to be in proximity at a time */ diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index 2ba08fae..6b801420 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -28,7 +28,7 @@ #define LIBINPUT_TABLET_AXIS_NONE 0 #define LIBINPUT_TOOL_NONE 0 -#define LIBINPUT_TOOL_MAX LIBINPUT_TOOL_LENS +#define LIBINPUT_TOOL_TYPE_MAX LIBINPUT_TOOL_TYPE_LENS enum tablet_status { TABLET_NONE = 0, @@ -163,14 +163,14 @@ 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; + case LIBINPUT_TOOL_TYPE_PEN: code = BTN_TOOL_PEN; break; + case LIBINPUT_TOOL_TYPE_ERASER: code = BTN_TOOL_RUBBER; break; + case LIBINPUT_TOOL_TYPE_BRUSH: code = BTN_TOOL_BRUSH; break; + case LIBINPUT_TOOL_TYPE_PENCIL: code = BTN_TOOL_PENCIL; break; + case LIBINPUT_TOOL_TYPE_AIRBRUSH: code = BTN_TOOL_AIRBRUSH; break; + case LIBINPUT_TOOL_TYPE_FINGER: code = BTN_TOOL_FINGER; break; + case LIBINPUT_TOOL_TYPE_MOUSE: code = BTN_TOOL_MOUSE; break; + case LIBINPUT_TOOL_TYPE_LENS: code = BTN_TOOL_LENS; break; default: abort(); } diff --git a/src/libinput.h b/src/libinput.h index 3b797a43..3962b9d6 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -172,7 +172,8 @@ struct libinput_tool; * 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. + * Wacom Pro Pen and a Wacom Grip Pen are all of type @ref + * LIBINPUT_TOOL_TYPE_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 @@ -182,18 +183,18 @@ struct libinput_tool; * @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. + * classic pen leaves the tool type as @ref LIBINPUT_TOOL_TYPE_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. + LIBINPUT_TOOL_TYPE_PEN = 1, /**< A generic pen */ + LIBINPUT_TOOL_TYPE_ERASER, /**< Eraser */ + LIBINPUT_TOOL_TYPE_BRUSH, /**< A paintbrush-like tool */ + LIBINPUT_TOOL_TYPE_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 */ + LIBINPUT_TOOL_TYPE_AIRBRUSH, /**< An airbrush-like tool */ + LIBINPUT_TOOL_TYPE_FINGER, /**< Touch */ + LIBINPUT_TOOL_TYPE_MOUSE, /**< A mouse bound to the tablet */ + LIBINPUT_TOOL_TYPE_LENS, /**< A mouse tool with a lens */ }; /** @@ -1357,10 +1358,10 @@ libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, * 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_TOOL_TYPE_MOUSE and @ref LIBINPUT_TOOL_TYPE_LENS tools + * the logical neutral position is pointing to the current logical north + * of the tablet. For the @ref LIBINPUT_TOOL_TYPE_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, diff --git a/test/tablet.c b/test/tablet.c index d82c650c..8048c707 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -62,7 +62,7 @@ START_TEST(proximity_in_out) 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_TOOL_TYPE_PEN); } libinput_event_destroy(event); } @@ -1289,7 +1289,7 @@ START_TEST(mouse_tool) tool = libinput_event_tablet_get_tool(tev); ck_assert_notnull(tool); ck_assert_int_eq(libinput_tool_get_type(tool), - LIBINPUT_TOOL_MOUSE); + LIBINPUT_TOOL_TYPE_MOUSE); libinput_event_destroy(event); } @@ -1558,7 +1558,7 @@ START_TEST(airbrush_tool) tool = libinput_event_tablet_get_tool(tev); ck_assert_notnull(tool); ck_assert_int_eq(libinput_tool_get_type(tool), - LIBINPUT_TOOL_AIRBRUSH); + LIBINPUT_TOOL_TYPE_AIRBRUSH); libinput_event_destroy(event); } @@ -1645,7 +1645,7 @@ START_TEST(artpen_tool) tool = libinput_event_tablet_get_tool(tev); ck_assert_notnull(tool); ck_assert_int_eq(libinput_tool_get_type(tool), - LIBINPUT_TOOL_PEN); + LIBINPUT_TOOL_TYPE_PEN); ck_assert(libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_ROTATION_Z)); diff --git a/tools/event-debug.c b/tools/event-debug.c index 29c0e56a..6e5f8a85 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -448,28 +448,28 @@ print_proximity_event(struct libinput_event *ev) *state_str; switch (libinput_tool_get_type(tool)) { - case LIBINPUT_TOOL_PEN: + case LIBINPUT_TOOL_TYPE_PEN: tool_str = "pen"; break; - case LIBINPUT_TOOL_ERASER: + case LIBINPUT_TOOL_TYPE_ERASER: tool_str = "eraser"; break; - case LIBINPUT_TOOL_BRUSH: + case LIBINPUT_TOOL_TYPE_BRUSH: tool_str = "brush"; break; - case LIBINPUT_TOOL_PENCIL: + case LIBINPUT_TOOL_TYPE_PENCIL: tool_str = "pencil"; break; - case LIBINPUT_TOOL_AIRBRUSH: + case LIBINPUT_TOOL_TYPE_AIRBRUSH: tool_str = "airbrush"; break; - case LIBINPUT_TOOL_FINGER: + case LIBINPUT_TOOL_TYPE_FINGER: tool_str = "finger"; break; - case LIBINPUT_TOOL_MOUSE: + case LIBINPUT_TOOL_TYPE_MOUSE: tool_str = "mouse"; break; - case LIBINPUT_TOOL_LENS: + case LIBINPUT_TOOL_TYPE_LENS: tool_str = "lens"; break; default: From 368ced1f2961b614190ad3a344fad7ad2e252439 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 9 Nov 2015 15:38:55 +1000 Subject: [PATCH 151/255] tablet: widen the tool id to 64 bits Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/libinput.c | 2 +- src/libinput.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libinput.c b/src/libinput.c index a05148f5..79e4863c 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1101,7 +1101,7 @@ libinput_tool_get_type(struct libinput_tool *tool) return tool->type; } -LIBINPUT_EXPORT uint32_t +LIBINPUT_EXPORT uint64_t libinput_tool_get_tool_id(struct libinput_tool *tool) { return tool->tool_id; diff --git a/src/libinput.h b/src/libinput.h index 3962b9d6..018dbd4a 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1583,7 +1583,7 @@ libinput_tool_get_type(struct libinput_tool *tool); * * @see libinput_tool_get_type */ -uint32_t +uint64_t libinput_tool_get_tool_id(struct libinput_tool *tool); /** From 4ca8f3b699bd81478632e75e855db672575c35f9 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 9 Nov 2015 15:39:20 +1000 Subject: [PATCH 152/255] tools: print the tool ID in event-debug Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- tools/event-debug.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/event-debug.c b/tools/event-debug.c index 6e5f8a85..05fb1a7f 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -490,8 +490,11 @@ print_proximity_event(struct libinput_event *ev) abort(); } - printf("\t%s (%#" PRIx64 ") %s", - tool_str, libinput_tool_get_serial(tool), state_str); + printf("\t%s (%#" PRIx64 ", id %#" PRIx64 ") %s", + tool_str, + libinput_tool_get_serial(tool), + libinput_tool_get_tool_id(tool), + state_str); printf("\taxes:"); if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_DISTANCE)) From f035def40147fbc952c864aabe5d0eb69707f60c Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 11 Nov 2015 14:05:18 +1000 Subject: [PATCH 153/255] test: add printing of tablet events to litest Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- test/litest.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/litest.c b/test/litest.c index d10175ff..ce2a6a7b 100644 --- a/test/litest.c +++ b/test/litest.c @@ -1898,6 +1898,7 @@ static void litest_print_event(struct libinput_event *event) { struct libinput_event_pointer *p; + struct libinput_event_tablet *t; struct libinput_device *dev; enum libinput_event_type type; double x, y; @@ -1943,6 +1944,17 @@ litest_print_event(struct libinput_event *event) LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL); fprintf(stderr, "vert %.f horiz %.2f", y, x); break; + case LIBINPUT_EVENT_TABLET_PROXIMITY: + t = libinput_event_get_tablet_event(event); + fprintf(stderr, "proximity %d\n", + libinput_event_tablet_get_proximity_state(t)); + break; + case LIBINPUT_EVENT_TABLET_BUTTON: + t = libinput_event_get_tablet_event(event); + fprintf(stderr, "button %d state %d\n", + libinput_event_tablet_get_button(t), + libinput_event_tablet_get_button_state(t)); + break; default: break; } From 480a72829ac8a863e0ee097e9bd1cde24ca4c958 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 11 Nov 2015 14:53:18 +1000 Subject: [PATCH 154/255] tablet: clarify tablet axis behavior in regards to proximity We send the axis state in the proximity event so we don't send another axis event for the same state. The first axis event is sent whenever the tool moves. This is largely of note for test cases, in real-world usage a tool cannot be held still enough to never send axis updates. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/libinput.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/libinput.h b/src/libinput.h index 018dbd4a..c5f9da7e 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -267,6 +267,13 @@ enum libinput_event_type { * LIBINPUT_DEVICE_CAP_TABLET capability. This event is only sent * when the tool is in proximity, see @ref * LIBINPUT_EVENT_TABLET_PROXIMITY for details. + * + * The proximity event contains the initial state of the axis as the + * tool comes into proximity. An event of type @ref + * LIBINPUT_EVENT_TABLET_AXIS is only sent when an axis value + * changes from this initial state. It is possible for a tool to + * enter and leave proximity without sending an event of type @ref + * LIBINPUT_EVENT_TABLET_AXIS. */ LIBINPUT_EVENT_TABLET_AXIS = 600, /** From 003e9b14d742fb6abab6dba8defe7b04bcb14627 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 11 Nov 2015 13:44:02 +1000 Subject: [PATCH 155/255] tablet: rename STYLUS_IN_CONTACT to TOOL_IN_CONTACT Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 6 +++--- src/evdev-tablet.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 04cd0829..72ec31d6 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -496,9 +496,9 @@ tablet_process_key(struct tablet_dispatch *tablet, break; case BTN_TOUCH: if (e->value) - tablet_set_status(tablet, TABLET_STYLUS_IN_CONTACT); + tablet_set_status(tablet, TABLET_TOOL_IN_CONTACT); else - tablet_unset_status(tablet, TABLET_STYLUS_IN_CONTACT); + tablet_unset_status(tablet, TABLET_TOOL_IN_CONTACT); /* Fall through */ case BTN_LEFT: @@ -843,7 +843,7 @@ sanitize_tablet_axes(struct tablet_dispatch *tablet) 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)) { + !tablet_has_status(tablet, TABLET_TOOL_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, diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index 6b801420..64e16c76 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -35,7 +35,7 @@ enum tablet_status { TABLET_AXES_UPDATED = 1 << 0, TABLET_BUTTONS_PRESSED = 1 << 1, TABLET_BUTTONS_RELEASED = 1 << 2, - TABLET_STYLUS_IN_CONTACT = 1 << 3, + TABLET_TOOL_IN_CONTACT = 1 << 3, TABLET_TOOL_LEAVING_PROXIMITY = 1 << 4, TABLET_TOOL_OUT_OF_PROXIMITY = 1 << 5, TABLET_TOOL_ENTERING_PROXIMITY = 1 << 6 From 30dbd6718ac28a950f5fd66c3bbbf81fac814c8d Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 11 Nov 2015 16:05:41 +1000 Subject: [PATCH 156/255] test: ensure proximity out coordinates are the ones from the last axis event Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- test/tablet.c | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/test/tablet.c b/test/tablet.c index 8048c707..5dcb9d30 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -167,6 +167,8 @@ START_TEST(proximity_has_axes) struct libinput_tool *tool; double x, y, distance; + double last_x, last_y, last_distance, + last_tx, last_ty; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, @@ -233,6 +235,35 @@ START_TEST(proximity_has_axes) litest_assert_empty_queue(li); libinput_event_destroy(event); + axes[0].value = 20; + axes[1].value = 15; + axes[2].value = 25; + litest_tablet_motion(dev, 20, 30, axes); + libinput_dispatch(li); + 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); + + 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); + if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_DISTANCE)) + last_distance = libinput_event_tablet_get_axis_value( + tablet_event, + LIBINPUT_TABLET_AXIS_DISTANCE); + if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_TILT_X) && + libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_TILT_Y)) { + last_tx = libinput_event_tablet_get_axis_value( + tablet_event, + LIBINPUT_TABLET_AXIS_TILT_X); + last_ty = libinput_event_tablet_get_axis_value( + tablet_event, + LIBINPUT_TABLET_AXIS_TILT_Y); + } + + libinput_event_destroy(event); + /* Make sure that the axes are still present on proximity out */ litest_tablet_proximity_out(dev); @@ -251,9 +282,8 @@ START_TEST(proximity_has_axes) 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); + litest_assert_double_eq(x, last_x); + litest_assert_double_eq(y, last_y); if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_DISTANCE)) { ck_assert(!libinput_event_tablet_axis_has_changed( @@ -263,7 +293,7 @@ START_TEST(proximity_has_axes) distance = libinput_event_tablet_get_axis_value( tablet_event, LIBINPUT_TABLET_AXIS_DISTANCE); - litest_assert_double_ne(distance, 0); + litest_assert_double_eq(distance, last_distance); } if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_TILT_X) && @@ -282,8 +312,8 @@ START_TEST(proximity_has_axes) tablet_event, LIBINPUT_TABLET_AXIS_TILT_Y); - litest_assert_double_ne(x, 0); - litest_assert_double_ne(y, 0); + litest_assert_double_eq(x, last_tx); + litest_assert_double_eq(y, last_ty); } litest_assert_empty_queue(li); From 1318ffadb527bdc9e924d4a67becb6a8aa5b1644 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 11 Nov 2015 13:39:43 +1000 Subject: [PATCH 157/255] tablet: split out tip handling into a separate event The tablet tip works like a button in the kernel but is otherwise not really a button. Split it into an explicit tip up/down event instead. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/libinput-private.h | 7 +++++++ src/libinput.c | 42 ++++++++++++++++++++++++++++++++++++++++++ src/libinput.h | 41 +++++++++++++++++++++++++++++++++++++++++ src/libinput.sym | 1 + test/litest.c | 8 ++++++++ test/tablet.c | 4 +++- tools/event-debug.c | 18 ++++++++++++++++++ tools/event-gui.c | 34 ++++++++++++++++++++++++++++++++++ 8 files changed, 154 insertions(+), 1 deletion(-) diff --git a/src/libinput-private.h b/src/libinput-private.h index 3d612221..0e7ddff3 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -476,6 +476,13 @@ tablet_notify_proximity(struct libinput_device *device, unsigned char *changed_axes, double *axes); +void +tablet_notify_tip(struct libinput_device *device, + uint64_t time, + struct libinput_tool *tool, + enum libinput_tool_tip_state tip_state, + double *axes); + void tablet_notify_button(struct libinput_device *device, uint64_t time, diff --git a/src/libinput.c b/src/libinput.c index 79e4863c..c47f9fcb 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -137,6 +137,7 @@ struct libinput_event_tablet { unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_AXIS_MAX + 1)]; struct libinput_tool *tool; enum libinput_tool_proximity_state proximity_state; + enum libinput_tool_tip_state tip_state; }; static void @@ -313,6 +314,7 @@ libinput_event_get_tablet_event(struct libinput_event *event) NULL, LIBINPUT_EVENT_TABLET_AXIS, LIBINPUT_EVENT_TABLET_PROXIMITY, + LIBINPUT_EVENT_TABLET_TIP, LIBINPUT_EVENT_TABLET_BUTTON); return (struct libinput_event_tablet *) event; @@ -918,6 +920,7 @@ libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, event->base.type, 0, LIBINPUT_EVENT_TABLET_AXIS, + LIBINPUT_EVENT_TABLET_TIP, LIBINPUT_EVENT_TABLET_PROXIMITY); return (NCHARS(axis) <= sizeof(event->changed_axes)) ? @@ -935,6 +938,7 @@ libinput_event_tablet_get_axis_value(struct libinput_event_tablet *event, event->base.type, 0, LIBINPUT_EVENT_TABLET_AXIS, + LIBINPUT_EVENT_TABLET_TIP, LIBINPUT_EVENT_TABLET_PROXIMITY); switch(axis) { @@ -968,6 +972,7 @@ libinput_event_tablet_get_axis_delta(struct libinput_event_tablet *event, event->base.type, 0, LIBINPUT_EVENT_TABLET_AXIS, + LIBINPUT_EVENT_TABLET_TIP, LIBINPUT_EVENT_TABLET_PROXIMITY); switch(axis) { @@ -999,6 +1004,7 @@ libinput_event_tablet_get_axis_delta_discrete( event->base.type, 0, LIBINPUT_EVENT_TABLET_AXIS, + LIBINPUT_EVENT_TABLET_TIP, LIBINPUT_EVENT_TABLET_PROXIMITY); switch(axis) { @@ -1028,6 +1034,7 @@ libinput_event_tablet_get_x_transformed(struct libinput_event_tablet *event, event->base.type, 0, LIBINPUT_EVENT_TABLET_AXIS, + LIBINPUT_EVENT_TABLET_TIP, LIBINPUT_EVENT_TABLET_PROXIMITY); return evdev_device_transform_x(device, @@ -1046,6 +1053,7 @@ libinput_event_tablet_get_y_transformed(struct libinput_event_tablet *event, event->base.type, 0, LIBINPUT_EVENT_TABLET_AXIS, + LIBINPUT_EVENT_TABLET_TIP, LIBINPUT_EVENT_TABLET_PROXIMITY); return evdev_device_transform_y(device, @@ -1065,6 +1073,12 @@ libinput_event_tablet_get_proximity_state(struct libinput_event_tablet *event) return event->proximity_state; } +LIBINPUT_EXPORT enum libinput_tool_tip_state +libinput_event_tablet_get_tip_state(struct libinput_event_tablet *event) +{ + return event->tip_state; +} + LIBINPUT_EXPORT uint32_t libinput_event_tablet_get_time(struct libinput_event_tablet *event) { @@ -1969,6 +1983,34 @@ tablet_notify_proximity(struct libinput_device *device, &proximity_event->base); } +void +tablet_notify_tip(struct libinput_device *device, + uint64_t time, + struct libinput_tool *tool, + enum libinput_tool_tip_state tip_state, + double *axes) +{ + struct libinput_event_tablet *tip_event; + + tip_event = zalloc(sizeof *tip_event); + if (!tip_event) + return; + + *tip_event = (struct libinput_event_tablet) { + .time = time, + .tool = tool, + .tip_state = tip_state, + }; + memcpy(tip_event->axes, + axes, + sizeof(tip_event->axes)); + + post_device_event(device, + time, + LIBINPUT_EVENT_TABLET_TIP, + &tip_event->base); +} + void tablet_notify_button(struct libinput_device *device, uint64_t time, diff --git a/src/libinput.h b/src/libinput.h index c5f9da7e..dc7e7d85 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -216,6 +216,20 @@ enum libinput_tool_proximity_state { LIBINPUT_TOOL_PROXIMITY_IN = 1, }; +/** + * @ingroup device + * + * The tip contact state for a tool on a device. The device must have + * the @ref LIBINPUT_DEVICE_CAP_TABLET capability. + * + * The tip contact state of a tool is a binary state signalling whether the tool is + * touching the surface of the tablet device. + */ +enum libinput_tool_tip_state { + LIBINPUT_TOOL_TIP_UP = 0, + LIBINPUT_TOOL_TIP_DOWN = 1, +}; + /** * @ingroup base * @@ -301,6 +315,19 @@ enum libinput_event_type { * proximity out event. */ LIBINPUT_EVENT_TABLET_PROXIMITY, + /** + * Signals that a tool has come in contact with the surface of a + * device with the @ref LIBINPUT_DEVICE_CAP_TABLET capability. + * + * On devices without distance proximity detection, the @ref + * LIBINPUT_EVENT_TABLET_TIP is sent immediately after @ref + * LIBINPUT_EVENT_TABLET_PROXIMITY for the tip down event, and + * immediately before for the tip up event. + * + * If a button and/or axis state change occurs at the same time as a + * tip state change, the order of events is device-dependent. + */ + LIBINPUT_EVENT_TABLET_TIP, LIBINPUT_EVENT_TABLET_BUTTON, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN = 800, @@ -1499,6 +1526,20 @@ libinput_event_tablet_get_tool(struct libinput_event_tablet *event); enum libinput_tool_proximity_state libinput_event_tablet_get_proximity_state(struct libinput_event_tablet *event); +/** + * @ingroup event_tablet + * + * Returns the new tip state of a tool from a tip event. + * Used to check whether or not a tool came in contact with the tablet + * surface or left contact with the tablet surface during an + * event of type @ref LIBINPUT_EVENT_TABLET_TIP. + * + * @param event The libinput tablet event + * @return The new tip state of the tool from the event. + */ +enum libinput_tool_tip_state +libinput_event_tablet_get_tip_state(struct libinput_event_tablet *event); + /** * @ingroup event_tablet * diff --git a/src/libinput.sym b/src/libinput.sym index 1c297c7f..33d5b33f 100644 --- a/src/libinput.sym +++ b/src/libinput.sym @@ -195,6 +195,7 @@ LIBINPUT_TABLET_SUPPORT { libinput_event_tablet_get_proximity_state; libinput_event_tablet_get_seat_button_count; libinput_event_tablet_get_time; + libinput_event_tablet_get_tip_state; libinput_event_tablet_get_tool; libinput_event_tablet_get_x_transformed; libinput_event_tablet_get_y_transformed; diff --git a/test/litest.c b/test/litest.c index ce2a6a7b..4bbabb20 100644 --- a/test/litest.c +++ b/test/litest.c @@ -1887,6 +1887,9 @@ litest_event_type_str(struct libinput_event *event) case LIBINPUT_EVENT_TABLET_PROXIMITY: str = "TABLET PROX"; break; + case LIBINPUT_EVENT_TABLET_TIP: + str = "TABLET TIP"; + break; case LIBINPUT_EVENT_TABLET_BUTTON: str = "TABLET BUTTON"; break; @@ -1949,6 +1952,11 @@ litest_print_event(struct libinput_event *event) fprintf(stderr, "proximity %d\n", libinput_event_tablet_get_proximity_state(t)); break; + case LIBINPUT_EVENT_TABLET_TIP: + t = libinput_event_get_tablet_event(event); + fprintf(stderr, "tip %d\n", + libinput_event_tablet_get_tip_state(t)); + break; case LIBINPUT_EVENT_TABLET_BUTTON: t = libinput_event_get_tablet_event(event); fprintf(stderr, "button %d state %d\n", diff --git a/test/tablet.c b/test/tablet.c index 5dcb9d30..444290c2 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -118,7 +118,7 @@ START_TEST(proximity_out_clear_buttons) /* Test that proximity out events send button releases for any currently * pressed stylus buttons */ - for (button = BTN_TOUCH; button <= BTN_STYLUS2; button++) { + for (button = BTN_TOUCH + 1; button <= BTN_STYLUS2; button++) { bool button_released = false; uint32_t event_button; enum libinput_button_state state; @@ -155,6 +155,8 @@ START_TEST(proximity_out_clear_buttons) libevdev_event_code_get_name(EV_KEY, button), event_button); } + + litest_assert_empty_queue(li); } END_TEST diff --git a/tools/event-debug.c b/tools/event-debug.c index 05fb1a7f..f0ae1dc8 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -115,6 +115,9 @@ print_event_header(struct libinput_event *ev) case LIBINPUT_EVENT_TABLET_PROXIMITY: type = "TABLET_PROXIMITY"; break; + case LIBINPUT_EVENT_TABLET_TIP: + type = "TABLET_TIP"; + break; case LIBINPUT_EVENT_TABLET_BUTTON: type = "TABLET_BUTTON"; break; @@ -278,6 +281,18 @@ print_pointer_button_event(struct libinput_event *ev) libinput_event_pointer_get_seat_button_count(p)); } +static void +print_tablet_tip_event(struct libinput_event *ev) +{ + struct libinput_event_tablet *p = libinput_event_get_tablet_event(ev); + enum libinput_tool_tip_state state; + + print_event_time(libinput_event_tablet_get_time(p)); + + state = libinput_event_tablet_get_tip_state(p); + printf("%s\n", state == LIBINPUT_TOOL_TIP_DOWN ? "down" : "up"); +} + static void print_tablet_button_event(struct libinput_event *ev) { @@ -667,6 +682,9 @@ handle_and_print_events(struct libinput *li) case LIBINPUT_EVENT_TABLET_PROXIMITY: print_proximity_event(ev); break; + case LIBINPUT_EVENT_TABLET_TIP: + print_tablet_tip_event(ev); + break; case LIBINPUT_EVENT_TABLET_BUTTON: print_tablet_button_event(ev); break; diff --git a/tools/event-gui.c b/tools/event-gui.c index c07213f9..a7d8dd93 100644 --- a/tools/event-gui.c +++ b/tools/event-gui.c @@ -88,6 +88,8 @@ struct window { struct { double x, y; double x_in, y_in; + double x_down, y_down; + double x_up, y_up; double pressure; double distance; double tilt_x, tilt_y; @@ -234,6 +236,20 @@ draw(GtkWidget *widget, cairo_t *cr, gpointer data) cairo_save(cr); } + if (w->tool.x_down && w->tool.y_down) { + cairo_rectangle(cr, w->tool.x_down - 10, w->tool.y_down - 10, 20, 20); + cairo_stroke(cr); + cairo_restore(cr); + cairo_save(cr); + } + + if (w->tool.x_up && w->tool.y_up) { + cairo_rectangle(cr, w->tool.x_up - 10, w->tool.y_up - 10, 20, 20); + cairo_stroke(cr); + cairo_restore(cr); + cairo_save(cr); + } + if (w->tool.pressure) cairo_set_source_rgb(cr, .8, .8, .2); @@ -584,6 +600,7 @@ static void handle_event_tablet(struct libinput_event *ev, struct window *w) { struct libinput_event_tablet *t = libinput_event_get_tablet_event(ev); + double x, y; switch (libinput_event_get_type(ev)) { case LIBINPUT_EVENT_TABLET_PROXIMITY: @@ -591,6 +608,10 @@ handle_event_tablet(struct libinput_event *ev, struct window *w) LIBINPUT_TOOL_PROXIMITY_OUT) { w->tool.x_in = 0; w->tool.y_in = 0; + w->tool.x_down = 0; + w->tool.y_down = 0; + w->tool.x_up = 0; + w->tool.y_up = 0; } else { w->tool.x_in = libinput_event_tablet_get_x_transformed(t, w->width); @@ -612,6 +633,18 @@ handle_event_tablet(struct libinput_event *ev, struct window *w) w->tool.tilt_y = libinput_event_tablet_get_axis_value(t, LIBINPUT_TABLET_AXIS_TILT_Y); break; + case LIBINPUT_EVENT_TABLET_TIP: + x = libinput_event_tablet_get_x_transformed(t, w->width); + y = libinput_event_tablet_get_y_transformed(t, w->height); + if (libinput_event_tablet_get_tip_state(t) == + LIBINPUT_TOOL_TIP_DOWN) { + w->tool.x_down = x; + w->tool.y_down = y; + } else { + w->tool.x_up = x; + w->tool.y_up = y; + } + break; case LIBINPUT_EVENT_TABLET_BUTTON: break; default: @@ -676,6 +709,7 @@ handle_event_libinput(GIOChannel *source, GIOCondition condition, gpointer data) break; case LIBINPUT_EVENT_TABLET_AXIS: case LIBINPUT_EVENT_TABLET_PROXIMITY: + case LIBINPUT_EVENT_TABLET_TIP: case LIBINPUT_EVENT_TABLET_BUTTON: handle_event_tablet(ev, w); break; From 6f5d9902c8d96a2d79c87d32865186fdbc59a1e9 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 11 Nov 2015 14:03:05 +1000 Subject: [PATCH 158/255] tablet: hook up tip events Behavior for axis events in the same event frame as the BTN_TOUCH is to always send axis events before any tip state. Behavior for button events in the same event frame as the BTN_TOUCH is to order button events to happen when the tip is in proximity, i.e. after the tip event on tip down and before the tip event on tip up. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 37 ++++- src/evdev-tablet.h | 6 +- test/litest.c | 15 ++ test/litest.h | 3 + test/tablet.c | 371 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 422 insertions(+), 10 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 72ec31d6..476dee2b 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -425,6 +425,8 @@ tablet_update_button(struct tablet_dispatch *tablet, uint32_t enable) { switch (evcode) { + case BTN_TOUCH: + return; case BTN_LEFT: case BTN_RIGHT: case BTN_MIDDLE: @@ -433,7 +435,6 @@ tablet_update_button(struct tablet_dispatch *tablet, case BTN_FORWARD: case BTN_BACK: case BTN_TASK: - case BTN_TOUCH: case BTN_STYLUS: case BTN_STYLUS2: break; @@ -496,11 +497,10 @@ tablet_process_key(struct tablet_dispatch *tablet, break; case BTN_TOUCH: if (e->value) - tablet_set_status(tablet, TABLET_TOOL_IN_CONTACT); + tablet_set_status(tablet, TABLET_TOOL_ENTERING_CONTACT); else - tablet_unset_status(tablet, TABLET_TOOL_IN_CONTACT); - - /* Fall through */ + tablet_set_status(tablet, TABLET_TOOL_LEAVING_CONTACT); + break; case BTN_LEFT: case BTN_RIGHT: case BTN_MIDDLE: @@ -622,7 +622,6 @@ tool_set_bits_from_libwacom(const struct tablet_dispatch *tablet, 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)) @@ -707,7 +706,6 @@ tool_set_bits(const struct tablet_dispatch *tablet, case LIBINPUT_TOOL_TYPE_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_TYPE_MOUSE: case LIBINPUT_TOOL_TYPE_LENS: @@ -843,7 +841,8 @@ sanitize_tablet_axes(struct tablet_dispatch *tablet) 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_TOOL_IN_CONTACT)) { + (!tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT) && + !tablet_has_status(tablet, TABLET_TOOL_ENTERING_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, @@ -881,6 +880,8 @@ tablet_flush(struct tablet_dispatch *tablet, 0, sizeof(tablet->button_state.stylus_buttons)); tablet_set_status(tablet, TABLET_BUTTONS_RELEASED); + if (tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT)) + tablet_set_status(tablet, TABLET_TOOL_LEAVING_CONTACT); } else if (tablet_has_status(tablet, TABLET_AXES_UPDATED) || tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY)) { sanitize_tablet_axes(tablet); @@ -890,6 +891,16 @@ tablet_flush(struct tablet_dispatch *tablet, tablet_unset_status(tablet, TABLET_AXES_UPDATED); } + if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_CONTACT)) { + tablet_notify_tip(&device->base, + time, + tool, + LIBINPUT_TOOL_TIP_DOWN, + tablet->axes); + tablet_unset_status(tablet, TABLET_TOOL_ENTERING_CONTACT); + tablet_set_status(tablet, TABLET_TOOL_IN_CONTACT); + } + if (tablet_has_status(tablet, TABLET_BUTTONS_RELEASED)) { tablet_notify_buttons(tablet, device, @@ -908,6 +919,16 @@ tablet_flush(struct tablet_dispatch *tablet, tablet_unset_status(tablet, TABLET_BUTTONS_PRESSED); } + if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_CONTACT)) { + tablet_notify_tip(&device->base, + time, + tool, + LIBINPUT_TOOL_TIP_UP, + tablet->axes); + tablet_unset_status(tablet, TABLET_TOOL_LEAVING_CONTACT); + tablet_unset_status(tablet, TABLET_TOOL_IN_CONTACT); + } + if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) { memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes)); tablet_notify_proximity(&device->base, diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index 64e16c76..9901b2a1 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -38,7 +38,9 @@ enum tablet_status { TABLET_TOOL_IN_CONTACT = 1 << 3, TABLET_TOOL_LEAVING_PROXIMITY = 1 << 4, TABLET_TOOL_OUT_OF_PROXIMITY = 1 << 5, - TABLET_TOOL_ENTERING_PROXIMITY = 1 << 6 + TABLET_TOOL_ENTERING_PROXIMITY = 1 << 6, + TABLET_TOOL_ENTERING_CONTACT = 1 << 7, + TABLET_TOOL_LEAVING_CONTACT = 1 << 8, }; struct button_state { @@ -48,7 +50,7 @@ struct button_state { struct tablet_dispatch { struct evdev_dispatch base; struct evdev_device *device; - unsigned char status; + unsigned int 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]; diff --git a/test/litest.c b/test/litest.c index 4bbabb20..292cddba 100644 --- a/test/litest.c +++ b/test/litest.c @@ -2330,6 +2330,21 @@ litest_is_gesture_event(struct libinput_event *event, return gevent; } +struct libinput_event_tablet * litest_is_tablet_event( + struct libinput_event *event, + enum libinput_event_type type) +{ + struct libinput_event_tablet *tevent; + + litest_assert(event != NULL); + litest_assert_int_eq(libinput_event_get_type(event), type); + + tevent = libinput_event_get_tablet_event(event); + litest_assert(tevent != NULL); + + return tevent; +} + void litest_assert_tablet_button_event(struct libinput *li, unsigned int button, enum libinput_button_state state) diff --git a/test/litest.h b/test/litest.h index bf165f07..a7a447e4 100644 --- a/test/litest.h +++ b/test/litest.h @@ -402,6 +402,9 @@ struct libinput_event_gesture * litest_is_gesture_event( struct libinput_event *event, enum libinput_event_type type, int nfingers); +struct libinput_event_tablet * litest_is_tablet_event( + struct libinput_event *event, + enum libinput_event_type type); void litest_assert_button_event(struct libinput *li, unsigned int button, diff --git a/test/tablet.c b/test/tablet.c index 444290c2..a954e531 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -34,6 +34,370 @@ #include "evdev-tablet.h" #include "litest.h" +START_TEST(tip_down_up) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_tablet *tablet_event; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 10 }, + { -1, -1 } + }; + + litest_tablet_proximity_in(dev, 10, 10, axes); + litest_drain_events(li); + + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TIP); + ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + LIBINPUT_TOOL_TIP_DOWN); + libinput_event_destroy(event); + litest_assert_empty_queue(li); + + litest_event(dev, EV_KEY, BTN_TOUCH, 0); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TIP); + ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + LIBINPUT_TOOL_TIP_UP); + libinput_event_destroy(event); + litest_assert_empty_queue(li); + + litest_assert_empty_queue(li); + +} +END_TEST + +START_TEST(tip_down_prox_in) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_tablet *tablet_event; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 10 }, + { -1, -1 } + }; + + litest_drain_events(li); + + litest_push_event_frame(dev); + litest_tablet_proximity_in(dev, 10, 10, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_pop_event_frame(dev); + + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_PROXIMITY); + ck_assert_int_eq(libinput_event_tablet_get_proximity_state(tablet_event), + LIBINPUT_TOOL_PROXIMITY_IN); + libinput_event_destroy(event); + + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TIP); + ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + LIBINPUT_TOOL_TIP_DOWN); + libinput_event_destroy(event); + + litest_assert_empty_queue(li); + +} +END_TEST + +START_TEST(tip_up_prox_out) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_tablet *tablet_event; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 10 }, + { -1, -1 } + }; + + litest_tablet_proximity_in(dev, 10, 10, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_drain_events(li); + + litest_push_event_frame(dev); + litest_event(dev, EV_KEY, BTN_TOUCH, 0); + litest_tablet_proximity_out(dev); + litest_pop_event_frame(dev); + + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TIP); + ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + LIBINPUT_TOOL_TIP_UP); + libinput_event_destroy(event); + + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_PROXIMITY); + ck_assert_int_eq(libinput_event_tablet_get_proximity_state(tablet_event), + LIBINPUT_TOOL_PROXIMITY_OUT); + libinput_event_destroy(event); + + litest_assert_empty_queue(li); + +} +END_TEST + +START_TEST(tip_up_btn_change) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_tablet *tablet_event; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 10 }, + { -1, -1 } + }; + + litest_tablet_proximity_in(dev, 10, 10, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_drain_events(li); + + litest_event(dev, EV_KEY, BTN_STYLUS, 1); + litest_event(dev, EV_KEY, BTN_TOUCH, 0); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_BUTTON); + ck_assert_int_eq(libinput_event_tablet_get_button(tablet_event), + BTN_STYLUS); + ck_assert_int_eq(libinput_event_tablet_get_button_state(tablet_event), + LIBINPUT_BUTTON_STATE_PRESSED); + libinput_event_destroy(event); + + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TIP); + ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + LIBINPUT_TOOL_TIP_UP); + libinput_event_destroy(event); + + litest_assert_empty_queue(li); + + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_drain_events(li); + + /* same thing with a release at tip-up */ + litest_event(dev, EV_KEY, BTN_TOUCH, 0); + litest_event(dev, EV_KEY, BTN_STYLUS, 0); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_BUTTON); + ck_assert_int_eq(libinput_event_tablet_get_button(tablet_event), + BTN_STYLUS); + ck_assert_int_eq(libinput_event_tablet_get_button_state(tablet_event), + LIBINPUT_BUTTON_STATE_RELEASED); + libinput_event_destroy(event); + + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TIP); + ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + LIBINPUT_TOOL_TIP_UP); + libinput_event_destroy(event); + + litest_assert_empty_queue(li); +} +END_TEST + +START_TEST(tip_down_btn_change) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_tablet *tablet_event; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 10 }, + { -1, -1 } + }; + + litest_tablet_proximity_in(dev, 10, 10, axes); + litest_drain_events(li); + + litest_event(dev, EV_KEY, BTN_STYLUS, 1); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TIP); + ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + LIBINPUT_TOOL_TIP_DOWN); + libinput_event_destroy(event); + + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_BUTTON); + ck_assert_int_eq(libinput_event_tablet_get_button(tablet_event), + BTN_STYLUS); + ck_assert_int_eq(libinput_event_tablet_get_button_state(tablet_event), + LIBINPUT_BUTTON_STATE_PRESSED); + libinput_event_destroy(event); + + litest_assert_empty_queue(li); + + litest_event(dev, EV_KEY, BTN_TOUCH, 0); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_drain_events(li); + + /* same thing with a release at tip-down */ + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_event(dev, EV_KEY, BTN_STYLUS, 0); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TIP); + ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + LIBINPUT_TOOL_TIP_DOWN); + libinput_event_destroy(event); + + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_BUTTON); + ck_assert_int_eq(libinput_event_tablet_get_button(tablet_event), + BTN_STYLUS); + ck_assert_int_eq(libinput_event_tablet_get_button_state(tablet_event), + LIBINPUT_BUTTON_STATE_RELEASED); + libinput_event_destroy(event); + + litest_assert_empty_queue(li); +} +END_TEST + +START_TEST(tip_down_motion) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_tablet *tablet_event; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 10 }, + { -1, -1 } + }; + double x, y, last_x, last_y; + + litest_tablet_proximity_in(dev, 10, 10, axes); + litest_drain_events(li); + + litest_push_event_frame(dev); + litest_tablet_motion(dev, 70, 70, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_pop_event_frame(dev); + + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_AXIS); + 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); + libinput_event_destroy(event); + + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TIP); + ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + LIBINPUT_TOOL_TIP_DOWN); + 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_double_eq(last_x, x); + ck_assert_double_eq(last_y, y); + libinput_event_destroy(event); + + litest_assert_empty_queue(li); +} +END_TEST + +START_TEST(tip_up_motion) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_tablet *tablet_event; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 10 }, + { -1, -1 } + }; + double x, y, last_x, last_y; + + litest_tablet_proximity_in(dev, 10, 10, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_drain_events(li); + + litest_push_event_frame(dev); + litest_tablet_motion(dev, 70, 70, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 0); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_pop_event_frame(dev); + + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_AXIS); + 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); + libinput_event_destroy(event); + + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TIP); + ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + LIBINPUT_TOOL_TIP_UP); + 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_double_eq(last_x, x); + ck_assert_double_eq(last_y, y); + libinput_event_destroy(event); + + litest_assert_empty_queue(li); +} +END_TEST + START_TEST(proximity_in_out) { struct litest_device *dev = litest_current_device(); @@ -1789,6 +2153,13 @@ litest_setup_tests(void) 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:tip", tip_down_up, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:tip", tip_down_prox_in, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:tip", tip_up_prox_out, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:tip", tip_down_btn_change, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:tip", tip_up_btn_change, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:tip", tip_down_motion, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:tip", tip_up_motion, LITEST_TABLET, 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); From 01dd021b20964f5128fcbc87951e6ad6926face2 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 12 Nov 2015 08:32:34 +1000 Subject: [PATCH 159/255] test: use the li variable where we have it No functional changes Signed-off-by: Peter Hutterer --- test/tablet.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/tablet.c b/test/tablet.c index a954e531..1f3c9471 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -412,7 +412,7 @@ START_TEST(proximity_in_out) { -1, -1 } }; - litest_drain_events(dev->libinput); + litest_drain_events(li); litest_tablet_proximity_in(dev, 10, 10, axes); libinput_dispatch(li); @@ -477,7 +477,7 @@ START_TEST(proximity_out_clear_buttons) { -1, -1 } }; - litest_drain_events(dev->libinput); + litest_drain_events(li); /* Test that proximity out events send button releases for any currently * pressed stylus buttons @@ -543,7 +543,7 @@ START_TEST(proximity_has_axes) { -1, -1} }; - litest_drain_events(dev->libinput); + litest_drain_events(li); litest_tablet_proximity_in(dev, 10, 10, axes); @@ -1107,7 +1107,7 @@ START_TEST(bad_distance_events) litest_tablet_proximity_in(dev, 10, 10, axes); litest_tablet_proximity_out(dev); - litest_drain_events(dev->libinput); + litest_drain_events(li); absinfo = libevdev_get_abs_info(dev->evdev, ABS_DISTANCE); ck_assert(absinfo != NULL); @@ -1134,7 +1134,7 @@ START_TEST(normalization) *tilt_vertical_absinfo, *tilt_horizontal_absinfo; - litest_drain_events(dev->libinput); + litest_drain_events(li); pressure_absinfo = libevdev_get_abs_info(dev->evdev, ABS_PRESSURE); tilt_vertical_absinfo = libevdev_get_abs_info(dev->evdev, ABS_TILT_X); From 117161dc728f9eb06a81388bf383a9b8ffcecd82 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 12 Nov 2015 07:29:51 +1000 Subject: [PATCH 160/255] tablet: add missing event type checks for tablet events Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/libinput.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/libinput.c b/src/libinput.c index c47f9fcb..ed9490f6 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1064,48 +1064,97 @@ libinput_event_tablet_get_y_transformed(struct libinput_event_tablet *event, LIBINPUT_EXPORT struct libinput_tool * libinput_event_tablet_get_tool(struct libinput_event_tablet *event) { + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_AXIS, + LIBINPUT_EVENT_TABLET_TIP, + LIBINPUT_EVENT_TABLET_BUTTON, + LIBINPUT_EVENT_TABLET_PROXIMITY); + return event->tool; } LIBINPUT_EXPORT enum libinput_tool_proximity_state libinput_event_tablet_get_proximity_state(struct libinput_event_tablet *event) { + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_PROXIMITY); + return event->proximity_state; } LIBINPUT_EXPORT enum libinput_tool_tip_state libinput_event_tablet_get_tip_state(struct libinput_event_tablet *event) { + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_TIP); + return event->tip_state; } LIBINPUT_EXPORT uint32_t libinput_event_tablet_get_time(struct libinput_event_tablet *event) { + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_AXIS, + LIBINPUT_EVENT_TABLET_TIP, + LIBINPUT_EVENT_TABLET_BUTTON, + LIBINPUT_EVENT_TABLET_PROXIMITY); + return us2ms(event->time); } LIBINPUT_EXPORT uint64_t libinput_event_tablet_get_time_usec(struct libinput_event_tablet *event) { + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_AXIS, + LIBINPUT_EVENT_TABLET_TIP, + LIBINPUT_EVENT_TABLET_BUTTON, + LIBINPUT_EVENT_TABLET_PROXIMITY); + return event->time; } LIBINPUT_EXPORT uint32_t libinput_event_tablet_get_button(struct libinput_event_tablet *event) { + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_BUTTON); + return event->button; } LIBINPUT_EXPORT enum libinput_button_state libinput_event_tablet_get_button_state(struct libinput_event_tablet *event) { + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_BUTTON); + return event->state; } LIBINPUT_EXPORT uint32_t libinput_event_tablet_get_seat_button_count(struct libinput_event_tablet *event) { + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_BUTTON); + return event->seat_button_count; } From 5f928dfeac25472bc4160eda4dc5e0103a14ad1e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 12 Nov 2015 07:32:34 +1000 Subject: [PATCH 161/255] tablet: allow checking for proximity state on all tablet events By definition, the state is always proximity in on other events but let's allow the call to be made anyway. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/libinput.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libinput.c b/src/libinput.c index ed9490f6..a2a98cc6 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1081,6 +1081,9 @@ libinput_event_tablet_get_proximity_state(struct libinput_event_tablet *event) require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, + LIBINPUT_EVENT_TABLET_AXIS, + LIBINPUT_EVENT_TABLET_TIP, + LIBINPUT_EVENT_TABLET_BUTTON, LIBINPUT_EVENT_TABLET_PROXIMITY); return event->proximity_state; @@ -1981,6 +1984,7 @@ tablet_notify_axis(struct libinput_device *device, *axis_event = (struct libinput_event_tablet) { .time = time, .tool = tool, + .proximity_state = LIBINPUT_TOOL_PROXIMITY_IN, }; memcpy(axis_event->changed_axes, @@ -2049,6 +2053,7 @@ tablet_notify_tip(struct libinput_device *device, .time = time, .tool = tool, .tip_state = tip_state, + .proximity_state = LIBINPUT_TOOL_PROXIMITY_IN, }; memcpy(tip_event->axes, axes, @@ -2085,6 +2090,7 @@ tablet_notify_button(struct libinput_device *device, .button = button, .state = state, .seat_button_count = seat_button_count, + .proximity_state = LIBINPUT_TOOL_PROXIMITY_IN, }; memcpy(button_event->axes, axes, sizeof(button_event->axes)); From 7835e7460498d57ea7cab13089fa3b939d474428 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 12 Nov 2015 08:01:43 +1000 Subject: [PATCH 162/255] tablet: allow fetching the tip state from any tablet event Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 13 +++- src/libinput-private.h | 2 + src/libinput.c | 9 ++- test/tablet.c | 170 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 192 insertions(+), 2 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 476dee2b..ed64d552 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -406,14 +406,20 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, LIBINPUT_TOOL_PROXIMITY_IN, tablet->changed_axes, axes); - else + else { + enum libinput_tool_tip_state tip_state; + + tip_state = tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT) ? + LIBINPUT_TOOL_TIP_DOWN : LIBINPUT_TOOL_TIP_UP; tablet_notify_axis(base, time, tool, + tip_state, tablet->changed_axes, axes, deltas, deltas_discrete); + } } memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes)); @@ -786,6 +792,10 @@ tablet_notify_button_mask(struct tablet_dispatch *tablet, struct libinput_device *base = &device->base; size_t i; size_t nbits = 8 * sizeof(buttons[0]) * buttons_len; + enum libinput_tool_tip_state tip_state; + + tip_state = tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT) ? + LIBINPUT_TOOL_TIP_DOWN : LIBINPUT_TOOL_TIP_UP; for (i = 0; i < nbits; i++) { if (!bit_is_set(buttons, i)) @@ -794,6 +804,7 @@ tablet_notify_button_mask(struct tablet_dispatch *tablet, tablet_notify_button(base, time, tool, + tip_state, tablet->axes, i, state); diff --git a/src/libinput-private.h b/src/libinput-private.h index 0e7ddff3..702bf6e8 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -463,6 +463,7 @@ void tablet_notify_axis(struct libinput_device *device, uint64_t time, struct libinput_tool *tool, + enum libinput_tool_tip_state tip_state, unsigned char *changed_axes, double *axes, double *deltas, @@ -487,6 +488,7 @@ void tablet_notify_button(struct libinput_device *device, uint64_t time, struct libinput_tool *tool, + enum libinput_tool_tip_state tip_state, double *axes, int32_t button, enum libinput_button_state state); diff --git a/src/libinput.c b/src/libinput.c index a2a98cc6..479418e2 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1095,7 +1095,10 @@ libinput_event_tablet_get_tip_state(struct libinput_event_tablet *event) require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, - LIBINPUT_EVENT_TABLET_TIP); + LIBINPUT_EVENT_TABLET_AXIS, + LIBINPUT_EVENT_TABLET_TIP, + LIBINPUT_EVENT_TABLET_BUTTON, + LIBINPUT_EVENT_TABLET_PROXIMITY); return event->tip_state; } @@ -1970,6 +1973,7 @@ void tablet_notify_axis(struct libinput_device *device, uint64_t time, struct libinput_tool *tool, + enum libinput_tool_tip_state tip_state, unsigned char *changed_axes, double *axes, double *deltas, @@ -1985,6 +1989,7 @@ tablet_notify_axis(struct libinput_device *device, .time = time, .tool = tool, .proximity_state = LIBINPUT_TOOL_PROXIMITY_IN, + .tip_state = tip_state, }; memcpy(axis_event->changed_axes, @@ -2069,6 +2074,7 @@ void tablet_notify_button(struct libinput_device *device, uint64_t time, struct libinput_tool *tool, + enum libinput_tool_tip_state tip_state, double *axes, int32_t button, enum libinput_button_state state) @@ -2091,6 +2097,7 @@ tablet_notify_button(struct libinput_device *device, .state = state, .seat_button_count = seat_button_count, .proximity_state = LIBINPUT_TOOL_PROXIMITY_IN, + .tip_state = tip_state, }; memcpy(button_event->axes, axes, sizeof(button_event->axes)); diff --git a/test/tablet.c b/test/tablet.c index 1f3c9471..1bd3f13c 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -398,6 +398,173 @@ START_TEST(tip_up_motion) } END_TEST +START_TEST(tip_state_proximity) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_tablet *tablet_event; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 10 }, + { -1, -1 } + }; + + litest_drain_events(li); + + litest_tablet_proximity_in(dev, 10, 10, axes); + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_PROXIMITY); + ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + LIBINPUT_TOOL_TIP_UP); + libinput_event_destroy(event); + + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_event(dev, EV_KEY, BTN_TOUCH, 0); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_drain_events(li); + + litest_tablet_proximity_out(dev); + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_PROXIMITY); + ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + LIBINPUT_TOOL_TIP_UP); + libinput_event_destroy(event); +} +END_TEST + +START_TEST(tip_state_axis) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_tablet *tablet_event; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 10 }, + { -1, -1 } + }; + + litest_tablet_proximity_in(dev, 10, 10, axes); + litest_drain_events(li); + + litest_tablet_motion(dev, 70, 70, axes); + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_AXIS); + ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + LIBINPUT_TOOL_TIP_UP); + libinput_event_destroy(event); + + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_drain_events(li); + + litest_tablet_motion(dev, 30, 30, axes); + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_AXIS); + ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + LIBINPUT_TOOL_TIP_DOWN); + libinput_event_destroy(event); + + litest_event(dev, EV_KEY, BTN_TOUCH, 0); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_drain_events(li); + + litest_tablet_motion(dev, 40, 80, axes); + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_AXIS); + ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + LIBINPUT_TOOL_TIP_UP); + libinput_event_destroy(event); + + litest_assert_empty_queue(li); +} +END_TEST + +START_TEST(tip_state_button) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_tablet *tablet_event; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 10 }, + { -1, -1 } + }; + + litest_tablet_proximity_in(dev, 10, 10, axes); + litest_drain_events(li); + + litest_event(dev, EV_KEY, BTN_STYLUS, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_BUTTON); + ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + LIBINPUT_TOOL_TIP_UP); + libinput_event_destroy(event); + + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_drain_events(li); + + litest_event(dev, EV_KEY, BTN_STYLUS, 0); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_BUTTON); + ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + LIBINPUT_TOOL_TIP_DOWN); + libinput_event_destroy(event); + + litest_event(dev, EV_KEY, BTN_TOUCH, 0); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_drain_events(li); + + litest_event(dev, EV_KEY, BTN_STYLUS, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_BUTTON); + ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + LIBINPUT_TOOL_TIP_UP); + libinput_event_destroy(event); + + litest_event(dev, EV_KEY, BTN_STYLUS, 0); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_BUTTON); + ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + LIBINPUT_TOOL_TIP_UP); + libinput_event_destroy(event); + + litest_assert_empty_queue(li); +} +END_TEST + START_TEST(proximity_in_out) { struct litest_device *dev = litest_current_device(); @@ -2160,6 +2327,9 @@ litest_setup_tests(void) litest_add("tablet:tip", tip_up_btn_change, LITEST_TABLET, LITEST_ANY); litest_add("tablet:tip", tip_down_motion, LITEST_TABLET, LITEST_ANY); litest_add("tablet:tip", tip_up_motion, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:tip", tip_state_proximity, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:tip", tip_state_axis, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:tip", tip_state_button, LITEST_TABLET, 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); From 98df9eb63f1af394de1c5af60ebe752ab6f01a14 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 16 Nov 2015 15:34:19 +1000 Subject: [PATCH 163/255] tablet: rename libinput_tool to libinput_tablet_tool Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 24 ++++++++++++------------ src/libinput-private.h | 10 +++++----- src/libinput.c | 36 ++++++++++++++++++------------------ src/libinput.h | 26 +++++++++++++------------- test/tablet.c | 28 ++++++++++++++-------------- tools/event-debug.c | 4 ++-- 6 files changed, 64 insertions(+), 64 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index ed64d552..7537e211 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -317,7 +317,7 @@ static void tablet_check_notify_axes(struct tablet_dispatch *tablet, struct evdev_device *device, uint64_t time, - struct libinput_tool *tool) + struct libinput_tablet_tool *tool) { struct libinput_device *base = &device->base; bool axis_update_needed = false; @@ -576,7 +576,7 @@ tablet_process_misc(struct tablet_dispatch *tablet, static inline void copy_axis_cap(const struct tablet_dispatch *tablet, - struct libinput_tool *tool, + struct libinput_tablet_tool *tool, enum libinput_tablet_axis axis) { if (bit_is_set(tablet->axis_caps, axis)) @@ -585,7 +585,7 @@ copy_axis_cap(const struct tablet_dispatch *tablet, static inline void copy_button_cap(const struct tablet_dispatch *tablet, - struct libinput_tool *tool, + struct libinput_tablet_tool *tool, uint32_t button) { struct libevdev *evdev = tablet->device->evdev; @@ -595,7 +595,7 @@ copy_button_cap(const struct tablet_dispatch *tablet, static inline int tool_set_bits_from_libwacom(const struct tablet_dispatch *tablet, - struct libinput_tool *tool) + struct libinput_tablet_tool *tool) { int rc = 1; @@ -668,7 +668,7 @@ out: static void tool_set_bits(const struct tablet_dispatch *tablet, - struct libinput_tool *tool) + struct libinput_tablet_tool *tool) { enum libinput_tool_type type = tool->type; @@ -726,13 +726,13 @@ tool_set_bits(const struct tablet_dispatch *tablet, } } -static struct libinput_tool * +static struct libinput_tablet_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 libinput_tablet_tool *tool = NULL, *t; struct list *tool_list; if (serial) { @@ -765,7 +765,7 @@ tablet_get_tool(struct tablet_dispatch *tablet, * add it */ if (!tool) { tool = zalloc(sizeof *tool); - *tool = (struct libinput_tool) { + *tool = (struct libinput_tablet_tool) { .type = type, .serial = serial, .tool_id = tool_id, @@ -784,7 +784,7 @@ static void tablet_notify_button_mask(struct tablet_dispatch *tablet, struct evdev_device *device, uint64_t time, - struct libinput_tool *tool, + struct libinput_tablet_tool *tool, const unsigned char *buttons, unsigned int buttons_len, enum libinput_button_state state) @@ -815,7 +815,7 @@ static void tablet_notify_buttons(struct tablet_dispatch *tablet, struct evdev_device *device, uint64_t time, - struct libinput_tool *tool, + struct libinput_tablet_tool *tool, enum libinput_button_state state) { unsigned char buttons[ARRAY_LENGTH(tablet->button_state.stylus_buttons)]; @@ -876,7 +876,7 @@ tablet_flush(struct tablet_dispatch *tablet, struct evdev_device *device, uint64_t time) { - struct libinput_tool *tool = + struct libinput_tablet_tool *tool = tablet_get_tool(tablet, tablet->current_tool_type, tablet->current_tool_id, @@ -1005,7 +1005,7 @@ tablet_destroy(struct evdev_dispatch *dispatch) { struct tablet_dispatch *tablet = (struct tablet_dispatch*)dispatch; - struct libinput_tool *tool, *tmp; + struct libinput_tablet_tool *tool, *tmp; list_for_each_safe(tool, tmp, &tablet->tool_list, link) { libinput_tool_unref(tool); diff --git a/src/libinput-private.h b/src/libinput-private.h index 702bf6e8..b28e0e1c 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -250,7 +250,7 @@ struct libinput_device { struct libinput_device_config config; }; -struct libinput_tool { +struct libinput_tablet_tool { struct list link; uint32_t serial; uint32_t tool_id; @@ -462,7 +462,7 @@ touch_notify_frame(struct libinput_device *device, void tablet_notify_axis(struct libinput_device *device, uint64_t time, - struct libinput_tool *tool, + struct libinput_tablet_tool *tool, enum libinput_tool_tip_state tip_state, unsigned char *changed_axes, double *axes, @@ -472,7 +472,7 @@ tablet_notify_axis(struct libinput_device *device, void tablet_notify_proximity(struct libinput_device *device, uint64_t time, - struct libinput_tool *tool, + struct libinput_tablet_tool *tool, enum libinput_tool_proximity_state state, unsigned char *changed_axes, double *axes); @@ -480,14 +480,14 @@ tablet_notify_proximity(struct libinput_device *device, void tablet_notify_tip(struct libinput_device *device, uint64_t time, - struct libinput_tool *tool, + struct libinput_tablet_tool *tool, enum libinput_tool_tip_state tip_state, double *axes); void tablet_notify_button(struct libinput_device *device, uint64_t time, - struct libinput_tool *tool, + struct libinput_tablet_tool *tool, enum libinput_tool_tip_state tip_state, double *axes, int32_t button, diff --git a/src/libinput.c b/src/libinput.c index 479418e2..b50f5334 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -135,7 +135,7 @@ struct libinput_event_tablet { 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; + struct libinput_tablet_tool *tool; enum libinput_tool_proximity_state proximity_state; enum libinput_tool_tip_state tip_state; }; @@ -1061,7 +1061,7 @@ libinput_event_tablet_get_y_transformed(struct libinput_event_tablet *event, height); } -LIBINPUT_EXPORT struct libinput_tool * +LIBINPUT_EXPORT struct libinput_tablet_tool * libinput_event_tablet_get_tool(struct libinput_event_tablet *event) { require_event_type(libinput_event_get_context(&event->base), @@ -1165,32 +1165,32 @@ libinput_event_tablet_get_seat_button_count(struct libinput_event_tablet *event) } LIBINPUT_EXPORT enum libinput_tool_type -libinput_tool_get_type(struct libinput_tool *tool) +libinput_tool_get_type(struct libinput_tablet_tool *tool) { return tool->type; } LIBINPUT_EXPORT uint64_t -libinput_tool_get_tool_id(struct libinput_tool *tool) +libinput_tool_get_tool_id(struct libinput_tablet_tool *tool) { return tool->tool_id; } LIBINPUT_EXPORT uint64_t -libinput_tool_get_serial(struct libinput_tool *tool) +libinput_tool_get_serial(struct libinput_tablet_tool *tool) { return tool->serial; } LIBINPUT_EXPORT int -libinput_tool_has_axis(struct libinput_tool *tool, +libinput_tool_has_axis(struct libinput_tablet_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, +libinput_tool_has_button(struct libinput_tablet_tool *tool, uint32_t code) { if (NCHARS(code) > sizeof(tool->buttons)) @@ -1200,27 +1200,27 @@ libinput_tool_has_button(struct libinput_tool *tool, } LIBINPUT_EXPORT void -libinput_tool_set_user_data(struct libinput_tool *tool, +libinput_tool_set_user_data(struct libinput_tablet_tool *tool, void *user_data) { tool->user_data = user_data; } LIBINPUT_EXPORT void * -libinput_tool_get_user_data(struct libinput_tool *tool) +libinput_tool_get_user_data(struct libinput_tablet_tool *tool) { return tool->user_data; } -LIBINPUT_EXPORT struct libinput_tool * -libinput_tool_ref(struct libinput_tool *tool) +LIBINPUT_EXPORT struct libinput_tablet_tool * +libinput_tool_ref(struct libinput_tablet_tool *tool) { tool->refcount++; return tool; } -LIBINPUT_EXPORT struct libinput_tool * -libinput_tool_unref(struct libinput_tool *tool) +LIBINPUT_EXPORT struct libinput_tablet_tool * +libinput_tool_unref(struct libinput_tablet_tool *tool) { assert(tool->refcount > 0); @@ -1337,7 +1337,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_tablet_tool *tool, *next_tool; struct libinput_device_group *group, *next_group; if (libinput == NULL) @@ -1972,7 +1972,7 @@ touch_notify_frame(struct libinput_device *device, void tablet_notify_axis(struct libinput_device *device, uint64_t time, - struct libinput_tool *tool, + struct libinput_tablet_tool *tool, enum libinput_tool_tip_state tip_state, unsigned char *changed_axes, double *axes, @@ -2010,7 +2010,7 @@ tablet_notify_axis(struct libinput_device *device, void tablet_notify_proximity(struct libinput_device *device, uint64_t time, - struct libinput_tool *tool, + struct libinput_tablet_tool *tool, enum libinput_tool_proximity_state proximity_state, unsigned char *changed_axes, double *axes) @@ -2044,7 +2044,7 @@ tablet_notify_proximity(struct libinput_device *device, void tablet_notify_tip(struct libinput_device *device, uint64_t time, - struct libinput_tool *tool, + struct libinput_tablet_tool *tool, enum libinput_tool_tip_state tip_state, double *axes) { @@ -2073,7 +2073,7 @@ tablet_notify_tip(struct libinput_device *device, void tablet_notify_button(struct libinput_device *device, uint64_t time, - struct libinput_tool *tool, + struct libinput_tablet_tool *tool, enum libinput_tool_tip_state tip_state, double *axes, int32_t button, diff --git a/src/libinput.h b/src/libinput.h index dc7e7d85..bda1f9d5 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -163,7 +163,7 @@ enum libinput_tablet_axis { * is possible to track the same physical tool across multiple * struct libinput_device devices. */ -struct libinput_tool; +struct libinput_tablet_tool; /** * @ingroup device @@ -1508,7 +1508,7 @@ libinput_event_tablet_get_y_transformed(struct libinput_event_tablet *event, * @param event The libinput tablet event * @return The new tool triggering this event */ -struct libinput_tool * +struct libinput_tablet_tool * libinput_event_tablet_get_tool(struct libinput_event_tablet *event); /** @@ -1614,7 +1614,7 @@ libinput_event_tablet_get_time_usec(struct libinput_event_tablet *event); * @see libinput_tool_get_tool_id */ enum libinput_tool_type -libinput_tool_get_type(struct libinput_tool *tool); +libinput_tool_get_type(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet @@ -1632,7 +1632,7 @@ libinput_tool_get_type(struct libinput_tool *tool); * @see libinput_tool_get_type */ uint64_t -libinput_tool_get_tool_id(struct libinput_tool *tool); +libinput_tool_get_tool_id(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet @@ -1642,8 +1642,8 @@ libinput_tool_get_tool_id(struct libinput_tool *tool); * @param tool The tool to increment the ref count of * @return The passed tool */ -struct libinput_tool * -libinput_tool_ref(struct libinput_tool *tool); +struct libinput_tablet_tool * +libinput_tool_ref(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet @@ -1655,7 +1655,7 @@ libinput_tool_ref(struct libinput_tool *tool); * @return Whether or not the axis is supported */ int -libinput_tool_has_axis(struct libinput_tool *tool, +libinput_tool_has_axis(struct libinput_tablet_tool *tool, enum libinput_tablet_axis axis); /** @@ -1670,7 +1670,7 @@ libinput_tool_has_axis(struct libinput_tool *tool, * @return 1 if the tool supports this button code, 0 if it does not */ int -libinput_tool_has_button(struct libinput_tool *tool, +libinput_tool_has_button(struct libinput_tablet_tool *tool, uint32_t code); /** @@ -1682,8 +1682,8 @@ libinput_tool_has_button(struct libinput_tool *tool, * @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); +struct libinput_tablet_tool * +libinput_tool_unref(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet @@ -1698,7 +1698,7 @@ libinput_tool_unref(struct libinput_tool *tool); * @return The new tool serial triggering this event */ uint64_t -libinput_tool_get_serial(struct libinput_tool *tool); +libinput_tool_get_serial(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet @@ -1709,7 +1709,7 @@ libinput_tool_get_serial(struct libinput_tool *tool); * @return The user data associated with the tool object */ void * -libinput_tool_get_user_data(struct libinput_tool *tool); +libinput_tool_get_user_data(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet @@ -1720,7 +1720,7 @@ libinput_tool_get_user_data(struct libinput_tool *tool); * @param user_data The user data to associate with the tool object */ void -libinput_tool_set_user_data(struct libinput_tool *tool, +libinput_tool_set_user_data(struct libinput_tablet_tool *tool, void *user_data); /** diff --git a/test/tablet.c b/test/tablet.c index 1bd3f13c..b7ccdab3 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -587,7 +587,7 @@ START_TEST(proximity_in_out) while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == LIBINPUT_EVENT_TABLET_PROXIMITY) { - struct libinput_tool * tool; + struct libinput_tablet_tool * tool; have_tool_update++; tablet_event = libinput_event_get_tablet_event(event); @@ -697,7 +697,7 @@ START_TEST(proximity_has_axes) struct libinput *li = dev->libinput; struct libinput_event_tablet *tablet_event; struct libinput_event *event; - struct libinput_tool *tool; + struct libinput_tablet_tool *tool; double x, y, distance; double last_x, last_y, last_distance, @@ -1440,7 +1440,7 @@ START_TEST(tool_serial) struct libinput *li = dev->libinput; struct libinput_event_tablet *tablet_event; struct libinput_event *event; - struct libinput_tool *tool; + struct libinput_tablet_tool *tool; litest_drain_events(li); @@ -1465,7 +1465,7 @@ START_TEST(serial_changes_tool) struct libinput *li = dev->libinput; struct libinput_event_tablet *tablet_event; struct libinput_event *event; - struct libinput_tool *tool; + struct libinput_tablet_tool *tool; litest_drain_events(li); @@ -1498,7 +1498,7 @@ START_TEST(invalid_serials) struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet *tablet_event; - struct libinput_tool *tool; + struct libinput_tablet_tool *tool; litest_drain_events(li); @@ -1534,7 +1534,7 @@ START_TEST(tool_ref) struct libinput *li = dev->libinput; struct libinput_event_tablet *tablet_event; struct libinput_event *event; - struct libinput_tool *tool; + struct libinput_tablet_tool *tool; litest_drain_events(li); @@ -1611,7 +1611,7 @@ START_TEST(tools_with_serials) { struct libinput *li = litest_create_context(); struct litest_device *dev[2]; - struct libinput_tool *tool[2] = {0}; + struct libinput_tablet_tool *tool[2] = {0}; struct libinput_event *event; int i; @@ -1660,7 +1660,7 @@ START_TEST(tools_without_serials) { struct libinput *li = litest_create_context(); struct litest_device *dev[2]; - struct libinput_tool *tool[2] = {0}; + struct libinput_tablet_tool *tool[2] = {0}; struct libinput_event *event; int i; @@ -1712,7 +1712,7 @@ START_TEST(tool_capabilities) struct litest_device *bamboo; struct libinput_event *event; struct libinput_event_tablet *t; - struct libinput_tool *tool; + struct libinput_tablet_tool *tool; /* The axis capabilities of a tool can differ depending on the type of * tablet the tool is being used with */ @@ -1831,7 +1831,7 @@ START_TEST(mouse_tool) struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet *tev; - struct libinput_tool *tool; + struct libinput_tablet_tool *tool; if (!libevdev_has_event_code(dev->evdev, EV_KEY, @@ -1864,7 +1864,7 @@ START_TEST(mouse_buttons) struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet *tev; - struct libinput_tool *tool; + struct libinput_tablet_tool *tool; int code; if (!libevdev_has_event_code(dev->evdev, @@ -2001,7 +2001,7 @@ START_TEST(mouse_wheel) struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet *tev; - struct libinput_tool *tool; + struct libinput_tablet_tool *tool; const struct input_absinfo *abs; double val; int i; @@ -2100,7 +2100,7 @@ START_TEST(airbrush_tool) struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet *tev; - struct libinput_tool *tool; + struct libinput_tablet_tool *tool; if (!libevdev_has_event_code(dev->evdev, EV_KEY, @@ -2186,7 +2186,7 @@ START_TEST(artpen_tool) struct libinput *li = dev->libinput; struct libinput_event *event; struct libinput_event_tablet *tev; - struct libinput_tool *tool; + struct libinput_tablet_tool *tool; if (!libevdev_has_event_code(dev->evdev, EV_ABS, diff --git a/tools/event-debug.c b/tools/event-debug.c index f0ae1dc8..bb818bc2 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -339,7 +339,7 @@ tablet_axis_changed_sym(struct libinput_event_tablet *t, static void print_tablet_axes(struct libinput_event_tablet *t) { - struct libinput_tool *tool = libinput_event_tablet_get_tool(t); + struct libinput_tablet_tool *tool = libinput_event_tablet_get_tool(t); double x, y, dx, dy; double dist, pressure; double rotation, slider, wheel; @@ -457,7 +457,7 @@ 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); + struct libinput_tablet_tool *tool = libinput_event_tablet_get_tool(t); enum libinput_tool_proximity_state state; const char *tool_str, *state_str; From cd2cd2f112ab590f008ec3201599b94be3fac4c3 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 16 Nov 2015 15:35:40 +1000 Subject: [PATCH 164/255] tablet: rename libinput_tablet_axis to libinput_tablet_tool_axis Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 14 +++++++------- src/evdev-tablet.h | 10 +++++----- src/libinput.c | 10 +++++----- src/libinput.h | 12 ++++++------ tools/event-debug.c | 2 +- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 7537e211..d1ffe093 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -69,7 +69,7 @@ tablet_get_released_buttons(struct tablet_dispatch *tablet, static int tablet_device_has_axis(struct tablet_dispatch *tablet, - enum libinput_tablet_axis axis) + enum libinput_tablet_tool_axis axis) { struct libevdev *evdev = tablet->device->evdev; bool has_axis = false; @@ -109,7 +109,7 @@ tablet_process_absolute(struct tablet_dispatch *tablet, struct input_event *e, uint64_t time) { - enum libinput_tablet_axis axis; + enum libinput_tablet_tool_axis axis; switch (e->code) { case ABS_X: @@ -158,7 +158,7 @@ static void tablet_mark_all_axes_changed(struct tablet_dispatch *tablet, struct evdev_device *device) { - enum libinput_tablet_axis a; + enum libinput_tablet_tool_axis a; for (a = LIBINPUT_TABLET_AXIS_X; a <= LIBINPUT_TABLET_AXIS_MAX; a++) { if (tablet_device_has_axis(tablet, a)) @@ -290,7 +290,7 @@ guess_wheel_delta(double current, double old) } static inline double -get_delta(enum libinput_tablet_axis axis, double current, double old) +get_delta(enum libinput_tablet_tool_axis axis, double current, double old) { double delta = 0; @@ -529,7 +529,7 @@ tablet_process_relative(struct tablet_dispatch *tablet, struct input_event *e, uint64_t time) { - enum libinput_tablet_axis axis; + enum libinput_tablet_tool_axis axis; switch (e->code) { case REL_WHEEL: @@ -577,7 +577,7 @@ tablet_process_misc(struct tablet_dispatch *tablet, static inline void copy_axis_cap(const struct tablet_dispatch *tablet, struct libinput_tablet_tool *tool, - enum libinput_tablet_axis axis) + enum libinput_tablet_tool_axis axis) { if (bit_is_set(tablet->axis_caps, axis)) set_bit(tool->axis_caps, axis); @@ -1071,7 +1071,7 @@ static int tablet_init(struct tablet_dispatch *tablet, struct evdev_device *device) { - enum libinput_tablet_axis axis; + enum libinput_tablet_tool_axis axis; tablet->base.interface = &tablet_interface; tablet->device = device; diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index 9901b2a1..36a3cecb 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -67,10 +67,10 @@ struct tablet_dispatch { uint32_t current_tool_serial; }; -static inline enum libinput_tablet_axis +static inline enum libinput_tablet_tool_axis evcode_to_axis(const uint32_t evcode) { - enum libinput_tablet_axis axis; + enum libinput_tablet_tool_axis axis; switch (evcode) { case ABS_X: @@ -105,10 +105,10 @@ evcode_to_axis(const uint32_t evcode) return axis; } -static inline enum libinput_tablet_axis +static inline enum libinput_tablet_tool_axis rel_evcode_to_axis(const uint32_t evcode) { - enum libinput_tablet_axis axis; + enum libinput_tablet_tool_axis axis; switch (evcode) { case REL_WHEEL: @@ -123,7 +123,7 @@ rel_evcode_to_axis(const uint32_t evcode) } static inline uint32_t -axis_to_evcode(const enum libinput_tablet_axis axis) +axis_to_evcode(const enum libinput_tablet_tool_axis axis) { uint32_t evcode; diff --git a/src/libinput.c b/src/libinput.c index b50f5334..4d012d3a 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -914,7 +914,7 @@ libinput_event_gesture_get_angle_delta(struct libinput_event_gesture *event) LIBINPUT_EXPORT int libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, - enum libinput_tablet_axis axis) + enum libinput_tablet_tool_axis axis) { require_event_type(libinput_event_get_context(&event->base), event->base.type, @@ -929,7 +929,7 @@ libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, LIBINPUT_EXPORT double libinput_event_tablet_get_axis_value(struct libinput_event_tablet *event, - enum libinput_tablet_axis axis) + enum libinput_tablet_tool_axis axis) { struct evdev_device *device = (struct evdev_device *) event->base.device; @@ -963,7 +963,7 @@ libinput_event_tablet_get_axis_value(struct libinput_event_tablet *event, LIBINPUT_EXPORT double libinput_event_tablet_get_axis_delta(struct libinput_event_tablet *event, - enum libinput_tablet_axis axis) + enum libinput_tablet_tool_axis axis) { struct evdev_device *device = (struct evdev_device *) event->base.device; @@ -998,7 +998,7 @@ libinput_event_tablet_get_axis_delta(struct libinput_event_tablet *event, LIBINPUT_EXPORT double libinput_event_tablet_get_axis_delta_discrete( struct libinput_event_tablet *event, - enum libinput_tablet_axis axis) + enum libinput_tablet_tool_axis axis) { require_event_type(libinput_event_get_context(&event->base), event->base.type, @@ -1184,7 +1184,7 @@ libinput_tool_get_serial(struct libinput_tablet_tool *tool) LIBINPUT_EXPORT int libinput_tool_has_axis(struct libinput_tablet_tool *tool, - enum libinput_tablet_axis axis) + enum libinput_tablet_tool_axis axis) { return bit_is_set(tool->axis_caps, axis); } diff --git a/src/libinput.h b/src/libinput.h index bda1f9d5..712a0bbe 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -140,7 +140,7 @@ enum libinput_pointer_axis_source { * Available axis types for a device. It must have the @ref * LIBINPUT_DEVICE_CAP_TABLET capability. */ -enum libinput_tablet_axis { +enum libinput_tablet_tool_axis { LIBINPUT_TABLET_AXIS_X = 1, LIBINPUT_TABLET_AXIS_Y = 2, LIBINPUT_TABLET_AXIS_DISTANCE = 3, @@ -1371,7 +1371,7 @@ libinput_event_tablet_get_base_event(struct libinput_event_tablet *event); */ int libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, - enum libinput_tablet_axis axis); + enum libinput_tablet_tool_axis axis); /** * @ingroup event_tablet @@ -1416,7 +1416,7 @@ libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, */ double libinput_event_tablet_get_axis_value(struct libinput_event_tablet *event, - enum libinput_tablet_axis axis); + enum libinput_tablet_tool_axis axis); /** * @ingroup event_tablet @@ -1435,7 +1435,7 @@ libinput_event_tablet_get_axis_value(struct libinput_event_tablet *event, */ double libinput_event_tablet_get_axis_delta(struct libinput_event_tablet *event, - enum libinput_tablet_axis axis); + enum libinput_tablet_tool_axis axis); /** * @ingroup event_tablet @@ -1453,7 +1453,7 @@ libinput_event_tablet_get_axis_delta(struct libinput_event_tablet *event, double libinput_event_tablet_get_axis_delta_discrete( struct libinput_event_tablet *event, - enum libinput_tablet_axis axis); + enum libinput_tablet_tool_axis axis); /** * @ingroup event_tablet @@ -1656,7 +1656,7 @@ libinput_tool_ref(struct libinput_tablet_tool *tool); */ int libinput_tool_has_axis(struct libinput_tablet_tool *tool, - enum libinput_tablet_axis axis); + enum libinput_tablet_tool_axis axis); /** * @ingroup event_tablet diff --git a/tools/event-debug.c b/tools/event-debug.c index bb818bc2..b7237abb 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -328,7 +328,7 @@ print_pointer_axis_event(struct libinput_event *ev) static const char* tablet_axis_changed_sym(struct libinput_event_tablet *t, - enum libinput_tablet_axis axis) + enum libinput_tablet_tool_axis axis) { if (libinput_event_tablet_axis_has_changed(t, axis)) return "*"; From 827abfbb56ab913c040e92f141a1d7dbbed5eec0 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 16 Nov 2015 15:36:30 +1000 Subject: [PATCH 165/255] tablet: rename the tablet axes to "LIBINPUT_TABLET_TOOL_AXIS_..." Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 126 +++++++++++------------ src/evdev-tablet.h | 48 ++++----- src/libinput-private.h | 4 +- src/libinput.c | 66 ++++++------ src/libinput.h | 36 +++---- test/tablet.c | 228 ++++++++++++++++++++--------------------- tools/event-debug.c | 82 +++++++-------- tools/event-gui.c | 8 +- 8 files changed, 299 insertions(+), 299 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index d1ffe093..4f9465ed 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -75,7 +75,7 @@ tablet_device_has_axis(struct tablet_dispatch *tablet, bool has_axis = false; unsigned int code; - if (axis == LIBINPUT_TABLET_AXIS_ROTATION_Z) { + if (axis == LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z) { has_axis = (libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_MOUSE) && @@ -89,7 +89,7 @@ tablet_device_has_axis(struct tablet_dispatch *tablet, has_axis |= libevdev_has_event_code(evdev, EV_ABS, code); - } else if (axis == LIBINPUT_TABLET_AXIS_REL_WHEEL) { + } else if (axis == LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL) { has_axis = libevdev_has_event_code(evdev, EV_REL, REL_WHEEL); @@ -121,7 +121,7 @@ tablet_process_absolute(struct tablet_dispatch *tablet, case ABS_DISTANCE: case ABS_WHEEL: axis = evcode_to_axis(e->code); - if (axis == LIBINPUT_TABLET_AXIS_NONE) { + if (axis == LIBINPUT_TABLET_TOOL_AXIS_NONE) { log_bug_libinput(device->base.seat->libinput, "Invalid ABS event code %#x\n", e->code); @@ -160,7 +160,7 @@ tablet_mark_all_axes_changed(struct tablet_dispatch *tablet, { enum libinput_tablet_tool_axis a; - for (a = LIBINPUT_TABLET_AXIS_X; a <= LIBINPUT_TABLET_AXIS_MAX; a++) { + for (a = LIBINPUT_TABLET_TOOL_AXIS_X; a <= LIBINPUT_TABLET_TOOL_AXIS_MAX; a++) { if (tablet_device_has_axis(tablet, a)) set_bit(tablet->changed_axes, a); } @@ -237,10 +237,10 @@ convert_tilt_to_rotation(struct tablet_dispatch *tablet) 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); + x = tablet->axes[LIBINPUT_TABLET_TOOL_AXIS_TILT_X]; + y = tablet->axes[LIBINPUT_TABLET_TOOL_AXIS_TILT_Y]; + clear_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_X); + clear_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); /* atan2 is CCW, we want CW -> negate x */ if (x || y) @@ -248,8 +248,8 @@ convert_tilt_to_rotation(struct tablet_dispatch *tablet) angle = fmod(360 + angle - offset, 360); - tablet->axes[LIBINPUT_TABLET_AXIS_ROTATION_Z] = angle; - set_bit(tablet->changed_axes, LIBINPUT_TABLET_AXIS_ROTATION_Z); + tablet->axes[LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z] = angle; + set_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); } static double @@ -295,16 +295,16 @@ get_delta(enum libinput_tablet_tool_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: + case LIBINPUT_TABLET_TOOL_AXIS_X: + case LIBINPUT_TABLET_TOOL_AXIS_Y: + case LIBINPUT_TABLET_TOOL_AXIS_DISTANCE: + case LIBINPUT_TABLET_TOOL_AXIS_PRESSURE: + case LIBINPUT_TABLET_TOOL_AXIS_SLIDER: + case LIBINPUT_TABLET_TOOL_AXIS_TILT_X: + case LIBINPUT_TABLET_TOOL_AXIS_TILT_Y: delta = current - old; break; - case LIBINPUT_TABLET_AXIS_ROTATION_Z: + case LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z: delta = guess_wheel_delta(current, old); break; default: @@ -322,12 +322,12 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, 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 axes[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1] = {0}; + double deltas[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1] = {0}; + double deltas_discrete[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1] = {0}; double oldval; - for (a = LIBINPUT_TABLET_AXIS_X; a <= LIBINPUT_TABLET_AXIS_MAX; a++) { + for (a = LIBINPUT_TABLET_TOOL_AXIS_X; a <= LIBINPUT_TABLET_TOOL_AXIS_MAX; a++) { const struct input_absinfo *absinfo; if (!bit_is_set(tablet->changed_axes, a)) { @@ -340,16 +340,16 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, /* 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 && + if (a == LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z && (tablet->current_tool_type == LIBINPUT_TOOL_TYPE_MOUSE || tablet->current_tool_type == LIBINPUT_TOOL_TYPE_LENS)) { convert_tilt_to_rotation(tablet); - axes[LIBINPUT_TABLET_AXIS_TILT_X] = 0; - axes[LIBINPUT_TABLET_AXIS_TILT_Y] = 0; + axes[LIBINPUT_TABLET_TOOL_AXIS_TILT_X] = 0; + axes[LIBINPUT_TABLET_TOOL_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) { + } else if (a == LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL) { deltas_discrete[a] = tablet->deltas[a]; deltas[a] = normalize_wheel(tablet, tablet->deltas[a]); @@ -361,23 +361,23 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, axis_to_evcode(a)); switch (a) { - case LIBINPUT_TABLET_AXIS_X: - case LIBINPUT_TABLET_AXIS_Y: + case LIBINPUT_TABLET_TOOL_AXIS_X: + case LIBINPUT_TABLET_TOOL_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: + case LIBINPUT_TABLET_TOOL_AXIS_DISTANCE: + case LIBINPUT_TABLET_TOOL_AXIS_PRESSURE: + case LIBINPUT_TABLET_TOOL_AXIS_SLIDER: tablet->axes[a] = normalize_pressure_dist_slider(absinfo); break; - case LIBINPUT_TABLET_AXIS_TILT_X: - case LIBINPUT_TABLET_AXIS_TILT_Y: + case LIBINPUT_TABLET_TOOL_AXIS_TILT_X: + case LIBINPUT_TABLET_TOOL_AXIS_TILT_Y: tablet->axes[a] = normalize_tilt(absinfo); break; - case LIBINPUT_TABLET_AXIS_ROTATION_Z: + case LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z: /* artpen has 0 with buttons pointing east */ tablet->axes[a] = convert_to_degrees(absinfo, 90); break; @@ -534,7 +534,7 @@ tablet_process_relative(struct tablet_dispatch *tablet, switch (e->code) { case REL_WHEEL: axis = rel_evcode_to_axis(e->code); - if (axis == LIBINPUT_TABLET_AXIS_NONE) { + if (axis == LIBINPUT_TABLET_TOOL_AXIS_NONE) { log_bug_libinput(device->base.seat->libinput, "Invalid ABS event code %#x\n", e->code); @@ -631,7 +631,7 @@ tool_set_bits_from_libwacom(const struct tablet_dispatch *tablet, } if (libwacom_stylus_has_wheel(s)) - copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_REL_WHEEL); + copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); axes = libwacom_stylus_get_axes(s); @@ -639,24 +639,24 @@ tool_set_bits_from_libwacom(const struct tablet_dispatch *tablet, /* tilt on the puck is converted to rotation */ if (type == WSTYLUS_PUCK) { set_bit(tool->axis_caps, - LIBINPUT_TABLET_AXIS_ROTATION_Z); + LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); } else { copy_axis_cap(tablet, tool, - LIBINPUT_TABLET_AXIS_TILT_X); + LIBINPUT_TABLET_TOOL_AXIS_TILT_X); copy_axis_cap(tablet, tool, - LIBINPUT_TABLET_AXIS_TILT_Y); + LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); } } if (axes & WACOM_AXIS_TYPE_ROTATION_Z) - copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_ROTATION_Z); + copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); if (axes & WACOM_AXIS_TYPE_DISTANCE) - copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_DISTANCE); + copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); if (axes & WACOM_AXIS_TYPE_SLIDER) - copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_SLIDER); + copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_SLIDER); if (axes & WACOM_AXIS_TYPE_PRESSURE) - copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_PRESSURE); + copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); rc = 0; out: @@ -686,17 +686,17 @@ tool_set_bits(const struct tablet_dispatch *tablet, case LIBINPUT_TOOL_TYPE_PENCIL: case LIBINPUT_TOOL_TYPE_BRUSH: case LIBINPUT_TOOL_TYPE_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); + copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); + copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X); + copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); + copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_SLIDER); + copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); break; case LIBINPUT_TOOL_TYPE_MOUSE: case LIBINPUT_TOOL_TYPE_LENS: - copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_ROTATION_Z); - copy_axis_cap(tablet, tool, LIBINPUT_TABLET_AXIS_REL_WHEEL); + copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); + copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); break; default: break; @@ -846,29 +846,29 @@ sanitize_tablet_axes(struct tablet_dispatch *tablet) 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) && + if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_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) && + clear_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); + tablet->axes[LIBINPUT_TABLET_TOOL_AXIS_DISTANCE] = 0; + } else if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE) && (!tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT) && !tablet_has_status(tablet, TABLET_TOOL_ENTERING_CONTACT))) { /* Make sure that the last axis value sent to the caller is a 0 */ - if (tablet->axes[LIBINPUT_TABLET_AXIS_PRESSURE] == 0) + if (tablet->axes[LIBINPUT_TABLET_TOOL_AXIS_PRESSURE] == 0) clear_bit(tablet->changed_axes, - LIBINPUT_TABLET_AXIS_PRESSURE); + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); else - tablet->axes[LIBINPUT_TABLET_AXIS_PRESSURE] = 0; + tablet->axes[LIBINPUT_TABLET_TOOL_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_TYPE_MOUSE || tablet->current_tool_type == LIBINPUT_TOOL_TYPE_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); + (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) || + bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y))) + set_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); } static void @@ -1079,8 +1079,8 @@ tablet_init(struct tablet_dispatch *tablet, tablet->current_tool_type = LIBINPUT_TOOL_NONE; list_init(&tablet->tool_list); - for (axis = LIBINPUT_TABLET_AXIS_X; - axis <= LIBINPUT_TABLET_AXIS_MAX; + for (axis = LIBINPUT_TABLET_TOOL_AXIS_X; + axis <= LIBINPUT_TABLET_TOOL_AXIS_MAX; axis++) { if (tablet_device_has_axis(tablet, axis)) set_bit(tablet->axis_caps, axis); diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index 36a3cecb..e88d87c2 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -26,7 +26,7 @@ #include "evdev.h" -#define LIBINPUT_TABLET_AXIS_NONE 0 +#define LIBINPUT_TABLET_TOOL_AXIS_NONE 0 #define LIBINPUT_TOOL_NONE 0 #define LIBINPUT_TOOL_TYPE_MAX LIBINPUT_TOOL_TYPE_LENS @@ -51,10 +51,10 @@ struct tablet_dispatch { struct evdev_dispatch base; struct evdev_device *device; unsigned int 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)]; + unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_TOOL_AXIS_MAX + 1)]; + double axes[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1]; + double deltas[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1]; + unsigned char axis_caps[NCHARS(LIBINPUT_TABLET_TOOL_AXIS_MAX + 1)]; /* Only used for tablets that don't report serial numbers */ struct list tool_list; @@ -74,31 +74,31 @@ evcode_to_axis(const uint32_t evcode) switch (evcode) { case ABS_X: - axis = LIBINPUT_TABLET_AXIS_X; + axis = LIBINPUT_TABLET_TOOL_AXIS_X; break; case ABS_Y: - axis = LIBINPUT_TABLET_AXIS_Y; + axis = LIBINPUT_TABLET_TOOL_AXIS_Y; break; case ABS_Z: - axis = LIBINPUT_TABLET_AXIS_ROTATION_Z; + axis = LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z; break; case ABS_DISTANCE: - axis = LIBINPUT_TABLET_AXIS_DISTANCE; + axis = LIBINPUT_TABLET_TOOL_AXIS_DISTANCE; break; case ABS_PRESSURE: - axis = LIBINPUT_TABLET_AXIS_PRESSURE; + axis = LIBINPUT_TABLET_TOOL_AXIS_PRESSURE; break; case ABS_TILT_X: - axis = LIBINPUT_TABLET_AXIS_TILT_X; + axis = LIBINPUT_TABLET_TOOL_AXIS_TILT_X; break; case ABS_TILT_Y: - axis = LIBINPUT_TABLET_AXIS_TILT_Y; + axis = LIBINPUT_TABLET_TOOL_AXIS_TILT_Y; break; case ABS_WHEEL: - axis = LIBINPUT_TABLET_AXIS_SLIDER; + axis = LIBINPUT_TABLET_TOOL_AXIS_SLIDER; break; default: - axis = LIBINPUT_TABLET_AXIS_NONE; + axis = LIBINPUT_TABLET_TOOL_AXIS_NONE; break; } @@ -112,10 +112,10 @@ rel_evcode_to_axis(const uint32_t evcode) switch (evcode) { case REL_WHEEL: - axis = LIBINPUT_TABLET_AXIS_REL_WHEEL; + axis = LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL; break; default: - axis = LIBINPUT_TABLET_AXIS_NONE; + axis = LIBINPUT_TABLET_TOOL_AXIS_NONE; break; } @@ -128,28 +128,28 @@ axis_to_evcode(const enum libinput_tablet_tool_axis axis) uint32_t evcode; switch (axis) { - case LIBINPUT_TABLET_AXIS_X: + case LIBINPUT_TABLET_TOOL_AXIS_X: evcode = ABS_X; break; - case LIBINPUT_TABLET_AXIS_Y: + case LIBINPUT_TABLET_TOOL_AXIS_Y: evcode = ABS_Y; break; - case LIBINPUT_TABLET_AXIS_DISTANCE: + case LIBINPUT_TABLET_TOOL_AXIS_DISTANCE: evcode = ABS_DISTANCE; break; - case LIBINPUT_TABLET_AXIS_PRESSURE: + case LIBINPUT_TABLET_TOOL_AXIS_PRESSURE: evcode = ABS_PRESSURE; break; - case LIBINPUT_TABLET_AXIS_TILT_X: + case LIBINPUT_TABLET_TOOL_AXIS_TILT_X: evcode = ABS_TILT_X; break; - case LIBINPUT_TABLET_AXIS_TILT_Y: + case LIBINPUT_TABLET_TOOL_AXIS_TILT_Y: evcode = ABS_TILT_Y; break; - case LIBINPUT_TABLET_AXIS_ROTATION_Z: + case LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z: evcode = ABS_Z; break; - case LIBINPUT_TABLET_AXIS_SLIDER: + case LIBINPUT_TABLET_TOOL_AXIS_SLIDER: evcode = ABS_WHEEL; break; default: diff --git a/src/libinput-private.h b/src/libinput-private.h index b28e0e1c..96a38d29 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -33,7 +33,7 @@ #include "libinput.h" #include "libinput-util.h" -#define LIBINPUT_TABLET_AXIS_MAX LIBINPUT_TABLET_AXIS_REL_WHEEL +#define LIBINPUT_TABLET_TOOL_AXIS_MAX LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL struct libinput_source; @@ -255,7 +255,7 @@ struct libinput_tablet_tool { uint32_t serial; uint32_t tool_id; enum libinput_tool_type type; - unsigned char axis_caps[NCHARS(LIBINPUT_TABLET_AXIS_MAX + 1)]; + unsigned char axis_caps[NCHARS(LIBINPUT_TABLET_TOOL_AXIS_MAX + 1)]; unsigned char buttons[NCHARS(KEY_MAX) + 1]; int refcount; void *user_data; diff --git a/src/libinput.c b/src/libinput.c index 4d012d3a..9d35927e 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -131,10 +131,10 @@ struct libinput_event_tablet { 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)]; + double axes[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1]; + double deltas[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1]; + double deltas_discrete[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1]; + unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_TOOL_AXIS_MAX + 1)]; struct libinput_tablet_tool *tool; enum libinput_tool_proximity_state proximity_state; enum libinput_tool_tip_state tip_state; @@ -942,19 +942,19 @@ libinput_event_tablet_get_axis_value(struct libinput_event_tablet *event, LIBINPUT_EVENT_TABLET_PROXIMITY); switch(axis) { - case LIBINPUT_TABLET_AXIS_X: + case LIBINPUT_TABLET_TOOL_AXIS_X: return evdev_convert_to_mm(device->abs.absinfo_x, event->axes[axis]); - case LIBINPUT_TABLET_AXIS_Y: + case LIBINPUT_TABLET_TOOL_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: + case LIBINPUT_TABLET_TOOL_AXIS_DISTANCE: + case LIBINPUT_TABLET_TOOL_AXIS_PRESSURE: + case LIBINPUT_TABLET_TOOL_AXIS_TILT_X: + case LIBINPUT_TABLET_TOOL_AXIS_TILT_Y: + case LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z: + case LIBINPUT_TABLET_TOOL_AXIS_SLIDER: + case LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL: return event->axes[axis]; default: return 0; @@ -976,19 +976,19 @@ libinput_event_tablet_get_axis_delta(struct libinput_event_tablet *event, LIBINPUT_EVENT_TABLET_PROXIMITY); switch(axis) { - case LIBINPUT_TABLET_AXIS_X: + case LIBINPUT_TABLET_TOOL_AXIS_X: return evdev_convert_to_mm(device->abs.absinfo_x, event->deltas[axis]); - case LIBINPUT_TABLET_AXIS_Y: + case LIBINPUT_TABLET_TOOL_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: + case LIBINPUT_TABLET_TOOL_AXIS_DISTANCE: + case LIBINPUT_TABLET_TOOL_AXIS_PRESSURE: + case LIBINPUT_TABLET_TOOL_AXIS_TILT_X: + case LIBINPUT_TABLET_TOOL_AXIS_TILT_Y: + case LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z: + case LIBINPUT_TABLET_TOOL_AXIS_SLIDER: + case LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL: return event->deltas[axis]; default: return 0; @@ -1008,15 +1008,15 @@ libinput_event_tablet_get_axis_delta_discrete( LIBINPUT_EVENT_TABLET_PROXIMITY); 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: + case LIBINPUT_TABLET_TOOL_AXIS_X: + case LIBINPUT_TABLET_TOOL_AXIS_Y: + case LIBINPUT_TABLET_TOOL_AXIS_DISTANCE: + case LIBINPUT_TABLET_TOOL_AXIS_PRESSURE: + case LIBINPUT_TABLET_TOOL_AXIS_TILT_X: + case LIBINPUT_TABLET_TOOL_AXIS_TILT_Y: + case LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z: + case LIBINPUT_TABLET_TOOL_AXIS_SLIDER: + case LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL: return event->deltas_discrete[axis]; default: return 0; @@ -1038,7 +1038,7 @@ libinput_event_tablet_get_x_transformed(struct libinput_event_tablet *event, LIBINPUT_EVENT_TABLET_PROXIMITY); return evdev_device_transform_x(device, - event->axes[LIBINPUT_TABLET_AXIS_X], + event->axes[LIBINPUT_TABLET_TOOL_AXIS_X], width); } @@ -1057,7 +1057,7 @@ libinput_event_tablet_get_y_transformed(struct libinput_event_tablet *event, LIBINPUT_EVENT_TABLET_PROXIMITY); return evdev_device_transform_y(device, - event->axes[LIBINPUT_TABLET_AXIS_Y], + event->axes[LIBINPUT_TABLET_TOOL_AXIS_Y], height); } diff --git a/src/libinput.h b/src/libinput.h index 712a0bbe..853367c4 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -141,15 +141,15 @@ enum libinput_pointer_axis_source { * LIBINPUT_DEVICE_CAP_TABLET capability. */ enum libinput_tablet_tool_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, + LIBINPUT_TABLET_TOOL_AXIS_X = 1, + LIBINPUT_TABLET_TOOL_AXIS_Y = 2, + LIBINPUT_TABLET_TOOL_AXIS_DISTANCE = 3, + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE = 4, + LIBINPUT_TABLET_TOOL_AXIS_TILT_X = 5, + LIBINPUT_TABLET_TOOL_AXIS_TILT_Y = 6, + LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z = 7, + LIBINPUT_TABLET_TOOL_AXIS_SLIDER = 8, + LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL = 9, }; /** @@ -1378,27 +1378,27 @@ libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, * * 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 + * - @ref LIBINPUT_TABLET_TOOL_AXIS_X and @ref LIBINPUT_TABLET_TOOL_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 + * - @ref LIBINPUT_TABLET_TOOL_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 + * - @ref LIBINPUT_TABLET_TOOL_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 - + * - @ref LIBINPUT_TABLET_TOOL_AXIS_TILT_X and @ref LIBINPUT_TABLET_TOOL_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 + * - @ref LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z - The z rotation of the tool in * degrees, clockwise from the tool's logical neutral position. For the * @ref LIBINPUT_TOOL_TYPE_MOUSE and @ref LIBINPUT_TOOL_TYPE_LENS tools * the logical neutral position is pointing to the current logical north * of the tablet. For the @ref LIBINPUT_TOOL_TYPE_BRUSH tool, the logical * neutral position is with the buttons pointing up. - * - @ref LIBINPUT_TABLET_AXIS_SLIDER - A slider on the tool, normalized + * - @ref LIBINPUT_TABLET_TOOL_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, + * - @ref LIBINPUT_TABLET_TOOL_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. * @@ -1423,7 +1423,7 @@ libinput_event_tablet_get_axis_value(struct libinput_event_tablet *event, * * 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, + * - @ref LIBINPUT_TABLET_TOOL_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 @@ -1442,7 +1442,7 @@ libinput_event_tablet_get_axis_delta(struct libinput_event_tablet *event, * * 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 + * - @ref LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL - the returned value is the number * of physical mouse wheel clicks. * For all other axes, this function returns 0. * diff --git a/test/tablet.c b/test/tablet.c index b7ccdab3..71fca967 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -324,9 +324,9 @@ START_TEST(tip_down_motion) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_AXIS); last_x = libinput_event_tablet_get_axis_value(tablet_event, - LIBINPUT_TABLET_AXIS_X); + LIBINPUT_TABLET_TOOL_AXIS_X); last_y = libinput_event_tablet_get_axis_value(tablet_event, - LIBINPUT_TABLET_AXIS_Y); + LIBINPUT_TABLET_TOOL_AXIS_Y); libinput_event_destroy(event); libinput_dispatch(li); @@ -336,9 +336,9 @@ START_TEST(tip_down_motion) ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), LIBINPUT_TOOL_TIP_DOWN); x = libinput_event_tablet_get_axis_value(tablet_event, - LIBINPUT_TABLET_AXIS_X); + LIBINPUT_TABLET_TOOL_AXIS_X); y = libinput_event_tablet_get_axis_value(tablet_event, - LIBINPUT_TABLET_AXIS_Y); + LIBINPUT_TABLET_TOOL_AXIS_Y); ck_assert_double_eq(last_x, x); ck_assert_double_eq(last_y, y); libinput_event_destroy(event); @@ -375,9 +375,9 @@ START_TEST(tip_up_motion) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_AXIS); last_x = libinput_event_tablet_get_axis_value(tablet_event, - LIBINPUT_TABLET_AXIS_X); + LIBINPUT_TABLET_TOOL_AXIS_X); last_y = libinput_event_tablet_get_axis_value(tablet_event, - LIBINPUT_TABLET_AXIS_Y); + LIBINPUT_TABLET_TOOL_AXIS_Y); libinput_event_destroy(event); libinput_dispatch(li); @@ -387,9 +387,9 @@ START_TEST(tip_up_motion) ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), LIBINPUT_TOOL_TIP_UP); x = libinput_event_tablet_get_axis_value(tablet_event, - LIBINPUT_TABLET_AXIS_X); + LIBINPUT_TABLET_TOOL_AXIS_X); y = libinput_event_tablet_get_axis_value(tablet_event, - LIBINPUT_TABLET_AXIS_Y); + LIBINPUT_TABLET_TOOL_AXIS_Y); ck_assert_double_eq(last_x, x); ck_assert_double_eq(last_y, y); libinput_event_destroy(event); @@ -722,44 +722,44 @@ START_TEST(proximity_has_axes) tool = libinput_event_tablet_get_tool(tablet_event); ck_assert(libinput_event_tablet_axis_has_changed( - tablet_event, LIBINPUT_TABLET_AXIS_X)); + tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X)); ck_assert(libinput_event_tablet_axis_has_changed( - tablet_event, LIBINPUT_TABLET_AXIS_Y)); + tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y)); x = libinput_event_tablet_get_axis_value(tablet_event, - LIBINPUT_TABLET_AXIS_X); + LIBINPUT_TABLET_TOOL_AXIS_X); y = libinput_event_tablet_get_axis_value(tablet_event, - LIBINPUT_TABLET_AXIS_Y); + LIBINPUT_TABLET_TOOL_AXIS_Y); litest_assert_double_ne(x, 0); litest_assert_double_ne(y, 0); - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_DISTANCE)) { + if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) { ck_assert(libinput_event_tablet_axis_has_changed( tablet_event, - LIBINPUT_TABLET_AXIS_DISTANCE)); + LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)); distance = libinput_event_tablet_get_axis_value( tablet_event, - LIBINPUT_TABLET_AXIS_DISTANCE); + LIBINPUT_TABLET_TOOL_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)) { + if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) && + libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { ck_assert(libinput_event_tablet_axis_has_changed( tablet_event, - LIBINPUT_TABLET_AXIS_TILT_X)); + LIBINPUT_TABLET_TOOL_AXIS_TILT_X)); ck_assert(libinput_event_tablet_axis_has_changed( tablet_event, - LIBINPUT_TABLET_AXIS_TILT_Y)); + LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)); x = libinput_event_tablet_get_axis_value( tablet_event, - LIBINPUT_TABLET_AXIS_TILT_X); + LIBINPUT_TABLET_TOOL_AXIS_TILT_X); y = libinput_event_tablet_get_axis_value( tablet_event, - LIBINPUT_TABLET_AXIS_TILT_Y); + LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); litest_assert_double_ne(x, 0); litest_assert_double_ne(y, 0); @@ -778,21 +778,21 @@ START_TEST(proximity_has_axes) tablet_event = libinput_event_get_tablet_event(event); last_x = libinput_event_tablet_get_axis_value(tablet_event, - LIBINPUT_TABLET_AXIS_X); + LIBINPUT_TABLET_TOOL_AXIS_X); last_y = libinput_event_tablet_get_axis_value(tablet_event, - LIBINPUT_TABLET_AXIS_Y); - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_DISTANCE)) + LIBINPUT_TABLET_TOOL_AXIS_Y); + if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) last_distance = libinput_event_tablet_get_axis_value( tablet_event, - LIBINPUT_TABLET_AXIS_DISTANCE); - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_TILT_X) && - libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_TILT_Y)) { + LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); + if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) && + libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { last_tx = libinput_event_tablet_get_axis_value( tablet_event, - LIBINPUT_TABLET_AXIS_TILT_X); + LIBINPUT_TABLET_TOOL_AXIS_TILT_X); last_ty = libinput_event_tablet_get_axis_value( tablet_event, - LIBINPUT_TABLET_AXIS_TILT_Y); + LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); } libinput_event_destroy(event); @@ -807,43 +807,43 @@ START_TEST(proximity_has_axes) tool = libinput_event_tablet_get_tool(tablet_event); ck_assert(!libinput_event_tablet_axis_has_changed( - tablet_event, LIBINPUT_TABLET_AXIS_X)); + tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X)); ck_assert(!libinput_event_tablet_axis_has_changed( - tablet_event, LIBINPUT_TABLET_AXIS_Y)); + tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y)); x = libinput_event_tablet_get_axis_value(tablet_event, - LIBINPUT_TABLET_AXIS_X); + LIBINPUT_TABLET_TOOL_AXIS_X); y = libinput_event_tablet_get_axis_value(tablet_event, - LIBINPUT_TABLET_AXIS_Y); + LIBINPUT_TABLET_TOOL_AXIS_Y); litest_assert_double_eq(x, last_x); litest_assert_double_eq(y, last_y); - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_DISTANCE)) { + if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) { ck_assert(!libinput_event_tablet_axis_has_changed( tablet_event, - LIBINPUT_TABLET_AXIS_DISTANCE)); + LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)); distance = libinput_event_tablet_get_axis_value( tablet_event, - LIBINPUT_TABLET_AXIS_DISTANCE); + LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); litest_assert_double_eq(distance, last_distance); } - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_TILT_X) && - libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_TILT_Y)) { + if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) && + libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { ck_assert(!libinput_event_tablet_axis_has_changed( tablet_event, - LIBINPUT_TABLET_AXIS_TILT_X)); + LIBINPUT_TABLET_TOOL_AXIS_TILT_X)); ck_assert(!libinput_event_tablet_axis_has_changed( tablet_event, - LIBINPUT_TABLET_AXIS_TILT_Y)); + LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)); x = libinput_event_tablet_get_axis_value( tablet_event, - LIBINPUT_TABLET_AXIS_TILT_X); + LIBINPUT_TABLET_TOOL_AXIS_TILT_X); y = libinput_event_tablet_get_axis_value( tablet_event, - LIBINPUT_TABLET_AXIS_TILT_Y); + LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); litest_assert_double_eq(x, last_tx); litest_assert_double_eq(y, last_ty); @@ -886,17 +886,17 @@ START_TEST(motion) LIBINPUT_EVENT_TABLET_PROXIMITY); x_changed = libinput_event_tablet_axis_has_changed( - tablet_event, LIBINPUT_TABLET_AXIS_X); + tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); y_changed = libinput_event_tablet_axis_has_changed( - tablet_event, LIBINPUT_TABLET_AXIS_Y); + tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); ck_assert(x_changed); ck_assert(y_changed); reported_x = libinput_event_tablet_get_axis_value( - tablet_event, LIBINPUT_TABLET_AXIS_X); + tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); reported_y = libinput_event_tablet_get_axis_value( - tablet_event, LIBINPUT_TABLET_AXIS_Y); + tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); litest_assert_double_lt(reported_x, reported_y); @@ -921,17 +921,17 @@ START_TEST(motion) if (type == LIBINPUT_EVENT_TABLET_AXIS) { x_changed = libinput_event_tablet_axis_has_changed( - tablet_event, LIBINPUT_TABLET_AXIS_X); + tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); y_changed = libinput_event_tablet_axis_has_changed( - tablet_event, LIBINPUT_TABLET_AXIS_Y); + tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); ck_assert(x_changed); ck_assert(y_changed); reported_x = libinput_event_tablet_get_axis_value( - tablet_event, LIBINPUT_TABLET_AXIS_X); + tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); reported_y = libinput_event_tablet_get_axis_value( - tablet_event, LIBINPUT_TABLET_AXIS_Y); + tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); litest_assert_double_gt(reported_x, last_reported_x); @@ -973,11 +973,11 @@ START_TEST(motion_delta) 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); + LIBINPUT_TABLET_TOOL_AXIS_X); y1 = libinput_event_tablet_get_axis_value(tablet_event, - LIBINPUT_TABLET_AXIS_Y); + LIBINPUT_TABLET_TOOL_AXIS_Y); dist1 = libinput_event_tablet_get_axis_value(tablet_event, - LIBINPUT_TABLET_AXIS_DISTANCE); + LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); libinput_event_destroy(event); axes[0].value = 40; @@ -989,20 +989,20 @@ START_TEST(motion_delta) 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); + LIBINPUT_TABLET_TOOL_AXIS_X); y2 = libinput_event_tablet_get_axis_value(tablet_event, - LIBINPUT_TABLET_AXIS_Y); + LIBINPUT_TABLET_TOOL_AXIS_Y); dist2 = libinput_event_tablet_get_axis_value(tablet_event, - LIBINPUT_TABLET_AXIS_DISTANCE); + LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); delta = libinput_event_tablet_get_axis_delta(tablet_event, - LIBINPUT_TABLET_AXIS_X); + LIBINPUT_TABLET_TOOL_AXIS_X); litest_assert_double_eq(delta, x2 - x1); delta = libinput_event_tablet_get_axis_delta(tablet_event, - LIBINPUT_TABLET_AXIS_Y); + LIBINPUT_TABLET_TOOL_AXIS_Y); litest_assert_double_eq(delta, y2 - y1); delta = libinput_event_tablet_get_axis_delta(tablet_event, - LIBINPUT_TABLET_AXIS_DISTANCE); + LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); litest_assert_double_eq(delta, dist2 - dist1); libinput_event_destroy(event); @@ -1037,21 +1037,21 @@ START_TEST(motion_delta_partial) tablet_event = libinput_event_get_tablet_event(event); ck_assert(!libinput_event_tablet_axis_has_changed(tablet_event, - LIBINPUT_TABLET_AXIS_X)); + LIBINPUT_TABLET_TOOL_AXIS_X)); dx = libinput_event_tablet_get_axis_delta(tablet_event, - LIBINPUT_TABLET_AXIS_X); + LIBINPUT_TABLET_TOOL_AXIS_X); litest_assert_double_eq(dx, 0.0); ck_assert(!libinput_event_tablet_axis_has_changed(tablet_event, - LIBINPUT_TABLET_AXIS_X)); + LIBINPUT_TABLET_TOOL_AXIS_X)); dy = libinput_event_tablet_get_axis_delta(tablet_event, - LIBINPUT_TABLET_AXIS_Y); + LIBINPUT_TABLET_TOOL_AXIS_Y); litest_assert_double_eq(dy, 0.0); ck_assert(libinput_event_tablet_axis_has_changed(tablet_event, - LIBINPUT_TABLET_AXIS_DISTANCE)); + LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)); ddist = libinput_event_tablet_get_axis_delta(tablet_event, - LIBINPUT_TABLET_AXIS_DISTANCE); + LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); ck_assert_double_gt(ddist, 0); libinput_event_destroy(event); @@ -1093,9 +1093,9 @@ START_TEST(left_handed) tablet_event = libinput_event_get_tablet_event(event); last_x = libinput_event_tablet_get_axis_value( - tablet_event, LIBINPUT_TABLET_AXIS_X); + tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); last_y = libinput_event_tablet_get_axis_value( - tablet_event, LIBINPUT_TABLET_AXIS_Y); + tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); litest_assert_double_eq(last_x, 0); litest_assert_double_eq(last_y, libinput_max_y); @@ -1111,9 +1111,9 @@ START_TEST(left_handed) tablet_event = libinput_event_get_tablet_event(event); x = libinput_event_tablet_get_axis_value( - tablet_event, LIBINPUT_TABLET_AXIS_X); + tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); y = libinput_event_tablet_get_axis_value( - tablet_event, LIBINPUT_TABLET_AXIS_Y); + tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); litest_assert_double_eq(x, libinput_max_x); litest_assert_double_eq(y, 0); @@ -1139,9 +1139,9 @@ START_TEST(left_handed) tablet_event = libinput_event_get_tablet_event(event); last_x = libinput_event_tablet_get_axis_value( - tablet_event, LIBINPUT_TABLET_AXIS_X); + tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); last_y = libinput_event_tablet_get_axis_value( - tablet_event, LIBINPUT_TABLET_AXIS_Y); + tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); litest_assert_double_eq(last_x, libinput_max_x); litest_assert_double_eq(last_y, 0); @@ -1157,9 +1157,9 @@ START_TEST(left_handed) tablet_event = libinput_event_get_tablet_event(event); x = libinput_event_tablet_get_axis_value( - tablet_event, LIBINPUT_TABLET_AXIS_X); + tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); y = libinput_event_tablet_get_axis_value( - tablet_event, LIBINPUT_TABLET_AXIS_Y); + tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); litest_assert_double_eq(x, 0); litest_assert_double_eq(y, libinput_max_y); @@ -1217,9 +1217,9 @@ START_TEST(motion_event_state) ck_assert_notnull(tablet_event); last_x = libinput_event_tablet_get_axis_value(tablet_event, - LIBINPUT_TABLET_AXIS_X); + LIBINPUT_TABLET_TOOL_AXIS_X); last_y = libinput_event_tablet_get_axis_value(tablet_event, - LIBINPUT_TABLET_AXIS_Y); + LIBINPUT_TABLET_TOOL_AXIS_Y); /* mark with a button event, then go back to bottom/left */ litest_event(dev, EV_KEY, BTN_STYLUS, 1); @@ -1245,9 +1245,9 @@ START_TEST(motion_event_state) ck_assert_notnull(tablet_event); x = libinput_event_tablet_get_axis_value(tablet_event, - LIBINPUT_TABLET_AXIS_X); + LIBINPUT_TABLET_TOOL_AXIS_X); y = libinput_event_tablet_get_axis_value(tablet_event, - LIBINPUT_TABLET_AXIS_Y); + LIBINPUT_TABLET_TOOL_AXIS_Y); ck_assert(x > last_x); ck_assert(y < last_y); @@ -1336,31 +1336,31 @@ START_TEST(normalization) if (libinput_event_tablet_axis_has_changed( tablet_event, - LIBINPUT_TABLET_AXIS_PRESSURE)) { + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) { pressure = libinput_event_tablet_get_axis_value( - tablet_event, LIBINPUT_TABLET_AXIS_PRESSURE); + tablet_event, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); litest_assert_double_eq(pressure, 0); } if (libinput_event_tablet_axis_has_changed( tablet_event, - LIBINPUT_TABLET_AXIS_TILT_X)) { + LIBINPUT_TABLET_TOOL_AXIS_TILT_X)) { tilt_vertical = libinput_event_tablet_get_axis_value( tablet_event, - LIBINPUT_TABLET_AXIS_TILT_X); + LIBINPUT_TABLET_TOOL_AXIS_TILT_X); litest_assert_double_eq(tilt_vertical, -1); } if (libinput_event_tablet_axis_has_changed( tablet_event, - LIBINPUT_TABLET_AXIS_TILT_Y)) { + LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { tilt_horizontal = libinput_event_tablet_get_axis_value( tablet_event, - LIBINPUT_TABLET_AXIS_TILT_Y); + LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); litest_assert_double_eq(tilt_horizontal, -1); } @@ -1398,31 +1398,31 @@ START_TEST(normalization) if (libinput_event_tablet_axis_has_changed( tablet_event, - LIBINPUT_TABLET_AXIS_PRESSURE)) { + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) { pressure = libinput_event_tablet_get_axis_value( - tablet_event, LIBINPUT_TABLET_AXIS_PRESSURE); + tablet_event, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); litest_assert_double_eq(pressure, 1); } if (libinput_event_tablet_axis_has_changed( tablet_event, - LIBINPUT_TABLET_AXIS_TILT_X)) { + LIBINPUT_TABLET_TOOL_AXIS_TILT_X)) { tilt_vertical = libinput_event_tablet_get_axis_value( tablet_event, - LIBINPUT_TABLET_AXIS_TILT_X); + LIBINPUT_TABLET_TOOL_AXIS_TILT_X); litest_assert_double_eq(tilt_vertical, 1); } if (libinput_event_tablet_axis_has_changed( tablet_event, - LIBINPUT_TABLET_AXIS_TILT_Y)) { + LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { tilt_horizontal = libinput_event_tablet_get_axis_value( tablet_event, - LIBINPUT_TABLET_AXIS_TILT_Y); + LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); litest_assert_double_eq(tilt_horizontal, 1); } @@ -1733,13 +1733,13 @@ START_TEST(tool_capabilities) tool = libinput_event_tablet_get_tool(t); ck_assert(libinput_tool_has_axis(tool, - LIBINPUT_TABLET_AXIS_PRESSURE)); + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)); ck_assert(libinput_tool_has_axis(tool, - LIBINPUT_TABLET_AXIS_DISTANCE)); + LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)); ck_assert(!libinput_tool_has_axis(tool, - LIBINPUT_TABLET_AXIS_TILT_X)); + LIBINPUT_TABLET_TOOL_AXIS_TILT_X)); ck_assert(!libinput_tool_has_axis(tool, - LIBINPUT_TABLET_AXIS_TILT_Y)); + LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)); libinput_event_destroy(event); litest_assert_empty_queue(li); @@ -1756,13 +1756,13 @@ START_TEST(tool_capabilities) tool = libinput_event_tablet_get_tool(t); ck_assert(libinput_tool_has_axis(tool, - LIBINPUT_TABLET_AXIS_PRESSURE)); + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)); ck_assert(libinput_tool_has_axis(tool, - LIBINPUT_TABLET_AXIS_DISTANCE)); + LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)); ck_assert(libinput_tool_has_axis(tool, - LIBINPUT_TABLET_AXIS_TILT_X)); + LIBINPUT_TABLET_TOOL_AXIS_TILT_X)); ck_assert(libinput_tool_has_axis(tool, - LIBINPUT_TABLET_AXIS_TILT_Y)); + LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)); libinput_event_destroy(event); litest_assert_empty_queue(li); @@ -1978,9 +1978,9 @@ START_TEST(mouse_rotation) 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)); + LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)); val = libinput_event_tablet_get_axis_value(tev, - LIBINPUT_TABLET_AXIS_ROTATION_Z); + LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); /* rounding error galore, we can't test for anything more precise than these */ @@ -2030,7 +2030,7 @@ START_TEST(mouse_wheel) libinput_event_destroy(event); ck_assert(libinput_tool_has_axis(tool, - LIBINPUT_TABLET_AXIS_REL_WHEEL)); + LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL)); for (i = 0; i < 3; i++) { litest_event(dev, EV_REL, REL_WHEEL, -1); @@ -2041,17 +2041,17 @@ START_TEST(mouse_wheel) 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)); + LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL)); val = libinput_event_tablet_get_axis_value(tev, - LIBINPUT_TABLET_AXIS_REL_WHEEL); + LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); ck_assert_int_eq(val, 0); val = libinput_event_tablet_get_axis_delta(tev, - LIBINPUT_TABLET_AXIS_REL_WHEEL); + LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); ck_assert_int_eq(val, 15); val = libinput_event_tablet_get_axis_delta_discrete(tev, - LIBINPUT_TABLET_AXIS_REL_WHEEL); + LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); ck_assert_int_eq(val, 1); libinput_event_destroy(event); @@ -2072,17 +2072,17 @@ START_TEST(mouse_wheel) 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)); + LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL)); val = libinput_event_tablet_get_axis_value(tev, - LIBINPUT_TABLET_AXIS_REL_WHEEL); + LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); ck_assert_int_eq(val, 0); val = libinput_event_tablet_get_axis_delta(tev, - LIBINPUT_TABLET_AXIS_REL_WHEEL); + LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); ck_assert_int_eq(val, 0); val = libinput_event_tablet_get_axis_delta_discrete(tev, - LIBINPUT_TABLET_AXIS_ROTATION_Z); + LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); ck_assert_int_eq(val, 0); libinput_event_destroy(event); @@ -2169,9 +2169,9 @@ START_TEST(airbrush_wheel) 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)); + LIBINPUT_TABLET_TOOL_AXIS_SLIDER)); val = libinput_event_tablet_get_axis_value(tev, - LIBINPUT_TABLET_AXIS_SLIDER); + LIBINPUT_TABLET_TOOL_AXIS_SLIDER); ck_assert_int_eq(val, (v - abs->minimum)/scale); libinput_event_destroy(event); @@ -2210,7 +2210,7 @@ START_TEST(artpen_tool) ck_assert_int_eq(libinput_tool_get_type(tool), LIBINPUT_TOOL_TYPE_PEN); ck_assert(libinput_tool_has_axis(tool, - LIBINPUT_TABLET_AXIS_ROTATION_Z)); + LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)); libinput_event_destroy(event); } @@ -2260,15 +2260,15 @@ START_TEST(artpen_rotation) 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)); + LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)); val = libinput_event_tablet_get_axis_value(tev, - LIBINPUT_TABLET_AXIS_ROTATION_Z); + LIBINPUT_TABLET_TOOL_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); + LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); ck_assert_int_eq(val, 8); libinput_event_destroy(event); diff --git a/tools/event-debug.c b/tools/event-debug.c index b7237abb..61969106 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -345,91 +345,91 @@ print_tablet_axes(struct libinput_event_tablet *t) 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); + x = libinput_event_tablet_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_X); + y = libinput_event_tablet_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_Y); + dx = libinput_event_tablet_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_X); + dy = libinput_event_tablet_get_axis_delta(t, LIBINPUT_TABLET_TOOL_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), + x, tablet_axis_changed_sym(t, LIBINPUT_TABLET_TOOL_AXIS_X), + y, tablet_axis_changed_sym(t, LIBINPUT_TABLET_TOOL_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)) { + if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) || + libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { x = libinput_event_tablet_get_axis_value(t, - LIBINPUT_TABLET_AXIS_TILT_X); + LIBINPUT_TABLET_TOOL_AXIS_TILT_X); y = libinput_event_tablet_get_axis_value(t, - LIBINPUT_TABLET_AXIS_TILT_Y); + LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); dx = libinput_event_tablet_get_axis_delta(t, - LIBINPUT_TABLET_AXIS_TILT_X); + LIBINPUT_TABLET_TOOL_AXIS_TILT_X); dy = libinput_event_tablet_get_axis_delta(t, - LIBINPUT_TABLET_AXIS_TILT_Y); + LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); printf("\ttilt: %.2f%s/%.2f%s (%.2f/%.2f)", x, tablet_axis_changed_sym(t, - LIBINPUT_TABLET_AXIS_TILT_X), + LIBINPUT_TABLET_TOOL_AXIS_TILT_X), y, tablet_axis_changed_sym(t, - LIBINPUT_TABLET_AXIS_TILT_Y), + LIBINPUT_TABLET_TOOL_AXIS_TILT_Y), dx, dy); } - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_DISTANCE) || - libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_PRESSURE)) { + if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE) || + libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) { dist = libinput_event_tablet_get_axis_value(t, - LIBINPUT_TABLET_AXIS_DISTANCE); + LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); pressure = libinput_event_tablet_get_axis_value(t, - LIBINPUT_TABLET_AXIS_PRESSURE); + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); if (dist) { delta = libinput_event_tablet_get_axis_delta(t, - LIBINPUT_TABLET_AXIS_DISTANCE); + LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); printf("\tdistance: %.2f%s (%.2f)", dist, tablet_axis_changed_sym(t, - LIBINPUT_TABLET_AXIS_DISTANCE), + LIBINPUT_TABLET_TOOL_AXIS_DISTANCE), delta); } else { delta = libinput_event_tablet_get_axis_delta(t, - LIBINPUT_TABLET_AXIS_PRESSURE); + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); printf("\tpressure: %.2f%s (%.2f)", pressure, tablet_axis_changed_sym(t, - LIBINPUT_TABLET_AXIS_PRESSURE), + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE), delta); } } - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_ROTATION_Z)) { + if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)) { rotation = libinput_event_tablet_get_axis_value(t, - LIBINPUT_TABLET_AXIS_ROTATION_Z); + LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); delta = libinput_event_tablet_get_axis_delta(t, - LIBINPUT_TABLET_AXIS_ROTATION_Z); + LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); printf("\trotation: %.2f%s (%.2f)", rotation, tablet_axis_changed_sym(t, - LIBINPUT_TABLET_AXIS_ROTATION_Z), + LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z), delta); } - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_SLIDER)) { + if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_SLIDER)) { slider = libinput_event_tablet_get_axis_value(t, - LIBINPUT_TABLET_AXIS_SLIDER); + LIBINPUT_TABLET_TOOL_AXIS_SLIDER); delta = libinput_event_tablet_get_axis_delta(t, - LIBINPUT_TABLET_AXIS_SLIDER); + LIBINPUT_TABLET_TOOL_AXIS_SLIDER); printf("\tslider: %.2f%s (%.2f)", slider, tablet_axis_changed_sym(t, - LIBINPUT_TABLET_AXIS_SLIDER), + LIBINPUT_TABLET_TOOL_AXIS_SLIDER), delta); } - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_REL_WHEEL)) { + if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL)) { wheel = libinput_event_tablet_get_axis_value(t, - LIBINPUT_TABLET_AXIS_REL_WHEEL); + LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); delta = libinput_event_tablet_get_axis_delta_discrete(t, - LIBINPUT_TABLET_AXIS_REL_WHEEL); + LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); printf("\twheel: %.2f%s (%d)", wheel, tablet_axis_changed_sym(t, - LIBINPUT_TABLET_AXIS_REL_WHEEL), + LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL), (int)delta); } } @@ -512,18 +512,18 @@ print_proximity_event(struct libinput_event *ev) state_str); printf("\taxes:"); - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_DISTANCE)) + if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) printf("d"); - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_PRESSURE)) + if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_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)) + if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) || + libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) printf("t"); - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_ROTATION_Z)) + if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)) printf("r"); - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_SLIDER)) + if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_SLIDER)) printf("s"); - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_AXIS_REL_WHEEL)) + if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL)) printf("w"); printf("\tbtn:"); diff --git a/tools/event-gui.c b/tools/event-gui.c index a7d8dd93..1a4f242c 100644 --- a/tools/event-gui.c +++ b/tools/event-gui.c @@ -625,13 +625,13 @@ handle_event_tablet(struct libinput_event *ev, struct window *w) w->tool.y = libinput_event_tablet_get_y_transformed(t, w->height); w->tool.pressure = libinput_event_tablet_get_axis_value(t, - LIBINPUT_TABLET_AXIS_PRESSURE); + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); w->tool.distance = libinput_event_tablet_get_axis_value(t, - LIBINPUT_TABLET_AXIS_DISTANCE); + LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); w->tool.tilt_x = libinput_event_tablet_get_axis_value(t, - LIBINPUT_TABLET_AXIS_TILT_X); + LIBINPUT_TABLET_TOOL_AXIS_TILT_X); w->tool.tilt_y = libinput_event_tablet_get_axis_value(t, - LIBINPUT_TABLET_AXIS_TILT_Y); + LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); break; case LIBINPUT_EVENT_TABLET_TIP: x = libinput_event_tablet_get_x_transformed(t, w->width); From b85d57fdf8a02a32ec2bf3f9b0aef7f3b4feaa63 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 16 Nov 2015 15:39:07 +1000 Subject: [PATCH 166/255] tablet: rename libinput_tool_type to libinput_tablet_tool_type Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 12 ++++++------ src/evdev-tablet.h | 4 ++-- src/libinput-private.h | 2 +- src/libinput.c | 2 +- src/libinput.h | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 4f9465ed..1afc0447 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -186,7 +186,7 @@ tablet_change_to_left_handed(struct evdev_device *device) static void tablet_update_tool(struct tablet_dispatch *tablet, struct evdev_device *device, - enum libinput_tool_type tool, + enum libinput_tablet_tool_type tool, bool enabled) { assert(tool != LIBINPUT_TOOL_NONE); @@ -460,10 +460,10 @@ tablet_update_button(struct tablet_dispatch *tablet, } } -static inline enum libinput_tool_type +static inline enum libinput_tablet_tool_type tablet_evcode_to_tool(int code) { - enum libinput_tool_type type; + enum libinput_tablet_tool_type type; switch (code) { case BTN_TOOL_PEN: type = LIBINPUT_TOOL_TYPE_PEN; break; @@ -670,7 +670,7 @@ static void tool_set_bits(const struct tablet_dispatch *tablet, struct libinput_tablet_tool *tool) { - enum libinput_tool_type type = tool->type; + enum libinput_tablet_tool_type type = tool->type; #if HAVE_LIBWACOM if (tool_set_bits_from_libwacom(tablet, tool) == 0) @@ -728,7 +728,7 @@ tool_set_bits(const struct tablet_dispatch *tablet, static struct libinput_tablet_tool * tablet_get_tool(struct tablet_dispatch *tablet, - enum libinput_tool_type type, + enum libinput_tablet_tool_type type, uint32_t tool_id, uint32_t serial) { @@ -1020,7 +1020,7 @@ tablet_check_initial_proximity(struct evdev_device *device, { bool tool_in_prox = false; int code, state; - enum libinput_tool_type tool; + enum libinput_tablet_tool_type tool; struct tablet_dispatch *tablet = (struct tablet_dispatch*)dispatch; for (tool = LIBINPUT_TOOL_TYPE_PEN; tool <= LIBINPUT_TOOL_TYPE_MAX; tool++) { diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index e88d87c2..fb5ddb73 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -62,7 +62,7 @@ struct tablet_dispatch { struct button_state button_state; struct button_state prev_button_state; - enum libinput_tool_type current_tool_type; + enum libinput_tablet_tool_type current_tool_type; uint32_t current_tool_id; uint32_t current_tool_serial; }; @@ -160,7 +160,7 @@ axis_to_evcode(const enum libinput_tablet_tool_axis axis) } static inline int -tablet_tool_to_evcode(enum libinput_tool_type type) +tablet_tool_to_evcode(enum libinput_tablet_tool_type type) { int code; diff --git a/src/libinput-private.h b/src/libinput-private.h index 96a38d29..394fd9b7 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -254,7 +254,7 @@ struct libinput_tablet_tool { struct list link; uint32_t serial; uint32_t tool_id; - enum libinput_tool_type type; + enum libinput_tablet_tool_type type; unsigned char axis_caps[NCHARS(LIBINPUT_TABLET_TOOL_AXIS_MAX + 1)]; unsigned char buttons[NCHARS(KEY_MAX) + 1]; int refcount; diff --git a/src/libinput.c b/src/libinput.c index 9d35927e..bef02bb1 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1164,7 +1164,7 @@ libinput_event_tablet_get_seat_button_count(struct libinput_event_tablet *event) return event->seat_button_count; } -LIBINPUT_EXPORT enum libinput_tool_type +LIBINPUT_EXPORT enum libinput_tablet_tool_type libinput_tool_get_type(struct libinput_tablet_tool *tool) { return tool->type; diff --git a/src/libinput.h b/src/libinput.h index 853367c4..07b07419 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -180,12 +180,12 @@ struct libinput_tablet_tool; * 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 + * @note The @ref libinput_tablet_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_TYPE_PEN. */ -enum libinput_tool_type { +enum libinput_tablet_tool_type { LIBINPUT_TOOL_TYPE_PEN = 1, /**< A generic pen */ LIBINPUT_TOOL_TYPE_ERASER, /**< Eraser */ LIBINPUT_TOOL_TYPE_BRUSH, /**< A paintbrush-like tool */ @@ -1613,7 +1613,7 @@ libinput_event_tablet_get_time_usec(struct libinput_event_tablet *event); * * @see libinput_tool_get_tool_id */ -enum libinput_tool_type +enum libinput_tablet_tool_type libinput_tool_get_type(struct libinput_tablet_tool *tool); /** From c7cb77b36f68ac012f6bffa4fd667cd09b5c874d Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 16 Nov 2015 15:40:43 +1000 Subject: [PATCH 167/255] tablet: rename TOOL_TYPE to TABLET_TOOL_TYPE Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 54 ++++++++++++++++++++++----------------------- src/evdev-tablet.h | 18 +++++++-------- src/libinput.h | 26 +++++++++++----------- test/tablet.c | 8 +++---- tools/event-debug.c | 16 +++++++------- 5 files changed, 61 insertions(+), 61 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 1afc0447..3dfc0052 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -341,8 +341,8 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, /* ROTATION_Z is higher than TILT_X/Y so we know that the tilt axes are already normalized and set */ if (a == LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z && - (tablet->current_tool_type == LIBINPUT_TOOL_TYPE_MOUSE || - tablet->current_tool_type == LIBINPUT_TOOL_TYPE_LENS)) { + (tablet->current_tool_type == LIBINPUT_TABLET_TOOL_TYPE_MOUSE || + tablet->current_tool_type == LIBINPUT_TABLET_TOOL_TYPE_LENS)) { convert_tilt_to_rotation(tablet); axes[LIBINPUT_TABLET_TOOL_AXIS_TILT_X] = 0; axes[LIBINPUT_TABLET_TOOL_AXIS_TILT_Y] = 0; @@ -466,14 +466,14 @@ tablet_evcode_to_tool(int code) enum libinput_tablet_tool_type type; switch (code) { - case BTN_TOOL_PEN: type = LIBINPUT_TOOL_TYPE_PEN; break; - case BTN_TOOL_RUBBER: type = LIBINPUT_TOOL_TYPE_ERASER; break; - case BTN_TOOL_BRUSH: type = LIBINPUT_TOOL_TYPE_BRUSH; break; - case BTN_TOOL_PENCIL: type = LIBINPUT_TOOL_TYPE_PENCIL; break; - case BTN_TOOL_AIRBRUSH: type = LIBINPUT_TOOL_TYPE_AIRBRUSH; break; - case BTN_TOOL_FINGER: type = LIBINPUT_TOOL_TYPE_FINGER; break; - case BTN_TOOL_MOUSE: type = LIBINPUT_TOOL_TYPE_MOUSE; break; - case BTN_TOOL_LENS: type = LIBINPUT_TOOL_TYPE_LENS; break; + case BTN_TOOL_PEN: type = LIBINPUT_TABLET_TOOL_TYPE_PEN; break; + case BTN_TOOL_RUBBER: type = LIBINPUT_TABLET_TOOL_TYPE_ERASER; break; + case BTN_TOOL_BRUSH: type = LIBINPUT_TABLET_TOOL_TYPE_BRUSH; break; + case BTN_TOOL_PENCIL: type = LIBINPUT_TABLET_TOOL_TYPE_PENCIL; break; + case BTN_TOOL_AIRBRUSH: type = LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH; break; + case BTN_TOOL_FINGER: type = LIBINPUT_TABLET_TOOL_TYPE_FINGER; break; + case BTN_TOOL_MOUSE: type = LIBINPUT_TABLET_TOOL_TYPE_MOUSE; break; + case BTN_TOOL_LENS: type = LIBINPUT_TABLET_TOOL_TYPE_LENS; break; default: abort(); } @@ -681,11 +681,11 @@ tool_set_bits(const struct tablet_dispatch *tablet, anyway. */ switch (type) { - case LIBINPUT_TOOL_TYPE_PEN: - case LIBINPUT_TOOL_TYPE_ERASER: - case LIBINPUT_TOOL_TYPE_PENCIL: - case LIBINPUT_TOOL_TYPE_BRUSH: - case LIBINPUT_TOOL_TYPE_AIRBRUSH: + case LIBINPUT_TABLET_TOOL_TYPE_PEN: + case LIBINPUT_TABLET_TOOL_TYPE_ERASER: + case LIBINPUT_TABLET_TOOL_TYPE_PENCIL: + case LIBINPUT_TABLET_TOOL_TYPE_BRUSH: + case LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH: copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X); @@ -693,8 +693,8 @@ tool_set_bits(const struct tablet_dispatch *tablet, copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_SLIDER); copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); break; - case LIBINPUT_TOOL_TYPE_MOUSE: - case LIBINPUT_TOOL_TYPE_LENS: + case LIBINPUT_TABLET_TOOL_TYPE_MOUSE: + case LIBINPUT_TABLET_TOOL_TYPE_LENS: copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); break; @@ -705,16 +705,16 @@ tool_set_bits(const struct tablet_dispatch *tablet, /* If we don't have libwacom, copy all pen-related ones from the tablet vs all mouse-related ones */ switch (type) { - case LIBINPUT_TOOL_TYPE_PEN: - case LIBINPUT_TOOL_TYPE_BRUSH: - case LIBINPUT_TOOL_TYPE_AIRBRUSH: - case LIBINPUT_TOOL_TYPE_PENCIL: - case LIBINPUT_TOOL_TYPE_ERASER: + case LIBINPUT_TABLET_TOOL_TYPE_PEN: + case LIBINPUT_TABLET_TOOL_TYPE_BRUSH: + case LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH: + case LIBINPUT_TABLET_TOOL_TYPE_PENCIL: + case LIBINPUT_TABLET_TOOL_TYPE_ERASER: copy_button_cap(tablet, tool, BTN_STYLUS); copy_button_cap(tablet, tool, BTN_STYLUS2); break; - case LIBINPUT_TOOL_TYPE_MOUSE: - case LIBINPUT_TOOL_TYPE_LENS: + case LIBINPUT_TABLET_TOOL_TYPE_MOUSE: + case LIBINPUT_TABLET_TOOL_TYPE_LENS: copy_button_cap(tablet, tool, BTN_LEFT); copy_button_cap(tablet, tool, BTN_MIDDLE); copy_button_cap(tablet, tool, BTN_RIGHT); @@ -864,8 +864,8 @@ sanitize_tablet_axes(struct tablet_dispatch *tablet) /* 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_TYPE_MOUSE || - tablet->current_tool_type == LIBINPUT_TOOL_TYPE_LENS) && + if ((tablet->current_tool_type == LIBINPUT_TABLET_TOOL_TYPE_MOUSE || + tablet->current_tool_type == LIBINPUT_TABLET_TOOL_TYPE_LENS) && (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) || bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y))) set_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); @@ -1023,7 +1023,7 @@ tablet_check_initial_proximity(struct evdev_device *device, enum libinput_tablet_tool_type tool; struct tablet_dispatch *tablet = (struct tablet_dispatch*)dispatch; - for (tool = LIBINPUT_TOOL_TYPE_PEN; tool <= LIBINPUT_TOOL_TYPE_MAX; tool++) { + for (tool = LIBINPUT_TABLET_TOOL_TYPE_PEN; tool <= LIBINPUT_TABLET_TOOL_TYPE_MAX; tool++) { code = tablet_tool_to_evcode(tool); /* we only expect one tool to be in proximity at a time */ diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index fb5ddb73..aafeda9d 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -28,7 +28,7 @@ #define LIBINPUT_TABLET_TOOL_AXIS_NONE 0 #define LIBINPUT_TOOL_NONE 0 -#define LIBINPUT_TOOL_TYPE_MAX LIBINPUT_TOOL_TYPE_LENS +#define LIBINPUT_TABLET_TOOL_TYPE_MAX LIBINPUT_TABLET_TOOL_TYPE_LENS enum tablet_status { TABLET_NONE = 0, @@ -165,14 +165,14 @@ tablet_tool_to_evcode(enum libinput_tablet_tool_type type) int code; switch (type) { - case LIBINPUT_TOOL_TYPE_PEN: code = BTN_TOOL_PEN; break; - case LIBINPUT_TOOL_TYPE_ERASER: code = BTN_TOOL_RUBBER; break; - case LIBINPUT_TOOL_TYPE_BRUSH: code = BTN_TOOL_BRUSH; break; - case LIBINPUT_TOOL_TYPE_PENCIL: code = BTN_TOOL_PENCIL; break; - case LIBINPUT_TOOL_TYPE_AIRBRUSH: code = BTN_TOOL_AIRBRUSH; break; - case LIBINPUT_TOOL_TYPE_FINGER: code = BTN_TOOL_FINGER; break; - case LIBINPUT_TOOL_TYPE_MOUSE: code = BTN_TOOL_MOUSE; break; - case LIBINPUT_TOOL_TYPE_LENS: code = BTN_TOOL_LENS; break; + case LIBINPUT_TABLET_TOOL_TYPE_PEN: code = BTN_TOOL_PEN; break; + case LIBINPUT_TABLET_TOOL_TYPE_ERASER: code = BTN_TOOL_RUBBER; break; + case LIBINPUT_TABLET_TOOL_TYPE_BRUSH: code = BTN_TOOL_BRUSH; break; + case LIBINPUT_TABLET_TOOL_TYPE_PENCIL: code = BTN_TOOL_PENCIL; break; + case LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH: code = BTN_TOOL_AIRBRUSH; break; + case LIBINPUT_TABLET_TOOL_TYPE_FINGER: code = BTN_TOOL_FINGER; break; + case LIBINPUT_TABLET_TOOL_TYPE_MOUSE: code = BTN_TOOL_MOUSE; break; + case LIBINPUT_TABLET_TOOL_TYPE_LENS: code = BTN_TOOL_LENS; break; default: abort(); } diff --git a/src/libinput.h b/src/libinput.h index 07b07419..b83a6fcc 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -173,7 +173,7 @@ struct libinput_tablet_tool; * 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_TYPE_PEN. + * LIBINPUT_TABLET_TOOL_TYPE_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 @@ -183,18 +183,18 @@ struct libinput_tablet_tool; * @note The @ref libinput_tablet_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_TYPE_PEN. + * classic pen leaves the tool type as @ref LIBINPUT_TABLET_TOOL_TYPE_PEN. */ enum libinput_tablet_tool_type { - LIBINPUT_TOOL_TYPE_PEN = 1, /**< A generic pen */ - LIBINPUT_TOOL_TYPE_ERASER, /**< Eraser */ - LIBINPUT_TOOL_TYPE_BRUSH, /**< A paintbrush-like tool */ - LIBINPUT_TOOL_TYPE_PENCIL, /**< Physical drawing tool, e.g. - Wacom Inking Pen */ - LIBINPUT_TOOL_TYPE_AIRBRUSH, /**< An airbrush-like tool */ - LIBINPUT_TOOL_TYPE_FINGER, /**< Touch */ - LIBINPUT_TOOL_TYPE_MOUSE, /**< A mouse bound to the tablet */ - LIBINPUT_TOOL_TYPE_LENS, /**< A mouse tool with a lens */ + LIBINPUT_TABLET_TOOL_TYPE_PEN = 1, /**< A generic pen */ + LIBINPUT_TABLET_TOOL_TYPE_ERASER, /**< Eraser */ + LIBINPUT_TABLET_TOOL_TYPE_BRUSH, /**< A paintbrush-like tool */ + LIBINPUT_TABLET_TOOL_TYPE_PENCIL, /**< Physical drawing tool, e.g. + Wacom Inking Pen */ + LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH, /**< An airbrush-like tool */ + LIBINPUT_TABLET_TOOL_TYPE_FINGER, /**< Touch */ + LIBINPUT_TABLET_TOOL_TYPE_MOUSE, /**< A mouse bound to the tablet */ + LIBINPUT_TABLET_TOOL_TYPE_LENS, /**< A mouse tool with a lens */ }; /** @@ -1392,9 +1392,9 @@ libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, * tool * - @ref LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z - The z rotation of the tool in * degrees, clockwise from the tool's logical neutral position. For the - * @ref LIBINPUT_TOOL_TYPE_MOUSE and @ref LIBINPUT_TOOL_TYPE_LENS tools + * @ref LIBINPUT_TABLET_TOOL_TYPE_MOUSE and @ref LIBINPUT_TABLET_TOOL_TYPE_LENS tools * the logical neutral position is pointing to the current logical north - * of the tablet. For the @ref LIBINPUT_TOOL_TYPE_BRUSH tool, the logical + * of the tablet. For the @ref LIBINPUT_TABLET_TOOL_TYPE_BRUSH tool, the logical * neutral position is with the buttons pointing up. * - @ref LIBINPUT_TABLET_TOOL_AXIS_SLIDER - A slider on the tool, normalized * from 0 to 1. e.g. the wheel-like tool on the Wacom Airbrush. diff --git a/test/tablet.c b/test/tablet.c index 71fca967..0e77a207 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -593,7 +593,7 @@ START_TEST(proximity_in_out) 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_TYPE_PEN); + LIBINPUT_TABLET_TOOL_TYPE_PEN); } libinput_event_destroy(event); } @@ -1852,7 +1852,7 @@ START_TEST(mouse_tool) tool = libinput_event_tablet_get_tool(tev); ck_assert_notnull(tool); ck_assert_int_eq(libinput_tool_get_type(tool), - LIBINPUT_TOOL_TYPE_MOUSE); + LIBINPUT_TABLET_TOOL_TYPE_MOUSE); libinput_event_destroy(event); } @@ -2121,7 +2121,7 @@ START_TEST(airbrush_tool) tool = libinput_event_tablet_get_tool(tev); ck_assert_notnull(tool); ck_assert_int_eq(libinput_tool_get_type(tool), - LIBINPUT_TOOL_TYPE_AIRBRUSH); + LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH); libinput_event_destroy(event); } @@ -2208,7 +2208,7 @@ START_TEST(artpen_tool) tool = libinput_event_tablet_get_tool(tev); ck_assert_notnull(tool); ck_assert_int_eq(libinput_tool_get_type(tool), - LIBINPUT_TOOL_TYPE_PEN); + LIBINPUT_TABLET_TOOL_TYPE_PEN); ck_assert(libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)); diff --git a/tools/event-debug.c b/tools/event-debug.c index 61969106..e4fe9ab7 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -463,28 +463,28 @@ print_proximity_event(struct libinput_event *ev) *state_str; switch (libinput_tool_get_type(tool)) { - case LIBINPUT_TOOL_TYPE_PEN: + case LIBINPUT_TABLET_TOOL_TYPE_PEN: tool_str = "pen"; break; - case LIBINPUT_TOOL_TYPE_ERASER: + case LIBINPUT_TABLET_TOOL_TYPE_ERASER: tool_str = "eraser"; break; - case LIBINPUT_TOOL_TYPE_BRUSH: + case LIBINPUT_TABLET_TOOL_TYPE_BRUSH: tool_str = "brush"; break; - case LIBINPUT_TOOL_TYPE_PENCIL: + case LIBINPUT_TABLET_TOOL_TYPE_PENCIL: tool_str = "pencil"; break; - case LIBINPUT_TOOL_TYPE_AIRBRUSH: + case LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH: tool_str = "airbrush"; break; - case LIBINPUT_TOOL_TYPE_FINGER: + case LIBINPUT_TABLET_TOOL_TYPE_FINGER: tool_str = "finger"; break; - case LIBINPUT_TOOL_TYPE_MOUSE: + case LIBINPUT_TABLET_TOOL_TYPE_MOUSE: tool_str = "mouse"; break; - case LIBINPUT_TOOL_TYPE_LENS: + case LIBINPUT_TABLET_TOOL_TYPE_LENS: tool_str = "lens"; break; default: From a22b94a22ca2c6e661ebe6903ebefd60100c4e1a Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 16 Nov 2015 15:41:48 +1000 Subject: [PATCH 168/255] tablet: rename tool_proximity_state to tablet_tool_proximity state Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/libinput-private.h | 2 +- src/libinput.c | 6 +++--- src/libinput.h | 4 ++-- tools/event-debug.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libinput-private.h b/src/libinput-private.h index 394fd9b7..a1f66b10 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -473,7 +473,7 @@ void tablet_notify_proximity(struct libinput_device *device, uint64_t time, struct libinput_tablet_tool *tool, - enum libinput_tool_proximity_state state, + enum libinput_tablet_tool_proximity_state state, unsigned char *changed_axes, double *axes); diff --git a/src/libinput.c b/src/libinput.c index bef02bb1..ab98d637 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -136,7 +136,7 @@ struct libinput_event_tablet { double deltas_discrete[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1]; unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_TOOL_AXIS_MAX + 1)]; struct libinput_tablet_tool *tool; - enum libinput_tool_proximity_state proximity_state; + enum libinput_tablet_tool_proximity_state proximity_state; enum libinput_tool_tip_state tip_state; }; @@ -1075,7 +1075,7 @@ libinput_event_tablet_get_tool(struct libinput_event_tablet *event) return event->tool; } -LIBINPUT_EXPORT enum libinput_tool_proximity_state +LIBINPUT_EXPORT enum libinput_tablet_tool_proximity_state libinput_event_tablet_get_proximity_state(struct libinput_event_tablet *event) { require_event_type(libinput_event_get_context(&event->base), @@ -2011,7 +2011,7 @@ void tablet_notify_proximity(struct libinput_device *device, uint64_t time, struct libinput_tablet_tool *tool, - enum libinput_tool_proximity_state proximity_state, + enum libinput_tablet_tool_proximity_state proximity_state, unsigned char *changed_axes, double *axes) { diff --git a/src/libinput.h b/src/libinput.h index b83a6fcc..ae3006b7 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -211,7 +211,7 @@ enum libinput_tablet_tool_type { * surface. On other hardware, the tool is still detectable within a short * distance (a few cm) off the surface. */ -enum libinput_tool_proximity_state { +enum libinput_tablet_tool_proximity_state { LIBINPUT_TOOL_PROXIMITY_OUT = 0, LIBINPUT_TOOL_PROXIMITY_IN = 1, }; @@ -1523,7 +1523,7 @@ libinput_event_tablet_get_tool(struct libinput_event_tablet *event); * @param event The libinput tablet event * @return The new proximity state of the tool from the event. */ -enum libinput_tool_proximity_state +enum libinput_tablet_tool_proximity_state libinput_event_tablet_get_proximity_state(struct libinput_event_tablet *event); /** diff --git a/tools/event-debug.c b/tools/event-debug.c index e4fe9ab7..af67f61f 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -458,7 +458,7 @@ print_proximity_event(struct libinput_event *ev) { struct libinput_event_tablet *t = libinput_event_get_tablet_event(ev); struct libinput_tablet_tool *tool = libinput_event_tablet_get_tool(t); - enum libinput_tool_proximity_state state; + enum libinput_tablet_tool_proximity_state state; const char *tool_str, *state_str; From cc2b45dd503933b806b44e83f6e9d3e448c8183e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 16 Nov 2015 15:42:31 +1000 Subject: [PATCH 169/255] tablet: rename TOOL_PROXIMITY_ to TABLET_TOOL_PROXIMITY Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 4 ++-- src/libinput.c | 6 +++--- src/libinput.h | 8 ++++---- test/tablet.c | 6 +++--- tools/event-debug.c | 4 ++-- tools/event-gui.c | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 3dfc0052..040582b8 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -403,7 +403,7 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, tablet_notify_proximity(&device->base, time, tool, - LIBINPUT_TOOL_PROXIMITY_IN, + LIBINPUT_TABLET_TOOL_PROXIMITY_IN, tablet->changed_axes, axes); else { @@ -945,7 +945,7 @@ tablet_flush(struct tablet_dispatch *tablet, tablet_notify_proximity(&device->base, time, tool, - LIBINPUT_TOOL_PROXIMITY_OUT, + LIBINPUT_TABLET_TOOL_PROXIMITY_OUT, tablet->changed_axes, tablet->axes); diff --git a/src/libinput.c b/src/libinput.c index ab98d637..bd33b25d 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1988,7 +1988,7 @@ tablet_notify_axis(struct libinput_device *device, *axis_event = (struct libinput_event_tablet) { .time = time, .tool = tool, - .proximity_state = LIBINPUT_TOOL_PROXIMITY_IN, + .proximity_state = LIBINPUT_TABLET_TOOL_PROXIMITY_IN, .tip_state = tip_state, }; @@ -2058,7 +2058,7 @@ tablet_notify_tip(struct libinput_device *device, .time = time, .tool = tool, .tip_state = tip_state, - .proximity_state = LIBINPUT_TOOL_PROXIMITY_IN, + .proximity_state = LIBINPUT_TABLET_TOOL_PROXIMITY_IN, }; memcpy(tip_event->axes, axes, @@ -2096,7 +2096,7 @@ tablet_notify_button(struct libinput_device *device, .button = button, .state = state, .seat_button_count = seat_button_count, - .proximity_state = LIBINPUT_TOOL_PROXIMITY_IN, + .proximity_state = LIBINPUT_TABLET_TOOL_PROXIMITY_IN, .tip_state = tip_state, }; memcpy(button_event->axes, axes, sizeof(button_event->axes)); diff --git a/src/libinput.h b/src/libinput.h index ae3006b7..2a563f82 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -212,8 +212,8 @@ enum libinput_tablet_tool_type { * distance (a few cm) off the surface. */ enum libinput_tablet_tool_proximity_state { - LIBINPUT_TOOL_PROXIMITY_OUT = 0, - LIBINPUT_TOOL_PROXIMITY_IN = 1, + LIBINPUT_TABLET_TOOL_PROXIMITY_OUT = 0, + LIBINPUT_TABLET_TOOL_PROXIMITY_IN = 1, }; /** @@ -299,9 +299,9 @@ enum libinput_event_type { * 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 + * type @ref LIBINPUT_TABLET_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_TABLET_TOOL_PROXIMITY_OUT are sent only once before @ref * LIBINPUT_EVENT_DEVICE_REMOVED. * * If the tool that comes into proximity supports x/y coordinates, diff --git a/test/tablet.c b/test/tablet.c index 0e77a207..50188d59 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -100,7 +100,7 @@ START_TEST(tip_down_prox_in) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_PROXIMITY); ck_assert_int_eq(libinput_event_tablet_get_proximity_state(tablet_event), - LIBINPUT_TOOL_PROXIMITY_IN); + LIBINPUT_TABLET_TOOL_PROXIMITY_IN); libinput_event_destroy(event); libinput_dispatch(li); @@ -150,7 +150,7 @@ START_TEST(tip_up_prox_out) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_PROXIMITY); ck_assert_int_eq(libinput_event_tablet_get_proximity_state(tablet_event), - LIBINPUT_TOOL_PROXIMITY_OUT); + LIBINPUT_TABLET_TOOL_PROXIMITY_OUT); libinput_event_destroy(event); litest_assert_empty_queue(li); @@ -609,7 +609,7 @@ START_TEST(proximity_in_out) libinput_event_get_tablet_event(event); if (libinput_event_tablet_get_proximity_state(t) == - LIBINPUT_TOOL_PROXIMITY_OUT) + LIBINPUT_TABLET_TOOL_PROXIMITY_OUT) have_proximity_out = true; } diff --git a/tools/event-debug.c b/tools/event-debug.c index af67f61f..5dc75054 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -495,10 +495,10 @@ print_proximity_event(struct libinput_event *ev) print_event_time(libinput_event_tablet_get_time(t)); - if (state == LIBINPUT_TOOL_PROXIMITY_IN) { + if (state == LIBINPUT_TABLET_TOOL_PROXIMITY_IN) { print_tablet_axes(t); state_str = "proximity-in"; - } else if (state == LIBINPUT_TOOL_PROXIMITY_OUT) { + } else if (state == LIBINPUT_TABLET_TOOL_PROXIMITY_OUT) { state_str = "proximity-out"; printf("\t"); } else { diff --git a/tools/event-gui.c b/tools/event-gui.c index 1a4f242c..f4f22db0 100644 --- a/tools/event-gui.c +++ b/tools/event-gui.c @@ -605,7 +605,7 @@ handle_event_tablet(struct libinput_event *ev, struct window *w) switch (libinput_event_get_type(ev)) { case LIBINPUT_EVENT_TABLET_PROXIMITY: if (libinput_event_tablet_get_proximity_state(t) == - LIBINPUT_TOOL_PROXIMITY_OUT) { + LIBINPUT_TABLET_TOOL_PROXIMITY_OUT) { w->tool.x_in = 0; w->tool.y_in = 0; w->tool.x_down = 0; From 7123c37f1c50eb450913902885f46e238a7befd1 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 16 Nov 2015 15:43:41 +1000 Subject: [PATCH 170/255] tablet: rename tool_tip_state to tablet_tool_tip_state Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 4 ++-- src/libinput-private.h | 6 +++--- src/libinput.c | 10 +++++----- src/libinput.h | 4 ++-- tools/event-debug.c | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 040582b8..871e10ed 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -407,7 +407,7 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, tablet->changed_axes, axes); else { - enum libinput_tool_tip_state tip_state; + enum libinput_tablet_tool_tip_state tip_state; tip_state = tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT) ? LIBINPUT_TOOL_TIP_DOWN : LIBINPUT_TOOL_TIP_UP; @@ -792,7 +792,7 @@ tablet_notify_button_mask(struct tablet_dispatch *tablet, struct libinput_device *base = &device->base; size_t i; size_t nbits = 8 * sizeof(buttons[0]) * buttons_len; - enum libinput_tool_tip_state tip_state; + enum libinput_tablet_tool_tip_state tip_state; tip_state = tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT) ? LIBINPUT_TOOL_TIP_DOWN : LIBINPUT_TOOL_TIP_UP; diff --git a/src/libinput-private.h b/src/libinput-private.h index a1f66b10..38a14b8f 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -463,7 +463,7 @@ void tablet_notify_axis(struct libinput_device *device, uint64_t time, struct libinput_tablet_tool *tool, - enum libinput_tool_tip_state tip_state, + enum libinput_tablet_tool_tip_state tip_state, unsigned char *changed_axes, double *axes, double *deltas, @@ -481,14 +481,14 @@ void tablet_notify_tip(struct libinput_device *device, uint64_t time, struct libinput_tablet_tool *tool, - enum libinput_tool_tip_state tip_state, + enum libinput_tablet_tool_tip_state tip_state, double *axes); void tablet_notify_button(struct libinput_device *device, uint64_t time, struct libinput_tablet_tool *tool, - enum libinput_tool_tip_state tip_state, + enum libinput_tablet_tool_tip_state tip_state, double *axes, int32_t button, enum libinput_button_state state); diff --git a/src/libinput.c b/src/libinput.c index bd33b25d..5308d8d4 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -137,7 +137,7 @@ struct libinput_event_tablet { unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_TOOL_AXIS_MAX + 1)]; struct libinput_tablet_tool *tool; enum libinput_tablet_tool_proximity_state proximity_state; - enum libinput_tool_tip_state tip_state; + enum libinput_tablet_tool_tip_state tip_state; }; static void @@ -1089,7 +1089,7 @@ libinput_event_tablet_get_proximity_state(struct libinput_event_tablet *event) return event->proximity_state; } -LIBINPUT_EXPORT enum libinput_tool_tip_state +LIBINPUT_EXPORT enum libinput_tablet_tool_tip_state libinput_event_tablet_get_tip_state(struct libinput_event_tablet *event) { require_event_type(libinput_event_get_context(&event->base), @@ -1973,7 +1973,7 @@ void tablet_notify_axis(struct libinput_device *device, uint64_t time, struct libinput_tablet_tool *tool, - enum libinput_tool_tip_state tip_state, + enum libinput_tablet_tool_tip_state tip_state, unsigned char *changed_axes, double *axes, double *deltas, @@ -2045,7 +2045,7 @@ void tablet_notify_tip(struct libinput_device *device, uint64_t time, struct libinput_tablet_tool *tool, - enum libinput_tool_tip_state tip_state, + enum libinput_tablet_tool_tip_state tip_state, double *axes) { struct libinput_event_tablet *tip_event; @@ -2074,7 +2074,7 @@ void tablet_notify_button(struct libinput_device *device, uint64_t time, struct libinput_tablet_tool *tool, - enum libinput_tool_tip_state tip_state, + enum libinput_tablet_tool_tip_state tip_state, double *axes, int32_t button, enum libinput_button_state state) diff --git a/src/libinput.h b/src/libinput.h index 2a563f82..a13700f6 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -225,7 +225,7 @@ enum libinput_tablet_tool_proximity_state { * The tip contact state of a tool is a binary state signalling whether the tool is * touching the surface of the tablet device. */ -enum libinput_tool_tip_state { +enum libinput_tablet_tool_tip_state { LIBINPUT_TOOL_TIP_UP = 0, LIBINPUT_TOOL_TIP_DOWN = 1, }; @@ -1537,7 +1537,7 @@ libinput_event_tablet_get_proximity_state(struct libinput_event_tablet *event); * @param event The libinput tablet event * @return The new tip state of the tool from the event. */ -enum libinput_tool_tip_state +enum libinput_tablet_tool_tip_state libinput_event_tablet_get_tip_state(struct libinput_event_tablet *event); /** diff --git a/tools/event-debug.c b/tools/event-debug.c index 5dc75054..75d8162e 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -285,7 +285,7 @@ static void print_tablet_tip_event(struct libinput_event *ev) { struct libinput_event_tablet *p = libinput_event_get_tablet_event(ev); - enum libinput_tool_tip_state state; + enum libinput_tablet_tool_tip_state state; print_event_time(libinput_event_tablet_get_time(p)); From 759ef0446596776ae5c716e6e335c7067953ce9b Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 16 Nov 2015 15:47:15 +1000 Subject: [PATCH 171/255] tablet: rename TOOL_TIP to TABLET_TOOL_TIP Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 8 ++++---- src/libinput.h | 4 ++-- test/tablet.c | 38 +++++++++++++++++++------------------- tools/event-debug.c | 2 +- tools/event-gui.c | 2 +- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 871e10ed..c1d69de0 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -410,7 +410,7 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, enum libinput_tablet_tool_tip_state tip_state; tip_state = tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT) ? - LIBINPUT_TOOL_TIP_DOWN : LIBINPUT_TOOL_TIP_UP; + LIBINPUT_TABLET_TOOL_TIP_DOWN : LIBINPUT_TABLET_TOOL_TIP_UP; tablet_notify_axis(base, time, tool, @@ -795,7 +795,7 @@ tablet_notify_button_mask(struct tablet_dispatch *tablet, enum libinput_tablet_tool_tip_state tip_state; tip_state = tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT) ? - LIBINPUT_TOOL_TIP_DOWN : LIBINPUT_TOOL_TIP_UP; + LIBINPUT_TABLET_TOOL_TIP_DOWN : LIBINPUT_TABLET_TOOL_TIP_UP; for (i = 0; i < nbits; i++) { if (!bit_is_set(buttons, i)) @@ -906,7 +906,7 @@ tablet_flush(struct tablet_dispatch *tablet, tablet_notify_tip(&device->base, time, tool, - LIBINPUT_TOOL_TIP_DOWN, + LIBINPUT_TABLET_TOOL_TIP_DOWN, tablet->axes); tablet_unset_status(tablet, TABLET_TOOL_ENTERING_CONTACT); tablet_set_status(tablet, TABLET_TOOL_IN_CONTACT); @@ -934,7 +934,7 @@ tablet_flush(struct tablet_dispatch *tablet, tablet_notify_tip(&device->base, time, tool, - LIBINPUT_TOOL_TIP_UP, + LIBINPUT_TABLET_TOOL_TIP_UP, tablet->axes); tablet_unset_status(tablet, TABLET_TOOL_LEAVING_CONTACT); tablet_unset_status(tablet, TABLET_TOOL_IN_CONTACT); diff --git a/src/libinput.h b/src/libinput.h index a13700f6..ff1eaa62 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -226,8 +226,8 @@ enum libinput_tablet_tool_proximity_state { * touching the surface of the tablet device. */ enum libinput_tablet_tool_tip_state { - LIBINPUT_TOOL_TIP_UP = 0, - LIBINPUT_TOOL_TIP_DOWN = 1, + LIBINPUT_TABLET_TOOL_TIP_UP = 0, + LIBINPUT_TABLET_TOOL_TIP_DOWN = 1, }; /** diff --git a/test/tablet.c b/test/tablet.c index 50188d59..7aa76b28 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -56,7 +56,7 @@ START_TEST(tip_down_up) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TIP); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), - LIBINPUT_TOOL_TIP_DOWN); + LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); litest_assert_empty_queue(li); @@ -68,7 +68,7 @@ START_TEST(tip_down_up) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TIP); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), - LIBINPUT_TOOL_TIP_UP); + LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); litest_assert_empty_queue(li); @@ -108,7 +108,7 @@ START_TEST(tip_down_prox_in) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TIP); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), - LIBINPUT_TOOL_TIP_DOWN); + LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); litest_assert_empty_queue(li); @@ -142,7 +142,7 @@ START_TEST(tip_up_prox_out) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TIP); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), - LIBINPUT_TOOL_TIP_UP); + LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); libinput_dispatch(li); @@ -193,7 +193,7 @@ START_TEST(tip_up_btn_change) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TIP); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), - LIBINPUT_TOOL_TIP_UP); + LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); litest_assert_empty_queue(li); @@ -222,7 +222,7 @@ START_TEST(tip_up_btn_change) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TIP); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), - LIBINPUT_TOOL_TIP_UP); + LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); litest_assert_empty_queue(li); @@ -252,7 +252,7 @@ START_TEST(tip_down_btn_change) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TIP); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), - LIBINPUT_TOOL_TIP_DOWN); + LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); libinput_dispatch(li); @@ -281,7 +281,7 @@ START_TEST(tip_down_btn_change) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TIP); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), - LIBINPUT_TOOL_TIP_DOWN); + LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); libinput_dispatch(li); @@ -334,7 +334,7 @@ START_TEST(tip_down_motion) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TIP); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), - LIBINPUT_TOOL_TIP_DOWN); + LIBINPUT_TABLET_TOOL_TIP_DOWN); x = libinput_event_tablet_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); y = libinput_event_tablet_get_axis_value(tablet_event, @@ -385,7 +385,7 @@ START_TEST(tip_up_motion) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TIP); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), - LIBINPUT_TOOL_TIP_UP); + LIBINPUT_TABLET_TOOL_TIP_UP); x = libinput_event_tablet_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); y = libinput_event_tablet_get_axis_value(tablet_event, @@ -418,7 +418,7 @@ START_TEST(tip_state_proximity) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_PROXIMITY); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), - LIBINPUT_TOOL_TIP_UP); + LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); litest_event(dev, EV_KEY, BTN_TOUCH, 1); @@ -434,7 +434,7 @@ START_TEST(tip_state_proximity) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_PROXIMITY); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), - LIBINPUT_TOOL_TIP_UP); + LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); } END_TEST @@ -460,7 +460,7 @@ START_TEST(tip_state_axis) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_AXIS); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), - LIBINPUT_TOOL_TIP_UP); + LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); litest_event(dev, EV_KEY, BTN_TOUCH, 1); @@ -474,7 +474,7 @@ START_TEST(tip_state_axis) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_AXIS); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), - LIBINPUT_TOOL_TIP_DOWN); + LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); litest_event(dev, EV_KEY, BTN_TOUCH, 0); @@ -488,7 +488,7 @@ START_TEST(tip_state_axis) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_AXIS); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), - LIBINPUT_TOOL_TIP_UP); + LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); litest_assert_empty_queue(li); @@ -517,7 +517,7 @@ START_TEST(tip_state_button) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_BUTTON); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), - LIBINPUT_TOOL_TIP_UP); + LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); litest_event(dev, EV_KEY, BTN_TOUCH, 1); @@ -532,7 +532,7 @@ START_TEST(tip_state_button) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_BUTTON); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), - LIBINPUT_TOOL_TIP_DOWN); + LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); litest_event(dev, EV_KEY, BTN_TOUCH, 0); @@ -547,7 +547,7 @@ START_TEST(tip_state_button) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_BUTTON); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), - LIBINPUT_TOOL_TIP_UP); + LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); litest_event(dev, EV_KEY, BTN_STYLUS, 0); @@ -558,7 +558,7 @@ START_TEST(tip_state_button) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_BUTTON); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), - LIBINPUT_TOOL_TIP_UP); + LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); litest_assert_empty_queue(li); diff --git a/tools/event-debug.c b/tools/event-debug.c index 75d8162e..c123917c 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -290,7 +290,7 @@ print_tablet_tip_event(struct libinput_event *ev) print_event_time(libinput_event_tablet_get_time(p)); state = libinput_event_tablet_get_tip_state(p); - printf("%s\n", state == LIBINPUT_TOOL_TIP_DOWN ? "down" : "up"); + printf("%s\n", state == LIBINPUT_TABLET_TOOL_TIP_DOWN ? "down" : "up"); } static void diff --git a/tools/event-gui.c b/tools/event-gui.c index f4f22db0..41993732 100644 --- a/tools/event-gui.c +++ b/tools/event-gui.c @@ -637,7 +637,7 @@ handle_event_tablet(struct libinput_event *ev, struct window *w) x = libinput_event_tablet_get_x_transformed(t, w->width); y = libinput_event_tablet_get_y_transformed(t, w->height); if (libinput_event_tablet_get_tip_state(t) == - LIBINPUT_TOOL_TIP_DOWN) { + LIBINPUT_TABLET_TOOL_TIP_DOWN) { w->tool.x_down = x; w->tool.y_down = y; } else { From b1b676e24a00be333911416ce7e002dd20ce5285 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 16 Nov 2015 16:26:56 +1000 Subject: [PATCH 172/255] tablet: rename the tablet capability to a tablet_tool capability Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev.c | 2 +- src/libinput.c | 2 +- src/libinput.h | 18 +++++++++--------- tools/event-debug.c | 2 +- tools/libinput-list-devices.c | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/evdev.c b/src/evdev.c index a3a72ef8..e2bbdc39 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -2418,7 +2418,7 @@ 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: + case LIBINPUT_DEVICE_CAP_TABLET_TOOL: return !!(device->seat_caps & EVDEV_DEVICE_TABLET); default: return 0; diff --git a/src/libinput.c b/src/libinput.c index 5308d8d4..708399f0 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1710,7 +1710,7 @@ device_has_cap(struct libinput_device *device, case LIBINPUT_DEVICE_CAP_GESTURE: capability = "CAP_GESTURE"; break; - case LIBINPUT_DEVICE_CAP_TABLET: + case LIBINPUT_DEVICE_CAP_TABLET_TOOL: capability = "CAP_TABLET"; break; } diff --git a/src/libinput.h b/src/libinput.h index ff1eaa62..86042840 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -58,7 +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_TABLET_TOOL = 3, LIBINPUT_DEVICE_CAP_GESTURE = 5, }; @@ -138,7 +138,7 @@ enum libinput_pointer_axis_source { * @ingroup device * * Available axis types for a device. It must have the @ref - * LIBINPUT_DEVICE_CAP_TABLET capability. + * LIBINPUT_DEVICE_CAP_TABLET_TOOL capability. */ enum libinput_tablet_tool_axis { LIBINPUT_TABLET_TOOL_AXIS_X = 1, @@ -156,7 +156,7 @@ enum libinput_tablet_tool_axis { * @ingroup device * * An object representing a tool being used by a device with the @ref - * LIBINPUT_DEVICE_CAP_TABLET capability. + * LIBINPUT_DEVICE_CAP_TABLET_TOOL 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 @@ -169,7 +169,7 @@ struct libinput_tablet_tool; * @ingroup device * * Available tool types for a device with the @ref - * LIBINPUT_DEVICE_CAP_TABLET capability. The tool type defines the default + * LIBINPUT_DEVICE_CAP_TABLET_TOOL 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 @@ -201,7 +201,7 @@ enum libinput_tablet_tool_type { * @ingroup device * * The state of proximity for a tool on a device. The device must have the @ref - * LIBINPUT_DEVICE_CAP_TABLET capability. + * LIBINPUT_DEVICE_CAP_TABLET_TOOL 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 @@ -220,7 +220,7 @@ enum libinput_tablet_tool_proximity_state { * @ingroup device * * The tip contact state for a tool on a device. The device must have - * the @ref LIBINPUT_DEVICE_CAP_TABLET capability. + * the @ref LIBINPUT_DEVICE_CAP_TABLET_TOOL capability. * * The tip contact state of a tool is a binary state signalling whether the tool is * touching the surface of the tablet device. @@ -278,7 +278,7 @@ enum libinput_event_type { /** * One or more axes have changed state on a device with the @ref - * LIBINPUT_DEVICE_CAP_TABLET capability. This event is only sent + * LIBINPUT_DEVICE_CAP_TABLET_TOOL capability. This event is only sent * when the tool is in proximity, see @ref * LIBINPUT_EVENT_TABLET_PROXIMITY for details. * @@ -292,7 +292,7 @@ enum libinput_event_type { 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. + * the @ref LIBINPUT_DEVICE_CAP_TABLET_TOOL 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 @@ -317,7 +317,7 @@ enum libinput_event_type { LIBINPUT_EVENT_TABLET_PROXIMITY, /** * Signals that a tool has come in contact with the surface of a - * device with the @ref LIBINPUT_DEVICE_CAP_TABLET capability. + * device with the @ref LIBINPUT_DEVICE_CAP_TABLET_TOOL capability. * * On devices without distance proximity detection, the @ref * LIBINPUT_EVENT_TABLET_TIP is sent immediately after @ref diff --git a/tools/event-debug.c b/tools/event-debug.c index c123917c..c35acef6 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -170,7 +170,7 @@ print_device_notify(struct libinput_event *ev) LIBINPUT_DEVICE_CAP_GESTURE)) printf("g"); if (libinput_device_has_capability(dev, - LIBINPUT_DEVICE_CAP_TABLET)) + LIBINPUT_DEVICE_CAP_TABLET_TOOL)) printf("T"); if (libinput_device_get_size(dev, &w, &h) == 0) diff --git a/tools/libinput-list-devices.c b/tools/libinput-list-devices.c index d9f71bd8..62eb915b 100644 --- a/tools/libinput-list-devices.c +++ b/tools/libinput-list-devices.c @@ -258,7 +258,7 @@ print_device_notify(struct libinput_event *ev) LIBINPUT_DEVICE_CAP_TOUCH)) printf("touch"); if (libinput_device_has_capability(dev, - LIBINPUT_DEVICE_CAP_TABLET)) + LIBINPUT_DEVICE_CAP_TABLET_TOOL)) printf("tablet"); printf("\n"); From 2cfd52244a56f52fa4f3d759622d77c132431f1e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 16 Nov 2015 16:27:46 +1000 Subject: [PATCH 173/255] tablet: rename LIBINPUT_EVENT_TABLET to LIBINPUT_EVENT_TABLET_TOOL Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- doc/tablet-support.dox | 2 +- src/libinput.c | 104 ++++++++++++++-------------- src/libinput.h | 46 ++++++------- test/litest.c | 16 ++--- test/misc.c | 4 +- test/tablet.c | 150 ++++++++++++++++++++--------------------- tools/event-debug.c | 16 ++--- tools/event-gui.c | 16 ++--- 8 files changed, 177 insertions(+), 177 deletions(-) diff --git a/doc/tablet-support.dox b/doc/tablet-support.dox index fb8ea323..47ad0054 100644 --- a/doc/tablet-support.dox +++ b/doc/tablet-support.dox @@ -8,7 +8,7 @@ Apple iPad. @section fake-proximity Handling of proximity events -libinput's @ref LIBINPUT_EVENT_TABLET_PROXIMITY events represent the +libinput's @ref LIBINPUT_EVENT_TABLET_TOOL_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 diff --git a/src/libinput.c b/src/libinput.c index 708399f0..79e38321 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -312,10 +312,10 @@ 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_TIP, - LIBINPUT_EVENT_TABLET_BUTTON); + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON); return (struct libinput_event_tablet *) event; } @@ -919,9 +919,9 @@ libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, - LIBINPUT_EVENT_TABLET_AXIS, - LIBINPUT_EVENT_TABLET_TIP, - LIBINPUT_EVENT_TABLET_PROXIMITY); + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return (NCHARS(axis) <= sizeof(event->changed_axes)) ? bit_is_set(event->changed_axes, axis) : 0; @@ -937,9 +937,9 @@ libinput_event_tablet_get_axis_value(struct libinput_event_tablet *event, require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, - LIBINPUT_EVENT_TABLET_AXIS, - LIBINPUT_EVENT_TABLET_TIP, - LIBINPUT_EVENT_TABLET_PROXIMITY); + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); switch(axis) { case LIBINPUT_TABLET_TOOL_AXIS_X: @@ -971,9 +971,9 @@ libinput_event_tablet_get_axis_delta(struct libinput_event_tablet *event, require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, - LIBINPUT_EVENT_TABLET_AXIS, - LIBINPUT_EVENT_TABLET_TIP, - LIBINPUT_EVENT_TABLET_PROXIMITY); + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); switch(axis) { case LIBINPUT_TABLET_TOOL_AXIS_X: @@ -1003,9 +1003,9 @@ libinput_event_tablet_get_axis_delta_discrete( require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, - LIBINPUT_EVENT_TABLET_AXIS, - LIBINPUT_EVENT_TABLET_TIP, - LIBINPUT_EVENT_TABLET_PROXIMITY); + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); switch(axis) { case LIBINPUT_TABLET_TOOL_AXIS_X: @@ -1033,9 +1033,9 @@ libinput_event_tablet_get_x_transformed(struct libinput_event_tablet *event, require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, - LIBINPUT_EVENT_TABLET_AXIS, - LIBINPUT_EVENT_TABLET_TIP, - LIBINPUT_EVENT_TABLET_PROXIMITY); + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return evdev_device_transform_x(device, event->axes[LIBINPUT_TABLET_TOOL_AXIS_X], @@ -1052,9 +1052,9 @@ libinput_event_tablet_get_y_transformed(struct libinput_event_tablet *event, require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, - LIBINPUT_EVENT_TABLET_AXIS, - LIBINPUT_EVENT_TABLET_TIP, - LIBINPUT_EVENT_TABLET_PROXIMITY); + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return evdev_device_transform_y(device, event->axes[LIBINPUT_TABLET_TOOL_AXIS_Y], @@ -1067,10 +1067,10 @@ libinput_event_tablet_get_tool(struct libinput_event_tablet *event) require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, - LIBINPUT_EVENT_TABLET_AXIS, - LIBINPUT_EVENT_TABLET_TIP, - LIBINPUT_EVENT_TABLET_BUTTON, - LIBINPUT_EVENT_TABLET_PROXIMITY); + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return event->tool; } @@ -1081,10 +1081,10 @@ libinput_event_tablet_get_proximity_state(struct libinput_event_tablet *event) require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, - LIBINPUT_EVENT_TABLET_AXIS, - LIBINPUT_EVENT_TABLET_TIP, - LIBINPUT_EVENT_TABLET_BUTTON, - LIBINPUT_EVENT_TABLET_PROXIMITY); + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return event->proximity_state; } @@ -1095,10 +1095,10 @@ libinput_event_tablet_get_tip_state(struct libinput_event_tablet *event) require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, - LIBINPUT_EVENT_TABLET_AXIS, - LIBINPUT_EVENT_TABLET_TIP, - LIBINPUT_EVENT_TABLET_BUTTON, - LIBINPUT_EVENT_TABLET_PROXIMITY); + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return event->tip_state; } @@ -1109,10 +1109,10 @@ libinput_event_tablet_get_time(struct libinput_event_tablet *event) require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, - LIBINPUT_EVENT_TABLET_AXIS, - LIBINPUT_EVENT_TABLET_TIP, - LIBINPUT_EVENT_TABLET_BUTTON, - LIBINPUT_EVENT_TABLET_PROXIMITY); + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return us2ms(event->time); } @@ -1123,10 +1123,10 @@ libinput_event_tablet_get_time_usec(struct libinput_event_tablet *event) require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, - LIBINPUT_EVENT_TABLET_AXIS, - LIBINPUT_EVENT_TABLET_TIP, - LIBINPUT_EVENT_TABLET_BUTTON, - LIBINPUT_EVENT_TABLET_PROXIMITY); + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return event->time; } @@ -1137,7 +1137,7 @@ libinput_event_tablet_get_button(struct libinput_event_tablet *event) require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, - LIBINPUT_EVENT_TABLET_BUTTON); + LIBINPUT_EVENT_TABLET_TOOL_BUTTON); return event->button; } @@ -1148,7 +1148,7 @@ libinput_event_tablet_get_button_state(struct libinput_event_tablet *event) require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, - LIBINPUT_EVENT_TABLET_BUTTON); + LIBINPUT_EVENT_TABLET_TOOL_BUTTON); return event->state; } @@ -1159,7 +1159,7 @@ libinput_event_tablet_get_seat_button_count(struct libinput_event_tablet *event) require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, - LIBINPUT_EVENT_TABLET_BUTTON); + LIBINPUT_EVENT_TABLET_TOOL_BUTTON); return event->seat_button_count; } @@ -2003,7 +2003,7 @@ tablet_notify_axis(struct libinput_device *device, post_device_event(device, time, - LIBINPUT_EVENT_TABLET_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_AXIS, &axis_event->base); } @@ -2037,7 +2037,7 @@ tablet_notify_proximity(struct libinput_device *device, post_device_event(device, time, - LIBINPUT_EVENT_TABLET_PROXIMITY, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, &proximity_event->base); } @@ -2066,7 +2066,7 @@ tablet_notify_tip(struct libinput_device *device, post_device_event(device, time, - LIBINPUT_EVENT_TABLET_TIP, + LIBINPUT_EVENT_TABLET_TOOL_TIP, &tip_event->base); } @@ -2103,7 +2103,7 @@ tablet_notify_button(struct libinput_device *device, post_device_event(device, time, - LIBINPUT_EVENT_TABLET_BUTTON, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON, &button_event->base); } @@ -2468,9 +2468,9 @@ 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); + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON); return &event->base; } diff --git a/src/libinput.h b/src/libinput.h index 86042840..77bf260e 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -280,23 +280,23 @@ enum libinput_event_type { * One or more axes have changed state on a device with the @ref * LIBINPUT_DEVICE_CAP_TABLET_TOOL capability. This event is only sent * when the tool is in proximity, see @ref - * LIBINPUT_EVENT_TABLET_PROXIMITY for details. + * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY for details. * * The proximity event contains the initial state of the axis as the * tool comes into proximity. An event of type @ref - * LIBINPUT_EVENT_TABLET_AXIS is only sent when an axis value + * LIBINPUT_EVENT_TABLET_TOOL_AXIS is only sent when an axis value * changes from this initial state. It is possible for a tool to * enter and leave proximity without sending an event of type @ref - * LIBINPUT_EVENT_TABLET_AXIS. + * LIBINPUT_EVENT_TABLET_TOOL_AXIS. */ - LIBINPUT_EVENT_TABLET_AXIS = 600, + LIBINPUT_EVENT_TABLET_TOOL_AXIS = 600, /** * Signals that a tool has come in or out of proximity of a device with * the @ref LIBINPUT_DEVICE_CAP_TABLET_TOOL 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. + * with @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS events. * * Some tools may always be in proximity. For these tools, events of * type @ref LIBINPUT_TABLET_TOOL_PROXIMITY_IN are sent only once after @ref @@ -314,21 +314,21 @@ enum libinput_event_type { * each button that was held down on the stylus are sent before the * proximity out event. */ - LIBINPUT_EVENT_TABLET_PROXIMITY, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, /** * Signals that a tool has come in contact with the surface of a * device with the @ref LIBINPUT_DEVICE_CAP_TABLET_TOOL capability. * * On devices without distance proximity detection, the @ref - * LIBINPUT_EVENT_TABLET_TIP is sent immediately after @ref - * LIBINPUT_EVENT_TABLET_PROXIMITY for the tip down event, and + * LIBINPUT_EVENT_TABLET_TOOL_TIP is sent immediately after @ref + * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY for the tip down event, and * immediately before for the tip up event. * * If a button and/or axis state change occurs at the same time as a * tip state change, the order of events is device-dependent. */ - LIBINPUT_EVENT_TABLET_TIP, - LIBINPUT_EVENT_TABLET_BUTTON, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN = 800, LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE, @@ -429,8 +429,8 @@ struct libinput_event_touch; * @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. + * event types for this event are @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref + * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY and @ref LIBINPUT_EVENT_TABLET_TOOL_BUTTON. */ struct libinput_event_tablet; @@ -1359,11 +1359,11 @@ 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. + * For tablet events that are not of type @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS or + * type @ref LIBINPUT_EVENT_TABLET_TOOL_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. + * @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS and @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. * * @param event The libinput tablet event * @param axis The axis to check for updates @@ -1406,7 +1406,7 @@ libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, * 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 + * If the event is of type @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY and the * event is a proximity out event, the value returned is the last known * value of the tool before it left proximity. * @@ -1516,7 +1516,7 @@ libinput_event_tablet_get_tool(struct libinput_event_tablet *event); * * 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. + * event of type @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. * * See @ref fake-proximity for recommendations on proximity handling. * @@ -1532,7 +1532,7 @@ libinput_event_tablet_get_proximity_state(struct libinput_event_tablet *event); * Returns the new tip state of a tool from a tip event. * Used to check whether or not a tool came in contact with the tablet * surface or left contact with the tablet surface during an - * event of type @ref LIBINPUT_EVENT_TABLET_TIP. + * event of type @ref LIBINPUT_EVENT_TABLET_TOOL_TIP. * * @param event The libinput tablet event * @return The new tip state of the tool from the event. @@ -1544,11 +1544,11 @@ libinput_event_tablet_get_tip_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 + * For tablet events that are not of type @ref LIBINPUT_EVENT_TABLET_TOOL_BUTTON, this * function returns 0. * * @note It is an application bug to call this function for events other than - * @ref LIBINPUT_EVENT_TABLET_BUTTON. + * @ref LIBINPUT_EVENT_TABLET_TOOL_BUTTON. * * @param event The libinput tablet event * @return the button triggering this event @@ -1562,7 +1562,7 @@ libinput_event_tablet_get_button(struct libinput_event_tablet *event); * 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. + * @ref LIBINPUT_EVENT_TABLET_TOOL_BUTTON. * * @param event The libinput tablet event * @return the button state triggering this event @@ -1573,12 +1573,12 @@ 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 + * For the button of a @ref LIBINPUT_EVENT_TABLET_TOOL_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. + * @ref LIBINPUT_EVENT_TABLET_TOOL_BUTTON. For other events, this function returns 0. * * @return the seat wide pressed button count for the key of this event */ diff --git a/test/litest.c b/test/litest.c index 292cddba..d9fa32be 100644 --- a/test/litest.c +++ b/test/litest.c @@ -1881,16 +1881,16 @@ litest_event_type_str(struct libinput_event *event) case LIBINPUT_EVENT_GESTURE_PINCH_END: str = "GESTURE PINCH END"; break; - case LIBINPUT_EVENT_TABLET_AXIS: + case LIBINPUT_EVENT_TABLET_TOOL_AXIS: str = "TABLET AXIS"; break; - case LIBINPUT_EVENT_TABLET_PROXIMITY: + case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: str = "TABLET PROX"; break; - case LIBINPUT_EVENT_TABLET_TIP: + case LIBINPUT_EVENT_TABLET_TOOL_TIP: str = "TABLET TIP"; break; - case LIBINPUT_EVENT_TABLET_BUTTON: + case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: str = "TABLET BUTTON"; break; } @@ -1947,17 +1947,17 @@ litest_print_event(struct libinput_event *event) LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL); fprintf(stderr, "vert %.f horiz %.2f", y, x); break; - case LIBINPUT_EVENT_TABLET_PROXIMITY: + case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: t = libinput_event_get_tablet_event(event); fprintf(stderr, "proximity %d\n", libinput_event_tablet_get_proximity_state(t)); break; - case LIBINPUT_EVENT_TABLET_TIP: + case LIBINPUT_EVENT_TABLET_TOOL_TIP: t = libinput_event_get_tablet_event(event); fprintf(stderr, "tip %d\n", libinput_event_tablet_get_tip_state(t)); break; - case LIBINPUT_EVENT_TABLET_BUTTON: + case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: t = libinput_event_get_tablet_event(event); fprintf(stderr, "button %d state %d\n", libinput_event_tablet_get_button(t), @@ -2351,7 +2351,7 @@ litest_assert_tablet_button_event(struct libinput *li, unsigned int button, { struct libinput_event *event; struct libinput_event_tablet *tev; - enum libinput_event_type type = LIBINPUT_EVENT_TABLET_BUTTON; + enum libinput_event_type type = LIBINPUT_EVENT_TABLET_TOOL_BUTTON; litest_wait_for_event(li); event = libinput_get_event(li); diff --git a/test/misc.c b/test/misc.c index a0c459dc..7ba6f9c8 100644 --- a/test/misc.c +++ b/test/misc.c @@ -412,8 +412,8 @@ START_TEST(event_conversion_tablet) enum libinput_event_type type; type = libinput_event_get_type(event); - if (type >= LIBINPUT_EVENT_TABLET_AXIS && - type <= LIBINPUT_EVENT_TABLET_BUTTON) { + if (type >= LIBINPUT_EVENT_TABLET_TOOL_AXIS && + type <= LIBINPUT_EVENT_TABLET_TOOL_BUTTON) { struct libinput_event_tablet *t; struct libinput_event *base; t = libinput_event_get_tablet_event(event); diff --git a/test/tablet.c b/test/tablet.c index 7aa76b28..383a7b1c 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -54,7 +54,7 @@ START_TEST(tip_down_up) libinput_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_TIP); + LIBINPUT_EVENT_TABLET_TOOL_TIP); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); @@ -66,7 +66,7 @@ START_TEST(tip_down_up) libinput_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_TIP); + LIBINPUT_EVENT_TABLET_TOOL_TIP); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); @@ -98,7 +98,7 @@ START_TEST(tip_down_prox_in) libinput_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_PROXIMITY); + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); ck_assert_int_eq(libinput_event_tablet_get_proximity_state(tablet_event), LIBINPUT_TABLET_TOOL_PROXIMITY_IN); libinput_event_destroy(event); @@ -106,7 +106,7 @@ START_TEST(tip_down_prox_in) libinput_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_TIP); + LIBINPUT_EVENT_TABLET_TOOL_TIP); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); @@ -140,7 +140,7 @@ START_TEST(tip_up_prox_out) libinput_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_TIP); + LIBINPUT_EVENT_TABLET_TOOL_TIP); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); @@ -148,7 +148,7 @@ START_TEST(tip_up_prox_out) libinput_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_PROXIMITY); + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); ck_assert_int_eq(libinput_event_tablet_get_proximity_state(tablet_event), LIBINPUT_TABLET_TOOL_PROXIMITY_OUT); libinput_event_destroy(event); @@ -181,7 +181,7 @@ START_TEST(tip_up_btn_change) libinput_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_BUTTON); + LIBINPUT_EVENT_TABLET_TOOL_BUTTON); ck_assert_int_eq(libinput_event_tablet_get_button(tablet_event), BTN_STYLUS); ck_assert_int_eq(libinput_event_tablet_get_button_state(tablet_event), @@ -191,7 +191,7 @@ START_TEST(tip_up_btn_change) libinput_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_TIP); + LIBINPUT_EVENT_TABLET_TOOL_TIP); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); @@ -210,7 +210,7 @@ START_TEST(tip_up_btn_change) libinput_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_BUTTON); + LIBINPUT_EVENT_TABLET_TOOL_BUTTON); ck_assert_int_eq(libinput_event_tablet_get_button(tablet_event), BTN_STYLUS); ck_assert_int_eq(libinput_event_tablet_get_button_state(tablet_event), @@ -220,7 +220,7 @@ START_TEST(tip_up_btn_change) libinput_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_TIP); + LIBINPUT_EVENT_TABLET_TOOL_TIP); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); @@ -250,7 +250,7 @@ START_TEST(tip_down_btn_change) libinput_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_TIP); + LIBINPUT_EVENT_TABLET_TOOL_TIP); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); @@ -258,7 +258,7 @@ START_TEST(tip_down_btn_change) libinput_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_BUTTON); + LIBINPUT_EVENT_TABLET_TOOL_BUTTON); ck_assert_int_eq(libinput_event_tablet_get_button(tablet_event), BTN_STYLUS); ck_assert_int_eq(libinput_event_tablet_get_button_state(tablet_event), @@ -279,7 +279,7 @@ START_TEST(tip_down_btn_change) libinput_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_TIP); + LIBINPUT_EVENT_TABLET_TOOL_TIP); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); @@ -287,7 +287,7 @@ START_TEST(tip_down_btn_change) libinput_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_BUTTON); + LIBINPUT_EVENT_TABLET_TOOL_BUTTON); ck_assert_int_eq(libinput_event_tablet_get_button(tablet_event), BTN_STYLUS); ck_assert_int_eq(libinput_event_tablet_get_button_state(tablet_event), @@ -322,7 +322,7 @@ START_TEST(tip_down_motion) libinput_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_AXIS); + LIBINPUT_EVENT_TABLET_TOOL_AXIS); last_x = libinput_event_tablet_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); last_y = libinput_event_tablet_get_axis_value(tablet_event, @@ -332,7 +332,7 @@ START_TEST(tip_down_motion) libinput_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_TIP); + LIBINPUT_EVENT_TABLET_TOOL_TIP); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_DOWN); x = libinput_event_tablet_get_axis_value(tablet_event, @@ -373,7 +373,7 @@ START_TEST(tip_up_motion) libinput_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_AXIS); + LIBINPUT_EVENT_TABLET_TOOL_AXIS); last_x = libinput_event_tablet_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); last_y = libinput_event_tablet_get_axis_value(tablet_event, @@ -383,7 +383,7 @@ START_TEST(tip_up_motion) libinput_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_TIP); + LIBINPUT_EVENT_TABLET_TOOL_TIP); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); x = libinput_event_tablet_get_axis_value(tablet_event, @@ -416,7 +416,7 @@ START_TEST(tip_state_proximity) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_PROXIMITY); + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); @@ -432,7 +432,7 @@ START_TEST(tip_state_proximity) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_PROXIMITY); + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); @@ -458,7 +458,7 @@ START_TEST(tip_state_axis) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_AXIS); + LIBINPUT_EVENT_TABLET_TOOL_AXIS); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); @@ -472,7 +472,7 @@ START_TEST(tip_state_axis) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_AXIS); + LIBINPUT_EVENT_TABLET_TOOL_AXIS); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); @@ -486,7 +486,7 @@ START_TEST(tip_state_axis) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_AXIS); + LIBINPUT_EVENT_TABLET_TOOL_AXIS); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); @@ -515,7 +515,7 @@ START_TEST(tip_state_button) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_BUTTON); + LIBINPUT_EVENT_TABLET_TOOL_BUTTON); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); @@ -530,7 +530,7 @@ START_TEST(tip_state_button) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_BUTTON); + LIBINPUT_EVENT_TABLET_TOOL_BUTTON); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); @@ -545,7 +545,7 @@ START_TEST(tip_state_button) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_BUTTON); + LIBINPUT_EVENT_TABLET_TOOL_BUTTON); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); @@ -556,7 +556,7 @@ START_TEST(tip_state_button) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_BUTTON); + LIBINPUT_EVENT_TABLET_TOOL_BUTTON); ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); @@ -586,7 +586,7 @@ START_TEST(proximity_in_out) while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_PROXIMITY) { + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY) { struct libinput_tablet_tool * tool; have_tool_update++; @@ -604,7 +604,7 @@ START_TEST(proximity_in_out) while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_PROXIMITY) { + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY) { struct libinput_event_tablet *t = libinput_event_get_tablet_event(event); @@ -624,7 +624,7 @@ START_TEST(proximity_in_out) while ((event = libinput_get_event(li))) { enum libinput_event_type type = libinput_event_get_type(event); - ck_assert(type != LIBINPUT_EVENT_TABLET_AXIS); + ck_assert(type != LIBINPUT_EVENT_TABLET_TOOL_AXIS); libinput_event_destroy(event); } @@ -668,7 +668,7 @@ START_TEST(proximity_out_clear_buttons) tablet_event = libinput_event_get_tablet_event(event); if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_BUTTON) { + LIBINPUT_EVENT_TABLET_TOOL_BUTTON) { event_button = libinput_event_tablet_get_button(tablet_event); state = libinput_event_tablet_get_button_state(tablet_event); @@ -714,7 +714,7 @@ START_TEST(proximity_has_axes) litest_tablet_proximity_in(dev, 10, 10, axes); - litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_PROXIMITY, -1); + litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); event = libinput_get_event(li); @@ -773,7 +773,7 @@ START_TEST(proximity_has_axes) axes[2].value = 25; litest_tablet_motion(dev, 20, 30, axes); libinput_dispatch(li); - litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_AXIS, -1); + litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, -1); event = libinput_get_event(li); tablet_event = libinput_event_get_tablet_event(event); @@ -800,7 +800,7 @@ START_TEST(proximity_has_axes) /* 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); + litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); event = libinput_get_event(li); tablet_event = libinput_event_get_tablet_event(event); @@ -874,7 +874,7 @@ START_TEST(motion) libinput_dispatch(li); litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_PROXIMITY, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); while ((event = libinput_get_event(li))) { @@ -883,7 +883,7 @@ START_TEST(motion) tablet_event = libinput_event_get_tablet_event(event); ck_assert_int_eq(libinput_event_get_type(event), - LIBINPUT_EVENT_TABLET_PROXIMITY); + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); x_changed = libinput_event_tablet_axis_has_changed( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); @@ -919,7 +919,7 @@ START_TEST(motion) tablet_event = libinput_event_get_tablet_event(event); type = libinput_event_get_type(event); - if (type == LIBINPUT_EVENT_TABLET_AXIS) { + if (type == LIBINPUT_EVENT_TABLET_TOOL_AXIS) { x_changed = libinput_event_tablet_axis_has_changed( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); y_changed = libinput_event_tablet_axis_has_changed( @@ -967,7 +967,7 @@ START_TEST(motion_delta) libinput_dispatch(li); litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_PROXIMITY, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); event = libinput_get_event(li); @@ -984,7 +984,7 @@ START_TEST(motion_delta) litest_tablet_motion(dev, 40, 100, axes); litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_AXIS, -1); event = libinput_get_event(li); tablet_event = libinput_event_get_tablet_event(event); @@ -1031,7 +1031,7 @@ START_TEST(motion_delta_partial) axes[0].value = 40; litest_tablet_motion(dev, 40, 100, axes); litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_AXIS, -1); event = libinput_get_event(li); tablet_event = libinput_event_get_tablet_event(event); @@ -1087,7 +1087,7 @@ START_TEST(left_handed) 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); + litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); while ((event = libinput_get_event(li))) { tablet_event = libinput_event_get_tablet_event(event); @@ -1104,7 +1104,7 @@ START_TEST(left_handed) } litest_tablet_motion(dev, 100, 0, axes); - litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_AXIS, -1); + litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, -1); while ((event = libinput_get_event(li))) { double x, y; @@ -1133,7 +1133,7 @@ START_TEST(left_handed) * proximity */ litest_tablet_proximity_in(dev, 0, 100, axes); - litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_PROXIMITY, -1); + litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); while ((event = libinput_get_event(li))) { tablet_event = libinput_event_get_tablet_event(event); @@ -1150,7 +1150,7 @@ START_TEST(left_handed) } litest_tablet_motion(dev, 100, 0, axes); - litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_AXIS, -1); + litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, -1); while ((event = libinput_get_event(li))) { double x, y; @@ -1206,7 +1206,7 @@ START_TEST(motion_event_state) libinput_dispatch(li); while ((event = libinput_get_event(li))) { - if (libinput_event_get_type(event) == LIBINPUT_EVENT_TABLET_AXIS) + if (libinput_event_get_type(event) == LIBINPUT_EVENT_TABLET_TOOL_AXIS) break; libinput_event_destroy(event); } @@ -1231,14 +1231,14 @@ START_TEST(motion_event_state) libinput_event_destroy(event); libinput_dispatch(li); ck_assert_int_eq(libinput_next_event_type(li), - LIBINPUT_EVENT_TABLET_AXIS); + LIBINPUT_EVENT_TABLET_TOOL_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) + if (libinput_event_get_type(event) != LIBINPUT_EVENT_TABLET_TOOL_AXIS) break; tablet_event = libinput_event_get_tablet_event(event); @@ -1258,7 +1258,7 @@ START_TEST(motion_event_state) } ck_assert_int_eq(libinput_event_get_type(event), - LIBINPUT_EVENT_TABLET_BUTTON); + LIBINPUT_EVENT_TABLET_TOOL_BUTTON); libinput_event_destroy(event); } END_TEST @@ -1331,7 +1331,7 @@ START_TEST(normalization) libinput_dispatch(li); while ((event = libinput_get_event(li))) { - if (libinput_event_get_type(event) == LIBINPUT_EVENT_TABLET_AXIS) { + if (libinput_event_get_type(event) == LIBINPUT_EVENT_TABLET_TOOL_AXIS) { tablet_event = libinput_event_get_tablet_event(event); if (libinput_event_tablet_axis_has_changed( @@ -1393,7 +1393,7 @@ START_TEST(normalization) libinput_dispatch(li); while ((event = libinput_get_event(li))) { - if (libinput_event_get_type(event) == LIBINPUT_EVENT_TABLET_AXIS) { + if (libinput_event_get_type(event) == LIBINPUT_EVENT_TABLET_TOOL_AXIS) { tablet_event = libinput_event_get_tablet_event(event); if (libinput_event_tablet_axis_has_changed( @@ -1449,7 +1449,7 @@ START_TEST(tool_serial) litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_PROXIMITY, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); event = libinput_get_event(li); tablet_event = libinput_event_get_tablet_event(event); @@ -1481,7 +1481,7 @@ START_TEST(serial_changes_tool) litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_PROXIMITY, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); event = libinput_get_event(li); tablet_event = libinput_event_get_tablet_event(event); @@ -1516,7 +1516,7 @@ START_TEST(invalid_serials) libinput_dispatch(li); while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_PROXIMITY) { + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY) { tablet_event = libinput_event_get_tablet_event(event); tool = libinput_event_tablet_get_tool(tablet_event); @@ -1543,7 +1543,7 @@ START_TEST(tool_ref) litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_PROXIMITY, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); event = libinput_get_event(li); tablet_event = libinput_event_get_tablet_event(event); @@ -1581,7 +1581,7 @@ START_TEST(pad_buttons_ignored) while ((event = libinput_get_event(li))) { ck_assert_int_ne(libinput_event_get_type(event), - LIBINPUT_EVENT_TABLET_BUTTON); + LIBINPUT_EVENT_TABLET_TOOL_BUTTON); libinput_event_destroy(event); libinput_dispatch(li); } @@ -1600,7 +1600,7 @@ START_TEST(pad_buttons_ignored) libinput_dispatch(li); while ((event = libinput_get_event(li))) { ck_assert_int_ne(libinput_event_get_type(event), - LIBINPUT_EVENT_TABLET_BUTTON); + LIBINPUT_EVENT_TABLET_TOOL_BUTTON); libinput_event_destroy(event); libinput_dispatch(li); } @@ -1634,7 +1634,7 @@ START_TEST(tools_with_serials) libinput_dispatch(li); while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_PROXIMITY) { + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY) { struct libinput_event_tablet *t = libinput_event_get_tablet_event(event); @@ -1683,7 +1683,7 @@ START_TEST(tools_without_serials) libinput_dispatch(li); while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_PROXIMITY) { + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY) { struct libinput_event_tablet *t = libinput_event_get_tablet_event(event); @@ -1725,7 +1725,7 @@ START_TEST(tool_capabilities) libinput_dispatch(li); litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_PROXIMITY, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); event = libinput_get_event(li); @@ -1748,7 +1748,7 @@ START_TEST(tool_capabilities) litest_event(intuos, EV_SYN, SYN_REPORT, 0); litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_PROXIMITY, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); event = libinput_get_event(li); @@ -1800,7 +1800,7 @@ START_TEST(tool_in_prox_before_start) libinput_event_destroy(event); litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_PROXIMITY, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); event = libinput_get_event(li); libinput_event_destroy(event); @@ -1809,17 +1809,17 @@ START_TEST(tool_in_prox_before_start) 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_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_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_assert_only_typed_events(li, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); litest_tablet_proximity_out(dev); litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_PROXIMITY, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); libinput_unref(li); } @@ -1845,7 +1845,7 @@ START_TEST(mouse_tool) litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_PROXIMITY, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); event = libinput_get_event(li); tev = libinput_event_get_tablet_event(event); @@ -1880,7 +1880,7 @@ START_TEST(mouse_buttons) litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_PROXIMITY, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); event = libinput_get_event(li); tev = libinput_event_get_tablet_event(event); @@ -1973,7 +1973,7 @@ START_TEST(mouse_rotation) litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_AXIS, -1); event = libinput_get_event(li); tev = libinput_event_get_tablet_event(event); @@ -2019,7 +2019,7 @@ START_TEST(mouse_wheel) litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_PROXIMITY, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); event = libinput_get_event(li); tev = libinput_event_get_tablet_event(event); @@ -2036,7 +2036,7 @@ START_TEST(mouse_wheel) 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); + litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, -1); event = libinput_get_event(li); tev = libinput_event_get_tablet_event(event); @@ -2067,7 +2067,7 @@ START_TEST(mouse_wheel) 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); + litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, -1); event = libinput_get_event(li); tev = libinput_event_get_tablet_event(event); @@ -2114,7 +2114,7 @@ START_TEST(airbrush_tool) litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_PROXIMITY, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); event = libinput_get_event(li); tev = libinput_event_get_tablet_event(event); @@ -2164,7 +2164,7 @@ START_TEST(airbrush_wheel) litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_AXIS, -1); event = libinput_get_event(li); tev = libinput_event_get_tablet_event(event); @@ -2201,7 +2201,7 @@ START_TEST(artpen_tool) litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_PROXIMITY, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); event = libinput_get_event(li); tev = libinput_event_get_tablet_event(event); @@ -2255,7 +2255,7 @@ START_TEST(artpen_rotation) litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_AXIS, -1); event = libinput_get_event(li); tev = libinput_event_get_tablet_event(event); @@ -2295,7 +2295,7 @@ START_TEST(tablet_time_usec) libinput_dispatch(li); litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_PROXIMITY, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); event = libinput_get_event(li); tev = libinput_event_get_tablet_event(event); diff --git a/tools/event-debug.c b/tools/event-debug.c index c35acef6..a16bd017 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -109,16 +109,16 @@ print_event_header(struct libinput_event *ev) case LIBINPUT_EVENT_GESTURE_PINCH_END: type = "GESTURE_PINCH_END"; break; - case LIBINPUT_EVENT_TABLET_AXIS: + case LIBINPUT_EVENT_TABLET_TOOL_AXIS: type = "TABLET_AXIS"; break; - case LIBINPUT_EVENT_TABLET_PROXIMITY: + case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: type = "TABLET_PROXIMITY"; break; - case LIBINPUT_EVENT_TABLET_TIP: + case LIBINPUT_EVENT_TABLET_TOOL_TIP: type = "TABLET_TIP"; break; - case LIBINPUT_EVENT_TABLET_BUTTON: + case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: type = "TABLET_BUTTON"; break; } @@ -676,16 +676,16 @@ 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: + case LIBINPUT_EVENT_TABLET_TOOL_AXIS: print_tablet_axis_event(ev); break; - case LIBINPUT_EVENT_TABLET_PROXIMITY: + case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: print_proximity_event(ev); break; - case LIBINPUT_EVENT_TABLET_TIP: + case LIBINPUT_EVENT_TABLET_TOOL_TIP: print_tablet_tip_event(ev); break; - case LIBINPUT_EVENT_TABLET_BUTTON: + case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: print_tablet_button_event(ev); break; } diff --git a/tools/event-gui.c b/tools/event-gui.c index 41993732..4818a402 100644 --- a/tools/event-gui.c +++ b/tools/event-gui.c @@ -603,7 +603,7 @@ handle_event_tablet(struct libinput_event *ev, struct window *w) double x, y; switch (libinput_event_get_type(ev)) { - case LIBINPUT_EVENT_TABLET_PROXIMITY: + case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: if (libinput_event_tablet_get_proximity_state(t) == LIBINPUT_TABLET_TOOL_PROXIMITY_OUT) { w->tool.x_in = 0; @@ -619,7 +619,7 @@ handle_event_tablet(struct libinput_event *ev, struct window *w) w->height); } break; - case LIBINPUT_EVENT_TABLET_AXIS: + case LIBINPUT_EVENT_TABLET_TOOL_AXIS: w->tool.x = libinput_event_tablet_get_x_transformed(t, w->width); w->tool.y = libinput_event_tablet_get_y_transformed(t, @@ -633,7 +633,7 @@ handle_event_tablet(struct libinput_event *ev, struct window *w) w->tool.tilt_y = libinput_event_tablet_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); break; - case LIBINPUT_EVENT_TABLET_TIP: + case LIBINPUT_EVENT_TABLET_TOOL_TIP: x = libinput_event_tablet_get_x_transformed(t, w->width); y = libinput_event_tablet_get_y_transformed(t, w->height); if (libinput_event_tablet_get_tip_state(t) == @@ -645,7 +645,7 @@ handle_event_tablet(struct libinput_event *ev, struct window *w) w->tool.y_up = y; } break; - case LIBINPUT_EVENT_TABLET_BUTTON: + case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: break; default: abort(); @@ -707,10 +707,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_TIP: - case LIBINPUT_EVENT_TABLET_BUTTON: + case LIBINPUT_EVENT_TABLET_TOOL_AXIS: + case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: + case LIBINPUT_EVENT_TABLET_TOOL_TIP: + case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: handle_event_tablet(ev, w); break; } From a10e92849cec366ef9491ae6bc1d45c4926c2aa3 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 16 Nov 2015 16:28:55 +1000 Subject: [PATCH 174/255] tablet: rename libinput_event_tablet to libinput_event_tablet_tool Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/libinput.c | 56 +++--- src/libinput.h | 66 +++---- src/libinput.sym | 32 ++-- test/litest.c | 30 +-- test/litest.h | 2 +- test/misc.c | 16 +- test/tablet.c | 438 ++++++++++++++++++++++---------------------- tools/event-debug.c | 72 ++++---- tools/event-gui.c | 26 +-- 9 files changed, 369 insertions(+), 369 deletions(-) diff --git a/src/libinput.c b/src/libinput.c index 79e38321..338255d8 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -125,7 +125,7 @@ struct libinput_event_gesture { double angle; }; -struct libinput_event_tablet { +struct libinput_event_tablet_tool { struct libinput_event base; uint32_t button; enum libinput_button_state state; @@ -306,8 +306,8 @@ 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) +LIBINPUT_EXPORT struct libinput_event_tablet_tool * +libinput_event_get_tablet_tool_event(struct libinput_event *event) { require_event_type(libinput_event_get_context(event), event->type, @@ -317,7 +317,7 @@ libinput_event_get_tablet_event(struct libinput_event *event) LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); - return (struct libinput_event_tablet *) event; + return (struct libinput_event_tablet_tool *) event; } LIBINPUT_EXPORT struct libinput_event_device_notify * @@ -913,7 +913,7 @@ libinput_event_gesture_get_angle_delta(struct libinput_event_gesture *event) } LIBINPUT_EXPORT int -libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, +libinput_event_tablet_tool_axis_has_changed(struct libinput_event_tablet_tool *event, enum libinput_tablet_tool_axis axis) { require_event_type(libinput_event_get_context(&event->base), @@ -928,7 +928,7 @@ libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, } LIBINPUT_EXPORT double -libinput_event_tablet_get_axis_value(struct libinput_event_tablet *event, +libinput_event_tablet_tool_get_axis_value(struct libinput_event_tablet_tool *event, enum libinput_tablet_tool_axis axis) { struct evdev_device *device = @@ -962,7 +962,7 @@ libinput_event_tablet_get_axis_value(struct libinput_event_tablet *event, } LIBINPUT_EXPORT double -libinput_event_tablet_get_axis_delta(struct libinput_event_tablet *event, +libinput_event_tablet_tool_get_axis_delta(struct libinput_event_tablet_tool *event, enum libinput_tablet_tool_axis axis) { struct evdev_device *device = @@ -996,8 +996,8 @@ libinput_event_tablet_get_axis_delta(struct libinput_event_tablet *event, } LIBINPUT_EXPORT double -libinput_event_tablet_get_axis_delta_discrete( - struct libinput_event_tablet *event, +libinput_event_tablet_tool_get_axis_delta_discrete( + struct libinput_event_tablet_tool *event, enum libinput_tablet_tool_axis axis) { require_event_type(libinput_event_get_context(&event->base), @@ -1024,7 +1024,7 @@ libinput_event_tablet_get_axis_delta_discrete( } LIBINPUT_EXPORT double -libinput_event_tablet_get_x_transformed(struct libinput_event_tablet *event, +libinput_event_tablet_tool_get_x_transformed(struct libinput_event_tablet_tool *event, uint32_t width) { struct evdev_device *device = @@ -1043,7 +1043,7 @@ libinput_event_tablet_get_x_transformed(struct libinput_event_tablet *event, } LIBINPUT_EXPORT double -libinput_event_tablet_get_y_transformed(struct libinput_event_tablet *event, +libinput_event_tablet_tool_get_y_transformed(struct libinput_event_tablet_tool *event, uint32_t height) { struct evdev_device *device = @@ -1062,7 +1062,7 @@ libinput_event_tablet_get_y_transformed(struct libinput_event_tablet *event, } LIBINPUT_EXPORT struct libinput_tablet_tool * -libinput_event_tablet_get_tool(struct libinput_event_tablet *event) +libinput_event_tablet_tool_get_tool(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, @@ -1076,7 +1076,7 @@ libinput_event_tablet_get_tool(struct libinput_event_tablet *event) } LIBINPUT_EXPORT enum libinput_tablet_tool_proximity_state -libinput_event_tablet_get_proximity_state(struct libinput_event_tablet *event) +libinput_event_tablet_tool_get_proximity_state(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, @@ -1090,7 +1090,7 @@ libinput_event_tablet_get_proximity_state(struct libinput_event_tablet *event) } LIBINPUT_EXPORT enum libinput_tablet_tool_tip_state -libinput_event_tablet_get_tip_state(struct libinput_event_tablet *event) +libinput_event_tablet_tool_get_tip_state(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, @@ -1104,7 +1104,7 @@ libinput_event_tablet_get_tip_state(struct libinput_event_tablet *event) } LIBINPUT_EXPORT uint32_t -libinput_event_tablet_get_time(struct libinput_event_tablet *event) +libinput_event_tablet_tool_get_time(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, @@ -1118,7 +1118,7 @@ libinput_event_tablet_get_time(struct libinput_event_tablet *event) } LIBINPUT_EXPORT uint64_t -libinput_event_tablet_get_time_usec(struct libinput_event_tablet *event) +libinput_event_tablet_tool_get_time_usec(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, @@ -1132,7 +1132,7 @@ libinput_event_tablet_get_time_usec(struct libinput_event_tablet *event) } LIBINPUT_EXPORT uint32_t -libinput_event_tablet_get_button(struct libinput_event_tablet *event) +libinput_event_tablet_tool_get_button(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, @@ -1143,7 +1143,7 @@ libinput_event_tablet_get_button(struct libinput_event_tablet *event) } LIBINPUT_EXPORT enum libinput_button_state -libinput_event_tablet_get_button_state(struct libinput_event_tablet *event) +libinput_event_tablet_tool_get_button_state(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, @@ -1154,7 +1154,7 @@ libinput_event_tablet_get_button_state(struct libinput_event_tablet *event) } LIBINPUT_EXPORT uint32_t -libinput_event_tablet_get_seat_button_count(struct libinput_event_tablet *event) +libinput_event_tablet_tool_get_seat_button_count(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, @@ -1979,13 +1979,13 @@ tablet_notify_axis(struct libinput_device *device, double *deltas, double *deltas_discrete) { - struct libinput_event_tablet *axis_event; + struct libinput_event_tablet_tool *axis_event; axis_event = zalloc(sizeof *axis_event); if (!axis_event) return; - *axis_event = (struct libinput_event_tablet) { + *axis_event = (struct libinput_event_tablet_tool) { .time = time, .tool = tool, .proximity_state = LIBINPUT_TABLET_TOOL_PROXIMITY_IN, @@ -2015,13 +2015,13 @@ tablet_notify_proximity(struct libinput_device *device, unsigned char *changed_axes, double *axes) { - struct libinput_event_tablet *proximity_event; + struct libinput_event_tablet_tool *proximity_event; proximity_event = zalloc(sizeof *proximity_event); if (!proximity_event) return; - *proximity_event = (struct libinput_event_tablet) { + *proximity_event = (struct libinput_event_tablet_tool) { .time = time, .tool = tool, .proximity_state = proximity_state, @@ -2048,13 +2048,13 @@ tablet_notify_tip(struct libinput_device *device, enum libinput_tablet_tool_tip_state tip_state, double *axes) { - struct libinput_event_tablet *tip_event; + struct libinput_event_tablet_tool *tip_event; tip_event = zalloc(sizeof *tip_event); if (!tip_event) return; - *tip_event = (struct libinput_event_tablet) { + *tip_event = (struct libinput_event_tablet_tool) { .time = time, .tool = tool, .tip_state = tip_state, @@ -2079,7 +2079,7 @@ tablet_notify_button(struct libinput_device *device, int32_t button, enum libinput_button_state state) { - struct libinput_event_tablet *button_event; + struct libinput_event_tablet_tool *button_event; int32_t seat_button_count; button_event = zalloc(sizeof *button_event); @@ -2090,7 +2090,7 @@ tablet_notify_button(struct libinput_device *device, button, state); - *button_event = (struct libinput_event_tablet) { + *button_event = (struct libinput_event_tablet_tool) { .time = time, .tool = tool, .button = button, @@ -2463,7 +2463,7 @@ libinput_event_gesture_get_base_event(struct libinput_event_gesture *event) } LIBINPUT_EXPORT struct libinput_event * -libinput_event_tablet_get_base_event(struct libinput_event_tablet *event) +libinput_event_tablet_tool_get_base_event(struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, diff --git a/src/libinput.h b/src/libinput.h index 77bf260e..9884cdcc 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -426,13 +426,13 @@ struct libinput_event_touch; /** * @ingroup event_tablet - * @struct libinput_event_tablet + * @struct libinput_event_tablet_tool * * Tablet event representing an axis update, button press, or tool update. Valid * event types for this event are @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY and @ref LIBINPUT_EVENT_TABLET_TOOL_BUTTON. */ -struct libinput_event_tablet; +struct libinput_event_tablet_tool; /** * @defgroup event Accessing and destruction of events @@ -546,12 +546,12 @@ libinput_event_get_gesture_event(struct libinput_event *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(). + * The inverse of this function is libinput_event_tablet_tool_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); +struct libinput_event_tablet_tool * +libinput_event_get_tablet_tool_event(struct libinput_event *event); /** * @ingroup event @@ -1353,7 +1353,7 @@ libinput_event_gesture_get_angle_delta(struct libinput_event_gesture *event); * @return The generic libinput_event of this event */ struct libinput_event * -libinput_event_tablet_get_base_event(struct libinput_event_tablet *event); +libinput_event_tablet_tool_get_base_event(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet @@ -1370,8 +1370,8 @@ libinput_event_tablet_get_base_event(struct libinput_event_tablet *event); * @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_tool_axis axis); +libinput_event_tablet_tool_axis_has_changed(struct libinput_event_tablet_tool *event, + enum libinput_tablet_tool_axis axis); /** * @ingroup event_tablet @@ -1380,8 +1380,8 @@ libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, * value is dependent on the axis: * - @ref LIBINPUT_TABLET_TOOL_AXIS_X and @ref LIBINPUT_TABLET_TOOL_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 + * tablet. Use libinput_event_tablet_tool_get_x_transformed() and + * libinput_event_tablet_tool_get_y_transformed() for transforming each * respective axis value into a different coordinate space. * - @ref LIBINPUT_TABLET_TOOL_AXIS_DISTANCE - The distance from the tablet's * sensor, normalized from 0 to 1 @@ -1400,10 +1400,10 @@ libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, * from 0 to 1. e.g. the wheel-like tool on the Wacom Airbrush. * - @ref LIBINPUT_TABLET_TOOL_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. + * libinput_event_tablet_tool_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_event_tablet_tool_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_TOOL_PROXIMITY and the @@ -1415,8 +1415,8 @@ libinput_event_tablet_axis_has_changed(struct libinput_event_tablet *event, * @return The current value of the the axis */ double -libinput_event_tablet_get_axis_value(struct libinput_event_tablet *event, - enum libinput_tablet_tool_axis axis); +libinput_event_tablet_tool_get_axis_value(struct libinput_event_tablet_tool *event, + enum libinput_tablet_tool_axis axis); /** * @ingroup event_tablet @@ -1426,7 +1426,7 @@ libinput_event_tablet_get_axis_value(struct libinput_event_tablet *event, * - @ref LIBINPUT_TABLET_TOOL_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 + * For all other axes, see libinput_event_tablet_tool_get_axis_value() for * details. * * @param event The libinput tablet event @@ -1434,8 +1434,8 @@ libinput_event_tablet_get_axis_value(struct libinput_event_tablet *event, * @return The delta to the previous axis value */ double -libinput_event_tablet_get_axis_delta(struct libinput_event_tablet *event, - enum libinput_tablet_tool_axis axis); +libinput_event_tablet_tool_get_axis_delta(struct libinput_event_tablet_tool *event, + enum libinput_tablet_tool_axis axis); /** * @ingroup event_tablet @@ -1451,8 +1451,8 @@ libinput_event_tablet_get_axis_delta(struct libinput_event_tablet *event, * @return The delta to the previous axis value in discrete steps */ double -libinput_event_tablet_get_axis_delta_discrete( - struct libinput_event_tablet *event, +libinput_event_tablet_tool_get_axis_delta_discrete( + struct libinput_event_tablet_tool *event, enum libinput_tablet_tool_axis axis); /** @@ -1462,7 +1462,7 @@ libinput_event_tablet_get_axis_delta_discrete( * 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_event_tablet_tool_axis_has_changed() returns 0 for that axis. * libinput always includes all device axes in the event. * * @param event The libinput tablet event @@ -1470,8 +1470,8 @@ libinput_event_tablet_get_axis_delta_discrete( * @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); +libinput_event_tablet_tool_get_x_transformed(struct libinput_event_tablet_tool *event, + uint32_t width); /** * @ingroup event_tablet @@ -1480,7 +1480,7 @@ libinput_event_tablet_get_x_transformed(struct libinput_event_tablet *event, * 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_event_tablet_tool_axis_has_changed() returns 0 for that axis. * libinput always includes all device axes in the event. * * @param event The libinput tablet event @@ -1488,8 +1488,8 @@ libinput_event_tablet_get_x_transformed(struct libinput_event_tablet *event, * @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); +libinput_event_tablet_tool_get_y_transformed(struct libinput_event_tablet_tool *event, + uint32_t height); /** * @ingroup event_tablet @@ -1509,7 +1509,7 @@ libinput_event_tablet_get_y_transformed(struct libinput_event_tablet *event, * @return The new tool triggering this event */ struct libinput_tablet_tool * -libinput_event_tablet_get_tool(struct libinput_event_tablet *event); +libinput_event_tablet_tool_get_tool(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet @@ -1524,7 +1524,7 @@ libinput_event_tablet_get_tool(struct libinput_event_tablet *event); * @return The new proximity state of the tool from the event. */ enum libinput_tablet_tool_proximity_state -libinput_event_tablet_get_proximity_state(struct libinput_event_tablet *event); +libinput_event_tablet_tool_get_proximity_state(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet @@ -1538,7 +1538,7 @@ libinput_event_tablet_get_proximity_state(struct libinput_event_tablet *event); * @return The new tip state of the tool from the event. */ enum libinput_tablet_tool_tip_state -libinput_event_tablet_get_tip_state(struct libinput_event_tablet *event); +libinput_event_tablet_tool_get_tip_state(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet @@ -1554,7 +1554,7 @@ libinput_event_tablet_get_tip_state(struct libinput_event_tablet *event); * @return the button triggering this event */ uint32_t -libinput_event_tablet_get_button(struct libinput_event_tablet *event); +libinput_event_tablet_tool_get_button(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet @@ -1568,7 +1568,7 @@ libinput_event_tablet_get_button(struct libinput_event_tablet *event); * @return the button state triggering this event */ enum libinput_button_state -libinput_event_tablet_get_button_state(struct libinput_event_tablet *event); +libinput_event_tablet_tool_get_button_state(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet @@ -1583,7 +1583,7 @@ libinput_event_tablet_get_button_state(struct libinput_event_tablet *event); * @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); +libinput_event_tablet_tool_get_seat_button_count(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet @@ -1592,7 +1592,7 @@ libinput_event_tablet_get_seat_button_count(struct libinput_event_tablet *event) * @return The event time for this event */ uint32_t -libinput_event_tablet_get_time(struct libinput_event_tablet *event); +libinput_event_tablet_tool_get_time(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet @@ -1601,7 +1601,7 @@ libinput_event_tablet_get_time(struct libinput_event_tablet *event); * @return The event time for this event in microseconds */ uint64_t -libinput_event_tablet_get_time_usec(struct libinput_event_tablet *event); +libinput_event_tablet_tool_get_time_usec(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet diff --git a/src/libinput.sym b/src/libinput.sym index 33d5b33f..5f9cbef3 100644 --- a/src/libinput.sym +++ b/src/libinput.sym @@ -184,22 +184,22 @@ LIBINPUT_1.1 { /* 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_tip_state; - libinput_event_tablet_get_tool; - libinput_event_tablet_get_x_transformed; - libinput_event_tablet_get_y_transformed; - libinput_event_tablet_get_time_usec; + libinput_event_get_tablet_tool_event; + libinput_event_tablet_tool_axis_has_changed; + libinput_event_tablet_tool_get_axis_delta; + libinput_event_tablet_tool_get_axis_delta_discrete; + libinput_event_tablet_tool_get_axis_value; + libinput_event_tablet_tool_get_base_event; + libinput_event_tablet_tool_get_button; + libinput_event_tablet_tool_get_button_state; + libinput_event_tablet_tool_get_proximity_state; + libinput_event_tablet_tool_get_seat_button_count; + libinput_event_tablet_tool_get_time; + libinput_event_tablet_tool_get_tip_state; + libinput_event_tablet_tool_get_tool; + libinput_event_tablet_tool_get_x_transformed; + libinput_event_tablet_tool_get_y_transformed; + libinput_event_tablet_tool_get_time_usec; libinput_tool_get_serial; libinput_tool_get_tool_id; libinput_tool_get_type; diff --git a/test/litest.c b/test/litest.c index d9fa32be..2dd45558 100644 --- a/test/litest.c +++ b/test/litest.c @@ -1901,7 +1901,7 @@ static void litest_print_event(struct libinput_event *event) { struct libinput_event_pointer *p; - struct libinput_event_tablet *t; + struct libinput_event_tablet_tool *t; struct libinput_device *dev; enum libinput_event_type type; double x, y; @@ -1948,20 +1948,20 @@ litest_print_event(struct libinput_event *event) fprintf(stderr, "vert %.f horiz %.2f", y, x); break; case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: - t = libinput_event_get_tablet_event(event); + t = libinput_event_get_tablet_tool_event(event); fprintf(stderr, "proximity %d\n", - libinput_event_tablet_get_proximity_state(t)); + libinput_event_tablet_tool_get_proximity_state(t)); break; case LIBINPUT_EVENT_TABLET_TOOL_TIP: - t = libinput_event_get_tablet_event(event); + t = libinput_event_get_tablet_tool_event(event); fprintf(stderr, "tip %d\n", - libinput_event_tablet_get_tip_state(t)); + libinput_event_tablet_tool_get_tip_state(t)); break; case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: - t = libinput_event_get_tablet_event(event); + t = libinput_event_get_tablet_tool_event(event); fprintf(stderr, "button %d state %d\n", - libinput_event_tablet_get_button(t), - libinput_event_tablet_get_button_state(t)); + libinput_event_tablet_tool_get_button(t), + libinput_event_tablet_tool_get_button_state(t)); break; default: break; @@ -2330,16 +2330,16 @@ litest_is_gesture_event(struct libinput_event *event, return gevent; } -struct libinput_event_tablet * litest_is_tablet_event( +struct libinput_event_tablet_tool * litest_is_tablet_event( struct libinput_event *event, enum libinput_event_type type) { - struct libinput_event_tablet *tevent; + struct libinput_event_tablet_tool *tevent; litest_assert(event != NULL); litest_assert_int_eq(libinput_event_get_type(event), type); - tevent = libinput_event_get_tablet_event(event); + tevent = libinput_event_get_tablet_tool_event(event); litest_assert(tevent != NULL); return tevent; @@ -2350,7 +2350,7 @@ 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; + struct libinput_event_tablet_tool *tev; enum libinput_event_type type = LIBINPUT_EVENT_TABLET_TOOL_BUTTON; litest_wait_for_event(li); @@ -2358,10 +2358,10 @@ litest_assert_tablet_button_event(struct libinput *li, unsigned int button, 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), + tev = libinput_event_get_tablet_tool_event(event); + litest_assert_int_eq(libinput_event_tablet_tool_get_button(tev), button); - litest_assert_int_eq(libinput_event_tablet_get_button_state(tev), + litest_assert_int_eq(libinput_event_tablet_tool_get_button_state(tev), state); libinput_event_destroy(event); } diff --git a/test/litest.h b/test/litest.h index a7a447e4..6216ac7a 100644 --- a/test/litest.h +++ b/test/litest.h @@ -402,7 +402,7 @@ struct libinput_event_gesture * litest_is_gesture_event( struct libinput_event *event, enum libinput_event_type type, int nfingers); -struct libinput_event_tablet * litest_is_tablet_event( +struct libinput_event_tablet_tool * litest_is_tablet_event( struct libinput_event *event, enum libinput_event_type type); diff --git a/test/misc.c b/test/misc.c index 7ba6f9c8..d8804961 100644 --- a/test/misc.c +++ b/test/misc.c @@ -133,7 +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); + ck_assert(libinput_event_get_tablet_tool_event(event) == NULL); litest_restore_log_handler(li); } @@ -189,7 +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); + ck_assert(libinput_event_get_tablet_tool_event(event) == NULL); litest_restore_log_handler(li); } libinput_event_destroy(event); @@ -239,7 +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); + ck_assert(libinput_event_get_tablet_tool_event(event) == NULL); litest_restore_log_handler(li); } libinput_event_destroy(event); @@ -282,7 +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); + ck_assert(libinput_event_get_tablet_tool_event(event) == NULL); litest_restore_log_handler(li); } libinput_event_destroy(event); @@ -332,7 +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); + ck_assert(libinput_event_get_tablet_tool_event(event) == NULL); litest_restore_log_handler(li); } libinput_event_destroy(event); @@ -414,10 +414,10 @@ START_TEST(event_conversion_tablet) if (type >= LIBINPUT_EVENT_TABLET_TOOL_AXIS && type <= LIBINPUT_EVENT_TABLET_TOOL_BUTTON) { - struct libinput_event_tablet *t; + struct libinput_event_tablet_tool *t; struct libinput_event *base; - t = libinput_event_get_tablet_event(event); - base = libinput_event_tablet_get_base_event(t); + t = libinput_event_get_tablet_tool_event(event); + base = libinput_event_tablet_tool_get_base_event(t); ck_assert(event == base); events++; diff --git a/test/tablet.c b/test/tablet.c index 383a7b1c..8c6a273a 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -39,7 +39,7 @@ START_TEST(tip_down_up) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; - struct libinput_event_tablet *tablet_event; + struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { -1, -1 } @@ -55,7 +55,7 @@ START_TEST(tip_down_up) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); - ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); litest_assert_empty_queue(li); @@ -67,7 +67,7 @@ START_TEST(tip_down_up) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); - ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); litest_assert_empty_queue(li); @@ -82,7 +82,7 @@ START_TEST(tip_down_prox_in) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; - struct libinput_event_tablet *tablet_event; + struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { -1, -1 } @@ -99,7 +99,7 @@ START_TEST(tip_down_prox_in) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); - ck_assert_int_eq(libinput_event_tablet_get_proximity_state(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_proximity_state(tablet_event), LIBINPUT_TABLET_TOOL_PROXIMITY_IN); libinput_event_destroy(event); @@ -107,7 +107,7 @@ START_TEST(tip_down_prox_in) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); - ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); @@ -121,7 +121,7 @@ START_TEST(tip_up_prox_out) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; - struct libinput_event_tablet *tablet_event; + struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { -1, -1 } @@ -141,7 +141,7 @@ START_TEST(tip_up_prox_out) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); - ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); @@ -149,7 +149,7 @@ START_TEST(tip_up_prox_out) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); - ck_assert_int_eq(libinput_event_tablet_get_proximity_state(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_proximity_state(tablet_event), LIBINPUT_TABLET_TOOL_PROXIMITY_OUT); libinput_event_destroy(event); @@ -163,7 +163,7 @@ START_TEST(tip_up_btn_change) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; - struct libinput_event_tablet *tablet_event; + struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { -1, -1 } @@ -182,9 +182,9 @@ START_TEST(tip_up_btn_change) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); - ck_assert_int_eq(libinput_event_tablet_get_button(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_button(tablet_event), BTN_STYLUS); - ck_assert_int_eq(libinput_event_tablet_get_button_state(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_button_state(tablet_event), LIBINPUT_BUTTON_STATE_PRESSED); libinput_event_destroy(event); @@ -192,7 +192,7 @@ START_TEST(tip_up_btn_change) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); - ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); @@ -211,9 +211,9 @@ START_TEST(tip_up_btn_change) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); - ck_assert_int_eq(libinput_event_tablet_get_button(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_button(tablet_event), BTN_STYLUS); - ck_assert_int_eq(libinput_event_tablet_get_button_state(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_button_state(tablet_event), LIBINPUT_BUTTON_STATE_RELEASED); libinput_event_destroy(event); @@ -221,7 +221,7 @@ START_TEST(tip_up_btn_change) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); - ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); @@ -234,7 +234,7 @@ START_TEST(tip_down_btn_change) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; - struct libinput_event_tablet *tablet_event; + struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { -1, -1 } @@ -251,7 +251,7 @@ START_TEST(tip_down_btn_change) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); - ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); @@ -259,9 +259,9 @@ START_TEST(tip_down_btn_change) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); - ck_assert_int_eq(libinput_event_tablet_get_button(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_button(tablet_event), BTN_STYLUS); - ck_assert_int_eq(libinput_event_tablet_get_button_state(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_button_state(tablet_event), LIBINPUT_BUTTON_STATE_PRESSED); libinput_event_destroy(event); @@ -280,7 +280,7 @@ START_TEST(tip_down_btn_change) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); - ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); @@ -288,9 +288,9 @@ START_TEST(tip_down_btn_change) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); - ck_assert_int_eq(libinput_event_tablet_get_button(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_button(tablet_event), BTN_STYLUS); - ck_assert_int_eq(libinput_event_tablet_get_button_state(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_button_state(tablet_event), LIBINPUT_BUTTON_STATE_RELEASED); libinput_event_destroy(event); @@ -303,7 +303,7 @@ START_TEST(tip_down_motion) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; - struct libinput_event_tablet *tablet_event; + struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { -1, -1 } @@ -323,9 +323,9 @@ START_TEST(tip_down_motion) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); - last_x = libinput_event_tablet_get_axis_value(tablet_event, + last_x = libinput_event_tablet_tool_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); - last_y = libinput_event_tablet_get_axis_value(tablet_event, + last_y = libinput_event_tablet_tool_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); libinput_event_destroy(event); @@ -333,11 +333,11 @@ START_TEST(tip_down_motion) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); - ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_DOWN); - x = libinput_event_tablet_get_axis_value(tablet_event, + x = libinput_event_tablet_tool_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); - y = libinput_event_tablet_get_axis_value(tablet_event, + y = libinput_event_tablet_tool_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); ck_assert_double_eq(last_x, x); ck_assert_double_eq(last_y, y); @@ -352,7 +352,7 @@ START_TEST(tip_up_motion) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; - struct libinput_event_tablet *tablet_event; + struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { -1, -1 } @@ -374,9 +374,9 @@ START_TEST(tip_up_motion) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); - last_x = libinput_event_tablet_get_axis_value(tablet_event, + last_x = libinput_event_tablet_tool_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); - last_y = libinput_event_tablet_get_axis_value(tablet_event, + last_y = libinput_event_tablet_tool_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); libinput_event_destroy(event); @@ -384,11 +384,11 @@ START_TEST(tip_up_motion) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); - ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); - x = libinput_event_tablet_get_axis_value(tablet_event, + x = libinput_event_tablet_tool_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); - y = libinput_event_tablet_get_axis_value(tablet_event, + y = libinput_event_tablet_tool_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); ck_assert_double_eq(last_x, x); ck_assert_double_eq(last_y, y); @@ -403,7 +403,7 @@ START_TEST(tip_state_proximity) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; - struct libinput_event_tablet *tablet_event; + struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { -1, -1 } @@ -417,7 +417,7 @@ START_TEST(tip_state_proximity) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); - ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); @@ -433,7 +433,7 @@ START_TEST(tip_state_proximity) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); - ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); } @@ -444,7 +444,7 @@ START_TEST(tip_state_axis) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; - struct libinput_event_tablet *tablet_event; + struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { -1, -1 } @@ -459,7 +459,7 @@ START_TEST(tip_state_axis) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); - ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); @@ -473,7 +473,7 @@ START_TEST(tip_state_axis) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); - ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); @@ -487,7 +487,7 @@ START_TEST(tip_state_axis) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); - ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); @@ -500,7 +500,7 @@ START_TEST(tip_state_button) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; - struct libinput_event_tablet *tablet_event; + struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { -1, -1 } @@ -516,7 +516,7 @@ START_TEST(tip_state_button) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); - ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); @@ -531,7 +531,7 @@ START_TEST(tip_state_button) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); - ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); @@ -546,7 +546,7 @@ START_TEST(tip_state_button) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); - ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); @@ -557,7 +557,7 @@ START_TEST(tip_state_button) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); - ck_assert_int_eq(libinput_event_tablet_get_tip_state(tablet_event), + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); @@ -569,7 +569,7 @@ 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_tablet_tool *tablet_event; struct libinput_event *event; bool have_tool_update = false, have_proximity_out = false; @@ -590,8 +590,8 @@ START_TEST(proximity_in_out) struct libinput_tablet_tool * tool; have_tool_update++; - tablet_event = libinput_event_get_tablet_event(event); - tool = libinput_event_tablet_get_tool(tablet_event); + tablet_event = libinput_event_get_tablet_tool_event(event); + tool = libinput_event_tablet_tool_get_tool(tablet_event); ck_assert_int_eq(libinput_tool_get_type(tool), LIBINPUT_TABLET_TOOL_TYPE_PEN); } @@ -605,10 +605,10 @@ START_TEST(proximity_in_out) while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY) { - struct libinput_event_tablet *t = - libinput_event_get_tablet_event(event); + struct libinput_event_tablet_tool *t = + libinput_event_get_tablet_tool_event(event); - if (libinput_event_tablet_get_proximity_state(t) == + if (libinput_event_tablet_tool_get_proximity_state(t) == LIBINPUT_TABLET_TOOL_PROXIMITY_OUT) have_proximity_out = true; } @@ -635,7 +635,7 @@ 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_tablet_tool *tablet_event; struct libinput_event *event; uint32_t button; @@ -665,13 +665,13 @@ START_TEST(proximity_out_clear_buttons) libinput_dispatch(li); while ((event = libinput_get_event(li))) { - tablet_event = libinput_event_get_tablet_event(event); + tablet_event = libinput_event_get_tablet_tool_event(event); if (libinput_event_get_type(event) == LIBINPUT_EVENT_TABLET_TOOL_BUTTON) { - event_button = libinput_event_tablet_get_button(tablet_event); - state = libinput_event_tablet_get_button_state(tablet_event); + event_button = libinput_event_tablet_tool_get_button(tablet_event); + state = libinput_event_tablet_tool_get_button_state(tablet_event); if (event_button == button && state == LIBINPUT_BUTTON_STATE_RELEASED) @@ -695,7 +695,7 @@ 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_tablet_tool *tablet_event; struct libinput_event *event; struct libinput_tablet_tool *tool; double x, y, @@ -718,28 +718,28 @@ START_TEST(proximity_has_axes) event = libinput_get_event(li); - tablet_event = libinput_event_get_tablet_event(event); - tool = libinput_event_tablet_get_tool(tablet_event); + tablet_event = libinput_event_get_tablet_tool_event(event); + tool = libinput_event_tablet_tool_get_tool(tablet_event); - ck_assert(libinput_event_tablet_axis_has_changed( + ck_assert(libinput_event_tablet_tool_axis_has_changed( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X)); - ck_assert(libinput_event_tablet_axis_has_changed( + ck_assert(libinput_event_tablet_tool_axis_has_changed( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y)); - x = libinput_event_tablet_get_axis_value(tablet_event, + x = libinput_event_tablet_tool_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); - y = libinput_event_tablet_get_axis_value(tablet_event, + y = libinput_event_tablet_tool_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); litest_assert_double_ne(x, 0); litest_assert_double_ne(y, 0); if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) { - ck_assert(libinput_event_tablet_axis_has_changed( + ck_assert(libinput_event_tablet_tool_axis_has_changed( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)); - distance = libinput_event_tablet_get_axis_value( + distance = libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); litest_assert_double_ne(distance, 0); @@ -747,17 +747,17 @@ START_TEST(proximity_has_axes) if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) && libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { - ck_assert(libinput_event_tablet_axis_has_changed( + ck_assert(libinput_event_tablet_tool_axis_has_changed( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_TILT_X)); - ck_assert(libinput_event_tablet_axis_has_changed( + ck_assert(libinput_event_tablet_tool_axis_has_changed( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)); - x = libinput_event_tablet_get_axis_value( + x = libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_TILT_X); - y = libinput_event_tablet_get_axis_value( + y = libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); @@ -775,22 +775,22 @@ START_TEST(proximity_has_axes) libinput_dispatch(li); litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, -1); event = libinput_get_event(li); - tablet_event = libinput_event_get_tablet_event(event); + tablet_event = libinput_event_get_tablet_tool_event(event); - last_x = libinput_event_tablet_get_axis_value(tablet_event, + last_x = libinput_event_tablet_tool_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); - last_y = libinput_event_tablet_get_axis_value(tablet_event, + last_y = libinput_event_tablet_tool_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) - last_distance = libinput_event_tablet_get_axis_value( + last_distance = libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) && libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { - last_tx = libinput_event_tablet_get_axis_value( + last_tx = libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_TILT_X); - last_ty = libinput_event_tablet_get_axis_value( + last_ty = libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); } @@ -803,27 +803,27 @@ START_TEST(proximity_has_axes) litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); event = libinput_get_event(li); - tablet_event = libinput_event_get_tablet_event(event); - tool = libinput_event_tablet_get_tool(tablet_event); + tablet_event = libinput_event_get_tablet_tool_event(event); + tool = libinput_event_tablet_tool_get_tool(tablet_event); - ck_assert(!libinput_event_tablet_axis_has_changed( + ck_assert(!libinput_event_tablet_tool_axis_has_changed( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X)); - ck_assert(!libinput_event_tablet_axis_has_changed( + ck_assert(!libinput_event_tablet_tool_axis_has_changed( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y)); - x = libinput_event_tablet_get_axis_value(tablet_event, + x = libinput_event_tablet_tool_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); - y = libinput_event_tablet_get_axis_value(tablet_event, + y = libinput_event_tablet_tool_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); litest_assert_double_eq(x, last_x); litest_assert_double_eq(y, last_y); if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) { - ck_assert(!libinput_event_tablet_axis_has_changed( + ck_assert(!libinput_event_tablet_tool_axis_has_changed( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)); - distance = libinput_event_tablet_get_axis_value( + distance = libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); litest_assert_double_eq(distance, last_distance); @@ -831,17 +831,17 @@ START_TEST(proximity_has_axes) if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) && libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { - ck_assert(!libinput_event_tablet_axis_has_changed( + ck_assert(!libinput_event_tablet_tool_axis_has_changed( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_TILT_X)); - ck_assert(!libinput_event_tablet_axis_has_changed( + ck_assert(!libinput_event_tablet_tool_axis_has_changed( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)); - x = libinput_event_tablet_get_axis_value( + x = libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_TILT_X); - y = libinput_event_tablet_get_axis_value( + y = libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); @@ -858,7 +858,7 @@ START_TEST(motion) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; - struct libinput_event_tablet *tablet_event; + struct libinput_event_tablet_tool *tablet_event; struct libinput_event *event; int test_x, test_y; double last_reported_x = 0, last_reported_y = 0; @@ -881,21 +881,21 @@ START_TEST(motion) bool x_changed, y_changed; double reported_x, reported_y; - tablet_event = libinput_event_get_tablet_event(event); + tablet_event = libinput_event_get_tablet_tool_event(event); ck_assert_int_eq(libinput_event_get_type(event), LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); - x_changed = libinput_event_tablet_axis_has_changed( + x_changed = libinput_event_tablet_tool_axis_has_changed( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); - y_changed = libinput_event_tablet_axis_has_changed( + y_changed = libinput_event_tablet_tool_axis_has_changed( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); ck_assert(x_changed); ck_assert(y_changed); - reported_x = libinput_event_tablet_get_axis_value( + reported_x = libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); - reported_y = libinput_event_tablet_get_axis_value( + reported_y = libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); litest_assert_double_lt(reported_x, reported_y); @@ -916,21 +916,21 @@ START_TEST(motion) libinput_dispatch(li); while ((event = libinput_get_event(li))) { - tablet_event = libinput_event_get_tablet_event(event); + tablet_event = libinput_event_get_tablet_tool_event(event); type = libinput_event_get_type(event); if (type == LIBINPUT_EVENT_TABLET_TOOL_AXIS) { - x_changed = libinput_event_tablet_axis_has_changed( + x_changed = libinput_event_tablet_tool_axis_has_changed( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); - y_changed = libinput_event_tablet_axis_has_changed( + y_changed = libinput_event_tablet_tool_axis_has_changed( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); ck_assert(x_changed); ck_assert(y_changed); - reported_x = libinput_event_tablet_get_axis_value( + reported_x = libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); - reported_y = libinput_event_tablet_get_axis_value( + reported_y = libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); litest_assert_double_gt(reported_x, @@ -952,7 +952,7 @@ 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_tablet_tool *tablet_event; struct libinput_event *event; double x1, y1, x2, y2, dist1, dist2; double delta; @@ -971,12 +971,12 @@ START_TEST(motion_delta) -1); event = libinput_get_event(li); - tablet_event = libinput_event_get_tablet_event(event); - x1 = libinput_event_tablet_get_axis_value(tablet_event, + tablet_event = libinput_event_get_tablet_tool_event(event); + x1 = libinput_event_tablet_tool_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); - y1 = libinput_event_tablet_get_axis_value(tablet_event, + y1 = libinput_event_tablet_tool_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); - dist1 = libinput_event_tablet_get_axis_value(tablet_event, + dist1 = libinput_event_tablet_tool_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); libinput_event_destroy(event); @@ -987,21 +987,21 @@ START_TEST(motion_delta) LIBINPUT_EVENT_TABLET_TOOL_AXIS, -1); event = libinput_get_event(li); - tablet_event = libinput_event_get_tablet_event(event); - x2 = libinput_event_tablet_get_axis_value(tablet_event, + tablet_event = libinput_event_get_tablet_tool_event(event); + x2 = libinput_event_tablet_tool_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); - y2 = libinput_event_tablet_get_axis_value(tablet_event, + y2 = libinput_event_tablet_tool_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); - dist2 = libinput_event_tablet_get_axis_value(tablet_event, + dist2 = libinput_event_tablet_tool_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); - delta = libinput_event_tablet_get_axis_delta(tablet_event, + delta = libinput_event_tablet_tool_get_axis_delta(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); litest_assert_double_eq(delta, x2 - x1); - delta = libinput_event_tablet_get_axis_delta(tablet_event, + delta = libinput_event_tablet_tool_get_axis_delta(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); litest_assert_double_eq(delta, y2 - y1); - delta = libinput_event_tablet_get_axis_delta(tablet_event, + delta = libinput_event_tablet_tool_get_axis_delta(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); litest_assert_double_eq(delta, dist2 - dist1); @@ -1013,7 +1013,7 @@ 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_tablet_tool *tablet_event; struct libinput_event *event; double dx, dy, ddist; struct axis_replacement axes[] = { @@ -1034,23 +1034,23 @@ START_TEST(motion_delta_partial) LIBINPUT_EVENT_TABLET_TOOL_AXIS, -1); event = libinput_get_event(li); - tablet_event = libinput_event_get_tablet_event(event); + tablet_event = libinput_event_get_tablet_tool_event(event); - ck_assert(!libinput_event_tablet_axis_has_changed(tablet_event, + ck_assert(!libinput_event_tablet_tool_axis_has_changed(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X)); - dx = libinput_event_tablet_get_axis_delta(tablet_event, + dx = libinput_event_tablet_tool_get_axis_delta(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); litest_assert_double_eq(dx, 0.0); - ck_assert(!libinput_event_tablet_axis_has_changed(tablet_event, + ck_assert(!libinput_event_tablet_tool_axis_has_changed(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X)); - dy = libinput_event_tablet_get_axis_delta(tablet_event, + dy = libinput_event_tablet_tool_get_axis_delta(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); litest_assert_double_eq(dy, 0.0); - ck_assert(libinput_event_tablet_axis_has_changed(tablet_event, + ck_assert(libinput_event_tablet_tool_axis_has_changed(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)); - ddist = libinput_event_tablet_get_axis_delta(tablet_event, + ddist = libinput_event_tablet_tool_get_axis_delta(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); ck_assert_double_gt(ddist, 0); @@ -1064,7 +1064,7 @@ START_TEST(left_handed) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct libinput_event *event; - struct libinput_event_tablet *tablet_event; + struct libinput_event_tablet_tool *tablet_event; double libinput_max_x, libinput_max_y; double last_x = -1.0, last_y = -1.0; struct axis_replacement axes[] = { @@ -1090,11 +1090,11 @@ START_TEST(left_handed) litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); while ((event = libinput_get_event(li))) { - tablet_event = libinput_event_get_tablet_event(event); + tablet_event = libinput_event_get_tablet_tool_event(event); - last_x = libinput_event_tablet_get_axis_value( + last_x = libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); - last_y = libinput_event_tablet_get_axis_value( + last_y = libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); litest_assert_double_eq(last_x, 0); @@ -1108,11 +1108,11 @@ START_TEST(left_handed) while ((event = libinput_get_event(li))) { double x, y; - tablet_event = libinput_event_get_tablet_event(event); + tablet_event = libinput_event_get_tablet_tool_event(event); - x = libinput_event_tablet_get_axis_value( + x = libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); - y = libinput_event_tablet_get_axis_value( + y = libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); litest_assert_double_eq(x, libinput_max_x); @@ -1136,11 +1136,11 @@ START_TEST(left_handed) litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); while ((event = libinput_get_event(li))) { - tablet_event = libinput_event_get_tablet_event(event); + tablet_event = libinput_event_get_tablet_tool_event(event); - last_x = libinput_event_tablet_get_axis_value( + last_x = libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); - last_y = libinput_event_tablet_get_axis_value( + last_y = libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); litest_assert_double_eq(last_x, libinput_max_x); @@ -1154,11 +1154,11 @@ START_TEST(left_handed) while ((event = libinput_get_event(li))) { double x, y; - tablet_event = libinput_event_get_tablet_event(event); + tablet_event = libinput_event_get_tablet_tool_event(event); - x = libinput_event_tablet_get_axis_value( + x = libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); - y = libinput_event_tablet_get_axis_value( + y = libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); litest_assert_double_eq(x, 0); @@ -1186,7 +1186,7 @@ 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; + struct libinput_event_tablet_tool *tablet_event; int test_x, test_y; double last_x, last_y; @@ -1213,12 +1213,12 @@ START_TEST(motion_event_state) /* pop the first event off */ ck_assert_notnull(event); - tablet_event = libinput_event_get_tablet_event(event); + tablet_event = libinput_event_get_tablet_tool_event(event); ck_assert_notnull(tablet_event); - last_x = libinput_event_tablet_get_axis_value(tablet_event, + last_x = libinput_event_tablet_tool_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); - last_y = libinput_event_tablet_get_axis_value(tablet_event, + last_y = libinput_event_tablet_tool_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); /* mark with a button event, then go back to bottom/left */ @@ -1241,12 +1241,12 @@ START_TEST(motion_event_state) if (libinput_event_get_type(event) != LIBINPUT_EVENT_TABLET_TOOL_AXIS) break; - tablet_event = libinput_event_get_tablet_event(event); + tablet_event = libinput_event_get_tablet_tool_event(event); ck_assert_notnull(tablet_event); - x = libinput_event_tablet_get_axis_value(tablet_event, + x = libinput_event_tablet_tool_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); - y = libinput_event_tablet_get_axis_value(tablet_event, + y = libinput_event_tablet_tool_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); ck_assert(x > last_x); @@ -1292,7 +1292,7 @@ START_TEST(normalization) { struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; - struct libinput_event_tablet *tablet_event; + struct libinput_event_tablet_tool *tablet_event; struct libinput_event *event; double pressure, tilt_vertical, @@ -1332,33 +1332,33 @@ START_TEST(normalization) while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == LIBINPUT_EVENT_TABLET_TOOL_AXIS) { - tablet_event = libinput_event_get_tablet_event(event); + tablet_event = libinput_event_get_tablet_tool_event(event); - if (libinput_event_tablet_axis_has_changed( + if (libinput_event_tablet_tool_axis_has_changed( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) { - pressure = libinput_event_tablet_get_axis_value( + pressure = libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); litest_assert_double_eq(pressure, 0); } - if (libinput_event_tablet_axis_has_changed( + if (libinput_event_tablet_tool_axis_has_changed( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_TILT_X)) { tilt_vertical = - libinput_event_tablet_get_axis_value( + libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_TILT_X); litest_assert_double_eq(tilt_vertical, -1); } - if (libinput_event_tablet_axis_has_changed( + if (libinput_event_tablet_tool_axis_has_changed( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { tilt_horizontal = - libinput_event_tablet_get_axis_value( + libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); @@ -1394,33 +1394,33 @@ START_TEST(normalization) while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == LIBINPUT_EVENT_TABLET_TOOL_AXIS) { - tablet_event = libinput_event_get_tablet_event(event); + tablet_event = libinput_event_get_tablet_tool_event(event); - if (libinput_event_tablet_axis_has_changed( + if (libinput_event_tablet_tool_axis_has_changed( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) { - pressure = libinput_event_tablet_get_axis_value( + pressure = libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); litest_assert_double_eq(pressure, 1); } - if (libinput_event_tablet_axis_has_changed( + if (libinput_event_tablet_tool_axis_has_changed( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_TILT_X)) { tilt_vertical = - libinput_event_tablet_get_axis_value( + libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_TILT_X); litest_assert_double_eq(tilt_vertical, 1); } - if (libinput_event_tablet_axis_has_changed( + if (libinput_event_tablet_tool_axis_has_changed( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { tilt_horizontal = - libinput_event_tablet_get_axis_value( + libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); @@ -1438,7 +1438,7 @@ 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_tablet_tool *tablet_event; struct libinput_event *event; struct libinput_tablet_tool *tool; @@ -1452,8 +1452,8 @@ START_TEST(tool_serial) LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); event = libinput_get_event(li); - tablet_event = libinput_event_get_tablet_event(event); - tool = libinput_event_tablet_get_tool(tablet_event); + tablet_event = libinput_event_get_tablet_tool_event(event); + tool = libinput_event_tablet_tool_get_tool(tablet_event); ck_assert_uint_eq(libinput_tool_get_serial(tool), 1000); libinput_event_destroy(event); } @@ -1463,7 +1463,7 @@ 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_tablet_tool *tablet_event; struct libinput_event *event; struct libinput_tablet_tool *tool; @@ -1484,8 +1484,8 @@ START_TEST(serial_changes_tool) LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); event = libinput_get_event(li); - tablet_event = libinput_event_get_tablet_event(event); - tool = libinput_event_tablet_get_tool(tablet_event); + tablet_event = libinput_event_get_tablet_tool_event(event); + tool = libinput_event_tablet_tool_get_tool(tablet_event); ck_assert_uint_eq(libinput_tool_get_serial(tool), 2000); libinput_event_destroy(event); @@ -1497,7 +1497,7 @@ 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_event_tablet_tool *tablet_event; struct libinput_tablet_tool *tool; litest_drain_events(li); @@ -1517,8 +1517,8 @@ START_TEST(invalid_serials) while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY) { - tablet_event = libinput_event_get_tablet_event(event); - tool = libinput_event_tablet_get_tool(tablet_event); + tablet_event = libinput_event_get_tablet_tool_event(event); + tool = libinput_event_tablet_tool_get_tool(tablet_event); ck_assert_uint_eq(libinput_tool_get_serial(tool), 1000); } @@ -1532,7 +1532,7 @@ 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_tablet_tool *tablet_event; struct libinput_event *event; struct libinput_tablet_tool *tool; @@ -1546,8 +1546,8 @@ START_TEST(tool_ref) LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); event = libinput_get_event(li); - tablet_event = libinput_event_get_tablet_event(event); - tool = libinput_event_tablet_get_tool(tablet_event); + tablet_event = libinput_event_get_tablet_tool_event(event); + tool = libinput_event_tablet_tool_get_tool(tablet_event); ck_assert_notnull(tool); ck_assert(tool == libinput_tool_ref(tool)); @@ -1635,10 +1635,10 @@ START_TEST(tools_with_serials) while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY) { - struct libinput_event_tablet *t = - libinput_event_get_tablet_event(event); + struct libinput_event_tablet_tool *t = + libinput_event_get_tablet_tool_event(event); - tool[i] = libinput_event_tablet_get_tool(t); + tool[i] = libinput_event_tablet_tool_get_tool(t); } libinput_event_destroy(event); @@ -1684,10 +1684,10 @@ START_TEST(tools_without_serials) while ((event = libinput_get_event(li))) { if (libinput_event_get_type(event) == LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY) { - struct libinput_event_tablet *t = - libinput_event_get_tablet_event(event); + struct libinput_event_tablet_tool *t = + libinput_event_get_tablet_tool_event(event); - tool[i] = libinput_event_tablet_get_tool(t); + tool[i] = libinput_event_tablet_tool_get_tool(t); } libinput_event_destroy(event); @@ -1711,7 +1711,7 @@ START_TEST(tool_capabilities) struct litest_device *intuos; struct litest_device *bamboo; struct libinput_event *event; - struct libinput_event_tablet *t; + struct libinput_event_tablet_tool *t; struct libinput_tablet_tool *tool; /* The axis capabilities of a tool can differ depending on the type of @@ -1729,8 +1729,8 @@ START_TEST(tool_capabilities) -1); event = libinput_get_event(li); - t = libinput_event_get_tablet_event(event); - tool = libinput_event_tablet_get_tool(t); + t = libinput_event_get_tablet_tool_event(event); + tool = libinput_event_tablet_tool_get_tool(t); ck_assert(libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)); @@ -1752,8 +1752,8 @@ START_TEST(tool_capabilities) -1); event = libinput_get_event(li); - t = libinput_event_get_tablet_event(event); - tool = libinput_event_tablet_get_tool(t); + t = libinput_event_get_tablet_tool_event(event); + tool = libinput_event_tablet_tool_get_tool(t); ck_assert(libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)); @@ -1830,7 +1830,7 @@ 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_event_tablet_tool *tev; struct libinput_tablet_tool *tool; if (!libevdev_has_event_code(dev->evdev, @@ -1848,8 +1848,8 @@ START_TEST(mouse_tool) LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); event = libinput_get_event(li); - tev = libinput_event_get_tablet_event(event); - tool = libinput_event_tablet_get_tool(tev); + tev = libinput_event_get_tablet_tool_event(event); + tool = libinput_event_tablet_tool_get_tool(tev); ck_assert_notnull(tool); ck_assert_int_eq(libinput_tool_get_type(tool), LIBINPUT_TABLET_TOOL_TYPE_MOUSE); @@ -1863,7 +1863,7 @@ 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_event_tablet_tool *tev; struct libinput_tablet_tool *tool; int code; @@ -1883,8 +1883,8 @@ START_TEST(mouse_buttons) LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); event = libinput_get_event(li); - tev = libinput_event_get_tablet_event(event); - tool = libinput_event_tablet_get_tool(tev); + tev = libinput_event_get_tablet_tool_event(event); + tool = libinput_event_tablet_tool_get_tool(tev); ck_assert_notnull(tool); libinput_tool_ref(tool); @@ -1924,7 +1924,7 @@ 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; + struct libinput_event_tablet_tool *tev; int angle; int tilt_center_x, tilt_center_y; const struct input_absinfo *abs; @@ -1976,10 +1976,10 @@ START_TEST(mouse_rotation) LIBINPUT_EVENT_TABLET_TOOL_AXIS, -1); event = libinput_get_event(li); - tev = libinput_event_get_tablet_event(event); - ck_assert(libinput_event_tablet_axis_has_changed(tev, + tev = libinput_event_get_tablet_tool_event(event); + ck_assert(libinput_event_tablet_tool_axis_has_changed(tev, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)); - val = libinput_event_tablet_get_axis_value(tev, + val = libinput_event_tablet_tool_get_axis_value(tev, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); /* rounding error galore, we can't test for anything more @@ -2000,7 +2000,7 @@ 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_event_tablet_tool *tev; struct libinput_tablet_tool *tool; const struct input_absinfo *abs; double val; @@ -2022,8 +2022,8 @@ START_TEST(mouse_wheel) LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); event = libinput_get_event(li); - tev = libinput_event_get_tablet_event(event); - tool = libinput_event_tablet_get_tool(tev); + tev = libinput_event_get_tablet_tool_event(event); + tool = libinput_event_tablet_tool_get_tool(tev); ck_assert_notnull(tool); libinput_tool_ref(tool); @@ -2039,18 +2039,18 @@ START_TEST(mouse_wheel) litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, -1); event = libinput_get_event(li); - tev = libinput_event_get_tablet_event(event); - ck_assert(libinput_event_tablet_axis_has_changed(tev, + tev = libinput_event_get_tablet_tool_event(event); + ck_assert(libinput_event_tablet_tool_axis_has_changed(tev, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL)); - val = libinput_event_tablet_get_axis_value(tev, + val = libinput_event_tablet_tool_get_axis_value(tev, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); ck_assert_int_eq(val, 0); - val = libinput_event_tablet_get_axis_delta(tev, + val = libinput_event_tablet_tool_get_axis_delta(tev, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); ck_assert_int_eq(val, 15); - val = libinput_event_tablet_get_axis_delta_discrete(tev, + val = libinput_event_tablet_tool_get_axis_delta_discrete(tev, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); ck_assert_int_eq(val, 1); @@ -2070,18 +2070,18 @@ START_TEST(mouse_wheel) litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, -1); event = libinput_get_event(li); - tev = libinput_event_get_tablet_event(event); - ck_assert(!libinput_event_tablet_axis_has_changed(tev, + tev = libinput_event_get_tablet_tool_event(event); + ck_assert(!libinput_event_tablet_tool_axis_has_changed(tev, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL)); - val = libinput_event_tablet_get_axis_value(tev, + val = libinput_event_tablet_tool_get_axis_value(tev, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); ck_assert_int_eq(val, 0); - val = libinput_event_tablet_get_axis_delta(tev, + val = libinput_event_tablet_tool_get_axis_delta(tev, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); ck_assert_int_eq(val, 0); - val = libinput_event_tablet_get_axis_delta_discrete(tev, + val = libinput_event_tablet_tool_get_axis_delta_discrete(tev, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); ck_assert_int_eq(val, 0); @@ -2099,7 +2099,7 @@ 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_event_tablet_tool *tev; struct libinput_tablet_tool *tool; if (!libevdev_has_event_code(dev->evdev, @@ -2117,8 +2117,8 @@ START_TEST(airbrush_tool) LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); event = libinput_get_event(li); - tev = libinput_event_get_tablet_event(event); - tool = libinput_event_tablet_get_tool(tev); + tev = libinput_event_get_tablet_tool_event(event); + tool = libinput_event_tablet_tool_get_tool(tev); ck_assert_notnull(tool); ck_assert_int_eq(libinput_tool_get_type(tool), LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH); @@ -2132,7 +2132,7 @@ 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; + struct libinput_event_tablet_tool *tev; const struct input_absinfo *abs; double val; double scale; @@ -2167,10 +2167,10 @@ START_TEST(airbrush_wheel) LIBINPUT_EVENT_TABLET_TOOL_AXIS, -1); event = libinput_get_event(li); - tev = libinput_event_get_tablet_event(event); - ck_assert(libinput_event_tablet_axis_has_changed(tev, + tev = libinput_event_get_tablet_tool_event(event); + ck_assert(libinput_event_tablet_tool_axis_has_changed(tev, LIBINPUT_TABLET_TOOL_AXIS_SLIDER)); - val = libinput_event_tablet_get_axis_value(tev, + val = libinput_event_tablet_tool_get_axis_value(tev, LIBINPUT_TABLET_TOOL_AXIS_SLIDER); ck_assert_int_eq(val, (v - abs->minimum)/scale); @@ -2185,7 +2185,7 @@ 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_event_tablet_tool *tev; struct libinput_tablet_tool *tool; if (!libevdev_has_event_code(dev->evdev, @@ -2204,8 +2204,8 @@ START_TEST(artpen_tool) LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); event = libinput_get_event(li); - tev = libinput_event_get_tablet_event(event); - tool = libinput_event_tablet_get_tool(tev); + tev = libinput_event_get_tablet_tool_event(event); + tool = libinput_event_tablet_tool_get_tool(tev); ck_assert_notnull(tool); ck_assert_int_eq(libinput_tool_get_type(tool), LIBINPUT_TABLET_TOOL_TYPE_PEN); @@ -2221,7 +2221,7 @@ 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; + struct libinput_event_tablet_tool *tev; const struct input_absinfo *abs; double val; double scale; @@ -2258,16 +2258,16 @@ START_TEST(artpen_rotation) LIBINPUT_EVENT_TABLET_TOOL_AXIS, -1); event = libinput_get_event(li); - tev = libinput_event_get_tablet_event(event); - ck_assert(libinput_event_tablet_axis_has_changed(tev, + tev = libinput_event_get_tablet_tool_event(event); + ck_assert(libinput_event_tablet_tool_axis_has_changed(tev, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)); - val = libinput_event_tablet_get_axis_value(tev, + val = libinput_event_tablet_tool_get_axis_value(tev, LIBINPUT_TABLET_TOOL_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, + val = libinput_event_tablet_tool_get_axis_delta(tev, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); ck_assert_int_eq(val, 8); @@ -2283,7 +2283,7 @@ 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 libinput_event_tablet_tool *tev; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { -1, -1 } @@ -2298,9 +2298,9 @@ START_TEST(tablet_time_usec) LIBINPUT_EVENT_TABLET_TOOL_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); + tev = libinput_event_get_tablet_tool_event(event); + ck_assert_int_eq(libinput_event_tablet_tool_get_time(tev), + libinput_event_tablet_tool_get_time_usec(tev) / 1000); libinput_event_destroy(event); } END_TEST diff --git a/tools/event-debug.c b/tools/event-debug.c index a16bd017..3b853c2a 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -284,28 +284,28 @@ print_pointer_button_event(struct libinput_event *ev) static void print_tablet_tip_event(struct libinput_event *ev) { - struct libinput_event_tablet *p = libinput_event_get_tablet_event(ev); + struct libinput_event_tablet_tool *p = libinput_event_get_tablet_tool_event(ev); enum libinput_tablet_tool_tip_state state; - print_event_time(libinput_event_tablet_get_time(p)); + print_event_time(libinput_event_tablet_tool_get_time(p)); - state = libinput_event_tablet_get_tip_state(p); + state = libinput_event_tablet_tool_get_tip_state(p); printf("%s\n", state == LIBINPUT_TABLET_TOOL_TIP_DOWN ? "down" : "up"); } static void print_tablet_button_event(struct libinput_event *ev) { - struct libinput_event_tablet *p = libinput_event_get_tablet_event(ev); + struct libinput_event_tablet_tool *p = libinput_event_get_tablet_tool_event(ev); enum libinput_button_state state; - print_event_time(libinput_event_tablet_get_time(p)); + print_event_time(libinput_event_tablet_tool_get_time(p)); - state = libinput_event_tablet_get_button_state(p); + state = libinput_event_tablet_tool_get_button_state(p); printf("%3d %s, seat count: %u\n", - libinput_event_tablet_get_button(p), + libinput_event_tablet_tool_get_button(p), state == LIBINPUT_BUTTON_STATE_PRESSED ? "pressed" : "released", - libinput_event_tablet_get_seat_button_count(p)); + libinput_event_tablet_tool_get_seat_button_count(p)); } static void @@ -327,28 +327,28 @@ print_pointer_axis_event(struct libinput_event *ev) } static const char* -tablet_axis_changed_sym(struct libinput_event_tablet *t, +tablet_axis_changed_sym(struct libinput_event_tablet_tool *t, enum libinput_tablet_tool_axis axis) { - if (libinput_event_tablet_axis_has_changed(t, axis)) + if (libinput_event_tablet_tool_axis_has_changed(t, axis)) return "*"; else return ""; } static void -print_tablet_axes(struct libinput_event_tablet *t) +print_tablet_axes(struct libinput_event_tablet_tool *t) { - struct libinput_tablet_tool *tool = libinput_event_tablet_get_tool(t); + struct libinput_tablet_tool *tool = libinput_event_tablet_tool_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_TOOL_AXIS_X); - y = libinput_event_tablet_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_Y); - dx = libinput_event_tablet_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_X); - dy = libinput_event_tablet_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_Y); + x = libinput_event_tablet_tool_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_X); + y = libinput_event_tablet_tool_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_Y); + dx = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_X); + dy = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_Y); printf("\t%.2f%s/%.2f%s (%.2f/%.2f)", x, tablet_axis_changed_sym(t, LIBINPUT_TABLET_TOOL_AXIS_X), y, tablet_axis_changed_sym(t, LIBINPUT_TABLET_TOOL_AXIS_Y), @@ -356,13 +356,13 @@ print_tablet_axes(struct libinput_event_tablet *t) if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) || libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { - x = libinput_event_tablet_get_axis_value(t, + x = libinput_event_tablet_tool_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_TILT_X); - y = libinput_event_tablet_get_axis_value(t, + y = libinput_event_tablet_tool_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); - dx = libinput_event_tablet_get_axis_delta(t, + dx = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_TILT_X); - dy = libinput_event_tablet_get_axis_delta(t, + dy = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); printf("\ttilt: %.2f%s/%.2f%s (%.2f/%.2f)", x, tablet_axis_changed_sym(t, @@ -374,12 +374,12 @@ print_tablet_axes(struct libinput_event_tablet *t) if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE) || libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) { - dist = libinput_event_tablet_get_axis_value(t, + dist = libinput_event_tablet_tool_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); - pressure = libinput_event_tablet_get_axis_value(t, + pressure = libinput_event_tablet_tool_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); if (dist) { - delta = libinput_event_tablet_get_axis_delta(t, + delta = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); printf("\tdistance: %.2f%s (%.2f)", dist, @@ -387,7 +387,7 @@ print_tablet_axes(struct libinput_event_tablet *t) LIBINPUT_TABLET_TOOL_AXIS_DISTANCE), delta); } else { - delta = libinput_event_tablet_get_axis_delta(t, + delta = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); printf("\tpressure: %.2f%s (%.2f)", pressure, @@ -398,9 +398,9 @@ print_tablet_axes(struct libinput_event_tablet *t) } if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)) { - rotation = libinput_event_tablet_get_axis_value(t, + rotation = libinput_event_tablet_tool_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); - delta = libinput_event_tablet_get_axis_delta(t, + delta = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); printf("\trotation: %.2f%s (%.2f)", rotation, @@ -410,9 +410,9 @@ print_tablet_axes(struct libinput_event_tablet *t) } if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_SLIDER)) { - slider = libinput_event_tablet_get_axis_value(t, + slider = libinput_event_tablet_tool_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_SLIDER); - delta = libinput_event_tablet_get_axis_delta(t, + delta = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_SLIDER); printf("\tslider: %.2f%s (%.2f)", slider, @@ -422,9 +422,9 @@ print_tablet_axes(struct libinput_event_tablet *t) } if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL)) { - wheel = libinput_event_tablet_get_axis_value(t, + wheel = libinput_event_tablet_tool_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); - delta = libinput_event_tablet_get_axis_delta_discrete(t, + delta = libinput_event_tablet_tool_get_axis_delta_discrete(t, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); printf("\twheel: %.2f%s (%d)", wheel, @@ -437,9 +437,9 @@ print_tablet_axes(struct libinput_event_tablet *t) static void print_tablet_axis_event(struct libinput_event *ev) { - struct libinput_event_tablet *t = libinput_event_get_tablet_event(ev); + struct libinput_event_tablet_tool *t = libinput_event_get_tablet_tool_event(ev); - print_event_time(libinput_event_tablet_get_time(t)); + print_event_time(libinput_event_tablet_tool_get_time(t)); print_tablet_axes(t); printf("\n"); } @@ -456,8 +456,8 @@ 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_tablet_tool *tool = libinput_event_tablet_get_tool(t); + struct libinput_event_tablet_tool *t = libinput_event_get_tablet_tool_event(ev); + struct libinput_tablet_tool *tool = libinput_event_tablet_tool_get_tool(t); enum libinput_tablet_tool_proximity_state state; const char *tool_str, *state_str; @@ -491,9 +491,9 @@ print_proximity_event(struct libinput_event *ev) abort(); } - state = libinput_event_tablet_get_proximity_state(t); + state = libinput_event_tablet_tool_get_proximity_state(t); - print_event_time(libinput_event_tablet_get_time(t)); + print_event_time(libinput_event_tablet_tool_get_time(t)); if (state == LIBINPUT_TABLET_TOOL_PROXIMITY_IN) { print_tablet_axes(t); diff --git a/tools/event-gui.c b/tools/event-gui.c index 4818a402..996842e0 100644 --- a/tools/event-gui.c +++ b/tools/event-gui.c @@ -599,12 +599,12 @@ handle_event_pinch(struct libinput_event *ev, struct window *w) static void handle_event_tablet(struct libinput_event *ev, struct window *w) { - struct libinput_event_tablet *t = libinput_event_get_tablet_event(ev); + struct libinput_event_tablet_tool *t = libinput_event_get_tablet_tool_event(ev); double x, y; switch (libinput_event_get_type(ev)) { case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: - if (libinput_event_tablet_get_proximity_state(t) == + if (libinput_event_tablet_tool_get_proximity_state(t) == LIBINPUT_TABLET_TOOL_PROXIMITY_OUT) { w->tool.x_in = 0; w->tool.y_in = 0; @@ -613,30 +613,30 @@ handle_event_tablet(struct libinput_event *ev, struct window *w) w->tool.x_up = 0; w->tool.y_up = 0; } else { - w->tool.x_in = libinput_event_tablet_get_x_transformed(t, + w->tool.x_in = libinput_event_tablet_tool_get_x_transformed(t, w->width); - w->tool.y_in = libinput_event_tablet_get_y_transformed(t, + w->tool.y_in = libinput_event_tablet_tool_get_y_transformed(t, w->height); } break; case LIBINPUT_EVENT_TABLET_TOOL_AXIS: - w->tool.x = libinput_event_tablet_get_x_transformed(t, + w->tool.x = libinput_event_tablet_tool_get_x_transformed(t, w->width); - w->tool.y = libinput_event_tablet_get_y_transformed(t, + w->tool.y = libinput_event_tablet_tool_get_y_transformed(t, w->height); - w->tool.pressure = libinput_event_tablet_get_axis_value(t, + w->tool.pressure = libinput_event_tablet_tool_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); - w->tool.distance = libinput_event_tablet_get_axis_value(t, + w->tool.distance = libinput_event_tablet_tool_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); - w->tool.tilt_x = libinput_event_tablet_get_axis_value(t, + w->tool.tilt_x = libinput_event_tablet_tool_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_TILT_X); - w->tool.tilt_y = libinput_event_tablet_get_axis_value(t, + w->tool.tilt_y = libinput_event_tablet_tool_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); break; case LIBINPUT_EVENT_TABLET_TOOL_TIP: - x = libinput_event_tablet_get_x_transformed(t, w->width); - y = libinput_event_tablet_get_y_transformed(t, w->height); - if (libinput_event_tablet_get_tip_state(t) == + x = libinput_event_tablet_tool_get_x_transformed(t, w->width); + y = libinput_event_tablet_tool_get_y_transformed(t, w->height); + if (libinput_event_tablet_tool_get_tip_state(t) == LIBINPUT_TABLET_TOOL_TIP_DOWN) { w->tool.x_down = x; w->tool.y_down = y; From abb98d57381aef15a07f0da311eaffae0b057c33 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 16 Nov 2015 16:35:03 +1000 Subject: [PATCH 175/255] tablet: rename the libinput_tool calls to libinput_tablet_tool Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 2 +- src/libinput.c | 26 ++++++++--------- src/libinput.h | 34 +++++++++++------------ src/libinput.sym | 18 ++++++------ test/tablet.c | 68 ++++++++++++++++++++++----------------------- tools/event-debug.c | 50 ++++++++++++++++----------------- 6 files changed, 99 insertions(+), 99 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index c1d69de0..7e1c2d0f 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -1008,7 +1008,7 @@ tablet_destroy(struct evdev_dispatch *dispatch) struct libinput_tablet_tool *tool, *tmp; list_for_each_safe(tool, tmp, &tablet->tool_list, link) { - libinput_tool_unref(tool); + libinput_tablet_tool_unref(tool); } free(tablet); diff --git a/src/libinput.c b/src/libinput.c index 338255d8..99c009df 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1165,33 +1165,33 @@ libinput_event_tablet_tool_get_seat_button_count(struct libinput_event_tablet_to } LIBINPUT_EXPORT enum libinput_tablet_tool_type -libinput_tool_get_type(struct libinput_tablet_tool *tool) +libinput_tablet_tool_get_type(struct libinput_tablet_tool *tool) { return tool->type; } LIBINPUT_EXPORT uint64_t -libinput_tool_get_tool_id(struct libinput_tablet_tool *tool) +libinput_tablet_tool_get_tool_id(struct libinput_tablet_tool *tool) { return tool->tool_id; } LIBINPUT_EXPORT uint64_t -libinput_tool_get_serial(struct libinput_tablet_tool *tool) +libinput_tablet_tool_get_serial(struct libinput_tablet_tool *tool) { return tool->serial; } LIBINPUT_EXPORT int -libinput_tool_has_axis(struct libinput_tablet_tool *tool, - enum libinput_tablet_tool_axis axis) +libinput_tablet_tool_has_axis(struct libinput_tablet_tool *tool, + enum libinput_tablet_tool_axis axis) { return bit_is_set(tool->axis_caps, axis); } LIBINPUT_EXPORT int -libinput_tool_has_button(struct libinput_tablet_tool *tool, - uint32_t code) +libinput_tablet_tool_has_button(struct libinput_tablet_tool *tool, + uint32_t code) { if (NCHARS(code) > sizeof(tool->buttons)) return 0; @@ -1200,27 +1200,27 @@ libinput_tool_has_button(struct libinput_tablet_tool *tool, } LIBINPUT_EXPORT void -libinput_tool_set_user_data(struct libinput_tablet_tool *tool, - void *user_data) +libinput_tablet_tool_set_user_data(struct libinput_tablet_tool *tool, + void *user_data) { tool->user_data = user_data; } LIBINPUT_EXPORT void * -libinput_tool_get_user_data(struct libinput_tablet_tool *tool) +libinput_tablet_tool_get_user_data(struct libinput_tablet_tool *tool) { return tool->user_data; } LIBINPUT_EXPORT struct libinput_tablet_tool * -libinput_tool_ref(struct libinput_tablet_tool *tool) +libinput_tablet_tool_ref(struct libinput_tablet_tool *tool) { tool->refcount++; return tool; } LIBINPUT_EXPORT struct libinput_tablet_tool * -libinput_tool_unref(struct libinput_tablet_tool *tool) +libinput_tablet_tool_unref(struct libinput_tablet_tool *tool) { assert(tool->refcount > 0); @@ -1374,7 +1374,7 @@ libinput_unref(struct libinput *libinput) } list_for_each_safe(tool, next_tool, &libinput->tool_list, link) { - libinput_tool_unref(tool); + libinput_tablet_tool_unref(tool); } libinput_timer_subsys_destroy(libinput); diff --git a/src/libinput.h b/src/libinput.h index 9884cdcc..be815e7b 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -174,7 +174,7 @@ struct libinput_tablet_tool; * 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_TABLET_TOOL_TYPE_PEN. - * Use libinput_tool_get_tool_id() to get a specific model where applicable. + * Use libinput_tablet_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 @@ -1497,7 +1497,7 @@ libinput_event_tablet_tool_get_y_transformed(struct libinput_event_tablet_tool * * 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 + * the tool may be extended by using libinput_tablet_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. @@ -1611,17 +1611,17 @@ libinput_event_tablet_tool_get_time_usec(struct libinput_event_tablet_tool *even * @param tool The libinput tool * @return The tool type for this tool object * - * @see libinput_tool_get_tool_id + * @see libinput_tablet_tool_get_tool_id */ enum libinput_tablet_tool_type -libinput_tool_get_type(struct libinput_tablet_tool *tool); +libinput_tablet_tool_get_type(struct libinput_tablet_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. + * libinput_tablet_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. @@ -1629,10 +1629,10 @@ libinput_tool_get_type(struct libinput_tablet_tool *tool); * @param tool The libinput tool * @return The tool ID for this tool object or 0 if none is provided * - * @see libinput_tool_get_type + * @see libinput_tablet_tool_get_type */ uint64_t -libinput_tool_get_tool_id(struct libinput_tablet_tool *tool); +libinput_tablet_tool_get_tool_id(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet @@ -1643,7 +1643,7 @@ libinput_tool_get_tool_id(struct libinput_tablet_tool *tool); * @return The passed tool */ struct libinput_tablet_tool * -libinput_tool_ref(struct libinput_tablet_tool *tool); +libinput_tablet_tool_ref(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet @@ -1655,8 +1655,8 @@ libinput_tool_ref(struct libinput_tablet_tool *tool); * @return Whether or not the axis is supported */ int -libinput_tool_has_axis(struct libinput_tablet_tool *tool, - enum libinput_tablet_tool_axis axis); +libinput_tablet_tool_has_axis(struct libinput_tablet_tool *tool, + enum libinput_tablet_tool_axis axis); /** * @ingroup event_tablet @@ -1670,8 +1670,8 @@ libinput_tool_has_axis(struct libinput_tablet_tool *tool, * @return 1 if the tool supports this button code, 0 if it does not */ int -libinput_tool_has_button(struct libinput_tablet_tool *tool, - uint32_t code); +libinput_tablet_tool_has_button(struct libinput_tablet_tool *tool, + uint32_t code); /** * @ingroup event_tablet @@ -1683,7 +1683,7 @@ libinput_tool_has_button(struct libinput_tablet_tool *tool, * @return NULL if the tool was destroyed otherwise the passed tool */ struct libinput_tablet_tool * -libinput_tool_unref(struct libinput_tablet_tool *tool); +libinput_tablet_tool_unref(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet @@ -1698,7 +1698,7 @@ libinput_tool_unref(struct libinput_tablet_tool *tool); * @return The new tool serial triggering this event */ uint64_t -libinput_tool_get_serial(struct libinput_tablet_tool *tool); +libinput_tablet_tool_get_serial(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet @@ -1709,7 +1709,7 @@ libinput_tool_get_serial(struct libinput_tablet_tool *tool); * @return The user data associated with the tool object */ void * -libinput_tool_get_user_data(struct libinput_tablet_tool *tool); +libinput_tablet_tool_get_user_data(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet @@ -1720,8 +1720,8 @@ libinput_tool_get_user_data(struct libinput_tablet_tool *tool); * @param user_data The user data to associate with the tool object */ void -libinput_tool_set_user_data(struct libinput_tablet_tool *tool, - void *user_data); +libinput_tablet_tool_set_user_data(struct libinput_tablet_tool *tool, + void *user_data); /** * @defgroup base Initialization and manipulation of libinput contexts diff --git a/src/libinput.sym b/src/libinput.sym index 5f9cbef3..1704903c 100644 --- a/src/libinput.sym +++ b/src/libinput.sym @@ -200,13 +200,13 @@ LIBINPUT_TABLET_SUPPORT { libinput_event_tablet_tool_get_x_transformed; libinput_event_tablet_tool_get_y_transformed; libinput_event_tablet_tool_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_tablet_tool_get_serial; + libinput_tablet_tool_get_tool_id; + libinput_tablet_tool_get_type; + libinput_tablet_tool_get_user_data; + libinput_tablet_tool_has_button; + libinput_tablet_tool_has_axis; + libinput_tablet_tool_ref; + libinput_tablet_tool_set_user_data; + libinput_tablet_tool_unref; } LIBINPUT_1.1; diff --git a/test/tablet.c b/test/tablet.c index 8c6a273a..c268045a 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -592,7 +592,7 @@ START_TEST(proximity_in_out) have_tool_update++; tablet_event = libinput_event_get_tablet_tool_event(event); tool = libinput_event_tablet_tool_get_tool(tablet_event); - ck_assert_int_eq(libinput_tool_get_type(tool), + ck_assert_int_eq(libinput_tablet_tool_get_type(tool), LIBINPUT_TABLET_TOOL_TYPE_PEN); } libinput_event_destroy(event); @@ -734,7 +734,7 @@ START_TEST(proximity_has_axes) litest_assert_double_ne(x, 0); litest_assert_double_ne(y, 0); - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) { + if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) { ck_assert(libinput_event_tablet_tool_axis_has_changed( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)); @@ -745,8 +745,8 @@ START_TEST(proximity_has_axes) litest_assert_double_ne(distance, 0); } - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) && - libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { + if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) && + libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { ck_assert(libinput_event_tablet_tool_axis_has_changed( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_TILT_X)); @@ -781,12 +781,12 @@ START_TEST(proximity_has_axes) LIBINPUT_TABLET_TOOL_AXIS_X); last_y = libinput_event_tablet_tool_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) + if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) last_distance = libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) && - libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { + if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) && + libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { last_tx = libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_TILT_X); @@ -818,7 +818,7 @@ START_TEST(proximity_has_axes) litest_assert_double_eq(x, last_x); litest_assert_double_eq(y, last_y); - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) { + if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) { ck_assert(!libinput_event_tablet_tool_axis_has_changed( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)); @@ -829,8 +829,8 @@ START_TEST(proximity_has_axes) litest_assert_double_eq(distance, last_distance); } - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) && - libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { + if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) && + libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { ck_assert(!libinput_event_tablet_tool_axis_has_changed( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_TILT_X)); @@ -1454,7 +1454,7 @@ START_TEST(tool_serial) event = libinput_get_event(li); tablet_event = libinput_event_get_tablet_tool_event(event); tool = libinput_event_tablet_tool_get_tool(tablet_event); - ck_assert_uint_eq(libinput_tool_get_serial(tool), 1000); + ck_assert_uint_eq(libinput_tablet_tool_get_serial(tool), 1000); libinput_event_destroy(event); } END_TEST @@ -1487,7 +1487,7 @@ START_TEST(serial_changes_tool) tablet_event = libinput_event_get_tablet_tool_event(event); tool = libinput_event_tablet_tool_get_tool(tablet_event); - ck_assert_uint_eq(libinput_tool_get_serial(tool), 2000); + ck_assert_uint_eq(libinput_tablet_tool_get_serial(tool), 2000); libinput_event_destroy(event); } END_TEST @@ -1520,7 +1520,7 @@ START_TEST(invalid_serials) tablet_event = libinput_event_get_tablet_tool_event(event); tool = libinput_event_tablet_tool_get_tool(tablet_event); - ck_assert_uint_eq(libinput_tool_get_serial(tool), 1000); + ck_assert_uint_eq(libinput_tablet_tool_get_serial(tool), 1000); } libinput_event_destroy(event); @@ -1550,9 +1550,9 @@ START_TEST(tool_ref) tool = libinput_event_tablet_tool_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); + ck_assert(tool == libinput_tablet_tool_ref(tool)); + ck_assert(tool == libinput_tablet_tool_unref(tool)); + ck_assert(libinput_tablet_tool_unref(tool) == NULL); libinput_event_destroy(event); } @@ -1732,13 +1732,13 @@ START_TEST(tool_capabilities) t = libinput_event_get_tablet_tool_event(event); tool = libinput_event_tablet_tool_get_tool(t); - ck_assert(libinput_tool_has_axis(tool, + ck_assert(libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)); - ck_assert(libinput_tool_has_axis(tool, + ck_assert(libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)); - ck_assert(!libinput_tool_has_axis(tool, + ck_assert(!libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X)); - ck_assert(!libinput_tool_has_axis(tool, + ck_assert(!libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)); libinput_event_destroy(event); @@ -1755,13 +1755,13 @@ START_TEST(tool_capabilities) t = libinput_event_get_tablet_tool_event(event); tool = libinput_event_tablet_tool_get_tool(t); - ck_assert(libinput_tool_has_axis(tool, + ck_assert(libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)); - ck_assert(libinput_tool_has_axis(tool, + ck_assert(libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)); - ck_assert(libinput_tool_has_axis(tool, + ck_assert(libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X)); - ck_assert(libinput_tool_has_axis(tool, + ck_assert(libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)); libinput_event_destroy(event); @@ -1851,7 +1851,7 @@ START_TEST(mouse_tool) tev = libinput_event_get_tablet_tool_event(event); tool = libinput_event_tablet_tool_get_tool(tev); ck_assert_notnull(tool); - ck_assert_int_eq(libinput_tool_get_type(tool), + ck_assert_int_eq(libinput_tablet_tool_get_type(tool), LIBINPUT_TABLET_TOOL_TYPE_MOUSE); libinput_event_destroy(event); @@ -1886,7 +1886,7 @@ START_TEST(mouse_buttons) tev = libinput_event_get_tablet_tool_event(event); tool = libinput_event_tablet_tool_get_tool(tev); ck_assert_notnull(tool); - libinput_tool_ref(tool); + libinput_tablet_tool_ref(tool); libinput_event_destroy(event); @@ -1895,7 +1895,7 @@ START_TEST(mouse_buttons) EV_KEY, code); ck_assert_int_eq(!!has_button, - !!libinput_tool_has_button(tool, code)); + !!libinput_tablet_tool_has_button(tool, code)); if (!has_button) continue; @@ -1915,7 +1915,7 @@ START_TEST(mouse_buttons) LIBINPUT_BUTTON_STATE_RELEASED); } - libinput_tool_unref(tool); + libinput_tablet_tool_unref(tool); } END_TEST @@ -2025,11 +2025,11 @@ START_TEST(mouse_wheel) tev = libinput_event_get_tablet_tool_event(event); tool = libinput_event_tablet_tool_get_tool(tev); ck_assert_notnull(tool); - libinput_tool_ref(tool); + libinput_tablet_tool_ref(tool); libinput_event_destroy(event); - ck_assert(libinput_tool_has_axis(tool, + ck_assert(libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL)); for (i = 0; i < 3; i++) { @@ -2090,7 +2090,7 @@ START_TEST(mouse_wheel) litest_assert_empty_queue(li); } - libinput_tool_unref(tool); + libinput_tablet_tool_unref(tool); } END_TEST @@ -2120,7 +2120,7 @@ START_TEST(airbrush_tool) tev = libinput_event_get_tablet_tool_event(event); tool = libinput_event_tablet_tool_get_tool(tev); ck_assert_notnull(tool); - ck_assert_int_eq(libinput_tool_get_type(tool), + ck_assert_int_eq(libinput_tablet_tool_get_type(tool), LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH); libinput_event_destroy(event); @@ -2207,9 +2207,9 @@ START_TEST(artpen_tool) tev = libinput_event_get_tablet_tool_event(event); tool = libinput_event_tablet_tool_get_tool(tev); ck_assert_notnull(tool); - ck_assert_int_eq(libinput_tool_get_type(tool), + ck_assert_int_eq(libinput_tablet_tool_get_type(tool), LIBINPUT_TABLET_TOOL_TYPE_PEN); - ck_assert(libinput_tool_has_axis(tool, + ck_assert(libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)); libinput_event_destroy(event); diff --git a/tools/event-debug.c b/tools/event-debug.c index 3b853c2a..ec4c43be 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -354,8 +354,8 @@ print_tablet_axes(struct libinput_event_tablet_tool *t) y, tablet_axis_changed_sym(t, LIBINPUT_TABLET_TOOL_AXIS_Y), dx, dy); - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) || - libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { + if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) || + libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { x = libinput_event_tablet_tool_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_TILT_X); y = libinput_event_tablet_tool_get_axis_value(t, @@ -372,8 +372,8 @@ print_tablet_axes(struct libinput_event_tablet_tool *t) dx, dy); } - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE) || - libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) { + if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE) || + libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) { dist = libinput_event_tablet_tool_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); pressure = libinput_event_tablet_tool_get_axis_value(t, @@ -397,7 +397,7 @@ print_tablet_axes(struct libinput_event_tablet_tool *t) } } - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)) { + if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)) { rotation = libinput_event_tablet_tool_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); delta = libinput_event_tablet_tool_get_axis_delta(t, @@ -409,7 +409,7 @@ print_tablet_axes(struct libinput_event_tablet_tool *t) delta); } - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_SLIDER)) { + if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_SLIDER)) { slider = libinput_event_tablet_tool_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_SLIDER); delta = libinput_event_tablet_tool_get_axis_delta(t, @@ -421,7 +421,7 @@ print_tablet_axes(struct libinput_event_tablet_tool *t) delta); } - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL)) { + if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL)) { wheel = libinput_event_tablet_tool_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); delta = libinput_event_tablet_tool_get_axis_delta_discrete(t, @@ -462,7 +462,7 @@ print_proximity_event(struct libinput_event *ev) const char *tool_str, *state_str; - switch (libinput_tool_get_type(tool)) { + switch (libinput_tablet_tool_get_type(tool)) { case LIBINPUT_TABLET_TOOL_TYPE_PEN: tool_str = "pen"; break; @@ -507,41 +507,41 @@ print_proximity_event(struct libinput_event *ev) printf("\t%s (%#" PRIx64 ", id %#" PRIx64 ") %s", tool_str, - libinput_tool_get_serial(tool), - libinput_tool_get_tool_id(tool), + libinput_tablet_tool_get_serial(tool), + libinput_tablet_tool_get_tool_id(tool), state_str); printf("\taxes:"); - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) + if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) printf("d"); - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) + if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) printf("p"); - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) || - libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) + if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) || + libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) printf("t"); - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)) + if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)) printf("r"); - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_SLIDER)) + if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_SLIDER)) printf("s"); - if (libinput_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL)) + if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL)) printf("w"); printf("\tbtn:"); - if (libinput_tool_has_button(tool, BTN_TOUCH)) + if (libinput_tablet_tool_has_button(tool, BTN_TOUCH)) printf("T"); - if (libinput_tool_has_button(tool, BTN_STYLUS)) + if (libinput_tablet_tool_has_button(tool, BTN_STYLUS)) printf("S"); - if (libinput_tool_has_button(tool, BTN_STYLUS2)) + if (libinput_tablet_tool_has_button(tool, BTN_STYLUS2)) printf("S2"); - if (libinput_tool_has_button(tool, BTN_LEFT)) + if (libinput_tablet_tool_has_button(tool, BTN_LEFT)) printf("L"); - if (libinput_tool_has_button(tool, BTN_MIDDLE)) + if (libinput_tablet_tool_has_button(tool, BTN_MIDDLE)) printf("M"); - if (libinput_tool_has_button(tool, BTN_RIGHT)) + if (libinput_tablet_tool_has_button(tool, BTN_RIGHT)) printf("R"); - if (libinput_tool_has_button(tool, BTN_SIDE)) + if (libinput_tablet_tool_has_button(tool, BTN_SIDE)) printf("Sd"); - if (libinput_tool_has_button(tool, BTN_EXTRA)) + if (libinput_tablet_tool_has_button(tool, BTN_EXTRA)) printf("Ex"); printf("\n"); From 4677c48ab66c90cda2b66f57061401482f6d9f09 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 16 Nov 2015 16:36:05 +1000 Subject: [PATCH 176/255] doc: tablet documentation updates Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- doc/svg/tablet.svg | 199 +++++++++++++++++++++++++++++++++++++++++ doc/tablet-support.dox | 52 ++++++++++- src/libinput.h | 5 +- 3 files changed, 252 insertions(+), 4 deletions(-) create mode 100644 doc/svg/tablet.svg diff --git a/doc/svg/tablet.svg b/doc/svg/tablet.svg new file mode 100644 index 00000000..7a9dda83 --- /dev/null +++ b/doc/svg/tablet.svg @@ -0,0 +1,199 @@ + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/tablet-support.dox b/doc/tablet-support.dox index 47ad0054..24d08d20 100644 --- a/doc/tablet-support.dox +++ b/doc/tablet-support.dox @@ -6,7 +6,53 @@ 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 +@image html tablet.svg "Illustration of a graphics tablet" + +@section tablet-tools Tablet buttons vs. tablet tools + +Most tablets provide two types of devices. The pysical tablet often provides +a number of buttons and a touch ring or strip. Interaction on the drawing +surface of the tablet requires a tool, usually in the shape of a stylus. +The libinput interface exposed by devices with the @ref +LIBINPUT_DEVICE_CAP_TABLET_TOOL applies only to events generated by tools. + +Touch events on the tablet itself are exposed +through the @ref LIBINPUT_DEVICE_CAP_TOUCH capability and are often found on +a separate libinput device. See libinput_device_get_device_group() for +information on how to associate the touch part with other devices exposed by +the same physical hardware. + +@section tablet-tip Tool tip events vs. button events + +The primary use of a tablet tool is to draw on the surface of the tablet. +When the tool tip comes into contact with the surface, libinput sends an +event of type @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, and again when the tip +ceases contact with the surface. + +Tablet tools may send button events; these are exclusively for extra buttons +unrelated to the tip. A button event is independent of the tip and occur +at any time. + +@section tablet-axes Special axes on tablet tools + +A tablet tool usually provides additional information beyond x/y positional +information and the tip state. A tool may provide the distance to the tablet +surface and the pressure exerted on the tip when in contact. Some tablets +additionally provide tilt information along the x and y axis. + +@image html tablet-axes.svg "Illustration of the distance, pressure and tilt axes" + +The granularity and precision of these axes varies between tablet devices +and cannot usually be mapped into a physical unit. +libinput normalizes distance and pressure into a fixed positive 2-byte +integer range. The tilt axes are normalized into a signed 2-byte integer +range. + +While the normalization range is identical for these axes, a caller should +not interpret identical values as identical across axes, i.e. a value V1 on +the distance axis has no relation to the same value V1 on the pressure axis. + +@section tablet-fake-proximity Handling of proximity events libinput's @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY events represent the physical proximity limits of the device. In some cases the caller should @@ -31,8 +77,8 @@ static bool in_proximity; double value; -value = libinput_event_pointer_get_axis_value(device, - LIBINPUT_TABLET_AXIS_DISTANCE); +value = libinput_event_tablet_tool_get_axis_value(device, + LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); if (value < min) { min = value; diff --git a/src/libinput.h b/src/libinput.h index be815e7b..a9eee3cc 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -139,6 +139,9 @@ enum libinput_pointer_axis_source { * * Available axis types for a device. It must have the @ref * LIBINPUT_DEVICE_CAP_TABLET_TOOL capability. + * + * For details on the interpretation of these axes see + * libinput_event_tablet_tool_get_axis_value(). */ enum libinput_tablet_tool_axis { LIBINPUT_TABLET_TOOL_AXIS_X = 1, @@ -1518,7 +1521,7 @@ libinput_event_tablet_tool_get_tool(struct libinput_event_tablet_tool *event); * Used to check whether or not a tool came in or out of proximity during an * event of type @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. * - * See @ref fake-proximity for recommendations on proximity handling. + * See @ref tablet-fake-proximity for recommendations on proximity handling. * * @param event The libinput tablet event * @return The new proximity state of the tool from the event. From 8829f4b69123d82b6f859c6b52ac6d79a16878b2 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 26 Nov 2015 06:37:56 +1000 Subject: [PATCH 177/255] Whitespace fix Signed-off-by: Peter Hutterer --- src/evdev-tablet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index aafeda9d..847b4bb1 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -169,7 +169,7 @@ tablet_tool_to_evcode(enum libinput_tablet_tool_type type) case LIBINPUT_TABLET_TOOL_TYPE_ERASER: code = BTN_TOOL_RUBBER; break; case LIBINPUT_TABLET_TOOL_TYPE_BRUSH: code = BTN_TOOL_BRUSH; break; case LIBINPUT_TABLET_TOOL_TYPE_PENCIL: code = BTN_TOOL_PENCIL; break; - case LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH: code = BTN_TOOL_AIRBRUSH; break; + case LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH: code = BTN_TOOL_AIRBRUSH; break; case LIBINPUT_TABLET_TOOL_TYPE_FINGER: code = BTN_TOOL_FINGER; break; case LIBINPUT_TABLET_TOOL_TYPE_MOUSE: code = BTN_TOOL_MOUSE; break; case LIBINPUT_TABLET_TOOL_TYPE_LENS: code = BTN_TOOL_LENS; break; From be520bf6e03f08f5d888f87d1d9fb6b26d855fcb Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 30 Nov 2015 12:55:06 +1000 Subject: [PATCH 178/255] tablet: add two missing curly braces Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 7e1c2d0f..af4ee95c 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -399,14 +399,15 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, 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)) + if (tablet_has_status(tablet, + TABLET_TOOL_ENTERING_PROXIMITY)) { tablet_notify_proximity(&device->base, time, tool, LIBINPUT_TABLET_TOOL_PROXIMITY_IN, tablet->changed_axes, axes); - else { + } else { enum libinput_tablet_tool_tip_state tip_state; tip_state = tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT) ? From 5952aa6b501bf9b5c17e6eb0af4ccd367b458b2c Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 30 Nov 2015 13:47:08 +1000 Subject: [PATCH 179/255] tablet: break up a condition to improve readability Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index af4ee95c..51f69e06 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -410,8 +410,12 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, } else { enum libinput_tablet_tool_tip_state tip_state; - tip_state = tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT) ? - LIBINPUT_TABLET_TOOL_TIP_DOWN : LIBINPUT_TABLET_TOOL_TIP_UP; + if (tablet_has_status(tablet, + TABLET_TOOL_IN_CONTACT)) + tip_state = LIBINPUT_TABLET_TOOL_TIP_DOWN; + else + tip_state = LIBINPUT_TABLET_TOOL_TIP_UP; + tablet_notify_axis(base, time, tool, From cd1ca500cbaabb2ea635ad8c929c7b9601c36548 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 30 Nov 2015 15:49:12 +1000 Subject: [PATCH 180/255] doc: fix double full stop Signed-off-by: Peter Hutterer --- doc/device-configuration-via-udev.dox | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/device-configuration-via-udev.dox b/doc/device-configuration-via-udev.dox index 85c5c9c9..f615cc1e 100644 --- a/doc/device-configuration-via-udev.dox +++ b/doc/device-configuration-via-udev.dox @@ -64,11 +64,11 @@ libinput_pointer_get_axis_source() for details.
A constant (linear) acceleration factor to apply to pointingstick deltas to normalize them.
LIBINPUT_MODEL_*
-
This prefix is reserved as private API, do not use.. See @ref +
This prefix is reserved as private API, do not use. See @ref model_specific_configuration for details.
LIBINPUT_ATTR_*
-
This prefix is reserved as private API, do not use.. See @ref +
This prefix is reserved as private API, do not use. See @ref model_specific_configuration for details.
From d070463a72c5c1fe6c8ece7a1cec23df68bed25d Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 1 Dec 2015 15:26:48 +1000 Subject: [PATCH 181/255] test: use the double comparison macros Signed-off-by: Peter Hutterer --- test/litest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/litest.c b/test/litest.c index 0083dac8..01d97d9f 100644 --- a/test/litest.c +++ b/test/litest.c @@ -1750,8 +1750,8 @@ int litest_scale(const struct litest_device *d, unsigned int axis, double val) { int min, max; - litest_assert_int_ge((int)val, 0); - litest_assert_int_le((int)val, 100); + litest_assert_double_ge(val, 0.0); + litest_assert_double_le(val, 100.0); litest_assert_int_le(axis, (unsigned int)ABS_Y); min = d->interface->min[axis]; From 8be0813e177dc2742d1b29e7d1ad16c3b5de4185 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 26 Nov 2015 06:33:17 +1000 Subject: [PATCH 182/255] tablet: drop the tool type 'finger' from the tablet interface If it's a finger, it's a touchscreen or a touchpad, not a tablet. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 6 ++++-- src/evdev-tablet.h | 1 - src/libinput.h | 1 - tools/event-debug.c | 3 --- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 51f69e06..82029a9c 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -476,7 +476,6 @@ tablet_evcode_to_tool(int code) case BTN_TOOL_BRUSH: type = LIBINPUT_TABLET_TOOL_TYPE_BRUSH; break; case BTN_TOOL_PENCIL: type = LIBINPUT_TABLET_TOOL_TYPE_PENCIL; break; case BTN_TOOL_AIRBRUSH: type = LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH; break; - case BTN_TOOL_FINGER: type = LIBINPUT_TABLET_TOOL_TYPE_FINGER; break; case BTN_TOOL_MOUSE: type = LIBINPUT_TABLET_TOOL_TYPE_MOUSE; break; case BTN_TOOL_LENS: type = LIBINPUT_TABLET_TOOL_TYPE_LENS; break; default: @@ -493,12 +492,15 @@ tablet_process_key(struct tablet_dispatch *tablet, uint64_t time) { switch (e->code) { + case BTN_TOOL_FINGER: + log_bug_libinput(device->base.seat->libinput, + "Invalid tool 'finger' on tablet interface\n"); + break; 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, diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index 847b4bb1..162b5366 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -170,7 +170,6 @@ tablet_tool_to_evcode(enum libinput_tablet_tool_type type) case LIBINPUT_TABLET_TOOL_TYPE_BRUSH: code = BTN_TOOL_BRUSH; break; case LIBINPUT_TABLET_TOOL_TYPE_PENCIL: code = BTN_TOOL_PENCIL; break; case LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH: code = BTN_TOOL_AIRBRUSH; break; - case LIBINPUT_TABLET_TOOL_TYPE_FINGER: code = BTN_TOOL_FINGER; break; case LIBINPUT_TABLET_TOOL_TYPE_MOUSE: code = BTN_TOOL_MOUSE; break; case LIBINPUT_TABLET_TOOL_TYPE_LENS: code = BTN_TOOL_LENS; break; default: diff --git a/src/libinput.h b/src/libinput.h index a9eee3cc..48f72a17 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -195,7 +195,6 @@ enum libinput_tablet_tool_type { LIBINPUT_TABLET_TOOL_TYPE_PENCIL, /**< Physical drawing tool, e.g. Wacom Inking Pen */ LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH, /**< An airbrush-like tool */ - LIBINPUT_TABLET_TOOL_TYPE_FINGER, /**< Touch */ LIBINPUT_TABLET_TOOL_TYPE_MOUSE, /**< A mouse bound to the tablet */ LIBINPUT_TABLET_TOOL_TYPE_LENS, /**< A mouse tool with a lens */ }; diff --git a/tools/event-debug.c b/tools/event-debug.c index bb32f4b2..fd4033a3 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -478,9 +478,6 @@ print_proximity_event(struct libinput_event *ev) case LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH: tool_str = "airbrush"; break; - case LIBINPUT_TABLET_TOOL_TYPE_FINGER: - tool_str = "finger"; - break; case LIBINPUT_TABLET_TOOL_TYPE_MOUSE: tool_str = "mouse"; break; From d7491704500900d8ae454530cac33a5102a4be4f Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 30 Nov 2015 14:14:03 +1000 Subject: [PATCH 183/255] test: add tablet pressure/distance test cases Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- test/tablet.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/test/tablet.c b/test/tablet.c index c268045a..125ab4bf 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -2305,6 +2305,65 @@ START_TEST(tablet_time_usec) } END_TEST +START_TEST(tablet_pressure_distance_exclusive) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_tablet_tool *tev; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 20 }, + { -1, -1 }, + }; + double pressure, distance; + + litest_tablet_proximity_in(dev, 5, 100, axes); + litest_drain_events(li); + + litest_tablet_motion(dev, 70, 70, axes); + libinput_dispatch(li); + + litest_wait_for_event_of_type(li, + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + -1); + event = libinput_get_event(li); + tev = libinput_event_get_tablet_tool_event(event); + + pressure = libinput_event_tablet_tool_get_axis_value(tev, + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + distance = libinput_event_tablet_tool_get_axis_value(tev, + LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); + + ck_assert_double_eq(pressure, 0.0); + ck_assert_double_ne(distance, 0.0); + + libinput_event_destroy(event); + + axes[0].value = 15; + axes[1].value = 25; + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_tablet_motion(dev, 30, 30, axes); + libinput_dispatch(li); + + litest_wait_for_event_of_type(li, + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + -1); + event = libinput_get_event(li); + tev = libinput_event_get_tablet_tool_event(event); + + pressure = libinput_event_tablet_tool_get_axis_value(tev, + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + distance = libinput_event_tablet_tool_get_axis_value(tev, + LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); + + ck_assert_double_eq(distance, 0.0); + ck_assert_double_ne(pressure, 0.0); + + libinput_event_destroy(event); +} +END_TEST + void litest_setup_tests(void) { @@ -2348,4 +2407,5 @@ litest_setup_tests(void) litest_add("tablet:artpen", artpen_rotation, LITEST_TABLET, LITEST_ANY); litest_add("tablet:time", tablet_time_usec, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:pressure", tablet_pressure_distance_exclusive, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY); } From 319fb38dedc9a85a841539a13f470e0e8eb30ecc Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 30 Nov 2015 15:00:43 +1000 Subject: [PATCH 184/255] tablet: drop pressure when either pressure or distance changed Keep pressure and distance mutually exclusive regardless which one of the two updates. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 82029a9c..2442ecd6 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -853,7 +853,9 @@ sanitize_tablet_axes(struct tablet_dispatch *tablet) 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_TOOL_AXIS_DISTANCE) && + if (distance && + (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE) || + bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) && distance->value > distance->minimum && pressure->value > pressure->minimum) { clear_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); From 70e9fd78749ee6b577621cd5148ec69640dc62a0 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 30 Nov 2015 15:04:49 +1000 Subject: [PATCH 185/255] tablet: force the pressure/distance to 0 depending on contact state If we have pressure but not BTN_TOUCH, force the pressure to 0. Otherwise, force distance to 0. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 2442ecd6..71e66430 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -846,23 +846,35 @@ tablet_notify_buttons(struct tablet_dispatch *tablet, static void sanitize_tablet_axes(struct tablet_dispatch *tablet) { + bool tool_in_contact; 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); + tool_in_contact = (tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT) || + tablet_has_status(tablet, + TABLET_TOOL_ENTERING_CONTACT)); + /* Keep distance and pressure mutually exclusive */ if (distance && (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE) || bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) && distance->value > distance->minimum && pressure->value > pressure->minimum) { - clear_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); - tablet->axes[LIBINPUT_TABLET_TOOL_AXIS_DISTANCE] = 0; + if (tool_in_contact) { + clear_bit(tablet->changed_axes, + LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); + tablet->axes[LIBINPUT_TABLET_TOOL_AXIS_DISTANCE] = + 0; + } else { + clear_bit(tablet->changed_axes, + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + tablet->axes[LIBINPUT_TABLET_TOOL_AXIS_PRESSURE] = 0; + } } else if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE) && - (!tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT) && - !tablet_has_status(tablet, TABLET_TOOL_ENTERING_CONTACT))) { + !tool_in_contact) { /* Make sure that the last axis value sent to the caller is a 0 */ if (tablet->axes[LIBINPUT_TABLET_TOOL_AXIS_PRESSURE] == 0) clear_bit(tablet->changed_axes, From 20db89f5c930eaded53018f4e37007a1d570d8c1 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 1 Dec 2015 15:46:44 +1000 Subject: [PATCH 186/255] evdev: make evdev_transform_absolute available within libinput Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev.c | 14 +++++++------- src/evdev.h | 4 ++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/evdev.c b/src/evdev.c index d56a4702..5a733409 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -212,9 +212,9 @@ evdev_device_led_update(struct evdev_device *device, enum libinput_led leds) (void)i; /* no, we really don't care about the return value */ } -static void -transform_absolute(struct evdev_device *device, - struct device_coords *point) +void +evdev_transform_absolute(struct evdev_device *device, + struct device_coords *point) { if (!device->abs.apply_calibration) return; @@ -340,7 +340,7 @@ evdev_flush_pending_event(struct evdev_device *device, uint64_t time) seat->slot_map |= 1 << seat_slot; point = device->mt.slots[slot].point; - transform_absolute(device, &point); + evdev_transform_absolute(device, &point); touch_notify_touch_down(base, time, slot, seat_slot, &point); @@ -355,7 +355,7 @@ evdev_flush_pending_event(struct evdev_device *device, uint64_t time) if (seat_slot == -1) break; - transform_absolute(device, &point); + evdev_transform_absolute(device, &point); touch_notify_touch_motion(base, time, slot, seat_slot, &point); break; @@ -394,13 +394,13 @@ evdev_flush_pending_event(struct evdev_device *device, uint64_t time) seat->slot_map |= 1 << seat_slot; point = device->abs.point; - transform_absolute(device, &point); + evdev_transform_absolute(device, &point); touch_notify_touch_down(base, time, -1, seat_slot, &point); break; case EVDEV_ABSOLUTE_MOTION: point = device->abs.point; - transform_absolute(device, &point); + evdev_transform_absolute(device, &point); if (device->seat_caps & EVDEV_DEVICE_TOUCH) { seat_slot = device->abs.seat_slot; diff --git a/src/evdev.h b/src/evdev.h index 1a02963b..d7b372f6 100644 --- a/src/evdev.h +++ b/src/evdev.h @@ -286,6 +286,10 @@ struct evdev_device * evdev_device_create(struct libinput_seat *seat, struct udev_device *device); +void +evdev_transform_absolute(struct evdev_device *device, + struct device_coords *point); + int evdev_device_init_pointer_acceleration(struct evdev_device *device, struct motion_filter *filter); From bd0f43eeb6d386a1d99065f629be14fd6c87e921 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 1 Dec 2015 14:05:16 +1000 Subject: [PATCH 187/255] tablet: enable the calibration matrix for internal tablets Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 51 +++++++++++++- src/evdev.c | 2 +- src/evdev.h | 4 ++ test/pointer.c | 2 +- test/tablet.c | 170 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 225 insertions(+), 4 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 71e66430..cd208a8f 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -326,10 +326,47 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, double deltas[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1] = {0}; double deltas_discrete[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1] = {0}; double oldval; + struct device_coords point, old_point; + const struct input_absinfo *absinfo; - for (a = LIBINPUT_TABLET_TOOL_AXIS_X; a <= LIBINPUT_TABLET_TOOL_AXIS_MAX; a++) { - const struct input_absinfo *absinfo; + /* x/y are special for left-handed and calibration */ + a = LIBINPUT_TABLET_TOOL_AXIS_X; + old_point.x = tablet->axes[a]; + if (bit_is_set(tablet->changed_axes, a)) { + absinfo = libevdev_get_abs_info(device->evdev, + axis_to_evcode(a)); + axis_update_needed = true; + if (device->left_handed.enabled) + tablet->axes[a] = invert_axis(absinfo); + else + tablet->axes[a] = absinfo->value; + } + point.x = tablet->axes[a]; + + a = LIBINPUT_TABLET_TOOL_AXIS_Y; + old_point.y = tablet->axes[a]; + if (bit_is_set(tablet->changed_axes, a)) { + absinfo = libevdev_get_abs_info(device->evdev, + axis_to_evcode(a)); + axis_update_needed = true; + + if (device->left_handed.enabled) + tablet->axes[a] = invert_axis(absinfo); + else + tablet->axes[a] = absinfo->value; + } + point.y = tablet->axes[a]; + + evdev_transform_absolute(device, &point); + evdev_transform_absolute(device, &old_point); + + axes[LIBINPUT_TABLET_TOOL_AXIS_X] = point.x; + axes[LIBINPUT_TABLET_TOOL_AXIS_Y] = point.y; + deltas[LIBINPUT_TABLET_TOOL_AXIS_X] = point.x - old_point.x; + deltas[LIBINPUT_TABLET_TOOL_AXIS_Y] = point.y - old_point.y; + + for (a = LIBINPUT_TABLET_TOOL_AXIS_DISTANCE; a <= LIBINPUT_TABLET_TOOL_AXIS_MAX; a++) { if (!bit_is_set(tablet->changed_axes, a)) { axes[a] = tablet->axes[a]; continue; @@ -1088,6 +1125,14 @@ static struct evdev_dispatch_interface tablet_interface = { tablet_check_initial_proximity, }; +static void +tablet_init_calibration(struct tablet_dispatch *tablet, + struct evdev_device *device) +{ + if (libevdev_has_property(device->evdev, INPUT_PROP_DIRECT)) + evdev_init_calibration(device, &tablet->base); +} + static int tablet_init(struct tablet_dispatch *tablet, struct evdev_device *device) @@ -1100,6 +1145,8 @@ tablet_init(struct tablet_dispatch *tablet, tablet->current_tool_type = LIBINPUT_TOOL_NONE; list_init(&tablet->tool_list); + tablet_init_calibration(tablet, device); + for (axis = LIBINPUT_TABLET_TOOL_AXIS_X; axis <= LIBINPUT_TABLET_TOOL_AXIS_MAX; axis++) { diff --git a/src/evdev.c b/src/evdev.c index 5a733409..993c5d8a 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -1178,7 +1178,7 @@ evdev_init_button_scroll(struct evdev_device *device, return 0; } -static void +void evdev_init_calibration(struct evdev_device *device, struct evdev_dispatch *dispatch) { diff --git a/src/evdev.h b/src/evdev.h index d7b372f6..75a2cb6a 100644 --- a/src/evdev.h +++ b/src/evdev.h @@ -290,6 +290,10 @@ void evdev_transform_absolute(struct evdev_device *device, struct device_coords *point); +void +evdev_init_calibration(struct evdev_device *device, + struct evdev_dispatch *dispatch); + int evdev_device_init_pointer_acceleration(struct evdev_device *device, struct motion_filter *filter); diff --git a/test/pointer.c b/test/pointer.c index 5c33d50f..d043fa8a 100644 --- a/test/pointer.c +++ b/test/pointer.c @@ -1600,7 +1600,7 @@ litest_setup_tests(void) 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); + litest_add("pointer:calibration", pointer_no_calibration, LITEST_ANY, LITEST_TOUCH|LITEST_SINGLE_TOUCH|LITEST_ABSOLUTE|LITEST_PROTOCOL_A|LITEST_TABLET); /* tests touchpads too */ litest_add("pointer:left-handed", pointer_left_handed_defaults, LITEST_BUTTON, LITEST_ANY); diff --git a/test/tablet.c b/test/tablet.c index 125ab4bf..18f08b23 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -2364,6 +2364,172 @@ START_TEST(tablet_pressure_distance_exclusive) } END_TEST +START_TEST(tablet_calibration_has_matrix) +{ + struct litest_device *dev = litest_current_device(); + struct libinput_device *d = dev->libinput_device; + enum libinput_config_status status; + int rc; + float calibration[6] = {1, 0, 0, 0, 1, 0}; + int has_calibration; + + has_calibration = libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT); + + rc = libinput_device_config_calibration_has_matrix(d); + ck_assert_int_eq(rc, has_calibration); + rc = libinput_device_config_calibration_get_matrix(d, calibration); + ck_assert_int_eq(rc, 0); + rc = libinput_device_config_calibration_get_default_matrix(d, + calibration); + ck_assert_int_eq(rc, 0); + + status = libinput_device_config_calibration_set_matrix(d, + calibration); + if (has_calibration) + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + else + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); +} +END_TEST + +START_TEST(tablet_calibration_set_matrix_delta) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_device *d = dev->libinput_device; + enum libinput_config_status status; + float calibration[6] = {0.5, 0, 0, 0, 0.5, 0}; + struct libinput_event *event; + struct libinput_event_tablet_tool *tablet_event; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 10 }, + { -1, -1 } + }; + int has_calibration; + double dx, dy, mdx, mdy; + + has_calibration = libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT); + if (!has_calibration) + return; + + litest_tablet_proximity_in(dev, 100, 100, axes); + litest_drain_events(li); + + litest_tablet_motion(dev, 80, 80, axes); + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + + dx = libinput_event_tablet_tool_get_axis_delta(tablet_event, + LIBINPUT_TABLET_TOOL_AXIS_X); + dy = libinput_event_tablet_tool_get_axis_delta(tablet_event, + LIBINPUT_TABLET_TOOL_AXIS_Y); + libinput_event_destroy(event); + litest_tablet_proximity_out(dev); + litest_drain_events(li); + + status = libinput_device_config_calibration_set_matrix(d, + calibration); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + litest_tablet_proximity_in(dev, 100, 100, axes); + litest_drain_events(li); + + litest_tablet_motion(dev, 80, 80, axes); + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + + mdx = libinput_event_tablet_tool_get_axis_delta(tablet_event, + LIBINPUT_TABLET_TOOL_AXIS_X); + mdy = libinput_event_tablet_tool_get_axis_delta(tablet_event, + LIBINPUT_TABLET_TOOL_AXIS_Y); + libinput_event_destroy(event); + litest_drain_events(li); + + ck_assert_double_gt(dx, mdx * 2 - 1); + ck_assert_double_lt(dx, mdx * 2 + 1); + ck_assert_double_gt(dy, mdy * 2 - 1); + ck_assert_double_lt(dy, mdy * 2 + 1); +} +END_TEST + +START_TEST(tablet_calibration_set_matrix) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_device *d = dev->libinput_device; + enum libinput_config_status status; + float calibration[6] = {0.5, 0, 0, 0, 1, 0}; + struct libinput_event *event; + struct libinput_event_tablet_tool *tablet_event; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 10 }, + { -1, -1 } + }; + int has_calibration; + double x, y; + + has_calibration = libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT); + if (!has_calibration) + return; + + litest_drain_events(li); + + status = libinput_device_config_calibration_set_matrix(d, + calibration); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + litest_tablet_proximity_in(dev, 100, 100, axes); + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + x = libinput_event_tablet_tool_get_x_transformed(tablet_event, 100); + y = libinput_event_tablet_tool_get_y_transformed(tablet_event, 100); + libinput_event_destroy(event); + + ck_assert_double_gt(x, 49.0); + ck_assert_double_lt(x, 51.0); + ck_assert_double_gt(y, 99.0); + ck_assert_double_lt(y, 100.0); + + litest_tablet_proximity_out(dev); + libinput_dispatch(li); + litest_tablet_proximity_in(dev, 50, 50, axes); + litest_tablet_proximity_out(dev); + litest_drain_events(li); + + calibration[0] = 1; + calibration[4] = 0.5; + status = libinput_device_config_calibration_set_matrix(d, + calibration); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + litest_tablet_proximity_in(dev, 100, 100, axes); + libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + x = libinput_event_tablet_tool_get_x_transformed(tablet_event, 100); + y = libinput_event_tablet_tool_get_y_transformed(tablet_event, 100); + libinput_event_destroy(event); + + ck_assert_double_gt(x, 99.0); + ck_assert_double_lt(x, 100.0); + ck_assert_double_gt(y, 49.0); + ck_assert_double_lt(y, 51.0); + + litest_tablet_proximity_out(dev); +} +END_TEST + void litest_setup_tests(void) { @@ -2408,4 +2574,8 @@ litest_setup_tests(void) litest_add("tablet:time", tablet_time_usec, LITEST_TABLET, LITEST_ANY); litest_add("tablet:pressure", tablet_pressure_distance_exclusive, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY); + + litest_add("tablet:calibration", tablet_calibration_has_matrix, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:calibration", tablet_calibration_set_matrix, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:calibration", tablet_calibration_set_matrix_delta, LITEST_TABLET, LITEST_ANY); } From 7ea1c134e6714c65f1477c103166ee83e4fdb8b8 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 11 Dec 2015 10:53:06 +1000 Subject: [PATCH 188/255] test: add the HUION PenTablet device Tablet with pressure and proximity but no distance axis. Signed-off-by: Peter Hutterer --- test/Makefile.am | 1 + test/litest-device-huion-pentablet.c | 98 ++++++++++++++++++++++++++++ test/litest.c | 2 + test/litest.h | 1 + 4 files changed, 102 insertions(+) create mode 100644 test/litest-device-huion-pentablet.c diff --git a/test/Makefile.am b/test/Makefile.am index 139beb83..f0b3d1bf 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -20,6 +20,7 @@ liblitest_la_SOURCES = \ litest-device-bcm5974.c \ litest-device-elantech-touchpad.c \ litest-device-generic-singletouch.c \ + litest-device-huion-pentablet.c \ litest-device-keyboard.c \ litest-device-keyboard-razer-blackwidow.c \ litest-device-logitech-trackball.c \ diff --git a/test/litest-device-huion-pentablet.c b/test/litest-device-huion-pentablet.c new file mode 100644 index 00000000..40093973 --- /dev/null +++ b/test/litest-device-huion-pentablet.c @@ -0,0 +1,98 @@ +/* + * Copyright © 2015 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_huion_tablet_setup(void) +{ + struct litest_device *d = litest_create_device(LITEST_HUION_TABLET); + 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_ABS, .code = ABS_X, .value = 0 }, + { .type = EV_ABS, .code = ABS_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_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, 40000, 0, 0, 157 }, + { ABS_Y, 0, 25000, 0, 0, 157 }, + { ABS_PRESSURE, 0, 2047, 0, 0, 0 }, + { .value = -1 }, +}; + +static struct input_id input_id = { + .bustype = 0x3, + .vendor = 0x256c, + .product = 0x6e, +}; + +static int events[] = { + EV_KEY, BTN_TOOL_PEN, + EV_KEY, BTN_TOUCH, + EV_KEY, BTN_STYLUS, + EV_KEY, BTN_STYLUS2, + EV_MSC, MSC_SCAN, + -1, -1, +}; + +struct litest_test_device litest_huion_tablet_device = { + .type = LITEST_HUION_TABLET, + .features = LITEST_TABLET, + .shortname = "huion-tablet", + .setup = litest_huion_tablet_setup, + .interface = &interface, + + .name = "HUION PenTablet Pen", + .id = &input_id, + .events = events, + .absinfo = absinfo, +}; diff --git a/test/litest.c b/test/litest.c index 73aa977f..f0def982 100644 --- a/test/litest.c +++ b/test/litest.c @@ -372,6 +372,7 @@ extern struct litest_test_device litest_elantech_touchpad_device; extern struct litest_test_device litest_mouse_gladius_device; extern struct litest_test_device litest_mouse_wheel_click_angle_device; extern struct litest_test_device litest_waltop_tablet_device; +extern struct litest_test_device litest_huion_tablet_device; struct litest_test_device* devices[] = { &litest_synaptics_clickpad_device, @@ -410,6 +411,7 @@ struct litest_test_device* devices[] = { &litest_mouse_gladius_device, &litest_mouse_wheel_click_angle_device, &litest_waltop_tablet_device, + &litest_huion_tablet_device, NULL, }; diff --git a/test/litest.h b/test/litest.h index ed9ddfe7..5f907e89 100644 --- a/test/litest.h +++ b/test/litest.h @@ -149,6 +149,7 @@ enum litest_device_type { LITEST_WACOM_INTUOS = -35, LITEST_WACOM_ISDV4 = -36, LITEST_WALTOP = -37, + LITEST_HUION_TABLET = -38, }; enum litest_device_feature { From 727d184230e6d02c8e6c3865ecaf7d92953bcd1a Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 10 Dec 2015 16:05:37 +1000 Subject: [PATCH 189/255] test: change extra axes to take a percentage as well And change them to doubles, we need more granularity when the range is only 0-100. Signed-off-by: Peter Hutterer --- test/litest.c | 36 ++++++++++++++++++++++++++++-------- test/litest.h | 2 +- test/touchpad.c | 22 +++++++++++----------- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/test/litest.c b/test/litest.c index f0def982..632b144a 100644 --- a/test/litest.c +++ b/test/litest.c @@ -1267,7 +1267,8 @@ litest_event(struct litest_device *d, unsigned int type, } static bool -axis_replacement_value(struct axis_replacement *axes, +axis_replacement_value(struct litest_device *d, + struct axis_replacement *axes, int32_t evcode, int32_t *value) { @@ -1278,7 +1279,7 @@ axis_replacement_value(struct axis_replacement *axes, while (axis->evcode != -1) { if (axis->evcode == evcode) { - *value = axis->value; + *value = litest_scale(d, evcode, axis->value); return true; } axis++; @@ -1319,7 +1320,7 @@ litest_auto_assign_value(struct litest_device *d, value = touching ? 0 : 1; break; default: - if (!axis_replacement_value(axes, ev->code, &value) && + if (!axis_replacement_value(d, axes, ev->code, &value) && d->interface->get_axis_default) d->interface->get_axis_default(d, ev->code, &value); break; @@ -1518,7 +1519,7 @@ auto_assign_tablet_value(struct litest_device *d, value = litest_scale(d, ABS_Y, y); break; default: - axis_replacement_value(axes, ev->code, &value); + axis_replacement_value(d, axes, ev->code, &value); break; } @@ -1757,17 +1758,36 @@ litest_keyboard_key(struct litest_device *d, unsigned int key, bool is_press) litest_button_click(d, key, is_press); } +static int +litest_scale_axis(const struct litest_device *d, + unsigned int axis, + double val) +{ + const struct input_absinfo *abs; + + litest_assert_double_ge(val, 0.0); + litest_assert_double_le(val, 100.0); + + abs = libevdev_get_abs_info(d->evdev, axis); + litest_assert_notnull(abs); + + return (abs->maximum - abs->minimum) * val/100.0 + abs->minimum; +} + int litest_scale(const struct litest_device *d, unsigned int axis, double val) { int min, max; litest_assert_double_ge(val, 0.0); litest_assert_double_le(val, 100.0); - litest_assert_int_le(axis, (unsigned int)ABS_Y); - min = d->interface->min[axis]; - max = d->interface->max[axis]; - return (max - min) * val/100.0 + min; + if (axis <= ABS_X) { + min = d->interface->min[axis]; + max = d->interface->max[axis]; + return (max - min) * val/100.0 + min; + } else { + return litest_scale_axis(d, axis, val); + } } void diff --git a/test/litest.h b/test/litest.h index 5f907e89..1d36ab9a 100644 --- a/test/litest.h +++ b/test/litest.h @@ -195,7 +195,7 @@ struct litest_device { struct axis_replacement { int32_t evcode; - int32_t value; + double value; }; /* A loop range, resolves to: diff --git a/test/touchpad.c b/test/touchpad.c index 7bc99e98..dab2781e 100644 --- a/test/touchpad.c +++ b/test/touchpad.c @@ -2983,7 +2983,7 @@ START_TEST(touchpad_thumb_begin_no_motion) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { - { ABS_MT_PRESSURE, 190 }, + { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; @@ -3007,7 +3007,7 @@ START_TEST(touchpad_thumb_update_no_motion) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { - { ABS_MT_PRESSURE, 190 }, + { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; @@ -3033,7 +3033,7 @@ START_TEST(touchpad_thumb_moving) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { - { ABS_MT_PRESSURE, 190 }, + { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; @@ -3062,7 +3062,7 @@ START_TEST(touchpad_thumb_clickfinger) struct libinput_event *event; struct libinput_event_pointer *ptrev; struct axis_replacement axes[] = { - { ABS_MT_PRESSURE, 190 }, + { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; @@ -3119,7 +3119,7 @@ START_TEST(touchpad_thumb_btnarea) struct libinput_event *event; struct libinput_event_pointer *ptrev; struct axis_replacement axes[] = { - { ABS_MT_PRESSURE, 190 }, + { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; @@ -3155,7 +3155,7 @@ START_TEST(touchpad_thumb_edgescroll) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { - { ABS_MT_PRESSURE, 190 }, + { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; @@ -3186,7 +3186,7 @@ START_TEST(touchpad_thumb_tap_begin) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { - { ABS_MT_PRESSURE, 190 }, + { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; @@ -3219,7 +3219,7 @@ START_TEST(touchpad_thumb_tap_touch) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { - { ABS_MT_PRESSURE, 190 }, + { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; @@ -3252,7 +3252,7 @@ START_TEST(touchpad_thumb_tap_hold) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { - { ABS_MT_PRESSURE, 190 }, + { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; @@ -3286,7 +3286,7 @@ START_TEST(touchpad_thumb_tap_hold_2ndfg) struct litest_device *dev = litest_current_device(); struct libinput *li = dev->libinput; struct axis_replacement axes[] = { - { ABS_MT_PRESSURE, 190 }, + { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; @@ -3337,7 +3337,7 @@ START_TEST(touchpad_thumb_tap_hold_2ndfg_tap) struct libinput_event *event; struct libinput_event_pointer *ptrev; struct axis_replacement axes[] = { - { ABS_MT_PRESSURE, 190 }, + { ABS_MT_PRESSURE, 75 }, { -1, 0 } }; From 1a3440113751e039316de2db8b388fb83e2a2b99 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 11 Dec 2015 17:39:57 +1000 Subject: [PATCH 190/255] test: set default axis values for all tablet devices Signed-off-by: Peter Hutterer --- test/litest-device-huion-pentablet.c | 14 ++++++++++++++ test/litest-device-wacom-bamboo-tablet.c | 13 +++++++++++++ test/litest-device-wacom-cintiq-tablet.c | 20 ++++++++++++++++++++ test/litest-device-wacom-intuos-tablet.c | 21 +++++++++++++++++++++ test/litest-device-wacom-isdv4-tablet.c | 13 +++++++++++++ test/litest-device-waltop-tablet.c | 18 ++++++++++++++++++ test/litest.c | 4 +++- 7 files changed, 102 insertions(+), 1 deletion(-) diff --git a/test/litest-device-huion-pentablet.c b/test/litest-device-huion-pentablet.c index 40093973..6be659b6 100644 --- a/test/litest-device-huion-pentablet.c +++ b/test/litest-device-huion-pentablet.c @@ -56,10 +56,24 @@ static struct input_event motion[] = { { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; + +static int +get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) +{ + switch (evcode) { + case ABS_PRESSURE: + *value = 100; + return 0; + } + return 1; +} + static struct litest_device_interface interface = { .tablet_proximity_in_events = proximity_in, .tablet_proximity_out_events = proximity_out, .tablet_motion_events = motion, + + .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { diff --git a/test/litest-device-wacom-bamboo-tablet.c b/test/litest-device-wacom-bamboo-tablet.c index d21d4be0..2cf98c35 100644 --- a/test/litest-device-wacom-bamboo-tablet.c +++ b/test/litest-device-wacom-bamboo-tablet.c @@ -60,10 +60,23 @@ static struct input_event motion[] = { { .type = -1, .code = -1 }, }; +static int +get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) +{ + switch (evcode) { + case ABS_PRESSURE: + *value = 100; + return 0; + } + return 1; +} + static struct litest_device_interface interface = { .tablet_proximity_in_events = proximity_in, .tablet_proximity_out_events = proximity_out, .tablet_motion_events = motion, + + .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { diff --git a/test/litest-device-wacom-cintiq-tablet.c b/test/litest-device-wacom-cintiq-tablet.c index 0217f560..db3173cd 100644 --- a/test/litest-device-wacom-cintiq-tablet.c +++ b/test/litest-device-wacom-cintiq-tablet.c @@ -71,10 +71,30 @@ static struct input_event motion[] = { { .type = -1, .code = -1 }, }; +static int +get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) +{ + switch (evcode) { + case ABS_TILT_X: + case ABS_TILT_Y: + *value = 0; + return 0; + case ABS_PRESSURE: + *value = 100; + return 0; + case ABS_DISTANCE: + *value = 0; + return 0; + } + return 1; +} + static struct litest_device_interface interface = { .tablet_proximity_in_events = proximity_in, .tablet_proximity_out_events = proximity_out, .tablet_motion_events = motion, + + .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { diff --git a/test/litest-device-wacom-intuos-tablet.c b/test/litest-device-wacom-intuos-tablet.c index e0e1d44b..682a56c1 100644 --- a/test/litest-device-wacom-intuos-tablet.c +++ b/test/litest-device-wacom-intuos-tablet.c @@ -70,10 +70,31 @@ static struct input_event motion[] = { { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; + +static int +get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) +{ + switch (evcode) { + case ABS_TILT_X: + case ABS_TILT_Y: + *value = 0; + return 0; + case ABS_PRESSURE: + *value = 100; + return 0; + case ABS_DISTANCE: + *value = 0; + return 0; + } + return 1; +} + static struct litest_device_interface interface = { .tablet_proximity_in_events = proximity_in, .tablet_proximity_out_events = proximity_out, .tablet_motion_events = motion, + + .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { diff --git a/test/litest-device-wacom-isdv4-tablet.c b/test/litest-device-wacom-isdv4-tablet.c index c9d40e77..bc607057 100644 --- a/test/litest-device-wacom-isdv4-tablet.c +++ b/test/litest-device-wacom-isdv4-tablet.c @@ -55,10 +55,23 @@ static struct input_event motion[] = { { .type = -1, .code = -1 }, }; +static int +get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) +{ + switch (evcode) { + case ABS_PRESSURE: + *value = 100; + return 0; + } + return 1; +} + static struct litest_device_interface interface = { .tablet_proximity_in_events = proximity_in, .tablet_proximity_out_events = proximity_out, .tablet_motion_events = motion, + + .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { diff --git a/test/litest-device-waltop-tablet.c b/test/litest-device-waltop-tablet.c index 93ec739d..206b831d 100644 --- a/test/litest-device-waltop-tablet.c +++ b/test/litest-device-waltop-tablet.c @@ -62,10 +62,28 @@ static struct input_event motion[] = { { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; + +static int +get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) +{ + switch (evcode) { + case ABS_TILT_X: + case ABS_TILT_Y: + *value = 0; + return 0; + case ABS_PRESSURE: + *value = 100; + return 0; + } + return 1; +} + static struct litest_device_interface interface = { .tablet_proximity_in_events = proximity_in, .tablet_proximity_out_events = proximity_out, .tablet_motion_events = motion, + + .get_axis_default = get_axis_default, }; static struct input_absinfo absinfo[] = { diff --git a/test/litest.c b/test/litest.c index 632b144a..5c829277 100644 --- a/test/litest.c +++ b/test/litest.c @@ -1519,7 +1519,9 @@ auto_assign_tablet_value(struct litest_device *d, value = litest_scale(d, ABS_Y, y); break; default: - axis_replacement_value(d, axes, ev->code, &value); + if (!axis_replacement_value(d, axes, ev->code, &value) && + d->interface->get_axis_default) + d->interface->get_axis_default(d, ev->code, &value); break; } From 7c449cf5f9defcab4c1e907974946c48c6c4e624 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 14 Dec 2015 07:36:14 +1000 Subject: [PATCH 191/255] tablet: add missing tip event to libinput_event_tablet_tool_get_base_event() Signed-off-by: Peter Hutterer --- src/libinput.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libinput.c b/src/libinput.c index 278ca850..df44e7ee 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -2469,6 +2469,7 @@ libinput_event_tablet_tool_get_base_event(struct libinput_event_tablet_tool *eve event->base.type, NULL, LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); From c7533b753db527922f247387b192f819ef036449 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 14 Dec 2015 08:49:57 +1000 Subject: [PATCH 192/255] test: fix copy/paste error in motion_delta_partial Signed-off-by: Peter Hutterer --- test/tablet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tablet.c b/test/tablet.c index 18f08b23..3ed16660 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -1043,7 +1043,7 @@ START_TEST(motion_delta_partial) litest_assert_double_eq(dx, 0.0); ck_assert(!libinput_event_tablet_tool_axis_has_changed(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_X)); + LIBINPUT_TABLET_TOOL_AXIS_Y)); dy = libinput_event_tablet_tool_get_axis_delta(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); litest_assert_double_eq(dy, 0.0); From 0c6f505ae6e6288409a7bd1547277a6908fd62d0 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 14 Dec 2015 09:37:14 +1000 Subject: [PATCH 193/255] tools: print the wheel axis delta, not the axis value The axis value for a rel wheel is always 0 Signed-off-by: Peter Hutterer --- tools/event-debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/event-debug.c b/tools/event-debug.c index 1fd29c6d..aaa31b21 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -428,7 +428,7 @@ print_tablet_axes(struct libinput_event_tablet_tool *t) } if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL)) { - wheel = libinput_event_tablet_tool_get_axis_value(t, + wheel = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); delta = libinput_event_tablet_tool_get_axis_delta_discrete(t, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); From 72249f8a16d5913913deab2b2ddb7eeb86084895 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 14 Dec 2015 10:21:47 +1000 Subject: [PATCH 194/255] test: fix test for tablet rel wheel discrete deltas Signed-off-by: Peter Hutterer --- test/tablet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tablet.c b/test/tablet.c index 3ed16660..ff3a6f9b 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -2082,7 +2082,7 @@ START_TEST(mouse_wheel) ck_assert_int_eq(val, 0); val = libinput_event_tablet_tool_get_axis_delta_discrete(tev, - LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); + LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); ck_assert_int_eq(val, 0); libinput_event_destroy(event); From f0a57fc97a1fa008ec42719fadc91f4c5b8a4d67 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 14 Dec 2015 10:28:05 +1000 Subject: [PATCH 195/255] test: change tablet matrix test to use absolute x/y values Prep work for dropping delta coordinates. Signed-off-by: Peter Hutterer --- test/tablet.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/test/tablet.c b/test/tablet.c index ff3a6f9b..4cd5cef6 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -2406,15 +2406,25 @@ START_TEST(tablet_calibration_set_matrix_delta) { -1, -1 } }; int has_calibration; - double dx, dy, mdx, mdy; + double x, y, dx, dy, mdx, mdy; has_calibration = libevdev_has_property(dev->evdev, INPUT_PROP_DIRECT); if (!has_calibration) return; - litest_tablet_proximity_in(dev, 100, 100, axes); litest_drain_events(li); + litest_tablet_proximity_in(dev, 100, 100, axes); + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + x = libinput_event_tablet_tool_get_axis_value(tablet_event, + LIBINPUT_TABLET_TOOL_AXIS_X); + y = libinput_event_tablet_tool_get_axis_value(tablet_event, + LIBINPUT_TABLET_TOOL_AXIS_Y); + libinput_event_destroy(event); + litest_tablet_motion(dev, 80, 80, axes); libinput_dispatch(li); @@ -2422,10 +2432,10 @@ START_TEST(tablet_calibration_set_matrix_delta) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); - dx = libinput_event_tablet_tool_get_axis_delta(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_X); - dy = libinput_event_tablet_tool_get_axis_delta(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_Y); + dx = libinput_event_tablet_tool_get_axis_value(tablet_event, + LIBINPUT_TABLET_TOOL_AXIS_X) - x; + dy = libinput_event_tablet_tool_get_axis_value(tablet_event, + LIBINPUT_TABLET_TOOL_AXIS_Y) - y; libinput_event_destroy(event); litest_tablet_proximity_out(dev); litest_drain_events(li); @@ -2435,7 +2445,15 @@ START_TEST(tablet_calibration_set_matrix_delta) ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); litest_tablet_proximity_in(dev, 100, 100, axes); - litest_drain_events(li); + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + x = libinput_event_tablet_tool_get_axis_value(tablet_event, + LIBINPUT_TABLET_TOOL_AXIS_X); + y = libinput_event_tablet_tool_get_axis_value(tablet_event, + LIBINPUT_TABLET_TOOL_AXIS_Y); + libinput_event_destroy(event); litest_tablet_motion(dev, 80, 80, axes); libinput_dispatch(li); @@ -2444,10 +2462,10 @@ START_TEST(tablet_calibration_set_matrix_delta) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); - mdx = libinput_event_tablet_tool_get_axis_delta(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_X); - mdy = libinput_event_tablet_tool_get_axis_delta(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_Y); + mdx = libinput_event_tablet_tool_get_axis_value(tablet_event, + LIBINPUT_TABLET_TOOL_AXIS_X) - x; + mdy = libinput_event_tablet_tool_get_axis_value(tablet_event, + LIBINPUT_TABLET_TOOL_AXIS_Y) - y; libinput_event_destroy(event); litest_drain_events(li); From 69dd3e46293861cae63a88c6716b82cc7dd59d7f Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 14 Dec 2015 13:51:55 +1000 Subject: [PATCH 196/255] doc: add missing tablet-axes.svg Missing from 4677c48ab66c90cda2b66f57061401482f6d9f09 Signed-off-by: Peter Hutterer --- doc/svg/tablet-axes.svg | 563 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 563 insertions(+) create mode 100644 doc/svg/tablet-axes.svg diff --git a/doc/svg/tablet-axes.svg b/doc/svg/tablet-axes.svg new file mode 100644 index 00000000..59b86482 --- /dev/null +++ b/doc/svg/tablet-axes.svg @@ -0,0 +1,563 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + Distance + + + + + + + + + + Pressure + + + + + + + Tilt + + + + + From 6861039c290de0aa574c21aaebac7e68b4b502ed Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 14 Dec 2015 15:24:42 +1000 Subject: [PATCH 197/255] tablet: drop unused condition Since bd0f43eeb6d386a1d99065f629be14fd6c87e921 this condition isn't triggered anymore. Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index cd208a8f..7f6eecb4 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -398,13 +398,6 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, axis_to_evcode(a)); switch (a) { - case LIBINPUT_TABLET_TOOL_AXIS_X: - case LIBINPUT_TABLET_TOOL_AXIS_Y: - if (device->left_handed.enabled) - tablet->axes[a] = invert_axis(absinfo); - else - tablet->axes[a] = absinfo->value; - break; case LIBINPUT_TABLET_TOOL_AXIS_DISTANCE: case LIBINPUT_TABLET_TOOL_AXIS_PRESSURE: case LIBINPUT_TABLET_TOOL_AXIS_SLIDER: From 09456ebf23b1ec9036bf22ebcecd19dcfef26615 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 14 Dec 2015 13:47:28 +1000 Subject: [PATCH 198/255] test: add pressure axes to proximity in for the bamboo and the cintiq Required for pressure offset testing Signed-off-by: Peter Hutterer --- test/litest-device-wacom-bamboo-tablet.c | 1 + test/litest-device-wacom-cintiq-tablet.c | 1 + 2 files changed, 2 insertions(+) diff --git a/test/litest-device-wacom-bamboo-tablet.c b/test/litest-device-wacom-bamboo-tablet.c index 2cf98c35..d1f5fc99 100644 --- a/test/litest-device-wacom-bamboo-tablet.c +++ b/test/litest-device-wacom-bamboo-tablet.c @@ -37,6 +37,7 @@ 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_PRESSURE, .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 }, diff --git a/test/litest-device-wacom-cintiq-tablet.c b/test/litest-device-wacom-cintiq-tablet.c index db3173cd..46fd2bbd 100644 --- a/test/litest-device-wacom-cintiq-tablet.c +++ b/test/litest-device-wacom-cintiq-tablet.c @@ -37,6 +37,7 @@ 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_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_ABS, .code = ABS_MISC, .value = 2083 }, From db852ef0dbb61eb68d26affb3d01c194e0242369 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 1 Dec 2015 11:07:57 +1000 Subject: [PATCH 199/255] tablet: support tool-specific pressure offsets If a tool wears out, it may have a pre-loaded pressure offset. In that case, even when the tool is not physically in contact with the tablet surface it will send pressure events. Use automatic pressure offset detection, similar to what the X.Org wacom driver does. On proximity-in, check the pressure and if the distance is above 50% of the range and the pressure is nonzero but below 20% of the range, use that value as pressure offset. Signed-off-by: Peter Hutterer Reviewed-by: Ping Cheng --- doc/tablet-support.dox | 29 +++ src/evdev-tablet.c | 85 +++++- src/evdev-tablet.h | 21 ++ src/libinput-private.h | 3 + test/litest-device-wacom-intuos-tablet.c | 1 + test/tablet.c | 313 ++++++++++++++++++++++- 6 files changed, 448 insertions(+), 4 deletions(-) diff --git a/doc/tablet-support.dox b/doc/tablet-support.dox index 24d08d20..5468c6ff 100644 --- a/doc/tablet-support.dox +++ b/doc/tablet-support.dox @@ -92,4 +92,33 @@ if (value < min) { } @endcode +@section tablet-pressure-offset Pressure offset on worn-out tools + +When a tool is used for an extended period it can wear down physically. A +worn-down tool may never return a zero pressure value. Even when hovering +above the surface, the pressure value returned by the tool is nonzero, +creating a fake surface touch and making interaction with the tablet less +predictable. + +libinput automatically detects pressure offsets and rescales the remaining +pressure range into the available range, making pressure-offsets transparent +to the caller. A tool with a pressure offset will thus send a 0 pressure +value for the detected offset and nonzero pressure values for values higher +than that offset. + +Some limitations apply to avoid misdetection of pressure offsets, +specifically: +- pressure offset is only detected on proximity in, and if a device is + capable of detection distances, +- pressure offset is only detected if the distance between the tool and the + tablet is high enough, +- pressure offset is only used if it is 20% or less of the pressure range + available to the tool. A pressure offset higher than 20% indicates either + a misdetection or a tool that should be replaced, and +- if a pressure value less than the current pressure offset is seen, the + offset resets to that value. + +Pressure offsets are not detected on @ref LIBINPUT_TABLET_TOOL_TYPE_MOUSE +and @ref LIBINPUT_TABLET_TOOL_TYPE_LENS tools. + */ diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 7f6eecb4..2f4d6804 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -21,6 +21,7 @@ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include "config.h" +#include "libinput-version.h" #include "evdev-tablet.h" #include @@ -202,7 +203,7 @@ tablet_update_tool(struct tablet_dispatch *tablet, } static inline double -normalize_pressure_dist_slider(const struct input_absinfo *absinfo) +normalize_dist_slider(const struct input_absinfo *absinfo) { double range = absinfo->maximum - absinfo->minimum; double value = (absinfo->value - absinfo->minimum) / range; @@ -210,6 +211,18 @@ normalize_pressure_dist_slider(const struct input_absinfo *absinfo) return value; } +static inline double +normalize_pressure(const struct input_absinfo *absinfo, + struct libinput_tablet_tool *tool) +{ + double range = absinfo->maximum - absinfo->minimum; + int offset = tool->has_pressure_offset ? + tool->pressure_offset : 0; + double value = (absinfo->value - offset - absinfo->minimum) / range; + + return value; +} + static inline double normalize_tilt(const struct input_absinfo *absinfo) { @@ -398,10 +411,12 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, axis_to_evcode(a)); switch (a) { - case LIBINPUT_TABLET_TOOL_AXIS_DISTANCE: case LIBINPUT_TABLET_TOOL_AXIS_PRESSURE: + tablet->axes[a] = normalize_pressure(absinfo, tool); + break; + case LIBINPUT_TABLET_TOOL_AXIS_DISTANCE: case LIBINPUT_TABLET_TOOL_AXIS_SLIDER: - tablet->axes[a] = normalize_pressure_dist_slider(absinfo); + tablet->axes[a] = normalize_dist_slider(absinfo); break; case LIBINPUT_TABLET_TOOL_AXIS_TILT_X: case LIBINPUT_TABLET_TOOL_AXIS_TILT_Y: @@ -809,6 +824,8 @@ tablet_get_tool(struct tablet_dispatch *tablet, .refcount = 1, }; + tool->pressure_offset = 0; + tool->has_pressure_offset = false; tool_set_bits(tablet, tool); list_insert(tool_list, &tool->link); @@ -922,6 +939,67 @@ sanitize_tablet_axes(struct tablet_dispatch *tablet) set_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); } +static inline int +axis_range_percentage(const struct input_absinfo *a, int percent) +{ + return (a->maximum - a->minimum) * percent/100 + a->minimum; +} + +static void +detect_pressure_offset(struct tablet_dispatch *tablet, + struct evdev_device *device, + struct libinput_tablet_tool *tool) +{ + const struct input_absinfo *pressure, *distance; + int offset; + + if (!bit_is_set(tablet->changed_axes, + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) + return; + + pressure = libevdev_get_abs_info(device->evdev, ABS_PRESSURE); + distance = libevdev_get_abs_info(device->evdev, ABS_DISTANCE); + + if (!pressure || !distance) + return; + + offset = pressure->value - pressure->minimum; + + if (tool->has_pressure_offset) { + if (offset < tool->pressure_offset) + tool->pressure_offset = offset; + return; + } + + /* we only set a pressure offset on proximity in */ + if (!tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY)) + return; + + /* If we're closer than 50% of the distance axis, skip pressure + * offset detection, too likely to be wrong */ + if (distance->value < axis_range_percentage(distance, 50)) + return; + + if (offset > axis_range_percentage(pressure, 20)) { + log_error(device->base.seat->libinput, + "Ignoring pressure offset greater than 20%% detected on tool %s (serial %#x). " + "See http://wayland.freedesktop.org/libinput/doc/%s/tablet-support.html\n", + tablet_tool_type_to_string(tool->type), + tool->serial, + LIBINPUT_VERSION); + return; + } + + log_info(device->base.seat->libinput, + "Pressure offset detected on tool %s (serial %#x). " + "See http://wayland.freedesktop.org/libinput/doc/%s/tablet-support.html\n", + tablet_tool_type_to_string(tool->type), + tool->serial, + LIBINPUT_VERSION); + tool->pressure_offset = offset; + tool->has_pressure_offset = true; +} + static void tablet_flush(struct tablet_dispatch *tablet, struct evdev_device *device, @@ -946,6 +1024,7 @@ tablet_flush(struct tablet_dispatch *tablet, tablet_set_status(tablet, TABLET_TOOL_LEAVING_CONTACT); } else if (tablet_has_status(tablet, TABLET_AXES_UPDATED) || tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY)) { + detect_pressure_offset(tablet, device, tool); sanitize_tablet_axes(tablet); tablet_check_notify_axes(tablet, device, time, tool); diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index 162b5366..4dcbccc6 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -178,4 +178,25 @@ tablet_tool_to_evcode(enum libinput_tablet_tool_type type) return code; } + +static inline const char * +tablet_tool_type_to_string(enum libinput_tablet_tool_type type) +{ + const char *str; + + switch (type) { + case LIBINPUT_TABLET_TOOL_TYPE_PEN: str = "pen"; break; + case LIBINPUT_TABLET_TOOL_TYPE_ERASER: str = "eraser"; break; + case LIBINPUT_TABLET_TOOL_TYPE_BRUSH: str = "brush"; break; + case LIBINPUT_TABLET_TOOL_TYPE_PENCIL: str = "pencil"; break; + case LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH: str = "airbrush"; break; + case LIBINPUT_TABLET_TOOL_TYPE_MOUSE: str = "mouse"; break; + case LIBINPUT_TABLET_TOOL_TYPE_LENS: str = "lens"; break; + default: + abort(); + } + + return str; +} + #endif diff --git a/src/libinput-private.h b/src/libinput-private.h index 38a14b8f..f5b26483 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -259,6 +259,9 @@ struct libinput_tablet_tool { unsigned char buttons[NCHARS(KEY_MAX) + 1]; int refcount; void *user_data; + + int pressure_offset; + bool has_pressure_offset; }; struct libinput_event { diff --git a/test/litest-device-wacom-intuos-tablet.c b/test/litest-device-wacom-intuos-tablet.c index 682a56c1..e1c9e3de 100644 --- a/test/litest-device-wacom-intuos-tablet.c +++ b/test/litest-device-wacom-intuos-tablet.c @@ -37,6 +37,7 @@ 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_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_ABS, .code = ABS_MISC, .value = 1050626 }, diff --git a/test/tablet.c b/test/tablet.c index 4cd5cef6..57f8083d 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -2313,7 +2313,7 @@ START_TEST(tablet_pressure_distance_exclusive) struct libinput_event_tablet_tool *tev; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, - { ABS_PRESSURE, 20 }, + { ABS_PRESSURE, 20 }, /* see the litest device */ { -1, -1 }, }; double pressure, distance; @@ -2548,6 +2548,310 @@ START_TEST(tablet_calibration_set_matrix) } END_TEST +START_TEST(tablet_pressure_offset) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_tablet_tool *tev; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 70 }, + { ABS_PRESSURE, 20 }, + { -1, -1 }, + }; + double pressure; + + litest_tablet_proximity_in(dev, 5, 100, axes); + litest_drain_events(li); + + axes[0].value = 0; + axes[1].value = 21; + litest_push_event_frame(dev); + litest_tablet_motion(dev, 70, 70, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_pop_event_frame(dev); + libinput_dispatch(li); + litest_drain_events(li); + + axes[1].value = 20; + litest_tablet_motion(dev, 70, 70, axes); + libinput_dispatch(li); + + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + pressure = libinput_event_tablet_tool_get_axis_value(tev, + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + ck_assert_double_eq(pressure, 0.0); + + libinput_event_destroy(event); + litest_drain_events(li); + + axes[1].value = 21; + litest_tablet_motion(dev, 70, 70, axes); + + libinput_dispatch(li); + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + + pressure = libinput_event_tablet_tool_get_axis_value(tev, + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + + /* can't use the double_eq here, the pressure value is too tiny */ + ck_assert(pressure > 0.0); + ck_assert(pressure < 1.0); + libinput_event_destroy(event); +} +END_TEST + +START_TEST(tablet_pressure_offset_decrease) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_tablet_tool *tev; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 70 }, + { ABS_PRESSURE, 20 }, + { -1, -1 }, + }; + double pressure; + + /* offset 20 on prox in */ + litest_tablet_proximity_in(dev, 5, 100, axes); + litest_drain_events(li); + + /* a reduced pressure value must reduce the offset */ + axes[0].value = 0; + axes[1].value = 10; + litest_push_event_frame(dev); + litest_tablet_motion(dev, 70, 70, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_pop_event_frame(dev); + libinput_dispatch(li); + + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + pressure = libinput_event_tablet_tool_get_axis_value(tev, + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + ck_assert_double_eq(pressure, 0.0); + + libinput_event_destroy(event); + litest_drain_events(li); + + axes[1].value = 11; + litest_tablet_motion(dev, 70, 70, axes); + libinput_dispatch(li); + + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + + pressure = libinput_event_tablet_tool_get_axis_value(tev, + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + + /* can't use the double_eq here, the pressure value is too tiny */ + ck_assert(pressure > 0.0); + ck_assert(pressure < 1.0); + libinput_event_destroy(event); +} +END_TEST + +START_TEST(tablet_pressure_offset_increase) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_tablet_tool *tev; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 70 }, + { ABS_PRESSURE, 20 }, + { -1, -1 }, + }; + double pressure; + + /* offset 20 on first prox in */ + litest_tablet_proximity_in(dev, 5, 100, axes); + litest_tablet_proximity_out(dev); + litest_drain_events(li); + + /* offset 30 on second prox in - must not change the offset */ + axes[1].value = 30; + litest_tablet_proximity_in(dev, 5, 100, axes); + litest_drain_events(li); + + axes[0].value = 0; + axes[1].value = 31; + litest_push_event_frame(dev); + litest_tablet_motion(dev, 70, 70, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_pop_event_frame(dev); + libinput_dispatch(li); + litest_drain_events(li); + + axes[1].value = 30; + litest_tablet_motion(dev, 70, 70, axes); + libinput_dispatch(li); + + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + pressure = libinput_event_tablet_tool_get_axis_value(tev, + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + /* can't use the double_eq here, the pressure value is too tiny */ + ck_assert(pressure > 0.0); + ck_assert(pressure < 1.0); + libinput_event_destroy(event); + + litest_drain_events(li); + + axes[1].value = 20; + litest_tablet_motion(dev, 70, 70, axes); + libinput_dispatch(li); + + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + + pressure = libinput_event_tablet_tool_get_axis_value(tev, + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + + ck_assert_double_eq(pressure, 0.0); + libinput_event_destroy(event); +} +END_TEST + +START_TEST(tablet_pressure_offset_exceed_threshold) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_tablet_tool *tev; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 70 }, + { ABS_PRESSURE, 30 }, + { -1, -1 }, + }; + double pressure; + + litest_drain_events(li); + + litest_disable_log_handler(li); + litest_tablet_proximity_in(dev, 5, 100, axes); + libinput_dispatch(li); + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + pressure = libinput_event_tablet_tool_get_axis_value(tev, + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + ck_assert_double_eq(pressure, 0.0); + libinput_event_destroy(event); + litest_restore_log_handler(li); + + axes[0].value = 0; + axes[1].value = 31; + litest_push_event_frame(dev); + litest_tablet_motion(dev, 70, 70, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_pop_event_frame(dev); + libinput_dispatch(li); + litest_drain_events(li); + + axes[1].value = 30; + litest_tablet_motion(dev, 70, 70, axes); + libinput_dispatch(li); + + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + pressure = libinput_event_tablet_tool_get_axis_value(tev, + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + ck_assert_double_gt(pressure, 0.0); + + libinput_event_destroy(event); +} +END_TEST + +START_TEST(tablet_pressure_offset_none_for_zero_distance) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_tablet_tool *tev; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 0 }, + { ABS_PRESSURE, 20 }, + { -1, -1 }, + }; + double pressure; + + litest_drain_events(li); + + /* we're going straight to touch on proximity, make sure we don't + * offset the pressure here */ + litest_push_event_frame(dev); + litest_tablet_proximity_in(dev, 5, 100, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_pop_event_frame(dev); + libinput_dispatch(li); + + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + pressure = libinput_event_tablet_tool_get_axis_value(tev, + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + ck_assert_double_gt(pressure, 0.0); + + libinput_event_destroy(event); +} +END_TEST + +START_TEST(tablet_pressure_offset_none_for_small_distance) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_tablet_tool *tev; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 20 }, + { ABS_PRESSURE, 20 }, + { -1, -1 }, + }; + double pressure; + + /* stylus too close to the tablet on the proximity in, ignore any + * pressure offset */ + litest_tablet_proximity_in(dev, 5, 100, axes); + litest_drain_events(li); + libinput_dispatch(li); + + axes[0].value = 0; + axes[1].value = 21; + litest_push_event_frame(dev); + litest_tablet_motion(dev, 70, 70, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_pop_event_frame(dev); + litest_drain_events(li); + + axes[1].value = 20; + litest_tablet_motion(dev, 70, 70, axes); + libinput_dispatch(li); + + litest_wait_for_event_of_type(li, + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + -1); + event = libinput_get_event(li); + tev = libinput_event_get_tablet_tool_event(event); + pressure = libinput_event_tablet_tool_get_axis_value(tev, + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + ck_assert_double_gt(pressure, 0.0); + + libinput_event_destroy(event); +} +END_TEST + void litest_setup_tests(void) { @@ -2596,4 +2900,11 @@ litest_setup_tests(void) litest_add("tablet:calibration", tablet_calibration_has_matrix, LITEST_TABLET, LITEST_ANY); litest_add("tablet:calibration", tablet_calibration_set_matrix, LITEST_TABLET, LITEST_ANY); litest_add("tablet:calibration", tablet_calibration_set_matrix_delta, LITEST_TABLET, LITEST_ANY); + + litest_add_for_device("tablet:pressure", tablet_pressure_offset, LITEST_WACOM_INTUOS); + litest_add_for_device("tablet:pressure", tablet_pressure_offset_decrease, LITEST_WACOM_INTUOS); + litest_add_for_device("tablet:pressure", tablet_pressure_offset_increase, LITEST_WACOM_INTUOS); + litest_add_for_device("tablet:pressure", tablet_pressure_offset_exceed_threshold, LITEST_WACOM_INTUOS); + litest_add_for_device("tablet:pressure", tablet_pressure_offset_none_for_zero_distance, LITEST_WACOM_INTUOS); + litest_add_for_device("tablet:pressure", tablet_pressure_offset_none_for_small_distance, LITEST_WACOM_INTUOS); } From 60b05c5696da4301b2333a0ac1d1c1b8da87ca7c Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 15 Dec 2015 08:29:00 +1000 Subject: [PATCH 200/255] doc: a couple of tablet documentation fixes Signed-off-by: Peter Hutterer --- doc/tablet-support.dox | 22 ++++++++++++++++++ src/libinput.h | 52 +++++++++++++++++++++++------------------- 2 files changed, 50 insertions(+), 24 deletions(-) diff --git a/doc/tablet-support.dox b/doc/tablet-support.dox index 5468c6ff..ac56e47a 100644 --- a/doc/tablet-support.dox +++ b/doc/tablet-support.dox @@ -121,4 +121,26 @@ specifically: Pressure offsets are not detected on @ref LIBINPUT_TABLET_TOOL_TYPE_MOUSE and @ref LIBINPUT_TABLET_TOOL_TYPE_LENS tools. +@section tablet-serial-numbers Tracking unique tools + +Some tools provide hardware information that enables libinput to uniquely +identify the physical device. For example, tools compatible with the Wacom +Intuos 4, Intuos 5, Intuos Pro and Cintiq series are uniquely identifiable +through a serial number. + +libinput creates a struct libinput_tablet_tool on the first proximity in of +this tool. By default, this struct is destroyed on proximity out and +re-initialized on the next proximity in. If a caller keeps a reference to +the tool by using libinput_tablet_tool_ref() libinput re-uses this struct +whenever that same physical tool comes into proximity on any tablet +recognized by libinput. It is possible to attach tool-specific virtual state +to the tool. For example, a graphics program such as the GIMP may assign a +specific color to each tool, allowing the artist to use the tools like +physical pens of different color. In multi-tablet setups it is also +possible to track the tool across devices. + +If the tool does not have a unique identifier, libinput creates a single +struct libinput_tablet_tool per tool type on each tablet the tool is used +on. + */ diff --git a/src/libinput.h b/src/libinput.h index 48f72a17..1cd6ea33 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -136,6 +136,7 @@ enum libinput_pointer_axis_source { /** * @ingroup device + * @struct libinput_tablet_tool * * Available axis types for a device. It must have the @ref * LIBINPUT_DEVICE_CAP_TABLET_TOOL capability. @@ -1346,7 +1347,7 @@ libinput_event_gesture_get_angle_delta(struct libinput_event_gesture *event); /** * @defgroup event_tablet Tablet events * - * Events that come from tablet devices. + * Events that come from tools on tablet devices. */ /** @@ -1497,15 +1498,15 @@ libinput_event_tablet_tool_get_y_transformed(struct libinput_event_tablet_tool * * @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_tablet_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. + * By default, a struct libinput_tablet_tool is created on proximity in and + * destroyed on proximity out. The lifetime of the tool may be extended by + * using libinput_tablet_tool_ref() to increment the reference count of the + * tool. This guarantees that the same struct will be used whenever the same + * physical tool comes back into proximity. * - * @note On tablets where the serial number of tools is not reported, each tool - * cannot be guaranteed to be unique. + * @note Physical tool tracking requires hardware support. If unavailable, + * libinput creates one tool per type per tablet. See @ref + * tablet-serial-numbers for more details. * * @param event The libinput tablet event * @return The new tool triggering this event @@ -1639,7 +1640,8 @@ libinput_tablet_tool_get_tool_id(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet * - * Increment the ref count of tool by one + * Increment the reference count of the tool by one. A tool is destroyed + * whenever the reference count reaches 0. See libinput_tablet_tool_unref(). * * @param tool The tool to increment the ref count of * @return The passed tool @@ -1647,6 +1649,18 @@ libinput_tablet_tool_get_tool_id(struct libinput_tablet_tool *tool); struct libinput_tablet_tool * libinput_tablet_tool_ref(struct libinput_tablet_tool *tool); +/** + * @ingroup event_tablet + * + * Decrement the reference count of the tool by one. When the reference + * 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_tablet_tool * +libinput_tablet_tool_unref(struct libinput_tablet_tool *tool); + /** * @ingroup event_tablet * @@ -1675,18 +1689,6 @@ int libinput_tablet_tool_has_button(struct libinput_tablet_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_tablet_tool * -libinput_tablet_tool_unref(struct libinput_tablet_tool *tool); - /** * @ingroup event_tablet * @@ -1705,7 +1707,9 @@ libinput_tablet_tool_get_serial(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet * - * Return the user data associated with a tool object. + * Return the user data associated with a tool object. libinput does + * not manage, look at, or modify this data. The caller must ensure the + * data is valid. * * @param tool The libinput tool * @return The user data associated with the tool object @@ -1716,7 +1720,7 @@ libinput_tablet_tool_get_user_data(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet * - * Set the user data associated with a tool object. + * Set the user data associated with a tool object, if any. * * @param tool The libinput tool * @param user_data The user data to associate with the tool object From 458734e6eb40bb48df49bd308e56170469640875 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 15 Dec 2015 11:26:29 +1000 Subject: [PATCH 201/255] doc: minor comment clarification Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 2f4d6804..ffb141c4 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -754,8 +754,8 @@ tool_set_bits(const struct tablet_dispatch *tablet, break; } - /* If we don't have libwacom, copy all pen-related ones from the - tablet vs all mouse-related ones */ + /* If we don't have libwacom, copy all pen-related buttons from the + tablet vs all mouse-related buttons */ switch (type) { case LIBINPUT_TABLET_TOOL_TYPE_PEN: case LIBINPUT_TABLET_TOOL_TYPE_BRUSH: From 50f4caf1b8123f345e06af8531283b6f40bfe696 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 15 Dec 2015 12:50:30 +1000 Subject: [PATCH 202/255] test: use proper proximity events in tablet serial test Signed-off-by: Peter Hutterer --- test/tablet.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/tablet.c b/test/tablet.c index 57f8083d..c3f53820 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -1627,9 +1627,10 @@ START_TEST(tools_with_serials) * Put a sleep(1) here and that usually fixes it. */ - litest_event(dev[i], EV_KEY, BTN_TOOL_PEN, 1); + litest_push_event_frame(dev[i]); + litest_tablet_proximity_in(dev[i], 10, 10, NULL); litest_event(dev[i], EV_MSC, MSC_SERIAL, 100); - litest_event(dev[i], EV_SYN, SYN_REPORT, 0); + litest_pop_event_frame(dev[i]); libinput_dispatch(li); while ((event = libinput_get_event(li))) { @@ -1677,8 +1678,7 @@ START_TEST(tools_without_serials) * 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); + litest_tablet_proximity_in(dev[i], 10, 10, NULL); libinput_dispatch(li); while ((event = libinput_get_event(li))) { From 67b92adee774814a19ed5669d3921226c2ff6b61 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 15 Dec 2015 12:53:00 +1000 Subject: [PATCH 203/255] test: modernise the tablet tool serial tests a bit Signed-off-by: Peter Hutterer --- test/tablet.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/test/tablet.c b/test/tablet.c index c3f53820..dc3ca8f2 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -1613,6 +1613,7 @@ START_TEST(tools_with_serials) struct litest_device *dev[2]; struct libinput_tablet_tool *tool[2] = {0}; struct libinput_event *event; + struct libinput_event_tablet_tool *tev; int i; for (i = 0; i < 2; i++) { @@ -1622,6 +1623,8 @@ START_TEST(tools_with_serials) NULL, NULL, NULL); + litest_drain_events(li); + /* 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. @@ -1633,17 +1636,10 @@ START_TEST(tools_with_serials) litest_pop_event_frame(dev[i]); libinput_dispatch(li); - while ((event = libinput_get_event(li))) { - if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY) { - struct libinput_event_tablet_tool *t = - libinput_event_get_tablet_tool_event(event); - - tool[i] = libinput_event_tablet_tool_get_tool(t); - } - - libinput_event_destroy(event); - } + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + tool[i] = libinput_event_tablet_tool_get_tool(tev); + libinput_event_destroy(event); } /* We should get the same object for both devices */ @@ -1663,6 +1659,7 @@ START_TEST(tools_without_serials) struct litest_device *dev[2]; struct libinput_tablet_tool *tool[2] = {0}; struct libinput_event *event; + struct libinput_event_tablet_tool *tev; int i; for (i = 0; i < 2; i++) { @@ -1673,6 +1670,8 @@ START_TEST(tools_without_serials) NULL, NULL); + litest_drain_events(li); + /* 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. @@ -1681,17 +1680,10 @@ START_TEST(tools_without_serials) litest_tablet_proximity_in(dev[i], 10, 10, NULL); libinput_dispatch(li); - while ((event = libinput_get_event(li))) { - if (libinput_event_get_type(event) == - LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY) { - struct libinput_event_tablet_tool *t = - libinput_event_get_tablet_tool_event(event); - - tool[i] = libinput_event_tablet_tool_get_tool(t); - } - - libinput_event_destroy(event); - } + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + tool[i] = libinput_event_tablet_tool_get_tool(tev); + libinput_event_destroy(event); } /* We should get different tool objects for each device */ From 5c9c481047fdef0641ae26275db6e51f6c59c23e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 14 Dec 2015 09:05:37 +1000 Subject: [PATCH 204/255] tablet: rename axis_has_changed into an axis-specific API set First part of the big revamp to get rid of libinput_tablet_tool_axis and replace it with a set of axis-specific APIs. Signed-off-by: Peter Hutterer Acked-by: Hans de Goede Reviewed-by: Lyude --- src/libinput.c | 128 +++++++++++++++++++++++++++++++++-- src/libinput.h | 159 +++++++++++++++++++++++++++++++++++++++++--- src/libinput.sym | 10 ++- test/tablet.c | 112 ++++++++++++------------------- tools/event-debug.c | 43 ++++-------- 5 files changed, 339 insertions(+), 113 deletions(-) diff --git a/src/libinput.c b/src/libinput.c index df44e7ee..f37d174f 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -913,8 +913,8 @@ libinput_event_gesture_get_angle_delta(struct libinput_event_gesture *event) } LIBINPUT_EXPORT int -libinput_event_tablet_tool_axis_has_changed(struct libinput_event_tablet_tool *event, - enum libinput_tablet_tool_axis axis) +libinput_event_tablet_tool_x_has_changed( + struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, @@ -923,8 +923,128 @@ libinput_event_tablet_tool_axis_has_changed(struct libinput_event_tablet_tool *e LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); - return (NCHARS(axis) <= sizeof(event->changed_axes)) ? - bit_is_set(event->changed_axes, axis) : 0; + return bit_is_set(event->changed_axes, + LIBINPUT_TABLET_TOOL_AXIS_X); +} + +LIBINPUT_EXPORT int +libinput_event_tablet_tool_y_has_changed( + struct libinput_event_tablet_tool *event) +{ + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + + return bit_is_set(event->changed_axes, + LIBINPUT_TABLET_TOOL_AXIS_Y); +} + +LIBINPUT_EXPORT int +libinput_event_tablet_tool_pressure_has_changed( + struct libinput_event_tablet_tool *event) +{ + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + + return bit_is_set(event->changed_axes, + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); +} + +LIBINPUT_EXPORT int +libinput_event_tablet_tool_distance_has_changed( + struct libinput_event_tablet_tool *event) +{ + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + + return bit_is_set(event->changed_axes, + LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); +} + +LIBINPUT_EXPORT int +libinput_event_tablet_tool_tilt_x_has_changed( + struct libinput_event_tablet_tool *event) +{ + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + + return bit_is_set(event->changed_axes, + LIBINPUT_TABLET_TOOL_AXIS_TILT_X); +} + +LIBINPUT_EXPORT int +libinput_event_tablet_tool_tilt_y_has_changed( + struct libinput_event_tablet_tool *event) +{ + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + + return bit_is_set(event->changed_axes, + LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); +} + +LIBINPUT_EXPORT int +libinput_event_tablet_tool_rotation_has_changed( + struct libinput_event_tablet_tool *event) +{ + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + + return bit_is_set(event->changed_axes, + LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); +} + +LIBINPUT_EXPORT int +libinput_event_tablet_tool_slider_has_changed( + struct libinput_event_tablet_tool *event) +{ + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + + return bit_is_set(event->changed_axes, + LIBINPUT_TABLET_TOOL_AXIS_SLIDER); +} + +LIBINPUT_EXPORT int +libinput_event_tablet_tool_wheel_has_changed( + struct libinput_event_tablet_tool *event) +{ + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + + return bit_is_set(event->changed_axes, + LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); } LIBINPUT_EXPORT double diff --git a/src/libinput.h b/src/libinput.h index 1cd6ea33..34225e06 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1361,20 +1361,161 @@ libinput_event_tablet_tool_get_base_event(struct libinput_event_tablet_tool *eve /** * @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_TOOL_AXIS or - * type @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. + * Check if the x axis was updated in this event. + * For tablet events that are not of type @ref + * LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or + * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. * * @note It is an application bug to call this function for events other than * @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS and @ref LIBINPUT_EVENT_TABLET_TOOL_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_tool_axis_has_changed(struct libinput_event_tablet_tool *event, - enum libinput_tablet_tool_axis axis); +libinput_event_tablet_tool_x_has_changed( + struct libinput_event_tablet_tool *event); + +/** + * @ingroup event_tablet + * + * Check if the y axis was updated in this event. + * For tablet events that are not of type @ref + * LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or + * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. + * + * @note It is an application bug to call this function for events other than + * @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS and @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. + * + * @param event The libinput tablet event + * @return 1 if the axis was updated or 0 otherwise + */ +int +libinput_event_tablet_tool_y_has_changed( + struct libinput_event_tablet_tool *event); + +/** + * @ingroup event_tablet + * + * Check if the pressure axis was updated in this event. + * For tablet events that are not of type @ref + * LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or + * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. + * + * @note It is an application bug to call this function for events other than + * @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS and @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. + * + * @param event The libinput tablet event + * @return 1 if the axis was updated or 0 otherwise + */ +int +libinput_event_tablet_tool_pressure_has_changed( + struct libinput_event_tablet_tool *event); + +/** + * @ingroup event_tablet + * + * Check if the distance axis was updated in this event. + * For tablet events that are not of type @ref + * LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or + * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. + * + * @note It is an application bug to call this function for events other than + * @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS and @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. + * + * @param event The libinput tablet event + * @return 1 if the axis was updated or 0 otherwise + */ +int +libinput_event_tablet_tool_distance_has_changed( + struct libinput_event_tablet_tool *event); + +/** + * @ingroup event_tablet + * + * Check if the tilt x axis was updated in this event. + * For tablet events that are not of type @ref + * LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or + * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. + * + * @note It is an application bug to call this function for events other than + * @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS and @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. + * + * @param event The libinput tablet event + * @return 1 if the axis was updated or 0 otherwise + */ +int +libinput_event_tablet_tool_tilt_x_has_changed( + struct libinput_event_tablet_tool *event); + +/** + * @ingroup event_tablet + * + * Check if the tilt y axis was updated in this event. + * For tablet events that are not of type @ref + * LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or + * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. + * + * @note It is an application bug to call this function for events other than + * @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS and @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. + * + * @param event The libinput tablet event + * @return 1 if the axis was updated or 0 otherwise + */ +int +libinput_event_tablet_tool_tilt_y_has_changed( + struct libinput_event_tablet_tool *event); +/** + * @ingroup event_tablet + * + * Check if the z-rotation axis was updated in this event. + * For tablet events that are not of type @ref + * LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or + * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. + * + * @note It is an application bug to call this function for events other than + * @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS and @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. + * + * @param event The libinput tablet event + * @return 1 if the axis was updated or 0 otherwise + */ +int +libinput_event_tablet_tool_rotation_has_changed( + struct libinput_event_tablet_tool *event); +/** + * @ingroup event_tablet + * + * Check if the slider axis was updated in this event. + * For tablet events that are not of type @ref + * LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or + * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. + * + * @note It is an application bug to call this function for events other than + * @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS and @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. + * + * @param event The libinput tablet event + * @return 1 if the axis was updated or 0 otherwise + */ +int +libinput_event_tablet_tool_slider_has_changed( + struct libinput_event_tablet_tool *event); +/** + * @ingroup event_tablet + * + * Check if the wheel axis was updated in this event. + * For tablet events that are not of type @ref + * LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or + * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. + * + * @note It is an application bug to call this function for events other than + * @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS and @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. + * + * @param event The libinput tablet event + * @return 1 if the axis was updated or 0 otherwise + */ +int +libinput_event_tablet_tool_wheel_has_changed( + struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet @@ -1406,7 +1547,7 @@ libinput_event_tablet_tool_axis_has_changed(struct libinput_event_tablet_tool *e * libinput_event_tablet_tool_get_axis_delta() instead. * * @note This function may be called for a specific axis even if - * libinput_event_tablet_tool_axis_has_changed() returns 0 for that axis. + * libinput_event_tablet_tool_*_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_TOOL_PROXIMITY and the @@ -1465,7 +1606,7 @@ libinput_event_tablet_tool_get_axis_delta_discrete( * screen coordinates. * * @note This function may be called for a specific axis even if - * libinput_event_tablet_tool_axis_has_changed() returns 0 for that axis. + * libinput_event_tablet_tool_*_has_changed() returns 0 for that axis. * libinput always includes all device axes in the event. * * @param event The libinput tablet event @@ -1483,7 +1624,7 @@ libinput_event_tablet_tool_get_x_transformed(struct libinput_event_tablet_tool * * screen coordinates. * * @note This function may be called for a specific axis even if - * libinput_event_tablet_tool_axis_has_changed() returns 0 for that axis. + * libinput_event_tablet_tool_*_has_changed() returns 0 for that axis. * libinput always includes all device axes in the event. * * @param event The libinput tablet event diff --git a/src/libinput.sym b/src/libinput.sym index 1704903c..bee03b9c 100644 --- a/src/libinput.sym +++ b/src/libinput.sym @@ -185,7 +185,15 @@ LIBINPUT_1.1 { * keep them separate */ LIBINPUT_TABLET_SUPPORT { libinput_event_get_tablet_tool_event; - libinput_event_tablet_tool_axis_has_changed; + libinput_event_tablet_tool_x_has_changed; + libinput_event_tablet_tool_y_has_changed; + libinput_event_tablet_tool_pressure_has_changed; + libinput_event_tablet_tool_distance_has_changed; + libinput_event_tablet_tool_rotation_has_changed; + libinput_event_tablet_tool_tilt_x_has_changed; + libinput_event_tablet_tool_tilt_y_has_changed; + libinput_event_tablet_tool_wheel_has_changed; + libinput_event_tablet_tool_slider_has_changed; libinput_event_tablet_tool_get_axis_delta; libinput_event_tablet_tool_get_axis_delta_discrete; libinput_event_tablet_tool_get_axis_value; diff --git a/test/tablet.c b/test/tablet.c index dc3ca8f2..1c715a2b 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -721,10 +721,8 @@ START_TEST(proximity_has_axes) tablet_event = libinput_event_get_tablet_tool_event(event); tool = libinput_event_tablet_tool_get_tool(tablet_event); - ck_assert(libinput_event_tablet_tool_axis_has_changed( - tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X)); - ck_assert(libinput_event_tablet_tool_axis_has_changed( - tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y)); + ck_assert(libinput_event_tablet_tool_x_has_changed(tablet_event)); + ck_assert(libinput_event_tablet_tool_y_has_changed(tablet_event)); x = libinput_event_tablet_tool_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); @@ -735,9 +733,8 @@ START_TEST(proximity_has_axes) litest_assert_double_ne(y, 0); if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) { - ck_assert(libinput_event_tablet_tool_axis_has_changed( - tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)); + ck_assert(libinput_event_tablet_tool_distance_has_changed( + tablet_event)); distance = libinput_event_tablet_tool_get_axis_value( tablet_event, @@ -747,12 +744,10 @@ START_TEST(proximity_has_axes) if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) && libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { - ck_assert(libinput_event_tablet_tool_axis_has_changed( - tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_TILT_X)); - ck_assert(libinput_event_tablet_tool_axis_has_changed( - tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)); + ck_assert(libinput_event_tablet_tool_tilt_x_has_changed( + tablet_event)); + ck_assert(libinput_event_tablet_tool_tilt_y_has_changed( + tablet_event)); x = libinput_event_tablet_tool_get_axis_value( tablet_event, @@ -806,10 +801,8 @@ START_TEST(proximity_has_axes) tablet_event = libinput_event_get_tablet_tool_event(event); tool = libinput_event_tablet_tool_get_tool(tablet_event); - ck_assert(!libinput_event_tablet_tool_axis_has_changed( - tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X)); - ck_assert(!libinput_event_tablet_tool_axis_has_changed( - tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y)); + ck_assert(!libinput_event_tablet_tool_x_has_changed(tablet_event)); + ck_assert(!libinput_event_tablet_tool_y_has_changed(tablet_event)); x = libinput_event_tablet_tool_get_axis_value(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); @@ -819,9 +812,8 @@ START_TEST(proximity_has_axes) litest_assert_double_eq(y, last_y); if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) { - ck_assert(!libinput_event_tablet_tool_axis_has_changed( - tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)); + ck_assert(!libinput_event_tablet_tool_distance_has_changed( + tablet_event)); distance = libinput_event_tablet_tool_get_axis_value( tablet_event, @@ -831,12 +823,10 @@ START_TEST(proximity_has_axes) if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) && libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { - ck_assert(!libinput_event_tablet_tool_axis_has_changed( - tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_TILT_X)); - ck_assert(!libinput_event_tablet_tool_axis_has_changed( - tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)); + ck_assert(!libinput_event_tablet_tool_tilt_x_has_changed( + tablet_event)); + ck_assert(!libinput_event_tablet_tool_tilt_y_has_changed( + tablet_event)); x = libinput_event_tablet_tool_get_axis_value( tablet_event, @@ -885,10 +875,10 @@ START_TEST(motion) ck_assert_int_eq(libinput_event_get_type(event), LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); - x_changed = libinput_event_tablet_tool_axis_has_changed( - tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); - y_changed = libinput_event_tablet_tool_axis_has_changed( - tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); + x_changed = libinput_event_tablet_tool_x_has_changed( + tablet_event); + y_changed = libinput_event_tablet_tool_y_has_changed( + tablet_event); ck_assert(x_changed); ck_assert(y_changed); @@ -920,10 +910,10 @@ START_TEST(motion) type = libinput_event_get_type(event); if (type == LIBINPUT_EVENT_TABLET_TOOL_AXIS) { - x_changed = libinput_event_tablet_tool_axis_has_changed( - tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); - y_changed = libinput_event_tablet_tool_axis_has_changed( - tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); + x_changed = libinput_event_tablet_tool_x_has_changed( + tablet_event); + y_changed = libinput_event_tablet_tool_y_has_changed( + tablet_event); ck_assert(x_changed); ck_assert(y_changed); @@ -1036,20 +1026,17 @@ START_TEST(motion_delta_partial) event = libinput_get_event(li); tablet_event = libinput_event_get_tablet_tool_event(event); - ck_assert(!libinput_event_tablet_tool_axis_has_changed(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_X)); + ck_assert(!libinput_event_tablet_tool_x_has_changed(tablet_event)); dx = libinput_event_tablet_tool_get_axis_delta(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); litest_assert_double_eq(dx, 0.0); - ck_assert(!libinput_event_tablet_tool_axis_has_changed(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_Y)); + ck_assert(!libinput_event_tablet_tool_y_has_changed(tablet_event)); dy = libinput_event_tablet_tool_get_axis_delta(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); litest_assert_double_eq(dy, 0.0); - ck_assert(libinput_event_tablet_tool_axis_has_changed(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)); + ck_assert(libinput_event_tablet_tool_distance_has_changed(tablet_event)); ddist = libinput_event_tablet_tool_get_axis_delta(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); ck_assert_double_gt(ddist, 0); @@ -1334,18 +1321,16 @@ START_TEST(normalization) if (libinput_event_get_type(event) == LIBINPUT_EVENT_TABLET_TOOL_AXIS) { tablet_event = libinput_event_get_tablet_tool_event(event); - if (libinput_event_tablet_tool_axis_has_changed( - tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) { + if (libinput_event_tablet_tool_pressure_has_changed( + tablet_event)) { pressure = libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); litest_assert_double_eq(pressure, 0); } - if (libinput_event_tablet_tool_axis_has_changed( - tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_TILT_X)) { + if (libinput_event_tablet_tool_tilt_x_has_changed( + tablet_event)) { tilt_vertical = libinput_event_tablet_tool_get_axis_value( tablet_event, @@ -1354,9 +1339,8 @@ START_TEST(normalization) litest_assert_double_eq(tilt_vertical, -1); } - if (libinput_event_tablet_tool_axis_has_changed( - tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { + if (libinput_event_tablet_tool_tilt_y_has_changed( + tablet_event)) { tilt_horizontal = libinput_event_tablet_tool_get_axis_value( tablet_event, @@ -1396,18 +1380,16 @@ START_TEST(normalization) if (libinput_event_get_type(event) == LIBINPUT_EVENT_TABLET_TOOL_AXIS) { tablet_event = libinput_event_get_tablet_tool_event(event); - if (libinput_event_tablet_tool_axis_has_changed( - tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) { + if (libinput_event_tablet_tool_pressure_has_changed( + tablet_event)) { pressure = libinput_event_tablet_tool_get_axis_value( tablet_event, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); litest_assert_double_eq(pressure, 1); } - if (libinput_event_tablet_tool_axis_has_changed( - tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_TILT_X)) { + if (libinput_event_tablet_tool_tilt_x_has_changed( + tablet_event)) { tilt_vertical = libinput_event_tablet_tool_get_axis_value( tablet_event, @@ -1416,9 +1398,8 @@ START_TEST(normalization) litest_assert_double_eq(tilt_vertical, 1); } - if (libinput_event_tablet_tool_axis_has_changed( - tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { + if (libinput_event_tablet_tool_tilt_y_has_changed( + tablet_event)) { tilt_horizontal = libinput_event_tablet_tool_get_axis_value( tablet_event, @@ -1969,8 +1950,7 @@ START_TEST(mouse_rotation) -1); event = libinput_get_event(li); tev = libinput_event_get_tablet_tool_event(event); - ck_assert(libinput_event_tablet_tool_axis_has_changed(tev, - LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)); + ck_assert(libinput_event_tablet_tool_rotation_has_changed(tev)); val = libinput_event_tablet_tool_get_axis_value(tev, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); @@ -2032,8 +2012,7 @@ START_TEST(mouse_wheel) event = libinput_get_event(li); tev = libinput_event_get_tablet_tool_event(event); - ck_assert(libinput_event_tablet_tool_axis_has_changed(tev, - LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL)); + ck_assert(libinput_event_tablet_tool_wheel_has_changed(tev)); val = libinput_event_tablet_tool_get_axis_value(tev, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); ck_assert_int_eq(val, 0); @@ -2063,8 +2042,7 @@ START_TEST(mouse_wheel) event = libinput_get_event(li); tev = libinput_event_get_tablet_tool_event(event); - ck_assert(!libinput_event_tablet_tool_axis_has_changed(tev, - LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL)); + ck_assert(!libinput_event_tablet_tool_wheel_has_changed(tev)); val = libinput_event_tablet_tool_get_axis_value(tev, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); ck_assert_int_eq(val, 0); @@ -2160,8 +2138,7 @@ START_TEST(airbrush_wheel) -1); event = libinput_get_event(li); tev = libinput_event_get_tablet_tool_event(event); - ck_assert(libinput_event_tablet_tool_axis_has_changed(tev, - LIBINPUT_TABLET_TOOL_AXIS_SLIDER)); + ck_assert(libinput_event_tablet_tool_slider_has_changed(tev)); val = libinput_event_tablet_tool_get_axis_value(tev, LIBINPUT_TABLET_TOOL_AXIS_SLIDER); @@ -2251,8 +2228,7 @@ START_TEST(artpen_rotation) -1); event = libinput_get_event(li); tev = libinput_event_get_tablet_tool_event(event); - ck_assert(libinput_event_tablet_tool_axis_has_changed(tev, - LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)); + ck_assert(libinput_event_tablet_tool_rotation_has_changed(tev)); val = libinput_event_tablet_tool_get_axis_value(tev, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); diff --git a/tools/event-debug.c b/tools/event-debug.c index aaa31b21..54ad1f2b 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -332,16 +332,6 @@ print_pointer_axis_event(struct libinput_event *ev) printf("vert %.2f%s horiz %.2f%s\n", v, have_vert, h, have_horiz); } -static const char* -tablet_axis_changed_sym(struct libinput_event_tablet_tool *t, - enum libinput_tablet_tool_axis axis) -{ - if (libinput_event_tablet_tool_axis_has_changed(t, axis)) - return "*"; - else - return ""; -} - static void print_tablet_axes(struct libinput_event_tablet_tool *t) { @@ -351,13 +341,16 @@ print_tablet_axes(struct libinput_event_tablet_tool *t) double rotation, slider, wheel; double delta; +#define changed_sym(ev, ax) \ + (libinput_event_tablet_tool_##ax##_has_changed(ev) ? "*" : "") + x = libinput_event_tablet_tool_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_X); y = libinput_event_tablet_tool_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_Y); dx = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_X); dy = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_Y); printf("\t%.2f%s/%.2f%s (%.2f/%.2f)", - x, tablet_axis_changed_sym(t, LIBINPUT_TABLET_TOOL_AXIS_X), - y, tablet_axis_changed_sym(t, LIBINPUT_TABLET_TOOL_AXIS_Y), + x, changed_sym(t, x), + y, changed_sym(t, y), dx, dy); if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) || @@ -371,10 +364,8 @@ print_tablet_axes(struct libinput_event_tablet_tool *t) dy = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); printf("\ttilt: %.2f%s/%.2f%s (%.2f/%.2f)", - x, tablet_axis_changed_sym(t, - LIBINPUT_TABLET_TOOL_AXIS_TILT_X), - y, tablet_axis_changed_sym(t, - LIBINPUT_TABLET_TOOL_AXIS_TILT_Y), + x, changed_sym(t, tilt_x), + y, changed_sym(t, tilt_y), dx, dy); } @@ -388,17 +379,13 @@ print_tablet_axes(struct libinput_event_tablet_tool *t) delta = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); printf("\tdistance: %.2f%s (%.2f)", - dist, - tablet_axis_changed_sym(t, - LIBINPUT_TABLET_TOOL_AXIS_DISTANCE), + dist, changed_sym(t, distance), delta); } else { delta = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); printf("\tpressure: %.2f%s (%.2f)", - pressure, - tablet_axis_changed_sym(t, - LIBINPUT_TABLET_TOOL_AXIS_PRESSURE), + pressure, changed_sym(t, pressure), delta); } } @@ -409,9 +396,7 @@ print_tablet_axes(struct libinput_event_tablet_tool *t) delta = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); printf("\trotation: %.2f%s (%.2f)", - rotation, - tablet_axis_changed_sym(t, - LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z), + rotation, changed_sym(t, rotation), delta); } @@ -421,9 +406,7 @@ print_tablet_axes(struct libinput_event_tablet_tool *t) delta = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_SLIDER); printf("\tslider: %.2f%s (%.2f)", - slider, - tablet_axis_changed_sym(t, - LIBINPUT_TABLET_TOOL_AXIS_SLIDER), + slider, changed_sym(t, slider), delta); } @@ -433,9 +416,7 @@ print_tablet_axes(struct libinput_event_tablet_tool *t) delta = libinput_event_tablet_tool_get_axis_delta_discrete(t, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); printf("\twheel: %.2f%s (%d)", - wheel, - tablet_axis_changed_sym(t, - LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL), + wheel, changed_sym(t, wheel), (int)delta); } } From e5a33086bccf574efe16069e08c5c7e51461f2ab Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 14 Dec 2015 09:51:11 +1000 Subject: [PATCH 205/255] tablet: rename axis_get_value into an axis-specific API set Second part of the big revamp to get rid of libinput_tablet_tool_axis and replace it with a set of axis-specific APIs. Note that this commit drops the ability to get the absolute value from a relative wheel. The previous API always returned 0 for this case, it is not needed anymore. Signed-off-by: Peter Hutterer Acked-by: Hans de Goede Reviewed-by: Lyude --- src/libinput.c | 58 +++++++++- src/libinput.h | 147 ++++++++++++++++++------- src/libinput.sym | 9 +- test/tablet.c | 257 +++++++++++++++----------------------------- tools/event-debug.c | 22 ++-- tools/event-gui.c | 12 +-- 6 files changed, 274 insertions(+), 231 deletions(-) diff --git a/src/libinput.c b/src/libinput.c index f37d174f..27fe297e 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1047,7 +1047,7 @@ libinput_event_tablet_tool_wheel_has_changed( LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); } -LIBINPUT_EXPORT double +static double libinput_event_tablet_tool_get_axis_value(struct libinput_event_tablet_tool *event, enum libinput_tablet_tool_axis axis) { @@ -1081,6 +1081,62 @@ libinput_event_tablet_tool_get_axis_value(struct libinput_event_tablet_tool *eve } } +LIBINPUT_EXPORT double +libinput_event_tablet_tool_get_x(struct libinput_event_tablet_tool *event) +{ + return libinput_event_tablet_tool_get_axis_value(event, + LIBINPUT_TABLET_TOOL_AXIS_X); +} + +LIBINPUT_EXPORT double +libinput_event_tablet_tool_get_y(struct libinput_event_tablet_tool *event) +{ + return libinput_event_tablet_tool_get_axis_value(event, + LIBINPUT_TABLET_TOOL_AXIS_Y); +} + +LIBINPUT_EXPORT double +libinput_event_tablet_tool_get_pressure(struct libinput_event_tablet_tool *event) +{ + return libinput_event_tablet_tool_get_axis_value(event, + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); +} + +LIBINPUT_EXPORT double +libinput_event_tablet_tool_get_distance(struct libinput_event_tablet_tool *event) +{ + return libinput_event_tablet_tool_get_axis_value(event, + LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); +} + +LIBINPUT_EXPORT double +libinput_event_tablet_tool_get_tilt_x(struct libinput_event_tablet_tool *event) +{ + return libinput_event_tablet_tool_get_axis_value(event, + LIBINPUT_TABLET_TOOL_AXIS_TILT_X); +} + +LIBINPUT_EXPORT double +libinput_event_tablet_tool_get_tilt_y(struct libinput_event_tablet_tool *event) +{ + return libinput_event_tablet_tool_get_axis_value(event, + LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); +} + +LIBINPUT_EXPORT double +libinput_event_tablet_tool_get_rotation(struct libinput_event_tablet_tool *event) +{ + return libinput_event_tablet_tool_get_axis_value(event, + LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); +} + +LIBINPUT_EXPORT double +libinput_event_tablet_tool_get_slider_position(struct libinput_event_tablet_tool *event) +{ + return libinput_event_tablet_tool_get_axis_value(event, + LIBINPUT_TABLET_TOOL_AXIS_SLIDER); +} + LIBINPUT_EXPORT double libinput_event_tablet_tool_get_axis_delta(struct libinput_event_tablet_tool *event, enum libinput_tablet_tool_axis axis) diff --git a/src/libinput.h b/src/libinput.h index 34225e06..12a31336 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1520,47 +1520,122 @@ libinput_event_tablet_tool_wheel_has_changed( /** * @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_TOOL_AXIS_X and @ref LIBINPUT_TABLET_TOOL_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_tool_get_x_transformed() and - * libinput_event_tablet_tool_get_y_transformed() for transforming each - * respective axis value into a different coordinate space. - * - @ref LIBINPUT_TABLET_TOOL_AXIS_DISTANCE - The distance from the tablet's - * sensor, normalized from 0 to 1 - * - @ref LIBINPUT_TABLET_TOOL_AXIS_PRESSURE - The current pressure being applied on - * the tool in use, normalized from 0 to 1 - * - @ref LIBINPUT_TABLET_TOOL_AXIS_TILT_X and @ref LIBINPUT_TABLET_TOOL_AXIS_TILT_Y - - * normalized value between -1 and 1 that indicates the X or Y tilt of the - * tool - * - @ref LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z - The z rotation of the tool in - * degrees, clockwise from the tool's logical neutral position. For the - * @ref LIBINPUT_TABLET_TOOL_TYPE_MOUSE and @ref LIBINPUT_TABLET_TOOL_TYPE_LENS tools - * the logical neutral position is pointing to the current logical north - * of the tablet. For the @ref LIBINPUT_TABLET_TOOL_TYPE_BRUSH tool, the logical - * neutral position is with the buttons pointing up. - * - @ref LIBINPUT_TABLET_TOOL_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_TOOL_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_tool_get_axis_delta() instead. - * - * @note This function may be called for a specific axis even if - * libinput_event_tablet_tool_*_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_TOOL_PROXIMITY and the - * event is a proximity out event, the value returned is the last known - * value of the tool before it left proximity. + * Returns the X coordinate of tablet tool, in mm from the top left corner + * of the tablet in its current logical orientation. Use + * libinput_event_tablet_tool_get_x_transformed() for transforming the axis + * value into a different coordinate space. * * @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_tool_get_axis_value(struct libinput_event_tablet_tool *event, - enum libinput_tablet_tool_axis axis); +libinput_event_tablet_tool_get_x(struct libinput_event_tablet_tool *event); + +/** + * @ingroup event_tablet + * + * Returns the Y coordinate of tablet tool, in mm from the top left corner + * of the tablet in its current logical orientation. Use + * libinput_event_tablet_tool_get_y_transformed() for transforming the axis + * value into a different coordinate space. + * + * @param event The libinput tablet event + * @return The current value of the the axis + */ +double +libinput_event_tablet_tool_get_y(struct libinput_event_tablet_tool *event); + +/** + * @ingroup event_tablet + * + * Returns the current pressure being applied on the tool in use, normalized + * to the range [0, 1]. + * + * If this axis does not exist on the device, this function returns 0. + * + * @param event The libinput tablet event + * @return The current value of the the axis + */ +double +libinput_event_tablet_tool_get_pressure(struct libinput_event_tablet_tool *event); + +/** + * @ingroup event_tablet + * + * Returns the current distance from the tablet's sensor, normalized to the + * range [0, 1]. + * + * If this axis does not exist on the device, this function returns 0. + * + * @param event The libinput tablet event + * @return The current value of the the axis + */ +double +libinput_event_tablet_tool_get_distance(struct libinput_event_tablet_tool *event); + +/** + * @ingroup event_tablet + * + * Returns the current tilt along the X axis of the tablet's current logical + * orientation, normalized to the range [-1, 1]. + * + * If this axis does not exist on the device, this function returns 0. + * + * @param event The libinput tablet event + * @return The current value of the the axis + */ +double +libinput_event_tablet_tool_get_tilt_x(struct libinput_event_tablet_tool *event); + +/** + * @ingroup event_tablet + * + * Returns the current tilt along the Y axis of the tablet's current logical + * orientation, normalized to the range [-1, 1]. + * + * If this axis does not exist on the device, this function returns 0. + * + * @param event The libinput tablet event + * @return The current value of the the axis + */ +double +libinput_event_tablet_tool_get_tilt_y(struct libinput_event_tablet_tool *event); + +/** + * @ingroup event_tablet + * + * Returns the current z rotation of the tool in degrees, clockwise from the + * tool's logical neutral position. + * + * For tools of type @ref LIBINPUT_TABLET_TOOL_TYPE_MOUSE and @ref + * LIBINPUT_TABLET_TOOL_TYPE_LENS the logical neutral position is + * pointing to the current logical north of the tablet. For tools of type @ref + * LIBINPUT_TABLET_TOOL_TYPE_BRUSH, the logical neutral position is with the + * buttons pointing up. + * + * If this axis does not exist on the device, this function returns 0. + * + * @param event The libinput tablet event + * @return The current value of the the axis + */ +double +libinput_event_tablet_tool_get_rotation(struct libinput_event_tablet_tool *event); + +/** + * @ingroup event_tablet + * + * Returns the current position of the slider on the tool, normalized to the + * range [-1, 1]. The logical zero is the neutral position of the slider, or + * the logical center of the axis. This axis is available on e.g. the Wacom + * Airbrush. + * + * If this axis does not exist on the device, this function returns 0. + * + * @param event The libinput tablet event + * @return The current value of the the axis + */ +double +libinput_event_tablet_tool_get_slider_position(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet diff --git a/src/libinput.sym b/src/libinput.sym index bee03b9c..ba4c537a 100644 --- a/src/libinput.sym +++ b/src/libinput.sym @@ -194,9 +194,16 @@ LIBINPUT_TABLET_SUPPORT { libinput_event_tablet_tool_tilt_y_has_changed; libinput_event_tablet_tool_wheel_has_changed; libinput_event_tablet_tool_slider_has_changed; + libinput_event_tablet_tool_get_x; + libinput_event_tablet_tool_get_y; + libinput_event_tablet_tool_get_pressure; + libinput_event_tablet_tool_get_distance; + libinput_event_tablet_tool_get_tilt_x; + libinput_event_tablet_tool_get_tilt_y; + libinput_event_tablet_tool_get_rotation; + libinput_event_tablet_tool_get_slider_position; libinput_event_tablet_tool_get_axis_delta; libinput_event_tablet_tool_get_axis_delta_discrete; - libinput_event_tablet_tool_get_axis_value; libinput_event_tablet_tool_get_base_event; libinput_event_tablet_tool_get_button; libinput_event_tablet_tool_get_button_state; diff --git a/test/tablet.c b/test/tablet.c index 1c715a2b..795a14c9 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -323,10 +323,8 @@ START_TEST(tip_down_motion) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); - last_x = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_X); - last_y = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_Y); + last_x = libinput_event_tablet_tool_get_x(tablet_event); + last_y = libinput_event_tablet_tool_get_y(tablet_event); libinput_event_destroy(event); libinput_dispatch(li); @@ -335,10 +333,8 @@ START_TEST(tip_down_motion) LIBINPUT_EVENT_TABLET_TOOL_TIP); ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_DOWN); - x = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_X); - y = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_Y); + x = libinput_event_tablet_tool_get_x(tablet_event); + y = libinput_event_tablet_tool_get_y(tablet_event); ck_assert_double_eq(last_x, x); ck_assert_double_eq(last_y, y); libinput_event_destroy(event); @@ -374,10 +370,8 @@ START_TEST(tip_up_motion) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); - last_x = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_X); - last_y = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_Y); + last_x = libinput_event_tablet_tool_get_x(tablet_event); + last_y = libinput_event_tablet_tool_get_y(tablet_event); libinput_event_destroy(event); libinput_dispatch(li); @@ -386,10 +380,8 @@ START_TEST(tip_up_motion) LIBINPUT_EVENT_TABLET_TOOL_TIP); ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); - x = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_X); - y = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_Y); + x = libinput_event_tablet_tool_get_x(tablet_event); + y = libinput_event_tablet_tool_get_y(tablet_event); ck_assert_double_eq(last_x, x); ck_assert_double_eq(last_y, y); libinput_event_destroy(event); @@ -724,10 +716,8 @@ START_TEST(proximity_has_axes) ck_assert(libinput_event_tablet_tool_x_has_changed(tablet_event)); ck_assert(libinput_event_tablet_tool_y_has_changed(tablet_event)); - x = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_X); - y = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_Y); + x = libinput_event_tablet_tool_get_x(tablet_event); + y = libinput_event_tablet_tool_get_y(tablet_event); litest_assert_double_ne(x, 0); litest_assert_double_ne(y, 0); @@ -736,9 +726,7 @@ START_TEST(proximity_has_axes) ck_assert(libinput_event_tablet_tool_distance_has_changed( tablet_event)); - distance = libinput_event_tablet_tool_get_axis_value( - tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); + distance = libinput_event_tablet_tool_get_distance(tablet_event); litest_assert_double_ne(distance, 0); } @@ -749,12 +737,8 @@ START_TEST(proximity_has_axes) ck_assert(libinput_event_tablet_tool_tilt_y_has_changed( tablet_event)); - x = libinput_event_tablet_tool_get_axis_value( - tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_TILT_X); - y = libinput_event_tablet_tool_get_axis_value( - tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); + x = libinput_event_tablet_tool_get_tilt_x(tablet_event); + y = libinput_event_tablet_tool_get_tilt_y(tablet_event); litest_assert_double_ne(x, 0); litest_assert_double_ne(y, 0); @@ -772,22 +756,15 @@ START_TEST(proximity_has_axes) event = libinput_get_event(li); tablet_event = libinput_event_get_tablet_tool_event(event); - last_x = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_X); - last_y = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_Y); + last_x = libinput_event_tablet_tool_get_x(tablet_event); + last_y = libinput_event_tablet_tool_get_y(tablet_event); if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) - last_distance = libinput_event_tablet_tool_get_axis_value( - tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); + last_distance = libinput_event_tablet_tool_get_distance( + tablet_event); if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) && libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { - last_tx = libinput_event_tablet_tool_get_axis_value( - tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_TILT_X); - last_ty = libinput_event_tablet_tool_get_axis_value( - tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); + last_tx = libinput_event_tablet_tool_get_tilt_x(tablet_event); + last_ty = libinput_event_tablet_tool_get_tilt_y(tablet_event); } libinput_event_destroy(event); @@ -804,10 +781,8 @@ START_TEST(proximity_has_axes) ck_assert(!libinput_event_tablet_tool_x_has_changed(tablet_event)); ck_assert(!libinput_event_tablet_tool_y_has_changed(tablet_event)); - x = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_X); - y = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_Y); + x = libinput_event_tablet_tool_get_x(tablet_event); + y = libinput_event_tablet_tool_get_y(tablet_event); litest_assert_double_eq(x, last_x); litest_assert_double_eq(y, last_y); @@ -815,9 +790,8 @@ START_TEST(proximity_has_axes) ck_assert(!libinput_event_tablet_tool_distance_has_changed( tablet_event)); - distance = libinput_event_tablet_tool_get_axis_value( - tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); + distance = libinput_event_tablet_tool_get_distance( + tablet_event); litest_assert_double_eq(distance, last_distance); } @@ -828,12 +802,8 @@ START_TEST(proximity_has_axes) ck_assert(!libinput_event_tablet_tool_tilt_y_has_changed( tablet_event)); - x = libinput_event_tablet_tool_get_axis_value( - tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_TILT_X); - y = libinput_event_tablet_tool_get_axis_value( - tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); + x = libinput_event_tablet_tool_get_tilt_x(tablet_event); + y = libinput_event_tablet_tool_get_tilt_y(tablet_event); litest_assert_double_eq(x, last_tx); litest_assert_double_eq(y, last_ty); @@ -883,10 +853,8 @@ START_TEST(motion) ck_assert(x_changed); ck_assert(y_changed); - reported_x = libinput_event_tablet_tool_get_axis_value( - tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); - reported_y = libinput_event_tablet_tool_get_axis_value( - tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); + reported_x = libinput_event_tablet_tool_get_x(tablet_event); + reported_y = libinput_event_tablet_tool_get_y(tablet_event); litest_assert_double_lt(reported_x, reported_y); @@ -918,10 +886,10 @@ START_TEST(motion) ck_assert(x_changed); ck_assert(y_changed); - reported_x = libinput_event_tablet_tool_get_axis_value( - tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); - reported_y = libinput_event_tablet_tool_get_axis_value( - tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); + reported_x = libinput_event_tablet_tool_get_x( + tablet_event); + reported_y = libinput_event_tablet_tool_get_y( + tablet_event); litest_assert_double_gt(reported_x, last_reported_x); @@ -962,12 +930,9 @@ START_TEST(motion_delta) event = libinput_get_event(li); tablet_event = libinput_event_get_tablet_tool_event(event); - x1 = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_X); - y1 = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_Y); - dist1 = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); + x1 = libinput_event_tablet_tool_get_x(tablet_event); + y1 = libinput_event_tablet_tool_get_y(tablet_event); + dist1 = libinput_event_tablet_tool_get_distance(tablet_event); libinput_event_destroy(event); axes[0].value = 40; @@ -978,12 +943,9 @@ START_TEST(motion_delta) -1); event = libinput_get_event(li); tablet_event = libinput_event_get_tablet_tool_event(event); - x2 = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_X); - y2 = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_Y); - dist2 = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); + x2 = libinput_event_tablet_tool_get_x(tablet_event); + y2 = libinput_event_tablet_tool_get_y(tablet_event); + dist2 = libinput_event_tablet_tool_get_distance(tablet_event); delta = libinput_event_tablet_tool_get_axis_delta(tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); @@ -1079,10 +1041,8 @@ START_TEST(left_handed) while ((event = libinput_get_event(li))) { tablet_event = libinput_event_get_tablet_tool_event(event); - last_x = libinput_event_tablet_tool_get_axis_value( - tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); - last_y = libinput_event_tablet_tool_get_axis_value( - tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); + last_x = libinput_event_tablet_tool_get_x(tablet_event); + last_y = libinput_event_tablet_tool_get_y(tablet_event); litest_assert_double_eq(last_x, 0); litest_assert_double_eq(last_y, libinput_max_y); @@ -1097,10 +1057,8 @@ START_TEST(left_handed) double x, y; tablet_event = libinput_event_get_tablet_tool_event(event); - x = libinput_event_tablet_tool_get_axis_value( - tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); - y = libinput_event_tablet_tool_get_axis_value( - tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); + x = libinput_event_tablet_tool_get_x(tablet_event); + y = libinput_event_tablet_tool_get_y(tablet_event); litest_assert_double_eq(x, libinput_max_x); litest_assert_double_eq(y, 0); @@ -1125,10 +1083,8 @@ START_TEST(left_handed) while ((event = libinput_get_event(li))) { tablet_event = libinput_event_get_tablet_tool_event(event); - last_x = libinput_event_tablet_tool_get_axis_value( - tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); - last_y = libinput_event_tablet_tool_get_axis_value( - tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); + last_x = libinput_event_tablet_tool_get_x(tablet_event); + last_y = libinput_event_tablet_tool_get_y(tablet_event); litest_assert_double_eq(last_x, libinput_max_x); litest_assert_double_eq(last_y, 0); @@ -1143,10 +1099,8 @@ START_TEST(left_handed) double x, y; tablet_event = libinput_event_get_tablet_tool_event(event); - x = libinput_event_tablet_tool_get_axis_value( - tablet_event, LIBINPUT_TABLET_TOOL_AXIS_X); - y = libinput_event_tablet_tool_get_axis_value( - tablet_event, LIBINPUT_TABLET_TOOL_AXIS_Y); + x = libinput_event_tablet_tool_get_x(tablet_event); + y = libinput_event_tablet_tool_get_y(tablet_event); litest_assert_double_eq(x, 0); litest_assert_double_eq(y, libinput_max_y); @@ -1203,10 +1157,8 @@ START_TEST(motion_event_state) tablet_event = libinput_event_get_tablet_tool_event(event); ck_assert_notnull(tablet_event); - last_x = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_X); - last_y = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_Y); + last_x = libinput_event_tablet_tool_get_x(tablet_event); + last_y = libinput_event_tablet_tool_get_y(tablet_event); /* mark with a button event, then go back to bottom/left */ litest_event(dev, EV_KEY, BTN_STYLUS, 1); @@ -1231,10 +1183,8 @@ START_TEST(motion_event_state) tablet_event = libinput_event_get_tablet_tool_event(event); ck_assert_notnull(tablet_event); - x = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_X); - y = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_Y); + x = libinput_event_tablet_tool_get_x(tablet_event); + y = libinput_event_tablet_tool_get_y(tablet_event); ck_assert(x > last_x); ck_assert(y < last_y); @@ -1323,8 +1273,8 @@ START_TEST(normalization) if (libinput_event_tablet_tool_pressure_has_changed( tablet_event)) { - pressure = libinput_event_tablet_tool_get_axis_value( - tablet_event, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + pressure = libinput_event_tablet_tool_get_pressure( + tablet_event); litest_assert_double_eq(pressure, 0); } @@ -1332,9 +1282,8 @@ START_TEST(normalization) if (libinput_event_tablet_tool_tilt_x_has_changed( tablet_event)) { tilt_vertical = - libinput_event_tablet_tool_get_axis_value( - tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_TILT_X); + libinput_event_tablet_tool_get_tilt_x( + tablet_event); litest_assert_double_eq(tilt_vertical, -1); } @@ -1342,9 +1291,8 @@ START_TEST(normalization) if (libinput_event_tablet_tool_tilt_y_has_changed( tablet_event)) { tilt_horizontal = - libinput_event_tablet_tool_get_axis_value( - tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); + libinput_event_tablet_tool_get_tilt_y( + tablet_event); litest_assert_double_eq(tilt_horizontal, -1); } @@ -1382,8 +1330,8 @@ START_TEST(normalization) if (libinput_event_tablet_tool_pressure_has_changed( tablet_event)) { - pressure = libinput_event_tablet_tool_get_axis_value( - tablet_event, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + pressure = libinput_event_tablet_tool_get_pressure( + tablet_event); litest_assert_double_eq(pressure, 1); } @@ -1391,9 +1339,8 @@ START_TEST(normalization) if (libinput_event_tablet_tool_tilt_x_has_changed( tablet_event)) { tilt_vertical = - libinput_event_tablet_tool_get_axis_value( - tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_TILT_X); + libinput_event_tablet_tool_get_tilt_x( + tablet_event); litest_assert_double_eq(tilt_vertical, 1); } @@ -1401,9 +1348,8 @@ START_TEST(normalization) if (libinput_event_tablet_tool_tilt_y_has_changed( tablet_event)) { tilt_horizontal = - libinput_event_tablet_tool_get_axis_value( - tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); + libinput_event_tablet_tool_get_tilt_y( + tablet_event); litest_assert_double_eq(tilt_horizontal, 1); } @@ -1951,8 +1897,7 @@ START_TEST(mouse_rotation) event = libinput_get_event(li); tev = libinput_event_get_tablet_tool_event(event); ck_assert(libinput_event_tablet_tool_rotation_has_changed(tev)); - val = libinput_event_tablet_tool_get_axis_value(tev, - LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); + val = libinput_event_tablet_tool_get_rotation(tev); /* rounding error galore, we can't test for anything more precise than these */ @@ -2013,9 +1958,6 @@ START_TEST(mouse_wheel) event = libinput_get_event(li); tev = libinput_event_get_tablet_tool_event(event); ck_assert(libinput_event_tablet_tool_wheel_has_changed(tev)); - val = libinput_event_tablet_tool_get_axis_value(tev, - LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); - ck_assert_int_eq(val, 0); val = libinput_event_tablet_tool_get_axis_delta(tev, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); @@ -2043,9 +1985,6 @@ START_TEST(mouse_wheel) event = libinput_get_event(li); tev = libinput_event_get_tablet_tool_event(event); ck_assert(!libinput_event_tablet_tool_wheel_has_changed(tev)); - val = libinput_event_tablet_tool_get_axis_value(tev, - LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); - ck_assert_int_eq(val, 0); val = libinput_event_tablet_tool_get_axis_delta(tev, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); @@ -2139,8 +2078,7 @@ START_TEST(airbrush_wheel) event = libinput_get_event(li); tev = libinput_event_get_tablet_tool_event(event); ck_assert(libinput_event_tablet_tool_slider_has_changed(tev)); - val = libinput_event_tablet_tool_get_axis_value(tev, - LIBINPUT_TABLET_TOOL_AXIS_SLIDER); + val = libinput_event_tablet_tool_get_slider_position(tev); ck_assert_int_eq(val, (v - abs->minimum)/scale); libinput_event_destroy(event); @@ -2229,8 +2167,7 @@ START_TEST(artpen_rotation) event = libinput_get_event(li); tev = libinput_event_get_tablet_tool_event(event); ck_assert(libinput_event_tablet_tool_rotation_has_changed(tev)); - val = libinput_event_tablet_tool_get_axis_value(tev, - LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); + val = libinput_event_tablet_tool_get_rotation(tev); /* artpen has a 90 deg offset cw */ ck_assert_int_eq(round(val), (angle + 90) % 360); @@ -2298,10 +2235,8 @@ START_TEST(tablet_pressure_distance_exclusive) event = libinput_get_event(li); tev = libinput_event_get_tablet_tool_event(event); - pressure = libinput_event_tablet_tool_get_axis_value(tev, - LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); - distance = libinput_event_tablet_tool_get_axis_value(tev, - LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); + pressure = libinput_event_tablet_tool_get_pressure(tev); + distance = libinput_event_tablet_tool_get_distance(tev); ck_assert_double_eq(pressure, 0.0); ck_assert_double_ne(distance, 0.0); @@ -2320,10 +2255,8 @@ START_TEST(tablet_pressure_distance_exclusive) event = libinput_get_event(li); tev = libinput_event_get_tablet_tool_event(event); - pressure = libinput_event_tablet_tool_get_axis_value(tev, - LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); - distance = libinput_event_tablet_tool_get_axis_value(tev, - LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); + pressure = libinput_event_tablet_tool_get_pressure(tev); + distance = libinput_event_tablet_tool_get_distance(tev); ck_assert_double_eq(distance, 0.0); ck_assert_double_ne(pressure, 0.0); @@ -2387,10 +2320,8 @@ START_TEST(tablet_calibration_set_matrix_delta) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); - x = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_X); - y = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_Y); + x = libinput_event_tablet_tool_get_x(tablet_event); + y = libinput_event_tablet_tool_get_y(tablet_event); libinput_event_destroy(event); litest_tablet_motion(dev, 80, 80, axes); @@ -2400,10 +2331,8 @@ START_TEST(tablet_calibration_set_matrix_delta) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); - dx = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_X) - x; - dy = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_Y) - y; + dx = libinput_event_tablet_tool_get_x(tablet_event) - x; + dy = libinput_event_tablet_tool_get_y(tablet_event) - y; libinput_event_destroy(event); litest_tablet_proximity_out(dev); litest_drain_events(li); @@ -2417,10 +2346,8 @@ START_TEST(tablet_calibration_set_matrix_delta) event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); - x = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_X); - y = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_Y); + x = libinput_event_tablet_tool_get_x(tablet_event); + y = libinput_event_tablet_tool_get_y(tablet_event); libinput_event_destroy(event); litest_tablet_motion(dev, 80, 80, axes); @@ -2430,10 +2357,8 @@ START_TEST(tablet_calibration_set_matrix_delta) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); - mdx = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_X) - x; - mdy = libinput_event_tablet_tool_get_axis_value(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_Y) - y; + mdx = libinput_event_tablet_tool_get_x(tablet_event) - x; + mdy = libinput_event_tablet_tool_get_y(tablet_event) - y; libinput_event_destroy(event); litest_drain_events(li); @@ -2548,8 +2473,7 @@ START_TEST(tablet_pressure_offset) event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); - pressure = libinput_event_tablet_tool_get_axis_value(tev, - LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + pressure = libinput_event_tablet_tool_get_pressure(tev); ck_assert_double_eq(pressure, 0.0); libinput_event_destroy(event); @@ -2563,8 +2487,7 @@ START_TEST(tablet_pressure_offset) tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); - pressure = libinput_event_tablet_tool_get_axis_value(tev, - LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + pressure = libinput_event_tablet_tool_get_pressure(tev); /* can't use the double_eq here, the pressure value is too tiny */ ck_assert(pressure > 0.0); @@ -2602,8 +2525,7 @@ START_TEST(tablet_pressure_offset_decrease) event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); - pressure = libinput_event_tablet_tool_get_axis_value(tev, - LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + pressure = libinput_event_tablet_tool_get_pressure(tev); ck_assert_double_eq(pressure, 0.0); libinput_event_destroy(event); @@ -2617,8 +2539,7 @@ START_TEST(tablet_pressure_offset_decrease) tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); - pressure = libinput_event_tablet_tool_get_axis_value(tev, - LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + pressure = libinput_event_tablet_tool_get_pressure(tev); /* can't use the double_eq here, the pressure value is too tiny */ ck_assert(pressure > 0.0); @@ -2666,8 +2587,7 @@ START_TEST(tablet_pressure_offset_increase) event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); - pressure = libinput_event_tablet_tool_get_axis_value(tev, - LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + pressure = libinput_event_tablet_tool_get_pressure(tev); /* can't use the double_eq here, the pressure value is too tiny */ ck_assert(pressure > 0.0); ck_assert(pressure < 1.0); @@ -2683,8 +2603,7 @@ START_TEST(tablet_pressure_offset_increase) tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); - pressure = libinput_event_tablet_tool_get_axis_value(tev, - LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + pressure = libinput_event_tablet_tool_get_pressure(tev); ck_assert_double_eq(pressure, 0.0); libinput_event_destroy(event); @@ -2712,8 +2631,7 @@ START_TEST(tablet_pressure_offset_exceed_threshold) event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); - pressure = libinput_event_tablet_tool_get_axis_value(tev, - LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + pressure = libinput_event_tablet_tool_get_pressure(tev); ck_assert_double_eq(pressure, 0.0); libinput_event_destroy(event); litest_restore_log_handler(li); @@ -2734,8 +2652,7 @@ START_TEST(tablet_pressure_offset_exceed_threshold) event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); - pressure = libinput_event_tablet_tool_get_axis_value(tev, - LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + pressure = libinput_event_tablet_tool_get_pressure(tev); ck_assert_double_gt(pressure, 0.0); libinput_event_destroy(event); @@ -2768,8 +2685,7 @@ START_TEST(tablet_pressure_offset_none_for_zero_distance) event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); - pressure = libinput_event_tablet_tool_get_axis_value(tev, - LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + pressure = libinput_event_tablet_tool_get_pressure(tev); ck_assert_double_gt(pressure, 0.0); libinput_event_destroy(event); @@ -2812,8 +2728,7 @@ START_TEST(tablet_pressure_offset_none_for_small_distance) -1); event = libinput_get_event(li); tev = libinput_event_get_tablet_tool_event(event); - pressure = libinput_event_tablet_tool_get_axis_value(tev, - LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + pressure = libinput_event_tablet_tool_get_pressure(tev); ck_assert_double_gt(pressure, 0.0); libinput_event_destroy(event); diff --git a/tools/event-debug.c b/tools/event-debug.c index 54ad1f2b..6489546f 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -344,8 +344,8 @@ print_tablet_axes(struct libinput_event_tablet_tool *t) #define changed_sym(ev, ax) \ (libinput_event_tablet_tool_##ax##_has_changed(ev) ? "*" : "") - x = libinput_event_tablet_tool_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_X); - y = libinput_event_tablet_tool_get_axis_value(t, LIBINPUT_TABLET_TOOL_AXIS_Y); + x = libinput_event_tablet_tool_get_x(t); + y = libinput_event_tablet_tool_get_x(t); dx = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_X); dy = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_Y); printf("\t%.2f%s/%.2f%s (%.2f/%.2f)", @@ -355,10 +355,8 @@ print_tablet_axes(struct libinput_event_tablet_tool *t) if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) || libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { - x = libinput_event_tablet_tool_get_axis_value(t, - LIBINPUT_TABLET_TOOL_AXIS_TILT_X); - y = libinput_event_tablet_tool_get_axis_value(t, - LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); + x = libinput_event_tablet_tool_get_tilt_x(t); + y = libinput_event_tablet_tool_get_tilt_y(t); dx = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_TILT_X); dy = libinput_event_tablet_tool_get_axis_delta(t, @@ -371,10 +369,8 @@ print_tablet_axes(struct libinput_event_tablet_tool *t) if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE) || libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) { - dist = libinput_event_tablet_tool_get_axis_value(t, - LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); - pressure = libinput_event_tablet_tool_get_axis_value(t, - LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + dist = libinput_event_tablet_tool_get_distance(t); + pressure = libinput_event_tablet_tool_get_pressure(t); if (dist) { delta = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); @@ -391,8 +387,7 @@ print_tablet_axes(struct libinput_event_tablet_tool *t) } if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)) { - rotation = libinput_event_tablet_tool_get_axis_value(t, - LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); + rotation = libinput_event_tablet_tool_get_rotation(t); delta = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); printf("\trotation: %.2f%s (%.2f)", @@ -401,8 +396,7 @@ print_tablet_axes(struct libinput_event_tablet_tool *t) } if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_SLIDER)) { - slider = libinput_event_tablet_tool_get_axis_value(t, - LIBINPUT_TABLET_TOOL_AXIS_SLIDER); + slider = libinput_event_tablet_tool_get_slider_position(t); delta = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_SLIDER); printf("\tslider: %.2f%s (%.2f)", diff --git a/tools/event-gui.c b/tools/event-gui.c index 996842e0..64a84da1 100644 --- a/tools/event-gui.c +++ b/tools/event-gui.c @@ -624,14 +624,10 @@ handle_event_tablet(struct libinput_event *ev, struct window *w) w->width); w->tool.y = libinput_event_tablet_tool_get_y_transformed(t, w->height); - w->tool.pressure = libinput_event_tablet_tool_get_axis_value(t, - LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); - w->tool.distance = libinput_event_tablet_tool_get_axis_value(t, - LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); - w->tool.tilt_x = libinput_event_tablet_tool_get_axis_value(t, - LIBINPUT_TABLET_TOOL_AXIS_TILT_X); - w->tool.tilt_y = libinput_event_tablet_tool_get_axis_value(t, - LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); + w->tool.pressure = libinput_event_tablet_tool_get_pressure(t); + w->tool.distance = libinput_event_tablet_tool_get_distance(t); + w->tool.tilt_x = libinput_event_tablet_tool_get_tilt_x(t); + w->tool.tilt_y = libinput_event_tablet_tool_get_tilt_y(t); break; case LIBINPUT_EVENT_TABLET_TOOL_TIP: x = libinput_event_tablet_tool_get_x_transformed(t, w->width); From 828ca69c770d51fa4832bb9819ccaf1dbf440c0c Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 14 Dec 2015 10:06:56 +1000 Subject: [PATCH 206/255] tablet: rename libinput_tablet_tool_has_axis into an axis-specific API set Part of the big revamp to get rid of libinput_tablet_tool_axis and replace it with a set of axis-specific APIs. Note that this commit drops the ability to check whether a tablet has an x or y axis. If it doesn't, libinput won't initialize the tablet anyway so this was superfluous already. Likewise with the tilt axes - either we have x and y tilt or we have neither, so separate checks for tilt_x and tilt_y is unnecessary. Signed-off-by: Peter Hutterer Acked-by: Hans de Goede Reviewed-by: Lyude --- src/libinput.c | 41 ++++++++++++++++++++++++++--- src/libinput.h | 63 +++++++++++++++++++++++++++++++++++++++++---- src/libinput.sym | 7 ++++- test/tablet.c | 43 ++++++++++--------------------- tools/event-debug.c | 26 +++++++++---------- 5 files changed, 128 insertions(+), 52 deletions(-) diff --git a/src/libinput.c b/src/libinput.c index 27fe297e..2f797dcb 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1359,10 +1359,45 @@ libinput_tablet_tool_get_serial(struct libinput_tablet_tool *tool) } LIBINPUT_EXPORT int -libinput_tablet_tool_has_axis(struct libinput_tablet_tool *tool, - enum libinput_tablet_tool_axis axis) +libinput_tablet_tool_has_pressure(struct libinput_tablet_tool *tool) { - return bit_is_set(tool->axis_caps, axis); + return bit_is_set(tool->axis_caps, + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); +} + +LIBINPUT_EXPORT int +libinput_tablet_tool_has_distance(struct libinput_tablet_tool *tool) +{ + return bit_is_set(tool->axis_caps, + LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); +} + +LIBINPUT_EXPORT int +libinput_tablet_tool_has_tilt(struct libinput_tablet_tool *tool) +{ + return bit_is_set(tool->axis_caps, + LIBINPUT_TABLET_TOOL_AXIS_TILT_X); +} + +LIBINPUT_EXPORT int +libinput_tablet_tool_has_rotation(struct libinput_tablet_tool *tool) +{ + return bit_is_set(tool->axis_caps, + LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); +} + +LIBINPUT_EXPORT int +libinput_tablet_tool_has_slider(struct libinput_tablet_tool *tool) +{ + return bit_is_set(tool->axis_caps, + LIBINPUT_TABLET_TOOL_AXIS_SLIDER); +} + +LIBINPUT_EXPORT int +libinput_tablet_tool_has_wheel(struct libinput_tablet_tool *tool) +{ + return bit_is_set(tool->axis_caps, + LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); } LIBINPUT_EXPORT int diff --git a/src/libinput.h b/src/libinput.h index 12a31336..01e23cb3 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1880,15 +1880,68 @@ libinput_tablet_tool_unref(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet * - * Return whether or not a tablet tool supports the specified axis + * Return whether the tablet tool supports pressure. * * @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 + * @return Nonzero if the axis is available, zero otherwise. */ int -libinput_tablet_tool_has_axis(struct libinput_tablet_tool *tool, - enum libinput_tablet_tool_axis axis); +libinput_tablet_tool_has_pressure(struct libinput_tablet_tool *tool); + +/** + * @ingroup event_tablet + * + * Return whether the tablet tool supports distance. + * + * @param tool The tool to check the axis capabilities of + * @return Nonzero if the axis is available, zero otherwise. + */ +int +libinput_tablet_tool_has_distance(struct libinput_tablet_tool *tool); + +/** + * @ingroup event_tablet + * + * Return whether the tablet tool supports tilt. + * + * @param tool The tool to check the axis capabilities of + * @return Nonzero if the axis is available, zero otherwise. + */ +int +libinput_tablet_tool_has_tilt(struct libinput_tablet_tool *tool); + +/** + * @ingroup event_tablet + * + * Return whether the tablet tool supports z-rotation. + * + * @param tool The tool to check the axis capabilities of + * @return Nonzero if the axis is available, zero otherwise. + */ +int +libinput_tablet_tool_has_rotation(struct libinput_tablet_tool *tool); + +/** + * @ingroup event_tablet + * + * Return whether the tablet tool has a slider axis. + * + * @param tool The tool to check the axis capabilities of + * @return Nonzero if the axis is available, zero otherwise. + */ +int +libinput_tablet_tool_has_slider(struct libinput_tablet_tool *tool); + +/** + * @ingroup event_tablet + * + * Return whether the tablet tool has a relative wheel. + * + * @param tool The tool to check the axis capabilities of + * @return Nonzero if the axis is available, zero otherwise. + */ +int +libinput_tablet_tool_has_wheel(struct libinput_tablet_tool *tool); /** * @ingroup event_tablet diff --git a/src/libinput.sym b/src/libinput.sym index ba4c537a..da98ac5c 100644 --- a/src/libinput.sym +++ b/src/libinput.sym @@ -219,8 +219,13 @@ LIBINPUT_TABLET_SUPPORT { libinput_tablet_tool_get_tool_id; libinput_tablet_tool_get_type; libinput_tablet_tool_get_user_data; + libinput_tablet_tool_has_pressure; + libinput_tablet_tool_has_distance; + libinput_tablet_tool_has_rotation; + libinput_tablet_tool_has_tilt; + libinput_tablet_tool_has_wheel; + libinput_tablet_tool_has_slider; libinput_tablet_tool_has_button; - libinput_tablet_tool_has_axis; libinput_tablet_tool_ref; libinput_tablet_tool_set_user_data; libinput_tablet_tool_unref; diff --git a/test/tablet.c b/test/tablet.c index 795a14c9..bc97538d 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -722,7 +722,7 @@ START_TEST(proximity_has_axes) litest_assert_double_ne(x, 0); litest_assert_double_ne(y, 0); - if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) { + if (libinput_tablet_tool_has_distance(tool)) { ck_assert(libinput_event_tablet_tool_distance_has_changed( tablet_event)); @@ -730,8 +730,7 @@ START_TEST(proximity_has_axes) litest_assert_double_ne(distance, 0); } - if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) && - libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { + if (libinput_tablet_tool_has_tilt(tool)) { ck_assert(libinput_event_tablet_tool_tilt_x_has_changed( tablet_event)); ck_assert(libinput_event_tablet_tool_tilt_y_has_changed( @@ -758,11 +757,10 @@ START_TEST(proximity_has_axes) last_x = libinput_event_tablet_tool_get_x(tablet_event); last_y = libinput_event_tablet_tool_get_y(tablet_event); - if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) + if (libinput_tablet_tool_has_distance(tool)) last_distance = libinput_event_tablet_tool_get_distance( tablet_event); - if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) && - libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { + if (libinput_tablet_tool_has_tilt(tool)) { last_tx = libinput_event_tablet_tool_get_tilt_x(tablet_event); last_ty = libinput_event_tablet_tool_get_tilt_y(tablet_event); } @@ -786,7 +784,7 @@ START_TEST(proximity_has_axes) litest_assert_double_eq(x, last_x); litest_assert_double_eq(y, last_y); - if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) { + if (libinput_tablet_tool_has_distance(tool)) { ck_assert(!libinput_event_tablet_tool_distance_has_changed( tablet_event)); @@ -795,8 +793,7 @@ START_TEST(proximity_has_axes) litest_assert_double_eq(distance, last_distance); } - if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) && - libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { + if (libinput_tablet_tool_has_tilt(tool)) { ck_assert(!libinput_event_tablet_tool_tilt_x_has_changed( tablet_event)); ck_assert(!libinput_event_tablet_tool_tilt_y_has_changed( @@ -1651,14 +1648,9 @@ START_TEST(tool_capabilities) t = libinput_event_get_tablet_tool_event(event); tool = libinput_event_tablet_tool_get_tool(t); - ck_assert(libinput_tablet_tool_has_axis(tool, - LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)); - ck_assert(libinput_tablet_tool_has_axis(tool, - LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)); - ck_assert(!libinput_tablet_tool_has_axis(tool, - LIBINPUT_TABLET_TOOL_AXIS_TILT_X)); - ck_assert(!libinput_tablet_tool_has_axis(tool, - LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)); + ck_assert(libinput_tablet_tool_has_pressure(tool)); + ck_assert(libinput_tablet_tool_has_distance(tool)); + ck_assert(!libinput_tablet_tool_has_tilt(tool)); libinput_event_destroy(event); litest_assert_empty_queue(li); @@ -1674,14 +1666,9 @@ START_TEST(tool_capabilities) t = libinput_event_get_tablet_tool_event(event); tool = libinput_event_tablet_tool_get_tool(t); - ck_assert(libinput_tablet_tool_has_axis(tool, - LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)); - ck_assert(libinput_tablet_tool_has_axis(tool, - LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)); - ck_assert(libinput_tablet_tool_has_axis(tool, - LIBINPUT_TABLET_TOOL_AXIS_TILT_X)); - ck_assert(libinput_tablet_tool_has_axis(tool, - LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)); + ck_assert(libinput_tablet_tool_has_pressure(tool)); + ck_assert(libinput_tablet_tool_has_distance(tool)); + ck_assert(libinput_tablet_tool_has_tilt(tool)); libinput_event_destroy(event); litest_assert_empty_queue(li); @@ -1946,8 +1933,7 @@ START_TEST(mouse_wheel) libinput_event_destroy(event); - ck_assert(libinput_tablet_tool_has_axis(tool, - LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL)); + ck_assert(libinput_tablet_tool_has_wheel(tool)); for (i = 0; i < 3; i++) { litest_event(dev, EV_REL, REL_WHEEL, -1); @@ -2116,8 +2102,7 @@ START_TEST(artpen_tool) ck_assert_notnull(tool); ck_assert_int_eq(libinput_tablet_tool_get_type(tool), LIBINPUT_TABLET_TOOL_TYPE_PEN); - ck_assert(libinput_tablet_tool_has_axis(tool, - LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)); + ck_assert(libinput_tablet_tool_has_rotation(tool)); libinput_event_destroy(event); } diff --git a/tools/event-debug.c b/tools/event-debug.c index 6489546f..b4e62f4f 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -353,8 +353,7 @@ print_tablet_axes(struct libinput_event_tablet_tool *t) y, changed_sym(t, y), dx, dy); - if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) || - libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { + if (libinput_tablet_tool_has_tilt(tool)) { x = libinput_event_tablet_tool_get_tilt_x(t); y = libinput_event_tablet_tool_get_tilt_y(t); dx = libinput_event_tablet_tool_get_axis_delta(t, @@ -367,8 +366,8 @@ print_tablet_axes(struct libinput_event_tablet_tool *t) dx, dy); } - if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE) || - libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) { + if (libinput_tablet_tool_has_distance(tool) || + libinput_tablet_tool_has_pressure(tool)) { dist = libinput_event_tablet_tool_get_distance(t); pressure = libinput_event_tablet_tool_get_pressure(t); if (dist) { @@ -386,7 +385,7 @@ print_tablet_axes(struct libinput_event_tablet_tool *t) } } - if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)) { + if (libinput_tablet_tool_has_rotation(tool)) { rotation = libinput_event_tablet_tool_get_rotation(t); delta = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); @@ -395,7 +394,7 @@ print_tablet_axes(struct libinput_event_tablet_tool *t) delta); } - if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_SLIDER)) { + if (libinput_tablet_tool_has_slider(tool)) { slider = libinput_event_tablet_tool_get_slider_position(t); delta = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_SLIDER); @@ -404,7 +403,7 @@ print_tablet_axes(struct libinput_event_tablet_tool *t) delta); } - if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL)) { + if (libinput_tablet_tool_has_wheel(tool)) { wheel = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); delta = libinput_event_tablet_tool_get_axis_delta_discrete(t, @@ -490,18 +489,17 @@ print_proximity_event(struct libinput_event *ev) state_str); printf("\taxes:"); - if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) + if (libinput_tablet_tool_has_distance(tool)) printf("d"); - if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) + if (libinput_tablet_tool_has_pressure(tool)) printf("p"); - if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) || - libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) + if (libinput_tablet_tool_has_tilt(tool)) printf("t"); - if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)) + if (libinput_tablet_tool_has_rotation(tool)) printf("r"); - if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_SLIDER)) + if (libinput_tablet_tool_has_slider(tool)) printf("s"); - if (libinput_tablet_tool_has_axis(tool, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL)) + if (libinput_tablet_tool_has_wheel(tool)) printf("w"); printf("\tbtn:"); From f96ee412df5e00e7ed9bf8d630c84fddacae6f4d Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 14 Dec 2015 10:23:56 +1000 Subject: [PATCH 207/255] tablet: reduce event deltas to only apply to the wheel Part of the big revamp to get rid of libinput_tablet_tool_axis and replace it with a set of axis-specific APIs. Only the rel wheel has true delta events, everything else is a delta calculated by libinput based on the previous position. Since we supply that position to the callers anyway, they can determine that delta themselves where needed. Signed-off-by: Peter Hutterer Acked-by: Hans de Goede Reviewed-by: Lyude --- src/libinput.c | 47 +++-------------- src/libinput.h | 37 ++++++-------- src/libinput.sym | 4 +- test/tablet.c | 119 ++------------------------------------------ tools/event-debug.c | 57 +++++++-------------- 5 files changed, 43 insertions(+), 221 deletions(-) diff --git a/src/libinput.c b/src/libinput.c index 2f797dcb..b1bced06 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1138,12 +1138,8 @@ libinput_event_tablet_tool_get_slider_position(struct libinput_event_tablet_tool } LIBINPUT_EXPORT double -libinput_event_tablet_tool_get_axis_delta(struct libinput_event_tablet_tool *event, - enum libinput_tablet_tool_axis axis) +libinput_event_tablet_tool_get_wheel_delta(struct libinput_event_tablet_tool *event) { - struct evdev_device *device = - (struct evdev_device *) event->base.device; - require_event_type(libinput_event_get_context(&event->base), event->base.type, 0, @@ -1151,30 +1147,12 @@ libinput_event_tablet_tool_get_axis_delta(struct libinput_event_tablet_tool *eve LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); - switch(axis) { - case LIBINPUT_TABLET_TOOL_AXIS_X: - return evdev_convert_to_mm(device->abs.absinfo_x, - event->deltas[axis]); - case LIBINPUT_TABLET_TOOL_AXIS_Y: - return evdev_convert_to_mm(device->abs.absinfo_y, - event->deltas[axis]); - case LIBINPUT_TABLET_TOOL_AXIS_DISTANCE: - case LIBINPUT_TABLET_TOOL_AXIS_PRESSURE: - case LIBINPUT_TABLET_TOOL_AXIS_TILT_X: - case LIBINPUT_TABLET_TOOL_AXIS_TILT_Y: - case LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z: - case LIBINPUT_TABLET_TOOL_AXIS_SLIDER: - case LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL: - return event->deltas[axis]; - default: - return 0; - } + return event->deltas[LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL]; } -LIBINPUT_EXPORT double -libinput_event_tablet_tool_get_axis_delta_discrete( - struct libinput_event_tablet_tool *event, - enum libinput_tablet_tool_axis axis) +LIBINPUT_EXPORT int +libinput_event_tablet_tool_get_wheel_delta_discrete( + struct libinput_event_tablet_tool *event) { require_event_type(libinput_event_get_context(&event->base), event->base.type, @@ -1183,20 +1161,7 @@ libinput_event_tablet_tool_get_axis_delta_discrete( LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); - switch(axis) { - case LIBINPUT_TABLET_TOOL_AXIS_X: - case LIBINPUT_TABLET_TOOL_AXIS_Y: - case LIBINPUT_TABLET_TOOL_AXIS_DISTANCE: - case LIBINPUT_TABLET_TOOL_AXIS_PRESSURE: - case LIBINPUT_TABLET_TOOL_AXIS_TILT_X: - case LIBINPUT_TABLET_TOOL_AXIS_TILT_Y: - case LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z: - case LIBINPUT_TABLET_TOOL_AXIS_SLIDER: - case LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL: - return event->deltas_discrete[axis]; - default: - return 0; - } + return event->deltas_discrete[LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL]; } LIBINPUT_EXPORT double diff --git a/src/libinput.h b/src/libinput.h index 01e23cb3..36911c81 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1640,39 +1640,30 @@ libinput_event_tablet_tool_get_slider_position(struct libinput_event_tablet_tool /** * @ingroup event_tablet * - * Return the delta for a given axis for a tablet. The interpretation of the - * value is axis-dependent: - * - @ref LIBINPUT_TABLET_TOOL_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_tool_get_axis_value() for - * details. + * Return the delta for the wheel in degrees. * * @param event The libinput tablet event - * @param axis The axis to retrieve the value of - * @return The delta to the previous axis value + * @return The delta of the wheel, in degrees, compared to the last event + * + * @see libinput_event_tablet_tool_get_wheel_delta_discrete */ double -libinput_event_tablet_tool_get_axis_delta(struct libinput_event_tablet_tool *event, - enum libinput_tablet_tool_axis axis); +libinput_event_tablet_tool_get_wheel_delta( + struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * - * Return the delta for a given axis for a tablet in discrete steps. - * How a value translates into a discrete step depends on the axis: - * - @ref LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL - the returned value is the number - * of physical mouse wheel clicks. - * For all other axes, this function returns 0. - * + * Return the delta for the wheel in discrete steps (e.g. wheel clicks). + * @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 + * @return The delta of the wheel, in discrete steps, compared to the last event + * + * @see libinput_event_tablet_tool_get_wheel_delta_discrete */ -double -libinput_event_tablet_tool_get_axis_delta_discrete( - struct libinput_event_tablet_tool *event, - enum libinput_tablet_tool_axis axis); +int +libinput_event_tablet_tool_get_wheel_delta_discrete( + struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet diff --git a/src/libinput.sym b/src/libinput.sym index da98ac5c..ddfe81dd 100644 --- a/src/libinput.sym +++ b/src/libinput.sym @@ -202,8 +202,8 @@ LIBINPUT_TABLET_SUPPORT { libinput_event_tablet_tool_get_tilt_y; libinput_event_tablet_tool_get_rotation; libinput_event_tablet_tool_get_slider_position; - libinput_event_tablet_tool_get_axis_delta; - libinput_event_tablet_tool_get_axis_delta_discrete; + libinput_event_tablet_tool_get_wheel_delta; + libinput_event_tablet_tool_get_wheel_delta_discrete; libinput_event_tablet_tool_get_base_event; libinput_event_tablet_tool_get_button; libinput_event_tablet_tool_get_button_state; diff --git a/test/tablet.c b/test/tablet.c index bc97538d..1afbb511 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -903,107 +903,6 @@ START_TEST(motion) } END_TEST -START_TEST(motion_delta) -{ - struct litest_device *dev = litest_current_device(); - struct libinput *li = dev->libinput; - struct libinput_event_tablet_tool *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_TOOL_PROXIMITY, - -1); - - event = libinput_get_event(li); - tablet_event = libinput_event_get_tablet_tool_event(event); - x1 = libinput_event_tablet_tool_get_x(tablet_event); - y1 = libinput_event_tablet_tool_get_y(tablet_event); - dist1 = libinput_event_tablet_tool_get_distance(tablet_event); - 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_TOOL_AXIS, - -1); - event = libinput_get_event(li); - tablet_event = libinput_event_get_tablet_tool_event(event); - x2 = libinput_event_tablet_tool_get_x(tablet_event); - y2 = libinput_event_tablet_tool_get_y(tablet_event); - dist2 = libinput_event_tablet_tool_get_distance(tablet_event); - - delta = libinput_event_tablet_tool_get_axis_delta(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_X); - litest_assert_double_eq(delta, x2 - x1); - delta = libinput_event_tablet_tool_get_axis_delta(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_Y); - litest_assert_double_eq(delta, y2 - y1); - delta = libinput_event_tablet_tool_get_axis_delta(tablet_event, - LIBINPUT_TABLET_TOOL_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_tool *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_TOOL_AXIS, - -1); - event = libinput_get_event(li); - tablet_event = libinput_event_get_tablet_tool_event(event); - - ck_assert(!libinput_event_tablet_tool_x_has_changed(tablet_event)); - dx = libinput_event_tablet_tool_get_axis_delta(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_X); - litest_assert_double_eq(dx, 0.0); - - ck_assert(!libinput_event_tablet_tool_y_has_changed(tablet_event)); - dy = libinput_event_tablet_tool_get_axis_delta(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_Y); - litest_assert_double_eq(dy, 0.0); - - ck_assert(libinput_event_tablet_tool_distance_has_changed(tablet_event)); - ddist = libinput_event_tablet_tool_get_axis_delta(tablet_event, - LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); - ck_assert_double_gt(ddist, 0); - - libinput_event_destroy(event); -} -END_TEST - START_TEST(left_handed) { #if HAVE_LIBWACOM @@ -1945,12 +1844,10 @@ START_TEST(mouse_wheel) tev = libinput_event_get_tablet_tool_event(event); ck_assert(libinput_event_tablet_tool_wheel_has_changed(tev)); - val = libinput_event_tablet_tool_get_axis_delta(tev, - LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); + val = libinput_event_tablet_tool_get_wheel_delta(tev); ck_assert_int_eq(val, 15); - val = libinput_event_tablet_tool_get_axis_delta_discrete(tev, - LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); + val = libinput_event_tablet_tool_get_wheel_delta_discrete(tev); ck_assert_int_eq(val, 1); libinput_event_destroy(event); @@ -1972,12 +1869,10 @@ START_TEST(mouse_wheel) tev = libinput_event_get_tablet_tool_event(event); ck_assert(!libinput_event_tablet_tool_wheel_has_changed(tev)); - val = libinput_event_tablet_tool_get_axis_delta(tev, - LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); + val = libinput_event_tablet_tool_get_wheel_delta(tev); ck_assert_int_eq(val, 0); - val = libinput_event_tablet_tool_get_axis_delta_discrete(tev, - LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); + val = libinput_event_tablet_tool_get_wheel_delta_discrete(tev); ck_assert_int_eq(val, 0); libinput_event_destroy(event); @@ -2157,10 +2052,6 @@ START_TEST(artpen_rotation) /* artpen has a 90 deg offset cw */ ck_assert_int_eq(round(val), (angle + 90) % 360); - val = libinput_event_tablet_tool_get_axis_delta(tev, - LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); - ck_assert_int_eq(val, 8); - libinput_event_destroy(event); litest_assert_empty_queue(li); @@ -2746,8 +2637,6 @@ litest_setup_tests(void) litest_add("tablet:tip", tip_state_axis, LITEST_TABLET, LITEST_ANY); litest_add("tablet:tip", tip_state_button, LITEST_TABLET, 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); diff --git a/tools/event-debug.c b/tools/event-debug.c index b4e62f4f..ddebc136 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -336,7 +336,7 @@ static void print_tablet_axes(struct libinput_event_tablet_tool *t) { struct libinput_tablet_tool *tool = libinput_event_tablet_tool_get_tool(t); - double x, y, dx, dy; + double x, y; double dist, pressure; double rotation, slider, wheel; double delta; @@ -346,68 +346,45 @@ print_tablet_axes(struct libinput_event_tablet_tool *t) x = libinput_event_tablet_tool_get_x(t); y = libinput_event_tablet_tool_get_x(t); - dx = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_X); - dy = libinput_event_tablet_tool_get_axis_delta(t, LIBINPUT_TABLET_TOOL_AXIS_Y); - printf("\t%.2f%s/%.2f%s (%.2f/%.2f)", + printf("\t%.2f%s/%.2f%s", x, changed_sym(t, x), - y, changed_sym(t, y), - dx, dy); + y, changed_sym(t, y)); if (libinput_tablet_tool_has_tilt(tool)) { x = libinput_event_tablet_tool_get_tilt_x(t); y = libinput_event_tablet_tool_get_tilt_y(t); - dx = libinput_event_tablet_tool_get_axis_delta(t, - LIBINPUT_TABLET_TOOL_AXIS_TILT_X); - dy = libinput_event_tablet_tool_get_axis_delta(t, - LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); - printf("\ttilt: %.2f%s/%.2f%s (%.2f/%.2f)", + printf("\ttilt: %.2f%s/%.2f%s", x, changed_sym(t, tilt_x), - y, changed_sym(t, tilt_y), - dx, dy); + y, changed_sym(t, tilt_y)); } if (libinput_tablet_tool_has_distance(tool) || libinput_tablet_tool_has_pressure(tool)) { dist = libinput_event_tablet_tool_get_distance(t); pressure = libinput_event_tablet_tool_get_pressure(t); - if (dist) { - delta = libinput_event_tablet_tool_get_axis_delta(t, - LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); - printf("\tdistance: %.2f%s (%.2f)", - dist, changed_sym(t, distance), - delta); - } else { - delta = libinput_event_tablet_tool_get_axis_delta(t, - LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); - printf("\tpressure: %.2f%s (%.2f)", - pressure, changed_sym(t, pressure), - delta); - } + if (dist) + printf("\tdistance: %.2f%s", + dist, changed_sym(t, distance)); + else + printf("\tpressure: %.2f%s", + pressure, changed_sym(t, pressure)); } if (libinput_tablet_tool_has_rotation(tool)) { rotation = libinput_event_tablet_tool_get_rotation(t); - delta = libinput_event_tablet_tool_get_axis_delta(t, - LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); - printf("\trotation: %.2f%s (%.2f)", - rotation, changed_sym(t, rotation), - delta); + printf("\trotation: %.2f%s", + rotation, changed_sym(t, rotation)); } if (libinput_tablet_tool_has_slider(tool)) { slider = libinput_event_tablet_tool_get_slider_position(t); - delta = libinput_event_tablet_tool_get_axis_delta(t, - LIBINPUT_TABLET_TOOL_AXIS_SLIDER); - printf("\tslider: %.2f%s (%.2f)", - slider, changed_sym(t, slider), - delta); + printf("\tslider: %.2f%s", + slider, changed_sym(t, slider)); } if (libinput_tablet_tool_has_wheel(tool)) { - wheel = libinput_event_tablet_tool_get_axis_delta(t, - LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); - delta = libinput_event_tablet_tool_get_axis_delta_discrete(t, - LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); + wheel = libinput_event_tablet_tool_get_wheel_delta(t); + delta = libinput_event_tablet_tool_get_wheel_delta_discrete(t); printf("\twheel: %.2f%s (%d)", wheel, changed_sym(t, wheel), (int)delta); From 8635ba556bd34a1b16353e8eb173b96b792719b0 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 14 Dec 2015 11:51:17 +1000 Subject: [PATCH 208/255] tablet: remove the libinput_tablet_tool_axis enum from the public API Internally we still use it, at least for now. Signed-off-by: Peter Hutterer Acked-by: Hans de Goede Reviewed-by: Lyude --- src/libinput-private.h | 16 ++++++++++++++-- src/libinput.h | 21 --------------------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/libinput-private.h b/src/libinput-private.h index f5b26483..1c8d97ce 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -33,8 +33,6 @@ #include "libinput.h" #include "libinput-util.h" -#define LIBINPUT_TABLET_TOOL_AXIS_MAX LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL - struct libinput_source; /* A coordinate pair in device coordinates */ @@ -250,6 +248,20 @@ struct libinput_device { struct libinput_device_config config; }; +enum libinput_tablet_tool_axis { + LIBINPUT_TABLET_TOOL_AXIS_X = 1, + LIBINPUT_TABLET_TOOL_AXIS_Y = 2, + LIBINPUT_TABLET_TOOL_AXIS_DISTANCE = 3, + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE = 4, + LIBINPUT_TABLET_TOOL_AXIS_TILT_X = 5, + LIBINPUT_TABLET_TOOL_AXIS_TILT_Y = 6, + LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z = 7, + LIBINPUT_TABLET_TOOL_AXIS_SLIDER = 8, + LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL = 9, +}; + +#define LIBINPUT_TABLET_TOOL_AXIS_MAX LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL + struct libinput_tablet_tool { struct list link; uint32_t serial; diff --git a/src/libinput.h b/src/libinput.h index 36911c81..73266a06 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -138,27 +138,6 @@ enum libinput_pointer_axis_source { * @ingroup device * @struct libinput_tablet_tool * - * Available axis types for a device. It must have the @ref - * LIBINPUT_DEVICE_CAP_TABLET_TOOL capability. - * - * For details on the interpretation of these axes see - * libinput_event_tablet_tool_get_axis_value(). - */ -enum libinput_tablet_tool_axis { - LIBINPUT_TABLET_TOOL_AXIS_X = 1, - LIBINPUT_TABLET_TOOL_AXIS_Y = 2, - LIBINPUT_TABLET_TOOL_AXIS_DISTANCE = 3, - LIBINPUT_TABLET_TOOL_AXIS_PRESSURE = 4, - LIBINPUT_TABLET_TOOL_AXIS_TILT_X = 5, - LIBINPUT_TABLET_TOOL_AXIS_TILT_Y = 6, - LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z = 7, - LIBINPUT_TABLET_TOOL_AXIS_SLIDER = 8, - LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL = 9, -}; - -/** - * @ingroup device - * * An object representing a tool being used by a device with the @ref * LIBINPUT_DEVICE_CAP_TABLET_TOOL capability. * From aaea4a63ec9494e93d99d816c774ea26571c1479 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 21 Dec 2015 09:01:57 +1000 Subject: [PATCH 209/255] tablet: add tilt tests Signed-off-by: Peter Hutterer --- test/litest-device-wacom-cintiq-tablet.c | 2 +- test/litest-device-wacom-intuos-tablet.c | 2 +- test/litest-device-waltop-tablet.c | 2 +- test/litest.h | 1 + test/tablet.c | 188 +++++++++++++++++++++++ 5 files changed, 192 insertions(+), 3 deletions(-) diff --git a/test/litest-device-wacom-cintiq-tablet.c b/test/litest-device-wacom-cintiq-tablet.c index 46fd2bbd..4685668d 100644 --- a/test/litest-device-wacom-cintiq-tablet.c +++ b/test/litest-device-wacom-cintiq-tablet.c @@ -146,7 +146,7 @@ static int events[] = { struct litest_test_device litest_wacom_cintiq_tablet_device = { .type = LITEST_WACOM_CINTIQ, - .features = LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_SERIAL, + .features = LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_SERIAL | LITEST_TILT, .shortname = "wacom-cintiq-tablet", .setup = litest_wacom_cintiq_tablet_setup, .interface = &interface, diff --git a/test/litest-device-wacom-intuos-tablet.c b/test/litest-device-wacom-intuos-tablet.c index e1c9e3de..b31f6a5c 100644 --- a/test/litest-device-wacom-intuos-tablet.c +++ b/test/litest-device-wacom-intuos-tablet.c @@ -151,7 +151,7 @@ static int events[] = { struct litest_test_device litest_wacom_intuos_tablet_device = { .type = LITEST_WACOM_INTUOS, - .features = LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_SERIAL, + .features = LITEST_TABLET | LITEST_DISTANCE | LITEST_TOOL_SERIAL | LITEST_TILT, .shortname = "wacom-intuos-tablet", .setup = litest_wacom_intuos_tablet_setup, .interface = &interface, diff --git a/test/litest-device-waltop-tablet.c b/test/litest-device-waltop-tablet.c index 206b831d..8b6de526 100644 --- a/test/litest-device-waltop-tablet.c +++ b/test/litest-device-waltop-tablet.c @@ -228,7 +228,7 @@ static int events[] = { struct litest_test_device litest_waltop_tablet_device = { .type = LITEST_WALTOP, - .features = LITEST_TABLET | LITEST_WHEEL, + .features = LITEST_TABLET | LITEST_WHEEL | LITEST_TILT, .shortname = "waltop-tablet", .setup = litest_waltop_tablet_setup, .interface = &interface, diff --git a/test/litest.h b/test/litest.h index 1d36ab9a..b58e45ea 100644 --- a/test/litest.h +++ b/test/litest.h @@ -175,6 +175,7 @@ enum litest_device_feature { LITEST_TABLET = 1 << 17, LITEST_DISTANCE = 1 << 18, LITEST_TOOL_SERIAL = 1 << 19, + LITEST_TILT = 1 << 20, }; struct litest_device { diff --git a/test/tablet.c b/test/tablet.c index 1afbb511..53cc5cbc 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -2611,6 +2611,190 @@ START_TEST(tablet_pressure_offset_none_for_small_distance) } END_TEST +START_TEST(tilt_available) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_tablet_tool *tev; + struct libinput_tablet_tool *tool; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 10 }, + { ABS_TILT_X, 80 }, + { ABS_TILT_Y, 20 }, + { -1, -1 } + }; + + litest_drain_events(li); + + litest_tablet_proximity_in(dev, 10, 10, axes); + libinput_dispatch(li); + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + + tool = libinput_event_tablet_tool_get_tool(tev); + ck_assert(libinput_tablet_tool_has_tilt(tool)); + + libinput_event_destroy(event); +} +END_TEST + +START_TEST(tilt_not_available) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_tablet_tool *tev; + struct libinput_tablet_tool *tool; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 10 }, + { ABS_TILT_X, 80 }, + { ABS_TILT_Y, 20 }, + { -1, -1 } + }; + + litest_drain_events(li); + + litest_tablet_proximity_in(dev, 10, 10, axes); + libinput_dispatch(li); + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + + tool = libinput_event_tablet_tool_get_tool(tev); + ck_assert(!libinput_tablet_tool_has_tilt(tool)); + + libinput_event_destroy(event); +} +END_TEST + +START_TEST(tilt_x) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_tablet_tool *tev; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 10 }, + { ABS_TILT_X, 90 }, + { ABS_TILT_Y, 0 }, + { -1, -1 } + }; + double tx, ty; + int tilt; + double expected_tx; + + litest_drain_events(li); + + litest_tablet_proximity_in(dev, 10, 10, axes); + libinput_dispatch(li); + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + + /* 90% of the actual axis but mapped into a [-1, 1] range, so we + * expect a pos. value of 80. Rounding errors in the scaling though, + * we'll get something between 0.79 and 0.80 */ + tx = libinput_event_tablet_tool_get_tilt_x(tev); + ck_assert_double_gt(tx, 0.79); + ck_assert_double_le(tx, 0.80); + + ty = libinput_event_tablet_tool_get_tilt_y(tev); + ck_assert_double_eq(ty, -1); + + libinput_event_destroy(event); + + expected_tx = -1.0; + + for (tilt = 0; tilt <= 100; tilt += 5) { + axes[1].value = tilt; + litest_tablet_motion(dev, 10, 10, axes); + libinput_dispatch(li); + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + + tx = libinput_event_tablet_tool_get_tilt_x(tev); + ck_assert_double_gt(tx, expected_tx - 0.1); + ck_assert_double_lt(tx, expected_tx + 0.1); + + ty = libinput_event_tablet_tool_get_tilt_y(tev); + ck_assert_double_eq(ty, -1); + + libinput_event_destroy(event); + + expected_tx += 0.1; + } + + /* the last event must reach the max */ + ck_assert_double_eq(tx, 1.0); +} +END_TEST + +START_TEST(tilt_y) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_tablet_tool *tev; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 10 }, + { ABS_TILT_X, 0 }, + { ABS_TILT_Y, 90 }, + { -1, -1 } + }; + double tx, ty; + int tilt; + double expected_ty; + + litest_drain_events(li); + + litest_tablet_proximity_in(dev, 10, 10, axes); + libinput_dispatch(li); + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + + /* 90% of the actual axis but mapped into a [-1, 1] range, so we + * expect a pos. value of 80. Rounding errors in the scaling though, + * we'll get something between 0.79 and 0.80 */ + ty = libinput_event_tablet_tool_get_tilt_y(tev); + ck_assert_double_gt(ty, 0.79); + ck_assert_double_le(ty, 0.80); + + tx = libinput_event_tablet_tool_get_tilt_x(tev); + ck_assert_double_eq(tx, -1); + + libinput_event_destroy(event); + + expected_ty = -1.0; + + for (tilt = 0; tilt <= 100; tilt += 5) { + axes[2].value = tilt; + litest_tablet_motion(dev, 10, 10, axes); + libinput_dispatch(li); + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + + ty = libinput_event_tablet_tool_get_tilt_y(tev); + ck_assert_double_gt(ty, expected_ty - 0.1); + ck_assert_double_lt(ty, expected_ty + 0.1); + + tx = libinput_event_tablet_tool_get_tilt_x(tev); + ck_assert_double_eq(tx, -1); + + libinput_event_destroy(event); + + expected_ty += 0.1; + } + + /* the last event must reach the max */ + ck_assert_double_eq(ty, 1.0); +} +END_TEST + void litest_setup_tests(void) { @@ -2638,6 +2822,10 @@ litest_setup_tests(void) litest_add("tablet:tip", tip_state_button, LITEST_TABLET, LITEST_ANY); litest_add("tablet:motion", motion, LITEST_TABLET, LITEST_ANY); litest_add("tablet:motion", motion_event_state, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:tilt", tilt_available, LITEST_TABLET|LITEST_TILT, LITEST_ANY); + litest_add("tablet:tilt", tilt_not_available, LITEST_TABLET, LITEST_TILT); + litest_add("tablet:tilt", tilt_x, LITEST_TABLET|LITEST_TILT, LITEST_ANY); + litest_add("tablet:tilt", tilt_y, LITEST_TABLET|LITEST_TILT, 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); From beee8403e9a4177979ef2bf3b36b7b8bb69719b1 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 21 Dec 2015 10:52:08 +1000 Subject: [PATCH 210/255] test: move litest_assert_ macros and helpers up to the rest of the defines Signed-off-by: Peter Hutterer --- test/litest.h | 80 +++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/test/litest.h b/test/litest.h index b58e45ea..edbfd7a8 100644 --- a/test/litest.h +++ b/test/litest.h @@ -35,6 +35,28 @@ #include #include +void +litest_fail_condition(const char *file, + int line, + const char *func, + const char *condition, + const char *message, + ...); +void +litest_fail_comparison_int(const char *file, + int line, + const char *func, + const char *operator, + int a, + int b, + const char *astr, + const char *bstr); +void +litest_fail_comparison_ptr(const char *file, + int line, + const char *func, + const char *comparison); + #define litest_assert(cond) \ do { \ if (!(cond)) \ @@ -111,6 +133,24 @@ #define litest_assert_ptr_notnull(a_) \ litest_assert_comparison_ptr_(a_, !=, NULL) +#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)) + enum litest_device_type { LITEST_NO_DEVICE = -1, LITEST_SYNAPTICS_CLICKPAD = -2, @@ -211,28 +251,6 @@ struct libinput *litest_create_context(void); void litest_disable_log_handler(struct libinput *libinput); void litest_restore_log_handler(struct libinput *libinput); -void -litest_fail_condition(const char *file, - int line, - const char *func, - const char *condition, - const char *message, - ...); -void -litest_fail_comparison_int(const char *file, - int line, - const char *func, - const char *operator, - int a, - int b, - const char *astr, - const char *bstr); -void -litest_fail_comparison_ptr(const char *file, - int line, - const char *func, - const char *comparison); - #define litest_add(name_, func_, ...) \ _litest_add(name_, #func_, func_, __VA_ARGS__) #define litest_add_ranged(name_, func_, ...) \ @@ -429,24 +447,6 @@ 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); void litest_timeout_softbuttons(void); From aaac47d442e3321f818985588430a2856a996eac Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 21 Dec 2015 10:53:29 +1000 Subject: [PATCH 211/255] test: add litest_axis_set_value helper function Signed-off-by: Peter Hutterer --- test/litest.h | 18 ++++++++++++++++++ test/tablet.c | 50 +++++++++++++++++++++++++------------------------- 2 files changed, 43 insertions(+), 25 deletions(-) diff --git a/test/litest.h b/test/litest.h index edbfd7a8..89377906 100644 --- a/test/litest.h +++ b/test/litest.h @@ -239,6 +239,24 @@ struct axis_replacement { double value; }; +static inline void litest_axis_set_value(struct axis_replacement *axes, + int code, + double value) +{ + litest_assert_double_ge(value, 0.0); + litest_assert_double_le(value, 100.0); + + while (axes->evcode != -1) { + if (axes->evcode == code) { + axes->value = value; + return; + } + axes++; + } + + litest_abort_msg("Missing axis code %d\n", code); +} + /* A loop range, resolves to: for (i = lower; i < upper; i++) */ diff --git a/test/tablet.c b/test/tablet.c index 53cc5cbc..456b0473 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -746,9 +746,9 @@ START_TEST(proximity_has_axes) litest_assert_empty_queue(li); libinput_event_destroy(event); - axes[0].value = 20; - axes[1].value = 15; - axes[2].value = 25; + litest_axis_set_value(axes, ABS_DISTANCE, 20); + litest_axis_set_value(axes, ABS_TILT_X, 15); + litest_axis_set_value(axes, ABS_TILT_Y, 25); litest_tablet_motion(dev, 20, 30, axes); libinput_dispatch(li); litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, -1); @@ -2119,8 +2119,8 @@ START_TEST(tablet_pressure_distance_exclusive) libinput_event_destroy(event); - axes[0].value = 15; - axes[1].value = 25; + litest_axis_set_value(axes, ABS_DISTANCE, 15); + litest_axis_set_value(axes, ABS_PRESSURE, 25); litest_event(dev, EV_KEY, BTN_TOUCH, 1); litest_tablet_motion(dev, 30, 30, axes); libinput_dispatch(li); @@ -2333,8 +2333,8 @@ START_TEST(tablet_pressure_offset) litest_tablet_proximity_in(dev, 5, 100, axes); litest_drain_events(li); - axes[0].value = 0; - axes[1].value = 21; + litest_axis_set_value(axes, ABS_DISTANCE, 0); + litest_axis_set_value(axes, ABS_PRESSURE, 21); litest_push_event_frame(dev); litest_tablet_motion(dev, 70, 70, axes); litest_event(dev, EV_KEY, BTN_TOUCH, 1); @@ -2342,7 +2342,7 @@ START_TEST(tablet_pressure_offset) libinput_dispatch(li); litest_drain_events(li); - axes[1].value = 20; + litest_axis_set_value(axes, ABS_PRESSURE, 20); litest_tablet_motion(dev, 70, 70, axes); libinput_dispatch(li); @@ -2355,7 +2355,7 @@ START_TEST(tablet_pressure_offset) libinput_event_destroy(event); litest_drain_events(li); - axes[1].value = 21; + litest_axis_set_value(axes, ABS_PRESSURE, 21); litest_tablet_motion(dev, 70, 70, axes); libinput_dispatch(li); @@ -2390,8 +2390,8 @@ START_TEST(tablet_pressure_offset_decrease) litest_drain_events(li); /* a reduced pressure value must reduce the offset */ - axes[0].value = 0; - axes[1].value = 10; + litest_axis_set_value(axes, ABS_DISTANCE, 0); + litest_axis_set_value(axes, ABS_PRESSURE, 10); litest_push_event_frame(dev); litest_tablet_motion(dev, 70, 70, axes); litest_event(dev, EV_KEY, BTN_TOUCH, 1); @@ -2407,7 +2407,7 @@ START_TEST(tablet_pressure_offset_decrease) libinput_event_destroy(event); litest_drain_events(li); - axes[1].value = 11; + litest_axis_set_value(axes, ABS_PRESSURE, 11); litest_tablet_motion(dev, 70, 70, axes); libinput_dispatch(li); @@ -2443,12 +2443,12 @@ START_TEST(tablet_pressure_offset_increase) litest_drain_events(li); /* offset 30 on second prox in - must not change the offset */ - axes[1].value = 30; + litest_axis_set_value(axes, ABS_PRESSURE, 30); litest_tablet_proximity_in(dev, 5, 100, axes); litest_drain_events(li); - axes[0].value = 0; - axes[1].value = 31; + litest_axis_set_value(axes, ABS_DISTANCE, 0); + litest_axis_set_value(axes, ABS_PRESSURE, 31); litest_push_event_frame(dev); litest_tablet_motion(dev, 70, 70, axes); litest_event(dev, EV_KEY, BTN_TOUCH, 1); @@ -2456,7 +2456,7 @@ START_TEST(tablet_pressure_offset_increase) libinput_dispatch(li); litest_drain_events(li); - axes[1].value = 30; + litest_axis_set_value(axes, ABS_PRESSURE, 30); litest_tablet_motion(dev, 70, 70, axes); libinput_dispatch(li); @@ -2471,7 +2471,7 @@ START_TEST(tablet_pressure_offset_increase) litest_drain_events(li); - axes[1].value = 20; + litest_axis_set_value(axes, ABS_PRESSURE, 20); litest_tablet_motion(dev, 70, 70, axes); libinput_dispatch(li); @@ -2512,8 +2512,8 @@ START_TEST(tablet_pressure_offset_exceed_threshold) libinput_event_destroy(event); litest_restore_log_handler(li); - axes[0].value = 0; - axes[1].value = 31; + litest_axis_set_value(axes, ABS_DISTANCE, 0); + litest_axis_set_value(axes, ABS_PRESSURE, 31); litest_push_event_frame(dev); litest_tablet_motion(dev, 70, 70, axes); litest_event(dev, EV_KEY, BTN_TOUCH, 1); @@ -2521,7 +2521,7 @@ START_TEST(tablet_pressure_offset_exceed_threshold) libinput_dispatch(li); litest_drain_events(li); - axes[1].value = 30; + litest_axis_set_value(axes, ABS_PRESSURE, 30); litest_tablet_motion(dev, 70, 70, axes); libinput_dispatch(li); @@ -2587,15 +2587,15 @@ START_TEST(tablet_pressure_offset_none_for_small_distance) litest_drain_events(li); libinput_dispatch(li); - axes[0].value = 0; - axes[1].value = 21; + litest_axis_set_value(axes, ABS_DISTANCE, 0); + litest_axis_set_value(axes, ABS_PRESSURE, 21); litest_push_event_frame(dev); litest_tablet_motion(dev, 70, 70, axes); litest_event(dev, EV_KEY, BTN_TOUCH, 1); litest_pop_event_frame(dev); litest_drain_events(li); - axes[1].value = 20; + litest_axis_set_value(axes, ABS_PRESSURE, 20); litest_tablet_motion(dev, 70, 70, axes); libinput_dispatch(li); @@ -2708,7 +2708,7 @@ START_TEST(tilt_x) expected_tx = -1.0; for (tilt = 0; tilt <= 100; tilt += 5) { - axes[1].value = tilt; + litest_axis_set_value(axes, ABS_TILT_X, tilt); litest_tablet_motion(dev, 10, 10, axes); libinput_dispatch(li); event = libinput_get_event(li); @@ -2771,7 +2771,7 @@ START_TEST(tilt_y) expected_ty = -1.0; for (tilt = 0; tilt <= 100; tilt += 5) { - axes[2].value = tilt; + litest_axis_set_value(axes, ABS_TILT_Y, tilt); litest_tablet_motion(dev, 10, 10, axes); libinput_dispatch(li); event = libinput_get_event(li); From d5e18a8e64be7fb936731b1caf9823b45fd0d695 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 14 Dec 2015 15:09:28 +1000 Subject: [PATCH 212/255] tablet: dump deltas_discrete, replace with a single wheel_discrete variable Only the wheel has a discrete value, no need to keep arrays for a single value. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 6 +++--- src/libinput-private.h | 2 +- src/libinput.c | 10 ++++------ 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index ffb141c4..83cf433b 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -337,7 +337,7 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, int a; double axes[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1] = {0}; double deltas[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1] = {0}; - double deltas_discrete[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1] = {0}; + int wheel_discrete = 0; double oldval; struct device_coords point, old_point; const struct input_absinfo *absinfo; @@ -400,7 +400,7 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, deltas[a] = get_delta(a, tablet->axes[a], oldval); continue; } else if (a == LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL) { - deltas_discrete[a] = tablet->deltas[a]; + wheel_discrete = tablet->deltas[a]; deltas[a] = normalize_wheel(tablet, tablet->deltas[a]); axes[a] = 0; @@ -468,7 +468,7 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, tablet->changed_axes, axes, deltas, - deltas_discrete); + wheel_discrete); } } diff --git a/src/libinput-private.h b/src/libinput-private.h index 1c8d97ce..b404b0ad 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -482,7 +482,7 @@ tablet_notify_axis(struct libinput_device *device, unsigned char *changed_axes, double *axes, double *deltas, - double *deltas_discrete); + int wheel_discrete); void tablet_notify_proximity(struct libinput_device *device, diff --git a/src/libinput.c b/src/libinput.c index b1bced06..e5b21805 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -133,7 +133,7 @@ struct libinput_event_tablet_tool { uint64_t time; double axes[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1]; double deltas[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1]; - double deltas_discrete[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1]; + int wheel_discrete; unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_TOOL_AXIS_MAX + 1)]; struct libinput_tablet_tool *tool; enum libinput_tablet_tool_proximity_state proximity_state; @@ -1161,7 +1161,7 @@ libinput_event_tablet_tool_get_wheel_delta_discrete( LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); - return event->deltas_discrete[LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL]; + return event->wheel_discrete; } LIBINPUT_EXPORT double @@ -2153,7 +2153,7 @@ tablet_notify_axis(struct libinput_device *device, unsigned char *changed_axes, double *axes, double *deltas, - double *deltas_discrete) + int wheel_discrete) { struct libinput_event_tablet_tool *axis_event; @@ -2166,6 +2166,7 @@ tablet_notify_axis(struct libinput_device *device, .tool = tool, .proximity_state = LIBINPUT_TABLET_TOOL_PROXIMITY_IN, .tip_state = tip_state, + .wheel_discrete = wheel_discrete, }; memcpy(axis_event->changed_axes, @@ -2173,9 +2174,6 @@ tablet_notify_axis(struct libinput_device *device, sizeof(axis_event->changed_axes)); memcpy(axis_event->axes, axes, sizeof(axis_event->axes)); memcpy(axis_event->deltas, deltas, sizeof(axis_event->deltas)); - memcpy(axis_event->deltas_discrete, - deltas_discrete, - sizeof(axis_event->deltas_discrete)); post_device_event(device, time, From 9fd0fb0df830fa1aa26d47547f881b404fcdddb9 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 14 Dec 2015 15:14:24 +1000 Subject: [PATCH 213/255] tablet: dump deltas, replace it with a single wheel_delta variable The wheel is the only one axis that has actual deltas, all others have straightforward deltas that we don't need to care about, the caller can calculate those where needed. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 56 +++--------------------------------------- src/libinput-private.h | 2 +- src/libinput.c | 8 +++--- 3 files changed, 9 insertions(+), 57 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 83cf433b..40a8bcc1 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -284,48 +284,6 @@ normalize_wheel(struct tablet_dispatch *tablet, 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_tool_axis axis, double current, double old) -{ - double delta = 0; - - switch (axis) { - case LIBINPUT_TABLET_TOOL_AXIS_X: - case LIBINPUT_TABLET_TOOL_AXIS_Y: - case LIBINPUT_TABLET_TOOL_AXIS_DISTANCE: - case LIBINPUT_TABLET_TOOL_AXIS_PRESSURE: - case LIBINPUT_TABLET_TOOL_AXIS_SLIDER: - case LIBINPUT_TABLET_TOOL_AXIS_TILT_X: - case LIBINPUT_TABLET_TOOL_AXIS_TILT_Y: - delta = current - old; - break; - case LIBINPUT_TABLET_TOOL_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, @@ -336,9 +294,8 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, bool axis_update_needed = false; int a; double axes[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1] = {0}; - double deltas[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1] = {0}; + double wheel_delta = 0; int wheel_discrete = 0; - double oldval; struct device_coords point, old_point; const struct input_absinfo *absinfo; @@ -376,8 +333,6 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, axes[LIBINPUT_TABLET_TOOL_AXIS_X] = point.x; axes[LIBINPUT_TABLET_TOOL_AXIS_Y] = point.y; - deltas[LIBINPUT_TABLET_TOOL_AXIS_X] = point.x - old_point.x; - deltas[LIBINPUT_TABLET_TOOL_AXIS_Y] = point.y - old_point.y; for (a = LIBINPUT_TABLET_TOOL_AXIS_DISTANCE; a <= LIBINPUT_TABLET_TOOL_AXIS_MAX; a++) { if (!bit_is_set(tablet->changed_axes, a)) { @@ -386,7 +341,6 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, } 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 */ @@ -397,12 +351,11 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, axes[LIBINPUT_TABLET_TOOL_AXIS_TILT_X] = 0; axes[LIBINPUT_TABLET_TOOL_AXIS_TILT_Y] = 0; axes[a] = tablet->axes[a]; - deltas[a] = get_delta(a, tablet->axes[a], oldval); continue; } else if (a == LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL) { wheel_discrete = tablet->deltas[a]; - deltas[a] = normalize_wheel(tablet, - tablet->deltas[a]); + wheel_delta = normalize_wheel(tablet, + tablet->deltas[a]); axes[a] = 0; continue; } @@ -433,7 +386,6 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, } 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 @@ -467,7 +419,7 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, tip_state, tablet->changed_axes, axes, - deltas, + wheel_delta, wheel_discrete); } } diff --git a/src/libinput-private.h b/src/libinput-private.h index b404b0ad..1f4dab6c 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -481,7 +481,7 @@ tablet_notify_axis(struct libinput_device *device, enum libinput_tablet_tool_tip_state tip_state, unsigned char *changed_axes, double *axes, - double *deltas, + double wheel_delta, int wheel_discrete); void diff --git a/src/libinput.c b/src/libinput.c index e5b21805..aff8dd27 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -132,7 +132,7 @@ struct libinput_event_tablet_tool { uint32_t seat_button_count; uint64_t time; double axes[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1]; - double deltas[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1]; + double wheel_delta; int wheel_discrete; unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_TOOL_AXIS_MAX + 1)]; struct libinput_tablet_tool *tool; @@ -1147,7 +1147,7 @@ libinput_event_tablet_tool_get_wheel_delta(struct libinput_event_tablet_tool *ev LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); - return event->deltas[LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL]; + return event->wheel_delta; } LIBINPUT_EXPORT int @@ -2152,7 +2152,7 @@ tablet_notify_axis(struct libinput_device *device, enum libinput_tablet_tool_tip_state tip_state, unsigned char *changed_axes, double *axes, - double *deltas, + double wheel_delta, int wheel_discrete) { struct libinput_event_tablet_tool *axis_event; @@ -2167,13 +2167,13 @@ tablet_notify_axis(struct libinput_device *device, .proximity_state = LIBINPUT_TABLET_TOOL_PROXIMITY_IN, .tip_state = tip_state, .wheel_discrete = wheel_discrete, + .wheel_delta = wheel_delta, }; 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)); post_device_event(device, time, From ea07cbcd891c1518e6569f22fdcfae3e80253668 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 14 Dec 2015 15:36:22 +1000 Subject: [PATCH 214/255] tablet: unroll the tablet axis processing loop Process the axes explicitly, rather than having a loop that needs special casing for most axes anyway. And since we do the axes one-by-one, we can use the evdev axis code directly rather than the axis_to_evcode helper. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 109 ++++++++++++++++++++++++++------------------- 1 file changed, 62 insertions(+), 47 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 40a8bcc1..ead159e8 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -303,8 +303,7 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, a = LIBINPUT_TABLET_TOOL_AXIS_X; old_point.x = tablet->axes[a]; if (bit_is_set(tablet->changed_axes, a)) { - absinfo = libevdev_get_abs_info(device->evdev, - axis_to_evcode(a)); + absinfo = libevdev_get_abs_info(device->evdev, ABS_X); axis_update_needed = true; if (device->left_handed.enabled) @@ -317,8 +316,8 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, a = LIBINPUT_TABLET_TOOL_AXIS_Y; old_point.y = tablet->axes[a]; if (bit_is_set(tablet->changed_axes, a)) { - absinfo = libevdev_get_abs_info(device->evdev, - axis_to_evcode(a)); + absinfo = libevdev_get_abs_info(device->evdev, ABS_Y); + axis_update_needed = true; if (device->left_handed.enabled) @@ -334,59 +333,75 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, axes[LIBINPUT_TABLET_TOOL_AXIS_X] = point.x; axes[LIBINPUT_TABLET_TOOL_AXIS_Y] = point.y; - for (a = LIBINPUT_TABLET_TOOL_AXIS_DISTANCE; a <= LIBINPUT_TABLET_TOOL_AXIS_MAX; a++) { - if (!bit_is_set(tablet->changed_axes, a)) { - axes[a] = tablet->axes[a]; - continue; - } - + a = LIBINPUT_TABLET_TOOL_AXIS_PRESSURE; + if (bit_is_set(tablet->changed_axes, a)) { axis_update_needed = true; + absinfo = libevdev_get_abs_info(device->evdev, ABS_PRESSURE); + tablet->axes[a] = normalize_pressure(absinfo, tool); + } + axes[a] = 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_TOOL_AXIS_ROTATION_Z && - (tablet->current_tool_type == LIBINPUT_TABLET_TOOL_TYPE_MOUSE || - tablet->current_tool_type == LIBINPUT_TABLET_TOOL_TYPE_LENS)) { + a = LIBINPUT_TABLET_TOOL_AXIS_DISTANCE; + if (bit_is_set(tablet->changed_axes, a)) { + axis_update_needed = true; + absinfo = libevdev_get_abs_info(device->evdev, ABS_DISTANCE); + tablet->axes[a] = normalize_dist_slider(absinfo); + } + axes[a] = tablet->axes[a]; + + a = LIBINPUT_TABLET_TOOL_AXIS_SLIDER; + if (bit_is_set(tablet->changed_axes, a)) { + axis_update_needed = true; + absinfo = libevdev_get_abs_info(device->evdev, ABS_WHEEL); + tablet->axes[a] = normalize_dist_slider(absinfo); + } + axes[a] = tablet->axes[a]; + + a = LIBINPUT_TABLET_TOOL_AXIS_TILT_X; + if (bit_is_set(tablet->changed_axes, a)) { + axis_update_needed = true; + absinfo = libevdev_get_abs_info(device->evdev, ABS_TILT_X); + tablet->axes[a] = normalize_tilt(absinfo); + } + axes[a] = tablet->axes[a]; + + a = LIBINPUT_TABLET_TOOL_AXIS_TILT_Y; + if (bit_is_set(tablet->changed_axes, a)) { + axis_update_needed = true; + absinfo = libevdev_get_abs_info(device->evdev, ABS_TILT_Y); + tablet->axes[a] = normalize_tilt(absinfo); + } + axes[a] = tablet->axes[a]; + + /* We must check ROTATION_Z after TILT_X/Y so that the tilt axes are + * already normalized and set if we have the mouse/lens tool */ + a = LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z; + if (bit_is_set(tablet->changed_axes, a)) { + if (tablet->current_tool_type == LIBINPUT_TABLET_TOOL_TYPE_MOUSE || + tablet->current_tool_type == LIBINPUT_TABLET_TOOL_TYPE_LENS) { convert_tilt_to_rotation(tablet); axes[LIBINPUT_TABLET_TOOL_AXIS_TILT_X] = 0; axes[LIBINPUT_TABLET_TOOL_AXIS_TILT_Y] = 0; - axes[a] = tablet->axes[a]; - continue; - } else if (a == LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL) { - wheel_discrete = tablet->deltas[a]; - wheel_delta = 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_TOOL_AXIS_PRESSURE: - tablet->axes[a] = normalize_pressure(absinfo, tool); - break; - case LIBINPUT_TABLET_TOOL_AXIS_DISTANCE: - case LIBINPUT_TABLET_TOOL_AXIS_SLIDER: - tablet->axes[a] = normalize_dist_slider(absinfo); - break; - case LIBINPUT_TABLET_TOOL_AXIS_TILT_X: - case LIBINPUT_TABLET_TOOL_AXIS_TILT_Y: - tablet->axes[a] = normalize_tilt(absinfo); - break; - case LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z: + } else { + absinfo = libevdev_get_abs_info(device->evdev, + ABS_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]; + axis_update_needed = true; } + axes[a] = tablet->axes[a]; + + a = LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL; + if (bit_is_set(tablet->changed_axes, a)) { + axis_update_needed = true; + wheel_discrete = tablet->deltas[a]; + wheel_delta = normalize_wheel(tablet, + tablet->deltas[a]); + axes[a] = 0; + } + axes[a] = tablet->axes[a]; /* 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 From c8a99cdf106ae6e1fd10ea8d72ca3fcd3ba6d11b Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 14 Dec 2015 15:59:05 +1000 Subject: [PATCH 215/255] tablet: simplify check for testing if an axis update is needed We know when one of the bits is set we need to send an event Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index ead159e8..a46a9728 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -298,6 +298,13 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, int wheel_discrete = 0; struct device_coords point, old_point; const struct input_absinfo *absinfo; + const char tmp[sizeof(tablet->changed_axes)] = {0}; + + if (memcmp(tmp, tablet->changed_axes, sizeof(tmp))) + axis_update_needed = true; + + if (!axis_update_needed) + return; /* x/y are special for left-handed and calibration */ a = LIBINPUT_TABLET_TOOL_AXIS_X; @@ -305,7 +312,6 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, if (bit_is_set(tablet->changed_axes, a)) { absinfo = libevdev_get_abs_info(device->evdev, ABS_X); - axis_update_needed = true; if (device->left_handed.enabled) tablet->axes[a] = invert_axis(absinfo); else @@ -318,8 +324,6 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, if (bit_is_set(tablet->changed_axes, a)) { absinfo = libevdev_get_abs_info(device->evdev, ABS_Y); - axis_update_needed = true; - if (device->left_handed.enabled) tablet->axes[a] = invert_axis(absinfo); else @@ -335,7 +339,6 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, a = LIBINPUT_TABLET_TOOL_AXIS_PRESSURE; if (bit_is_set(tablet->changed_axes, a)) { - axis_update_needed = true; absinfo = libevdev_get_abs_info(device->evdev, ABS_PRESSURE); tablet->axes[a] = normalize_pressure(absinfo, tool); } @@ -343,7 +346,6 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, a = LIBINPUT_TABLET_TOOL_AXIS_DISTANCE; if (bit_is_set(tablet->changed_axes, a)) { - axis_update_needed = true; absinfo = libevdev_get_abs_info(device->evdev, ABS_DISTANCE); tablet->axes[a] = normalize_dist_slider(absinfo); } @@ -351,7 +353,6 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, a = LIBINPUT_TABLET_TOOL_AXIS_SLIDER; if (bit_is_set(tablet->changed_axes, a)) { - axis_update_needed = true; absinfo = libevdev_get_abs_info(device->evdev, ABS_WHEEL); tablet->axes[a] = normalize_dist_slider(absinfo); } @@ -359,7 +360,6 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, a = LIBINPUT_TABLET_TOOL_AXIS_TILT_X; if (bit_is_set(tablet->changed_axes, a)) { - axis_update_needed = true; absinfo = libevdev_get_abs_info(device->evdev, ABS_TILT_X); tablet->axes[a] = normalize_tilt(absinfo); } @@ -367,7 +367,6 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, a = LIBINPUT_TABLET_TOOL_AXIS_TILT_Y; if (bit_is_set(tablet->changed_axes, a)) { - axis_update_needed = true; absinfo = libevdev_get_abs_info(device->evdev, ABS_TILT_Y); tablet->axes[a] = normalize_tilt(absinfo); } @@ -389,13 +388,11 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, /* artpen has 0 with buttons pointing east */ tablet->axes[a] = convert_to_degrees(absinfo, 90); } - axis_update_needed = true; } axes[a] = tablet->axes[a]; a = LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL; if (bit_is_set(tablet->changed_axes, a)) { - axis_update_needed = true; wheel_discrete = tablet->deltas[a]; wheel_delta = normalize_wheel(tablet, tablet->deltas[a]); @@ -408,8 +405,7 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, * 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) && + if (!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)) { From 67220c643ff7aa968d7dd1fc25b5ad5900b4de7d Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 21 Dec 2015 14:56:41 +1000 Subject: [PATCH 216/255] tablet: simplify check for testing if an axis update is needed We know when one of the bits is set we need to send an event Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index a46a9728..56ade1c6 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -291,7 +291,6 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, struct libinput_tablet_tool *tool) { struct libinput_device *base = &device->base; - bool axis_update_needed = false; int a; double axes[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1] = {0}; double wheel_delta = 0; @@ -300,10 +299,7 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, const struct input_absinfo *absinfo; const char tmp[sizeof(tablet->changed_axes)] = {0}; - if (memcmp(tmp, tablet->changed_axes, sizeof(tmp))) - axis_update_needed = true; - - if (!axis_update_needed) + if (memcmp(tmp, tablet->changed_axes, sizeof(tmp)) == 0) return; /* x/y are special for left-handed and calibration */ From fa71278c19847af31066039296b56662d8f888d4 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 14 Dec 2015 16:25:22 +1000 Subject: [PATCH 217/255] tablet: store the wheel delta in the normal axes Now that we don't provide an API anymore to access the absolute value of the wheel and the axes are handled separately, we can safely store the wheel delta in the normal axis array. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 9 ++++----- src/libinput-private.h | 1 - src/libinput.c | 5 ++--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 56ade1c6..e1757796 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -293,7 +293,6 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, struct libinput_device *base = &device->base; int a; double axes[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1] = {0}; - double wheel_delta = 0; int wheel_discrete = 0; struct device_coords point, old_point; const struct input_absinfo *absinfo; @@ -390,9 +389,10 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, a = LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL; if (bit_is_set(tablet->changed_axes, a)) { wheel_discrete = tablet->deltas[a]; - wheel_delta = normalize_wheel(tablet, - tablet->deltas[a]); - axes[a] = 0; + tablet->axes[a] = normalize_wheel(tablet, + tablet->deltas[a]); + } else { + tablet->axes[a] = 0; } axes[a] = tablet->axes[a]; @@ -426,7 +426,6 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, tip_state, tablet->changed_axes, axes, - wheel_delta, wheel_discrete); } } diff --git a/src/libinput-private.h b/src/libinput-private.h index 1f4dab6c..4e0f7f43 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -481,7 +481,6 @@ tablet_notify_axis(struct libinput_device *device, enum libinput_tablet_tool_tip_state tip_state, unsigned char *changed_axes, double *axes, - double wheel_delta, int wheel_discrete); void diff --git a/src/libinput.c b/src/libinput.c index aff8dd27..093f3186 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1147,7 +1147,8 @@ libinput_event_tablet_tool_get_wheel_delta(struct libinput_event_tablet_tool *ev LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); - return event->wheel_delta; + return libinput_event_tablet_tool_get_axis_value(event, + LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); } LIBINPUT_EXPORT int @@ -2152,7 +2153,6 @@ tablet_notify_axis(struct libinput_device *device, enum libinput_tablet_tool_tip_state tip_state, unsigned char *changed_axes, double *axes, - double wheel_delta, int wheel_discrete) { struct libinput_event_tablet_tool *axis_event; @@ -2167,7 +2167,6 @@ tablet_notify_axis(struct libinput_device *device, .proximity_state = LIBINPUT_TABLET_TOOL_PROXIMITY_IN, .tip_state = tip_state, .wheel_discrete = wheel_discrete, - .wheel_delta = wheel_delta, }; memcpy(axis_event->changed_axes, From 53ac112d6cb124fa05c4eb90d2da0e8db31bae73 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 14 Dec 2015 16:28:07 +1000 Subject: [PATCH 218/255] tablet: split out axis handling into helper functions Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 184 +++++++++++++++++++++++++++++++---------- src/libinput-private.h | 5 ++ 2 files changed, 147 insertions(+), 42 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index e1757796..5ea7f4d5 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -284,26 +284,15 @@ normalize_wheel(struct tablet_dispatch *tablet, return value * device->scroll.wheel_click_angle; } -static void -tablet_check_notify_axes(struct tablet_dispatch *tablet, - struct evdev_device *device, - uint64_t time, - struct libinput_tablet_tool *tool) +static inline struct device_coords +tablet_handle_xy(struct tablet_dispatch *tablet, + struct evdev_device *device) { - struct libinput_device *base = &device->base; - int a; - double axes[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1] = {0}; - int wheel_discrete = 0; - struct device_coords point, old_point; + struct device_coords point; const struct input_absinfo *absinfo; - const char tmp[sizeof(tablet->changed_axes)] = {0}; + int a; - if (memcmp(tmp, tablet->changed_axes, sizeof(tmp)) == 0) - return; - - /* x/y are special for left-handed and calibration */ a = LIBINPUT_TABLET_TOOL_AXIS_X; - old_point.x = tablet->axes[a]; if (bit_is_set(tablet->changed_axes, a)) { absinfo = libevdev_get_abs_info(device->evdev, ABS_X); @@ -315,7 +304,6 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, point.x = tablet->axes[a]; a = LIBINPUT_TABLET_TOOL_AXIS_Y; - old_point.y = tablet->axes[a]; if (bit_is_set(tablet->changed_axes, a)) { absinfo = libevdev_get_abs_info(device->evdev, ABS_Y); @@ -327,74 +315,186 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, point.y = tablet->axes[a]; evdev_transform_absolute(device, &point); - evdev_transform_absolute(device, &old_point); - axes[LIBINPUT_TABLET_TOOL_AXIS_X] = point.x; - axes[LIBINPUT_TABLET_TOOL_AXIS_Y] = point.y; + return point; +} + +static inline double +tablet_handle_pressure(struct tablet_dispatch *tablet, + struct evdev_device *device, + struct libinput_tablet_tool *tool) +{ + const struct input_absinfo *absinfo; + int a; a = LIBINPUT_TABLET_TOOL_AXIS_PRESSURE; if (bit_is_set(tablet->changed_axes, a)) { absinfo = libevdev_get_abs_info(device->evdev, ABS_PRESSURE); tablet->axes[a] = normalize_pressure(absinfo, tool); } - axes[a] = tablet->axes[a]; + + return tablet->axes[a]; +} + +static inline double +tablet_handle_distance(struct tablet_dispatch *tablet, + struct evdev_device *device) +{ + const struct input_absinfo *absinfo; + int a; a = LIBINPUT_TABLET_TOOL_AXIS_DISTANCE; if (bit_is_set(tablet->changed_axes, a)) { absinfo = libevdev_get_abs_info(device->evdev, ABS_DISTANCE); tablet->axes[a] = normalize_dist_slider(absinfo); } - axes[a] = tablet->axes[a]; + + return tablet->axes[a]; +} + +static inline double +tablet_handle_slider(struct tablet_dispatch *tablet, + struct evdev_device *device) +{ + const struct input_absinfo *absinfo; + int a; a = LIBINPUT_TABLET_TOOL_AXIS_SLIDER; if (bit_is_set(tablet->changed_axes, a)) { absinfo = libevdev_get_abs_info(device->evdev, ABS_WHEEL); tablet->axes[a] = normalize_dist_slider(absinfo); } - axes[a] = tablet->axes[a]; + + return tablet->axes[a]; +} + +static inline struct normalized_range_coords +tablet_handle_tilt(struct tablet_dispatch *tablet, + struct evdev_device *device) +{ + struct normalized_range_coords tilt; + const struct input_absinfo *absinfo; + int a; a = LIBINPUT_TABLET_TOOL_AXIS_TILT_X; if (bit_is_set(tablet->changed_axes, a)) { absinfo = libevdev_get_abs_info(device->evdev, ABS_TILT_X); tablet->axes[a] = normalize_tilt(absinfo); } - axes[a] = tablet->axes[a]; + tilt.x = tablet->axes[a]; a = LIBINPUT_TABLET_TOOL_AXIS_TILT_Y; if (bit_is_set(tablet->changed_axes, a)) { absinfo = libevdev_get_abs_info(device->evdev, ABS_TILT_Y); tablet->axes[a] = normalize_tilt(absinfo); } - axes[a] = tablet->axes[a]; + tilt.y = tablet->axes[a]; + + return tilt; +} + +static inline double +tablet_handle_artpen_rotation(struct tablet_dispatch *tablet, + struct evdev_device *device) +{ + const struct input_absinfo *absinfo; + int a; - /* We must check ROTATION_Z after TILT_X/Y so that the tilt axes are - * already normalized and set if we have the mouse/lens tool */ a = LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z; if (bit_is_set(tablet->changed_axes, a)) { - if (tablet->current_tool_type == LIBINPUT_TABLET_TOOL_TYPE_MOUSE || - tablet->current_tool_type == LIBINPUT_TABLET_TOOL_TYPE_LENS) { - convert_tilt_to_rotation(tablet); - axes[LIBINPUT_TABLET_TOOL_AXIS_TILT_X] = 0; - axes[LIBINPUT_TABLET_TOOL_AXIS_TILT_Y] = 0; - - } else { - absinfo = libevdev_get_abs_info(device->evdev, - ABS_Z); - /* artpen has 0 with buttons pointing east */ - tablet->axes[a] = convert_to_degrees(absinfo, 90); - } + absinfo = libevdev_get_abs_info(device->evdev, + ABS_Z); + /* artpen has 0 with buttons pointing east */ + tablet->axes[a] = convert_to_degrees(absinfo, 90); } - axes[a] = tablet->axes[a]; + + return tablet->axes[a]; +} + +static inline double +tablet_handle_mouse_rotation(struct tablet_dispatch *tablet, + struct evdev_device *device) +{ + int a; + + a = LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z; + if (bit_is_set(tablet->changed_axes, + LIBINPUT_TABLET_TOOL_AXIS_TILT_X) || + bit_is_set(tablet->changed_axes, + LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { + convert_tilt_to_rotation(tablet); + } + + return tablet->axes[a]; +} + +static inline double +tablet_handle_wheel(struct tablet_dispatch *tablet, + struct evdev_device *device, + int *wheel_discrete) +{ + int a; a = LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL; if (bit_is_set(tablet->changed_axes, a)) { - wheel_discrete = tablet->deltas[a]; + *wheel_discrete = tablet->deltas[a]; tablet->axes[a] = normalize_wheel(tablet, tablet->deltas[a]); } else { tablet->axes[a] = 0; + *wheel_discrete = 0; } - axes[a] = tablet->axes[a]; + + return tablet->axes[a]; +} + +static void +tablet_check_notify_axes(struct tablet_dispatch *tablet, + struct evdev_device *device, + uint64_t time, + struct libinput_tablet_tool *tool) +{ + struct libinput_device *base = &device->base; + double axes[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1] = {0}; + int wheel_discrete = 0; + struct device_coords point; + struct normalized_range_coords tilt; + const char tmp[sizeof(tablet->changed_axes)] = {0}; + + if (memcmp(tmp, tablet->changed_axes, sizeof(tmp)) == 0) + return; + + point = tablet_handle_xy(tablet, device); + axes[LIBINPUT_TABLET_TOOL_AXIS_X] = point.x; + axes[LIBINPUT_TABLET_TOOL_AXIS_Y] = point.y; + + axes[LIBINPUT_TABLET_TOOL_AXIS_PRESSURE] = + tablet_handle_pressure(tablet, device, tool); + axes[LIBINPUT_TABLET_TOOL_AXIS_DISTANCE] = + tablet_handle_distance(tablet, device); + axes[LIBINPUT_TABLET_TOOL_AXIS_SLIDER] = + tablet_handle_slider(tablet, device); + + tilt = tablet_handle_tilt(tablet, device); + axes[LIBINPUT_TABLET_TOOL_AXIS_TILT_X] = tilt.x; + axes[LIBINPUT_TABLET_TOOL_AXIS_TILT_Y] = tilt.y; + + /* We must check ROTATION_Z after TILT_X/Y so that the tilt axes are + * already normalized and set if we have the mouse/lens tool */ + if (tablet->current_tool_type == LIBINPUT_TABLET_TOOL_TYPE_MOUSE || + tablet->current_tool_type == LIBINPUT_TABLET_TOOL_TYPE_LENS) { + axes[LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z] = + tablet_handle_mouse_rotation(tablet, device); + axes[LIBINPUT_TABLET_TOOL_AXIS_TILT_X] = 0; + axes[LIBINPUT_TABLET_TOOL_AXIS_TILT_Y] = 0; + + } else { + axes[LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z] = + tablet_handle_artpen_rotation(tablet, device); + } + + axes[LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL] = + tablet_handle_wheel(tablet, device, &wheel_discrete); /* 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 diff --git a/src/libinput-private.h b/src/libinput-private.h index 4e0f7f43..246986e1 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -58,6 +58,11 @@ struct discrete_coords { int x, y; }; +/* A pair of coordinates normalized to a [0,1] or [-1, 1] range */ +struct normalized_range_coords { + double x, y; +}; + struct libinput_interface_backend { int (*resume)(struct libinput *libinput); void (*suspend)(struct libinput *libinput); From c39a91200e1a8214eeb554546d12cf628d8c1395 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 15 Dec 2015 11:15:36 +1000 Subject: [PATCH 219/255] tablet: don't mark all axes changed on init This will be set when the tool comes into proximity later. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 5ea7f4d5..af705b7e 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -1284,8 +1284,6 @@ tablet_init(struct tablet_dispatch *tablet, set_bit(tablet->axis_caps, axis); } - tablet_mark_all_axes_changed(tablet, device); - tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY); return 0; From 7309fd0ed38170757946bf21e4542a249be0452c Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 15 Dec 2015 11:18:14 +1000 Subject: [PATCH 220/255] tablet: simplify marking axes as changed The only time we need this is on proximity in, so move it to where we handle that to have better locality. And rather than looping through and checking each bit, just memcpy the axis capabilities, because by definition they represent the set of axes that can possibly change. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index af705b7e..24a54df2 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -155,20 +155,6 @@ tablet_process_absolute(struct tablet_dispatch *tablet, } } -static void -tablet_mark_all_axes_changed(struct tablet_dispatch *tablet, - struct evdev_device *device) -{ - enum libinput_tablet_tool_axis a; - - for (a = LIBINPUT_TABLET_TOOL_AXIS_X; a <= LIBINPUT_TABLET_TOOL_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) { @@ -194,7 +180,6 @@ tablet_update_tool(struct tablet_dispatch *tablet, 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); } @@ -782,6 +767,9 @@ tool_set_bits(const struct tablet_dispatch *tablet, { enum libinput_tablet_tool_type type = tool->type; + copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_X); + copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_Y); + #if HAVE_LIBWACOM if (tool_set_bits_from_libwacom(tablet, tool) == 0) return; @@ -1058,6 +1046,20 @@ detect_pressure_offset(struct tablet_dispatch *tablet, tool->has_pressure_offset = true; } +static void +tablet_mark_all_axes_changed(struct tablet_dispatch *tablet, + struct evdev_device *device, + struct libinput_tablet_tool *tool) +{ + static_assert(sizeof(tablet->changed_axes) == + sizeof(tool->axis_caps), + "Mismatching array sizes"); + + memcpy(tablet->changed_axes, + tool->axis_caps, + sizeof(tablet->changed_axes)); +} + static void tablet_flush(struct tablet_dispatch *tablet, struct evdev_device *device, @@ -1082,6 +1084,9 @@ tablet_flush(struct tablet_dispatch *tablet, tablet_set_status(tablet, TABLET_TOOL_LEAVING_CONTACT); } else if (tablet_has_status(tablet, TABLET_AXES_UPDATED) || tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY)) { + if (tablet_has_status(tablet, + TABLET_TOOL_ENTERING_PROXIMITY)) + tablet_mark_all_axes_changed(tablet, device, tool); detect_pressure_offset(tablet, device, tool); sanitize_tablet_axes(tablet); tablet_check_notify_axes(tablet, device, time, tool); From cbb9e9e809c14e70658d269b0af771ba93b1d507 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 15 Dec 2015 12:39:52 +1000 Subject: [PATCH 221/255] tablet: add libinput_tablet_tool_is_unique() For checking if a tablet tool can be uniquely identified by libinput. In practice this means checking for a nonzero serial number, but let's not restrict ourselves to allowing just that. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- doc/tablet-support.dox | 4 +++- src/libinput.c | 6 ++++++ src/libinput.h | 24 ++++++++++++++++++------ src/libinput.sym | 1 + test/tablet.c | 25 +++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 7 deletions(-) diff --git a/doc/tablet-support.dox b/doc/tablet-support.dox index ac56e47a..fbe778da 100644 --- a/doc/tablet-support.dox +++ b/doc/tablet-support.dox @@ -126,7 +126,9 @@ and @ref LIBINPUT_TABLET_TOOL_TYPE_LENS tools. Some tools provide hardware information that enables libinput to uniquely identify the physical device. For example, tools compatible with the Wacom Intuos 4, Intuos 5, Intuos Pro and Cintiq series are uniquely identifiable -through a serial number. +through a serial number. libinput does not specify how a tool can be +identified uniquely, a caller should use libinput_tablet_tool_is_unique() to +check if the tool is unique. libinput creates a struct libinput_tablet_tool on the first proximity in of this tool. By default, this struct is destroyed on proximity out and diff --git a/src/libinput.c b/src/libinput.c index 093f3186..082c1b05 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1318,6 +1318,12 @@ libinput_tablet_tool_get_tool_id(struct libinput_tablet_tool *tool) return tool->tool_id; } +LIBINPUT_EXPORT int +libinput_tablet_tool_is_unique(struct libinput_tablet_tool *tool) +{ + return tool->serial != 0; +} + LIBINPUT_EXPORT uint64_t libinput_tablet_tool_get_serial(struct libinput_tablet_tool *tool) { diff --git a/src/libinput.h b/src/libinput.h index 73266a06..71d28203 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -144,7 +144,7 @@ enum libinput_pointer_axis_source { * 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_device devices, see @ref tablet-serial-numbers. */ struct libinput_tablet_tool; @@ -1931,14 +1931,26 @@ libinput_tablet_tool_has_button(struct libinput_tablet_tool *tool, /** * @ingroup event_tablet * - * Return the serial number of a tool + * Return nonzero if the physical tool can be uniquely identified by + * libinput, or nonzero otherwise. If a tool can be uniquely identified, + * keeping a reference to the tool allows tracking the tool across + * proximity out sequences and across compatible tablets. + * See @ref tablet-serial-numbers for more details. * - * @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 A tablet tool + * @return 1 if the tool can be uniquely identified, 0 otherwise. + */ +int +libinput_tablet_tool_is_unique(struct libinput_tablet_tool *tool); + +/** + * @ingroup event_tablet + * + * Return the serial number of a tool. If the tool does not report a serial + * number, this function returns zero. * * @param tool The libinput tool - * @return The new tool serial triggering this event + * @return The tool serial number */ uint64_t libinput_tablet_tool_get_serial(struct libinput_tablet_tool *tool); diff --git a/src/libinput.sym b/src/libinput.sym index ddfe81dd..22a8dd82 100644 --- a/src/libinput.sym +++ b/src/libinput.sym @@ -226,6 +226,7 @@ LIBINPUT_TABLET_SUPPORT { libinput_tablet_tool_has_wheel; libinput_tablet_tool_has_slider; libinput_tablet_tool_has_button; + libinput_tablet_tool_is_unique; libinput_tablet_tool_ref; libinput_tablet_tool_set_user_data; libinput_tablet_tool_unref; diff --git a/test/tablet.c b/test/tablet.c index 456b0473..a2d0b36d 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -1257,6 +1257,30 @@ START_TEST(normalization) } END_TEST +START_TEST(tool_unique) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event_tablet_tool *tablet_event; + struct libinput_event *event; + struct libinput_tablet_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); + + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + tool = libinput_event_tablet_tool_get_tool(tablet_event); + ck_assert(libinput_tablet_tool_is_unique(tool)); + libinput_event_destroy(event); +} +END_TEST + START_TEST(tool_serial) { struct litest_device *dev = litest_current_device(); @@ -2801,6 +2825,7 @@ 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_unique, LITEST_TABLET | LITEST_TOOL_SERIAL, 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); From cd36b44b9bce9f9b481d5e2f8f1067d717ef615b Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 15 Dec 2015 13:58:01 +1000 Subject: [PATCH 222/255] tablet: invert tilt axes when left-handed is enabled Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev-tablet.c | 4 ++++ test/tablet.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 24a54df2..2187ed35 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -365,6 +365,8 @@ tablet_handle_tilt(struct tablet_dispatch *tablet, if (bit_is_set(tablet->changed_axes, a)) { absinfo = libevdev_get_abs_info(device->evdev, ABS_TILT_X); tablet->axes[a] = normalize_tilt(absinfo); + if (device->left_handed.enabled) + tablet->axes[a] *= -1; } tilt.x = tablet->axes[a]; @@ -372,6 +374,8 @@ tablet_handle_tilt(struct tablet_dispatch *tablet, if (bit_is_set(tablet->changed_axes, a)) { absinfo = libevdev_get_abs_info(device->evdev, ABS_TILT_Y); tablet->axes[a] = normalize_tilt(absinfo); + if (device->left_handed.enabled) + tablet->axes[a] *= -1; } tilt.y = tablet->axes[a]; diff --git a/test/tablet.c b/test/tablet.c index a2d0b36d..66c19902 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -1018,6 +1018,43 @@ START_TEST(no_left_handed) } END_TEST +START_TEST(left_handed_tilt) +{ +#if HAVE_LIBWACOM + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_tablet_tool *tev; + enum libinput_config_status status; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 10 }, + { ABS_TILT_X, 90 }, + { ABS_TILT_Y, 10 }, + { -1, -1 } + }; + double tx, ty; + + status = libinput_device_config_left_handed_set(dev->libinput_device, 1); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + litest_drain_events(li); + + litest_tablet_proximity_in(dev, 10, 10, axes); + libinput_dispatch(li); + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + tx = libinput_event_tablet_tool_get_tilt_x(tev); + ty = libinput_event_tablet_tool_get_tilt_y(tev); + + ck_assert_double_lt(tx, 0); + ck_assert_double_gt(ty, 0); + + libinput_event_destroy(event); +#endif +} +END_TEST + START_TEST(motion_event_state) { struct litest_device *dev = litest_current_device(); @@ -2852,6 +2889,7 @@ litest_setup_tests(void) litest_add("tablet:tilt", tilt_x, LITEST_TABLET|LITEST_TILT, LITEST_ANY); litest_add("tablet:tilt", tilt_y, LITEST_TABLET|LITEST_TILT, LITEST_ANY); litest_add_for_device("tablet:left_handed", left_handed, LITEST_WACOM_INTUOS); + litest_add_for_device("tablet:left_handed", left_handed_tilt, 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); From c124209cad94be8041adf2675ead64aad26a0317 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 23 Dec 2015 09:04:12 +1000 Subject: [PATCH 223/255] tablet: drop unused argument from tablet_mark_all_axes_changed Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 2187ed35..cec05c49 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -1052,7 +1052,6 @@ detect_pressure_offset(struct tablet_dispatch *tablet, static void tablet_mark_all_axes_changed(struct tablet_dispatch *tablet, - struct evdev_device *device, struct libinput_tablet_tool *tool) { static_assert(sizeof(tablet->changed_axes) == @@ -1090,7 +1089,7 @@ tablet_flush(struct tablet_dispatch *tablet, tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY)) { if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY)) - tablet_mark_all_axes_changed(tablet, device, tool); + tablet_mark_all_axes_changed(tablet, tool); detect_pressure_offset(tablet, device, tool); sanitize_tablet_axes(tablet); tablet_check_notify_axes(tablet, device, time, tool); From 2f481ba4a2a9c97d41d01c691ddd332d00a17b5c Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 2 Dec 2015 17:16:18 +1000 Subject: [PATCH 224/255] tablet: handle custom proximity handling For the puck/lens cursor tool we need to artificially reduce proximity detection. These tools are usually used in a relative mode (i.e. like a mouse) and thus require lifting and resetting the tool multiple times to move across the screen. The tablets' distance detection goes too far, requiring the user to lift the device several cm on every move. This is uncomfortable. Introduce an artificial distance threshold for the devices with the default value taken from the X.Org wacom driver. If a tool is in proximity but outside of this range, fake proximity events accordingly. If a button was pressed while we were out of range we discard that event and send it later when we enter proximity again. This is the simple implementation that only takes one proximity out value (the one from the wacom driver) and applies it to all. Those devices that support a button/lens tool and have a different default threshold are well out of date. Reviewed-by: Hans de Goede [rebased, tests updated for new axis percentage behavior (8d76734f)] Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 105 ++++++++++++++++++++- src/evdev-tablet.h | 3 + test/litest.c | 18 ++++ test/litest.h | 3 +- test/tablet.c | 221 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 348 insertions(+), 2 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index cec05c49..3834e56d 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -68,6 +68,22 @@ tablet_get_released_buttons(struct tablet_dispatch *tablet, ~(state->stylus_buttons[i]); } +/* Merge the previous state with the current one so all buttons look like + * they just got pressed in this frame */ +static inline void +tablet_force_button_presses(struct tablet_dispatch *tablet) +{ + struct button_state *state = &tablet->button_state, + *prev_state = &tablet->prev_button_state; + size_t i; + + for (i = 0; i < sizeof(state->stylus_buttons); i++) { + state->stylus_buttons[i] = state->stylus_buttons[i] | + prev_state->stylus_buttons[i]; + prev_state->stylus_buttons[i] = 0; + } +} + static int tablet_device_has_axis(struct tablet_dispatch *tablet, enum libinput_tablet_tool_axis axis) @@ -1063,6 +1079,63 @@ tablet_mark_all_axes_changed(struct tablet_dispatch *tablet, sizeof(tablet->changed_axes)); } +static void +tablet_update_proximity_state(struct tablet_dispatch *tablet, + struct evdev_device *device, + struct libinput_tablet_tool *tool) +{ + const struct input_absinfo *distance; + int dist_max = tablet->cursor_proximity_threshold; + int dist; + + distance = libevdev_get_abs_info(tablet->device->evdev, ABS_DISTANCE); + if (!distance) + return; + + dist = distance->value; + if (dist == 0) + return; + + /* Tool got into permitted range */ + if (dist < dist_max && + (tablet_has_status(tablet, TABLET_TOOL_OUT_OF_RANGE) || + tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY))) { + tablet_unset_status(tablet, + TABLET_TOOL_OUT_OF_RANGE); + tablet_unset_status(tablet, + TABLET_TOOL_OUT_OF_PROXIMITY); + tablet_set_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY); + tablet_mark_all_axes_changed(tablet, tool); + + tablet_set_status(tablet, TABLET_BUTTONS_PRESSED); + tablet_force_button_presses(tablet); + return; + } + + if (dist < dist_max) + return; + + /* Still out of range/proximity */ + if (tablet_has_status(tablet, TABLET_TOOL_OUT_OF_RANGE) || + tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY)) + return; + + /* Tool entered prox but is outside of permitted range */ + if (tablet_has_status(tablet, + TABLET_TOOL_ENTERING_PROXIMITY)) { + tablet_set_status(tablet, + TABLET_TOOL_OUT_OF_RANGE); + tablet_unset_status(tablet, + TABLET_TOOL_ENTERING_PROXIMITY); + return; + } + + /* Tool was in prox and is now outside of range. Set leaving + * proximity, on the next event it will be OUT_OF_PROXIMITY and thus + * caught by the above conditions */ + tablet_set_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY); +} + static void tablet_flush(struct tablet_dispatch *tablet, struct evdev_device *device, @@ -1074,7 +1147,12 @@ tablet_flush(struct tablet_dispatch *tablet, tablet->current_tool_id, tablet->current_tool_serial); - if (tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY)) + if (tool->type == LIBINPUT_TABLET_TOOL_TYPE_MOUSE || + tool->type == LIBINPUT_TABLET_TOOL_TYPE_LENS) + tablet_update_proximity_state(tablet, device, tool); + + if (tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY) || + tablet_has_status(tablet, TABLET_TOOL_OUT_OF_RANGE)) return; if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) { @@ -1271,6 +1349,30 @@ tablet_init_calibration(struct tablet_dispatch *tablet, evdev_init_calibration(device, &tablet->base); } +static void +tablet_init_proximity_threshold(struct tablet_dispatch *tablet, + struct evdev_device *device) +{ + /* This rules out most of the bamboos and other devices, we're + * pretty much down to + */ + if (!libevdev_has_event_code(device->evdev, EV_KEY, BTN_TOOL_MOUSE) && + !libevdev_has_event_code(device->evdev, EV_KEY, BTN_TOOL_LENS)) + return; + + /* 42 is the default proximity threshold the xf86-input-wacom driver + * uses for Intuos/Cintiq models. Graphire models have a threshold + * of 10 but since they haven't been manufactured in ages and the + * intersection of users having a graphire, running libinput and + * wanting to use the mouse/lens cursor tool is small enough to not + * worry about it for now. If we need to, we can introduce a udev + * property later. + * + * Value is in device coordinates. + */ + tablet->cursor_proximity_threshold = 42; +} + static int tablet_init(struct tablet_dispatch *tablet, struct evdev_device *device) @@ -1284,6 +1386,7 @@ tablet_init(struct tablet_dispatch *tablet, list_init(&tablet->tool_list); tablet_init_calibration(tablet, device); + tablet_init_proximity_threshold(tablet, device); for (axis = LIBINPUT_TABLET_TOOL_AXIS_X; axis <= LIBINPUT_TABLET_TOOL_AXIS_MAX; diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index 4dcbccc6..0225dcf4 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -41,6 +41,7 @@ enum tablet_status { TABLET_TOOL_ENTERING_PROXIMITY = 1 << 6, TABLET_TOOL_ENTERING_CONTACT = 1 << 7, TABLET_TOOL_LEAVING_CONTACT = 1 << 8, + TABLET_TOOL_OUT_OF_RANGE = 1 << 9, }; struct button_state { @@ -65,6 +66,8 @@ struct tablet_dispatch { enum libinput_tablet_tool_type current_tool_type; uint32_t current_tool_id; uint32_t current_tool_serial; + + uint32_t cursor_proximity_threshold; }; static inline enum libinput_tablet_tool_axis diff --git a/test/litest.c b/test/litest.c index fd5e3b9c..4446f7b7 100644 --- a/test/litest.c +++ b/test/litest.c @@ -2403,6 +2403,24 @@ litest_assert_tablet_button_event(struct libinput *li, unsigned int button, libinput_event_destroy(event); } +void litest_assert_tablet_proximity_event(struct libinput *li, + enum libinput_tablet_tool_proximity_state state) +{ + struct libinput_event *event; + struct libinput_event_tablet_tool *tev; + enum libinput_event_type type = LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY; + + 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_tool_event(event); + litest_assert_int_eq(libinput_event_tablet_tool_get_proximity_state(tev), + state); + libinput_event_destroy(event); +} + void litest_assert_scroll(struct libinput *li, enum libinput_pointer_axis axis, diff --git a/test/litest.h b/test/litest.h index 89377906..406e47fd 100644 --- a/test/litest.h +++ b/test/litest.h @@ -457,7 +457,8 @@ void litest_assert_only_typed_events(struct libinput *li, void litest_assert_tablet_button_event(struct libinput *li, unsigned int button, enum libinput_button_state state); - +void litest_assert_tablet_proximity_event(struct libinput *li, + enum libinput_tablet_tool_proximity_state state); struct libevdev_uinput * litest_create_uinput_device(const char *name, struct input_id *id, ...); diff --git a/test/tablet.c b/test/tablet.c index 66c19902..122a1ba2 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -811,6 +811,222 @@ START_TEST(proximity_has_axes) } END_TEST +START_TEST(proximity_range_enter) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 90 }, + { -1, -1 } + }; + + if (!libevdev_has_event_code(dev->evdev, + EV_KEY, + BTN_TOOL_MOUSE)) + return; + + 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_assert_empty_queue(li); + + axes[0].value = 20; + litest_tablet_motion(dev, 10, 10, axes); + libinput_dispatch(li); + + litest_assert_tablet_proximity_event(li, + LIBINPUT_TABLET_TOOL_PROXIMITY_IN); + axes[0].value = 90; + litest_tablet_motion(dev, 10, 10, axes); + libinput_dispatch(li); + litest_assert_tablet_proximity_event(li, + LIBINPUT_TABLET_TOOL_PROXIMITY_OUT); + + litest_tablet_proximity_out(dev); + litest_assert_empty_queue(li); +} +END_TEST + +START_TEST(proximity_range_in_out) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 20 }, + { -1, -1 } + }; + + if (!libevdev_has_event_code(dev->evdev, + EV_KEY, + BTN_TOOL_MOUSE)) + return; + + 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); + libinput_dispatch(li); + litest_assert_tablet_proximity_event(li, + LIBINPUT_TABLET_TOOL_PROXIMITY_IN); + + axes[0].value = 90; + litest_tablet_motion(dev, 10, 10, axes); + libinput_dispatch(li); + litest_assert_tablet_proximity_event(li, + LIBINPUT_TABLET_TOOL_PROXIMITY_OUT); + + litest_tablet_motion(dev, 30, 30, axes); + litest_assert_empty_queue(li); + + axes[0].value = 20; + litest_tablet_motion(dev, 10, 10, axes); + libinput_dispatch(li); + litest_assert_tablet_proximity_event(li, + LIBINPUT_TABLET_TOOL_PROXIMITY_IN); + + litest_tablet_proximity_out(dev); + litest_assert_tablet_proximity_event(li, + LIBINPUT_TABLET_TOOL_PROXIMITY_OUT); + litest_assert_empty_queue(li); +} +END_TEST + +START_TEST(proximity_range_button_click) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 90 }, + { -1, -1 } + }; + + if (!libevdev_has_event_code(dev->evdev, + EV_KEY, + BTN_TOOL_MOUSE)) + return; + + 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); + + litest_event(dev, EV_KEY, BTN_STYLUS, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + libinput_dispatch(li); + litest_event(dev, EV_KEY, BTN_STYLUS, 0); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + libinput_dispatch(li); + + litest_tablet_proximity_out(dev); + litest_assert_empty_queue(li); +} +END_TEST + +START_TEST(proximity_range_button_press) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 20 }, + { -1, -1 } + }; + + if (!libevdev_has_event_code(dev->evdev, + EV_KEY, + BTN_TOOL_MOUSE)) + return; + + 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); + + litest_event(dev, EV_KEY, BTN_STYLUS, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + libinput_dispatch(li); + + litest_assert_tablet_button_event(li, + BTN_STYLUS, + LIBINPUT_BUTTON_STATE_PRESSED); + + axes[0].value = 90; + litest_tablet_motion(dev, 15, 15, axes); + libinput_dispatch(li); + + /* expect fake button release */ + litest_assert_tablet_button_event(li, + BTN_STYLUS, + LIBINPUT_BUTTON_STATE_RELEASED); + litest_assert_tablet_proximity_event(li, + LIBINPUT_TABLET_TOOL_PROXIMITY_OUT); + + litest_event(dev, EV_KEY, BTN_STYLUS, 0); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + libinput_dispatch(li); + + litest_tablet_proximity_out(dev); + litest_assert_empty_queue(li); +} +END_TEST + +START_TEST(proximity_range_button_release) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 90 }, + { -1, -1 } + }; + + if (!libevdev_has_event_code(dev->evdev, + EV_KEY, + BTN_TOOL_MOUSE)) + return; + + 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); + + litest_event(dev, EV_KEY, BTN_STYLUS, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_assert_empty_queue(li); + + axes[0].value = 20; + litest_tablet_motion(dev, 15, 15, axes); + libinput_dispatch(li); + + litest_assert_tablet_proximity_event(li, + LIBINPUT_TABLET_TOOL_PROXIMITY_IN); + /* expect fake button press */ + litest_assert_tablet_button_event(li, + BTN_STYLUS, + LIBINPUT_BUTTON_STATE_PRESSED); + litest_assert_empty_queue(li); + + litest_event(dev, EV_KEY, BTN_STYLUS, 0); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + libinput_dispatch(li); + litest_assert_tablet_button_event(li, + BTN_STYLUS, + LIBINPUT_BUTTON_STATE_RELEASED); + + litest_tablet_proximity_out(dev); + litest_assert_tablet_proximity_event(li, + LIBINPUT_TABLET_TOOL_PROXIMITY_OUT); +} +END_TEST + START_TEST(motion) { struct litest_device *dev = litest_current_device(); @@ -2872,6 +3088,11 @@ litest_setup_tests(void) 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:proximity", proximity_range_enter, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY); + litest_add("tablet:proximity", proximity_range_in_out, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY); + litest_add("tablet:proximity", proximity_range_button_click, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY); + litest_add("tablet:proximity", proximity_range_button_press, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY); + litest_add("tablet:proximity", proximity_range_button_release, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY); litest_add("tablet:tip", tip_down_up, LITEST_TABLET, LITEST_ANY); litest_add("tablet:tip", tip_down_prox_in, LITEST_TABLET, LITEST_ANY); litest_add("tablet:tip", tip_up_prox_out, LITEST_TABLET, LITEST_ANY); From 3a16203a340fbee8fb7288036e923768fe3ba2e6 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 3 Dec 2015 11:19:44 +1000 Subject: [PATCH 225/255] test: add two more tests for correct button sequence on proximity Signed-off-by: Peter Hutterer --- test/tablet.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/test/tablet.c b/test/tablet.c index 122a1ba2..e5c2cb68 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -623,6 +623,62 @@ START_TEST(proximity_in_out) } END_TEST +START_TEST(proximity_in_button_down) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 10 }, + { -1, -1 } + }; + + litest_drain_events(li); + + litest_push_event_frame(dev); + litest_tablet_proximity_in(dev, 10, 10, axes); + litest_event(dev, EV_KEY, BTN_STYLUS, 1); + litest_pop_event_frame(dev); + libinput_dispatch(li); + + litest_assert_tablet_proximity_event(li, + LIBINPUT_TABLET_TOOL_PROXIMITY_IN); + litest_assert_tablet_button_event(li, + BTN_STYLUS, + LIBINPUT_BUTTON_STATE_PRESSED); + litest_assert_empty_queue(li); +} +END_TEST + +START_TEST(proximity_out_button_up) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 10 }, + { -1, -1 } + }; + + litest_tablet_proximity_in(dev, 10, 10, axes); + + litest_event(dev, EV_KEY, BTN_STYLUS, 1); + litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_drain_events(li); + + litest_push_event_frame(dev); + litest_tablet_proximity_out(dev); + litest_event(dev, EV_KEY, BTN_STYLUS, 0); + litest_pop_event_frame(dev); + libinput_dispatch(li); + + litest_assert_tablet_button_event(li, + BTN_STYLUS, + LIBINPUT_BUTTON_STATE_RELEASED); + litest_assert_tablet_proximity_event(li, + LIBINPUT_TABLET_TOOL_PROXIMITY_OUT); + litest_assert_empty_queue(li); +} +END_TEST + START_TEST(proximity_out_clear_buttons) { struct litest_device *dev = litest_current_device(); @@ -3086,6 +3142,8 @@ litest_setup_tests(void) 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_in_button_down, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:proximity", proximity_out_button_up, 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:proximity", proximity_range_enter, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY); From 77c1c75a6466a03e00faa1e614214c7b7ae8fc49 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 23 Dec 2015 09:52:13 +1000 Subject: [PATCH 226/255] test: use the litest_axis_set_value helper Should've been part of 2f481ba4a2 during rebasing. Signed-off-by: Peter Hutterer --- test/tablet.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/tablet.c b/test/tablet.c index e5c2cb68..d41c2c17 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -889,13 +889,14 @@ START_TEST(proximity_range_enter) litest_pop_event_frame(dev); litest_assert_empty_queue(li); - axes[0].value = 20; + litest_axis_set_value(axes, ABS_DISTANCE, 20); litest_tablet_motion(dev, 10, 10, axes); libinput_dispatch(li); litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_IN); - axes[0].value = 90; + + litest_axis_set_value(axes, ABS_DISTANCE, 90); litest_tablet_motion(dev, 10, 10, axes); libinput_dispatch(li); litest_assert_tablet_proximity_event(li, @@ -930,7 +931,7 @@ START_TEST(proximity_range_in_out) litest_assert_tablet_proximity_event(li, LIBINPUT_TABLET_TOOL_PROXIMITY_IN); - axes[0].value = 90; + litest_axis_set_value(axes, ABS_DISTANCE, 90); litest_tablet_motion(dev, 10, 10, axes); libinput_dispatch(li); litest_assert_tablet_proximity_event(li, @@ -939,7 +940,7 @@ START_TEST(proximity_range_in_out) litest_tablet_motion(dev, 30, 30, axes); litest_assert_empty_queue(li); - axes[0].value = 20; + litest_axis_set_value(axes, ABS_DISTANCE, 20); litest_tablet_motion(dev, 10, 10, axes); libinput_dispatch(li); litest_assert_tablet_proximity_event(li, @@ -1014,7 +1015,7 @@ START_TEST(proximity_range_button_press) BTN_STYLUS, LIBINPUT_BUTTON_STATE_PRESSED); - axes[0].value = 90; + litest_axis_set_value(axes, ABS_DISTANCE, 90); litest_tablet_motion(dev, 15, 15, axes); libinput_dispatch(li); @@ -1058,7 +1059,7 @@ START_TEST(proximity_range_button_release) litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_assert_empty_queue(li); - axes[0].value = 20; + litest_axis_set_value(axes, ABS_DISTANCE, 20); litest_tablet_motion(dev, 15, 15, axes); libinput_dispatch(li); From 67e0b232a037572b83a5c752a258fdbd9003d0b3 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 14 Dec 2015 07:39:26 +1000 Subject: [PATCH 227/255] Add event debugging to libinput_post_event Print the type of event when it is queued up internally. This makes it a lot easier to associate evdev events with the libinput event queued up and does not depend on the caller calling libinput_dispatch(). Since this should only be used during development, hide it behind an if 0. Signed-off-by: Peter Hutterer --- src/libinput.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/libinput.c b/src/libinput.c index 082c1b05..b3fca6c9 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -2369,6 +2369,39 @@ gesture_notify_pinch_end(struct libinput_device *device, 2, cancelled, &zero, &zero, scale, 0.0); } +static inline const char * +event_type_to_str(enum libinput_event_type type) +{ + switch(type) { + CASE_RETURN_STRING(LIBINPUT_EVENT_DEVICE_ADDED); + CASE_RETURN_STRING(LIBINPUT_EVENT_DEVICE_REMOVED); + CASE_RETURN_STRING(LIBINPUT_EVENT_KEYBOARD_KEY); + CASE_RETURN_STRING(LIBINPUT_EVENT_POINTER_MOTION); + CASE_RETURN_STRING(LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE); + CASE_RETURN_STRING(LIBINPUT_EVENT_POINTER_BUTTON); + CASE_RETURN_STRING(LIBINPUT_EVENT_POINTER_AXIS); + CASE_RETURN_STRING(LIBINPUT_EVENT_TOUCH_DOWN); + CASE_RETURN_STRING(LIBINPUT_EVENT_TOUCH_UP); + CASE_RETURN_STRING(LIBINPUT_EVENT_TOUCH_MOTION); + CASE_RETURN_STRING(LIBINPUT_EVENT_TOUCH_CANCEL); + CASE_RETURN_STRING(LIBINPUT_EVENT_TOUCH_FRAME); + CASE_RETURN_STRING(LIBINPUT_EVENT_TABLET_TOOL_AXIS); + CASE_RETURN_STRING(LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + CASE_RETURN_STRING(LIBINPUT_EVENT_TABLET_TOOL_TIP); + CASE_RETURN_STRING(LIBINPUT_EVENT_TABLET_TOOL_BUTTON); + CASE_RETURN_STRING(LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN); + CASE_RETURN_STRING(LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE); + CASE_RETURN_STRING(LIBINPUT_EVENT_GESTURE_SWIPE_END); + CASE_RETURN_STRING(LIBINPUT_EVENT_GESTURE_PINCH_BEGIN); + CASE_RETURN_STRING(LIBINPUT_EVENT_GESTURE_PINCH_UPDATE); + CASE_RETURN_STRING(LIBINPUT_EVENT_GESTURE_PINCH_END); + case LIBINPUT_EVENT_NONE: + abort(); + } + + return NULL; +} + static void libinput_post_event(struct libinput *libinput, struct libinput_event *event) @@ -2379,6 +2412,10 @@ libinput_post_event(struct libinput *libinput, size_t move_len; size_t new_out; +#if 0 + log_debug(libinput, "Queuing %s\n", event_type_to_str(event->type)); +#endif + events_count++; if (events_count > events_len) { events_len *= 2; From 0319ee1d3316393c4cb0d551445529bfee415a1a Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 15 Dec 2015 08:39:56 +1000 Subject: [PATCH 228/255] tablet: split sanitize_tablet_axes up into two helpers Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 3834e56d..7804c91c 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -957,7 +957,7 @@ tablet_notify_buttons(struct tablet_dispatch *tablet, } static void -sanitize_tablet_axes(struct tablet_dispatch *tablet) +sanitize_pressure_distance(struct tablet_dispatch *tablet) { bool tool_in_contact; const struct input_absinfo *distance, @@ -995,7 +995,11 @@ sanitize_tablet_axes(struct tablet_dispatch *tablet) else tablet->axes[LIBINPUT_TABLET_TOOL_AXIS_PRESSURE] = 0; } +} +static inline void +sanitize_mouse_lens_rotation(struct tablet_dispatch *tablet) +{ /* 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_TABLET_TOOL_TYPE_MOUSE || @@ -1011,6 +1015,13 @@ axis_range_percentage(const struct input_absinfo *a, int percent) return (a->maximum - a->minimum) * percent/100 + a->minimum; } +static void +sanitize_tablet_axes(struct tablet_dispatch *tablet) +{ + sanitize_pressure_distance(tablet); + sanitize_mouse_lens_rotation(tablet); +} + static void detect_pressure_offset(struct tablet_dispatch *tablet, struct evdev_device *device, From 6098655cfa3e1e4861291cbda2fa3cc3dc7f4a90 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 21 Dec 2015 15:42:33 +1000 Subject: [PATCH 229/255] test: fix a bunch of tablet tests to assume, rather than wait for events litest_wait_for_event_of_type() skips all other events in the queue before the one we want. This isn't appropriate in most cases, and unless we're dealing with timeouts we should assume that a certain sequence triggered a specific event rather than waiting some time for it to trigger. Signed-off-by: Peter Hutterer --- test/tablet.c | 237 ++++++++++++++++++++++---------------------------- 1 file changed, 104 insertions(+), 133 deletions(-) diff --git a/test/tablet.c b/test/tablet.c index d41c2c17..3c509e77 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -761,12 +761,11 @@ START_TEST(proximity_has_axes) litest_drain_events(li); litest_tablet_proximity_in(dev, 10, 10, axes); - - litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); + libinput_dispatch(li); event = libinput_get_event(li); - - tablet_event = libinput_event_get_tablet_tool_event(event); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tablet_event); ck_assert(libinput_event_tablet_tool_x_has_changed(tablet_event)); @@ -807,9 +806,8 @@ START_TEST(proximity_has_axes) litest_axis_set_value(axes, ABS_TILT_Y, 25); litest_tablet_motion(dev, 20, 30, axes); libinput_dispatch(li); - litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, -1); event = libinput_get_event(li); - tablet_event = libinput_event_get_tablet_tool_event(event); + tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); last_x = libinput_event_tablet_tool_get_x(tablet_event); last_y = libinput_event_tablet_tool_get_y(tablet_event); @@ -825,11 +823,11 @@ START_TEST(proximity_has_axes) /* Make sure that the axes are still present on proximity out */ litest_tablet_proximity_out(dev); + libinput_dispatch(li); - litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); event = libinput_get_event(li); - - tablet_event = libinput_event_get_tablet_tool_event(event); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tablet_event); ck_assert(!libinput_event_tablet_tool_x_has_changed(tablet_event)); @@ -1103,11 +1101,9 @@ START_TEST(motion) litest_tablet_proximity_in(dev, 5, 100, axes); libinput_dispatch(li); - litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, - -1); + event = libinput_get_event(li); - while ((event = libinput_get_event(li))) { + do { bool x_changed, y_changed; double reported_x, reported_y; @@ -1132,7 +1128,8 @@ START_TEST(motion) last_reported_y = reported_y; libinput_event_destroy(event); - } + event = libinput_get_event(li); + } while (event != NULL); for (test_x = 10, test_y = 90; test_x <= 100; @@ -1185,11 +1182,14 @@ START_TEST(left_handed) struct libinput_event_tablet_tool *tablet_event; double libinput_max_x, libinput_max_y; double last_x = -1.0, last_y = -1.0; + double x, y; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, { -1, -1 } }; + litest_drain_events(li); + ck_assert(libinput_device_config_left_handed_is_available(dev->libinput_device)); libinput_device_get_size (dev->libinput_device, @@ -1205,38 +1205,35 @@ START_TEST(left_handed) libinput_dispatch(li); libinput_device_config_left_handed_set(dev->libinput_device, 1); - litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); - while ((event = libinput_get_event(li))) { - tablet_event = libinput_event_get_tablet_tool_event(event); + last_x = libinput_event_tablet_tool_get_x(tablet_event); + last_y = libinput_event_tablet_tool_get_y(tablet_event); - last_x = libinput_event_tablet_tool_get_x(tablet_event); - last_y = libinput_event_tablet_tool_get_y(tablet_event); + litest_assert_double_eq(last_x, 0); + litest_assert_double_eq(last_y, libinput_max_y); - litest_assert_double_eq(last_x, 0); - litest_assert_double_eq(last_y, libinput_max_y); - - libinput_event_destroy(event); - } + libinput_event_destroy(event); litest_tablet_motion(dev, 100, 0, axes); - litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, -1); + libinput_dispatch(li); - while ((event = libinput_get_event(li))) { - double x, y; - tablet_event = libinput_event_get_tablet_tool_event(event); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); - x = libinput_event_tablet_tool_get_x(tablet_event); - y = libinput_event_tablet_tool_get_y(tablet_event); + x = libinput_event_tablet_tool_get_x(tablet_event); + y = libinput_event_tablet_tool_get_y(tablet_event); - litest_assert_double_eq(x, libinput_max_x); - litest_assert_double_eq(y, 0); + 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); + litest_assert_double_gt(x, last_x); + litest_assert_double_lt(y, last_y); - libinput_event_destroy(event); - } + libinput_event_destroy(event); litest_tablet_proximity_out(dev); litest_drain_events(li); @@ -1246,39 +1243,39 @@ START_TEST(left_handed) * mode, so the axes should be inverted once we bring it back into * proximity */ litest_tablet_proximity_in(dev, 0, 100, axes); + libinput_dispatch(li); - litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, -1); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); - while ((event = libinput_get_event(li))) { - tablet_event = libinput_event_get_tablet_tool_event(event); + last_x = libinput_event_tablet_tool_get_x(tablet_event); + last_y = libinput_event_tablet_tool_get_y(tablet_event); - last_x = libinput_event_tablet_tool_get_x(tablet_event); - last_y = libinput_event_tablet_tool_get_y(tablet_event); + litest_assert_double_eq(last_x, libinput_max_x); + litest_assert_double_eq(last_y, 0); - litest_assert_double_eq(last_x, libinput_max_x); - litest_assert_double_eq(last_y, 0); - - libinput_event_destroy(event); - } + libinput_event_destroy(event); litest_tablet_motion(dev, 100, 0, axes); - litest_wait_for_event_of_type(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, -1); + libinput_dispatch(li); - while ((event = libinput_get_event(li))) { - double x, y; - tablet_event = libinput_event_get_tablet_tool_event(event); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); - x = libinput_event_tablet_tool_get_x(tablet_event); - y = libinput_event_tablet_tool_get_y(tablet_event); + tablet_event = libinput_event_get_tablet_tool_event(event); - litest_assert_double_eq(x, 0); - litest_assert_double_eq(y, libinput_max_y); + x = libinput_event_tablet_tool_get_x(tablet_event); + y = libinput_event_tablet_tool_get_y(tablet_event); - litest_assert_double_lt(x, last_x); - litest_assert_double_gt(y, last_y); + litest_assert_double_eq(x, 0); + litest_assert_double_eq(y, libinput_max_y); - libinput_event_destroy(event); - } + litest_assert_double_lt(x, last_x); + litest_assert_double_gt(y, last_y); + + libinput_event_destroy(event); #endif } END_TEST @@ -1604,12 +1601,11 @@ START_TEST(tool_serial) 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); + libinput_dispatch(li); - litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, - -1); event = libinput_get_event(li); - tablet_event = libinput_event_get_tablet_tool_event(event); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tablet_event); ck_assert_uint_eq(libinput_tablet_tool_get_serial(tool), 1000); libinput_event_destroy(event); @@ -1636,12 +1632,11 @@ START_TEST(serial_changes_tool) 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); + libinput_dispatch(li); - litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, - -1); event = libinput_get_event(li); - tablet_event = libinput_event_get_tablet_tool_event(event); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tablet_event); ck_assert_uint_eq(libinput_tablet_tool_get_serial(tool), 2000); @@ -1698,12 +1693,11 @@ START_TEST(tool_ref) 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); + libinput_dispatch(li); - litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, - -1); event = libinput_get_event(li); - tablet_event = libinput_event_get_tablet_tool_event(event); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tablet_event); ck_assert_notnull(tool); @@ -1867,18 +1861,15 @@ START_TEST(tool_capabilities) * tablet the tool is being used with */ bamboo = litest_add_device(li, LITEST_WACOM_BAMBOO); intuos = litest_add_device(li, LITEST_WACOM_INTUOS); + litest_drain_events(li); 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_TOOL_PROXIMITY, - -1); - event = libinput_get_event(li); - t = libinput_event_get_tablet_tool_event(event); + t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(t); ck_assert(libinput_tablet_tool_has_pressure(tool)); @@ -1890,13 +1881,11 @@ START_TEST(tool_capabilities) 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_TOOL_PROXIMITY, - -1); + libinput_dispatch(li); event = libinput_get_event(li); - t = libinput_event_get_tablet_tool_event(event); + t = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + tool = libinput_event_tablet_tool_get_tool(t); tool = libinput_event_tablet_tool_get_tool(t); ck_assert(libinput_tablet_tool_has_pressure(tool)); @@ -1982,12 +1971,11 @@ START_TEST(mouse_tool) 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); + libinput_dispatch(li); - litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, - -1); event = libinput_get_event(li); - tev = libinput_event_get_tablet_tool_event(event); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tev); ck_assert_notnull(tool); ck_assert_int_eq(libinput_tablet_tool_get_type(tool), @@ -2017,12 +2005,11 @@ START_TEST(mouse_buttons) 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); + libinput_dispatch(li); - litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, - -1); event = libinput_get_event(li); - tev = libinput_event_get_tablet_tool_event(event); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tev); ck_assert_notnull(tool); libinput_tablet_tool_ref(tool); @@ -2110,12 +2097,11 @@ START_TEST(mouse_rotation) 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); + libinput_dispatch(li); - litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_TOOL_AXIS, - -1); event = libinput_get_event(li); - tev = libinput_event_get_tablet_tool_event(event); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); ck_assert(libinput_event_tablet_tool_rotation_has_changed(tev)); val = libinput_event_tablet_tool_get_rotation(tev); @@ -2154,12 +2140,11 @@ START_TEST(mouse_wheel) 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); + libinput_dispatch(li); - litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, - -1); event = libinput_get_event(li); - tev = libinput_event_get_tablet_tool_event(event); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tev); ck_assert_notnull(tool); libinput_tablet_tool_ref(tool); @@ -2171,11 +2156,11 @@ START_TEST(mouse_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_TOOL_AXIS, -1); + libinput_dispatch(li); event = libinput_get_event(li); - tev = libinput_event_get_tablet_tool_event(event); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); ck_assert(libinput_event_tablet_tool_wheel_has_changed(tev)); val = libinput_event_tablet_tool_get_wheel_delta(tev); @@ -2196,11 +2181,11 @@ START_TEST(mouse_wheel) 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_TOOL_AXIS, -1); + libinput_dispatch(li); event = libinput_get_event(li); - tev = libinput_event_get_tablet_tool_event(event); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); ck_assert(!libinput_event_tablet_tool_wheel_has_changed(tev)); val = libinput_event_tablet_tool_get_wheel_delta(tev); @@ -2236,13 +2221,13 @@ START_TEST(airbrush_tool) 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); + libinput_dispatch(li); - litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, - -1); event = libinput_get_event(li); - tev = libinput_event_get_tablet_tool_event(event); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tev); + ck_assert_notnull(tool); ck_assert_int_eq(libinput_tablet_tool_get_type(tool), LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH); @@ -2286,12 +2271,10 @@ START_TEST(airbrush_wheel) 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_TOOL_AXIS, - -1); + libinput_dispatch(li); event = libinput_get_event(li); - tev = libinput_event_get_tablet_tool_event(event); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); ck_assert(libinput_event_tablet_tool_slider_has_changed(tev)); val = libinput_event_tablet_tool_get_slider_position(tev); @@ -2321,12 +2304,10 @@ START_TEST(artpen_tool) 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_TOOL_PROXIMITY, - -1); + libinput_dispatch(li); event = libinput_get_event(li); - tev = libinput_event_get_tablet_tool_event(event); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); tool = libinput_event_tablet_tool_get_tool(tev); ck_assert_notnull(tool); ck_assert_int_eq(libinput_tablet_tool_get_type(tool), @@ -2374,12 +2355,10 @@ START_TEST(artpen_rotation) 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_TOOL_AXIS, - -1); + libinput_dispatch(li); event = libinput_get_event(li); - tev = libinput_event_get_tablet_tool_event(event); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); ck_assert(libinput_event_tablet_tool_rotation_has_changed(tev)); val = libinput_event_tablet_tool_get_rotation(tev); @@ -2409,11 +2388,9 @@ START_TEST(tablet_time_usec) litest_tablet_proximity_in(dev, 5, 100, axes); libinput_dispatch(li); - litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, - -1); event = libinput_get_event(li); - tev = libinput_event_get_tablet_tool_event(event); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); ck_assert_int_eq(libinput_event_tablet_tool_get_time(tev), libinput_event_tablet_tool_get_time_usec(tev) / 1000); libinput_event_destroy(event); @@ -2439,11 +2416,8 @@ START_TEST(tablet_pressure_distance_exclusive) litest_tablet_motion(dev, 70, 70, axes); libinput_dispatch(li); - litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_TOOL_AXIS, - -1); event = libinput_get_event(li); - tev = libinput_event_get_tablet_tool_event(event); + tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); pressure = libinput_event_tablet_tool_get_pressure(tev); distance = libinput_event_tablet_tool_get_distance(tev); @@ -2933,11 +2907,8 @@ START_TEST(tablet_pressure_offset_none_for_small_distance) litest_tablet_motion(dev, 70, 70, axes); libinput_dispatch(li); - litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_TOOL_AXIS, - -1); event = libinput_get_event(li); - tev = libinput_event_get_tablet_tool_event(event); + tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); pressure = libinput_event_tablet_tool_get_pressure(tev); ck_assert_double_gt(pressure, 0.0); From 9114054fa29084d69784c09e2f811325e0520a14 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 21 Dec 2015 15:24:03 +1000 Subject: [PATCH 230/255] tablet: explicitly set the tip state on the proximity event Signed-off-by: Peter Hutterer --- src/libinput.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libinput.c b/src/libinput.c index b3fca6c9..3a10df43 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -2203,6 +2203,7 @@ tablet_notify_proximity(struct libinput_device *device, *proximity_event = (struct libinput_event_tablet_tool) { .time = time, .tool = tool, + .tip_state = LIBINPUT_TABLET_TOOL_TIP_UP, .proximity_state = proximity_state, }; memcpy(proximity_event->axes, From 665daba9a9c79b832b9b82e6f09cf0742f0e5446 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 5 Jan 2016 12:35:49 +1000 Subject: [PATCH 231/255] doc: improve absolute axis documentation a bit Signed-off-by: Peter Hutterer --- doc/absolute-axes.dox | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/doc/absolute-axes.dox b/doc/absolute-axes.dox index 664c6164..0e1a21bb 100644 --- a/doc/absolute-axes.dox +++ b/doc/absolute-axes.dox @@ -10,7 +10,7 @@ libinput supports three types of devices with absolute axes: - multi-touch screens - single-touch screens - - graphics tablets (currently WIP) + - @ref tablet-support "graphics tablets" Touchpads are technically absolute devices but libinput converts the axis values to directional motion and posts events as relative events. Touchpads do not count @@ -18,7 +18,10 @@ as absolute devices in libinput. For all absolute devices in libinput, the default unit for x/y coordinates is in mm off the top left corner on the device, or more specifically off the -device's sensor. +device's sensor. If the device is physically rotated from its natural +position and this rotation was communicated to libinput (e.g. +@ref libinput_device_config_left_handed_set "by setting the device left-handed"), +the coordinate origin is the top left corner of in the current rotation. @section absolute_axes_handling Handling of absolute coordinates @@ -40,7 +43,7 @@ coordinate. @section absolute_axes_nores Devices without x/y resolution An absolute device that does not provide a valid resolution is considered -buggy and must be fixed in the kernel. Some touchpad devices that do not +buggy and must be fixed in the kernel. Some touchpad devices do not provide resolution, those devices are correctly handled within libinput (touchpads are not absolute devices, as mentioned above). @@ -107,11 +110,14 @@ The most common matrices are: See Wikipedia's Transformation -Matrix article for more information on the matrix maths. - -See libinput_device_config_calibration_get_default_matrix() for how these +Matrix article for more information on the matrix maths. See +libinput_device_config_calibration_get_default_matrix() for how these matrices must be supplied to libinput. +Once applied, any x and y axis value has the calibration applied before it +is made available to the caller. libinput does not provide access to the +raw coordinates before the calibration is applied. + @section absolute_axes_nonorm Why x/y coordinates are not normalized x/y are not given in @ref motion_normalization "normalized coordinates" From 8f0016ba8a1f482f86e2ba423d327a908917d972 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 5 Jan 2016 13:19:56 +1000 Subject: [PATCH 232/255] doc: fix and improve the tablet documentation Signed-off-by: Peter Hutterer --- doc/tablet-support.dox | 94 +++++++++++++++++++++--------------------- src/libinput.h | 42 ++++++++++++------- 2 files changed, 74 insertions(+), 62 deletions(-) diff --git a/doc/tablet-support.dox b/doc/tablet-support.dox index fbe778da..90c2e098 100644 --- a/doc/tablet-support.dox +++ b/doc/tablet-support.dox @@ -16,11 +16,13 @@ surface of the tablet requires a tool, usually in the shape of a stylus. The libinput interface exposed by devices with the @ref LIBINPUT_DEVICE_CAP_TABLET_TOOL applies only to events generated by tools. -Touch events on the tablet itself are exposed -through the @ref LIBINPUT_DEVICE_CAP_TOUCH capability and are often found on -a separate libinput device. See libinput_device_get_device_group() for -information on how to associate the touch part with other devices exposed by -the same physical hardware. +Touch events on the tablet integrated into a screen itself are exposed +through the @ref LIBINPUT_DEVICE_CAP_TOUCH capability. Touch events on a +standalone tablet are exposed through the @ref LIBINPUT_DEVICE_CAP_POINTER +capability. In both cases, the kernel usually provides a separate event +node for the touch device, resulting in a separate libinput device. +See libinput_device_get_device_group() for information on how to associate +the touch part with other devices exposed by the same physical hardware. @section tablet-tip Tool tip events vs. button events @@ -30,8 +32,8 @@ event of type @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, and again when the tip ceases contact with the surface. Tablet tools may send button events; these are exclusively for extra buttons -unrelated to the tip. A button event is independent of the tip and occur -at any time. +unrelated to the tip. A button event is independent of the tip and can while +the tip is down or up. @section tablet-axes Special axes on tablet tools @@ -44,53 +46,28 @@ additionally provide tilt information along the x and y axis. The granularity and precision of these axes varies between tablet devices and cannot usually be mapped into a physical unit. -libinput normalizes distance and pressure into a fixed positive 2-byte -integer range. The tilt axes are normalized into a signed 2-byte integer -range. +libinput normalizes distance and pressure into the [0, 1] range and the tilt +axes into the [-1, 1] range with 0 as the neutral point. While the normalization range is identical for these axes, a caller should -not interpret identical values as identical across axes, i.e. a value V1 on -the distance axis has no relation to the same value V1 on the pressure axis. +not interpret identical values as identical across axes, i.e. a value v1 on +the distance axis has no relation to the same value v1 on the pressure axis. @section tablet-fake-proximity Handling of proximity events -libinput's @ref LIBINPUT_EVENT_TABLET_TOOL_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. +libinput's @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY events notify a caller +when a tool comes into sensor range or leaves the sensor range. On some +tools this range does not represent the physical range but a reduced +tool-specific logical range. If the range is reduced, this is done +transparent to the caller. -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_tablet_tool_get_axis_value(device, - LIBINPUT_TABLET_TOOL_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 +For example, the Wacom mouse and lens cursor tools are usually +used in relative mode, lying flat on the tablet. Movement typically follows +the interaction normal mouse movements have, i.e. slightly lift the tool and +place it in a separate location. 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. For such tools, libinput +provides software-emulated proximity. @section tablet-pressure-offset Pressure offset on worn-out tools @@ -145,4 +122,25 @@ If the tool does not have a unique identifier, libinput creates a single struct libinput_tablet_tool per tool type on each tablet the tool is used on. +@section tablet-tool-types Vendor-specific tablet tool types + +libinput supports a number of high-level tool types that describe the +general interaction expected with the tool. For example, a user would expect +a tool of type @ref LIBINPUT_TABLET_TOOL_TYPE_PEN to interact with a +graphics application taking pressure and tilt into account. The default +virtual tool assigned should be a drawing tool, e.g. a virtual pen or brush. +A tool of type @ref LIBINPUT_TABLET_TOOL_TYPE_ERASER would normally be +mapped to an eraser-like virtual tool. See @ref libinput_tablet_tool_type +for the list of all available tools. + +Vendors may provide more fine-grained information about the tool in use by +adding a hardware-specific tool ID. libinput provides this ID to the caller +with libinput_tablet_tool_get_tool_id() but makes no promises about the +content or format of the ID. + +libinput currently supports Wacom-style tool IDs as provided on the Wacom +Intuos 3, 4, 5, Wacon Cintiq and Wacom Intuos Pro series. The tool ID can +be used to distinguish between e.g. a Wacom Classic Pen or a Wacom Pro Pen. +It is the caller's responsibility to interpret the tool ID. + */ diff --git a/src/libinput.h b/src/libinput.h index 71d28203..f1142340 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -145,6 +145,9 @@ enum libinput_pointer_axis_source { * 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, see @ref tablet-serial-numbers. + * + * This struct is refcounted, use libinput_tablet_tool_ref() and + * libinput_tablet_tool_unref(). */ struct libinput_tablet_tool; @@ -1530,7 +1533,7 @@ libinput_event_tablet_tool_get_y(struct libinput_event_tablet_tool *event); * Returns the current pressure being applied on the tool in use, normalized * to the range [0, 1]. * - * If this axis does not exist on the device, this function returns 0. + * If this axis does not exist on the current tool, this function returns 0. * * @param event The libinput tablet event * @return The current value of the the axis @@ -1544,7 +1547,7 @@ libinput_event_tablet_tool_get_pressure(struct libinput_event_tablet_tool *event * Returns the current distance from the tablet's sensor, normalized to the * range [0, 1]. * - * If this axis does not exist on the device, this function returns 0. + * If this axis does not exist on the current tool, this function returns 0. * * @param event The libinput tablet event * @return The current value of the the axis @@ -1558,7 +1561,7 @@ libinput_event_tablet_tool_get_distance(struct libinput_event_tablet_tool *event * Returns the current tilt along the X axis of the tablet's current logical * orientation, normalized to the range [-1, 1]. * - * If this axis does not exist on the device, this function returns 0. + * If this axis does not exist on the current tool, this function returns 0. * * @param event The libinput tablet event * @return The current value of the the axis @@ -1572,7 +1575,7 @@ libinput_event_tablet_tool_get_tilt_x(struct libinput_event_tablet_tool *event); * Returns the current tilt along the Y axis of the tablet's current logical * orientation, normalized to the range [-1, 1]. * - * If this axis does not exist on the device, this function returns 0. + * If this axis does not exist on the current tool, this function returns 0. * * @param event The libinput tablet event * @return The current value of the the axis @@ -1592,7 +1595,7 @@ libinput_event_tablet_tool_get_tilt_y(struct libinput_event_tablet_tool *event); * LIBINPUT_TABLET_TOOL_TYPE_BRUSH, the logical neutral position is with the * buttons pointing up. * - * If this axis does not exist on the device, this function returns 0. + * If this axis does not exist on the current tool, this function returns 0. * * @param event The libinput tablet event * @return The current value of the the axis @@ -1608,7 +1611,7 @@ libinput_event_tablet_tool_get_rotation(struct libinput_event_tablet_tool *event * the logical center of the axis. This axis is available on e.g. the Wacom * Airbrush. * - * If this axis does not exist on the device, this function returns 0. + * If this axis does not exist on the current tool, this function returns 0. * * @param event The libinput tablet event * @return The current value of the the axis @@ -1684,12 +1687,12 @@ libinput_event_tablet_tool_get_y_transformed(struct libinput_event_tablet_tool * * @ingroup event_tablet * * Returns the tool that was in use during this event. - * By default, a struct libinput_tablet_tool is created on proximity in and - * destroyed on proximity out. The lifetime of the tool may be extended by - * using libinput_tablet_tool_ref() to increment the reference count of the - * tool. This guarantees that the same struct will be used whenever the same - * physical tool comes back into proximity. * + * If the caller holds at least one reference (see + * libinput_tablet_tool_ref()), this struct is used whenever the + * tools enters proximity. Otherwise, if no references remain when the tool + * leaves proximity, the tool may be destroyed. + * * @note Physical tool tracking requires hardware support. If unavailable, * libinput creates one tool per type per tablet. See @ref * tablet-serial-numbers for more details. @@ -1795,7 +1798,8 @@ libinput_event_tablet_tool_get_time_usec(struct libinput_event_tablet_tool *even /** * @ingroup event_tablet * - * Return the type of tool type for a tool object + * Return the type of tool type for a tool object, see @ref + * tablet-tool-types for details. * * @param tool The libinput tool * @return The tool type for this tool object @@ -1810,7 +1814,8 @@ libinput_tablet_tool_get_type(struct libinput_tablet_tool *tool); * * 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_tablet_tool_get_type(). Not all tablets support a tool ID. + * libinput_tablet_tool_get_type(), see @ref tablet-tool-types. 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. @@ -1831,6 +1836,8 @@ libinput_tablet_tool_get_tool_id(struct libinput_tablet_tool *tool); * * @param tool The tool to increment the ref count of * @return The passed tool + * + * @see libinput_tablet_tool_unref */ struct libinput_tablet_tool * libinput_tablet_tool_ref(struct libinput_tablet_tool *tool); @@ -1843,6 +1850,8 @@ libinput_tablet_tool_ref(struct libinput_tablet_tool *tool); * * @param tool The tool to decrement the ref count of * @return NULL if the tool was destroyed otherwise the passed tool + * + * @see libinput_tablet_tool_ref */ struct libinput_tablet_tool * libinput_tablet_tool_unref(struct libinput_tablet_tool *tool); @@ -1939,6 +1948,8 @@ libinput_tablet_tool_has_button(struct libinput_tablet_tool *tool, * * @param tool A tablet tool * @return 1 if the tool can be uniquely identified, 0 otherwise. + * + * @see libinput_tablet_tool_get_serial */ int libinput_tablet_tool_is_unique(struct libinput_tablet_tool *tool); @@ -1947,10 +1958,13 @@ libinput_tablet_tool_is_unique(struct libinput_tablet_tool *tool); * @ingroup event_tablet * * Return the serial number of a tool. If the tool does not report a serial - * number, this function returns zero. + * number, this function returns zero. See @ref tablet-serial-numbers for + * details. * * @param tool The libinput tool * @return The tool serial number + * + * @see libinput_tablet_tool_is_unique */ uint64_t libinput_tablet_tool_get_serial(struct libinput_tablet_tool *tool); From c5b87828ee4641b4a3cd7db8d1b86432283873c7 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 5 Jan 2016 13:33:51 +1000 Subject: [PATCH 233/255] doc: add missing tip event to the allowed set of events We can call the various has_changed() functions on a tip event. Signed-off-by: Peter Hutterer --- doc/tablet-support.dox | 4 +-- src/libinput.h | 56 ++++++++++++++++++++++++++++-------------- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/doc/tablet-support.dox b/doc/tablet-support.dox index 90c2e098..c95d8052 100644 --- a/doc/tablet-support.dox +++ b/doc/tablet-support.dox @@ -66,8 +66,8 @@ used in relative mode, lying flat on the tablet. Movement typically follows the interaction normal mouse movements have, i.e. slightly lift the tool and place it in a separate location. 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. For such tools, libinput -provides software-emulated proximity. +tool may not be lifted out of physical proximity. For such tools, libinput +provides software-emulated proximity. @section tablet-pressure-offset Pressure offset on worn-out tools diff --git a/src/libinput.h b/src/libinput.h index f1142340..e29b01a6 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1348,8 +1348,10 @@ libinput_event_tablet_tool_get_base_event(struct libinput_event_tablet_tool *eve * LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. * - * @note It is an application bug to call this function for events other than - * @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS and @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. + * @note It is an application bug to call this function for events other + * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref + * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref + * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. * * @param event The libinput tablet event * @return 1 if the axis was updated or 0 otherwise @@ -1366,8 +1368,10 @@ libinput_event_tablet_tool_x_has_changed( * LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. * - * @note It is an application bug to call this function for events other than - * @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS and @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. + * @note It is an application bug to call this function for events other + * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref + * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref + * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. * * @param event The libinput tablet event * @return 1 if the axis was updated or 0 otherwise @@ -1384,8 +1388,10 @@ libinput_event_tablet_tool_y_has_changed( * LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. * - * @note It is an application bug to call this function for events other than - * @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS and @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. + * @note It is an application bug to call this function for events other + * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref + * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref + * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. * * @param event The libinput tablet event * @return 1 if the axis was updated or 0 otherwise @@ -1401,9 +1407,13 @@ libinput_event_tablet_tool_pressure_has_changed( * For tablet events that are not of type @ref * LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. + * For tablet events of type @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this + * function always returns 1. * - * @note It is an application bug to call this function for events other than - * @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS and @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. + * @note It is an application bug to call this function for events other + * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref + * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref + * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. * * @param event The libinput tablet event * @return 1 if the axis was updated or 0 otherwise @@ -1420,8 +1430,10 @@ libinput_event_tablet_tool_distance_has_changed( * LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. * - * @note It is an application bug to call this function for events other than - * @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS and @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. + * @note It is an application bug to call this function for events other + * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref + * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref + * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. * * @param event The libinput tablet event * @return 1 if the axis was updated or 0 otherwise @@ -1438,8 +1450,10 @@ libinput_event_tablet_tool_tilt_x_has_changed( * LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. * - * @note It is an application bug to call this function for events other than - * @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS and @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. + * @note It is an application bug to call this function for events other + * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref + * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref + * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. * * @param event The libinput tablet event * @return 1 if the axis was updated or 0 otherwise @@ -1455,8 +1469,10 @@ libinput_event_tablet_tool_tilt_y_has_changed( * LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. * - * @note It is an application bug to call this function for events other than - * @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS and @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. + * @note It is an application bug to call this function for events other + * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref + * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref + * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. * * @param event The libinput tablet event * @return 1 if the axis was updated or 0 otherwise @@ -1472,8 +1488,10 @@ libinput_event_tablet_tool_rotation_has_changed( * LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. * - * @note It is an application bug to call this function for events other than - * @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS and @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. + * @note It is an application bug to call this function for events other + * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref + * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref + * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. * * @param event The libinput tablet event * @return 1 if the axis was updated or 0 otherwise @@ -1489,8 +1507,10 @@ libinput_event_tablet_tool_slider_has_changed( * LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref LIBINPUT_EVENT_TABLET_TOOL_TIP, or * @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, this function returns 0. * - * @note It is an application bug to call this function for events other than - * @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS and @ref LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. + * @note It is an application bug to call this function for events other + * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref + * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref + * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. * * @param event The libinput tablet event * @return 1 if the axis was updated or 0 otherwise From 0b124a1a5d5e8d49d2a75af7da741f004b58ebbe Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 5 Jan 2016 14:08:01 +1000 Subject: [PATCH 234/255] tablet: insert "STATE" into proximity/tip states Makes it even longer, but at least it's consistent with button and key state. Signed-off-by: Peter Hutterer Reviewed-by: Jason Gerecke --- src/evdev-tablet.c | 4 ++-- src/libinput.c | 6 +++--- src/libinput.h | 8 ++++---- test/tablet.c | 28 ++++++++++++++-------------- tools/event-debug.c | 4 ++-- tools/event-gui.c | 2 +- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 7804c91c..8eb69a56 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -513,7 +513,7 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, tablet_notify_proximity(&device->base, time, tool, - LIBINPUT_TABLET_TOOL_PROXIMITY_IN, + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN, tablet->changed_axes, axes); } else { @@ -1230,7 +1230,7 @@ tablet_flush(struct tablet_dispatch *tablet, tablet_notify_proximity(&device->base, time, tool, - LIBINPUT_TABLET_TOOL_PROXIMITY_OUT, + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT, tablet->changed_axes, tablet->axes); diff --git a/src/libinput.c b/src/libinput.c index 3a10df43..d73637a8 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -2170,7 +2170,7 @@ tablet_notify_axis(struct libinput_device *device, *axis_event = (struct libinput_event_tablet_tool) { .time = time, .tool = tool, - .proximity_state = LIBINPUT_TABLET_TOOL_PROXIMITY_IN, + .proximity_state = LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN, .tip_state = tip_state, .wheel_discrete = wheel_discrete, }; @@ -2238,7 +2238,7 @@ tablet_notify_tip(struct libinput_device *device, .time = time, .tool = tool, .tip_state = tip_state, - .proximity_state = LIBINPUT_TABLET_TOOL_PROXIMITY_IN, + .proximity_state = LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN, }; memcpy(tip_event->axes, axes, @@ -2276,7 +2276,7 @@ tablet_notify_button(struct libinput_device *device, .button = button, .state = state, .seat_button_count = seat_button_count, - .proximity_state = LIBINPUT_TABLET_TOOL_PROXIMITY_IN, + .proximity_state = LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN, .tip_state = tip_state, }; memcpy(button_event->axes, axes, sizeof(button_event->axes)); diff --git a/src/libinput.h b/src/libinput.h index e29b01a6..9848d59e 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -197,8 +197,8 @@ enum libinput_tablet_tool_type { * distance (a few cm) off the surface. */ enum libinput_tablet_tool_proximity_state { - LIBINPUT_TABLET_TOOL_PROXIMITY_OUT = 0, - LIBINPUT_TABLET_TOOL_PROXIMITY_IN = 1, + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT = 0, + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN = 1, }; /** @@ -284,9 +284,9 @@ enum libinput_event_type { * with @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS events. * * Some tools may always be in proximity. For these tools, events of - * type @ref LIBINPUT_TABLET_TOOL_PROXIMITY_IN are sent only once after @ref + * type @ref LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN are sent only once after @ref * LIBINPUT_EVENT_DEVICE_ADDED, and events of type @ref - * LIBINPUT_TABLET_TOOL_PROXIMITY_OUT are sent only once before @ref + * LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT are sent only once before @ref * LIBINPUT_EVENT_DEVICE_REMOVED. * * If the tool that comes into proximity supports x/y coordinates, diff --git a/test/tablet.c b/test/tablet.c index 3c509e77..6c5d625c 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -100,7 +100,7 @@ START_TEST(tip_down_prox_in) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); ck_assert_int_eq(libinput_event_tablet_tool_get_proximity_state(tablet_event), - LIBINPUT_TABLET_TOOL_PROXIMITY_IN); + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); libinput_event_destroy(event); libinput_dispatch(li); @@ -150,7 +150,7 @@ START_TEST(tip_up_prox_out) tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); ck_assert_int_eq(libinput_event_tablet_tool_get_proximity_state(tablet_event), - LIBINPUT_TABLET_TOOL_PROXIMITY_OUT); + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); libinput_event_destroy(event); litest_assert_empty_queue(li); @@ -601,7 +601,7 @@ START_TEST(proximity_in_out) libinput_event_get_tablet_tool_event(event); if (libinput_event_tablet_tool_get_proximity_state(t) == - LIBINPUT_TABLET_TOOL_PROXIMITY_OUT) + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT) have_proximity_out = true; } @@ -641,7 +641,7 @@ START_TEST(proximity_in_button_down) libinput_dispatch(li); litest_assert_tablet_proximity_event(li, - LIBINPUT_TABLET_TOOL_PROXIMITY_IN); + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); litest_assert_tablet_button_event(li, BTN_STYLUS, LIBINPUT_BUTTON_STATE_PRESSED); @@ -674,7 +674,7 @@ START_TEST(proximity_out_button_up) BTN_STYLUS, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_tablet_proximity_event(li, - LIBINPUT_TABLET_TOOL_PROXIMITY_OUT); + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); litest_assert_empty_queue(li); } END_TEST @@ -892,13 +892,13 @@ START_TEST(proximity_range_enter) libinput_dispatch(li); litest_assert_tablet_proximity_event(li, - LIBINPUT_TABLET_TOOL_PROXIMITY_IN); + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); litest_axis_set_value(axes, ABS_DISTANCE, 90); litest_tablet_motion(dev, 10, 10, axes); libinput_dispatch(li); litest_assert_tablet_proximity_event(li, - LIBINPUT_TABLET_TOOL_PROXIMITY_OUT); + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); litest_tablet_proximity_out(dev); litest_assert_empty_queue(li); @@ -927,13 +927,13 @@ START_TEST(proximity_range_in_out) litest_pop_event_frame(dev); libinput_dispatch(li); litest_assert_tablet_proximity_event(li, - LIBINPUT_TABLET_TOOL_PROXIMITY_IN); + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); litest_axis_set_value(axes, ABS_DISTANCE, 90); litest_tablet_motion(dev, 10, 10, axes); libinput_dispatch(li); litest_assert_tablet_proximity_event(li, - LIBINPUT_TABLET_TOOL_PROXIMITY_OUT); + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); litest_tablet_motion(dev, 30, 30, axes); litest_assert_empty_queue(li); @@ -942,11 +942,11 @@ START_TEST(proximity_range_in_out) litest_tablet_motion(dev, 10, 10, axes); libinput_dispatch(li); litest_assert_tablet_proximity_event(li, - LIBINPUT_TABLET_TOOL_PROXIMITY_IN); + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); litest_tablet_proximity_out(dev); litest_assert_tablet_proximity_event(li, - LIBINPUT_TABLET_TOOL_PROXIMITY_OUT); + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); litest_assert_empty_queue(li); } END_TEST @@ -1022,7 +1022,7 @@ START_TEST(proximity_range_button_press) BTN_STYLUS, LIBINPUT_BUTTON_STATE_RELEASED); litest_assert_tablet_proximity_event(li, - LIBINPUT_TABLET_TOOL_PROXIMITY_OUT); + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); litest_event(dev, EV_KEY, BTN_STYLUS, 0); litest_event(dev, EV_SYN, SYN_REPORT, 0); @@ -1062,7 +1062,7 @@ START_TEST(proximity_range_button_release) libinput_dispatch(li); litest_assert_tablet_proximity_event(li, - LIBINPUT_TABLET_TOOL_PROXIMITY_IN); + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); /* expect fake button press */ litest_assert_tablet_button_event(li, BTN_STYLUS, @@ -1078,7 +1078,7 @@ START_TEST(proximity_range_button_release) litest_tablet_proximity_out(dev); litest_assert_tablet_proximity_event(li, - LIBINPUT_TABLET_TOOL_PROXIMITY_OUT); + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT); } END_TEST diff --git a/tools/event-debug.c b/tools/event-debug.c index ddebc136..48f6e948 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -449,10 +449,10 @@ print_proximity_event(struct libinput_event *ev) print_event_time(libinput_event_tablet_tool_get_time(t)); - if (state == LIBINPUT_TABLET_TOOL_PROXIMITY_IN) { + if (state == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN) { print_tablet_axes(t); state_str = "proximity-in"; - } else if (state == LIBINPUT_TABLET_TOOL_PROXIMITY_OUT) { + } else if (state == LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT) { state_str = "proximity-out"; printf("\t"); } else { diff --git a/tools/event-gui.c b/tools/event-gui.c index 64a84da1..a2691d9e 100644 --- a/tools/event-gui.c +++ b/tools/event-gui.c @@ -605,7 +605,7 @@ handle_event_tablet(struct libinput_event *ev, struct window *w) switch (libinput_event_get_type(ev)) { case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: if (libinput_event_tablet_tool_get_proximity_state(t) == - LIBINPUT_TABLET_TOOL_PROXIMITY_OUT) { + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT) { w->tool.x_in = 0; w->tool.y_in = 0; w->tool.x_down = 0; From b71aa64fbfeb32d084ea08cdc5067b8551d1682b Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 6 Jan 2016 13:31:17 +1000 Subject: [PATCH 235/255] doc: fix two grammar issues "of tablet tool" -> "of the tablet tool" Signed-off-by: Peter Hutterer --- src/libinput.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libinput.h b/src/libinput.h index 9848d59e..ab57b4cb 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1522,8 +1522,8 @@ libinput_event_tablet_tool_wheel_has_changed( /** * @ingroup event_tablet * - * Returns the X coordinate of tablet tool, in mm from the top left corner - * of the tablet in its current logical orientation. Use + * Returns the X coordinate of the tablet tool, in mm from the top left + * corner of the tablet in its current logical orientation. Use * libinput_event_tablet_tool_get_x_transformed() for transforming the axis * value into a different coordinate space. * @@ -1536,8 +1536,8 @@ libinput_event_tablet_tool_get_x(struct libinput_event_tablet_tool *event); /** * @ingroup event_tablet * - * Returns the Y coordinate of tablet tool, in mm from the top left corner - * of the tablet in its current logical orientation. Use + * Returns the Y coordinate of the tablet tool, in mm from the top left + * corner of the tablet in its current logical orientation. Use * libinput_event_tablet_tool_get_y_transformed() for transforming the axis * value into a different coordinate space. * From a28c198e2a44bea044c352c2c5b629e7510318da Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 6 Jan 2016 14:47:47 +1000 Subject: [PATCH 236/255] tablet: whitespace fix Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 8eb69a56..6ca2c185 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -286,8 +286,7 @@ normalize_wheel(struct tablet_dispatch *tablet, } static inline struct device_coords -tablet_handle_xy(struct tablet_dispatch *tablet, - struct evdev_device *device) +tablet_handle_xy(struct tablet_dispatch *tablet, struct evdev_device *device) { struct device_coords point; const struct input_absinfo *absinfo; From d51c8f94205780d15154e7aac72cc34a251ebe3f Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 21 Dec 2015 12:53:00 +1000 Subject: [PATCH 237/255] tablet: always set the pressure offset Signed-off-by: Peter Hutterer Acked-by: Jason Gerecke --- src/evdev-tablet.c | 8 ++++++++ src/libinput-private.h | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 6ca2c185..f1b22f1f 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -881,6 +881,8 @@ tablet_get_tool(struct tablet_dispatch *tablet, /* If we didn't already have the new_tool in our list of tools, * add it */ if (!tool) { + const struct input_absinfo *pressure; + tool = zalloc(sizeof *tool); *tool = (struct libinput_tablet_tool) { .type = type, @@ -891,6 +893,12 @@ tablet_get_tool(struct tablet_dispatch *tablet, tool->pressure_offset = 0; tool->has_pressure_offset = false; + + pressure = libevdev_get_abs_info(tablet->device->evdev, + ABS_PRESSURE); + if (pressure) + tool->pressure_offset = pressure->minimum; + tool_set_bits(tablet, tool); list_insert(tool_list, &tool->link); diff --git a/src/libinput-private.h b/src/libinput-private.h index 246986e1..3d714af8 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -277,7 +277,7 @@ struct libinput_tablet_tool { int refcount; void *user_data; - int pressure_offset; + int pressure_offset; /* in device coordinates */ bool has_pressure_offset; }; From 8d79b718fd252c7e813cc8fac0bff7d064c0c524 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 14 Dec 2015 08:05:32 +1000 Subject: [PATCH 238/255] test: fix a bunch of tablet tests for pressure threshold introduction Preparation work for a pressure threshold where we can't just send a BTN_TOUCH and expect it to trigger the tip event. So the event sequence now needs to resemble the right order so the threshold will be triggered. In some cases requires processing an axis event before the tip event. That behavior will be changed in a follow-up commit. It also requires that all tablets set ABS_PRESSURE on proximity in. Signed-off-by: Peter Hutterer Acked-by: Jason Gerecke --- test/litest-device-huion-pentablet.c | 1 + test/litest-device-wacom-isdv4-tablet.c | 1 + test/litest-device-waltop-tablet.c | 1 + test/tablet.c | 209 ++++++++++++++++++++---- 4 files changed, 182 insertions(+), 30 deletions(-) diff --git a/test/litest-device-huion-pentablet.c b/test/litest-device-huion-pentablet.c index 6be659b6..e030f208 100644 --- a/test/litest-device-huion-pentablet.c +++ b/test/litest-device-huion-pentablet.c @@ -36,6 +36,7 @@ static void litest_huion_tablet_setup(void) 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_PRESSURE, .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 }, diff --git a/test/litest-device-wacom-isdv4-tablet.c b/test/litest-device-wacom-isdv4-tablet.c index bc607057..400fb57b 100644 --- a/test/litest-device-wacom-isdv4-tablet.c +++ b/test/litest-device-wacom-isdv4-tablet.c @@ -36,6 +36,7 @@ static void litest_wacom_isdv4_tablet_setup(void) 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_PRESSURE, .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 }, diff --git a/test/litest-device-waltop-tablet.c b/test/litest-device-waltop-tablet.c index 8b6de526..880ddf3e 100644 --- a/test/litest-device-waltop-tablet.c +++ b/test/litest-device-waltop-tablet.c @@ -38,6 +38,7 @@ static struct input_event proximity_in[] = { { .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_ABS, .code = ABS_PRESSURE, .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 }, diff --git a/test/tablet.c b/test/tablet.c index 6c5d625c..76dfe804 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -42,16 +42,27 @@ START_TEST(tip_down_up) struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, { -1, -1 } }; litest_tablet_proximity_in(dev, 10, 10, axes); litest_drain_events(li); + litest_axis_set_value(axes, ABS_DISTANCE, 0); + litest_axis_set_value(axes, ABS_PRESSURE, 30); + litest_push_event_frame(dev); + litest_tablet_motion(dev, 10, 10, axes); litest_event(dev, EV_KEY, BTN_TOUCH, 1); - litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_pop_event_frame(dev); libinput_dispatch(li); + + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + libinput_event_destroy(event); + event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); @@ -60,10 +71,19 @@ START_TEST(tip_down_up) libinput_event_destroy(event); litest_assert_empty_queue(li); + litest_axis_set_value(axes, ABS_DISTANCE, 10); + litest_axis_set_value(axes, ABS_PRESSURE, 0); + litest_push_event_frame(dev); + litest_tablet_motion(dev, 10, 10, axes); litest_event(dev, EV_KEY, BTN_TOUCH, 0); - litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_pop_event_frame(dev); libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + libinput_event_destroy(event); + event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); @@ -84,7 +104,8 @@ START_TEST(tip_down_prox_in) struct libinput_event *event; struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { - { ABS_DISTANCE, 10 }, + { ABS_DISTANCE, 0 }, + { ABS_PRESSURE, 30 }, { -1, -1 } }; @@ -92,6 +113,7 @@ START_TEST(tip_down_prox_in) litest_push_event_frame(dev); litest_tablet_proximity_in(dev, 10, 10, axes); + litest_tablet_motion(dev, 10, 10, axes); litest_event(dev, EV_KEY, BTN_TOUCH, 1); litest_pop_event_frame(dev); @@ -123,7 +145,8 @@ START_TEST(tip_up_prox_out) struct libinput_event *event; struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { - { ABS_DISTANCE, 10 }, + { ABS_DISTANCE, 0 }, + { ABS_PRESSURE, 30 }, { -1, -1 } }; @@ -132,7 +155,10 @@ START_TEST(tip_up_prox_out) litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_drain_events(li); + litest_axis_set_value(axes, ABS_DISTANCE, 30); + litest_axis_set_value(axes, ABS_PRESSURE, 0); litest_push_event_frame(dev); + litest_tablet_motion(dev, 10, 10, axes); litest_event(dev, EV_KEY, BTN_TOUCH, 0); litest_tablet_proximity_out(dev); litest_pop_event_frame(dev); @@ -165,20 +191,32 @@ START_TEST(tip_up_btn_change) struct libinput_event *event; struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { - { ABS_DISTANCE, 10 }, + { ABS_DISTANCE, 0 }, + { ABS_PRESSURE, 30 }, { -1, -1 } }; + litest_push_event_frame(dev); litest_tablet_proximity_in(dev, 10, 10, axes); + litest_tablet_motion(dev, 10, 10, axes); litest_event(dev, EV_KEY, BTN_TOUCH, 1); - litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_pop_event_frame(dev); litest_drain_events(li); + litest_axis_set_value(axes, ABS_DISTANCE, 30); + litest_axis_set_value(axes, ABS_PRESSURE, 0); + litest_push_event_frame(dev); + litest_tablet_motion(dev, 10, 20, axes); litest_event(dev, EV_KEY, BTN_STYLUS, 1); litest_event(dev, EV_KEY, BTN_TOUCH, 0); - litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_pop_event_frame(dev); libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + libinput_event_destroy(event); + event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); @@ -188,7 +226,6 @@ START_TEST(tip_up_btn_change) LIBINPUT_BUTTON_STATE_PRESSED); libinput_event_destroy(event); - libinput_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); @@ -198,16 +235,29 @@ START_TEST(tip_up_btn_change) litest_assert_empty_queue(li); + litest_axis_set_value(axes, ABS_DISTANCE, 0); + litest_axis_set_value(axes, ABS_PRESSURE, 30); + litest_push_event_frame(dev); + litest_tablet_motion(dev, 10, 10, axes); litest_event(dev, EV_KEY, BTN_TOUCH, 1); - litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_pop_event_frame(dev); litest_drain_events(li); /* same thing with a release at tip-up */ + litest_axis_set_value(axes, ABS_DISTANCE, 30); + litest_axis_set_value(axes, ABS_PRESSURE, 0); + litest_push_event_frame(dev); + litest_tablet_motion(dev, 10, 10, axes); litest_event(dev, EV_KEY, BTN_TOUCH, 0); litest_event(dev, EV_KEY, BTN_STYLUS, 0); - litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_pop_event_frame(dev); libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + libinput_event_destroy(event); + event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_BUTTON); @@ -237,17 +287,27 @@ START_TEST(tip_down_btn_change) struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, { -1, -1 } }; litest_tablet_proximity_in(dev, 10, 10, axes); litest_drain_events(li); + litest_axis_set_value(axes, ABS_DISTANCE, 0); + litest_axis_set_value(axes, ABS_PRESSURE, 30); + litest_push_event_frame(dev); + litest_tablet_motion(dev, 10, 20, axes); litest_event(dev, EV_KEY, BTN_STYLUS, 1); litest_event(dev, EV_KEY, BTN_TOUCH, 1); - litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_pop_event_frame(dev); libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + libinput_event_destroy(event); + event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); @@ -267,16 +327,29 @@ START_TEST(tip_down_btn_change) litest_assert_empty_queue(li); + litest_axis_set_value(axes, ABS_DISTANCE, 30); + litest_axis_set_value(axes, ABS_PRESSURE, 0); + litest_push_event_frame(dev); + litest_tablet_motion(dev, 10, 20, axes); litest_event(dev, EV_KEY, BTN_TOUCH, 0); - litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_pop_event_frame(dev); litest_drain_events(li); /* same thing with a release at tip-down */ + litest_axis_set_value(axes, ABS_DISTANCE, 0); + litest_axis_set_value(axes, ABS_PRESSURE, 30); + litest_push_event_frame(dev); + litest_tablet_motion(dev, 10, 20, axes); litest_event(dev, EV_KEY, BTN_TOUCH, 1); litest_event(dev, EV_KEY, BTN_STYLUS, 0); - litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_pop_event_frame(dev); libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + libinput_event_destroy(event); + event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); @@ -306,6 +379,7 @@ START_TEST(tip_down_motion) struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, { -1, -1 } }; double x, y, last_x, last_y; @@ -313,6 +387,8 @@ START_TEST(tip_down_motion) litest_tablet_proximity_in(dev, 10, 10, axes); litest_drain_events(li); + litest_axis_set_value(axes, ABS_DISTANCE, 0); + litest_axis_set_value(axes, ABS_PRESSURE, 20); litest_push_event_frame(dev); litest_tablet_motion(dev, 70, 70, axes); litest_event(dev, EV_KEY, BTN_TOUCH, 1); @@ -350,16 +426,21 @@ START_TEST(tip_up_motion) struct libinput_event *event; struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { - { ABS_DISTANCE, 10 }, + { ABS_DISTANCE, 0 }, + { ABS_PRESSURE, 20 }, { -1, -1 } }; double x, y, last_x, last_y; + litest_push_event_frame(dev); litest_tablet_proximity_in(dev, 10, 10, axes); + litest_tablet_motion(dev, 70, 70, axes); litest_event(dev, EV_KEY, BTN_TOUCH, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_pop_event_frame(dev); litest_drain_events(li); + litest_axis_set_value(axes, ABS_PRESSURE, 0); litest_push_event_frame(dev); litest_tablet_motion(dev, 70, 70, axes); litest_event(dev, EV_KEY, BTN_TOUCH, 0); @@ -398,6 +479,7 @@ START_TEST(tip_state_proximity) struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, { -1, -1 } }; @@ -413,10 +495,20 @@ START_TEST(tip_state_proximity) LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); + litest_axis_set_value(axes, ABS_PRESSURE, 30); + litest_axis_set_value(axes, ABS_DISTANCE, 0); + litest_push_event_frame(dev); + litest_tablet_motion(dev, 10, 10, axes); litest_event(dev, EV_KEY, BTN_TOUCH, 1); - litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_pop_event_frame(dev); + + litest_axis_set_value(axes, ABS_PRESSURE, 0); + litest_axis_set_value(axes, ABS_DISTANCE, 10); + litest_push_event_frame(dev); + litest_tablet_motion(dev, 10, 10, axes); litest_event(dev, EV_KEY, BTN_TOUCH, 0); - litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_pop_event_frame(dev); + litest_drain_events(li); litest_tablet_proximity_out(dev); @@ -439,6 +531,7 @@ START_TEST(tip_state_axis) struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, { -1, -1 } }; @@ -455,8 +548,12 @@ START_TEST(tip_state_axis) LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); + litest_axis_set_value(axes, ABS_PRESSURE, 30); + litest_axis_set_value(axes, ABS_DISTANCE, 0); + litest_push_event_frame(dev); + litest_tablet_motion(dev, 40, 40, axes); litest_event(dev, EV_KEY, BTN_TOUCH, 1); - litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_pop_event_frame(dev); litest_drain_events(li); litest_tablet_motion(dev, 30, 30, axes); @@ -469,8 +566,12 @@ START_TEST(tip_state_axis) LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); + litest_axis_set_value(axes, ABS_PRESSURE, 0); + litest_axis_set_value(axes, ABS_DISTANCE, 10); + litest_push_event_frame(dev); + litest_tablet_motion(dev, 40, 40, axes); litest_event(dev, EV_KEY, BTN_TOUCH, 0); - litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_pop_event_frame(dev); litest_drain_events(li); litest_tablet_motion(dev, 40, 80, axes); @@ -495,6 +596,7 @@ START_TEST(tip_state_button) struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, { -1, -1 } }; @@ -512,8 +614,12 @@ START_TEST(tip_state_button) LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); + litest_axis_set_value(axes, ABS_PRESSURE, 30); + litest_axis_set_value(axes, ABS_DISTANCE, 0); + litest_push_event_frame(dev); + litest_tablet_motion(dev, 40, 40, axes); litest_event(dev, EV_KEY, BTN_TOUCH, 1); - litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_pop_event_frame(dev); litest_drain_events(li); litest_event(dev, EV_KEY, BTN_STYLUS, 0); @@ -527,8 +633,12 @@ START_TEST(tip_state_button) LIBINPUT_TABLET_TOOL_TIP_DOWN); libinput_event_destroy(event); + litest_axis_set_value(axes, ABS_PRESSURE, 0); + litest_axis_set_value(axes, ABS_DISTANCE, 10); + litest_push_event_frame(dev); + litest_tablet_motion(dev, 40, 40, axes); litest_event(dev, EV_KEY, BTN_TOUCH, 0); - litest_event(dev, EV_SYN, SYN_REPORT, 0); + litest_pop_event_frame(dev); litest_drain_events(li); litest_event(dev, EV_KEY, BTN_STYLUS, 1); @@ -568,6 +678,7 @@ START_TEST(proximity_in_out) struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, { -1, -1 } }; @@ -629,6 +740,7 @@ START_TEST(proximity_in_button_down) struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, { -1, -1 } }; @@ -655,6 +767,7 @@ START_TEST(proximity_out_button_up) struct libinput *li = dev->libinput; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, { -1, -1 } }; @@ -689,6 +802,7 @@ START_TEST(proximity_out_clear_buttons) struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, { -1, -1 } }; @@ -753,6 +867,7 @@ START_TEST(proximity_has_axes) struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, { ABS_TILT_X, 10 }, { ABS_TILT_Y, 10 }, { -1, -1} @@ -1093,6 +1208,7 @@ START_TEST(motion) enum libinput_event_type type; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, { -1, -1 } }; @@ -1185,6 +1301,7 @@ START_TEST(left_handed) double x, y; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, { -1, -1 } }; @@ -1298,6 +1415,7 @@ START_TEST(left_handed_tilt) enum libinput_config_status status; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, { ABS_TILT_X, 90 }, { ABS_TILT_Y, 10 }, { -1, -1 } @@ -1336,6 +1454,7 @@ START_TEST(motion_event_state) struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, { -1, -1 } }; @@ -1716,6 +1835,7 @@ START_TEST(pad_buttons_ignored) struct libinput_event *event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, { -1, -1 } }; int button; @@ -1908,6 +2028,7 @@ START_TEST(tool_in_prox_before_start) struct libinput_event *event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, { ABS_TILT_X, 0 }, { ABS_TILT_Y, 0 }, { -1, -1 } @@ -2058,6 +2179,7 @@ START_TEST(mouse_rotation) struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, { ABS_TILT_X, 0 }, { ABS_TILT_Y, 0 }, { -1, -1 } @@ -2380,6 +2502,7 @@ START_TEST(tablet_time_usec) struct libinput_event_tablet_tool *tev; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, { -1, -1 } }; @@ -2488,6 +2611,7 @@ START_TEST(tablet_calibration_set_matrix_delta) struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, { -1, -1 } }; int has_calibration; @@ -2564,6 +2688,7 @@ START_TEST(tablet_calibration_set_matrix) struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, { -1, -1 } }; int has_calibration; @@ -2641,8 +2766,11 @@ START_TEST(tablet_pressure_offset) litest_tablet_proximity_in(dev, 5, 100, axes); litest_drain_events(li); + /* Put the pen down, with a pressure high enough to meet the + * threshold */ litest_axis_set_value(axes, ABS_DISTANCE, 0); - litest_axis_set_value(axes, ABS_PRESSURE, 21); + litest_axis_set_value(axes, ABS_PRESSURE, 25); + litest_push_event_frame(dev); litest_tablet_motion(dev, 70, 70, axes); litest_event(dev, EV_KEY, BTN_TOUCH, 1); @@ -2650,7 +2778,9 @@ START_TEST(tablet_pressure_offset) libinput_dispatch(li); litest_drain_events(li); - litest_axis_set_value(axes, ABS_PRESSURE, 20); + /* Reduce pressure to just a tick over the offset, otherwise we get + * the tip up event again */ + litest_axis_set_value(axes, ABS_PRESSURE, 20.1); litest_tablet_motion(dev, 70, 70, axes); libinput_dispatch(li); @@ -2658,6 +2788,10 @@ START_TEST(tablet_pressure_offset) tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS); pressure = libinput_event_tablet_tool_get_pressure(tev); + + /* we can't actually get a real 0.0 because that would trigger a tip + * up. but it's close enough to zero that ck_assert_double_eq won't + * notice */ ck_assert_double_eq(pressure, 0.0); libinput_event_destroy(event); @@ -2695,28 +2829,33 @@ START_TEST(tablet_pressure_offset_decrease) /* offset 20 on prox in */ litest_tablet_proximity_in(dev, 5, 100, axes); + litest_tablet_proximity_out(dev); litest_drain_events(li); /* a reduced pressure value must reduce the offset */ - litest_axis_set_value(axes, ABS_DISTANCE, 0); litest_axis_set_value(axes, ABS_PRESSURE, 10); - litest_push_event_frame(dev); - litest_tablet_motion(dev, 70, 70, axes); - litest_event(dev, EV_KEY, BTN_TOUCH, 1); - litest_pop_event_frame(dev); - libinput_dispatch(li); + litest_tablet_proximity_in(dev, 5, 100, axes); + litest_tablet_proximity_out(dev); + litest_drain_events(li); + /* a reduced pressure value must reduce the offset */ + litest_tablet_proximity_in(dev, 5, 100, axes); + libinput_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_TOOL_AXIS); + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); pressure = libinput_event_tablet_tool_get_pressure(tev); ck_assert_double_eq(pressure, 0.0); libinput_event_destroy(event); litest_drain_events(li); - litest_axis_set_value(axes, ABS_PRESSURE, 11); + /* trigger the pressure threshold */ + litest_axis_set_value(axes, ABS_PRESSURE, 15); + litest_push_event_frame(dev); litest_tablet_motion(dev, 70, 70, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); + litest_pop_event_frame(dev); libinput_dispatch(li); event = libinput_get_event(li); @@ -2925,6 +3064,7 @@ START_TEST(tilt_available) struct libinput_tablet_tool *tool; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, { ABS_TILT_X, 80 }, { ABS_TILT_Y, 20 }, { -1, -1 } @@ -2954,6 +3094,7 @@ START_TEST(tilt_not_available) struct libinput_tablet_tool *tool; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, { ABS_TILT_X, 80 }, { ABS_TILT_Y, 20 }, { -1, -1 } @@ -2982,6 +3123,7 @@ START_TEST(tilt_x) struct libinput_event_tablet_tool *tev; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, { ABS_TILT_X, 90 }, { ABS_TILT_Y, 0 }, { -1, -1 } @@ -3012,6 +3154,9 @@ START_TEST(tilt_x) expected_tx = -1.0; + litest_axis_set_value(axes, ABS_DISTANCE, 0); + litest_axis_set_value(axes, ABS_PRESSURE, 1); + for (tilt = 0; tilt <= 100; tilt += 5) { litest_axis_set_value(axes, ABS_TILT_X, tilt); litest_tablet_motion(dev, 10, 10, axes); @@ -3045,6 +3190,7 @@ START_TEST(tilt_y) struct libinput_event_tablet_tool *tev; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, { ABS_TILT_X, 0 }, { ABS_TILT_Y, 90 }, { -1, -1 } @@ -3075,6 +3221,9 @@ START_TEST(tilt_y) expected_ty = -1.0; + litest_axis_set_value(axes, ABS_DISTANCE, 0); + litest_axis_set_value(axes, ABS_PRESSURE, 1); + for (tilt = 0; tilt <= 100; tilt += 5) { litest_axis_set_value(axes, ABS_TILT_Y, tilt); litest_tablet_motion(dev, 10, 10, axes); From 96fbf848625c0fb2eb53bd7e55664a96155c46ed Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 11 Dec 2015 17:40:36 +1000 Subject: [PATCH 239/255] tablet: add pressure threshold handling On tablets with ABS_PRESSURE use a pressure value to determine tip state, not BTN_TOUCH. This enables us (down the road) to have device-specific pressure thresholds. For now we use a 5% default for all devices. The threshold is a range, if we go past the upper range we initiate the tip down, if we go below the lower range we release the tip again. This affects two current tests: * Once we have pressure offsets and pressure thresholds, we're biased towards pressure. So we can only check that distance is zero when there is a pressure value, not the other way round. * When the pressure threshold is exceeded on proximity in with a nonzero distance, we can only warn and handle the pressure as normal. Since this is a niche case anyway anything fancier is likely unnecessary. Signed-off-by: Peter Hutterer Acked-by: Jason Gerecke --- doc/tablet-support.dox | 16 +++++++ src/evdev-tablet.c | 98 ++++++++++++++++++++++++++++++++++-------- src/libinput-private.h | 8 ++++ test/tablet.c | 67 ++++++++++------------------- 4 files changed, 126 insertions(+), 63 deletions(-) diff --git a/doc/tablet-support.dox b/doc/tablet-support.dox index c95d8052..5e6f3932 100644 --- a/doc/tablet-support.dox +++ b/doc/tablet-support.dox @@ -35,6 +35,22 @@ Tablet tools may send button events; these are exclusively for extra buttons unrelated to the tip. A button event is independent of the tip and can while the tip is down or up. +Some tablet tools' pressure detection is too sensitive, causing phantom +touches when the user only slightly brushes the surfaces. For example, some +tools are capable of detecting 1 gram of pressure. + +libinput uses a device-specific pressure threshold to determine when the tip +is considered logically down. As a result, libinput may send a nonzero +pressure value while the tip is logically up. Most application can and +should ignore pressure information until they receive the event of type @ref +LIBINPUT_EVENT_TABLET_TOOL_TIP. Applications that require extremely +fine-grained pressure sensitivity should use the pressure data instead of +the tip events. + +Note that the pressure threshold to trigger a logical tip event may be zero +on some devices. On tools without pressure sensitivity, determining when a +tip is down is device-specific. + @section tablet-axes Special axes on tablet tools A tablet tool usually provides additional information beyond x/y positional diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index f1b22f1f..070ac9a1 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -616,10 +616,15 @@ tablet_process_key(struct tablet_dispatch *tablet, e->value); break; case BTN_TOUCH: - if (e->value) - tablet_set_status(tablet, TABLET_TOOL_ENTERING_CONTACT); - else - tablet_set_status(tablet, TABLET_TOOL_LEAVING_CONTACT); + if (!bit_is_set(tablet->axis_caps, + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) { + if (e->value) + tablet_set_status(tablet, + TABLET_TOOL_ENTERING_CONTACT); + else + tablet_set_status(tablet, + TABLET_TOOL_LEAVING_CONTACT); + } break; case BTN_LEFT: case BTN_RIGHT: @@ -843,6 +848,12 @@ tool_set_bits(const struct tablet_dispatch *tablet, } } +static inline int +axis_range_percentage(const struct input_absinfo *a, double percent) +{ + return (a->maximum - a->minimum) * percent/100.0 + a->minimum; +} + static struct libinput_tablet_tool * tablet_get_tool(struct tablet_dispatch *tablet, enum libinput_tablet_tool_type type, @@ -893,12 +904,21 @@ tablet_get_tool(struct tablet_dispatch *tablet, tool->pressure_offset = 0; tool->has_pressure_offset = false; + tool->pressure_threshold.lower = 0; + tool->pressure_threshold.upper = 1; pressure = libevdev_get_abs_info(tablet->device->evdev, ABS_PRESSURE); - if (pressure) + if (pressure) { tool->pressure_offset = pressure->minimum; + /* 5% of the pressure range */ + tool->pressure_threshold.upper = + axis_range_percentage(pressure, 5); + tool->pressure_threshold.lower = + pressure->minimum; + } + tool_set_bits(tablet, tool); list_insert(tool_list, &tool->link); @@ -964,7 +984,8 @@ tablet_notify_buttons(struct tablet_dispatch *tablet, } static void -sanitize_pressure_distance(struct tablet_dispatch *tablet) +sanitize_pressure_distance(struct tablet_dispatch *tablet, + struct libinput_tablet_tool *tool) { bool tool_in_contact; const struct input_absinfo *distance, @@ -973,9 +994,14 @@ sanitize_pressure_distance(struct tablet_dispatch *tablet) distance = libevdev_get_abs_info(tablet->device->evdev, ABS_DISTANCE); pressure = libevdev_get_abs_info(tablet->device->evdev, ABS_PRESSURE); - tool_in_contact = (tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT) || - tablet_has_status(tablet, - TABLET_TOOL_ENTERING_CONTACT)); + if (!pressure || !distance) + return; + + if (!bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE) && + !bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) + return; + + tool_in_contact = (pressure->value > tool->pressure_offset); /* Keep distance and pressure mutually exclusive */ if (distance && @@ -1016,16 +1042,11 @@ sanitize_mouse_lens_rotation(struct tablet_dispatch *tablet) set_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); } -static inline int -axis_range_percentage(const struct input_absinfo *a, int percent) -{ - return (a->maximum - a->minimum) * percent/100 + a->minimum; -} - static void -sanitize_tablet_axes(struct tablet_dispatch *tablet) +sanitize_tablet_axes(struct tablet_dispatch *tablet, + struct libinput_tablet_tool *tool) { - sanitize_pressure_distance(tablet); + sanitize_pressure_distance(tablet, tool); sanitize_mouse_lens_rotation(tablet); } @@ -1084,6 +1105,46 @@ detect_pressure_offset(struct tablet_dispatch *tablet, tool->has_pressure_offset = true; } +static void +detect_tool_contact(struct tablet_dispatch *tablet, + struct evdev_device *device, + struct libinput_tablet_tool *tool) +{ + const struct input_absinfo *p; + int pressure; + + if (!bit_is_set(tool->axis_caps, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) + return; + + /* if we have pressure, always use that for contact, not BTN_TOUCH */ + if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_CONTACT)) + log_bug_libinput(device->base.seat->libinput, + "Invalid status: entering contact\n"); + if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_CONTACT) && + !tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) + log_bug_libinput(device->base.seat->libinput, + "Invalid status: leaving contact\n"); + + p = libevdev_get_abs_info(tablet->device->evdev, ABS_PRESSURE); + if (!p) { + log_bug_libinput(device->base.seat->libinput, + "Missing pressure axis\n"); + return; + } + pressure = p->value; + + if (tool->has_pressure_offset) + pressure -= (tool->pressure_offset - p->minimum); + + if (pressure <= tool->pressure_threshold.lower && + tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT)) { + tablet_set_status(tablet, TABLET_TOOL_LEAVING_CONTACT); + } else if (pressure >= tool->pressure_threshold.upper && + !tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT)) { + tablet_set_status(tablet, TABLET_TOOL_ENTERING_CONTACT); + } +} + static void tablet_mark_all_axes_changed(struct tablet_dispatch *tablet, struct libinput_tablet_tool *tool) @@ -1187,7 +1248,8 @@ tablet_flush(struct tablet_dispatch *tablet, TABLET_TOOL_ENTERING_PROXIMITY)) tablet_mark_all_axes_changed(tablet, tool); detect_pressure_offset(tablet, device, tool); - sanitize_tablet_axes(tablet); + detect_tool_contact(tablet, device, tool); + sanitize_tablet_axes(tablet, tool); tablet_check_notify_axes(tablet, device, time, tool); tablet_unset_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY); diff --git a/src/libinput-private.h b/src/libinput-private.h index 3d714af8..5238e646 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -63,6 +63,12 @@ struct normalized_range_coords { double x, y; }; +/* A threshold with an upper and lower limit */ +struct threshold { + int upper; + int lower; +}; + struct libinput_interface_backend { int (*resume)(struct libinput *libinput); void (*suspend)(struct libinput *libinput); @@ -277,6 +283,8 @@ struct libinput_tablet_tool { int refcount; void *user_data; + /* The pressure threshold assumes a pressure_offset of 0 */ + struct threshold pressure_threshold; int pressure_offset; /* in device coordinates */ bool has_pressure_offset; }; diff --git a/test/tablet.c b/test/tablet.c index 76dfe804..421deb06 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -2528,7 +2528,7 @@ START_TEST(tablet_pressure_distance_exclusive) struct libinput_event_tablet_tool *tev; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, - { ABS_PRESSURE, 20 }, /* see the litest device */ + { ABS_PRESSURE, 0 }, { -1, -1 }, }; double pressure, distance; @@ -2536,6 +2536,7 @@ START_TEST(tablet_pressure_distance_exclusive) litest_tablet_proximity_in(dev, 5, 100, axes); litest_drain_events(li); + litest_axis_set_value(axes, ABS_PRESSURE, 2); litest_tablet_motion(dev, 70, 70, axes); libinput_dispatch(li); @@ -2545,28 +2546,8 @@ START_TEST(tablet_pressure_distance_exclusive) pressure = libinput_event_tablet_tool_get_pressure(tev); distance = libinput_event_tablet_tool_get_distance(tev); - ck_assert_double_eq(pressure, 0.0); - ck_assert_double_ne(distance, 0.0); - - libinput_event_destroy(event); - - litest_axis_set_value(axes, ABS_DISTANCE, 15); - litest_axis_set_value(axes, ABS_PRESSURE, 25); - litest_event(dev, EV_KEY, BTN_TOUCH, 1); - litest_tablet_motion(dev, 30, 30, axes); - libinput_dispatch(li); - - litest_wait_for_event_of_type(li, - LIBINPUT_EVENT_TABLET_TOOL_AXIS, - -1); - event = libinput_get_event(li); - tev = libinput_event_get_tablet_tool_event(event); - - pressure = libinput_event_tablet_tool_get_pressure(tev); - distance = libinput_event_tablet_tool_get_distance(tev); - - ck_assert_double_eq(distance, 0.0); ck_assert_double_ne(pressure, 0.0); + ck_assert_double_eq(distance, 0.0); libinput_event_destroy(event); } @@ -2933,6 +2914,18 @@ START_TEST(tablet_pressure_offset_increase) } END_TEST +static void pressure_threshold_warning(struct libinput *libinput, + enum libinput_log_priority priority, + const char *format, + va_list args) +{ + int *warning_triggered = (int*)libinput_get_user_data(libinput); + + if (priority == LIBINPUT_LOG_PRIORITY_ERROR && + strstr(format, "pressure offset greater")) + (*warning_triggered)++; +} + START_TEST(tablet_pressure_offset_exceed_threshold) { struct litest_device *dev = litest_current_device(); @@ -2945,40 +2938,24 @@ START_TEST(tablet_pressure_offset_exceed_threshold) { -1, -1 }, }; double pressure; + int warning_triggered = 0; litest_drain_events(li); - litest_disable_log_handler(li); + libinput_set_user_data(li, &warning_triggered); + + libinput_log_set_handler(li, pressure_threshold_warning); litest_tablet_proximity_in(dev, 5, 100, axes); libinput_dispatch(li); event = libinput_get_event(li); tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); pressure = libinput_event_tablet_tool_get_pressure(tev); - ck_assert_double_eq(pressure, 0.0); - libinput_event_destroy(event); - litest_restore_log_handler(li); - - litest_axis_set_value(axes, ABS_DISTANCE, 0); - litest_axis_set_value(axes, ABS_PRESSURE, 31); - litest_push_event_frame(dev); - litest_tablet_motion(dev, 70, 70, axes); - litest_event(dev, EV_KEY, BTN_TOUCH, 1); - litest_pop_event_frame(dev); - libinput_dispatch(li); - litest_drain_events(li); - - litest_axis_set_value(axes, ABS_PRESSURE, 30); - litest_tablet_motion(dev, 70, 70, axes); - libinput_dispatch(li); - - event = libinput_get_event(li); - tev = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_TOOL_AXIS); - pressure = libinput_event_tablet_tool_get_pressure(tev); ck_assert_double_gt(pressure, 0.0); - libinput_event_destroy(event); + + ck_assert_int_eq(warning_triggered, 1); + litest_restore_log_handler(li); } END_TEST From 1a99977ca027962824cc93be851508c5eeee19d5 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 15 Dec 2015 08:39:56 +1000 Subject: [PATCH 240/255] tablet: a tip event can replace an axis event When we're only dealing with BTN_TOUCH we can make the tip event independent of the axis event. Now that we handle pressure thresholds to trigger tip state this does not work, we'd have to send an axis event with the new pressure and then a tip event. Since the pressure triggers the tip event this seems disconnected. Make the tip event officially capable of carrying axes. A caller can then decide how to forward this to the next layer. Signed-off-by: Peter Hutterer Acked-by: Jason Gerecke --- doc/tablet-support.dox | 3 +- src/evdev-tablet.c | 168 ++++++++++++++++++++++++++--------------- src/libinput-private.h | 1 + src/libinput.c | 4 + src/libinput.h | 28 ++++++- test/tablet.c | 101 ++++++++++--------------- 6 files changed, 179 insertions(+), 126 deletions(-) diff --git a/doc/tablet-support.dox b/doc/tablet-support.dox index 5e6f3932..7207a473 100644 --- a/doc/tablet-support.dox +++ b/doc/tablet-support.dox @@ -45,7 +45,8 @@ pressure value while the tip is logically up. Most application can and should ignore pressure information until they receive the event of type @ref LIBINPUT_EVENT_TABLET_TOOL_TIP. Applications that require extremely fine-grained pressure sensitivity should use the pressure data instead of -the tip events. +the tip events to determine a logical tip down state and treat the tip +events like axis events otherwise. Note that the pressure threshold to trigger a logical tip event may be zero on some devices. On tools without pressure sensitivity, determining when a diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 070ac9a1..1dc607be 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -452,13 +452,14 @@ tablet_handle_wheel(struct tablet_dispatch *tablet, return tablet->axes[a]; } -static void +static bool tablet_check_notify_axes(struct tablet_dispatch *tablet, struct evdev_device *device, - uint64_t time, - struct libinput_tablet_tool *tool) + struct libinput_tablet_tool *tool, + double *axes_out, + size_t axes_sz, + int *wheel_discrete_out) { - struct libinput_device *base = &device->base; double axes[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1] = {0}; int wheel_discrete = 0; struct device_coords point; @@ -466,8 +467,9 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, const char tmp[sizeof(tablet->changed_axes)] = {0}; if (memcmp(tmp, tablet->changed_axes, sizeof(tmp)) == 0) - return; + return false; + assert(axes_sz == sizeof(axes)); point = tablet_handle_xy(tablet, device); axes[LIBINPUT_TABLET_TOOL_AXIS_X] = point.x; axes[LIBINPUT_TABLET_TOOL_AXIS_Y] = point.y; @@ -500,41 +502,10 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, axes[LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL] = tablet_handle_wheel(tablet, device, &wheel_discrete); - /* 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 (!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_TABLET_TOOL_PROXIMITY_STATE_IN, - tablet->changed_axes, - axes); - } else { - enum libinput_tablet_tool_tip_state tip_state; + memcpy(axes_out, axes, sizeof(axes)); + *wheel_discrete_out = wheel_discrete; - if (tablet_has_status(tablet, - TABLET_TOOL_IN_CONTACT)) - tip_state = LIBINPUT_TABLET_TOOL_TIP_DOWN; - else - tip_state = LIBINPUT_TABLET_TOOL_TIP_UP; - - tablet_notify_axis(base, - time, - tool, - tip_state, - tablet->changed_axes, - axes, - wheel_discrete); - } - } - - memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes)); + return true; } static void @@ -1215,6 +1186,98 @@ tablet_update_proximity_state(struct tablet_dispatch *tablet, tablet_set_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY); } +static void +tablet_send_axis_proximity_tip_down_events(struct tablet_dispatch *tablet, + struct evdev_device *device, + struct libinput_tablet_tool *tool, + uint64_t time) +{ + double axes[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1] = {0}; + int wheel_discrete = 0; + + /* 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 (tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY)) + goto out; + else if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) { + /* Tool is leaving proximity, we can't rely on the last axis + * information (it'll be mostly 0), so we just get the + * current state and skip over updating the axes. + */ + static_assert(sizeof(axes) == sizeof(tablet->axes), + "Mismatching array sizes"); + memcpy(axes, tablet->axes, sizeof(axes)); + + /* Dont' send an axis event, but we may have a tip event + * update */ + tablet_unset_status(tablet, TABLET_AXES_UPDATED); + } else if (!tablet_check_notify_axes(tablet, + device, + tool, + axes, + sizeof(axes), + &wheel_discrete)) { + goto out; + } + + if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY)) { + tablet_notify_proximity(&device->base, + time, + tool, + LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN, + tablet->changed_axes, + axes); + tablet_unset_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY); + tablet_unset_status(tablet, TABLET_AXES_UPDATED); + } + + if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_CONTACT)) { + tablet_notify_tip(&device->base, + time, + tool, + LIBINPUT_TABLET_TOOL_TIP_DOWN, + tablet->changed_axes, + tablet->axes); + tablet_unset_status(tablet, TABLET_AXES_UPDATED); + tablet_unset_status(tablet, TABLET_TOOL_ENTERING_CONTACT); + tablet_set_status(tablet, TABLET_TOOL_IN_CONTACT); + } else if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_CONTACT)) { + tablet_notify_tip(&device->base, + time, + tool, + LIBINPUT_TABLET_TOOL_TIP_UP, + tablet->changed_axes, + tablet->axes); + tablet_unset_status(tablet, TABLET_AXES_UPDATED); + tablet_unset_status(tablet, TABLET_TOOL_LEAVING_CONTACT); + tablet_unset_status(tablet, TABLET_TOOL_IN_CONTACT); + } else if (tablet_has_status(tablet, TABLET_AXES_UPDATED)) { + enum libinput_tablet_tool_tip_state tip_state; + + if (tablet_has_status(tablet, + TABLET_TOOL_IN_CONTACT)) + tip_state = LIBINPUT_TABLET_TOOL_TIP_DOWN; + else + tip_state = LIBINPUT_TABLET_TOOL_TIP_UP; + + tablet_notify_axis(&device->base, + time, + tool, + tip_state, + tablet->changed_axes, + axes, + wheel_discrete); + tablet_unset_status(tablet, TABLET_AXES_UPDATED); + } + +out: + memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes)); + tablet_unset_status(tablet, TABLET_TOOL_ENTERING_CONTACT); +} + static void tablet_flush(struct tablet_dispatch *tablet, struct evdev_device *device, @@ -1250,21 +1313,12 @@ tablet_flush(struct tablet_dispatch *tablet, detect_pressure_offset(tablet, device, tool); detect_tool_contact(tablet, device, tool); sanitize_tablet_axes(tablet, tool); - 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_TOOL_ENTERING_CONTACT)) { - tablet_notify_tip(&device->base, - time, - tool, - LIBINPUT_TABLET_TOOL_TIP_DOWN, - tablet->axes); - tablet_unset_status(tablet, TABLET_TOOL_ENTERING_CONTACT); - tablet_set_status(tablet, TABLET_TOOL_IN_CONTACT); - } + tablet_send_axis_proximity_tip_down_events(tablet, + device, + tool, + time); if (tablet_has_status(tablet, TABLET_BUTTONS_RELEASED)) { tablet_notify_buttons(tablet, @@ -1284,16 +1338,6 @@ tablet_flush(struct tablet_dispatch *tablet, tablet_unset_status(tablet, TABLET_BUTTONS_PRESSED); } - if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_CONTACT)) { - tablet_notify_tip(&device->base, - time, - tool, - LIBINPUT_TABLET_TOOL_TIP_UP, - tablet->axes); - tablet_unset_status(tablet, TABLET_TOOL_LEAVING_CONTACT); - tablet_unset_status(tablet, TABLET_TOOL_IN_CONTACT); - } - if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) { memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes)); tablet_notify_proximity(&device->base, diff --git a/src/libinput-private.h b/src/libinput-private.h index 5238e646..2dbc555a 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -509,6 +509,7 @@ tablet_notify_tip(struct libinput_device *device, uint64_t time, struct libinput_tablet_tool *tool, enum libinput_tablet_tool_tip_state tip_state, + unsigned char *changed_axes, double *axes); void diff --git a/src/libinput.c b/src/libinput.c index d73637a8..e9883ffd 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -2226,6 +2226,7 @@ tablet_notify_tip(struct libinput_device *device, uint64_t time, struct libinput_tablet_tool *tool, enum libinput_tablet_tool_tip_state tip_state, + unsigned char *changed_axes, double *axes) { struct libinput_event_tablet_tool *tip_event; @@ -2243,6 +2244,9 @@ tablet_notify_tip(struct libinput_device *device, memcpy(tip_event->axes, axes, sizeof(tip_event->axes)); + memcpy(tip_event->changed_axes, + changed_axes, + sizeof(tip_event->changed_axes)); post_device_event(device, time, diff --git a/src/libinput.h b/src/libinput.h index ab57b4cb..7b9236de 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -273,6 +273,10 @@ enum libinput_event_type { * changes from this initial state. It is possible for a tool to * enter and leave proximity without sending an event of type @ref * LIBINPUT_EVENT_TABLET_TOOL_AXIS. + * + * An event of type @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS is sent + * when the tip state does not change. See the documentation for + * @ref LIBINPUT_EVENT_TABLET_TOOL_TIP for more details. */ LIBINPUT_EVENT_TABLET_TOOL_AXIS = 600, /** @@ -309,10 +313,30 @@ enum libinput_event_type { * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY for the tip down event, and * immediately before for the tip up event. * - * If a button and/or axis state change occurs at the same time as a - * tip state change, the order of events is device-dependent. + * The decision when a tip touches the surface is device-dependent + * and may be derived from pressure data or other means. If the tip + * state is changed by axes changing state, the + * @ref LIBINPUT_EVENT_TABLET_TOOL_TIP event includes the changed + * axes and no additional axis event is sent for this state change. + * In other words, a caller must look at both @ref + * LIBINPUT_EVENT_TABLET_TOOL_AXIS and @ref + * LIBINPUT_EVENT_TABLET_TOOL_TIP events to know the current state + * of the axes. + * + * If a button state change occurs at the same time as a tip state + * change, the order of events is device-dependent. */ LIBINPUT_EVENT_TABLET_TOOL_TIP, + /** + * Signals that a tool has changed a logical button state on a + * device with the @ref LIBINPUT_DEVICE_CAP_TABLET_TOOL capability. + * + * Button state changes occur on their own and do not include axis + * state changes. If button and axis state changes occur within the + * same logical hardware event, the order of the @ref + * LIBINPUT_EVENT_TABLET_TOOL_BUTTON and @ref + * LIBINPUT_EVENT_TABLET_TOOL_AXIS event is device-specific. + */ LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN = 800, diff --git a/test/tablet.c b/test/tablet.c index 421deb06..4976d1eb 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -1,5 +1,5 @@ /* - * Copyright © 2014 Red Hat, Inc. + * Copyright © 2014-2015 Red Hat, Inc. * Copyright © 2014 Stephen Chandler "Lyude" Paul * * Permission to use, copy, modify, distribute, and sell this software and @@ -58,11 +58,6 @@ START_TEST(tip_down_up) libinput_dispatch(li); - event = libinput_get_event(li); - tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_TOOL_AXIS); - libinput_event_destroy(event); - event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); @@ -79,11 +74,6 @@ START_TEST(tip_down_up) litest_pop_event_frame(dev); libinput_dispatch(li); - event = libinput_get_event(li); - tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_TOOL_AXIS); - libinput_event_destroy(event); - event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); @@ -125,7 +115,6 @@ START_TEST(tip_down_prox_in) LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN); libinput_event_destroy(event); - libinput_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); @@ -212,9 +201,12 @@ START_TEST(tip_up_btn_change) litest_pop_event_frame(dev); libinput_dispatch(li); + event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_TOOL_AXIS); + LIBINPUT_EVENT_TABLET_TOOL_TIP); + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), + LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); event = libinput_get_event(li); @@ -226,13 +218,6 @@ START_TEST(tip_up_btn_change) LIBINPUT_BUTTON_STATE_PRESSED); libinput_event_destroy(event); - event = libinput_get_event(li); - tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_TOOL_TIP); - ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), - LIBINPUT_TABLET_TOOL_TIP_UP); - libinput_event_destroy(event); - litest_assert_empty_queue(li); litest_axis_set_value(axes, ABS_DISTANCE, 0); @@ -253,9 +238,12 @@ START_TEST(tip_up_btn_change) litest_pop_event_frame(dev); libinput_dispatch(li); + event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_TOOL_AXIS); + LIBINPUT_EVENT_TABLET_TOOL_TIP); + ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), + LIBINPUT_TABLET_TOOL_TIP_UP); libinput_event_destroy(event); event = libinput_get_event(li); @@ -267,14 +255,6 @@ START_TEST(tip_up_btn_change) LIBINPUT_BUTTON_STATE_RELEASED); libinput_event_destroy(event); - libinput_dispatch(li); - event = libinput_get_event(li); - tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_TOOL_TIP); - ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), - LIBINPUT_TABLET_TOOL_TIP_UP); - libinput_event_destroy(event); - litest_assert_empty_queue(li); } END_TEST @@ -303,10 +283,6 @@ START_TEST(tip_down_btn_change) litest_pop_event_frame(dev); libinput_dispatch(li); - event = libinput_get_event(li); - tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_TOOL_AXIS); - libinput_event_destroy(event); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, @@ -345,10 +321,6 @@ START_TEST(tip_down_btn_change) litest_pop_event_frame(dev); libinput_dispatch(li); - event = libinput_get_event(li); - tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_TOOL_AXIS); - libinput_event_destroy(event); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, @@ -384,9 +356,18 @@ START_TEST(tip_down_motion) }; double x, y, last_x, last_y; - litest_tablet_proximity_in(dev, 10, 10, axes); litest_drain_events(li); + litest_tablet_proximity_in(dev, 10, 10, axes); + libinput_dispatch(li); + event = libinput_get_event(li); + tablet_event = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + last_x = libinput_event_tablet_tool_get_x(tablet_event); + last_y = libinput_event_tablet_tool_get_y(tablet_event); + libinput_event_destroy(event); + + /* move x/y on tip down, make sure x/y changed */ litest_axis_set_value(axes, ABS_DISTANCE, 0); litest_axis_set_value(axes, ABS_PRESSURE, 20); litest_push_event_frame(dev); @@ -395,24 +376,18 @@ START_TEST(tip_down_motion) litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_pop_event_frame(dev); - libinput_dispatch(li); - event = libinput_get_event(li); - tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_TOOL_AXIS); - last_x = libinput_event_tablet_tool_get_x(tablet_event); - last_y = libinput_event_tablet_tool_get_y(tablet_event); - libinput_event_destroy(event); - libinput_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_DOWN); + ck_assert(libinput_event_tablet_tool_x_has_changed(tablet_event)); + ck_assert(libinput_event_tablet_tool_y_has_changed(tablet_event)); x = libinput_event_tablet_tool_get_x(tablet_event); y = libinput_event_tablet_tool_get_y(tablet_event); - ck_assert_double_eq(last_x, x); - ck_assert_double_eq(last_y, y); + ck_assert_double_lt(last_x, x); + ck_assert_double_lt(last_y, y); libinput_event_destroy(event); litest_assert_empty_queue(li); @@ -427,44 +402,48 @@ START_TEST(tip_up_motion) struct libinput_event_tablet_tool *tablet_event; struct axis_replacement axes[] = { { ABS_DISTANCE, 0 }, - { ABS_PRESSURE, 20 }, + { ABS_PRESSURE, 0 }, { -1, -1 } }; double x, y, last_x, last_y; - litest_push_event_frame(dev); litest_tablet_proximity_in(dev, 10, 10, axes); - litest_tablet_motion(dev, 70, 70, axes); - litest_event(dev, EV_KEY, BTN_TOUCH, 1); - litest_event(dev, EV_SYN, SYN_REPORT, 0); - litest_pop_event_frame(dev); litest_drain_events(li); - litest_axis_set_value(axes, ABS_PRESSURE, 0); + litest_axis_set_value(axes, ABS_PRESSURE, 20); litest_push_event_frame(dev); litest_tablet_motion(dev, 70, 70, axes); - litest_event(dev, EV_KEY, BTN_TOUCH, 0); + litest_event(dev, EV_KEY, BTN_TOUCH, 1); litest_event(dev, EV_SYN, SYN_REPORT, 0); litest_pop_event_frame(dev); libinput_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_TOOL_AXIS); + LIBINPUT_EVENT_TABLET_TOOL_TIP); last_x = libinput_event_tablet_tool_get_x(tablet_event); last_y = libinput_event_tablet_tool_get_y(tablet_event); libinput_event_destroy(event); + /* move x/y on tip up, make sure x/y changed */ + litest_axis_set_value(axes, ABS_PRESSURE, 0); + litest_push_event_frame(dev); + litest_tablet_motion(dev, 40, 40, axes); + litest_event(dev, EV_KEY, BTN_TOUCH, 0); + litest_pop_event_frame(dev); + libinput_dispatch(li); event = libinput_get_event(li); tablet_event = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_TIP); ck_assert_int_eq(libinput_event_tablet_tool_get_tip_state(tablet_event), LIBINPUT_TABLET_TOOL_TIP_UP); + ck_assert(libinput_event_tablet_tool_x_has_changed(tablet_event)); + ck_assert(libinput_event_tablet_tool_y_has_changed(tablet_event)); x = libinput_event_tablet_tool_get_x(tablet_event); y = libinput_event_tablet_tool_get_y(tablet_event); - ck_assert_double_eq(last_x, x); - ck_assert_double_eq(last_y, y); + ck_assert_double_ne(last_x, x); + ck_assert_double_ne(last_y, y); libinput_event_destroy(event); litest_assert_empty_queue(li); @@ -2841,7 +2820,7 @@ START_TEST(tablet_pressure_offset_decrease) event = libinput_get_event(li); tev = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_TOOL_AXIS); + LIBINPUT_EVENT_TABLET_TOOL_TIP); pressure = libinput_event_tablet_tool_get_pressure(tev); @@ -2905,7 +2884,7 @@ START_TEST(tablet_pressure_offset_increase) event = libinput_get_event(li); tev = litest_is_tablet_event(event, - LIBINPUT_EVENT_TABLET_TOOL_AXIS); + LIBINPUT_EVENT_TABLET_TOOL_TIP); pressure = libinput_event_tablet_tool_get_pressure(tev); From 3c5483ac160572e6b5ede10561a790e5c21d717e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 5 Jan 2016 11:09:35 +1000 Subject: [PATCH 241/255] tablet: don't set a pressure offset of 0 Signed-off-by: Peter Hutterer Acked-by: Jason Gerecke --- src/evdev-tablet.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 1dc607be..b4182574 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -1047,6 +1047,9 @@ detect_pressure_offset(struct tablet_dispatch *tablet, return; } + if (offset == 0) + return; + /* we only set a pressure offset on proximity in */ if (!tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY)) return; From d5a07eb00b4f6c4aa404164d6dbbd981bf917141 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 14 Jan 2016 14:12:28 +1000 Subject: [PATCH 242/255] tablet: allow the various get_ on tablet button events There's no reason to prevent this for button events. Unlike the pointer which is a relative device a tablet is (usually) a device with a lot of state. Caller code that handles axes is likely shared between the various events, treating button events separately here doesn't get us any benefit. Signed-off-by: Peter Hutterer Acked-by: Jason Gerecke --- src/libinput.c | 12 ++++++++++++ src/libinput.h | 27 ++++++++++++++++++--------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/libinput.c b/src/libinput.c index e9883ffd..84a723a3 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -921,6 +921,7 @@ libinput_event_tablet_tool_x_has_changed( 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return bit_is_set(event->changed_axes, @@ -936,6 +937,7 @@ libinput_event_tablet_tool_y_has_changed( 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return bit_is_set(event->changed_axes, @@ -951,6 +953,7 @@ libinput_event_tablet_tool_pressure_has_changed( 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return bit_is_set(event->changed_axes, @@ -966,6 +969,7 @@ libinput_event_tablet_tool_distance_has_changed( 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return bit_is_set(event->changed_axes, @@ -981,6 +985,7 @@ libinput_event_tablet_tool_tilt_x_has_changed( 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return bit_is_set(event->changed_axes, @@ -996,6 +1001,7 @@ libinput_event_tablet_tool_tilt_y_has_changed( 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return bit_is_set(event->changed_axes, @@ -1011,6 +1017,7 @@ libinput_event_tablet_tool_rotation_has_changed( 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return bit_is_set(event->changed_axes, @@ -1026,6 +1033,7 @@ libinput_event_tablet_tool_slider_has_changed( 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return bit_is_set(event->changed_axes, @@ -1041,6 +1049,7 @@ libinput_event_tablet_tool_wheel_has_changed( 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return bit_is_set(event->changed_axes, @@ -1059,6 +1068,7 @@ libinput_event_tablet_tool_get_axis_value(struct libinput_event_tablet_tool *eve 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); switch(axis) { @@ -1177,6 +1187,7 @@ libinput_event_tablet_tool_get_x_transformed(struct libinput_event_tablet_tool * 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return evdev_device_transform_x(device, @@ -1196,6 +1207,7 @@ libinput_event_tablet_tool_get_y_transformed(struct libinput_event_tablet_tool * 0, LIBINPUT_EVENT_TABLET_TOOL_AXIS, LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return evdev_device_transform_y(device, diff --git a/src/libinput.h b/src/libinput.h index 7b9236de..3b90f0b0 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1375,7 +1375,8 @@ libinput_event_tablet_tool_get_base_event(struct libinput_event_tablet_tool *eve * @note It is an application bug to call this function for events other * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref - * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. + * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, or @ref + * LIBINPUT_EVENT_TABLET_TOOL_BUTTON. * * @param event The libinput tablet event * @return 1 if the axis was updated or 0 otherwise @@ -1395,7 +1396,8 @@ libinput_event_tablet_tool_x_has_changed( * @note It is an application bug to call this function for events other * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref - * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. + * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, or @ref + * LIBINPUT_EVENT_TABLET_TOOL_BUTTON. * * @param event The libinput tablet event * @return 1 if the axis was updated or 0 otherwise @@ -1415,7 +1417,8 @@ libinput_event_tablet_tool_y_has_changed( * @note It is an application bug to call this function for events other * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref - * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. + * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, or @ref + * LIBINPUT_EVENT_TABLET_TOOL_BUTTON. * * @param event The libinput tablet event * @return 1 if the axis was updated or 0 otherwise @@ -1437,7 +1440,8 @@ libinput_event_tablet_tool_pressure_has_changed( * @note It is an application bug to call this function for events other * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref - * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. + * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, or @ref + * LIBINPUT_EVENT_TABLET_TOOL_BUTTON. * * @param event The libinput tablet event * @return 1 if the axis was updated or 0 otherwise @@ -1457,7 +1461,8 @@ libinput_event_tablet_tool_distance_has_changed( * @note It is an application bug to call this function for events other * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref - * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. + * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, or @ref + * LIBINPUT_EVENT_TABLET_TOOL_BUTTON. * * @param event The libinput tablet event * @return 1 if the axis was updated or 0 otherwise @@ -1477,7 +1482,8 @@ libinput_event_tablet_tool_tilt_x_has_changed( * @note It is an application bug to call this function for events other * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref - * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. + * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, or @ref + * LIBINPUT_EVENT_TABLET_TOOL_BUTTON. * * @param event The libinput tablet event * @return 1 if the axis was updated or 0 otherwise @@ -1496,7 +1502,8 @@ libinput_event_tablet_tool_tilt_y_has_changed( * @note It is an application bug to call this function for events other * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref - * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. + * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, or @ref + * LIBINPUT_EVENT_TABLET_TOOL_BUTTON. * * @param event The libinput tablet event * @return 1 if the axis was updated or 0 otherwise @@ -1515,7 +1522,8 @@ libinput_event_tablet_tool_rotation_has_changed( * @note It is an application bug to call this function for events other * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref - * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. + * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, or @ref + * LIBINPUT_EVENT_TABLET_TOOL_BUTTON. * * @param event The libinput tablet event * @return 1 if the axis was updated or 0 otherwise @@ -1534,7 +1542,8 @@ libinput_event_tablet_tool_slider_has_changed( * @note It is an application bug to call this function for events other * than @ref LIBINPUT_EVENT_TABLET_TOOL_AXIS, @ref * LIBINPUT_EVENT_TABLET_TOOL_TIP, or @ref - * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY. + * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, or @ref + * LIBINPUT_EVENT_TABLET_TOOL_BUTTON. * * @param event The libinput tablet event * @return 1 if the axis was updated or 0 otherwise From 3e6579998aa0fde1b802bd1d2c39634b3afcaf28 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 12 Jan 2016 14:40:27 +1000 Subject: [PATCH 243/255] tools: get pressure/distance/tilt from a tip event too Signed-off-by: Peter Hutterer Acked-by: Jason Gerecke --- tools/event-gui.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/event-gui.c b/tools/event-gui.c index a2691d9e..636c28be 100644 --- a/tools/event-gui.c +++ b/tools/event-gui.c @@ -632,6 +632,10 @@ handle_event_tablet(struct libinput_event *ev, struct window *w) case LIBINPUT_EVENT_TABLET_TOOL_TIP: x = libinput_event_tablet_tool_get_x_transformed(t, w->width); y = libinput_event_tablet_tool_get_y_transformed(t, w->height); + w->tool.pressure = libinput_event_tablet_tool_get_pressure(t); + w->tool.distance = libinput_event_tablet_tool_get_distance(t); + w->tool.tilt_x = libinput_event_tablet_tool_get_tilt_x(t); + w->tool.tilt_y = libinput_event_tablet_tool_get_tilt_y(t); if (libinput_event_tablet_tool_get_tip_state(t) == LIBINPUT_TABLET_TOOL_TIP_DOWN) { w->tool.x_down = x; From b1d6c5aa5434bdf720948b0c240324a235345c01 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 12 Jan 2016 14:41:57 +1000 Subject: [PATCH 244/255] tools: share the axis and tip code where appropriate Signed-off-by: Peter Hutterer Acked-by: Jason Gerecke --- tools/event-gui.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/tools/event-gui.c b/tools/event-gui.c index 636c28be..fa0e1a09 100644 --- a/tools/event-gui.c +++ b/tools/event-gui.c @@ -602,6 +602,9 @@ handle_event_tablet(struct libinput_event *ev, struct window *w) struct libinput_event_tablet_tool *t = libinput_event_get_tablet_tool_event(ev); double x, y; + x = libinput_event_tablet_tool_get_x_transformed(t, w->width); + y = libinput_event_tablet_tool_get_y_transformed(t, w->height); + switch (libinput_event_get_type(ev)) { case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: if (libinput_event_tablet_tool_get_proximity_state(t) == @@ -613,25 +616,11 @@ handle_event_tablet(struct libinput_event *ev, struct window *w) w->tool.x_up = 0; w->tool.y_up = 0; } else { - w->tool.x_in = libinput_event_tablet_tool_get_x_transformed(t, - w->width); - w->tool.y_in = libinput_event_tablet_tool_get_y_transformed(t, - w->height); + w->tool.x_in = x; + w->tool.y_in = y; } break; - case LIBINPUT_EVENT_TABLET_TOOL_AXIS: - w->tool.x = libinput_event_tablet_tool_get_x_transformed(t, - w->width); - w->tool.y = libinput_event_tablet_tool_get_y_transformed(t, - w->height); - w->tool.pressure = libinput_event_tablet_tool_get_pressure(t); - w->tool.distance = libinput_event_tablet_tool_get_distance(t); - w->tool.tilt_x = libinput_event_tablet_tool_get_tilt_x(t); - w->tool.tilt_y = libinput_event_tablet_tool_get_tilt_y(t); - break; case LIBINPUT_EVENT_TABLET_TOOL_TIP: - x = libinput_event_tablet_tool_get_x_transformed(t, w->width); - y = libinput_event_tablet_tool_get_y_transformed(t, w->height); w->tool.pressure = libinput_event_tablet_tool_get_pressure(t); w->tool.distance = libinput_event_tablet_tool_get_distance(t); w->tool.tilt_x = libinput_event_tablet_tool_get_tilt_x(t); @@ -644,6 +633,14 @@ handle_event_tablet(struct libinput_event *ev, struct window *w) w->tool.x_up = x; w->tool.y_up = y; } + /* fallthrough */ + case LIBINPUT_EVENT_TABLET_TOOL_AXIS: + w->tool.x = x; + w->tool.y = y; + w->tool.pressure = libinput_event_tablet_tool_get_pressure(t); + w->tool.distance = libinput_event_tablet_tool_get_distance(t); + w->tool.tilt_x = libinput_event_tablet_tool_get_tilt_x(t); + w->tool.tilt_y = libinput_event_tablet_tool_get_tilt_y(t); break; case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: break; From d524313d2b207ac70a2089775674bd3410122a53 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 6 Jan 2016 16:16:46 +1000 Subject: [PATCH 245/255] tablet: use a struct rather than a double array for axis values Makes the code less generic, but more expressive. No visible functional changes. Signed-off-by: Peter Hutterer Acked-by: Jason Gerecke --- src/evdev-tablet.c | 172 ++++++++++++++++------------------------- src/evdev-tablet.h | 2 +- src/libinput-private.h | 20 +++-- src/libinput.c | 141 ++++++++++++++++++--------------- 4 files changed, 161 insertions(+), 174 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index b4182574..29c86ad4 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -251,8 +251,8 @@ convert_tilt_to_rotation(struct tablet_dispatch *tablet) 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_TOOL_AXIS_TILT_X]; - y = tablet->axes[LIBINPUT_TABLET_TOOL_AXIS_TILT_Y]; + x = tablet->axes.tilt.x; + y = tablet->axes.tilt.y; clear_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_X); clear_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); @@ -262,7 +262,7 @@ convert_tilt_to_rotation(struct tablet_dispatch *tablet) angle = fmod(360 + angle - offset, 360); - tablet->axes[LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z] = angle; + tablet->axes.rotation = angle; set_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); } @@ -290,29 +290,26 @@ tablet_handle_xy(struct tablet_dispatch *tablet, struct evdev_device *device) { struct device_coords point; const struct input_absinfo *absinfo; - int a; - a = LIBINPUT_TABLET_TOOL_AXIS_X; - if (bit_is_set(tablet->changed_axes, a)) { + if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_X)) { absinfo = libevdev_get_abs_info(device->evdev, ABS_X); if (device->left_handed.enabled) - tablet->axes[a] = invert_axis(absinfo); + tablet->axes.point.x = invert_axis(absinfo); else - tablet->axes[a] = absinfo->value; + tablet->axes.point.x = absinfo->value; } - point.x = tablet->axes[a]; + point.x = tablet->axes.point.x; - a = LIBINPUT_TABLET_TOOL_AXIS_Y; - if (bit_is_set(tablet->changed_axes, a)) { + if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_Y)) { absinfo = libevdev_get_abs_info(device->evdev, ABS_Y); if (device->left_handed.enabled) - tablet->axes[a] = invert_axis(absinfo); + tablet->axes.point.y = invert_axis(absinfo); else - tablet->axes[a] = absinfo->value; + tablet->axes.point.y = absinfo->value; } - point.y = tablet->axes[a]; + point.y = tablet->axes.point.y; evdev_transform_absolute(device, &point); @@ -325,15 +322,14 @@ tablet_handle_pressure(struct tablet_dispatch *tablet, struct libinput_tablet_tool *tool) { const struct input_absinfo *absinfo; - int a; - a = LIBINPUT_TABLET_TOOL_AXIS_PRESSURE; - if (bit_is_set(tablet->changed_axes, a)) { + if (bit_is_set(tablet->changed_axes, + LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) { absinfo = libevdev_get_abs_info(device->evdev, ABS_PRESSURE); - tablet->axes[a] = normalize_pressure(absinfo, tool); + tablet->axes.pressure = normalize_pressure(absinfo, tool); } - return tablet->axes[a]; + return tablet->axes.pressure; } static inline double @@ -341,15 +337,14 @@ tablet_handle_distance(struct tablet_dispatch *tablet, struct evdev_device *device) { const struct input_absinfo *absinfo; - int a; - a = LIBINPUT_TABLET_TOOL_AXIS_DISTANCE; - if (bit_is_set(tablet->changed_axes, a)) { + if (bit_is_set(tablet->changed_axes, + LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) { absinfo = libevdev_get_abs_info(device->evdev, ABS_DISTANCE); - tablet->axes[a] = normalize_dist_slider(absinfo); + tablet->axes.distance = normalize_dist_slider(absinfo); } - return tablet->axes[a]; + return tablet->axes.distance; } static inline double @@ -357,15 +352,14 @@ tablet_handle_slider(struct tablet_dispatch *tablet, struct evdev_device *device) { const struct input_absinfo *absinfo; - int a; - a = LIBINPUT_TABLET_TOOL_AXIS_SLIDER; - if (bit_is_set(tablet->changed_axes, a)) { + if (bit_is_set(tablet->changed_axes, + LIBINPUT_TABLET_TOOL_AXIS_SLIDER)) { absinfo = libevdev_get_abs_info(device->evdev, ABS_WHEEL); - tablet->axes[a] = normalize_dist_slider(absinfo); + tablet->axes.slider = normalize_dist_slider(absinfo); } - return tablet->axes[a]; + return tablet->axes.slider; } static inline struct normalized_range_coords @@ -374,25 +368,24 @@ tablet_handle_tilt(struct tablet_dispatch *tablet, { struct normalized_range_coords tilt; const struct input_absinfo *absinfo; - int a; - a = LIBINPUT_TABLET_TOOL_AXIS_TILT_X; - if (bit_is_set(tablet->changed_axes, a)) { + if (bit_is_set(tablet->changed_axes, + LIBINPUT_TABLET_TOOL_AXIS_TILT_X)) { absinfo = libevdev_get_abs_info(device->evdev, ABS_TILT_X); - tablet->axes[a] = normalize_tilt(absinfo); + tablet->axes.tilt.x = normalize_tilt(absinfo); if (device->left_handed.enabled) - tablet->axes[a] *= -1; + tablet->axes.tilt.x *= -1; } - tilt.x = tablet->axes[a]; + tilt.x = tablet->axes.tilt.x; - a = LIBINPUT_TABLET_TOOL_AXIS_TILT_Y; - if (bit_is_set(tablet->changed_axes, a)) { + if (bit_is_set(tablet->changed_axes, + LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) { absinfo = libevdev_get_abs_info(device->evdev, ABS_TILT_Y); - tablet->axes[a] = normalize_tilt(absinfo); + tablet->axes.tilt.y = normalize_tilt(absinfo); if (device->left_handed.enabled) - tablet->axes[a] *= -1; + tablet->axes.tilt.y *= -1; } - tilt.y = tablet->axes[a]; + tilt.y = tablet->axes.tilt.y; return tilt; } @@ -402,26 +395,22 @@ tablet_handle_artpen_rotation(struct tablet_dispatch *tablet, struct evdev_device *device) { const struct input_absinfo *absinfo; - int a; - a = LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z; - if (bit_is_set(tablet->changed_axes, a)) { + if (bit_is_set(tablet->changed_axes, + LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)) { absinfo = libevdev_get_abs_info(device->evdev, ABS_Z); /* artpen has 0 with buttons pointing east */ - tablet->axes[a] = convert_to_degrees(absinfo, 90); + tablet->axes.rotation = convert_to_degrees(absinfo, 90); } - return tablet->axes[a]; + return tablet->axes.rotation; } static inline double tablet_handle_mouse_rotation(struct tablet_dispatch *tablet, struct evdev_device *device) { - int a; - - a = LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z; if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) || bit_is_set(tablet->changed_axes, @@ -429,7 +418,7 @@ tablet_handle_mouse_rotation(struct tablet_dispatch *tablet, convert_tilt_to_rotation(tablet); } - return tablet->axes[a]; + return tablet->axes.rotation; } static inline double @@ -442,68 +431,50 @@ tablet_handle_wheel(struct tablet_dispatch *tablet, a = LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL; if (bit_is_set(tablet->changed_axes, a)) { *wheel_discrete = tablet->deltas[a]; - tablet->axes[a] = normalize_wheel(tablet, - tablet->deltas[a]); + tablet->axes.wheel = normalize_wheel(tablet, + tablet->deltas[a]); } else { - tablet->axes[a] = 0; + tablet->axes.wheel = 0; *wheel_discrete = 0; } - return tablet->axes[a]; + return tablet->axes.wheel; } static bool tablet_check_notify_axes(struct tablet_dispatch *tablet, struct evdev_device *device, struct libinput_tablet_tool *tool, - double *axes_out, - size_t axes_sz, - int *wheel_discrete_out) + struct tablet_axes *axes_out) { - double axes[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1] = {0}; - int wheel_discrete = 0; - struct device_coords point; - struct normalized_range_coords tilt; + struct tablet_axes axes = {0}; const char tmp[sizeof(tablet->changed_axes)] = {0}; if (memcmp(tmp, tablet->changed_axes, sizeof(tmp)) == 0) return false; - assert(axes_sz == sizeof(axes)); - point = tablet_handle_xy(tablet, device); - axes[LIBINPUT_TABLET_TOOL_AXIS_X] = point.x; - axes[LIBINPUT_TABLET_TOOL_AXIS_Y] = point.y; + axes.point = tablet_handle_xy(tablet, device); + axes.pressure = tablet_handle_pressure(tablet, device, tool); + axes.distance = tablet_handle_distance(tablet, device); + axes.slider = tablet_handle_slider(tablet, device); - axes[LIBINPUT_TABLET_TOOL_AXIS_PRESSURE] = - tablet_handle_pressure(tablet, device, tool); - axes[LIBINPUT_TABLET_TOOL_AXIS_DISTANCE] = - tablet_handle_distance(tablet, device); - axes[LIBINPUT_TABLET_TOOL_AXIS_SLIDER] = - tablet_handle_slider(tablet, device); - - tilt = tablet_handle_tilt(tablet, device); - axes[LIBINPUT_TABLET_TOOL_AXIS_TILT_X] = tilt.x; - axes[LIBINPUT_TABLET_TOOL_AXIS_TILT_Y] = tilt.y; + axes.tilt = tablet_handle_tilt(tablet, device); /* We must check ROTATION_Z after TILT_X/Y so that the tilt axes are * already normalized and set if we have the mouse/lens tool */ if (tablet->current_tool_type == LIBINPUT_TABLET_TOOL_TYPE_MOUSE || tablet->current_tool_type == LIBINPUT_TABLET_TOOL_TYPE_LENS) { - axes[LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z] = - tablet_handle_mouse_rotation(tablet, device); - axes[LIBINPUT_TABLET_TOOL_AXIS_TILT_X] = 0; - axes[LIBINPUT_TABLET_TOOL_AXIS_TILT_Y] = 0; + axes.rotation = tablet_handle_mouse_rotation(tablet, device); + axes.tilt.x = 0; + axes.tilt.y = 0; } else { - axes[LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z] = - tablet_handle_artpen_rotation(tablet, device); + axes.rotation = tablet_handle_artpen_rotation(tablet, device); } - axes[LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL] = - tablet_handle_wheel(tablet, device, &wheel_discrete); + axes.wheel = tablet_handle_wheel(tablet, device, &axes.wheel_discrete); - memcpy(axes_out, axes, sizeof(axes)); - *wheel_discrete_out = wheel_discrete; + *axes_out = axes; return true; } @@ -923,7 +894,7 @@ tablet_notify_button_mask(struct tablet_dispatch *tablet, time, tool, tip_state, - tablet->axes, + &tablet->axes, i, state); } @@ -983,21 +954,20 @@ sanitize_pressure_distance(struct tablet_dispatch *tablet, if (tool_in_contact) { clear_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); - tablet->axes[LIBINPUT_TABLET_TOOL_AXIS_DISTANCE] = - 0; + tablet->axes.distance = 0; } else { clear_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); - tablet->axes[LIBINPUT_TABLET_TOOL_AXIS_PRESSURE] = 0; + tablet->axes.pressure = 0; } } else if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE) && !tool_in_contact) { /* Make sure that the last axis value sent to the caller is a 0 */ - if (tablet->axes[LIBINPUT_TABLET_TOOL_AXIS_PRESSURE] == 0) + if (tablet->axes.pressure == 0) clear_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); else - tablet->axes[LIBINPUT_TABLET_TOOL_AXIS_PRESSURE] = 0; + tablet->axes.pressure = 0; } } @@ -1195,8 +1165,7 @@ tablet_send_axis_proximity_tip_down_events(struct tablet_dispatch *tablet, struct libinput_tablet_tool *tool, uint64_t time) { - double axes[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1] = {0}; - int wheel_discrete = 0; + struct tablet_axes axes = {0}; /* 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 @@ -1210,9 +1179,7 @@ tablet_send_axis_proximity_tip_down_events(struct tablet_dispatch *tablet, * information (it'll be mostly 0), so we just get the * current state and skip over updating the axes. */ - static_assert(sizeof(axes) == sizeof(tablet->axes), - "Mismatching array sizes"); - memcpy(axes, tablet->axes, sizeof(axes)); + axes = tablet->axes; /* Dont' send an axis event, but we may have a tip event * update */ @@ -1220,9 +1187,7 @@ tablet_send_axis_proximity_tip_down_events(struct tablet_dispatch *tablet, } else if (!tablet_check_notify_axes(tablet, device, tool, - axes, - sizeof(axes), - &wheel_discrete)) { + &axes)) { goto out; } @@ -1232,7 +1197,7 @@ tablet_send_axis_proximity_tip_down_events(struct tablet_dispatch *tablet, tool, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN, tablet->changed_axes, - axes); + &axes); tablet_unset_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY); tablet_unset_status(tablet, TABLET_AXES_UPDATED); } @@ -1243,7 +1208,7 @@ tablet_send_axis_proximity_tip_down_events(struct tablet_dispatch *tablet, tool, LIBINPUT_TABLET_TOOL_TIP_DOWN, tablet->changed_axes, - tablet->axes); + &tablet->axes); tablet_unset_status(tablet, TABLET_AXES_UPDATED); tablet_unset_status(tablet, TABLET_TOOL_ENTERING_CONTACT); tablet_set_status(tablet, TABLET_TOOL_IN_CONTACT); @@ -1253,7 +1218,7 @@ tablet_send_axis_proximity_tip_down_events(struct tablet_dispatch *tablet, tool, LIBINPUT_TABLET_TOOL_TIP_UP, tablet->changed_axes, - tablet->axes); + &tablet->axes); tablet_unset_status(tablet, TABLET_AXES_UPDATED); tablet_unset_status(tablet, TABLET_TOOL_LEAVING_CONTACT); tablet_unset_status(tablet, TABLET_TOOL_IN_CONTACT); @@ -1271,8 +1236,7 @@ tablet_send_axis_proximity_tip_down_events(struct tablet_dispatch *tablet, tool, tip_state, tablet->changed_axes, - axes, - wheel_discrete); + &axes); tablet_unset_status(tablet, TABLET_AXES_UPDATED); } @@ -1348,7 +1312,7 @@ tablet_flush(struct tablet_dispatch *tablet, tool, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT, tablet->changed_axes, - tablet->axes); + &tablet->axes); tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY); tablet_unset_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY); diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index 0225dcf4..4d359bbd 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -53,7 +53,7 @@ struct tablet_dispatch { struct evdev_device *device; unsigned int status; unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_TOOL_AXIS_MAX + 1)]; - double axes[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1]; + struct tablet_axes axes; double deltas[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1]; unsigned char axis_caps[NCHARS(LIBINPUT_TABLET_TOOL_AXIS_MAX + 1)]; diff --git a/src/libinput-private.h b/src/libinput-private.h index 2dbc555a..ff43d007 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -69,6 +69,17 @@ struct threshold { int lower; }; +struct tablet_axes { + struct device_coords point; + double distance; + double pressure; + struct normalized_range_coords tilt; + double rotation; + double slider; + double wheel; + int wheel_discrete; +}; + struct libinput_interface_backend { int (*resume)(struct libinput *libinput); void (*suspend)(struct libinput *libinput); @@ -493,8 +504,7 @@ tablet_notify_axis(struct libinput_device *device, struct libinput_tablet_tool *tool, enum libinput_tablet_tool_tip_state tip_state, unsigned char *changed_axes, - double *axes, - int wheel_discrete); + const struct tablet_axes *axes); void tablet_notify_proximity(struct libinput_device *device, @@ -502,7 +512,7 @@ tablet_notify_proximity(struct libinput_device *device, struct libinput_tablet_tool *tool, enum libinput_tablet_tool_proximity_state state, unsigned char *changed_axes, - double *axes); + const struct tablet_axes *axes); void tablet_notify_tip(struct libinput_device *device, @@ -510,14 +520,14 @@ tablet_notify_tip(struct libinput_device *device, struct libinput_tablet_tool *tool, enum libinput_tablet_tool_tip_state tip_state, unsigned char *changed_axes, - double *axes); + const struct tablet_axes *axes); void tablet_notify_button(struct libinput_device *device, uint64_t time, struct libinput_tablet_tool *tool, enum libinput_tablet_tool_tip_state tip_state, - double *axes, + const struct tablet_axes *axes, int32_t button, enum libinput_button_state state); diff --git a/src/libinput.c b/src/libinput.c index 84a723a3..7beb8b77 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -131,9 +131,7 @@ struct libinput_event_tablet_tool { enum libinput_button_state state; uint32_t seat_button_count; uint64_t time; - double axes[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1]; - double wheel_delta; - int wheel_discrete; + struct tablet_axes axes; unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_TOOL_AXIS_MAX + 1)]; struct libinput_tablet_tool *tool; enum libinput_tablet_tool_proximity_state proximity_state; @@ -1056,9 +1054,8 @@ libinput_event_tablet_tool_wheel_has_changed( LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); } -static double -libinput_event_tablet_tool_get_axis_value(struct libinput_event_tablet_tool *event, - enum libinput_tablet_tool_axis axis) +LIBINPUT_EXPORT double +libinput_event_tablet_tool_get_x(struct libinput_event_tablet_tool *event) { struct evdev_device *device = (struct evdev_device *) event->base.device; @@ -1071,80 +1068,103 @@ libinput_event_tablet_tool_get_axis_value(struct libinput_event_tablet_tool *eve LIBINPUT_EVENT_TABLET_TOOL_BUTTON, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); - switch(axis) { - case LIBINPUT_TABLET_TOOL_AXIS_X: - return evdev_convert_to_mm(device->abs.absinfo_x, - event->axes[axis]); - case LIBINPUT_TABLET_TOOL_AXIS_Y: - return evdev_convert_to_mm(device->abs.absinfo_y, - event->axes[axis]); - case LIBINPUT_TABLET_TOOL_AXIS_DISTANCE: - case LIBINPUT_TABLET_TOOL_AXIS_PRESSURE: - case LIBINPUT_TABLET_TOOL_AXIS_TILT_X: - case LIBINPUT_TABLET_TOOL_AXIS_TILT_Y: - case LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z: - case LIBINPUT_TABLET_TOOL_AXIS_SLIDER: - case LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL: - return event->axes[axis]; - default: - return 0; - } -} - -LIBINPUT_EXPORT double -libinput_event_tablet_tool_get_x(struct libinput_event_tablet_tool *event) -{ - return libinput_event_tablet_tool_get_axis_value(event, - LIBINPUT_TABLET_TOOL_AXIS_X); + return evdev_convert_to_mm(device->abs.absinfo_x, + event->axes.point.x); } LIBINPUT_EXPORT double libinput_event_tablet_tool_get_y(struct libinput_event_tablet_tool *event) { - return libinput_event_tablet_tool_get_axis_value(event, - LIBINPUT_TABLET_TOOL_AXIS_Y); + struct evdev_device *device = + (struct evdev_device *) event->base.device; + + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + + return evdev_convert_to_mm(device->abs.absinfo_y, + event->axes.point.y); } LIBINPUT_EXPORT double libinput_event_tablet_tool_get_pressure(struct libinput_event_tablet_tool *event) { - return libinput_event_tablet_tool_get_axis_value(event, - LIBINPUT_TABLET_TOOL_AXIS_PRESSURE); + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + + return event->axes.pressure; } LIBINPUT_EXPORT double libinput_event_tablet_tool_get_distance(struct libinput_event_tablet_tool *event) { - return libinput_event_tablet_tool_get_axis_value(event, - LIBINPUT_TABLET_TOOL_AXIS_DISTANCE); + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + + return event->axes.distance; } LIBINPUT_EXPORT double libinput_event_tablet_tool_get_tilt_x(struct libinput_event_tablet_tool *event) { - return libinput_event_tablet_tool_get_axis_value(event, - LIBINPUT_TABLET_TOOL_AXIS_TILT_X); + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + + return event->axes.tilt.x; } LIBINPUT_EXPORT double libinput_event_tablet_tool_get_tilt_y(struct libinput_event_tablet_tool *event) { - return libinput_event_tablet_tool_get_axis_value(event, - LIBINPUT_TABLET_TOOL_AXIS_TILT_Y); + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + + return event->axes.tilt.y; } LIBINPUT_EXPORT double libinput_event_tablet_tool_get_rotation(struct libinput_event_tablet_tool *event) { - return libinput_event_tablet_tool_get_axis_value(event, - LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z); + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + + return event->axes.rotation; } LIBINPUT_EXPORT double libinput_event_tablet_tool_get_slider_position(struct libinput_event_tablet_tool *event) { - return libinput_event_tablet_tool_get_axis_value(event, - LIBINPUT_TABLET_TOOL_AXIS_SLIDER); + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + + return event->axes.slider; } LIBINPUT_EXPORT double @@ -1157,8 +1177,7 @@ libinput_event_tablet_tool_get_wheel_delta(struct libinput_event_tablet_tool *ev LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); - return libinput_event_tablet_tool_get_axis_value(event, - LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL); + return event->axes.wheel; } LIBINPUT_EXPORT int @@ -1172,7 +1191,7 @@ libinput_event_tablet_tool_get_wheel_delta_discrete( LIBINPUT_EVENT_TABLET_TOOL_TIP, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); - return event->wheel_discrete; + return event->axes.wheel_discrete; } LIBINPUT_EXPORT double @@ -1191,7 +1210,7 @@ libinput_event_tablet_tool_get_x_transformed(struct libinput_event_tablet_tool * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return evdev_device_transform_x(device, - event->axes[LIBINPUT_TABLET_TOOL_AXIS_X], + event->axes.point.x, width); } @@ -1211,7 +1230,7 @@ libinput_event_tablet_tool_get_y_transformed(struct libinput_event_tablet_tool * LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); return evdev_device_transform_y(device, - event->axes[LIBINPUT_TABLET_TOOL_AXIS_Y], + event->axes.point.y, height); } @@ -2170,8 +2189,7 @@ tablet_notify_axis(struct libinput_device *device, struct libinput_tablet_tool *tool, enum libinput_tablet_tool_tip_state tip_state, unsigned char *changed_axes, - double *axes, - int wheel_discrete) + const struct tablet_axes *axes) { struct libinput_event_tablet_tool *axis_event; @@ -2184,13 +2202,12 @@ tablet_notify_axis(struct libinput_device *device, .tool = tool, .proximity_state = LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN, .tip_state = tip_state, - .wheel_discrete = wheel_discrete, + .axes = *axes, }; memcpy(axis_event->changed_axes, changed_axes, sizeof(axis_event->changed_axes)); - memcpy(axis_event->axes, axes, sizeof(axis_event->axes)); post_device_event(device, time, @@ -2204,7 +2221,7 @@ tablet_notify_proximity(struct libinput_device *device, struct libinput_tablet_tool *tool, enum libinput_tablet_tool_proximity_state proximity_state, unsigned char *changed_axes, - double *axes) + const struct tablet_axes *axes) { struct libinput_event_tablet_tool *proximity_event; @@ -2217,10 +2234,8 @@ tablet_notify_proximity(struct libinput_device *device, .tool = tool, .tip_state = LIBINPUT_TABLET_TOOL_TIP_UP, .proximity_state = proximity_state, + .axes = *axes, }; - memcpy(proximity_event->axes, - axes, - sizeof(proximity_event->axes)); memcpy(proximity_event->changed_axes, changed_axes, sizeof(proximity_event->changed_axes)); @@ -2239,7 +2254,7 @@ tablet_notify_tip(struct libinput_device *device, struct libinput_tablet_tool *tool, enum libinput_tablet_tool_tip_state tip_state, unsigned char *changed_axes, - double *axes) + const struct tablet_axes *axes) { struct libinput_event_tablet_tool *tip_event; @@ -2252,10 +2267,8 @@ tablet_notify_tip(struct libinput_device *device, .tool = tool, .tip_state = tip_state, .proximity_state = LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN, + .axes = *axes, }; - memcpy(tip_event->axes, - axes, - sizeof(tip_event->axes)); memcpy(tip_event->changed_axes, changed_axes, sizeof(tip_event->changed_axes)); @@ -2271,7 +2284,7 @@ tablet_notify_button(struct libinput_device *device, uint64_t time, struct libinput_tablet_tool *tool, enum libinput_tablet_tool_tip_state tip_state, - double *axes, + const struct tablet_axes *axes, int32_t button, enum libinput_button_state state) { @@ -2294,8 +2307,8 @@ tablet_notify_button(struct libinput_device *device, .seat_button_count = seat_button_count, .proximity_state = LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN, .tip_state = tip_state, + .axes = *axes, }; - memcpy(button_event->axes, axes, sizeof(button_event->axes)); post_device_event(device, time, From f5200c532527644d7a32da6149bb7edb5d8fc9b1 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 6 Jan 2016 16:20:38 +1000 Subject: [PATCH 246/255] tablet: drop delta array, provided by the tablet_axis struct now Signed-off-by: Peter Hutterer Acked-by: Jason Gerecke --- src/evdev-tablet.c | 7 +++---- src/evdev-tablet.h | 1 - src/libinput.c | 2 -- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 29c86ad4..1870e7e3 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -430,9 +430,9 @@ tablet_handle_wheel(struct tablet_dispatch *tablet, a = LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL; if (bit_is_set(tablet->changed_axes, a)) { - *wheel_discrete = tablet->deltas[a]; + *wheel_discrete = tablet->axes.wheel_discrete; tablet->axes.wheel = normalize_wheel(tablet, - tablet->deltas[a]); + tablet->axes.wheel_discrete); } else { tablet->axes.wheel = 0; *wheel_discrete = 0; @@ -457,7 +457,6 @@ tablet_check_notify_axes(struct tablet_dispatch *tablet, axes.pressure = tablet_handle_pressure(tablet, device, tool); axes.distance = tablet_handle_distance(tablet, device); axes.slider = tablet_handle_slider(tablet, device); - axes.tilt = tablet_handle_tilt(tablet, device); /* We must check ROTATION_Z after TILT_X/Y so that the tilt axes are @@ -602,7 +601,7 @@ tablet_process_relative(struct tablet_dispatch *tablet, break; } set_bit(tablet->changed_axes, axis); - tablet->deltas[axis] = -1 * e->value; + tablet->axes.wheel_discrete = -1 * e->value; tablet_set_status(tablet, TABLET_AXES_UPDATED); break; default: diff --git a/src/evdev-tablet.h b/src/evdev-tablet.h index 4d359bbd..1d6fc936 100644 --- a/src/evdev-tablet.h +++ b/src/evdev-tablet.h @@ -54,7 +54,6 @@ struct tablet_dispatch { unsigned int status; unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_TOOL_AXIS_MAX + 1)]; struct tablet_axes axes; - double deltas[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1]; unsigned char axis_caps[NCHARS(LIBINPUT_TABLET_TOOL_AXIS_MAX + 1)]; /* Only used for tablets that don't report serial numbers */ diff --git a/src/libinput.c b/src/libinput.c index 7beb8b77..2f80f039 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -2240,8 +2240,6 @@ tablet_notify_proximity(struct libinput_device *device, changed_axes, sizeof(proximity_event->changed_axes)); - /* deltas are always 0 on prox-in/out */ - post_device_event(device, time, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, From 108a191a3ec868c00e5ee72be383b437894b2fc5 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 6 Jan 2016 14:47:18 +1000 Subject: [PATCH 247/255] tablet: add support for relative x/y motion deltas Instead of an explicit tablet mode that device must be changed into, let the caller decide which coordinates are preferred. The tablet mode may be application-specific and usually depends on the tool as well. This patch adds an interface to get a motion delta for the x/y axes in pixel-like coordinates. libinput provides some magic to convert the tablet data into something that resembles pixels from a mouse motion. For unaccelerated relative motion, the caller should use the mm values from the tablet and calculate deltas manually. Signed-off-by: Peter Hutterer Acked-by: Jason Gerecke --- doc/normalization-of-relative-motion.dox | 4 +++ doc/tablet-support.dox | 22 +++++++++++++++ src/libinput-private.h | 1 + src/libinput.c | 26 ++++++++++++++++++ src/libinput.h | 34 ++++++++++++++++++++++++ src/libinput.sym | 2 ++ 6 files changed, 89 insertions(+) diff --git a/doc/normalization-of-relative-motion.dox b/doc/normalization-of-relative-motion.dox index d0a42e03..d0ab5603 100644 --- a/doc/normalization-of-relative-motion.dox +++ b/doc/normalization-of-relative-motion.dox @@ -38,6 +38,10 @@ libinput scales unaccelerated touchpad motion to the resolution of the touchpad's x axis, i.e. the unaccelerated value for the y axis is: y = (x / resolution_x) * resolution_y +@section motion_normalization_tablet Normalization of tablet coordinates + +See @ref tablet-relative-motion + @section motion_normalization_customization Setting custom DPI settings Devices usually do not advertise their resolution and libinput relies on diff --git a/doc/tablet-support.dox b/doc/tablet-support.dox index 7207a473..cc5d4091 100644 --- a/doc/tablet-support.dox +++ b/doc/tablet-support.dox @@ -52,6 +52,28 @@ Note that the pressure threshold to trigger a logical tip event may be zero on some devices. On tools without pressure sensitivity, determining when a tip is down is device-specific. +@section tablet-relative-motion Relative motion for tablet tools + +libinput calculates the relative motion vector for each event and converts +it to the same coordinate space that a normal mouse device would use. For +the caller, this means that the delta coordinates returned by +libinput_event_tablet_tool_get_dx() and +libinput_event_tablet_tool_get_dy() can be used identical to the delta +coordinates from any other pointer event. Any resolution differences between +the x and y axes are accommodated for, a delta of N/N represents a 45 degree +diagonal move on the tablet. + +The delta coordinates are available for all tablet events, it is up to the +caller to decide when a tool should be used in relative mode. It is +recommended that mouse and lens cursor tool default to relative mode and +all pen-like tools to absolute mode. + +If a tool in relative mode must not use pointer acceleration, callers +should use the absolute coordinates returned by +libinput_event_tablet_tool_get_x() and libinput_event_tablet_tool_get_y() +and calculate the delta themselves. Callers that require exact physical +distance should also use these functions to calculate delta movements. + @section tablet-axes Special axes on tablet tools A tablet tool usually provides additional information beyond x/y positional diff --git a/src/libinput-private.h b/src/libinput-private.h index ff43d007..d78be646 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -71,6 +71,7 @@ struct threshold { struct tablet_axes { struct device_coords point; + struct normalized_coords delta; double distance; double pressure; struct normalized_range_coords tilt; diff --git a/src/libinput.c b/src/libinput.c index 2f80f039..a0dc6d68 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -1089,6 +1089,32 @@ libinput_event_tablet_tool_get_y(struct libinput_event_tablet_tool *event) event->axes.point.y); } +LIBINPUT_EXPORT double +libinput_event_tablet_tool_get_dx(struct libinput_event_tablet_tool *event) +{ + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + + return event->axes.delta.x; +} + +LIBINPUT_EXPORT double +libinput_event_tablet_tool_get_dy(struct libinput_event_tablet_tool *event) +{ + require_event_type(libinput_event_get_context(&event->base), + event->base.type, + 0, + LIBINPUT_EVENT_TABLET_TOOL_AXIS, + LIBINPUT_EVENT_TABLET_TOOL_TIP, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + + return event->axes.delta.y; +} + LIBINPUT_EXPORT double libinput_event_tablet_tool_get_pressure(struct libinput_event_tablet_tool *event) { diff --git a/src/libinput.h b/src/libinput.h index 1cf690b9..500224df 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -1580,6 +1580,40 @@ libinput_event_tablet_tool_get_x(struct libinput_event_tablet_tool *event); double libinput_event_tablet_tool_get_y(struct libinput_event_tablet_tool *event); +/** + * @ingroup event_tablet + * + * Return the delta between the last event and the current event. + * If the tool employs pointer acceleration, the delta returned by this + * function is the accelerated delta. + * + * This value is in screen coordinate space, the delta is to be interpreted + * like the return value of libinput_event_pointer_get_dx(). + * See @ref tablet-relative-motion for more details. + * + * @param event The libinput tablet event + * @return The relative x movement since the last event + */ +double +libinput_event_tablet_tool_get_dx(struct libinput_event_tablet_tool *event); + +/** + * @ingroup event_tablet + * + * Return the delta between the last event and the current event. + * If the tool employs pointer acceleration, the delta returned by this + * function is the accelerated delta. + * + * This value is in screen coordinate space, the delta is to be interpreted + * like the return value of libinput_event_pointer_get_dx(). + * See @ref tablet-relative-motion for more details. + * + * @param event The libinput tablet event + * @return The relative y movement since the last event + */ +double +libinput_event_tablet_tool_get_dy(struct libinput_event_tablet_tool *event); + /** * @ingroup event_tablet * diff --git a/src/libinput.sym b/src/libinput.sym index 22a8dd82..666f3668 100644 --- a/src/libinput.sym +++ b/src/libinput.sym @@ -194,6 +194,8 @@ LIBINPUT_TABLET_SUPPORT { libinput_event_tablet_tool_tilt_y_has_changed; libinput_event_tablet_tool_wheel_has_changed; libinput_event_tablet_tool_slider_has_changed; + libinput_event_tablet_tool_get_dx; + libinput_event_tablet_tool_get_dy; libinput_event_tablet_tool_get_x; libinput_event_tablet_tool_get_y; libinput_event_tablet_tool_get_pressure; From 7164d6eff5c83b8280d1d55eb33fb173160f9de9 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 6 Jan 2016 15:26:49 +1000 Subject: [PATCH 248/255] tablet: hook up relative motion events Signed-off-by: Peter Hutterer Acked-by: Jason Gerecke --- doc/pointer-acceleration.dox | 6 ++ src/evdev-tablet.c | 116 ++++++++++++++++++-- src/evdev.c | 13 +++ src/evdev.h | 4 + src/filter.c | 94 ++++++++++++++++ src/filter.h | 3 + src/libinput-util.h | 10 ++ test/tablet.c | 204 +++++++++++++++++++++++++++++++++++ 8 files changed, 440 insertions(+), 10 deletions(-) diff --git a/doc/pointer-acceleration.dox b/doc/pointer-acceleration.dox index 7ec5e74d..2fbb4cc2 100644 --- a/doc/pointer-acceleration.dox +++ b/doc/pointer-acceleration.dox @@ -124,4 +124,10 @@ velocity of the pointer and each delta (dx, dy) results in an accelerated delta (dx * factor, dy * factor). This provides 1:1 movement between the device and the pointer on-screen. +@section ptraccel-tablet Pointer acceleration on tablets + +Pointer acceleration for relative motion on tablet devices is a flat +acceleration, with the speed seeting slowing down or speeding up the pointer +motion by a constant factor. Tablets do not allow for switchable profiles. + */ diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 1870e7e3..ae205501 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -285,19 +285,29 @@ normalize_wheel(struct tablet_dispatch *tablet, return value * device->scroll.wheel_click_angle; } -static inline struct device_coords -tablet_handle_xy(struct tablet_dispatch *tablet, struct evdev_device *device) +static inline void +tablet_handle_xy(struct tablet_dispatch *tablet, + struct evdev_device *device, + struct device_coords *point_out, + struct device_coords *delta_out) { struct device_coords point; + struct device_coords delta = { 0, 0 }; const struct input_absinfo *absinfo; + int value; if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_X)) { absinfo = libevdev_get_abs_info(device->evdev, ABS_X); if (device->left_handed.enabled) - tablet->axes.point.x = invert_axis(absinfo); + value = invert_axis(absinfo); else - tablet->axes.point.x = absinfo->value; + value = absinfo->value; + + if (!tablet_has_status(tablet, + TABLET_TOOL_ENTERING_PROXIMITY)) + delta.x = value - tablet->axes.point.x; + tablet->axes.point.x = value; } point.x = tablet->axes.point.x; @@ -305,15 +315,41 @@ tablet_handle_xy(struct tablet_dispatch *tablet, struct evdev_device *device) absinfo = libevdev_get_abs_info(device->evdev, ABS_Y); if (device->left_handed.enabled) - tablet->axes.point.y = invert_axis(absinfo); + value = invert_axis(absinfo); else - tablet->axes.point.y = absinfo->value; + value = absinfo->value; + + if (!tablet_has_status(tablet, + TABLET_TOOL_ENTERING_PROXIMITY)) + delta.y = value - tablet->axes.point.y; + tablet->axes.point.y = value; } point.y = tablet->axes.point.y; evdev_transform_absolute(device, &point); + evdev_transform_relative(device, &delta); - return point; + *delta_out = delta; + *point_out = point; +} + +static inline struct normalized_coords +tablet_process_delta(struct tablet_dispatch *tablet, + const struct evdev_device *device, + const struct device_coords *delta, + uint64_t time) +{ + struct normalized_coords accel; + + /* The tablet accel code uses mm as input */ + accel.x = 1.0 * delta->x/device->abs.absinfo_x->resolution; + accel.y = 1.0 * delta->y/device->abs.absinfo_y->resolution; + + if (normalized_is_zero(accel)) + return accel; + + return filter_dispatch(device->pointer.filter, + &accel, tablet, time); } static inline double @@ -445,19 +481,22 @@ static bool tablet_check_notify_axes(struct tablet_dispatch *tablet, struct evdev_device *device, struct libinput_tablet_tool *tool, - struct tablet_axes *axes_out) + struct tablet_axes *axes_out, + uint64_t time) { struct tablet_axes axes = {0}; const char tmp[sizeof(tablet->changed_axes)] = {0}; + struct device_coords delta; if (memcmp(tmp, tablet->changed_axes, sizeof(tmp)) == 0) return false; - axes.point = tablet_handle_xy(tablet, device); + tablet_handle_xy(tablet, device, &axes.point, &delta); axes.pressure = tablet_handle_pressure(tablet, device, tool); axes.distance = tablet_handle_distance(tablet, device); axes.slider = tablet_handle_slider(tablet, device); axes.tilt = tablet_handle_tilt(tablet, device); + axes.delta = tablet_process_delta(tablet, device, &delta, time); /* We must check ROTATION_Z after TILT_X/Y so that the tilt axes are * already normalized and set if we have the mouse/lens tool */ @@ -1186,7 +1225,8 @@ tablet_send_axis_proximity_tip_down_events(struct tablet_dispatch *tablet, } else if (!tablet_check_notify_axes(tablet, device, tool, - &axes)) { + &axes, + time)) { goto out; } @@ -1463,11 +1503,64 @@ tablet_init_proximity_threshold(struct tablet_dispatch *tablet, tablet->cursor_proximity_threshold = 42; } +static uint32_t +tablet_accel_config_get_profiles(struct libinput_device *libinput_device) +{ + return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE; +} + +static enum libinput_config_status +tablet_accel_config_set_profile(struct libinput_device *libinput_device, + enum libinput_config_accel_profile profile) +{ + return LIBINPUT_CONFIG_STATUS_UNSUPPORTED; +} + +static enum libinput_config_accel_profile +tablet_accel_config_get_profile(struct libinput_device *libinput_device) +{ + return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE; +} + +static enum libinput_config_accel_profile +tablet_accel_config_get_default_profile(struct libinput_device *libinput_device) +{ + return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE; +} + +static int +tablet_init_accel(struct tablet_dispatch *tablet, struct evdev_device *device) +{ + const struct input_absinfo *x, *y; + struct motion_filter *filter; + int rc; + + x = device->abs.absinfo_x; + y = device->abs.absinfo_y; + + filter = create_pointer_accelerator_filter_tablet(x->resolution, + y->resolution); + + rc = evdev_device_init_pointer_acceleration(device, filter); + if (rc != 0) + return rc; + + /* we override the profile hooks for accel configuration with hooks + * that don't allow selection of profiles */ + device->pointer.config.get_profiles = tablet_accel_config_get_profiles; + device->pointer.config.set_profile = tablet_accel_config_set_profile; + device->pointer.config.get_profile = tablet_accel_config_get_profile; + device->pointer.config.get_default_profile = tablet_accel_config_get_default_profile; + + return 0; +} + static int tablet_init(struct tablet_dispatch *tablet, struct evdev_device *device) { enum libinput_tablet_tool_axis axis; + int rc; tablet->base.interface = &tablet_interface; tablet->device = device; @@ -1477,6 +1570,9 @@ tablet_init(struct tablet_dispatch *tablet, tablet_init_calibration(tablet, device); tablet_init_proximity_threshold(tablet, device); + rc = tablet_init_accel(tablet, device); + if (rc != 0) + return rc; for (axis = LIBINPUT_TABLET_TOOL_AXIS_X; axis <= LIBINPUT_TABLET_TOOL_AXIS_MAX; diff --git a/src/evdev.c b/src/evdev.c index 82359237..8f0a6079 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -222,6 +222,19 @@ evdev_transform_absolute(struct evdev_device *device, matrix_mult_vec(&device->abs.calibration, &point->x, &point->y); } +void +evdev_transform_relative(struct evdev_device *device, + struct device_coords *point) +{ + struct matrix rel_matrix; + + if (!device->abs.apply_calibration) + return; + + matrix_to_relative(&rel_matrix, &device->abs.calibration); + matrix_mult_vec(&rel_matrix, &point->x, &point->y); +} + static inline double scale_axis(const struct input_absinfo *absinfo, double val, double to_range) { diff --git a/src/evdev.h b/src/evdev.h index cf0eda9b..02b51126 100644 --- a/src/evdev.h +++ b/src/evdev.h @@ -292,6 +292,10 @@ void evdev_transform_absolute(struct evdev_device *device, struct device_coords *point); +void +evdev_transform_relative(struct evdev_device *device, + struct device_coords *point); + void evdev_init_calibration(struct evdev_device *device, struct evdev_dispatch *dispatch); diff --git a/src/filter.c b/src/filter.c index 0d0b95d4..4c39b0e2 100644 --- a/src/filter.c +++ b/src/filter.c @@ -163,6 +163,13 @@ struct pointer_accelerator_flat { double dpi_factor; }; +struct tablet_accelerator_flat { + struct motion_filter base; + + double factor; + int xres, yres; +}; + static void feed_trackers(struct pointer_accelerator *accel, const struct normalized_coords *delta, @@ -964,3 +971,90 @@ create_pointer_accelerator_filter_flat(int dpi) return &filter->base; } + +/* The tablet accel code uses mm as input */ +static struct normalized_coords +tablet_accelerator_filter_flat(struct motion_filter *filter, + const struct normalized_coords *mm, + void *data, uint64_t time) +{ + struct tablet_accelerator_flat *accel_filter = + (struct tablet_accelerator_flat *)filter; + struct normalized_coords accelerated; + + /* Tablet input is in mm, output is supposed to be in logical + * pixels roughly equivalent to a mouse/touchpad. + * + * This is a magical constant found by trial and error. On a 96dpi + * screen 0.4mm of movement correspond to 1px logical pixel which + * is almost identical to the tablet mapped to screen in absolute + * mode. Tested on a Intuos5, other tablets may vary. + */ + const double DPI_CONVERSION = 96.0/25.4 * 2.5; /* unitless factor */ + + accelerated.x = mm->x * accel_filter->factor * DPI_CONVERSION; + accelerated.y = mm->y * accel_filter->factor * DPI_CONVERSION; + + return accelerated; +} + +static bool +tablet_accelerator_set_speed(struct motion_filter *filter, + double speed_adjustment) +{ + struct tablet_accelerator_flat *accel_filter = + (struct tablet_accelerator_flat *)filter; + + assert(speed_adjustment >= -1.0 && speed_adjustment <= 1.0); + + accel_filter->factor = speed_adjustment + 1.0; + + return true; +} + +static void +tablet_accelerator_destroy(struct motion_filter *filter) +{ + struct tablet_accelerator_flat *accel_filter = + (struct tablet_accelerator_flat *)filter; + + free(accel_filter); +} + +struct motion_filter_interface accelerator_interface_tablet = { + .type = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT, + .filter = tablet_accelerator_filter_flat, + .filter_constant = NULL, + .restart = NULL, + .destroy = tablet_accelerator_destroy, + .set_speed = tablet_accelerator_set_speed, +}; + +static struct tablet_accelerator_flat * +create_tablet_filter_flat(int xres, int yres) +{ + struct tablet_accelerator_flat *filter; + + filter = zalloc(sizeof *filter); + if (filter == NULL) + return NULL; + + filter->xres = xres; + filter->yres = yres; + + return filter; +} + +struct motion_filter * +create_pointer_accelerator_filter_tablet(int xres, int yres) +{ + struct tablet_accelerator_flat *filter; + + filter = create_tablet_filter_flat(xres, yres); + if (!filter) + return NULL; + + filter->base.interface = &accelerator_interface_tablet; + + return &filter->base; +} diff --git a/src/filter.h b/src/filter.h index e1566429..c1b43a5d 100644 --- a/src/filter.h +++ b/src/filter.h @@ -101,6 +101,9 @@ create_pointer_accelerator_filter_lenovo_x230(int dpi); struct motion_filter * create_pointer_accelerator_filter_trackpoint(int dpi); +struct motion_filter * +create_pointer_accelerator_filter_tablet(int xres, int yres); + /* * Pointer acceleration profiles. */ diff --git a/src/libinput-util.h b/src/libinput-util.h index 93f7f0e4..6adbbc91 100644 --- a/src/libinput-util.h +++ b/src/libinput-util.h @@ -270,6 +270,16 @@ matrix_to_farray6(const struct matrix *m, float out[6]) out[5] = m->val[1][2]; } +static inline void +matrix_to_relative(struct matrix *dest, const struct matrix *src) +{ + matrix_init_identity(dest); + dest->val[0][0] = src->val[0][0]; + dest->val[0][1] = src->val[0][1]; + dest->val[1][0] = src->val[1][0]; + dest->val[1][1] = src->val[1][1]; +} + /** * Simple wrapper for asprintf that ensures the passed in-pointer is set * to NULL upon error. diff --git a/test/tablet.c b/test/tablet.c index 4976d1eb..59aefe5b 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -3205,6 +3205,205 @@ START_TEST(tilt_y) } END_TEST +START_TEST(relative_no_profile) +{ + struct litest_device *dev = litest_current_device(); + struct libinput_device *device = dev->libinput_device; + enum libinput_config_accel_profile profile; + enum libinput_config_status status; + uint32_t profiles; + + ck_assert(libinput_device_config_accel_is_available(device)); + + profile = libinput_device_config_accel_get_default_profile(device); + ck_assert_int_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); + + profile = libinput_device_config_accel_get_profile(device); + ck_assert_int_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); + + profiles = libinput_device_config_accel_get_profiles(device); + ck_assert_int_eq(profiles & LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE, 0); + ck_assert_int_eq(profiles & LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT, 0); + + status = libinput_device_config_accel_set_profile(device, + LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); + profile = libinput_device_config_accel_get_profile(device); + ck_assert_int_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); + + status = libinput_device_config_accel_set_profile(device, + LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED); + profile = libinput_device_config_accel_get_profile(device); + ck_assert_int_eq(profile, LIBINPUT_CONFIG_ACCEL_PROFILE_NONE); +} +END_TEST + +START_TEST(relative_no_delta_prox_in) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_tablet_tool *tev; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, + { -1, -1 } + }; + double dx, dy; + + litest_drain_events(li); + + litest_tablet_proximity_in(dev, 10, 10, axes); + libinput_dispatch(li); + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY); + dx = libinput_event_tablet_tool_get_dx(tev); + dy = libinput_event_tablet_tool_get_dy(tev); + ck_assert(dx == 0.0); + ck_assert(dy == 0.0); + + libinput_event_destroy(event); +} +END_TEST + +START_TEST(relative_delta) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_tablet_tool *tev; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, + { -1, -1 } + }; + double dx, dy; + + litest_tablet_proximity_in(dev, 10, 10, axes); + litest_drain_events(li); + + litest_tablet_motion(dev, 20, 10, axes); + libinput_dispatch(li); + + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + dx = libinput_event_tablet_tool_get_dx(tev); + dy = libinput_event_tablet_tool_get_dy(tev); + ck_assert(dx > 0.0); + ck_assert(dy == 0.0); + libinput_event_destroy(event); + + litest_tablet_motion(dev, 10, 10, axes); + libinput_dispatch(li); + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + dx = libinput_event_tablet_tool_get_dx(tev); + dy = libinput_event_tablet_tool_get_dy(tev); + ck_assert(dx < 0.0); + ck_assert(dy == 0.0); + libinput_event_destroy(event); + + litest_tablet_motion(dev, 10, 20, axes); + libinput_dispatch(li); + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + dx = libinput_event_tablet_tool_get_dx(tev); + dy = libinput_event_tablet_tool_get_dy(tev); + ck_assert(dx == 0.0); + ck_assert(dy > 0.0); + libinput_event_destroy(event); + + litest_tablet_motion(dev, 10, 10, axes); + libinput_dispatch(li); + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + dx = libinput_event_tablet_tool_get_dx(tev); + dy = libinput_event_tablet_tool_get_dy(tev); + ck_assert(dx == 0.0); + ck_assert(dy < 0.0); + libinput_event_destroy(event); +} +END_TEST + +START_TEST(relative_calibration) +{ + struct litest_device *dev = litest_current_device(); + struct libinput *li = dev->libinput; + struct libinput_event *event; + struct libinput_event_tablet_tool *tev; + struct axis_replacement axes[] = { + { ABS_DISTANCE, 10 }, + { ABS_PRESSURE, 0 }, + { -1, -1 } + }; + double dx, dy; + float calibration[] = { -1, 0, 1, 0, -1, 1 }; + enum libinput_config_status status; + + if (!libinput_device_config_calibration_has_matrix(dev->libinput_device)) + return; + + status = libinput_device_config_calibration_set_matrix( + dev->libinput_device, + calibration); + ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS); + + litest_tablet_proximity_in(dev, 10, 10, axes); + litest_drain_events(li); + + litest_tablet_motion(dev, 20, 10, axes); + libinput_dispatch(li); + + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + dx = libinput_event_tablet_tool_get_dx(tev); + dy = libinput_event_tablet_tool_get_dy(tev); + ck_assert(dx < 0.0); + ck_assert(dy == 0.0); + libinput_event_destroy(event); + + litest_tablet_motion(dev, 10, 10, axes); + libinput_dispatch(li); + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + dx = libinput_event_tablet_tool_get_dx(tev); + dy = libinput_event_tablet_tool_get_dy(tev); + ck_assert(dx > 0.0); + ck_assert(dy == 0.0); + libinput_event_destroy(event); + + litest_tablet_motion(dev, 10, 20, axes); + libinput_dispatch(li); + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + dx = libinput_event_tablet_tool_get_dx(tev); + dy = libinput_event_tablet_tool_get_dy(tev); + ck_assert(dx == 0.0); + ck_assert(dy < 0.0); + libinput_event_destroy(event); + + litest_tablet_motion(dev, 10, 10, axes); + libinput_dispatch(li); + event = libinput_get_event(li); + tev = litest_is_tablet_event(event, + LIBINPUT_EVENT_TABLET_TOOL_AXIS); + dx = libinput_event_tablet_tool_get_dx(tev); + dy = libinput_event_tablet_tool_get_dy(tev); + ck_assert(dx == 0.0); + ck_assert(dy > 0.0); + libinput_event_destroy(event); +} +END_TEST + void litest_setup_tests(void) { @@ -3271,4 +3470,9 @@ litest_setup_tests(void) litest_add_for_device("tablet:pressure", tablet_pressure_offset_exceed_threshold, LITEST_WACOM_INTUOS); litest_add_for_device("tablet:pressure", tablet_pressure_offset_none_for_zero_distance, LITEST_WACOM_INTUOS); litest_add_for_device("tablet:pressure", tablet_pressure_offset_none_for_small_distance, LITEST_WACOM_INTUOS); + + litest_add("tablet:relative", relative_no_profile, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:relative", relative_no_delta_prox_in, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:relative", relative_delta, LITEST_TABLET, LITEST_ANY); + litest_add("tablet:relative", relative_calibration, LITEST_TABLET, LITEST_ANY); } From 7899a6cf8d2446563e8a9e8b6d27cbbebe46aa01 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 12 Jan 2016 16:39:15 +1000 Subject: [PATCH 249/255] tools: add support for tablet relative events to the event-gui Signed-off-by: Peter Hutterer Acked-by: Jason Gerecke --- tools/event-gui.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tools/event-gui.c b/tools/event-gui.c index fa0e1a09..bb73d781 100644 --- a/tools/event-gui.c +++ b/tools/event-gui.c @@ -51,6 +51,10 @@ struct touch { int x, y; }; +struct point { + double x, y; +}; + struct window { GtkWidget *win; GtkWidget *area; @@ -93,6 +97,12 @@ struct window { double pressure; double distance; double tilt_x, tilt_y; + + /* these are for the delta coordinates, but they're not + * deltas, theyconverted into + * abs positions */ + size_t ndeltas; + struct point deltas[64]; } tool; struct libinput_device *devices[50]; @@ -128,6 +138,8 @@ draw(GtkWidget *widget, cairo_t *cr, gpointer data) struct window *w = data; struct touch *t; int i, offset; + int first, last, mask; + double x, y; cairo_set_source_rgb(cr, 1, 1, 1); cairo_rectangle(cr, 0, 0, w->width, w->height); @@ -261,6 +273,26 @@ draw(GtkWidget *widget, cairo_t *cr, gpointer data) cairo_fill(cr); cairo_restore(cr); + /* tablet deltas */ + mask = ARRAY_LENGTH(w->tool.deltas); + first = max(w->tool.ndeltas + 1, mask) - mask; + last = w->tool.ndeltas; + + cairo_save(cr); + cairo_set_source_rgb(cr, .8, .8, .2); + + x = w->tool.deltas[first % mask].x; + y = w->tool.deltas[first % mask].y; + cairo_move_to(cr, x, y); + + for (i = first + 1; i < last; i++) { + x = w->tool.deltas[i % mask].x; + y = w->tool.deltas[i % mask].y; + cairo_line_to(cr, x, y); + } + + cairo_stroke(cr); + return TRUE; } @@ -601,6 +633,9 @@ handle_event_tablet(struct libinput_event *ev, struct window *w) { struct libinput_event_tablet_tool *t = libinput_event_get_tablet_tool_event(ev); double x, y; + struct point point; + int idx; + const int mask = ARRAY_LENGTH(w->tool.deltas); x = libinput_event_tablet_tool_get_x_transformed(t, w->width); y = libinput_event_tablet_tool_get_y_transformed(t, w->height); @@ -618,6 +653,9 @@ handle_event_tablet(struct libinput_event *ev, struct window *w) } else { w->tool.x_in = x; w->tool.y_in = y; + w->tool.ndeltas = 0; + w->tool.deltas[0].x = w->width/2; + w->tool.deltas[0].y = w->height/2; } break; case LIBINPUT_EVENT_TABLET_TOOL_TIP: @@ -641,6 +679,17 @@ handle_event_tablet(struct libinput_event *ev, struct window *w) w->tool.distance = libinput_event_tablet_tool_get_distance(t); w->tool.tilt_x = libinput_event_tablet_tool_get_tilt_x(t); w->tool.tilt_y = libinput_event_tablet_tool_get_tilt_y(t); + + /* Add the delta to the last position and store them as abs + * coordinates */ + idx = w->tool.ndeltas % mask; + point = w->tool.deltas[idx]; + + idx = (w->tool.ndeltas + 1) % mask; + point.x += libinput_event_tablet_tool_get_dx(t); + point.y += libinput_event_tablet_tool_get_dy(t); + w->tool.deltas[idx] = point; + w->tool.ndeltas++; break; case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: break; From f5a60d1d82a5ac91a07548a1a59865b5f8b7cad5 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 22 Jan 2016 18:04:41 +1000 Subject: [PATCH 250/255] test: shut up coverity warnings Coverity claims they're used uninitialized which isn't true. The condition that guards it's use also guards its initialization. Signed-off-by: Peter Hutterer --- test/tablet.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/tablet.c b/test/tablet.c index 59aefe5b..8936d577 100644 --- a/test/tablet.c +++ b/test/tablet.c @@ -841,8 +841,9 @@ START_TEST(proximity_has_axes) struct libinput_tablet_tool *tool; double x, y, distance; - double last_x, last_y, last_distance, - last_tx, last_ty; + double last_x, last_y, + last_distance = 0.0, + last_tx = 0.0, last_ty = 0.0; struct axis_replacement axes[] = { { ABS_DISTANCE, 10 }, From a6b43386d6bbd196ee5357d26d5e338a26d8c8c2 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 22 Jan 2016 18:06:01 +1000 Subject: [PATCH 251/255] test: fix uninitialized variable Found by coverity Signed-off-by: Peter Hutterer --- test/misc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/misc.c b/test/misc.c index 4e37007a..5ae87a07 100644 --- a/test/misc.c +++ b/test/misc.c @@ -442,7 +442,7 @@ START_TEST(bitfield_helpers) * 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)]; + unsigned char write_bitfield[ARRAY_LENGTH(read_bitfield)] = {0}; size_t i; /* Now check that the bitfield we wrote to came out to be the same as From 6920a42fd4ec8dfa633ef5bc1865f994afc63693 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 22 Jan 2016 18:08:44 +1000 Subject: [PATCH 252/255] tablet: fix potential null-pointer dereference Found by coverity Signed-off-by: Peter Hutterer --- src/evdev-tablet.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index ae205501..e684055b 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -875,6 +875,8 @@ tablet_get_tool(struct tablet_dispatch *tablet, const struct input_absinfo *pressure; tool = zalloc(sizeof *tool); + if (!tool) + return NULL; *tool = (struct libinput_tablet_tool) { .type = type, .serial = serial, @@ -1295,6 +1297,9 @@ tablet_flush(struct tablet_dispatch *tablet, tablet->current_tool_id, tablet->current_tool_serial); + if (!tool) + return; /* OOM */ + if (tool->type == LIBINPUT_TABLET_TOOL_TYPE_MOUSE || tool->type == LIBINPUT_TABLET_TOOL_TYPE_LENS) tablet_update_proximity_state(tablet, device, tool); From 71fcd387f716f46b553f6646561cd33f3ca2eb54 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 25 Jan 2016 10:50:02 +1000 Subject: [PATCH 253/255] gestures: jump straight to swipe for 3+ finger gestures on ST touchpads The first/second variables are only needed for pinch, so we can skip them here. Signed-off-by: Peter Hutterer --- src/evdev-mt-touchpad-gestures.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/evdev-mt-touchpad-gestures.c b/src/evdev-mt-touchpad-gestures.c index 5aa256fd..8fe0bb85 100644 --- a/src/evdev-mt-touchpad-gestures.c +++ b/src/evdev-mt-touchpad-gestures.c @@ -240,6 +240,13 @@ tp_gesture_handle_state_none(struct tp_dispatch *tp, uint64_t time) if (ntouches < 2) return GESTURE_STATE_NONE; + if (!tp->gesture.enabled) { + if (ntouches == 2) + return GESTURE_STATE_SCROLL; + else + return GESTURE_STATE_SWIPE; + } + first = touches[0]; second = touches[1]; @@ -271,8 +278,7 @@ tp_gesture_handle_state_none(struct tp_dispatch *tp, uint64_t time) if (first == second) return GESTURE_STATE_NONE; - } else if (!tp->gesture.enabled) - return GESTURE_STATE_SCROLL; + } tp->gesture.initial_time = time; first->gesture.initial = first->point; From b6f59d0e3b2e38abd0c79e36a5971dc7ea1e2b16 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 25 Jan 2016 11:19:58 +1000 Subject: [PATCH 254/255] gestures: average motion by active touches, not moved touches Signed-off-by: Peter Hutterer --- src/evdev-mt-touchpad-gestures.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/evdev-mt-touchpad-gestures.c b/src/evdev-mt-touchpad-gestures.c index 8fe0bb85..dc8d6060 100644 --- a/src/evdev-mt-touchpad-gestures.c +++ b/src/evdev-mt-touchpad-gestures.c @@ -49,15 +49,19 @@ static struct normalized_coords tp_get_touches_delta(struct tp_dispatch *tp, bool average) { struct tp_touch *t; - unsigned int i, nchanged = 0; + unsigned int i, nactive = 0; struct normalized_coords normalized; struct normalized_coords delta = {0.0, 0.0}; for (i = 0; i < tp->num_slots; i++) { t = &tp->touches[i]; - if (tp_touch_active(tp, t) && t->dirty) { - nchanged++; + if (!tp_touch_active(tp, t)) + continue; + + nactive++; + + if (t->dirty) { normalized = tp_get_delta(t); delta.x += normalized.x; @@ -65,11 +69,11 @@ tp_get_touches_delta(struct tp_dispatch *tp, bool average) } } - if (!average || nchanged == 0) + if (!average || nactive == 0) return delta; - delta.x /= nchanged; - delta.y /= nchanged; + delta.x /= nactive; + delta.y /= nactive; return delta; } From 62a0097d9698aefb12babc8742a389d71a0748ad Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 27 Jan 2016 15:38:47 +1000 Subject: [PATCH 255/255] Prepare tablet-support branch for merging Signed-off-by: Peter Hutterer --- src/libinput.sym | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/libinput.sym b/src/libinput.sym index 40143d8d..a2113883 100644 --- a/src/libinput.sym +++ b/src/libinput.sym @@ -185,11 +185,6 @@ LIBINPUT_1.2 { libinput_device_config_tap_get_drag_enabled; libinput_device_config_tap_get_default_drag_enabled; libinput_device_config_tap_set_drag_enabled; -} LIBINPUT_1.1; - -/* tablet APIs, they are not part of any stable API promise yet. - * keep them separate */ -LIBINPUT_TABLET_SUPPORT { libinput_event_get_tablet_tool_event; libinput_event_tablet_tool_x_has_changed; libinput_event_tablet_tool_y_has_changed; @@ -238,4 +233,4 @@ LIBINPUT_TABLET_SUPPORT { libinput_tablet_tool_ref; libinput_tablet_tool_set_user_data; libinput_tablet_tool_unref; -} LIBINPUT_1.2; +} LIBINPUT_1.1;