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

Commit 6601b7bd authored by Craig Mautner's avatar Craig Mautner
Browse files

Exclude regions from the tap detector.

Fix typing on the keyboard causing focus to shift stacks.

Change-Id: I4ec9ccdbe35e27f4860a5bdf0e2818f58e53b873
parent eda67299
Loading
Loading
Loading
Loading
+26 −3
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import static com.android.server.wm.WindowManagerService.DEBUG_VISIBILITY;
import static com.android.server.wm.WindowManagerService.TAG;
import static com.android.server.wm.WindowManagerService.TAG;


import android.graphics.Rect;
import android.graphics.Rect;
import android.graphics.Region;
import android.util.Slog;
import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseArray;
import android.view.Display;
import android.view.Display;
@@ -70,6 +71,8 @@ class DisplayContent {
    private final DisplayInfo mDisplayInfo = new DisplayInfo();
    private final DisplayInfo mDisplayInfo = new DisplayInfo();
    private final Display mDisplay;
    private final Display mDisplay;


    Rect mBaseDisplayRect = new Rect();

    // Accessed directly by all users.
    // Accessed directly by all users.
    boolean layoutNeeded;
    boolean layoutNeeded;
    int pendingLayoutChanges;
    int pendingLayoutChanges;
@@ -94,9 +97,6 @@ class DisplayContent {
    /** True when the home StackBox is at the top of mStackBoxes, false otherwise. */
    /** True when the home StackBox is at the top of mStackBoxes, false otherwise. */
    private TaskStack mHomeStack = null;
    private TaskStack mHomeStack = null;


    /** Save allocating when retrieving tasks */
    ArrayList<Task> mTmpTasks = new ArrayList<Task>();

    /** Sorted most recent at top, oldest at [0]. */
    /** Sorted most recent at top, oldest at [0]. */
    ArrayList<TaskStack> mStackHistory = new ArrayList<TaskStack>();
    ArrayList<TaskStack> mStackHistory = new ArrayList<TaskStack>();


@@ -106,8 +106,17 @@ class DisplayContent {
    /** Detect user tapping outside of current focused stack bounds .*/
    /** Detect user tapping outside of current focused stack bounds .*/
    StackTapDetector mTapDetector;
    StackTapDetector mTapDetector;


    /** Detect user tapping outside of current focused stack bounds .*/
    Region mTouchExcludeRegion = new Region();

    SparseArray<UserStacks> mUserStacks = new SparseArray<UserStacks>();
    SparseArray<UserStacks> mUserStacks = new SparseArray<UserStacks>();


    /** Save allocating when retrieving tasks */
    ArrayList<Task> mTmpTasks = new ArrayList<Task>();

    /** Save allocating when calculating rects */
    Rect mTmpRect = new Rect();

    /**
    /**
     * @param display May not be null.
     * @param display May not be null.
     */
     */
@@ -328,6 +337,20 @@ class DisplayContent {
        return topBox.stackIdFromPoint(x, y);
        return topBox.stackIdFromPoint(x, y);
    }
    }


    void setTouchExcludeRegion(TaskStack focusedStack) {
        mTouchExcludeRegion.set(mBaseDisplayRect);
        WindowList windows = getWindowList();
        for (int i = windows.size() - 1; i >= 0; --i) {
            final WindowState win = windows.get(i);
            final TaskStack stack = win.getStack();
            if (win.isVisibleLw() && stack != null && stack != focusedStack) {
                mTmpRect.set(win.mVisibleFrame);
                mTmpRect.intersect(win.mVisibleInsets);
                mTouchExcludeRegion.op(mTmpRect, Region.Op.DIFFERENCE);
            }
        }
    }

    void switchUserStacks(int oldUserId, int newUserId) {
    void switchUserStacks(int oldUserId, int newUserId) {
        final WindowList windows = getWindowList();
        final WindowList windows = getWindowList();
        for (int i = 0; i < windows.size(); i++) {
        for (int i = 0; i < windows.size(); i++) {
+4 −8
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.wm;
package com.android.server.wm;


import android.graphics.Rect;
import android.graphics.Rect;
import android.graphics.Region;
import android.os.Looper;
import android.os.Looper;
import android.view.DisplayInfo;
import android.view.DisplayInfo;
import android.view.InputChannel;
import android.view.InputChannel;
@@ -35,7 +36,7 @@ public class StackTapDetector extends InputEventReceiver {
    private float mDownX;
    private float mDownX;
    private float mDownY;
    private float mDownY;
    private int mPointerId;
    private int mPointerId;
    private Rect mStackBounds = new Rect();
    final private Region mTouchExcludeRegion;
    private final WindowManagerService mService;
    private final WindowManagerService mService;
    private final DisplayContent mDisplayContent;
    private final DisplayContent mDisplayContent;


@@ -44,6 +45,7 @@ public class StackTapDetector extends InputEventReceiver {
        super(inputChannel, looper);
        super(inputChannel, looper);
        mService = service;
        mService = service;
        mDisplayContent = displayContent;
        mDisplayContent = displayContent;
        mTouchExcludeRegion = displayContent.mTouchExcludeRegion;
        DisplayInfo info = displayContent.getDisplayInfo();
        DisplayInfo info = displayContent.getDisplayInfo();
        mMotionSlop = (int)(info.logicalDensityDpi * TAP_MOTION_SLOP_INCHES);
        mMotionSlop = (int)(info.logicalDensityDpi * TAP_MOTION_SLOP_INCHES);
    }
    }
@@ -84,7 +86,7 @@ public class StackTapDetector extends InputEventReceiver {
                        if ((motionEvent.getEventTime() - motionEvent.getDownTime())
                        if ((motionEvent.getEventTime() - motionEvent.getDownTime())
                                < TAP_TIMEOUT_MSEC
                                < TAP_TIMEOUT_MSEC
                                && (x - mDownX) < mMotionSlop && (y - mDownY) < mMotionSlop
                                && (x - mDownX) < mMotionSlop && (y - mDownY) < mMotionSlop
                                && !mStackBounds.contains(x, y)) {
                                && !mTouchExcludeRegion.contains(x, y)) {
                            mService.mH.obtainMessage(H.TAP_OUTSIDE_STACK, x, y, mDisplayContent)
                            mService.mH.obtainMessage(H.TAP_OUTSIDE_STACK, x, y, mDisplayContent)
                                    .sendToTarget();
                                    .sendToTarget();
                        }
                        }
@@ -95,10 +97,4 @@ public class StackTapDetector extends InputEventReceiver {
            }
            }
        }
        }
    }
    }

    void setStackBounds(Rect bounds) {
        synchronized (this) {
            mStackBounds.set(bounds);
        }
    }
}
}
+3 −1
Original line number Original line Diff line number Diff line
@@ -3715,7 +3715,7 @@ public class WindowManagerService extends IWindowManager.Stub
        if (mFocusedApp != null) {
        if (mFocusedApp != null) {
            Task task = mTaskIdToTask.get(mFocusedApp.groupId);
            Task task = mTaskIdToTask.get(mFocusedApp.groupId);
            stack = task.mStack;
            stack = task.mStack;
            task.getDisplayContent().mTapDetector.setStackBounds(stack.mStackBox.mBounds);
            task.getDisplayContent().setTouchExcludeRegion(stack);
        } else {
        } else {
            stack = null;
            stack = null;
        }
        }
@@ -6895,6 +6895,8 @@ public class WindowManagerService extends IWindowManager.Stub
                    displayContent.mBaseDisplayWidth = displayContent.mInitialDisplayWidth;
                    displayContent.mBaseDisplayWidth = displayContent.mInitialDisplayWidth;
                    displayContent.mBaseDisplayHeight = displayContent.mInitialDisplayHeight;
                    displayContent.mBaseDisplayHeight = displayContent.mInitialDisplayHeight;
                    displayContent.mBaseDisplayDensity = displayContent.mInitialDisplayDensity;
                    displayContent.mBaseDisplayDensity = displayContent.mInitialDisplayDensity;
                    displayContent.mBaseDisplayRect.set(0, 0,
                            displayContent.mBaseDisplayWidth, displayContent.mBaseDisplayHeight);
                }
                }
            }
            }
        }
        }