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

Commit 32618b0b authored by Yuichiro Hanada's avatar Yuichiro Hanada
Browse files

Return the default snap bounds if there is no active desk

DesktopTilingDecorViewModel.get{Right,Left}SnapBoundsIfTiled can be
called when a window drag starts from fullscreen.
It should return the default snap bounds rather than an empty bounds.

Bug: 421068243
Test: manual - follow the step in the bug
Test: atest WMShellUnitTests
Flag: EXEMPT small bug fix
Change-Id: I3edff93694bc752f376724d50b102a5a02dbae59
parent 0b4e1d2f
Loading
Loading
Loading
Loading
+8 −28
Original line number Diff line number Diff line
@@ -215,19 +215,6 @@ class DesktopTilingDecorViewModel(
    }

    fun getRightSnapBoundsIfTiled(displayId: Int): Rect {
        val deskId = getCurrentActiveDeskForDisplay(displayId)
        if (deskId == null) {
            logW(
                "Attempted to get right tiling snap bounds with no active desktop for displayId=%d.",
                displayId,
            )
            return Rect()
        }
        val tilingBounds =
            tilingHandlerByUserAndDeskId[currentUserId]?.get(deskId)?.getRightSnapBoundsIfTiled()
        if (tilingBounds != null) {
            return tilingBounds
        }
        val displayLayout = displayController.getDisplayLayout(displayId)
        val stableBounds = Rect()
        displayLayout?.getStableBounds(stableBounds)
@@ -240,23 +227,13 @@ class DesktopTilingDecorViewModel(
                stableBounds.right,
                stableBounds.bottom,
            )
        return snapBounds

        val deskId = getCurrentActiveDeskForDisplay(displayId) ?: return snapBounds
        val tilingHandler = tilingHandlerByUserAndDeskId[currentUserId]?.get(deskId)
        return tilingHandler?.getRightSnapBoundsIfTiled() ?: snapBounds
    }

    fun getLeftSnapBoundsIfTiled(displayId: Int): Rect {
        val deskId = getCurrentActiveDeskForDisplay(displayId)
        if (deskId == null) {
            logW(
                "Attempted to get left tiling snap bounds with no active desktop for displayId=%d.",
                displayId,
            )
            return Rect()
        }
        val tilingBounds =
            tilingHandlerByUserAndDeskId[currentUserId]?.get(deskId)?.getLeftSnapBoundsIfTiled()
        if (tilingBounds != null) {
            return tilingBounds
        }
        val displayLayout = displayController.getDisplayLayout(displayId)
        val stableBounds = Rect()
        displayLayout?.getStableBounds(stableBounds)
@@ -268,7 +245,10 @@ class DesktopTilingDecorViewModel(
                    context.resources.getDimensionPixelSize(R.dimen.split_divider_bar_width) / 2,
                stableBounds.bottom,
            )
        return snapBounds

        val deskId = getCurrentActiveDeskForDisplay(displayId) ?: return snapBounds
        val tilingHandler = tilingHandlerByUserAndDeskId[currentUserId]?.get(deskId)
        return tilingHandler?.getLeftSnapBoundsIfTiled() ?: snapBounds
    }

    /** Notifies tiling of a desk being deactivated. */
+9 −0
Original line number Diff line number Diff line
@@ -400,6 +400,15 @@ class DesktopTilingDecorViewModelTest : ShellTestCase() {
            .isEqualTo(Rect(12, 7, 8, 9))
    }

    @Test
    fun getTiledAppBounds_NoActiveDesk() {
        whenever(desktopRepository.getActiveDeskId(any())).thenReturn(null)
        assertThat(desktopTilingDecorViewModel.getLeftSnapBoundsIfTiled(2))
            .isEqualTo(Rect(6, 7, 2, 9))
        assertThat(desktopTilingDecorViewModel.getRightSnapBoundsIfTiled(2))
            .isEqualTo(Rect(12, 7, 8, 9))
    }

    companion object {
        private val BOUNDS = Rect(1, 2, 3, 4)
        private val STABLE_BOUNDS = Rect(6, 7, 8, 9)