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

Commit e612008c authored by Graciela Wissen Putri's avatar Graciela Wissen Putri
Browse files

Reset cascading position to center if snapped to left/right

Check for bottom and top points of window to ensure window snapped to
left/right doesn't return TopLeft/TopRight cascading position, but
return to default cascading position instead.

Flag: com.android.window.flags.enable_cascading_windows
Fix: 357673974
Test: atest DesktopTasksControllerTest
Change-Id: Ie981a8733748c987caae63f0b4e553cca78dd1f5
parent 0d20e8d9
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -116,10 +116,10 @@ fun canChangeTaskPosition(taskInfo: TaskInfo): Boolean {
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
fun Rect.getDesktopTaskPosition(bounds: Rect): DesktopTaskPosition {
    return when {
        top == bounds.top && left == bounds.left -> TopLeft
        top == bounds.top && right == bounds.right -> TopRight
        bottom == bounds.bottom && left == bounds.left -> BottomLeft
        bottom == bounds.bottom && right == bounds.right -> BottomRight
        top == bounds.top && left == bounds.left && bottom != bounds.bottom -> TopLeft
        top == bounds.top && right == bounds.right && bottom != bounds.bottom -> TopRight
        bottom == bounds.bottom && left == bounds.left && top != bounds.top -> BottomLeft
        bottom == bounds.bottom && right == bounds.right && top != bounds.top -> BottomRight
        else -> Center
    }
}
+58 −0
Original line number Diff line number Diff line
@@ -729,6 +729,64 @@ class DesktopTasksControllerTest : ShellTestCase() {
      .isEqualTo(DesktopTaskPosition.Center)
  }

  @Test
  @EnableFlags(Flags.FLAG_ENABLE_CASCADING_WINDOWS)
  fun addMoveToDesktopChanges_lastWindowSnapLeft_positionResetsToCenter() {
    setUpLandscapeDisplay()
    val stableBounds = Rect()
    displayLayout.getStableBoundsForDesktopMode(stableBounds)

    // Add freeform task with half display size snap bounds at left side.
    setUpFreeformTask(bounds = Rect(stableBounds.left, stableBounds.top, 500, stableBounds.bottom))

    val task = setUpFullscreenTask()
    val wct = WindowContainerTransaction()
    controller.addMoveToDesktopChanges(wct, task)

    val finalBounds = findBoundsChange(wct, task)
    assertThat(stableBounds.getDesktopTaskPosition(finalBounds!!))
      .isEqualTo(DesktopTaskPosition.Center)
  }

  @Test
  @EnableFlags(Flags.FLAG_ENABLE_CASCADING_WINDOWS)
  fun addMoveToDesktopChanges_lastWindowSnapRight_positionResetsToCenter() {
    setUpLandscapeDisplay()
    val stableBounds = Rect()
    displayLayout.getStableBoundsForDesktopMode(stableBounds)

    // Add freeform task with half display size snap bounds at right side.
    setUpFreeformTask(bounds = Rect(
      stableBounds.right - 500, stableBounds.top, stableBounds.right, stableBounds.bottom))

    val task = setUpFullscreenTask()
    val wct = WindowContainerTransaction()
    controller.addMoveToDesktopChanges(wct, task)

    val finalBounds = findBoundsChange(wct, task)
    assertThat(stableBounds.getDesktopTaskPosition(finalBounds!!))
      .isEqualTo(DesktopTaskPosition.Center)
  }

  @Test
  @EnableFlags(Flags.FLAG_ENABLE_CASCADING_WINDOWS)
  fun addMoveToDesktopChanges_lastWindowMaximised_positionResetsToCenter() {
    setUpLandscapeDisplay()
    val stableBounds = Rect()
    displayLayout.getStableBoundsForDesktopMode(stableBounds)

    // Add maximised freeform task.
    setUpFreeformTask(bounds = Rect(stableBounds))

    val task = setUpFullscreenTask()
    val wct = WindowContainerTransaction()
    controller.addMoveToDesktopChanges(wct, task)

    val finalBounds = findBoundsChange(wct, task)
    assertThat(stableBounds.getDesktopTaskPosition(finalBounds!!))
      .isEqualTo(DesktopTaskPosition.Center)
  }

  @Test
  @EnableFlags(Flags.FLAG_ENABLE_CASCADING_WINDOWS)
  fun addMoveToDesktopChanges_defaultToCenterIfFree() {