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

Commit 1cfb8c70 authored by Shuming Hao's avatar Shuming Hao Committed by Android (Google) Code Review
Browse files

Merge "Break up DesktopTasksController#moveToDisplay" into main

parents 0b439658 a33c19b8
Loading
Loading
Loading
Loading
+52 −33
Original line number Diff line number Diff line
@@ -1198,6 +1198,11 @@ class DesktopTasksController(
            return
        }

        if (splitScreenController.isTaskInSplitScreen(task.taskId)) {
            moveSplitPairToDisplay(task, displayId)
            return
        }

        val wct = WindowContainerTransaction()
        val displayAreaInfo = rootTaskDisplayAreaOrganizer.getDisplayAreaInfo(displayId)
        if (displayAreaInfo == null) {
@@ -1205,39 +1210,6 @@ class DesktopTasksController(
            return
        }

        // check if the task is part of splitscreen
        if (
            Flags.enableNonDefaultDisplaySplit() &&
                Flags.enableMoveToNextDisplayShortcut() &&
                splitScreenController.isTaskInSplitScreen(task.taskId)
        ) {
            val activeDeskId = taskRepository.getActiveDeskId(displayId)
            logV("moveToDisplay: moving split root to displayId=%d", displayId)
            val stageCoordinatorRootTaskToken =
                splitScreenController.multiDisplayProvider.getDisplayRootForDisplayId(
                    DEFAULT_DISPLAY
                )
            wct.reparent(stageCoordinatorRootTaskToken, displayAreaInfo.token, true /* onTop */)
            val deactivationRunnable =
                if (activeDeskId != null) {
                    // Split is being placed on top of an existing desk in the target display. Make
                    // sure it is cleaned up.
                    performDesktopExitCleanUp(
                        wct = wct,
                        deskId = activeDeskId,
                        displayId = displayId,
                        willExitDesktop = true,
                        shouldEndUpAtHome = false,
                    )
                } else {
                    null
                }
            val transition =
                transitions.startTransition(TRANSIT_CHANGE, wct, moveToDisplayTransitionHandler)
            deactivationRunnable?.invoke(transition)
            return
        }

        val destinationDeskId = taskRepository.getDefaultDeskId(displayId)
        if (destinationDeskId == null) {
            logW("moveToDisplay: desk not found for display: $displayId")
@@ -1298,6 +1270,53 @@ class DesktopTasksController(
        activationRunnable?.invoke(transition)
    }

    /**
     * Move split pair associated with the [task] to display with [displayId].
     *
     * No-op if task is already on that display per [RunningTaskInfo.displayId].
     */
    private fun moveSplitPairToDisplay(task: RunningTaskInfo, displayId: Int) {
        if (!splitScreenController.isTaskInSplitScreen(task.taskId)) {
            return
        }

        if (!Flags.enableNonDefaultDisplaySplit() || !Flags.enableMoveToNextDisplayShortcut()) {
            return
        }

        val wct = WindowContainerTransaction()
        val displayAreaInfo = rootTaskDisplayAreaOrganizer.getDisplayAreaInfo(displayId)
        if (displayAreaInfo == null) {
            logW("moveSplitPairToDisplay: display not found")
            return
        }

        val activeDeskId = taskRepository.getActiveDeskId(displayId)
        logV("moveSplitPairToDisplay: moving split root to displayId=%d", displayId)

        val stageCoordinatorRootTaskToken =
            splitScreenController.multiDisplayProvider.getDisplayRootForDisplayId(DEFAULT_DISPLAY)
        wct.reparent(stageCoordinatorRootTaskToken, displayAreaInfo.token, true /* onTop */)

        val deactivationRunnable =
            if (activeDeskId != null) {
                // Split is being placed on top of an existing desk in the target display. Make
                // sure it is cleaned up.
                performDesktopExitCleanUp(
                    wct = wct,
                    deskId = activeDeskId,
                    displayId = displayId,
                    willExitDesktop = true,
                    shouldEndUpAtHome = false,
                )
            } else {
                null
            }
        val transition = transitions.startTransition(TRANSIT_CHANGE, wct, /* handler= */ null)
        deactivationRunnable?.invoke(transition)
        return
    }

    /**
     * Quick-resizes a desktop task, toggling between a fullscreen state (represented by the stable
     * bounds) and a free floating state (either the last saved bounds if available or the default