touchpad: add an option for tapping while holding other fingers down

Doesn't do anything useful yet.

Signed-off-by: satrmb <10471-satrmb@users.noreply.gitlab.freedesktop.org>
This commit is contained in:
satrmb 2020-08-02 11:40:13 +02:00
parent 484ccb0fb3
commit 21bf80ab05
15 changed files with 309 additions and 0 deletions

View file

@ -82,6 +82,9 @@ __all_seats()
+ '(dwtp)' \
'--enable-dwtp[Enable disable-while-trackpointing]' \
'--disable-dwtp[Disable disable-while-trackpointing]' \
+ '(hold-and-tap)' \
'--enable-hold-tap[Enable hold-and-tap]' \
'--disable-hold-tap[Disable hold-and-tap]' \
+ '(left-handed)' \
'--enable-left-handed[Enable left handed button configuration]' \
'--disable-left-handed[Disable left handed button configuration]' \

View file

@ -29,6 +29,7 @@ options exposed by libinput are:
- a toggle to enable/disable tapping
- a toggle to enable/disable tap-and-drag, see :ref:`tapndrag`.
- a toggle to enable/disable tap-and-drag drag lock, see :ref:`tapndrag`
- a toggle to enable/disable hold-and-tap
- The default order is 1, 2, 3 finger tap mapping to left, right, middle
click, respectively. This order can be changed to left, middle, right click,
respectively.

View file

@ -1483,10 +1483,22 @@ tp_tap_update_map(struct tp_dispatch *tp)
tp->tap.map = tp->tap.want_map;
}
static inline void
tp_tap_update_hold_tap(struct tp_dispatch *tp)
{
if (tp->tap.state != TAP_STATE_IDLE ||
tp->tap.drag_state != DRAG_STATE_IDLE)
return;
if (tp->tap.hold_tap_enabled != tp->tap.want_hold_tap_enabled)
tp->tap.hold_tap_enabled = tp->tap.want_hold_tap_enabled;
}
void
tp_tap_post_process_state(struct tp_dispatch *tp)
{
tp_tap_update_map(tp);
tp_tap_update_hold_tap(tp);
}
static void
@ -1690,6 +1702,43 @@ tp_tap_config_get_default_draglock_enabled(struct libinput_device *device)
return tp_drag_lock_default(evdev);
}
static enum libinput_config_status
tp_tap_config_set_hold_tap_enabled(struct libinput_device *device,
enum libinput_config_hold_tap_state enabled)
{
struct evdev_dispatch *dispatch = evdev_device(device)->dispatch;
struct tp_dispatch *tp = tp_dispatch(dispatch);
tp->tap.want_hold_tap_enabled = enabled;
tp_tap_update_hold_tap(tp);
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static enum libinput_config_hold_tap_state
tp_tap_config_get_hold_tap_enabled(struct libinput_device *device)
{
struct evdev_dispatch *dispatch = evdev_device(device)->dispatch;
struct tp_dispatch *tp = tp_dispatch(dispatch);
return tp->tap.want_hold_tap_enabled;
}
static inline enum libinput_config_hold_tap_state
tp_hold_tap_default(struct evdev_device *device)
{
return LIBINPUT_CONFIG_HOLD_TAP_DISABLED;
}
static enum libinput_config_hold_tap_state
tp_tap_config_get_default_hold_tap_enabled(struct libinput_device *device)
{
struct evdev_device *evdev = evdev_device(device);
return tp_hold_tap_default(evdev);
}
void
tp_init_tap(struct tp_dispatch *tp)
{
@ -1708,6 +1757,9 @@ tp_init_tap(struct tp_dispatch *tp)
tp->tap.config.set_draglock_enabled = tp_tap_config_set_draglock_enabled;
tp->tap.config.get_draglock_enabled = tp_tap_config_get_draglock_enabled;
tp->tap.config.get_default_draglock_enabled = tp_tap_config_get_default_draglock_enabled;
tp->tap.config.set_hold_tap_enabled = tp_tap_config_set_hold_tap_enabled;
tp->tap.config.get_hold_tap_enabled = tp_tap_config_get_hold_tap_enabled;
tp->tap.config.get_default_hold_tap_enabled = tp_tap_config_get_default_hold_tap_enabled;
tp->device->base.config.tap = &tp->tap.config;
tp->tap.state = TAP_STATE_IDLE;
@ -1717,6 +1769,8 @@ tp_init_tap(struct tp_dispatch *tp)
tp->tap.want_map = tp->tap.map;
tp->tap.drag_enabled = tp_drag_default(tp->device);
tp->tap.drag_lock = tp_drag_lock_default(tp->device);
tp->tap.hold_tap_enabled = tp_hold_tap_default(tp->device);
tp->tap.want_hold_tap_enabled = tp->tap.hold_tap_enabled;
snprintf(timer_name,
sizeof(timer_name),

View file

@ -445,6 +445,9 @@ struct tp_dispatch {
bool drag_enabled;
enum libinput_config_drag_lock_state drag_lock;
bool hold_tap_enabled;
bool want_hold_tap_enabled;
unsigned int nfingers_down; /* number of fingers down for tapping (excl. thumb/palm) */
} tap;

View file

@ -216,6 +216,11 @@ struct libinput_device_config_tap {
enum libinput_config_drag_lock_state);
enum libinput_config_drag_lock_state (*get_draglock_enabled)(struct libinput_device *device);
enum libinput_config_drag_lock_state (*get_default_draglock_enabled)(struct libinput_device *device);
enum libinput_config_status (*set_hold_tap_enabled)(struct libinput_device *device,
enum libinput_config_hold_tap_state);
enum libinput_config_hold_tap_state (*get_hold_tap_enabled)(struct libinput_device *device);
enum libinput_config_hold_tap_state (*get_default_hold_tap_enabled)(struct libinput_device *device);
};
struct libinput_device_config_calibration {

View file

@ -70,6 +70,7 @@ ASSERT_INT_SIZE(enum libinput_config_tap_state);
ASSERT_INT_SIZE(enum libinput_config_tap_button_map);
ASSERT_INT_SIZE(enum libinput_config_drag_state);
ASSERT_INT_SIZE(enum libinput_config_drag_lock_state);
ASSERT_INT_SIZE(enum libinput_config_hold_tap_state);
ASSERT_INT_SIZE(enum libinput_config_send_events_mode);
ASSERT_INT_SIZE(enum libinput_config_accel_profile);
ASSERT_INT_SIZE(enum libinput_config_click_method);
@ -4106,6 +4107,39 @@ libinput_device_config_tap_get_default_drag_lock_enabled(struct libinput_device
return device->config.tap->get_default_draglock_enabled(device);
}
LIBINPUT_EXPORT enum libinput_config_status
libinput_device_config_tap_set_hold_tap_enabled(struct libinput_device *device,
enum libinput_config_hold_tap_state enable)
{
if (enable != LIBINPUT_CONFIG_HOLD_TAP_ENABLED &&
enable != LIBINPUT_CONFIG_HOLD_TAP_DISABLED)
return LIBINPUT_CONFIG_STATUS_INVALID;
if (libinput_device_config_tap_get_finger_count(device) == 0)
return enable ? LIBINPUT_CONFIG_STATUS_UNSUPPORTED :
LIBINPUT_CONFIG_STATUS_SUCCESS;
return device->config.tap->set_hold_tap_enabled(device, enable);
}
LIBINPUT_EXPORT enum libinput_config_hold_tap_state
libinput_device_config_tap_get_hold_tap_enabled(struct libinput_device *device)
{
if (libinput_device_config_tap_get_finger_count(device) == 0)
return LIBINPUT_CONFIG_HOLD_TAP_DISABLED;
return device->config.tap->get_hold_tap_enabled(device);
}
LIBINPUT_EXPORT enum libinput_config_hold_tap_state
libinput_device_config_tap_get_default_hold_tap_enabled(struct libinput_device *device)
{
if (libinput_device_config_tap_get_finger_count(device) == 0)
return LIBINPUT_CONFIG_HOLD_TAP_DISABLED;
return device->config.tap->get_default_hold_tap_enabled(device);
}
LIBINPUT_EXPORT int
libinput_device_config_calibration_has_matrix(struct libinput_device *device)
{

View file

@ -4617,6 +4617,8 @@ libinput_device_group_get_user_data(struct libinput_device_group *group);
* - libinput_device_config_tap_set_enabled()
* - libinput_device_config_tap_set_drag_enabled()
* - libinput_device_config_tap_set_drag_lock_enabled()
* - libinput_device_config_tap_set_hold_tap_enabled()
* - libinput_device_config_tap_set_button_map()
* - libinput_device_config_click_set_method()
* - libinput_device_config_click_set_clickfinger_button_map()
* - libinput_device_config_scroll_set_method()
@ -5024,6 +5026,97 @@ libinput_device_config_tap_get_drag_lock_enabled(struct libinput_device *device)
enum libinput_config_drag_lock_state
libinput_device_config_tap_get_default_drag_lock_enabled(struct libinput_device *device);
/**
* @ingroup config
*
* @since 1.18
*/
enum libinput_config_hold_tap_state {
/** Hold-and-tap is to be disabled, or is currently disabled */
LIBINPUT_CONFIG_HOLD_TAP_DISABLED,
/** Hold-and-tap is to be enabled, or is currently enabled */
LIBINPUT_CONFIG_HOLD_TAP_ENABLED,
};
/**
* @ingroup config
*
* Enable or disable hold-and-tap on this device. When enabled, tapping with
* additional fingers while other fingers are already held down performs a
* tap as if no fingers were held down. During a drag taps with the same
* number of fingers as used to start the drag are ignored. Starting a drag
* still requires lifting all fingers.
* When disabled, tapping with additional fingers generally has no effect,
* taps are meant to be performed from a neutral state.
*
* Enabling or disabling hold-and-tap may not take effect immediately,
* the device may wait until it is in a neutral state before applying any
* changes.
*
* Enabling hold-and-tap on a device that has tapping disabled is permitted,
* but has no effect until tapping is enabled.
*
* @param device The device to configure
* @param enable @ref LIBINPUT_CONFIG_HOLD_TAP_ENABLED to enable hold-and-tap
* or @ref LIBINPUT_CONFIG_HOLD_TAP_DISABLED to disable hold-and-tap
*
* @return A config status code. Disabling hold-and-tap on a device that does
* not support tapping always succeeds.
*
* @see libinput_device_config_tap_get_hold_tap_enabled
* @see libinput_device_config_tap_get_default_hold_tap_enabled
*
* @since 1.18
*/
enum libinput_config_status
libinput_device_config_tap_set_hold_tap_enabled(struct libinput_device *device,
enum libinput_config_hold_tap_state enable);
/**
* @ingroup config
*
* Check if hold-and-tap is enabled on this device. If the device does not
* support tapping, this function always returns
* @ref LIBINPUT_CONFIG_HOLD_TAP_DISABLED.
*
* Hold-and-tap may be enabled even when tapping is disabled.
*
* @param device The device to configure
*
* @retval LIBINPUT_CONFIG_HOLD_TAP_ENABLED If hold-and-tap is currently enabled
* @retval LIBINPUT_CONFIG_HOLD_TAP_DISABLED If hold-and-tap is currently
* disabled
*
* @see libinput_device_config_tap_set_hold_tap_enabled
* @see libinput_device_config_tap_get_default_hold_tap_enabled
*
* @since 1.18
*/
enum libinput_config_hold_tap_state
libinput_device_config_tap_get_hold_tap_enabled(struct libinput_device *device);
/**
* @ingroup config
*
* Check if hold-and-tap is enabled by default on this device. If the device
* does not support tapping, this function always returns
* @ref LIBINPUT_CONFIG_HOLD_TAP_DISABLED.
*
* @param device The device to configure
*
* @retval LIBINPUT_CONFIG_HOLD_TAP_ENABLED If hold-and-tap is enabled by
* default
* @retval LIBINPUT_CONFIG_HOLD_TAP_DISABLED If hold-and-tap is disabled by
* default
*
* @see libinput_device_config_tap_set_hold_tap_enabled
* @see libinput_device_config_tap_get_hold_tap_enabled
*
* @since 1.18
*/
enum libinput_config_hold_tap_state
libinput_device_config_tap_get_default_hold_tap_enabled(struct libinput_device *device);
/**
* @ingroup config
*

View file

@ -356,4 +356,7 @@ LIBINPUT_1.27 {
libinput_device_config_area_set_rectangle;
libinput_device_config_area_get_rectangle;
libinput_device_config_area_get_default_rectangle;
libinput_device_config_tap_set_hold_tap_enabled;
libinput_device_config_tap_get_hold_tap_enabled;
libinput_device_config_tap_get_default_hold_tap_enabled;
} LIBINPUT_1.26;

View file

@ -1359,6 +1359,30 @@ litest_disable_drag_lock(struct libinput_device *device)
litest_assert_int_eq(status, expected);
}
static inline void
litest_enable_hold_tap(struct libinput_device *device)
{
enum libinput_config_status status, expected;
expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
status = libinput_device_config_tap_set_hold_tap_enabled(device,
LIBINPUT_CONFIG_HOLD_TAP_ENABLED);
litest_assert_int_eq(status, expected);
}
static inline void
litest_disable_hold_tap(struct libinput_device *device)
{
enum libinput_config_status status, expected;
expected = LIBINPUT_CONFIG_STATUS_SUCCESS;
status = libinput_device_config_tap_set_hold_tap_enabled(device,
LIBINPUT_CONFIG_HOLD_TAP_DISABLED);
litest_assert_int_eq(status, expected);
}
static inline void
litest_enable_middleemu(struct litest_device *dev)
{

View file

@ -4269,6 +4269,60 @@ START_TEST(touchpad_drag_lock_default_unavailable)
}
END_TEST
START_TEST(touchpad_hold_tap_default_disabled)
{
struct litest_device *dev = litest_current_device();
struct libinput_device *device = dev->libinput_device;
enum libinput_config_status status;
ck_assert_int_eq(libinput_device_config_tap_get_hold_tap_enabled(device),
LIBINPUT_CONFIG_HOLD_TAP_DISABLED);
ck_assert_int_eq(libinput_device_config_tap_get_default_hold_tap_enabled(device),
LIBINPUT_CONFIG_HOLD_TAP_DISABLED);
status = libinput_device_config_tap_set_hold_tap_enabled(device,
LIBINPUT_CONFIG_HOLD_TAP_ENABLED);
ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
status = libinput_device_config_tap_set_hold_tap_enabled(device,
LIBINPUT_CONFIG_HOLD_TAP_DISABLED);
ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
status = libinput_device_config_tap_set_hold_tap_enabled(device,
LIBINPUT_CONFIG_HOLD_TAP_ENABLED);
ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
status = libinput_device_config_tap_set_hold_tap_enabled(device,
3);
ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_INVALID);
}
END_TEST
START_TEST(touchpad_hold_tap_default_unavailable)
{
struct litest_device *dev = litest_current_device();
struct libinput_device *device = dev->libinput_device;
enum libinput_config_status status;
ck_assert_int_eq(libinput_device_config_tap_get_hold_tap_enabled(device),
LIBINPUT_CONFIG_HOLD_TAP_DISABLED);
ck_assert_int_eq(libinput_device_config_tap_get_default_hold_tap_enabled(device),
LIBINPUT_CONFIG_HOLD_TAP_DISABLED);
status = libinput_device_config_tap_set_hold_tap_enabled(device,
LIBINPUT_CONFIG_HOLD_TAP_ENABLED);
ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED);
status = libinput_device_config_tap_set_hold_tap_enabled(device,
LIBINPUT_CONFIG_HOLD_TAP_DISABLED);
ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
status = libinput_device_config_tap_set_hold_tap_enabled(device,
3);
ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_INVALID);
}
END_TEST
static inline bool
touchpad_has_palm_pressure(struct litest_device *dev)
{
@ -5749,6 +5803,9 @@ TEST_COLLECTION(touchpad_tap)
litest_add(touchpad_tap_get_map_no_tapping, LITEST_ANY, LITEST_TOUCHPAD);
litest_add(touchpad_tap_map_delayed, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT);
litest_add(touchpad_hold_tap_default_disabled, LITEST_TOUCHPAD, LITEST_ANY);
litest_add(touchpad_hold_tap_default_unavailable, LITEST_ANY, LITEST_TOUCHPAD);
litest_add(clickpad_1fg_tap_click, LITEST_CLICKPAD, LITEST_ANY);
litest_add(clickpad_2fg_tap_click, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH|LITEST_APPLE_CLICKPAD);
}

View file

@ -72,6 +72,9 @@ Enable or disable disable-while-typing
.B \-\-enable\-dwtp|\-\-disable\-dwtp
Enable or disable disable-while-trackpointing
.TP 8
.B \-\-enable\-hold-tap|\-\-disable\-hold\-tap
Enable or disable hold-and-tap
.TP 8
.B \-\-enable\-left\-handed|\-\-disable\-left\-handed
Enable or disable left handed button configuration
.TP 8

View file

@ -72,6 +72,18 @@ draglock_default(struct libinput_device *device)
return "disabled";
}
static const char *
hold_tap_default(struct libinput_device *device)
{
if (!libinput_device_config_tap_get_finger_count(device))
return "n/a";
if (libinput_device_config_tap_get_default_hold_tap_enabled(device))
return "enabled";
else
return "disabled";
}
static const char*
left_handed_default(struct libinput_device *device)
{
@ -382,6 +394,7 @@ print_device_notify(struct libinput_event *ev)
printf("Tap-to-click: %s\n", tap_default(dev));
printf("Tap-and-drag: %s\n", drag_default(dev));
printf("Tap drag lock: %s\n", draglock_default(dev));
printf("Hold-and-tap: %s\n", hold_tap_default(dev));
printf("Left-handed: %s\n", left_handed_default(dev));
printf("Nat.scrolling: %s\n", nat_scroll_default(dev));
printf("Middle emulation: %s\n", middle_emulation_default(dev));

View file

@ -112,6 +112,7 @@ tools_init_options(struct tools_options *options)
options->tap_map = -1;
options->drag = -1;
options->drag_lock = -1;
options->hold_tap = -1;
options->natural_scroll = -1;
options->left_handed = -1;
options->middlebutton = -1;
@ -185,6 +186,12 @@ tools_parse_option(int option,
case OPT_DRAG_LOCK_DISABLE:
options->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_DISABLED;
break;
case OPT_HOLD_TAP_ENABLE:
options->hold_tap = 1;
break;
case OPT_HOLD_TAP_DISABLE:
options->hold_tap = 0;
break;
case OPT_NATURAL_SCROLL_ENABLE:
options->natural_scroll = 1;
break;
@ -569,6 +576,9 @@ tools_device_apply_config(struct libinput_device *device,
if (options->drag_lock != -1)
libinput_device_config_tap_set_drag_lock_enabled(device,
options->drag_lock);
if (options->hold_tap != -1)
libinput_device_config_tap_set_hold_tap_enabled(device,
options->hold_tap);
if (options->natural_scroll != -1)
libinput_device_config_scroll_set_natural_scroll_enabled(device,
options->natural_scroll);

View file

@ -42,6 +42,8 @@ enum configuration_options {
OPT_DRAG_DISABLE,
OPT_DRAG_LOCK_ENABLE,
OPT_DRAG_LOCK_DISABLE,
OPT_HOLD_TAP_ENABLE,
OPT_HOLD_TAP_DISABLE,
OPT_NATURAL_SCROLL_ENABLE,
OPT_NATURAL_SCROLL_DISABLE,
OPT_LEFT_HANDED_ENABLE,
@ -79,6 +81,8 @@ enum configuration_options {
{ "disable-drag", no_argument, 0, OPT_DRAG_DISABLE }, \
{ "enable-drag-lock", optional_argument, 0, OPT_DRAG_LOCK_ENABLE }, \
{ "disable-drag-lock", no_argument, 0, OPT_DRAG_LOCK_DISABLE }, \
{ "enable-hold-tap", no_argument, 0, OPT_HOLD_TAP_ENABLE }, \
{ "disable-hold-tap", no_argument, 0, OPT_HOLD_TAP_DISABLE }, \
{ "enable-natural-scrolling", no_argument, 0, OPT_NATURAL_SCROLL_ENABLE }, \
{ "disable-natural-scrolling", no_argument, 0, OPT_NATURAL_SCROLL_DISABLE }, \
{ "enable-left-handed", no_argument, 0, OPT_LEFT_HANDED_ENABLE }, \
@ -119,6 +123,7 @@ struct tools_options {
int tapping;
int drag;
int drag_lock;
int hold_tap;
int natural_scroll;
int left_handed;
int middlebutton;

View file

@ -206,6 +206,7 @@ options = {
"tap",
"drag",
"drag-lock",
"hold-tap",
"middlebutton",
"natural-scrolling",
"left-handed",