| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501 |
- /*
- * Copyright © 2014 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.
- */
- #include <config.h>
- #include <errno.h>
- #include <fcntl.h>
- #include <libinput.h>
- #include <unistd.h>
- #include "libinput-util.h"
- #include "litest.h"
- static inline bool
- has_disable_while_trackpointing(struct litest_device *device)
- {
- return libinput_device_config_dwtp_is_available(device->libinput_device);
- }
- START_TEST(trackpoint_middlebutton)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_event *event;
- struct libinput_event_pointer *ptrev;
- uint64_t ptime, rtime;
- litest_drain_events(li);
- /* A quick middle button click should get reported normally */
- litest_button_click_debounced(dev, li, BTN_MIDDLE, 1);
- msleep(2);
- litest_button_click_debounced(dev, li, BTN_MIDDLE, 0);
- litest_wait_for_event(li);
- event = libinput_get_event(li);
- ptrev = litest_is_button_event(event,
- BTN_MIDDLE,
- LIBINPUT_BUTTON_STATE_PRESSED);
- ptime = libinput_event_pointer_get_time(ptrev);
- libinput_event_destroy(event);
- event = libinput_get_event(li);
- ptrev = litest_is_button_event(event,
- BTN_MIDDLE,
- LIBINPUT_BUTTON_STATE_RELEASED);
- rtime = libinput_event_pointer_get_time(ptrev);
- libinput_event_destroy(event);
- litest_assert_int_lt(ptime, rtime);
- litest_assert_empty_queue(li);
- }
- END_TEST
- START_TEST(trackpoint_scroll)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- litest_drain_events(li);
- litest_button_scroll(dev, BTN_MIDDLE, 1, 6);
- litest_assert_scroll(li,
- LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS,
- LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
- 6);
- litest_button_scroll(dev, BTN_MIDDLE, 1, -7);
- litest_assert_scroll(li,
- LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS,
- LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
- -7);
- litest_button_scroll(dev, BTN_MIDDLE, 8, 1);
- litest_assert_scroll(li,
- LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS,
- LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
- 8);
- litest_button_scroll(dev, BTN_MIDDLE, -9, 1);
- litest_assert_scroll(li,
- LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS,
- LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
- -9);
- /* scroll smaller than the threshold should not generate axis events */
- litest_button_scroll(dev, BTN_MIDDLE, 1, 1);
- litest_button_scroll(dev, BTN_MIDDLE, 0, 0);
- litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_PRESSED);
- litest_assert_button_event(li, BTN_MIDDLE, LIBINPUT_BUTTON_STATE_RELEASED);
- litest_assert_empty_queue(li);
- }
- END_TEST
- START_TEST(trackpoint_middlebutton_noscroll)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_event *event;
- /* Disable middle button scrolling */
- libinput_device_config_scroll_set_method(dev->libinput_device,
- LIBINPUT_CONFIG_SCROLL_NO_SCROLL);
- litest_drain_events(li);
- /* A long middle button click + motion should get reported normally now */
- litest_button_scroll(dev, BTN_MIDDLE, 0, 10);
- litest_assert_button_event(li, BTN_MIDDLE, 1);
- event = libinput_get_event(li);
- litest_assert_notnull(event);
- litest_assert_event_type(event, LIBINPUT_EVENT_POINTER_MOTION);
- libinput_event_destroy(event);
- litest_assert_button_event(li, BTN_MIDDLE, 0);
- litest_assert_empty_queue(li);
- /* Restore default scroll behavior */
- libinput_device_config_scroll_set_method(
- dev->libinput_device,
- libinput_device_config_scroll_get_default_method(dev->libinput_device));
- }
- END_TEST
- START_TEST(trackpoint_scroll_source)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_event *event;
- struct libinput_event_pointer *ptrev;
- litest_drain_events(li);
- litest_button_scroll(dev, BTN_MIDDLE, 0, 6);
- litest_wait_for_event_of_type(li, LIBINPUT_EVENT_POINTER_AXIS);
- while ((event = libinput_get_event(li))) {
- ptrev = libinput_event_get_pointer_event(event);
- litest_assert_enum_eq(litest_event_pointer_get_axis_source(ptrev),
- LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS);
- libinput_event_destroy(event);
- }
- }
- END_TEST
- START_TEST(trackpoint_topsoftbuttons_left_handed_trackpoint)
- {
- struct litest_device *touchpad = litest_current_device();
- struct libinput *li = touchpad->libinput;
- enum libinput_config_status status;
- struct libinput_event *event;
- struct libinput_device *device;
- litest_disable_hold_gestures(touchpad->libinput_device);
- _destroy_(litest_device) *trackpoint = litest_add_device(li, LITEST_TRACKPOINT);
- litest_drain_events(li);
- /* touchpad right-handed, trackpoint left-handed */
- status = libinput_device_config_left_handed_set(trackpoint->libinput_device, 1);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- litest_touch_down(touchpad, 0, 5, 5);
- litest_dispatch(li);
- litest_button_click_debounced(touchpad, li, BTN_LEFT, true);
- litest_dispatch(li);
- event = libinput_get_event(li);
- litest_is_button_event(event, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED);
- device = libinput_event_get_device(event);
- litest_assert(device == trackpoint->libinput_device);
- libinput_event_destroy(event);
- litest_button_click_debounced(touchpad, li, BTN_LEFT, false);
- litest_dispatch(li);
- event = libinput_get_event(li);
- litest_is_button_event(event, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED);
- device = libinput_event_get_device(event);
- litest_assert(device == trackpoint->libinput_device);
- libinput_event_destroy(event);
- }
- END_TEST
- START_TEST(trackpoint_topsoftbuttons_left_handed_touchpad)
- {
- struct litest_device *touchpad = litest_current_device();
- struct libinput *li = touchpad->libinput;
- enum libinput_config_status status;
- struct libinput_event *event;
- struct libinput_device *device;
- litest_disable_hold_gestures(touchpad->libinput_device);
- _destroy_(litest_device) *trackpoint = litest_add_device(li, LITEST_TRACKPOINT);
- litest_drain_events(li);
- /* touchpad left-handed, trackpoint right-handed */
- status = libinput_device_config_left_handed_set(touchpad->libinput_device, 1);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- litest_touch_down(touchpad, 0, 5, 5);
- litest_dispatch(li);
- litest_button_click_debounced(touchpad, li, BTN_LEFT, true);
- litest_dispatch(li);
- event = libinput_get_event(li);
- litest_is_button_event(event, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
- device = libinput_event_get_device(event);
- litest_assert(device == trackpoint->libinput_device);
- libinput_event_destroy(event);
- litest_button_click_debounced(touchpad, li, BTN_LEFT, false);
- litest_dispatch(li);
- event = libinput_get_event(li);
- litest_is_button_event(event, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED);
- device = libinput_event_get_device(event);
- litest_assert(device == trackpoint->libinput_device);
- libinput_event_destroy(event);
- }
- END_TEST
- START_TEST(trackpoint_topsoftbuttons_left_handed_both)
- {
- struct litest_device *touchpad = litest_current_device();
- struct libinput *li = touchpad->libinput;
- enum libinput_config_status status;
- struct libinput_event *event;
- struct libinput_device *device;
- litest_disable_hold_gestures(touchpad->libinput_device);
- _destroy_(litest_device) *trackpoint = litest_add_device(li, LITEST_TRACKPOINT);
- litest_drain_events(li);
- /* touchpad left-handed, trackpoint left-handed */
- status = libinput_device_config_left_handed_set(touchpad->libinput_device, 1);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- status = libinput_device_config_left_handed_set(trackpoint->libinput_device, 1);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- litest_touch_down(touchpad, 0, 5, 5);
- litest_dispatch(li);
- litest_button_click_debounced(touchpad, li, BTN_LEFT, true);
- litest_dispatch(li);
- event = libinput_get_event(li);
- litest_is_button_event(event, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED);
- device = libinput_event_get_device(event);
- litest_assert(device == trackpoint->libinput_device);
- libinput_event_destroy(event);
- litest_button_click_debounced(touchpad, li, BTN_LEFT, false);
- litest_dispatch(li);
- event = libinput_get_event(li);
- litest_is_button_event(event, BTN_RIGHT, LIBINPUT_BUTTON_STATE_RELEASED);
- device = libinput_event_get_device(event);
- litest_assert(device == trackpoint->libinput_device);
- libinput_event_destroy(event);
- }
- END_TEST
- static inline void
- enable_dwtp_with_timeout(struct litest_device *dev, uint32_t timeout)
- {
- enum libinput_config_status status, expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
- status = libinput_device_config_dwtp_set_enabled(dev->libinput_device,
- LIBINPUT_CONFIG_DWTP_ENABLED);
- litest_assert_enum_eq(status, expected);
- if (timeout) {
- auto status =
- libinput_device_config_dwtp_set_timeout(dev->libinput_device,
- timeout);
- litest_assert_enum_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
- }
- }
- static inline void
- enable_dwtp(struct litest_device *dev)
- {
- enable_dwtp_with_timeout(dev, 0);
- }
- static inline void
- disable_dwtp(struct litest_device *dev)
- {
- enum libinput_config_status status, expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
- status = libinput_device_config_dwtp_set_enabled(dev->libinput_device,
- LIBINPUT_CONFIG_DWTP_DISABLED);
- litest_assert_enum_eq(status, expected);
- }
- START_TEST(trackpoint_palmdetect)
- {
- struct litest_device *trackpoint = litest_current_device();
- struct libinput *li = trackpoint->libinput;
- int i;
- uint32_t timeout = litest_test_param_get_u32(test_env->params, "timeout");
- _destroy_(litest_device) *touchpad =
- litest_add_device(li, LITEST_SYNAPTICS_I2C);
- if (has_disable_while_trackpointing(touchpad))
- enable_dwtp_with_timeout(touchpad, timeout);
- litest_disable_hold_gestures(touchpad->libinput_device);
- litest_drain_events(li);
- for (i = 0; i < 10; i++) {
- litest_event(trackpoint, EV_REL, REL_X, 1);
- litest_event(trackpoint, EV_REL, REL_Y, 1);
- litest_event(trackpoint, EV_SYN, SYN_REPORT, 0);
- litest_dispatch(li);
- }
- litest_drain_events(li);
- litest_touch_down(touchpad, 0, 30, 30);
- litest_touch_move_to(touchpad, 0, 30, 30, 80, 80, 10);
- litest_touch_up(touchpad, 0);
- litest_assert_empty_queue(li);
- if (timeout) {
- litest_timeout(li, timeout);
- } else {
- litest_timeout_trackpoint(li);
- }
- litest_touch_down(touchpad, 0, 30, 30);
- litest_touch_move_to(touchpad, 0, 30, 30, 80, 80, 10);
- litest_touch_up(touchpad, 0);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
- }
- END_TEST
- START_TEST(trackpoint_palmdetect_dwtp_disabled)
- {
- struct litest_device *trackpoint = litest_current_device();
- struct libinput *li = trackpoint->libinput;
- int i;
- _destroy_(litest_device) *touchpad =
- litest_add_device(li, LITEST_SYNAPTICS_I2C);
- if (has_disable_while_trackpointing(touchpad))
- disable_dwtp(touchpad);
- litest_disable_hold_gestures(touchpad->libinput_device);
- litest_drain_events(li);
- for (i = 0; i < 10; i++) {
- litest_event(trackpoint, EV_REL, REL_X, 1);
- litest_event(trackpoint, EV_REL, REL_Y, 1);
- litest_event(trackpoint, EV_SYN, SYN_REPORT, 0);
- litest_dispatch(li);
- }
- litest_drain_events(li);
- litest_touch_down(touchpad, 0, 30, 30);
- litest_touch_move_to(touchpad, 0, 30, 30, 80, 80, 10);
- litest_touch_up(touchpad, 0);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
- }
- END_TEST
- START_TEST(trackpoint_palmdetect_resume_touch)
- {
- struct litest_device *trackpoint = litest_current_device();
- struct libinput *li = trackpoint->libinput;
- int i;
- _destroy_(litest_device) *touchpad =
- litest_add_device(li, LITEST_SYNAPTICS_I2C);
- if (has_disable_while_trackpointing(touchpad))
- enable_dwtp(touchpad);
- litest_disable_hold_gestures(touchpad->libinput_device);
- litest_drain_events(li);
- for (i = 0; i < 10; i++) {
- litest_event(trackpoint, EV_REL, REL_X, 1);
- litest_event(trackpoint, EV_REL, REL_Y, 1);
- litest_event(trackpoint, EV_SYN, SYN_REPORT, 0);
- litest_dispatch(li);
- }
- litest_drain_events(li);
- litest_touch_down(touchpad, 0, 30, 30);
- litest_touch_move_to(touchpad, 0, 30, 30, 80, 80, 10);
- litest_assert_empty_queue(li);
- litest_timeout_trackpoint(li);
- /* touch started after last tp event, expect resume */
- litest_touch_move_to(touchpad, 0, 80, 80, 30, 30, 10);
- litest_touch_up(touchpad, 0);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
- }
- END_TEST
- START_TEST(trackpoint_palmdetect_require_min_events)
- {
- struct litest_device *trackpoint = litest_current_device();
- struct libinput *li = trackpoint->libinput;
- _destroy_(litest_device) *touchpad =
- litest_add_device(li, LITEST_SYNAPTICS_I2C);
- if (has_disable_while_trackpointing(touchpad))
- enable_dwtp(touchpad);
- litest_disable_hold_gestures(touchpad->libinput_device);
- litest_drain_events(li);
- /* A single event does not trigger palm detection */
- litest_event(trackpoint, EV_REL, REL_X, 1);
- litest_event(trackpoint, EV_REL, REL_Y, 1);
- litest_event(trackpoint, EV_SYN, SYN_REPORT, 0);
- litest_dispatch(li);
- litest_drain_events(li);
- litest_touch_down(touchpad, 0, 30, 30);
- litest_touch_move_to(touchpad, 0, 30, 30, 80, 80, 10);
- litest_touch_up(touchpad, 0);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
- }
- END_TEST
- START_TEST(trackpoint_palmdetect_require_min_events_timeout)
- {
- struct litest_device *trackpoint = litest_current_device();
- struct libinput *li = trackpoint->libinput;
- _destroy_(litest_device) *touchpad =
- litest_add_device(li, LITEST_SYNAPTICS_I2C);
- if (has_disable_while_trackpointing(touchpad))
- enable_dwtp(touchpad);
- litest_disable_hold_gestures(touchpad->libinput_device);
- litest_drain_events(li);
- for (int i = 0; i < 10; i++) {
- /* A single event does not trigger palm detection */
- litest_event(trackpoint, EV_REL, REL_X, 1);
- litest_event(trackpoint, EV_REL, REL_Y, 1);
- litest_event(trackpoint, EV_SYN, SYN_REPORT, 0);
- litest_dispatch(li);
- litest_drain_events(li);
- litest_touch_down(touchpad, 0, 30, 30);
- litest_touch_move_to(touchpad, 0, 30, 30, 80, 80, 10);
- litest_touch_up(touchpad, 0);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
- litest_timeout_trackpoint(li);
- }
- }
- END_TEST
- TEST_COLLECTION(trackpoint)
- {
- /* clang-format off */
- litest_add(trackpoint_middlebutton, LITEST_POINTINGSTICK, LITEST_ANY);
- litest_add(trackpoint_middlebutton_noscroll, LITEST_POINTINGSTICK, LITEST_ANY);
- litest_add(trackpoint_scroll, LITEST_POINTINGSTICK, LITEST_ANY);
- litest_add(trackpoint_scroll_source, LITEST_POINTINGSTICK, LITEST_ANY);
- litest_add(trackpoint_topsoftbuttons_left_handed_trackpoint, LITEST_TOPBUTTONPAD, LITEST_ANY);
- litest_add(trackpoint_topsoftbuttons_left_handed_touchpad, LITEST_TOPBUTTONPAD, LITEST_ANY);
- litest_add(trackpoint_topsoftbuttons_left_handed_both, LITEST_TOPBUTTONPAD, LITEST_ANY);
- litest_with_parameters(params, "timeout", 'u', 4, 0, 120, 300, 900) {
- litest_add_parametrized(trackpoint_palmdetect, LITEST_POINTINGSTICK, LITEST_ANY, params);
- }
- litest_add(trackpoint_palmdetect_dwtp_disabled, LITEST_POINTINGSTICK, LITEST_ANY);
- litest_add(trackpoint_palmdetect_resume_touch, LITEST_POINTINGSTICK, LITEST_ANY);
- litest_add(trackpoint_palmdetect_require_min_events, LITEST_POINTINGSTICK, LITEST_ANY);
- litest_add(trackpoint_palmdetect_require_min_events_timeout, LITEST_POINTINGSTICK, LITEST_ANY);
- /* clang-format on */
- }
|