Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 24492e67 authored by Harry Cutts's avatar Harry Cutts
Browse files

Add IS_GENERATED_GESTURE flag to touchpad scrolling

The IS_GENERATED_GESTURE flag was added to improve scrolling in ARC++,
and tells GestureDetector that the finger going down and moving is
definitely for scrolling, meaning that it doesn't wait until ~20 pixels
of movement have happened before starting the scroll. Adding it here
should make scrolling a little more responsive, and also make the events
more consistent with those for scrolling on ChromeOS.

Bug: 251196347
Test: atest inputflinger_test
Test: check touchpad scrolling still works well
Change-Id: I17ac063fdea1f38413fd8060258c79bff3ccd5c0
parent 3fcbed1e
Loading
Loading
Loading
Loading
+17 −11
Original line number Original line Diff line number Diff line
@@ -210,10 +210,12 @@ std::list<NotifyArgs> GestureConverter::handleScroll(nsecs_t when, nsecs_t readT
        coords.setAxisValue(AMOTION_EVENT_AXIS_Y, yCursorPosition);
        coords.setAxisValue(AMOTION_EVENT_AXIS_Y, yCursorPosition);
        coords.setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 1.0f);
        coords.setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 1.0f);
        mDownTime = when;
        mDownTime = when;
        out.push_back(makeMotionArgs(when, readTime, AMOTION_EVENT_ACTION_DOWN,
        NotifyMotionArgs args =
                                     /* actionButton= */ 0, mButtonState, /* pointerCount= */ 1,
                makeMotionArgs(when, readTime, AMOTION_EVENT_ACTION_DOWN, /* actionButton= */ 0,
                                     mFingerProps.data(), mFakeFingerCoords.data(), xCursorPosition,
                               mButtonState, /* pointerCount= */ 1, mFingerProps.data(),
                                     yCursorPosition));
                               mFakeFingerCoords.data(), xCursorPosition, yCursorPosition);
        args.flags |= AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE;
        out.push_back(args);
    }
    }
    float deltaX = gesture.details.scroll.dx;
    float deltaX = gesture.details.scroll.dx;
    float deltaY = gesture.details.scroll.dy;
    float deltaY = gesture.details.scroll.dy;
@@ -224,9 +226,12 @@ std::list<NotifyArgs> GestureConverter::handleScroll(nsecs_t when, nsecs_t readT
    // TODO(b/262876643): set AXIS_GESTURE_{X,Y}_OFFSET.
    // TODO(b/262876643): set AXIS_GESTURE_{X,Y}_OFFSET.
    coords.setAxisValue(AMOTION_EVENT_AXIS_GESTURE_SCROLL_X_DISTANCE, -gesture.details.scroll.dx);
    coords.setAxisValue(AMOTION_EVENT_AXIS_GESTURE_SCROLL_X_DISTANCE, -gesture.details.scroll.dx);
    coords.setAxisValue(AMOTION_EVENT_AXIS_GESTURE_SCROLL_Y_DISTANCE, -gesture.details.scroll.dy);
    coords.setAxisValue(AMOTION_EVENT_AXIS_GESTURE_SCROLL_Y_DISTANCE, -gesture.details.scroll.dy);
    out.push_back(makeMotionArgs(when, readTime, AMOTION_EVENT_ACTION_MOVE, /* actionButton= */ 0,
    NotifyMotionArgs args =
            makeMotionArgs(when, readTime, AMOTION_EVENT_ACTION_MOVE, /* actionButton= */ 0,
                           mButtonState, /* pointerCount= */ 1, mFingerProps.data(),
                           mButtonState, /* pointerCount= */ 1, mFingerProps.data(),
                                 mFakeFingerCoords.data(), xCursorPosition, yCursorPosition));
                           mFakeFingerCoords.data(), xCursorPosition, yCursorPosition);
    args.flags |= AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE;
    out.push_back(args);
    return out;
    return out;
}
}


@@ -243,10 +248,11 @@ NotifyArgs GestureConverter::handleFling(nsecs_t when, nsecs_t readTime, const G
    mPointerController->getPosition(&xCursorPosition, &yCursorPosition);
    mPointerController->getPosition(&xCursorPosition, &yCursorPosition);
    mFakeFingerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_GESTURE_SCROLL_X_DISTANCE, 0);
    mFakeFingerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_GESTURE_SCROLL_X_DISTANCE, 0);
    mFakeFingerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_GESTURE_SCROLL_Y_DISTANCE, 0);
    mFakeFingerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_GESTURE_SCROLL_Y_DISTANCE, 0);
    NotifyArgs args = makeMotionArgs(when, readTime, AMOTION_EVENT_ACTION_UP,
    NotifyMotionArgs args =
                                     /* actionButton= */ 0, mButtonState, /* pointerCount= */ 1,
            makeMotionArgs(when, readTime, AMOTION_EVENT_ACTION_UP, /* actionButton= */ 0,
                                     mFingerProps.data(), mFakeFingerCoords.data(), xCursorPosition,
                           mButtonState, /* pointerCount= */ 1, mFingerProps.data(),
                                     yCursorPosition);
                           mFakeFingerCoords.data(), xCursorPosition, yCursorPosition);
    args.flags |= AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE;
    mCurrentClassification = MotionClassification::NONE;
    mCurrentClassification = MotionClassification::NONE;
    return args;
    return args;
}
}
+8 −4
Original line number Original line Diff line number Diff line
@@ -252,14 +252,16 @@ TEST_F(GestureConverterTest, Scroll) {
                AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y),
                AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y),
                      WithGestureScrollDistance(0, 0, EPSILON),
                      WithGestureScrollDistance(0, 0, EPSILON),
                      WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
                      WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
                      WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER), WithDownTime(downTime)));
                      WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER), WithDownTime(downTime),
                      WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE)));
    args.pop_front();
    args.pop_front();
    ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
    ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
                AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
                AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
                      WithCoords(POINTER_X, POINTER_Y - 10),
                      WithCoords(POINTER_X, POINTER_Y - 10),
                      WithGestureScrollDistance(0, 10, EPSILON),
                      WithGestureScrollDistance(0, 10, EPSILON),
                      WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
                      WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
                      WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER)));
                      WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER),
                      WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE)));


    Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
    Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
    args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
    args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);
@@ -269,7 +271,8 @@ TEST_F(GestureConverterTest, Scroll) {
                      WithCoords(POINTER_X, POINTER_Y - 15),
                      WithCoords(POINTER_X, POINTER_Y - 15),
                      WithGestureScrollDistance(0, 5, EPSILON),
                      WithGestureScrollDistance(0, 5, EPSILON),
                      WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
                      WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
                      WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER)));
                      WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER),
                      WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE)));


    Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
    Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
                         GESTURES_FLING_START);
                         GESTURES_FLING_START);
@@ -280,7 +283,8 @@ TEST_F(GestureConverterTest, Scroll) {
                      WithCoords(POINTER_X, POINTER_Y - 15),
                      WithCoords(POINTER_X, POINTER_Y - 15),
                      WithGestureScrollDistance(0, 0, EPSILON),
                      WithGestureScrollDistance(0, 0, EPSILON),
                      WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
                      WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
                      WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER)));
                      WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER),
                      WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE)));
}
}


TEST_F(GestureConverterTest, Scroll_Rotated) {
TEST_F(GestureConverterTest, Scroll_Rotated) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -145,7 +145,7 @@ MATCHER_P(WithToolType, toolType, "InputEvent with specified tool type") {


MATCHER_P(WithFlags, flags, "InputEvent with specified flags") {
MATCHER_P(WithFlags, flags, "InputEvent with specified flags") {
    *result_listener << "expected flags " << flags << ", but got " << arg.flags;
    *result_listener << "expected flags " << flags << ", but got " << arg.flags;
    return arg.flags == flags;
    return arg.flags == static_cast<int32_t>(flags);
}
}


MATCHER_P(WithMotionClassification, classification,
MATCHER_P(WithMotionClassification, classification,