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

Commit c6fb62e9 authored by Qijing Yao's avatar Qijing Yao
Browse files

Prevent unnecessary animation when dragging window within same display

The commit addresses an issue in MultiDisplayVeiledResizeTaskPositioner
where dragging a window within the same display could trigger an
unnecessary animation due to minor changes in width or height caused by
DPI scaling.

The fix involves checking if the drag operation occurs within the same
display. If it does, the logic falls back to the single-display drag
behavior, where we only updates the window left and top coordinates.

See details in b/390370556#comment2

Bug: 390370556
Test: Manual
Flag: com.android.window.flags.enable_connected_displays_window_drag
Change-Id: I6797e115361577955443ae0492c1b72dd1519de1
parent f02aead5
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -237,8 +237,12 @@ class MultiDisplayVeiledResizeTaskPositioner(
            val startDisplayLayout = displayController.getDisplayLayout(startDisplayId)
            val currentDisplayLayout = displayController.getDisplayLayout(displayId)

            if (startDisplayLayout == null || currentDisplayLayout == null) {
                // Fall back to single-display drag behavior if any display layout is unavailable.
            if (startDisplayId == displayId
                || startDisplayLayout == null || currentDisplayLayout == null) {
                // Fall back to single-display drag behavior if:
                // 1. The drag destination display is the same as the start display. This prevents
                // unnecessary animations caused by minor width/height changes due to DPI scaling.
                // 2. Either the starting or current display layout is unavailable.
                DragPositioningCallbackUtility.updateTaskBounds(
                    repositionTaskBounds,
                    taskBoundsAtDragStart,
+19 −0
Original line number Diff line number Diff line
@@ -248,6 +248,25 @@ class MultiDisplayVeiledResizeTaskPositionerTest : ShellTestCase() {
        Assert.assertEquals(rectAfterEnd, endBounds)
    }

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

        taskPositioner.onDragPositioningEnd(
            DISPLAY_ID_0,
            STARTING_BOUNDS.left.toFloat() + 70,
            STARTING_BOUNDS.top.toFloat() + 20,
        )

        verify(spyDisplayLayout0, never()).localPxToGlobalDp(any(), any())
        verify(spyDisplayLayout0, never()).globalDpToLocalPx(any(), any())
    }

    @Test
    fun testDragResize_movesTaskToNewDisplay() = runOnUiThread {
        taskPositioner.onDragPositioningStart(