fix(trackapd): fix some jumps when quick scrolling

This commit is contained in:
Florian Didron
2025-12-04 17:19:36 +07:00
parent 878b3c7bf9
commit b9d73bee2e
2 changed files with 3 additions and 65 deletions

View File

@@ -454,10 +454,6 @@ report_mouse_t navigator_trackpad_get_report(report_mouse_t mouse_report) {
// Handle finger up - evaluate tap at lift time (libinput style)
if (!is_touching && !was_idle) {
# ifdef NAVIGATOR_TRACKPAD_DEBUG_SCROLL
printf("GESTURE END: state=%d, max_fingers=%d, duration=%dms\n",
gesture.state, gesture.max_finger_count, timer_elapsed(gesture.touch_start_time));
# endif
uint16_t duration = timer_elapsed(gesture.touch_start_time);
// Calculate distance from settled position (or treat as no movement if never settled)
@@ -472,30 +468,16 @@ report_mouse_t navigator_trackpad_get_report(report_mouse_t mouse_report) {
bool is_tap = (duration <= NAVIGATOR_TRACKPAD_TAP_TIMEOUT) &&
(dist_sq <= NAVIGATOR_TRACKPAD_TAP_MOVE_THRESHOLD);
# ifdef NAVIGATOR_TRACKPAD_DEBUG_SCROLL
if (is_tap) {
printf("TAP DETECTED: duration=%d, dist_sq=%ld, max_fingers=%d\n",
duration, (long)dist_sq, gesture.max_finger_count);
}
# endif
// Don't trigger taps if we were scrolling (two fingers detected)
// Also suppress taps that happen shortly after a scroll ends (within 100ms)
# ifdef NAVIGATOR_TRACKPAD_SCROLL_WITH_TWO_FINGERS
if (is_tap && (gesture.max_finger_count >= 2 ||
timer_elapsed(gesture.last_scroll_end) < 100)) {
# ifdef NAVIGATOR_TRACKPAD_DEBUG_SCROLL
printf("TAP SUPPRESSED: was scrolling (max_fingers=%d, time_since_scroll=%d)\n",
gesture.max_finger_count, timer_elapsed(gesture.last_scroll_end));
# endif
is_tap = false; // Suppress tap after scrolling
}
# endif
if (is_tap) {
# ifdef NAVIGATOR_TRACKPAD_DEBUG_SCROLL
printf("TAP TRIGGERED: max_fingers=%d\n", gesture.max_finger_count);
# endif
# ifdef NAVIGATOR_TRACKPAD_ENABLE_DOUBLE_TAP
if (gesture.max_finger_count >= 2) {
mouse_report.x = 0;
@@ -551,45 +533,15 @@ report_mouse_t navigator_trackpad_get_report(report_mouse_t mouse_report) {
# ifdef NAVIGATOR_TRACKPAD_SCROLL_WITH_TWO_FINGERS
// Determine mode based on finger count
// Once scrolling starts, keep scrolling until all fingers lift (no mid-gesture transitions)
if (fingers >= 2 && gesture.state != TP_SCROLLING) {
# ifdef NAVIGATOR_TRACKPAD_DEBUG_SCROLL
printf("SCROLL START: fingers=%d, f0=(%d,%d), f1=(%d,%d), prev=(%d,%d)\n",
fingers, local_report.fingers[0].x, local_report.fingers[0].y,
local_report.fingers[1].x, local_report.fingers[1].y,
gesture.prev_x, gesture.prev_y);
# endif
gesture.state = TP_SCROLLING;
// Reset position tracking - use finger[0] initially
gesture.prev_x = local_report.fingers[0].x;
gesture.prev_y = local_report.fingers[0].y;
} else if (fingers < 2 && gesture.state == TP_SCROLLING) {
# ifdef NAVIGATOR_TRACKPAD_DEBUG_SCROLL
printf("SCROLL->MOVE: fingers=%d, f0=(%d,%d), prev=(%d,%d)\n",
fingers, local_report.fingers[0].x, local_report.fingers[0].y,
gesture.prev_x, gesture.prev_y);
# endif
# ifdef NAVIGATOR_TRACKPAD_SCROLL_INERTIA_ENABLE
// Check if we should trigger inertia before transitioning
// This handles the case where fingers lift quickly (2->1->0)
int16_t abs_vx = scroll_inertia.smooth_vx < 0 ? -scroll_inertia.smooth_vx : scroll_inertia.smooth_vx;
int16_t abs_vy = scroll_inertia.smooth_vy < 0 ? -scroll_inertia.smooth_vy : scroll_inertia.smooth_vy;
if (abs_vx >= (NAVIGATOR_TRACKPAD_SCROLL_INERTIA_TRIGGER * 256) ||
abs_vy >= (NAVIGATOR_TRACKPAD_SCROLL_INERTIA_TRIGGER * 256)) {
// Store inertia values before transitioning
scroll_inertia.vx = scroll_inertia.smooth_vx;
scroll_inertia.vy = scroll_inertia.smooth_vy;
scroll_inertia.timer = timer_read();
scroll_inertia.active = true;
} else {
scroll_inertia.active = false;
}
# endif
// Transition from scrolling back to moving when finger is lifted
gesture.state = TP_MOVING;
// Reset position tracking - use current position of remaining finger
gesture.prev_x = local_report.fingers[0].x;
gesture.prev_y = local_report.fingers[0].y;
}
// Note: We don't transition from SCROLLING back to MOVING mid-gesture anymore
// Once scroll starts, it continues until all fingers lift (gesture ends)
# endif
uint16_t duration = timer_elapsed(gesture.touch_start_time);
@@ -617,15 +569,6 @@ report_mouse_t navigator_trackpad_get_report(report_mouse_t mouse_report) {
int16_t delta_x = local_report.fingers[0].x - gesture.prev_x;
int16_t delta_y = local_report.fingers[0].y - gesture.prev_y;
# ifdef NAVIGATOR_TRACKPAD_DEBUG_SCROLL
if ((delta_x != 0 || delta_y != 0)) {
printf("%s: fingers=%d, f0=(%d,%d), prev=(%d,%d), delta=(%d,%d)\n",
gesture.state == TP_SCROLLING ? "SCROLL MOVE" : "CURSOR MOVE",
fingers, local_report.fingers[0].x, local_report.fingers[0].y,
gesture.prev_x, gesture.prev_y, delta_x, delta_y);
}
# endif
// Clamp deltas to prevent jumps from bad data
if (delta_x > NAVIGATOR_TRACKPAD_MAX_DELTA) delta_x = NAVIGATOR_TRACKPAD_MAX_DELTA;
if (delta_x < -NAVIGATOR_TRACKPAD_MAX_DELTA) delta_x = -NAVIGATOR_TRACKPAD_MAX_DELTA;

View File

@@ -28,8 +28,6 @@
#define NAVIGATOR_TRACKPAD_READ 10
#define NAVIGATOR_TRACKPAD_PROBE 1000
#define NAVIGATOR_TRACKPAD_TAPPING_TERM 100
#define NAVIGATOR_TRACKPAD_TAP_DEBOUNCE 100
#ifndef NAVIGATOR_TRACKPAD_TAP_MOVE_THRESHOLD
# define NAVIGATOR_TRACKPAD_TAP_MOVE_THRESHOLD 100 // Max movement (squared) before tap becomes a drag
@@ -108,9 +106,6 @@
// Two-finger scrolling (define to enable)
// #define NAVIGATOR_TRACKPAD_SCROLL_WITH_TWO_FINGERS
// Debug logging for scroll issues (define to enable)
// #define NAVIGATOR_TRACKPAD_DEBUG_SCROLL
// Scroll inversion configuration
// Define these to invert scroll direction on respective axes
// #define NAVIGATOR_SCROLL_INVERT_X