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

Commit d766c709 authored by dakinola's avatar dakinola
Browse files

[1/n] Update desktop task drag listeners to not update task position immediately on drag stop

Before, the DragPositioningCallback would immediately send a WCT to update the task position onDragPositioningEnd. This isn't necessary all the time, since the callers of DragPositioningCallback also end up creating a WCT to set task position after their own transformations (i.e. the differnt indicator listeners in DesktopTasksController). So now, only the task leash will be updated in onDragPositiongMove, and the last position of the task leash will be returned from onDragPositioningEnd, meaning only one WCT will be needed (if needed at all).

Bug: 354280814
Flag: EXEMPT bugfix
Test: atest DesktopTasksControllerTest
Test: atest DesktopModeWindowDecorViewModelTests
Change-Id: I92fb73eff79f5c9859e7606d7a6fa21779648214
parent 65672c90
Loading
Loading
Loading
Loading
+33 −25
Original line number Diff line number Diff line
@@ -639,16 +639,23 @@ class DesktopTasksController(
    /**
     * Quick-resize to the right or left half of the stable bounds.
     *
     * @param taskInfo current task that is being snap-resized via dragging or maximize menu button
     * @param currentDragBounds current position of the task leash being dragged (or current task
     *                          bounds if being snapped resize via maximize menu button)
     * @param position the portion of the screen (RIGHT or LEFT) we want to snap the task to.
     */
    fun snapToHalfScreen(taskInfo: RunningTaskInfo, position: SnapPosition) {
    fun snapToHalfScreen(
        taskInfo: RunningTaskInfo,
        currentDragBounds: Rect,
        position: SnapPosition
    ) {
        val destinationBounds = getSnapBounds(taskInfo, position)

        if (destinationBounds == taskInfo.configuration.windowConfiguration.bounds) return

        val wct = WindowContainerTransaction().setBounds(taskInfo.token, destinationBounds)
        if (Transitions.ENABLE_SHELL_TRANSITIONS) {
            toggleResizeDesktopTaskTransitionHandler.startTransition(wct)
            toggleResizeDesktopTaskTransitionHandler.startTransition(wct, currentDragBounds)
        } else {
            shellTaskOrganizer.applyTransaction(wct)
        }
@@ -1239,7 +1246,7 @@ class DesktopTasksController(
        taskSurface: SurfaceControl,
        inputX: Float,
        taskTop: Float
    ): DesktopModeVisualIndicator.IndicatorType {
    ): IndicatorType {
        // If the visual indicator does not exist, create it.
        val indicator =
            visualIndicator
@@ -1262,13 +1269,15 @@ class DesktopTasksController(
     * @param taskInfo the task being dragged.
     * @param position position of surface when drag ends.
     * @param inputCoordinate the coordinates of the motion event
     * @param taskBounds the updated bounds of the task being dragged.
     * @param currentDragBounds the current bounds of where the visible task is (might be actual
     *                          task bounds or just task leash)
     * @param validDragArea the bounds of where the task can be dragged within the display.
     */
    fun onDragPositioningEnd(
        taskInfo: RunningTaskInfo,
        position: Point,
        inputCoordinate: PointF,
        taskBounds: Rect,
        currentDragBounds: Rect,
        validDragArea: Rect
    ) {
        if (taskInfo.configuration.windowConfiguration.windowingMode != WINDOWING_MODE_FREEFORM) {
@@ -1278,41 +1287,40 @@ class DesktopTasksController(
        val indicator = visualIndicator ?: return
        val indicatorType =
            indicator.updateIndicatorType(
                PointF(inputCoordinate.x, taskBounds.top.toFloat()),
                PointF(inputCoordinate.x, currentDragBounds.top.toFloat()),
                taskInfo.windowingMode
            )
        when (indicatorType) {
            DesktopModeVisualIndicator.IndicatorType.TO_FULLSCREEN_INDICATOR -> {
            IndicatorType.TO_FULLSCREEN_INDICATOR -> {
                moveToFullscreenWithAnimation(
                    taskInfo,
                    position,
                    DesktopModeTransitionSource.TASK_DRAG
                )
            }
            DesktopModeVisualIndicator.IndicatorType.TO_SPLIT_LEFT_INDICATOR -> {
            IndicatorType.TO_SPLIT_LEFT_INDICATOR -> {
                releaseVisualIndicator()
                snapToHalfScreen(taskInfo, SnapPosition.LEFT)
                snapToHalfScreen(taskInfo, currentDragBounds, SnapPosition.LEFT)
            }
            DesktopModeVisualIndicator.IndicatorType.TO_SPLIT_RIGHT_INDICATOR -> {
            IndicatorType.TO_SPLIT_RIGHT_INDICATOR -> {
                releaseVisualIndicator()
                snapToHalfScreen(taskInfo, SnapPosition.RIGHT)
                snapToHalfScreen(taskInfo, currentDragBounds, SnapPosition.RIGHT)
            }
            DesktopModeVisualIndicator.IndicatorType.NO_INDICATOR -> {
                // If task bounds are outside valid drag area, snap them inward and perform a
                // transaction to set bounds.
                if (
            IndicatorType.NO_INDICATOR -> {
                // If task bounds are outside valid drag area, snap them inward
                DragPositioningCallbackUtility.snapTaskBoundsIfNecessary(
                        taskBounds,
                    currentDragBounds,
                    validDragArea
                )
                ) {

                // Update task bounds so that the task position will match the position of its leash
                val wct = WindowContainerTransaction()
                    wct.setBounds(taskInfo.token, taskBounds)
                wct.setBounds(taskInfo.token, currentDragBounds)
                transitions.startTransition(TRANSIT_CHANGE, wct, null)
                }

                releaseVisualIndicator()
            }
            DesktopModeVisualIndicator.IndicatorType.TO_DESKTOP_INDICATOR -> {
            IndicatorType.TO_DESKTOP_INDICATOR -> {
                throw IllegalArgumentException(
                    "Should not be receiving TO_DESKTOP_INDICATOR for " + "a freeform task."
                )
+14 −4
Original line number Diff line number Diff line
@@ -45,15 +45,24 @@ class ToggleResizeDesktopTaskTransitionHandler(
    private lateinit var onTaskResizeAnimationListener: OnTaskResizeAnimationListener

    private var boundsAnimator: Animator? = null
    private var initialBounds: Rect? = null

    constructor(
        transitions: Transitions,
        interactionJankMonitor: InteractionJankMonitor
    ) : this(transitions, Supplier { SurfaceControl.Transaction() }, interactionJankMonitor)

    /** Starts a quick resize transition. */
    fun startTransition(wct: WindowContainerTransaction) {
    /**
     * Starts a quick resize transition.
     *
     *  @param wct WindowContainerTransaction that will update core about the task changes applied
     *  @param taskLeashBounds current bounds of the task leash (Note: not guaranteed to be the
     *                         bounds of the actual task). This is provided so that the animation
     *                         resizing can begin where the task leash currently is for smoother UX.
     */
    fun startTransition(wct: WindowContainerTransaction, taskLeashBounds: Rect? = null) {
        transitions.startTransition(TRANSIT_DESKTOP_MODE_TOGGLE_RESIZE, wct, this)
        initialBounds = taskLeashBounds
    }

    fun setOnTaskResizeAnimationListener(listener: OnTaskResizeAnimationListener) {
@@ -70,7 +79,7 @@ class ToggleResizeDesktopTaskTransitionHandler(
        val change = findRelevantChange(info)
        val leash = change.leash
        val taskId = checkNotNull(change.taskInfo).taskId
        val startBounds = change.startAbsBounds
        val startBounds = initialBounds ?: change.startAbsBounds
        val endBounds = change.endAbsBounds

        val tx = transactionSupplier.get()
@@ -92,7 +101,7 @@ class ToggleResizeDesktopTaskTransitionHandler(
                            onTaskResizeAnimationListener.onAnimationStart(
                                taskId,
                                startTransaction,
                                startBounds
                                startBounds,
                            )
                        },
                        onEnd = {
@@ -106,6 +115,7 @@ class ToggleResizeDesktopTaskTransitionHandler(
                                .show(leash)
                            onTaskResizeAnimationListener.onAnimationEnd(taskId)
                            finishCallback.onTransitionFinished(null)
                            initialBounds = null
                            boundsAnimator = null
                            interactionJankMonitor.end(
                                Cuj.CUJ_DESKTOP_MODE_MAXIMIZE_WINDOW)
+8 −4
Original line number Diff line number Diff line
@@ -297,7 +297,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
        mDisplayInsetsController.addInsetsChangedListener(mContext.getDisplayId(),
                new DesktopModeOnInsetsChangedListener());
        mDesktopTasksController.setOnTaskResizeAnimationListener(
                new DeskopModeOnTaskResizeAnimationListener());
                new DesktopModeOnTaskResizeAnimationListener());
        try {
            mWindowManager.registerSystemGestureExclusionListener(mGestureExclusionListener,
                    mContext.getDisplayId());
@@ -437,6 +437,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
            return;
        }
        mDesktopTasksController.snapToHalfScreen(decoration.mTaskInfo,
                decoration.mTaskInfo.configuration.windowConfiguration.getBounds(),
                left ? SnapPosition.LEFT : SnapPosition.RIGHT);
        decoration.closeHandleMenu();
        decoration.closeMaximizeMenu();
@@ -767,6 +768,9 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
                            (int) (e.getRawY(dragPointerIdx) - e.getY(dragPointerIdx)));
                    final Rect newTaskBounds = mDragPositioningCallback.onDragPositioningEnd(
                            e.getRawX(dragPointerIdx), e.getRawY(dragPointerIdx));
                    // Tasks bounds haven't actually been updated (only its leash), so pass to
                    // DesktopTasksController to allow secondary transformations (i.e. snap resizing
                    // or transforming to fullscreen) before setting new task bounds.
                    mDesktopTasksController.onDragPositioningEnd(taskInfo, position,
                            new PointF(e.getRawX(dragPointerIdx), e.getRawY(dragPointerIdx)),
                            newTaskBounds, decoration.calculateValidDragArea());
@@ -1267,7 +1271,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
        pw.println(innerPrefix + "mWindowDecorByTaskId=" + mWindowDecorByTaskId);
    }

    private class DeskopModeOnTaskResizeAnimationListener
    private class DesktopModeOnTaskResizeAnimationListener
            implements OnTaskResizeAnimationListener {
        @Override
        public void onAnimationStart(int taskId, Transaction t, Rect bounds) {
+0 −3
Original line number Diff line number Diff line
@@ -152,11 +152,8 @@ class FluidResizeTaskPositioner implements DragPositioningCallback,
            }
            mDragResizeEndTransition = mTransitions.startTransition(TRANSIT_CHANGE, wct, this);
        } else if (mCtrlType == CTRL_TYPE_UNDEFINED) {
            final WindowContainerTransaction wct = new WindowContainerTransaction();
            DragPositioningCallbackUtility.updateTaskBounds(mRepositionTaskBounds,
                    mTaskBoundsAtDragStart, mRepositionStartPoint, x, y);
            wct.setBounds(mWindowDecoration.mTaskInfo.token, mRepositionTaskBounds);
            mTransitions.startTransition(TRANSIT_CHANGE, wct, this);
        }

        mTaskBoundsAtDragStart.setEmpty();
+0 −7
Original line number Diff line number Diff line
@@ -163,15 +163,8 @@ public class VeiledResizeTaskPositioner implements DragPositioningCallback,
        } else {
            DragPositioningCallbackUtility.updateTaskBounds(mRepositionTaskBounds,
                    mTaskBoundsAtDragStart, mRepositionStartPoint, x, y);
            if (!mTaskBoundsAtDragStart.equals(mRepositionTaskBounds)) {
                final WindowContainerTransaction wct = new WindowContainerTransaction();
                wct.setBounds(mDesktopWindowDecoration.mTaskInfo.token, mRepositionTaskBounds);
                mTransitions.startTransition(TRANSIT_CHANGE, wct, this);
            } else {
                // Drag-move ended where it originally started, no need to update WM.
                mInteractionJankMonitor.end(CUJ_DESKTOP_MODE_DRAG_WINDOW);
        }
        }

        mCtrlType = CTRL_TYPE_UNDEFINED;
        mTaskBoundsAtDragStart.setEmpty();
Loading