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

Commit 85dde963 authored by Yuichiro Hanada's avatar Yuichiro Hanada Committed by Android (Google) Code Review
Browse files

Merge "Make a window translucent when a cursor is on another display" into main

parents 55f62f96 8d89ee00
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -215,6 +215,13 @@ class MultiDisplayVeiledResizeTaskPositioner(
                    repositionTaskBounds.left.toFloat(),
                    repositionTaskBounds.top.toFloat(),
                )
                // Make the window translucent in the case when the cursor moves to another display.
                val alpha = if (startDisplayId == displayId) {
                    ALPHA_FOR_WINDOW_ON_DISPLAY_WITH_CURSOR
                } else {
                    ALPHA_FOR_WINDOW_ON_NON_CURSOR_DISPLAY
                }
                t.setAlpha(desktopWindowDecoration.leash, alpha)
            }
            t.setFrameTimeline(Choreographer.getInstance().vsyncId)
            t.apply()
@@ -387,5 +394,8 @@ class MultiDisplayVeiledResizeTaskPositioner(
        // Timeout used for resize and drag CUJs, this is longer than the default timeout to avoid
        // timing out in the middle of a resize or drag action.
        private val LONG_CUJ_TIMEOUT_MS = TimeUnit.SECONDS.toMillis(/* duration= */ 10L)

        private val ALPHA_FOR_WINDOW_ON_DISPLAY_WITH_CURSOR = 1.0f
        private val ALPHA_FOR_WINDOW_ON_NON_CURSOR_DISPLAY = 0.8f
    }
}
+43 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ import org.mockito.Mock
import org.mockito.Mockito.argThat
import org.mockito.Mockito.doAnswer
import org.mockito.Mockito.eq
import org.mockito.Mockito.inOrder
import org.mockito.Mockito.mock
import org.mockito.Mockito.never
import org.mockito.Mockito.times
@@ -144,6 +145,7 @@ class MultiDisplayVeiledResizeTaskPositionerTest : ShellTestCase() {
        `when`(mockTransactionFactory.get()).thenReturn(mockTransaction)
        `when`(mockDesktopWindowDecoration.leash).thenReturn(mockSurfaceControl)
        `when`(mockTransaction.setPosition(any(), any(), any())).thenReturn(mockTransaction)
        `when`(mockTransaction.setAlpha(any(), any())).thenReturn(mockTransaction)
        mockDesktopWindowDecoration.mTaskInfo =
            ActivityManager.RunningTaskInfo().apply {
                taskId = TASK_ID
@@ -275,6 +277,8 @@ class MultiDisplayVeiledResizeTaskPositionerTest : ShellTestCase() {
        val rectAfterMove = Rect(200, -50, 300, 50)
        verify(mockTransaction)
            .setPosition(any(), eq(rectAfterMove.left.toFloat()), eq(rectAfterMove.top.toFloat()))
        verify(mockTransaction)
            .setAlpha(eq(mockDesktopWindowDecoration.leash), eq(ALPHA_FOR_TRANSLUCENT_WINDOW))

        val endBounds = taskPositioner.onDragPositioningEnd(DISPLAY_ID_1, 300f, 450f)
        val rectAfterEnd = Rect(300, 450, 500, 650)
@@ -285,6 +289,43 @@ class MultiDisplayVeiledResizeTaskPositionerTest : ShellTestCase() {
        Assert.assertEquals(rectAfterEnd, endBounds)
    }

    @Test
    fun testDragResize_movesTaskToNewDisplayThenBackToOriginalDisplay() = runOnUiThread {
        taskPositioner.onDragPositioningStart(
            CTRL_TYPE_UNDEFINED,
            DISPLAY_ID_0,
            STARTING_BOUNDS.left.toFloat(),
            STARTING_BOUNDS.top.toFloat(),
        )

        val inOrder = inOrder(mockTransaction)

        // Move to the display 1
        taskPositioner.onDragPositioningMove(DISPLAY_ID_1, 200f, 800f)
        val rectAfterMove = Rect(200, -600, 300, -400)
        inOrder.verify(mockTransaction)
            .setPosition(any(), eq(rectAfterMove.left.toFloat()), eq(rectAfterMove.top.toFloat()))
        inOrder.verify(mockTransaction)
            .setAlpha(eq(mockDesktopWindowDecoration.leash), eq(ALPHA_FOR_TRANSLUCENT_WINDOW))

        // Moving back to the original display
        taskPositioner.onDragPositioningMove(DISPLAY_ID_0, 100f, 1500f)
        rectAfterMove.set(100, 1500, 200, 1700)
        inOrder.verify(mockTransaction)
            .setPosition(any(), eq(rectAfterMove.left.toFloat()), eq(rectAfterMove.top.toFloat()))
        inOrder.verify(mockTransaction)
            .setAlpha(eq(mockDesktopWindowDecoration.leash), eq(ALPHA_FOR_VISIBLE_WINDOW))

        // Finish the drag move on the original display
        val endBounds = taskPositioner.onDragPositioningEnd(DISPLAY_ID_0, 50f, 50f)
        rectAfterMove.set(50, 50, 150, 150)

        verify(mockDesktopWindowDecoration, never()).showResizeVeil(any())
        verify(mockDesktopWindowDecoration, never()).hideResizeVeil()
        verify(mockMultiDisplayDragMoveIndicatorController).onDragEnd(eq(TASK_ID), any())
        Assert.assertEquals(rectAfterMove, endBounds)
    }

    @Test
    fun testDragResize_resize_boundsUpdateOnEnd() = runOnUiThread {
        taskPositioner.onDragPositioningStart(
@@ -681,6 +722,8 @@ class MultiDisplayVeiledResizeTaskPositionerTest : ShellTestCase() {
        private const val NAVBAR_HEIGHT = 50
        private const val CAPTION_HEIGHT = 50
        private const val DISALLOWED_AREA_FOR_END_BOUNDS_HEIGHT = 10
        private const val ALPHA_FOR_TRANSLUCENT_WINDOW = 0.8f
        private const val ALPHA_FOR_VISIBLE_WINDOW = 1.0f
        private val DISPLAY_BOUNDS = Rect(0, 0, 2400, 1600)
        private val STARTING_BOUNDS = Rect(100, 100, 200, 200)
        private val STABLE_BOUNDS_LANDSCAPE =