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

Commit 830d7ccf authored by Omar Elmekkawy's avatar Omar Elmekkawy
Browse files

[4/n] Add an API to disable edge resizing for tiling.

This change updates DesktopModeWindowDecoration with an new API,
updateDisabledResizingEdge, that disables a resizing edge including its
corners for finger, mouse and styles gestures.

This is needed because on tiling a task on the left, its right resizing
edge should be disabled, and on tiling a task on the right, its left
resizing edge should be disabled.

Flag: com.android.window.flags.enable_tile_resizing
Test: tests are WIP
Bug: 369043190
Change-Id: I06298eb08ef3f798bf11bd1823b7a2e113a39128
parent ee4c7cfa
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -290,9 +290,11 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL

        final Resources res = mResult.mRootView.getResources();
        mDragResizeListener.setGeometry(new DragResizeWindowGeometry(0 /* taskCornerRadius */,
                new Size(mResult.mWidth, mResult.mHeight), getResizeEdgeHandleSize(res),
                        new Size(mResult.mWidth, mResult.mHeight),
                        getResizeEdgeHandleSize(res),
                        getResizeHandleEdgeInset(res), getFineResizeCornerSize(res),
                getLargeResizeCornerSize(res)), touchSlop);
                        getLargeResizeCornerSize(res), DragResizeWindowGeometry.DisabledEdge.NONE),
                touchSlop);
    }

    /**
+25 −1
Original line number Diff line number Diff line
@@ -27,10 +27,13 @@ import static android.view.MotionEvent.ACTION_UP;
import static android.window.DesktopModeFlags.ENABLE_CAPTION_COMPAT_INSET_FORCE_CONSUMPTION;
import static android.window.DesktopModeFlags.ENABLE_CAPTION_COMPAT_INSET_FORCE_CONSUMPTION_ALWAYS;


import static com.android.launcher3.icons.BaseIconFactory.MODE_DEFAULT;
import static com.android.wm.shell.shared.desktopmode.DesktopModeStatus.canEnterDesktopMode;
import static com.android.wm.shell.shared.desktopmode.DesktopModeTransitionSource.APP_HANDLE_MENU_BUTTON;
import static com.android.wm.shell.shared.split.SplitScreenConstants.SPLIT_POSITION_BOTTOM_OR_RIGHT;
import static com.android.wm.shell.windowdecor.DragResizeWindowGeometry.DisabledEdge;
import static com.android.wm.shell.windowdecor.DragResizeWindowGeometry.DisabledEdge.NONE;
import static com.android.wm.shell.windowdecor.DragResizeWindowGeometry.getFineResizeCornerSize;
import static com.android.wm.shell.windowdecor.DragResizeWindowGeometry.getLargeResizeCornerSize;
import static com.android.wm.shell.windowdecor.DragResizeWindowGeometry.getResizeEdgeHandleSize;
@@ -154,6 +157,8 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
    private DragResizeInputListener mDragResizeListener;
    private Runnable mCurrentViewHostRunnable = null;
    private RelayoutParams mRelayoutParams = new RelayoutParams();
    private DisabledEdge mDisabledResizingEdge =
            NONE;
    private final WindowDecoration.RelayoutResult<WindowDecorLinearLayout> mResult =
            new WindowDecoration.RelayoutResult<>();
    private final Runnable mViewHostRunnable =
@@ -394,6 +399,24 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
        }
    }

    /**
     * Disables resizing for the given edge.
     *
     * @param disabledResizingEdge edge to disable.
     * @param shouldDelayUpdate whether the update should be executed immediately or delayed.
     */
    public void updateDisabledResizingEdge(
            DragResizeWindowGeometry.DisabledEdge disabledResizingEdge, boolean shouldDelayUpdate) {
        mDisabledResizingEdge = disabledResizingEdge;
        final boolean inFullImmersive = mDesktopRepository
                .isTaskInFullImmersiveState(mTaskInfo.taskId);
        if (shouldDelayUpdate) {
            return;
        }
        updateDragResizeListener(mDecorationContainerSurface, inFullImmersive);
    }


    void relayout(ActivityManager.RunningTaskInfo taskInfo,
            SurfaceControl.Transaction startT, SurfaceControl.Transaction finishT,
            boolean applyStartTransactionOnDraw, boolean shouldSetTaskPositionAndCrop,
@@ -650,7 +673,8 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
                new DragResizeWindowGeometry(mRelayoutParams.mCornerRadius,
                        new Size(mResult.mWidth, mResult.mHeight),
                        getResizeEdgeHandleSize(res), getResizeHandleEdgeInset(res),
                        getFineResizeCornerSize(res), getLargeResizeCornerSize(res)), touchSlop)
                        getFineResizeCornerSize(res), getLargeResizeCornerSize(res),
                        mDisabledResizingEdge), touchSlop)
                || !mTaskInfo.positionInParent.equals(mPositionInParent)) {
            updateExclusionRegion(inFullImmersive);
        }
+48 −22
Original line number Diff line number Diff line
@@ -58,19 +58,24 @@ final class DragResizeWindowGeometry {
    // The bounds for each edge drag region, which can resize the task in one direction.
    final @NonNull TaskEdges mTaskEdges;

    private final DisabledEdge mDisabledEdge;

    DragResizeWindowGeometry(int taskCornerRadius, @NonNull Size taskSize,
            int resizeHandleEdgeOutset, int resizeHandleEdgeInset, int fineCornerSize,
            int largeCornerSize) {
            int largeCornerSize, DisabledEdge disabledEdge) {
        mTaskCornerRadius = taskCornerRadius;
        mTaskSize = taskSize;
        mResizeHandleEdgeOutset = resizeHandleEdgeOutset;
        mResizeHandleEdgeInset = resizeHandleEdgeInset;

        mLargeTaskCorners = new TaskCorners(mTaskSize, largeCornerSize);
        mFineTaskCorners = new TaskCorners(mTaskSize, fineCornerSize);
        mDisabledEdge = disabledEdge;

        mLargeTaskCorners = new TaskCorners(mTaskSize, largeCornerSize, disabledEdge);
        mFineTaskCorners = new TaskCorners(mTaskSize, fineCornerSize, disabledEdge);

        // Save touch areas for each edge.
        mTaskEdges = new TaskEdges(mTaskSize, mResizeHandleEdgeOutset, mResizeHandleEdgeInset);
        mTaskEdges = new TaskEdges(mTaskSize, mResizeHandleEdgeOutset, mResizeHandleEdgeInset,
                mDisabledEdge);
    }

    /**
@@ -187,8 +192,9 @@ final class DragResizeWindowGeometry {
    /**
     * Returns the control type for the drag-resize, based on the touch regions and this
     * MotionEvent's coordinates.
     *
     * @param isTouchscreen Controls the size of the corner resize regions; touchscreen events
     *                      (finger & stylus) are eligible for a larger area than cursor events
     *                      (finger & stylus) are eligible for a larger area than cursor events.
     * @param isEdgeResizePermitted Indicates if the event is eligible for falling into an edge
     *                              resize region.
     */
@@ -252,6 +258,10 @@ final class DragResizeWindowGeometry {
    @DragPositioningCallback.CtrlType
    private int checkDistanceFromCenter(@DragPositioningCallback.CtrlType int ctrlType, float x,
            float y) {
        if ((mDisabledEdge == DisabledEdge.RIGHT && (ctrlType & CTRL_TYPE_RIGHT) != 0)
                || mDisabledEdge == DisabledEdge.LEFT && ((ctrlType & CTRL_TYPE_LEFT) != 0)) {
            return CTRL_TYPE_UNDEFINED;
        }
        final Point cornerRadiusCenter = calculateCenterForCornerRadius(ctrlType);
        double distanceFromCenter = Math.hypot(x - cornerRadiusCenter.x, y - cornerRadiusCenter.y);

@@ -337,29 +347,31 @@ final class DragResizeWindowGeometry {
        private final @NonNull Rect mRightTopCornerBounds;
        private final @NonNull Rect mLeftBottomCornerBounds;
        private final @NonNull Rect mRightBottomCornerBounds;
        private final @NonNull DisabledEdge mDisabledEdge;

        TaskCorners(@NonNull Size taskSize, int cornerSize) {
        TaskCorners(@NonNull Size taskSize, int cornerSize, DisabledEdge disabledEdge) {
            mCornerSize = cornerSize;
            mDisabledEdge = disabledEdge;
            final int cornerRadius = cornerSize / 2;
            mLeftTopCornerBounds = new Rect(
            mLeftTopCornerBounds = (disabledEdge == DisabledEdge.LEFT) ? new Rect() : new Rect(
                    -cornerRadius,
                    -cornerRadius,
                    cornerRadius,
                    cornerRadius);

            mRightTopCornerBounds = new Rect(
            mRightTopCornerBounds = (disabledEdge == DisabledEdge.RIGHT) ? new Rect() : new Rect(
                    taskSize.getWidth() - cornerRadius,
                    -cornerRadius,
                    taskSize.getWidth() + cornerRadius,
                    cornerRadius);

            mLeftBottomCornerBounds = new Rect(
            mLeftBottomCornerBounds = (disabledEdge == DisabledEdge.LEFT) ? new Rect() : new Rect(
                    -cornerRadius,
                    taskSize.getHeight() - cornerRadius,
                    cornerRadius,
                    taskSize.getHeight() + cornerRadius);

            mRightBottomCornerBounds = new Rect(
            mRightBottomCornerBounds = (disabledEdge == DisabledEdge.RIGHT) ? new Rect() : new Rect(
                    taskSize.getWidth() - cornerRadius,
                    taskSize.getHeight() - cornerRadius,
                    taskSize.getWidth() + cornerRadius,
@@ -370,11 +382,15 @@ final class DragResizeWindowGeometry {
         * Updates the region to include all four corners.
         */
        void union(Region region) {
            region.union(mLeftTopCornerBounds);
            if (mDisabledEdge != DisabledEdge.RIGHT) {
                region.union(mRightTopCornerBounds);
            region.union(mLeftBottomCornerBounds);
                region.union(mRightBottomCornerBounds);
            }
            if (mDisabledEdge != DisabledEdge.LEFT) {
                region.union(mLeftTopCornerBounds);
                region.union(mLeftBottomCornerBounds);
            }
        }

        /**
         * Returns the control type based on the position of the {@code MotionEvent}'s coordinates.
@@ -440,9 +456,12 @@ final class DragResizeWindowGeometry {
        private final @NonNull Rect mRightEdgeBounds;
        private final @NonNull Rect mBottomEdgeBounds;
        private final @NonNull Region mRegion;
        private final @NonNull DisabledEdge mDisabledEdge;

        private TaskEdges(@NonNull Size taskSize, int resizeHandleThickness,
                int resizeHandleEdgeInset) {
                int resizeHandleEdgeInset, DisabledEdge disabledEdge) {
            // Save touch areas for each edge.
            mDisabledEdge = disabledEdge;
            // Save touch areas for each edge.
            mTopEdgeBounds = new Rect(
                    -resizeHandleThickness,
@@ -466,10 +485,7 @@ final class DragResizeWindowGeometry {
                    taskSize.getHeight() + resizeHandleThickness);

            mRegion = new Region();
            mRegion.union(mTopEdgeBounds);
            mRegion.union(mLeftEdgeBounds);
            mRegion.union(mRightEdgeBounds);
            mRegion.union(mBottomEdgeBounds);
            union(mRegion);
        }

        /**
@@ -483,9 +499,13 @@ final class DragResizeWindowGeometry {
         * Updates the region to include all four corners.
         */
        private void union(Region region) {
            region.union(mTopEdgeBounds);
            region.union(mLeftEdgeBounds);
            if (mDisabledEdge != DisabledEdge.RIGHT) {
                region.union(mRightEdgeBounds);
            }
            if (mDisabledEdge != DisabledEdge.LEFT) {
                region.union(mLeftEdgeBounds);
            }
            region.union(mTopEdgeBounds);
            region.union(mBottomEdgeBounds);
        }

@@ -519,4 +539,10 @@ final class DragResizeWindowGeometry {
                    mBottomEdgeBounds);
        }
    }

    public enum DisabledEdge {
        LEFT,
        RIGHT,
        NONE
    }
}