Merge branch 'resumable-3fd' into 'main'

Draft: Request for feedback: Add three-finger touch dragging with drag-lock timeout

See merge request libinput/libinput!712
This commit is contained in:
abc def 2025-07-01 05:28:29 +02:00
commit db19de5932
6 changed files with 1280 additions and 2 deletions

View file

@ -387,6 +387,7 @@ src_libinput = src_libfilter + [
'src/evdev-middle-button.c', 'src/evdev-middle-button.c',
'src/evdev-mt-touchpad.c', 'src/evdev-mt-touchpad.c',
'src/evdev-mt-touchpad-tap.c', 'src/evdev-mt-touchpad-tap.c',
'src/evdev-mt-touchpad-tfd.c',
'src/evdev-mt-touchpad-thumb.c', 'src/evdev-mt-touchpad-thumb.c',
'src/evdev-mt-touchpad-buttons.c', 'src/evdev-mt-touchpad-buttons.c',
'src/evdev-mt-touchpad-edge-scroll.c', 'src/evdev-mt-touchpad-edge-scroll.c',

View file

@ -1851,7 +1851,7 @@ tp_gesture_post_events(struct tp_dispatch *tp, uint64_t time,
* physical button is down, don't allow gestures unless the button * physical button is down, don't allow gestures unless the button
* is held down by a *thumb*, specifically. * is held down by a *thumb*, specifically.
*/ */
if (tp_tap_dragging(tp) || if (tp_tap_dragging(tp) || tp_tfd_dragging(tp) ||
(tp->buttons.is_clickpad && tp->buttons.state && (tp->buttons.is_clickpad && tp->buttons.state &&
tp->thumb.state == THUMB_STATE_FINGER)) { tp->thumb.state == THUMB_STATE_FINGER)) {
if (tp->gesture.state != GESTURE_STATE_POINTER_MOTION) { if (tp->gesture.state != GESTURE_STATE_POINTER_MOTION) {
@ -2012,7 +2012,8 @@ tp_gesture_update_finger_state(struct tp_dispatch *tp, uint64_t time)
active_touches++; active_touches++;
} }
if (active_touches != tp->gesture.finger_count) { if (active_touches != tp->gesture.finger_count ||
(active_touches == 3 && true)) { // tp->tfd.three_finger_dragging_enabled)) {
/* If all fingers are lifted immediately end the gesture */ /* If all fingers are lifted immediately end the gesture */
if (active_touches == 0) { if (active_touches == 0) {
tp_gesture_stop(tp, time); tp_gesture_stop(tp, time);

View file

@ -145,10 +145,14 @@ tp_tap_notify(struct tp_dispatch *tp,
else else
tp->tap.buttons_pressed &= ~bit(nfingers); tp->tap.buttons_pressed &= ~bit(nfingers);
evdev_pointer_notify_button(tp->device, evdev_pointer_notify_button(tp->device,
time, time,
evdev_usage_from_uint32_t(button), evdev_usage_from_uint32_t(button),
state); state);
if (state != LIBINPUT_BUTTON_STATE_PRESSED)
tp_tfd_handle_tap(tp, time);
} }
static void static void

1193
src/evdev-mt-touchpad-tfd.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -837,6 +837,10 @@ tp_touch_active_for_gesture(const struct tp_dispatch *tp, const struct tp_touch
return (t->state == TOUCH_BEGIN || t->state == TOUCH_UPDATE) && return (t->state == TOUCH_BEGIN || t->state == TOUCH_UPDATE) &&
t->palm.state == PALM_NONE && t->palm.state == PALM_NONE &&
!t->pinned.is_pinned && !t->pinned.is_pinned &&
/* let's see if this works */
!tp->tfd.cursor_pinned &&
!tp_thumb_ignored_for_gesture(tp, t) && !tp_thumb_ignored_for_gesture(tp, t) &&
tp_button_touch_active(tp, t) && tp_button_touch_active(tp, t) &&
tp_edge_scroll_touch_active(tp, t); tp_edge_scroll_touch_active(tp, t);
@ -1853,6 +1857,8 @@ tp_post_events(struct tp_dispatch *tp, uint64_t time)
ignore_motion |= tp_tap_handle_state(tp, time); ignore_motion |= tp_tap_handle_state(tp, time);
ignore_motion |= tp_post_button_events(tp, time); ignore_motion |= tp_post_button_events(tp, time);
tp_tfd_handle_state(tp, time);
if (tp->palm.trackpoint_active || tp->dwt.keyboard_active) { if (tp->palm.trackpoint_active || tp->dwt.keyboard_active) {
tp_edge_scroll_stop_events(tp, time); tp_edge_scroll_stop_events(tp, time);
tp_gesture_cancel(tp, time); tp_gesture_cancel(tp, time);
@ -3744,6 +3750,8 @@ tp_init(struct tp_dispatch *tp,
if (!tp_init_accel(tp, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE)) if (!tp_init_accel(tp, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE))
return false; return false;
tp_init_tfd(tp);
tp_init_tap(tp); tp_init_tap(tp);
tp_init_buttons(tp, device); tp_init_buttons(tp, device);
tp_init_dwt(tp, device); tp_init_dwt(tp, device);

View file

@ -134,6 +134,33 @@ enum tp_tap_state {
TAP_STATE_DEAD, /**< finger count exceeded */ TAP_STATE_DEAD, /**< finger count exceeded */
}; };
enum tp_tfd_state {
/* [debounce] = brief states anticipating a further increase/decrease in finger
count, preventing unintended drops on account of motion events */
/* waiting for 3 fingers */
TFD_STATE_IDLE,
// not used -- TODO: remove after testing drag_and_debounce
// /* [debounce] disambiguate between starting a drag and a possible 4+ gesture */
// TFD_STATE_POSSIBLE_BEGIN,
/* 3 fingers touching, waiting for motion or timeout */
TFD_STATE_AWAIT_DRAG,
/* [debounce] same as drag state, but cancellable in case of possible 4+
gesture. Replacement state for POSSIBLE_BEGIN */
TFD_STATE_DRAG_AND_DEBOUNCE,
/* 3 fingers touching and button press has been output */
TFD_STATE_DRAG,
/* [debounce] drag-lock; 1 finger touching, possibly going to 0 fingers.
Prevents premature cancellation of AWAIT_RESUME by 1 finger motion events. */
TFD_STATE_POSSIBLE_ZERO_FINGERS,
/* drag-lock; waiting for 3 finger drag continuation */
TFD_STATE_AWAIT_RESUME,
/* TODO: possible to replace this state with DRAG_AND_DEBOUNCE as well? */
/* [debounce] disambiguate between drag continuation and a possible 4+ gesture */
TFD_STATE_POSSIBLE_RESUME,
};
enum tp_tap_touch_state { enum tp_tap_touch_state {
TAP_TOUCH_STATE_IDLE = 16, /**< not in touch */ TAP_TOUCH_STATE_IDLE = 16, /**< not in touch */
TAP_TOUCH_STATE_TOUCH, /**< touching, may tap */ TAP_TOUCH_STATE_TOUCH, /**< touching, may tap */
@ -256,6 +283,13 @@ struct tp_touch {
bool is_palm; bool is_palm;
} tap; } tap;
struct {
// enum tp_tap_touch_state state;
struct device_coords previous;
// bool is_thumb;
// bool is_palm;
} tfd;
struct { struct {
enum tp_edge_scroll_touch_state edge_state; enum tp_edge_scroll_touch_state edge_state;
uint32_t edge; uint32_t edge;
@ -448,6 +482,31 @@ struct tp_dispatch {
unsigned int nfingers_down; /* number of fingers down for tapping (excl. thumb/palm) */ unsigned int nfingers_down; /* number of fingers down for tapping (excl. thumb/palm) */
} tap; } tap;
struct {
//struct libinput_device_config_tap config;
bool enabled;
bool suspended;
struct libinput_timer timer;
struct libinput_timer resume_timer;
enum tp_tfd_state state;
uint32_t buttons_pressed;
uint64_t saved_press_time,
saved_release_time;
// enum libinput_config_tap_button_map map;
//enum libinput_config_tap_button_map want_map;
/* true if cursor movement should not be output to clients */
bool cursor_pinned;
struct device_coords pinned_point;
//bool drag_enabled;
//bool drag_lock_enabled;
bool three_finger_dragging_enabled;
unsigned int finger_count; /* number of fingers down for 3 finger dragging */
} tfd;
struct { struct {
struct libinput_device_config_3fg_drag config; struct libinput_device_config_3fg_drag config;
size_t nfingers; size_t nfingers;
@ -639,6 +698,12 @@ tp_touch_active_for_gesture(const struct tp_dispatch *tp,
int int
tp_tap_handle_state(struct tp_dispatch *tp, uint64_t time); tp_tap_handle_state(struct tp_dispatch *tp, uint64_t time);
void
tp_tfd_handle_state(struct tp_dispatch *tp, uint64_t time);
void
tp_tfd_handle_tap(struct tp_dispatch *tp, uint64_t time);
void void
tp_tap_post_process_state(struct tp_dispatch *tp); tp_tap_post_process_state(struct tp_dispatch *tp);
@ -648,6 +713,9 @@ tp_button_post_process_state(struct tp_dispatch *tp);
void void
tp_init_tap(struct tp_dispatch *tp); tp_init_tap(struct tp_dispatch *tp);
void
tp_init_tfd(struct tp_dispatch *tp);
void void
tp_remove_tap(struct tp_dispatch *tp); tp_remove_tap(struct tp_dispatch *tp);
@ -698,6 +766,9 @@ tp_tap_resume(struct tp_dispatch *tp, uint64_t time);
bool bool
tp_tap_dragging(const struct tp_dispatch *tp); tp_tap_dragging(const struct tp_dispatch *tp);
bool
tp_tfd_dragging(const struct tp_dispatch *tp);
bool bool
tp_tap_dragging_or_double_tapping(const struct tp_dispatch *tp); tp_tap_dragging_or_double_tapping(const struct tp_dispatch *tp);