diff options
2 files changed, 94 insertions, 2 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingWindowDecoration.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingWindowDecoration.kt index 854d9e1deef1..b57931121881 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingWindowDecoration.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingWindowDecoration.kt @@ -432,15 +432,38 @@ class DesktopTilingWindowDecoration( startTransaction: Transaction, finishTransaction: Transaction, ) { + var leftTaskBroughtToFront = false + var rightTaskBroughtToFront = false + for (change in info.changes) { change.taskInfo?.let { if (it.isFullscreen || isMinimized(change.mode, info.type)) { removeTaskIfTiled(it.taskId, /* taskVanished= */ false, it.isFullscreen) } else if (isEnteringPip(change, info.type)) { removeTaskIfTiled(it.taskId, /* taskVanished= */ true, it.isFullscreen) + } else if (isTransitionToFront(change.mode, info.type)) { + handleTaskBroughtToFront(it.taskId) + leftTaskBroughtToFront = + leftTaskBroughtToFront || + it.taskId == leftTaskResizingHelper?.taskInfo?.taskId + rightTaskBroughtToFront = + rightTaskBroughtToFront || + it.taskId == rightTaskResizingHelper?.taskInfo?.taskId } } } + + if (leftTaskBroughtToFront && rightTaskBroughtToFront) { + desktopTilingDividerWindowManager?.showDividerBar() + } + } + + private fun handleTaskBroughtToFront(taskId: Int) { + if (taskId == leftTaskResizingHelper?.taskInfo?.taskId) { + leftTaskResizingHelper?.onAppBecomingVisible() + } else if (taskId == rightTaskResizingHelper?.taskInfo?.taskId) { + rightTaskResizingHelper?.onAppBecomingVisible() + } } private fun isMinimized(changeMode: Int, infoType: Int): Boolean { @@ -471,6 +494,9 @@ class DesktopTilingWindowDecoration( return false } + private fun isTransitionToFront(changeMode: Int, transitionType: Int): Boolean = + changeMode == TRANSIT_TO_FRONT && transitionType == TRANSIT_TO_FRONT + class AppResizingHelper( val taskInfo: RunningTaskInfo, val desktopModeWindowDecoration: DesktopModeWindowDecoration, @@ -484,6 +510,7 @@ class DesktopTilingWindowDecoration( ) { var isInitialised = false var newBounds = Rect(bounds) + var visibilityCallback: (() -> Unit)? = null private lateinit var resizeVeil: ResizeVeil private val displayContext = displayController.getDisplayContext(taskInfo.displayId) private val userContext = @@ -521,6 +548,11 @@ class DesktopTilingWindowDecoration( fun updateVeil(t: Transaction) = resizeVeil.updateTransactionWithResizeVeil(t, newBounds) + fun onAppBecomingVisible() { + visibilityCallback?.invoke() + visibilityCallback = null + } + fun hideVeil() = resizeVeil.hideVeil() private fun createIconFactory(context: Context, dimensions: Int): BaseIconFactory { @@ -593,11 +625,16 @@ class DesktopTilingWindowDecoration( removeTask(leftTaskResizingHelper, taskVanished, shouldDelayUpdate) leftTaskResizingHelper = null val taskId = rightTaskResizingHelper?.taskInfo?.taskId - if (taskId != null && taskRepository.isVisibleTask(taskId)) { + val callback: (() -> Unit)? = { rightTaskResizingHelper ?.desktopModeWindowDecoration ?.updateDisabledResizingEdge(NONE, shouldDelayUpdate) } + if (taskId != null && taskRepository.isVisibleTask(taskId)) { + callback?.invoke() + } else if (rightTaskResizingHelper != null) { + rightTaskResizingHelper?.visibilityCallback = callback + } tearDownTiling() return } @@ -607,11 +644,17 @@ class DesktopTilingWindowDecoration( removeTask(rightTaskResizingHelper, taskVanished, shouldDelayUpdate) rightTaskResizingHelper = null val taskId = leftTaskResizingHelper?.taskInfo?.taskId - if (taskId != null && taskRepository.isVisibleTask(taskId)) { + val callback: (() -> Unit)? = { leftTaskResizingHelper ?.desktopModeWindowDecoration ?.updateDisabledResizingEdge(NONE, shouldDelayUpdate) } + if (taskId != null && taskRepository.isVisibleTask(taskId)) { + callback?.invoke() + } else if (leftTaskResizingHelper != null) { + leftTaskResizingHelper?.visibilityCallback = callback + } + tearDownTiling() } } diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingWindowDecorationTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingWindowDecorationTest.kt index e5f8d7d34a47..0adca5e864bf 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingWindowDecorationTest.kt +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingWindowDecorationTest.kt @@ -587,6 +587,31 @@ class DesktopTilingWindowDecorationTest : ShellTestCase() { } @Test + fun tilingDivider_shouldBeShown_whenTiledTasksBecomeVisible() { + val task1 = createVisibleTask() + val task2 = createVisibleTask() + val additionalTaskHelper: DesktopTilingWindowDecoration.AppResizingHelper = mock() + whenever(tiledTaskHelper.taskInfo).thenReturn(task1) + whenever(tiledTaskHelper.desktopModeWindowDecoration).thenReturn(desktopWindowDecoration) + whenever(additionalTaskHelper.taskInfo).thenReturn(task2) + whenever(additionalTaskHelper.desktopModeWindowDecoration) + .thenReturn(desktopWindowDecoration) + + tilingDecoration.leftTaskResizingHelper = tiledTaskHelper + tilingDecoration.rightTaskResizingHelper = additionalTaskHelper + tilingDecoration.desktopTilingDividerWindowManager = desktopTilingDividerWindowManager + val changeInfo = createTransitFrontTransition(task1, task2) + tilingDecoration.onTransitionReady( + transition = mock(), + info = changeInfo, + startTransaction = mock(), + finishTransaction = mock(), + ) + + verify(desktopTilingDividerWindowManager, times(1)).showDividerBar() + } + + @Test fun taskNotTiled_shouldNotBeRemoved_whenNotTiled() { val task1 = createVisibleTask() val task2 = createVisibleTask() @@ -762,6 +787,30 @@ class DesktopTilingWindowDecorationTest : ShellTestCase() { ) } + private fun createTransitFrontTransition( + task1: RunningTaskInfo?, + task2: RunningTaskInfo?, + type: Int = TRANSIT_TO_FRONT, + ) = + TransitionInfo(type, /* flags= */ 0).apply { + addChange( + Change(mock(), mock()).apply { + mode = TRANSIT_TO_FRONT + parent = null + taskInfo = task1 + flags = flags + } + ) + addChange( + Change(mock(), mock()).apply { + mode = TRANSIT_TO_FRONT + parent = null + taskInfo = task2 + flags = flags + } + ) + } + companion object { private val NON_STABLE_BOUNDS_MOCK = Rect(50, 55, 100, 100) private val STABLE_BOUNDS_MOCK = Rect(0, 0, 100, 100) |