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

Commit b8dd45d8 authored by Nergi Rahardi's avatar Nergi Rahardi
Browse files

Use MotionEvent.isSynthesizedTouchpadGesture()

Bug: 393330032
Bug: 436380669
Test: DesktopModeWindowDecorViewModelTests
Test: DragDetectorTest
Flag: EXEMPT refactor
Change-Id: Ib44f4cbce3152ef94ddb9fd426a44f5f27e7d423
parent 10179b0a
Loading
Loading
Loading
Loading
+1 −8
Original line number Diff line number Diff line
@@ -130,7 +130,7 @@ public class MouseToTouchProcessor extends InputEventCompatProcessor {
        }
        boolean primaryButton = (event.getButtonState() & MotionEvent.BUTTON_PRIMARY)
                == MotionEvent.BUTTON_PRIMARY;
        if (primaryButton || isTouchpadGesture(event)) {
        if (primaryButton || event.isSynthesizedTouchpadGesture()) {
            mState = STATE_CONVERTING;
            return List.of(obtainRewrittenEventAsTouch(event));
        } else {
@@ -263,11 +263,4 @@ public class MouseToTouchProcessor extends InputEventCompatProcessor {
        return action == MotionEvent.ACTION_BUTTON_PRESS
                || action == MotionEvent.ACTION_BUTTON_RELEASE;
    }

    private static boolean isTouchpadGesture(MotionEvent event) {
        return event.getToolType(0) == MotionEvent.TOOL_TYPE_FINGER
                && (event.getClassification() == MotionEvent.CLASSIFICATION_TWO_FINGER_SWIPE
                || event.getClassification() == MotionEvent.CLASSIFICATION_MULTI_FINGER_SWIPE
                || event.getClassification() == MotionEvent.CLASSIFICATION_PINCH);
    }
}
+1 −2
Original line number Diff line number Diff line
@@ -160,7 +160,6 @@ import com.android.wm.shell.windowdecor.common.WindowDecorationGestureExclusionT
import com.android.wm.shell.windowdecor.common.viewhost.WindowDecorViewHost;
import com.android.wm.shell.windowdecor.common.viewhost.WindowDecorViewHostSupplier;
import com.android.wm.shell.windowdecor.extension.InsetsStateKt;
import com.android.wm.shell.windowdecor.extension.MotionEventKt;
import com.android.wm.shell.windowdecor.extension.TaskInfoKt;
import com.android.wm.shell.windowdecor.tiling.DesktopTilingDecorViewModel;
import com.android.wm.shell.windowdecor.tiling.SnapEventHandler;
@@ -1295,7 +1294,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
                    && id != R.id.maximize_window && id != R.id.minimize_window) {
                return false;
            }
            if (MotionEventKt.isTouchpadGesture(e)) {
            if (e.isSynthesizedTouchpadGesture()) {
                // Touchpad finger gestures are ignored.
                return false;
            }
+1 −3
Original line number Diff line number Diff line
@@ -34,8 +34,6 @@ import android.view.View;

import androidx.annotation.Nullable;

import com.android.wm.shell.windowdecor.extension.MotionEventKt;

/**
 * A detector for touch inputs that differentiates between drag and click inputs. It receives a flow
 * of {@link MotionEvent} and generates a new flow of motion events with slop in consideration to
@@ -92,7 +90,7 @@ public class DragDetector {
     * {@link #mEventHandler} handles the previous down event if the event shouldn't be passed
     */
    public boolean onMotionEvent(View v, MotionEvent ev) {
        if (MotionEventKt.isTouchpadGesture(ev)) {
        if (ev.isSynthesizedTouchpadGesture()) {
            // Touchpad finger gestures are ignored.
            return false;
        }
+0 −32
Original line number Diff line number Diff line
/*
 * Copyright 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.wm.shell.windowdecor.extension

import android.view.InputDevice
import android.view.MotionEvent

/**
 * Checks if the [MotionEvent] is a part of a synthesized touchpad gesture.
 *
 * @return true if the [MotionEvent] is a touchpad gesture, false otherwise.
 */
fun MotionEvent.isTouchpadGesture(): Boolean =
    source == InputDevice.SOURCE_MOUSE &&
        getToolType(0) == MotionEvent.TOOL_TYPE_FINGER &&
        (classification == MotionEvent.CLASSIFICATION_TWO_FINGER_SWIPE ||
            classification == MotionEvent.CLASSIFICATION_PINCH ||
            classification == MotionEvent.CLASSIFICATION_MULTI_FINGER_SWIPE)