From a33c19b877205b941a3a67386cc1981c290d10d2 Mon Sep 17 00:00:00 2001 From: Shuming Hao Date: Wed, 26 Feb 2025 13:37:09 -0800 Subject: Break up DesktopTasksController#moveToDisplay Break up DesktopTasksController#moveToDisplay into two smaller functions: one for split screen tasks, one for the rest of tasks. Bug: 399411604 Test: manual Flag: EXEMPT refactor Change-Id: I0c8662b78425d477e203299b1fa8f24eeec462ab --- .../wm/shell/desktopmode/DesktopTasksController.kt | 85 +++++++++++++--------- 1 file changed, 52 insertions(+), 33 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt index 301b79afd537..9e9cc513ea6a 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt @@ -1169,6 +1169,11 @@ class DesktopTasksController( return } + if (splitScreenController.isTaskInSplitScreen(task.taskId)) { + moveSplitPairToDisplay(task, displayId) + return + } + val wct = WindowContainerTransaction() val displayAreaInfo = rootTaskDisplayAreaOrganizer.getDisplayAreaInfo(displayId) if (displayAreaInfo == null) { @@ -1176,39 +1181,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") @@ -1269,6 +1241,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 -- cgit v1.2.3-59-g8ed1b