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

Commit 70a6c052 authored by Hiroki Sato's avatar Hiroki Sato Committed by Android (Google) Code Review
Browse files

Merge changes If18f6539,I37018926 into main

* changes:
  Simplify adding FLAG_IS_GENERATED_GESTURE in GestureConverter
  Don't affect window focus on touchpad gesture
parents 4d06f2ec 517f46af
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -185,3 +185,10 @@ flag {
  description: "Collect quality metrics on framework palm rejection."
  bug: "341717757"
}

flag {
  name: "enable_touchpad_no_focus_change"
  namespace: "input"
  description: "Prevents touchpad gesture changing window focus."
  bug: "364460018"
}
+29 −4
Original line number Diff line number Diff line
@@ -60,6 +60,21 @@ uint32_t gesturesButtonToMotionEventButton(uint32_t gesturesButton) {
    }
}

bool isGestureNoFocusChange(MotionClassification classification) {
    switch (classification) {
        case MotionClassification::TWO_FINGER_SWIPE:
        case MotionClassification::MULTI_FINGER_SWIPE:
        case MotionClassification::PINCH:
            // Most gestures can be performed on an unfocused window, so they should not
            // not affect window focus.
            return true;
        case MotionClassification::NONE:
        case MotionClassification::AMBIGUOUS_GESTURE:
        case MotionClassification::DEEP_PRESS:
            return false;
    }
}

} // namespace

GestureConverter::GestureConverter(InputReaderContext& readerContext,
@@ -67,6 +82,7 @@ GestureConverter::GestureConverter(InputReaderContext& readerContext,
      : mDeviceId(deviceId),
        mReaderContext(readerContext),
        mEnableFlingStop(input_flags::enable_touchpad_fling_stop()),
        mEnableNoFocusChange(input_flags::enable_touchpad_no_focus_change()),
        // We can safely assume that ABS_MT_POSITION_X and _Y axes will be available, as EventHub
        // won't classify a device as a touchpad if they're not present.
        mXAxisInfo(deviceContext.getAbsoluteAxisInfo(ABS_MT_POSITION_X).value()),
@@ -338,7 +354,6 @@ std::list<NotifyArgs> GestureConverter::handleScroll(nsecs_t when, nsecs_t readT
        NotifyMotionArgs args =
                makeMotionArgs(when, readTime, AMOTION_EVENT_ACTION_DOWN, /* actionButton= */ 0,
                               mButtonState, /* pointerCount= */ 1, mFakeFingerCoords.data());
        args.flags |= AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE;
        out.push_back(args);
    }
    float deltaX = gesture.details.scroll.dx;
@@ -353,7 +368,6 @@ std::list<NotifyArgs> GestureConverter::handleScroll(nsecs_t when, nsecs_t readT
    NotifyMotionArgs args =
            makeMotionArgs(when, readTime, AMOTION_EVENT_ACTION_MOVE, /* actionButton= */ 0,
                           mButtonState, /* pointerCount= */ 1, mFakeFingerCoords.data());
    args.flags |= AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE;
    out.push_back(args);
    return out;
}
@@ -427,7 +441,6 @@ std::list<NotifyArgs> GestureConverter::endScroll(nsecs_t when, nsecs_t readTime
    NotifyMotionArgs args =
            makeMotionArgs(when, readTime, AMOTION_EVENT_ACTION_UP, /* actionButton= */ 0,
                           mButtonState, /* pointerCount= */ 1, mFakeFingerCoords.data());
    args.flags |= AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE;
    out.push_back(args);
    mCurrentClassification = MotionClassification::NONE;
    out += enterHover(when, readTime);
@@ -624,6 +637,18 @@ NotifyMotionArgs GestureConverter::makeMotionArgs(nsecs_t when, nsecs_t readTime
                                                  int32_t actionButton, int32_t buttonState,
                                                  uint32_t pointerCount,
                                                  const PointerCoords* pointerCoords) {
    int32_t flags = 0;
    if (action == AMOTION_EVENT_ACTION_CANCEL) {
        flags |= AMOTION_EVENT_FLAG_CANCELED;
    }
    if (mEnableNoFocusChange && isGestureNoFocusChange(mCurrentClassification)) {
        flags |= AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE;
    }
    if (mCurrentClassification == MotionClassification::TWO_FINGER_SWIPE) {
        // This helps to make GestureDetector responsive.
        flags |= AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE;
    }

    return {mReaderContext.getNextId(),
            when,
            readTime,
@@ -633,7 +658,7 @@ NotifyMotionArgs GestureConverter::makeMotionArgs(nsecs_t when, nsecs_t readTime
            /* policyFlags= */ POLICY_FLAG_WAKE,
            action,
            /* actionButton= */ actionButton,
            /* flags= */ action == AMOTION_EVENT_ACTION_CANCEL ? AMOTION_EVENT_FLAG_CANCELED : 0,
            flags,
            mReaderContext.getGlobalMetaState(),
            buttonState,
            mCurrentClassification,
+1 −0
Original line number Diff line number Diff line
@@ -99,6 +99,7 @@ private:
    const int32_t mDeviceId;
    InputReaderContext& mReaderContext;
    const bool mEnableFlingStop;
    const bool mEnableNoFocusChange;

    std::optional<ui::LogicalDisplayId> mDisplayId;
    FloatRect mBoundsInLogicalDisplay{};
+32 −12
Original line number Diff line number Diff line
@@ -279,6 +279,8 @@ TEST_F(GestureConverterTest, DragWithButton) {
}

TEST_F(GestureConverterTest, Scroll) {
    input_flags::enable_touchpad_no_focus_change(true);

    const nsecs_t downTime = 12345;
    InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
    GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
@@ -300,7 +302,8 @@ TEST_F(GestureConverterTest, Scroll) {
    ASSERT_THAT(args,
                Each(VariantWith<NotifyMotionArgs>(
                        AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
                              WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
                              WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE |
                                        AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE),
                              WithToolType(ToolType::FINGER),
                              WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));

@@ -312,7 +315,8 @@ TEST_F(GestureConverterTest, Scroll) {
                              WithGestureScrollDistance(0, 5, EPSILON),
                              WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
                              WithToolType(ToolType::FINGER),
                              WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
                              WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE |
                                        AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE),
                              WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));

    Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
@@ -325,7 +329,8 @@ TEST_F(GestureConverterTest, Scroll) {
                                          WithGestureScrollDistance(0, 0, EPSILON),
                                          WithMotionClassification(
                                                  MotionClassification::TWO_FINGER_SWIPE),
                                          WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))),
                                          WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE |
                                                    AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))),
                            VariantWith<NotifyMotionArgs>(
                                    AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
                                          WithCoords(0, 0),
@@ -845,6 +850,8 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) {
}

TEST_F(GestureConverterTest, Pinch_Inwards) {
    input_flags::enable_touchpad_no_focus_change(true);

    InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
    GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
    converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
@@ -867,7 +874,8 @@ TEST_F(GestureConverterTest, Pinch_Inwards) {
                        AllOf(WithMotionClassification(MotionClassification::PINCH),
                              WithGesturePinchScaleFactor(1.0f, EPSILON),
                              WithToolType(ToolType::FINGER),
                              WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
                              WithDisplayId(ui::LogicalDisplayId::DEFAULT),
                              WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE)))));

    Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
                          /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
@@ -879,7 +887,8 @@ TEST_F(GestureConverterTest, Pinch_Inwards) {
                              WithGesturePinchScaleFactor(0.8f, EPSILON),
                              WithPointerCoords(0, -80, 0), WithPointerCoords(1, 80, 0),
                              WithPointerCount(2u), WithToolType(ToolType::FINGER),
                              WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
                              WithDisplayId(ui::LogicalDisplayId::DEFAULT),
                              WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE)))));

    Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
                       GESTURES_ZOOM_END);
@@ -891,12 +900,14 @@ TEST_F(GestureConverterTest, Pinch_Inwards) {
                                                  1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
                                          WithMotionClassification(MotionClassification::PINCH),
                                          WithGesturePinchScaleFactor(1.0f, EPSILON),
                                          WithPointerCount(2u))),
                                          WithPointerCount(2u),
                                          WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))),
                            VariantWith<NotifyMotionArgs>(
                                    AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
                                          WithMotionClassification(MotionClassification::PINCH),
                                          WithGesturePinchScaleFactor(1.0f, EPSILON),
                                          WithPointerCount(1u))),
                                          WithPointerCount(1u),
                                          WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))),
                            VariantWith<NotifyMotionArgs>(
                                    AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
                                          WithCoords(0, 0),
@@ -908,6 +919,8 @@ TEST_F(GestureConverterTest, Pinch_Inwards) {
}

TEST_F(GestureConverterTest, Pinch_Outwards) {
    input_flags::enable_touchpad_no_focus_change(true);

    InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
    GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
    converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
@@ -930,7 +943,8 @@ TEST_F(GestureConverterTest, Pinch_Outwards) {
                        AllOf(WithMotionClassification(MotionClassification::PINCH),
                              WithGesturePinchScaleFactor(1.0f, EPSILON),
                              WithToolType(ToolType::FINGER),
                              WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
                              WithDisplayId(ui::LogicalDisplayId::DEFAULT),
                              WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE)))));

    Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
                          /* dz= */ 1.1, GESTURES_ZOOM_UPDATE);
@@ -942,7 +956,8 @@ TEST_F(GestureConverterTest, Pinch_Outwards) {
                              WithGesturePinchScaleFactor(1.1f, EPSILON),
                              WithPointerCoords(0, -110, 0), WithPointerCoords(1, 110, 0),
                              WithPointerCount(2u), WithToolType(ToolType::FINGER),
                              WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
                              WithDisplayId(ui::LogicalDisplayId::DEFAULT),
                              WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE)))));

    Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
                       GESTURES_ZOOM_END);
@@ -954,12 +969,14 @@ TEST_F(GestureConverterTest, Pinch_Outwards) {
                                                  1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
                                          WithMotionClassification(MotionClassification::PINCH),
                                          WithGesturePinchScaleFactor(1.0f, EPSILON),
                                          WithPointerCount(2u))),
                                          WithPointerCount(2u),
                                          WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))),
                            VariantWith<NotifyMotionArgs>(
                                    AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
                                          WithMotionClassification(MotionClassification::PINCH),
                                          WithGesturePinchScaleFactor(1.0f, EPSILON),
                                          WithPointerCount(1u))),
                                          WithPointerCount(1u),
                                          WithFlags(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))),
                            VariantWith<NotifyMotionArgs>(
                                    AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
                                          WithCoords(0, 0),
@@ -1055,6 +1072,8 @@ TEST_F(GestureConverterTest, ResetWithButtonPressed) {
}

TEST_F(GestureConverterTest, ResetDuringScroll) {
    input_flags::enable_touchpad_no_focus_change(true);

    InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
    GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
    converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
@@ -1070,7 +1089,8 @@ TEST_F(GestureConverterTest, ResetDuringScroll) {
                                          WithGestureScrollDistance(0, 0, EPSILON),
                                          WithMotionClassification(
                                                  MotionClassification::TWO_FINGER_SWIPE),
                                          WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))),
                                          WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE |
                                                    AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE))),
                            VariantWith<NotifyMotionArgs>(
                                    AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
                                          WithCoords(0, 0),