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

Commit 93d68c27 authored by Vishnu Nair's avatar Vishnu Nair
Browse files

WM: Add a crop to touchable region if needed

When populating the touchable region, check whether we should crop to stack bounds. With the
introduction of public SurfaceControl, users can position the surface outside of the bounds
its parents. SurfaceFlinger will ensure that regions outside its parents are not drawn but
the surface may still consume touch input.

Setting the crop will ensure that we crop the touch region to the specified surface.

Bug: 123992966

Test: go/wm-smoke
Test: manual input tests and check winscope trace
Change-Id: I4426500ea0a70a6b511cb26b4f9cdf5e0bcbac3f
parent 16b4163b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -245,7 +245,7 @@ final class InputMonitor {
            final boolean hasFocus, final boolean hasWallpaper) {
        // Add a window to our list of input windows.
        inputWindowHandle.name = child.toString();
        flags = child.getSurfaceTouchableRegion(inputWindowHandle.touchableRegion, flags);
        flags = child.getSurfaceTouchableRegion(inputWindowHandle, flags);
        inputWindowHandle.layoutParamsFlags = flags;
        inputWindowHandle.layoutParamsType = type;
        inputWindowHandle.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
+20 −2
Original line number Diff line number Diff line
@@ -213,7 +213,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
    static final String TAG = TAG_WITH_CLASS_NAME ? "WindowState" : TAG_WM;

    // The minimal size of a window within the usable area of the freeform stack.
    // TODO(multi-window): fix the min sizes when we have mininum width/height support,
    // TODO(multi-window): fix the min sizes when we have minimum width/height support,
    //                     use hard-coded min sizes for now.
    static final int MINIMUM_VISIBLE_WIDTH_IN_DP = 48;
    static final int MINIMUM_VISIBLE_HEIGHT_IN_DP = 32;
@@ -2183,8 +2183,11 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        }
    }

    int getSurfaceTouchableRegion(Region region, int flags) {
    int getSurfaceTouchableRegion(InputWindowHandle inputWindowHandle, int flags) {
        final boolean modal = (flags & (FLAG_NOT_TOUCH_MODAL | FLAG_NOT_FOCUSABLE)) == 0;
        final Region region = inputWindowHandle.touchableRegion;
        setTouchableRegionCropIfNeeded(inputWindowHandle);

        if (mAppToken != null && !mAppToken.getResolvedOverrideBounds().isEmpty()) {
            // There may have touchable letterboxes around the activity, so in order to let the
            // letterboxes are able to receive touch event and slip to activity, the activity with
@@ -2246,6 +2249,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
                region.set(-dw, -dh, dw + dw, dh + dh);
                // Subtract the area that cannot be touched.
                region.op(touchExcludeRegion, Region.Op.DIFFERENCE);
                inputWindowHandle.setTouchableRegionCrop(null);
            }
            touchExcludeRegion.recycle();
        } else {
@@ -2920,6 +2924,20 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        subtractTouchExcludeRegionIfNeeded(outRegion);
    }

    private void setTouchableRegionCropIfNeeded(InputWindowHandle handle) {
        final Task task = getTask();
        if (task == null || !task.cropWindowsToStackBounds()) {
            return;
        }

        final TaskStack stack = task.mStack;
        if (stack == null) {
            return;
        }

        handle.setTouchableRegionCrop(stack.getSurfaceControl());
    }

    private void cropRegionToStackBoundsIfNeeded(Region region) {
        final Task task = getTask();
        if (task == null || !task.cropWindowsToStackBounds()) {