2014-09-18 11:15:27 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2014 Red Hat, Inc.
|
|
|
|
|
*
|
2015-06-11 12:09:18 +10:00
|
|
|
* 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:
|
2014-09-18 11:15:27 +02:00
|
|
|
*
|
2015-06-11 12:09:18 +10:00
|
|
|
* 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.
|
2014-09-18 11:15:27 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include <check.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <libinput.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
#include "libinput-util.h"
|
|
|
|
|
#include "litest.h"
|
|
|
|
|
|
|
|
|
|
START_TEST(trackpoint_middlebutton)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *dev = litest_current_device();
|
|
|
|
|
struct libinput *li = dev->libinput;
|
2015-06-01 14:38:29 +10:00
|
|
|
struct libinput_event *event;
|
|
|
|
|
struct libinput_event_pointer *ptrev;
|
|
|
|
|
uint64_t ptime, rtime;
|
2014-09-18 11:15:27 +02:00
|
|
|
|
|
|
|
|
litest_drain_events(li);
|
|
|
|
|
|
|
|
|
|
/* A quick middle button click should get reported normally */
|
|
|
|
|
litest_button_click(dev, BTN_MIDDLE, 1);
|
2015-06-01 14:38:29 +10:00
|
|
|
msleep(2);
|
2014-09-18 11:15:27 +02:00
|
|
|
litest_button_click(dev, BTN_MIDDLE, 0);
|
|
|
|
|
|
2015-06-01 14:38:29 +10:00
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
ck_assert_int_lt(ptime, rtime);
|
2014-09-18 11:15:27 +02:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
2014-11-06 16:32:53 +01:00
|
|
|
litest_button_scroll(dev, BTN_MIDDLE, 1, 6);
|
2014-09-18 11:15:27 +02:00
|
|
|
litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 6);
|
2014-11-06 16:32:53 +01:00
|
|
|
litest_button_scroll(dev, BTN_MIDDLE, 1, -7);
|
2014-09-18 11:15:27 +02:00
|
|
|
litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -7);
|
2014-11-06 16:32:53 +01:00
|
|
|
litest_button_scroll(dev, BTN_MIDDLE, 8, 1);
|
2014-09-18 11:15:27 +02:00
|
|
|
litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, 8);
|
2014-11-06 16:32:53 +01:00
|
|
|
litest_button_scroll(dev, BTN_MIDDLE, -9, 1);
|
2014-09-18 11:15:27 +02:00
|
|
|
litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, -9);
|
|
|
|
|
|
|
|
|
|
/* scroll smaller than the threshold should not generate events */
|
2014-11-06 16:32:53 +01:00
|
|
|
litest_button_scroll(dev, BTN_MIDDLE, 1, 1);
|
2014-09-18 11:15:27 +02:00
|
|
|
/* long middle press without movement should not generate events */
|
2014-11-06 16:32:53 +01:00
|
|
|
litest_button_scroll(dev, BTN_MIDDLE, 0, 0);
|
2014-09-18 11:15:27 +02:00
|
|
|
|
|
|
|
|
litest_assert_empty_queue(li);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2014-11-06 14:23:12 +01:00
|
|
|
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 */
|
2014-11-19 12:16:28 +10:00
|
|
|
libinput_device_config_scroll_set_method(dev->libinput_device,
|
2014-11-06 14:23:12 +01:00
|
|
|
LIBINPUT_CONFIG_SCROLL_NO_SCROLL);
|
|
|
|
|
|
|
|
|
|
litest_drain_events(li);
|
|
|
|
|
|
|
|
|
|
/* A long middle button click + motion should get reported normally now */
|
2014-11-06 16:32:53 +01:00
|
|
|
litest_button_scroll(dev, BTN_MIDDLE, 0, 10);
|
2014-11-06 14:23:12 +01:00
|
|
|
|
|
|
|
|
litest_assert_button_event(li, BTN_MIDDLE, 1);
|
|
|
|
|
|
|
|
|
|
event = libinput_get_event(li);
|
|
|
|
|
ck_assert(event != NULL);
|
|
|
|
|
ck_assert_int_eq(libinput_event_get_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 */
|
2014-11-19 12:16:28 +10:00
|
|
|
libinput_device_config_scroll_set_method(dev->libinput_device,
|
|
|
|
|
libinput_device_config_scroll_get_default_method(
|
2014-11-06 14:23:12 +01:00
|
|
|
dev->libinput_device));
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
Add pointer axis sources to the API
For a caller to implement/provide kinetic scrolling ("inertial scrolling",
"fling scrolling"), it needs to know how the scrolling motion was implemented,
and what to expect in the future. Add this information to the pointer axis
event.
The three scroll sources we have are:
* wheels: scrolling is in discreet steps, you don't know when it ends, the
wheel will just stop sending events
* fingers: scrolling is continuous coordinate space, we know when it stops and
we can tell the caller
* continuous: scrolling is in continuous coordinate space but we may or may not
know when it stops. if scroll lock is used, the device may never technically
get out of scroll mode even if it doesn't send events at any given moment
Use case: trackpoint/trackball scroll emulation on button press
The stop event is now codified in the API documentation, so callers can use
that for kinetic scrolling. libinput does not implement kinetic scrolling
itself.
Not covered by this patch:
* The wheel event is currently defined as "typical mouse wheel step", this is
different to Qt where the step value is 1/8 of a degree. Some better
definition here may help.
* It is unclear how an absolute device would map into relative motion if the
device itself is not controlling absolute motion.
* For diagonal scrolling, the vertical/horizontal terminator events would come
in separately. The caller would have to deal with that somehow.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Original patch, before the rebase onto today's master:
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-11-05 16:22:07 +10:00
|
|
|
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, -1);
|
|
|
|
|
|
|
|
|
|
while ((event = libinput_get_event(li))) {
|
|
|
|
|
ptrev = libinput_event_get_pointer_event(event);
|
|
|
|
|
|
|
|
|
|
ck_assert_int_eq(libinput_event_pointer_get_axis_source(ptrev),
|
|
|
|
|
LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS);
|
|
|
|
|
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2016-03-30 15:31:07 +10:00
|
|
|
START_TEST(trackpoint_topsoftbuttons_left_handed_trackpoint)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *touchpad = litest_current_device();
|
|
|
|
|
struct litest_device *trackpoint;
|
|
|
|
|
struct libinput *li = touchpad->libinput;
|
|
|
|
|
enum libinput_config_status status;
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
struct libinput_device *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);
|
|
|
|
|
ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
|
|
|
|
|
|
|
|
|
|
litest_touch_down(touchpad, 0, 5, 5);
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
litest_button_click(touchpad, BTN_LEFT, true);
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
|
|
|
|
|
event = libinput_get_event(li);
|
|
|
|
|
litest_is_button_event(event,
|
|
|
|
|
BTN_RIGHT,
|
|
|
|
|
LIBINPUT_BUTTON_STATE_PRESSED);
|
|
|
|
|
device = libinput_event_get_device(event);
|
|
|
|
|
ck_assert(device == trackpoint->libinput_device);
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
|
|
|
|
|
litest_button_click(touchpad, BTN_LEFT, false);
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
event = libinput_get_event(li);
|
|
|
|
|
litest_is_button_event(event,
|
|
|
|
|
BTN_RIGHT,
|
|
|
|
|
LIBINPUT_BUTTON_STATE_RELEASED);
|
|
|
|
|
device = libinput_event_get_device(event);
|
|
|
|
|
ck_assert(device == trackpoint->libinput_device);
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
|
|
|
|
|
litest_delete_device(trackpoint);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(trackpoint_topsoftbuttons_left_handed_touchpad)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *touchpad = litest_current_device();
|
|
|
|
|
struct litest_device *trackpoint;
|
|
|
|
|
struct libinput *li = touchpad->libinput;
|
|
|
|
|
enum libinput_config_status status;
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
struct libinput_device *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);
|
|
|
|
|
ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
|
|
|
|
|
|
|
|
|
|
litest_touch_down(touchpad, 0, 5, 5);
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
litest_button_click(touchpad, BTN_LEFT, true);
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
|
|
|
|
|
event = libinput_get_event(li);
|
|
|
|
|
litest_is_button_event(event, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
|
|
|
|
|
device = libinput_event_get_device(event);
|
|
|
|
|
ck_assert(device == trackpoint->libinput_device);
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
|
|
|
|
|
litest_button_click(touchpad, BTN_LEFT, false);
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
event = libinput_get_event(li);
|
|
|
|
|
litest_is_button_event(event,
|
|
|
|
|
BTN_LEFT,
|
|
|
|
|
LIBINPUT_BUTTON_STATE_RELEASED);
|
|
|
|
|
device = libinput_event_get_device(event);
|
|
|
|
|
ck_assert(device == trackpoint->libinput_device);
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
|
|
|
|
|
litest_delete_device(trackpoint);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(trackpoint_topsoftbuttons_left_handed_both)
|
|
|
|
|
{
|
|
|
|
|
struct litest_device *touchpad = litest_current_device();
|
|
|
|
|
struct litest_device *trackpoint;
|
|
|
|
|
struct libinput *li = touchpad->libinput;
|
|
|
|
|
enum libinput_config_status status;
|
|
|
|
|
struct libinput_event *event;
|
|
|
|
|
struct libinput_device *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);
|
|
|
|
|
ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
|
|
|
|
|
status = libinput_device_config_left_handed_set(
|
|
|
|
|
trackpoint->libinput_device, 1);
|
|
|
|
|
ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
|
|
|
|
|
|
|
|
|
|
litest_touch_down(touchpad, 0, 5, 5);
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
litest_button_click(touchpad, BTN_LEFT, true);
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
|
|
|
|
|
event = libinput_get_event(li);
|
|
|
|
|
litest_is_button_event(event,
|
|
|
|
|
BTN_RIGHT,
|
|
|
|
|
LIBINPUT_BUTTON_STATE_PRESSED);
|
|
|
|
|
device = libinput_event_get_device(event);
|
|
|
|
|
ck_assert(device == trackpoint->libinput_device);
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
|
|
|
|
|
litest_button_click(touchpad, BTN_LEFT, false);
|
|
|
|
|
libinput_dispatch(li);
|
|
|
|
|
event = libinput_get_event(li);
|
|
|
|
|
litest_is_button_event(event,
|
|
|
|
|
BTN_RIGHT,
|
|
|
|
|
LIBINPUT_BUTTON_STATE_RELEASED);
|
|
|
|
|
device = libinput_event_get_device(event);
|
|
|
|
|
ck_assert(device == trackpoint->libinput_device);
|
|
|
|
|
libinput_event_destroy(event);
|
|
|
|
|
|
|
|
|
|
litest_delete_device(trackpoint);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
2016-05-03 14:14:04 +10:00
|
|
|
|
2015-05-20 09:36:01 +10:00
|
|
|
void
|
|
|
|
|
litest_setup_tests(void)
|
2015-05-01 11:41:12 +10:00
|
|
|
{
|
2014-09-18 11:15:27 +02:00
|
|
|
litest_add("trackpoint:middlebutton", trackpoint_middlebutton, LITEST_POINTINGSTICK, LITEST_ANY);
|
2014-11-06 14:23:12 +01:00
|
|
|
litest_add("trackpoint:middlebutton", trackpoint_middlebutton_noscroll, LITEST_POINTINGSTICK, LITEST_ANY);
|
2014-09-18 11:15:27 +02:00
|
|
|
litest_add("trackpoint:scroll", trackpoint_scroll, LITEST_POINTINGSTICK, LITEST_ANY);
|
Add pointer axis sources to the API
For a caller to implement/provide kinetic scrolling ("inertial scrolling",
"fling scrolling"), it needs to know how the scrolling motion was implemented,
and what to expect in the future. Add this information to the pointer axis
event.
The three scroll sources we have are:
* wheels: scrolling is in discreet steps, you don't know when it ends, the
wheel will just stop sending events
* fingers: scrolling is continuous coordinate space, we know when it stops and
we can tell the caller
* continuous: scrolling is in continuous coordinate space but we may or may not
know when it stops. if scroll lock is used, the device may never technically
get out of scroll mode even if it doesn't send events at any given moment
Use case: trackpoint/trackball scroll emulation on button press
The stop event is now codified in the API documentation, so callers can use
that for kinetic scrolling. libinput does not implement kinetic scrolling
itself.
Not covered by this patch:
* The wheel event is currently defined as "typical mouse wheel step", this is
different to Qt where the step value is 1/8 of a degree. Some better
definition here may help.
* It is unclear how an absolute device would map into relative motion if the
device itself is not controlling absolute motion.
* For diagonal scrolling, the vertical/horizontal terminator events would come
in separately. The caller would have to deal with that somehow.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Original patch, before the rebase onto today's master:
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2014-11-05 16:22:07 +10:00
|
|
|
litest_add("trackpoint:scroll", trackpoint_scroll_source, LITEST_POINTINGSTICK, LITEST_ANY);
|
2016-03-30 15:31:07 +10:00
|
|
|
litest_add("trackpoint:left-handed", trackpoint_topsoftbuttons_left_handed_trackpoint, LITEST_TOPBUTTONPAD, LITEST_ANY);
|
|
|
|
|
litest_add("trackpoint:left-handed", trackpoint_topsoftbuttons_left_handed_touchpad, LITEST_TOPBUTTONPAD, LITEST_ANY);
|
|
|
|
|
litest_add("trackpoint:left-handed", trackpoint_topsoftbuttons_left_handed_both, LITEST_TOPBUTTONPAD, LITEST_ANY);
|
2014-09-18 11:15:27 +02:00
|
|
|
}
|