From 857411f84e14ca7fe816d93ffa2c39fc617cddce Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 28 Nov 2016 09:44:04 +1000 Subject: [PATCH 1/3] Add wheel tilt as axis source Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/libinput.h | 15 +++++++++++++++ tools/event-debug.c | 3 +++ 2 files changed, 18 insertions(+) diff --git a/src/libinput.h b/src/libinput.h index 18a96bd4..aac93fcf 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -259,6 +259,12 @@ enum libinput_pointer_axis_source { * The event is caused by the motion of some device. */ LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS, + /** + * The event is caused by the tilting of a mouse wheel rather than + * its rotation. This method is commonly used on mice without + * separate horizontal scroll wheels. + */ + LIBINPUT_POINTER_AXIS_SOURCE_WHEEL_TILT, }; /** @@ -1285,6 +1291,15 @@ libinput_event_pointer_get_axis_value(struct libinput_event_pointer *event, * The coordinate system is identical to the cursor movement, i.e. a * scroll value of 1 represents the equivalent relative motion of 1. * + * If the source is @ref LIBINPUT_POINTER_AXIS_SOURCE_WHEEL_TILT, no + * terminating event is guaranteed (though it may happen). + * Scrolling is in discrete steps and there is no physical equivalent for + * the value returned here. For backwards compatibility, the value returned + * by this function is identical to a single mouse wheel rotation by this + * device (see the documentation for @ref LIBINPUT_POINTER_AXIS_SOURCE_WHEEL + * above). Callers should not use this value but instead exclusively refer + * to the value returned by libinput_event_pointer_get_axis_value_discrete(). + * * For pointer events that are not of type @ref LIBINPUT_EVENT_POINTER_AXIS, * this function returns 0. * diff --git a/tools/event-debug.c b/tools/event-debug.c index d7d20188..a3e460a2 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -377,6 +377,9 @@ print_pointer_axis_event(struct libinput_event *ev) case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS: source = "continuous"; break; + case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL_TILT: + source = "tilt"; + break; } if (libinput_event_pointer_has_axis(p, From 4bf8b8934d6d8fc304ae0631d9a346c80f3ea201 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 28 Nov 2016 10:52:16 +1000 Subject: [PATCH 2/3] evdev: add support for wheel tilt This is added on top of the click angle handling, so the actual axis values simply fall back onto whatever is set by udev, including the default fallbacks to 15 and whatnot. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/evdev.c | 31 +++++++++++++++++++++++++++++-- src/evdev.h | 2 ++ src/libinput-private.h | 5 +++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/evdev.c b/src/evdev.c index c06daa66..83d762e0 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -958,6 +958,7 @@ fallback_process_relative(struct fallback_dispatch *dispatch, { struct normalized_coords wheel_degrees = { 0.0, 0.0 }; struct discrete_coords discrete = { 0.0, 0.0 }; + enum libinput_pointer_axis_source source; if (fallback_reject_relative(device, e, time)) return; @@ -980,11 +981,16 @@ fallback_process_relative(struct fallback_dispatch *dispatch, wheel_degrees.y = -1 * e->value * device->scroll.wheel_click_angle.x; discrete.y = -1 * e->value; + + source = device->scroll.is_tilt.vertical ? + LIBINPUT_POINTER_AXIS_SOURCE_WHEEL_TILT: + LIBINPUT_POINTER_AXIS_SOURCE_WHEEL; + evdev_notify_axis( device, time, AS_MASK(LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL), - LIBINPUT_POINTER_AXIS_SOURCE_WHEEL, + source, &wheel_degrees, &discrete); break; @@ -993,11 +999,16 @@ fallback_process_relative(struct fallback_dispatch *dispatch, wheel_degrees.x = e->value * device->scroll.wheel_click_angle.y; discrete.x = e->value; + + source = device->scroll.is_tilt.horizontal ? + LIBINPUT_POINTER_AXIS_SOURCE_WHEEL_TILT: + LIBINPUT_POINTER_AXIS_SOURCE_WHEEL; + evdev_notify_axis( device, time, AS_MASK(LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL), - LIBINPUT_POINTER_AXIS_SOURCE_WHEEL, + source, &wheel_degrees, &discrete); break; @@ -2110,6 +2121,21 @@ evdev_read_wheel_click_props(struct evdev_device *device) return angles; } +static inline struct wheel_tilt_flags +evdev_read_wheel_tilt_props(struct evdev_device *device) +{ + struct wheel_tilt_flags flags; + + flags.vertical = parse_udev_flag(device, + device->udev_device, + "MOUSE_WHEEL_TILT_VERTICAL"); + + flags.horizontal = parse_udev_flag(device, + device->udev_device, + "MOUSE_WHEEL_TILT_HORIZONTAL"); + return flags; +} + static inline int evdev_get_trackpoint_dpi(struct evdev_device *device) { @@ -2848,6 +2874,7 @@ evdev_device_create(struct libinput_seat *seat, device->scroll.direction = 0; device->scroll.wheel_click_angle = evdev_read_wheel_click_props(device); + device->scroll.is_tilt = evdev_read_wheel_tilt_props(device); device->model_flags = evdev_read_model_flags(device); device->dpi = DEFAULT_MOUSE_DPI; diff --git a/src/evdev.h b/src/evdev.h index c07b09fe..4fb2651e 100644 --- a/src/evdev.h +++ b/src/evdev.h @@ -198,6 +198,8 @@ struct evdev_device { /* angle per REL_WHEEL click in degrees */ struct wheel_angle wheel_click_angle; + + struct wheel_tilt_flags is_tilt; } scroll; struct { diff --git a/src/libinput-private.h b/src/libinput-private.h index 0c75b3aa..40cc9269 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -94,6 +94,11 @@ struct phys_coords { double y; }; +/* A pair of tilt flags */ +struct wheel_tilt_flags { + bool vertical, horizontal; +}; + struct tablet_axes { struct device_coords point; struct normalized_coords delta; From dbb376f74b78ed3e6ca0dd94c5bd2cf596a652a5 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 28 Nov 2016 11:08:01 +1000 Subject: [PATCH 3/3] test: add wheel tilt tests Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- test/Makefile.am | 1 + test/litest-device-mouse-wheel-tilt.c | 76 +++++++++++++++++++++++++++ test/litest.c | 2 + test/litest.h | 1 + test/pointer.c | 34 ++++++++++-- 5 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 test/litest-device-mouse-wheel-tilt.c diff --git a/test/Makefile.am b/test/Makefile.am index 983264c8..3eb8446c 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -36,6 +36,7 @@ liblitest_la_SOURCES = \ litest-device-nexus4-touch-screen.c \ litest-device-magic-trackpad.c \ litest-device-mouse.c \ + litest-device-mouse-wheel-tilt.c \ litest-device-mouse-roccat.c \ litest-device-mouse-low-dpi.c \ litest-device-mouse-wheel-click-angle.c \ diff --git a/test/litest-device-mouse-wheel-tilt.c b/test/litest-device-mouse-wheel-tilt.c new file mode 100644 index 00000000..2a63469c --- /dev/null +++ b/test/litest-device-mouse-wheel-tilt.c @@ -0,0 +1,76 @@ +/* + * Copyright © 2016 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include "litest.h" +#include "litest-int.h" + +static void litest_mouse_setup(void) +{ + struct litest_device *d = litest_create_device(LITEST_MOUSE_WHEEL_TILT); + litest_set_current_device(d); +} + +static struct input_id input_id = { + .bustype = 0x3, + .vendor = 0x17ef, + .product = 0x6019, +}; + +static int events[] = { + EV_KEY, BTN_LEFT, + EV_KEY, BTN_RIGHT, + EV_KEY, BTN_MIDDLE, + EV_REL, REL_X, + EV_REL, REL_Y, + EV_REL, REL_WHEEL, + EV_REL, REL_HWHEEL, + -1 , -1, +}; + +static const char udev_rule[] = +"ACTION==\"remove\", GOTO=\"wheel_wheel_tilt_end\"\n" +"KERNEL!=\"event*\", GOTO=\"wheel_wheel_tilt_end\"\n" +"\n" +"ATTRS{name}==\"litest Wheel Tilt Mouse*\",\\\n" +" ENV{MOUSE_WHEEL_TILT_HORIZONTAL}=\"1\",\\\n" +" ENV{MOUSE_WHEEL_TILT_VERTICAL}=\"1\"\n" +"\n" +"LABEL=\"wheel_wheel_tilt_end\""; + +struct litest_test_device litest_mouse_wheel_tilt_device = { + .type = LITEST_MOUSE_WHEEL_TILT, + .features = LITEST_RELATIVE | LITEST_BUTTON | LITEST_WHEEL, + .shortname = "mouse-wheel-tilt", + .setup = litest_mouse_setup, + .interface = NULL, + + .name = "Wheel Tilt Mouse", + .id = &input_id, + .absinfo = NULL, + .events = events, + .udev_rule = udev_rule, +}; diff --git a/test/litest.c b/test/litest.c index 0574c0a4..9178c679 100644 --- a/test/litest.c +++ b/test/litest.c @@ -406,6 +406,7 @@ extern struct litest_test_device litest_mouse_wheel_click_count_device; extern struct litest_test_device litest_calibrated_touchscreen_device; extern struct litest_test_device litest_acer_hawaii_keyboard_device; extern struct litest_test_device litest_acer_hawaii_touchpad_device; +extern struct litest_test_device litest_mouse_wheel_tilt_device; struct litest_test_device* devices[] = { &litest_synaptics_clickpad_device, @@ -466,6 +467,7 @@ struct litest_test_device* devices[] = { &litest_calibrated_touchscreen_device, &litest_acer_hawaii_keyboard_device, &litest_acer_hawaii_touchpad_device, + &litest_mouse_wheel_tilt_device, NULL, }; diff --git a/test/litest.h b/test/litest.h index a7075096..46a916a0 100644 --- a/test/litest.h +++ b/test/litest.h @@ -226,6 +226,7 @@ enum litest_device_type { LITEST_CALIBRATED_TOUCHSCREEN, LITEST_ACER_HAWAII_KEYBOARD, LITEST_ACER_HAWAII_TOUCHPAD, + LITEST_MOUSE_WHEEL_TILT, }; enum litest_device_feature { diff --git a/test/pointer.c b/test/pointer.c index e0cd0646..291f5456 100644 --- a/test/pointer.c +++ b/test/pointer.c @@ -531,6 +531,33 @@ out: return angle; } +static enum libinput_pointer_axis_source +wheel_source(struct litest_device *dev, int which) +{ + struct udev_device *d; + bool is_tilt = false; + + d = libinput_device_get_udev_device(dev->libinput_device); + litest_assert_ptr_notnull(d); + + switch(which) { + case REL_WHEEL: + is_tilt = !!udev_device_get_property_value(d, "MOUSE_WHEEL_TILT_VERTICAL"); + break; + case REL_HWHEEL: + is_tilt = !!udev_device_get_property_value(d, "MOUSE_WHEEL_TILT_HORIZONTAL"); + break; + default: + litest_abort_msg("Invalid source axis %d\n", which); + break; + } + + udev_device_unref(d); + return is_tilt ? + LIBINPUT_POINTER_AXIS_SOURCE_WHEEL_TILT : + LIBINPUT_POINTER_AXIS_SOURCE_WHEEL; +} + static void test_wheel_event(struct litest_device *dev, int which, int amount) { @@ -538,10 +565,12 @@ test_wheel_event(struct litest_device *dev, int which, int amount) struct libinput_event *event; struct libinput_event_pointer *ptrev; enum libinput_pointer_axis axis; + enum libinput_pointer_axis_source source; double scroll_step, expected, discrete; scroll_step = wheel_click_angle(dev, which); + source = wheel_source(dev, which); expected = amount * scroll_step; discrete = amount; @@ -561,10 +590,9 @@ test_wheel_event(struct litest_device *dev, int which, int amount) axis = (which == REL_WHEEL) ? LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL : LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL; + event = libinput_get_event(li); - ptrev = litest_is_axis_event(event, - axis, - LIBINPUT_POINTER_AXIS_SOURCE_WHEEL); + ptrev = litest_is_axis_event(event, axis, source); litest_assert_double_eq( libinput_event_pointer_get_axis_value(ptrev, axis),