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

Commit 19037586 authored by Pierre Barbier de Reuille's avatar Pierre Barbier de Reuille Committed by Android (Google) Code Review
Browse files

Merge "Make sure Tiling knows when a task is focused" into main

parents 01bdfef3 e0eb24a7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -103,7 +103,7 @@ class DesktopTilingDecorViewModel(
    fun moveTaskToFrontIfTiled(taskInfo: RunningTaskInfo): Boolean {
        return tilingTransitionHandlerByDisplayId
            .get(taskInfo.displayId)
            ?.moveTiledPairToFront(taskInfo) ?: false
            ?.moveTiledPairToFront(taskInfo, isTaskFocused = true) ?: false
    }

    fun onOverviewAnimationStateChange(isRunning: Boolean) {
+18 −8
Original line number Diff line number Diff line
@@ -230,14 +230,14 @@ class DesktopTilingWindowDecoration(
            ResizeTrigger.TILING_DIVIDER,
            motionEvent,
            leftTiledTask.taskInfo,
            displayController
            displayController,
        )

        desktopModeEventLogger.logTaskResizingStarted(
            ResizeTrigger.TILING_DIVIDER,
            motionEvent,
            rightTiledTask.taskInfo,
            displayController
            displayController,
        )
    }

@@ -303,7 +303,7 @@ class DesktopTilingWindowDecoration(
            leftTiledTask.taskInfo,
            leftTiledTask.newBounds.height(),
            leftTiledTask.newBounds.width(),
            displayController
            displayController,
        )

        desktopModeEventLogger.logTaskResizingEnded(
@@ -312,7 +312,7 @@ class DesktopTilingWindowDecoration(
            rightTiledTask.taskInfo,
            rightTiledTask.newBounds.height(),
            rightTiledTask.newBounds.width(),
            displayController
            displayController,
        )

        if (leftTiledTask.newBounds == leftTiledTask.bounds) {
@@ -471,9 +471,9 @@ class DesktopTilingWindowDecoration(
        }
    }

    // Only called if [taskInfo] relates to a focused task
    private fun isTilingFocusRemoved(taskInfo: RunningTaskInfo): Boolean {
        return taskInfo.isFocused &&
            isTilingFocused &&
        return isTilingFocused &&
            taskInfo.taskId != leftTaskResizingHelper?.taskInfo?.taskId &&
            taskInfo.taskId != rightTaskResizingHelper?.taskInfo?.taskId
    }
@@ -484,9 +484,9 @@ class DesktopTilingWindowDecoration(
        }
    }

    // Only called if [taskInfo] relates to a focused task
    private fun isTilingRefocused(taskInfo: RunningTaskInfo): Boolean {
        return !isTilingFocused &&
            taskInfo.isFocused &&
            (taskInfo.taskId == leftTaskResizingHelper?.taskInfo?.taskId ||
                taskInfo.taskId == rightTaskResizingHelper?.taskInfo?.taskId)
    }
@@ -573,9 +573,19 @@ class DesktopTilingWindowDecoration(
        removeTaskIfTiled(taskId, taskVanished = true, shouldDelayUpdate = true)
    }

    fun moveTiledPairToFront(taskInfo: RunningTaskInfo): Boolean {
    /**
     * Moves the tiled pair to the front of the task stack, if the [taskInfo] is focused and one of
     * the two tiled tasks.
     *
     * If specified, [isTaskFocused] will override [RunningTaskInfo.isFocused]. This is to be used
     * when called when the task will be focused, but the [taskInfo] hasn't been updated yet.
     */
    fun moveTiledPairToFront(taskInfo: RunningTaskInfo, isTaskFocused: Boolean? = null): Boolean {
        if (!isTilingManagerInitialised) return false

        val isFocused = isTaskFocused ?: taskInfo.isFocused
        if (!isFocused) return false

        // If a task that isn't tiled is being focused, let the generic handler do the work.
        if (isTilingFocusRemoved(taskInfo)) {
            isTilingFocused = false
+3 −2
Original line number Diff line number Diff line
@@ -24,8 +24,8 @@ import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.ShellTestCase
import com.android.wm.shell.common.DisplayController
import com.android.wm.shell.common.SyncTransactionQueue
import com.android.wm.shell.desktopmode.DesktopRepository
import com.android.wm.shell.desktopmode.DesktopModeEventLogger
import com.android.wm.shell.desktopmode.DesktopRepository
import com.android.wm.shell.desktopmode.DesktopTasksController
import com.android.wm.shell.desktopmode.DesktopTestHelpers.Companion.createFreeformTask
import com.android.wm.shell.desktopmode.ReturnToDragStartAnimator
@@ -130,7 +130,8 @@ class DesktopTilingDecorViewModelTest : ShellTestCase() {
        )
        desktopTilingDecorViewModel.moveTaskToFrontIfTiled(task1)

        verify(desktopTilingDecoration, times(1)).moveTiledPairToFront(any())
        verify(desktopTilingDecoration, times(1))
            .moveTiledPairToFront(any(), isTaskFocused = eq(true))
    }

    @Test
+31 −0
Original line number Diff line number Diff line
@@ -327,6 +327,37 @@ class DesktopTilingWindowDecorationTest : ShellTestCase() {
        verify(transitions, times(1)).startTransition(eq(TRANSIT_TO_FRONT), any(), eq(null))
    }

    @Test
    fun taskTiled_broughtToFront_taskInfoNotUpdated_bringToFront() {
        val task1 = createFreeformTask()
        val task2 = createFreeformTask()
        val task3 = createFreeformTask()
        val stableBounds = STABLE_BOUNDS_MOCK
        whenever(displayLayout.getStableBounds(any())).thenAnswer { i ->
            (i.arguments.first() as Rect).set(stableBounds)
        }
        whenever(context.resources).thenReturn(resources)
        whenever(resources.getDimensionPixelSize(any())).thenReturn(split_divider_width)
        whenever(desktopWindowDecoration.getLeash()).thenReturn(surfaceControlMock)
        whenever(desktopRepository.isVisibleTask(any())).thenReturn(true)
        tilingDecoration.onAppTiled(
            task1,
            desktopWindowDecoration,
            DesktopTasksController.SnapPosition.RIGHT,
            BOUNDS,
        )
        tilingDecoration.onAppTiled(
            task2,
            desktopWindowDecoration,
            DesktopTasksController.SnapPosition.LEFT,
            BOUNDS,
        )

        assertThat(tilingDecoration.moveTiledPairToFront(task3, isTaskFocused = true)).isFalse()
        assertThat(tilingDecoration.moveTiledPairToFront(task1, isTaskFocused = true)).isTrue()
        verify(transitions, times(1)).startTransition(eq(TRANSIT_TO_FRONT), any(), eq(null))
    }

    @Test
    fun taskTiledTasks_NotResized_BeforeTouchEndArrival() {
        // Setup