diff options
| author | 2024-10-31 20:28:04 +0000 | |
|---|---|---|
| committer | 2024-10-31 20:28:04 +0000 | |
| commit | 69ce428622a200674527dabbb2d0e40ff0eaa0c9 (patch) | |
| tree | 030396bd868579758ee0a18302f724d09fd9b55e | |
| parent | 90a82be1f6f17575e56625a7c39caf09169dee59 (diff) | |
| parent | a2cc1612bc13490208528fd0def5c2ee47a84af1 (diff) | |
Merge "[13/n] Enable drawing rounded corners for tiling." into main
4 files changed, 54 insertions, 6 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDividerWindowManager.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDividerWindowManager.kt index 9bf1304f2b39..209eb5e501b2 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDividerWindowManager.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDividerWindowManager.kt @@ -23,6 +23,7 @@ import android.graphics.Rect import android.graphics.Region import android.os.Binder import android.view.LayoutInflater +import android.view.RoundedCorner import android.view.SurfaceControl import android.view.SurfaceControlViewHost import android.view.View @@ -53,12 +54,14 @@ class DesktopTilingDividerWindowManager( private val transitionHandler: DesktopTilingWindowDecoration, private val transactionSupplier: Supplier<SurfaceControl.Transaction>, private var dividerBounds: Rect, + private val displayContext: Context, ) : WindowlessWindowManager(config, leash, null), DividerMoveCallback, View.OnLayoutChangeListener { private lateinit var viewHost: SurfaceControlViewHost private var tilingDividerView: TilingDividerView? = null private var dividerShown = false private var handleRegionWidth: Int = -1 private var setTouchRegion = true + private val maxRoundedCornerRadius = getMaxRoundedCornerRadius() /** * Gets bounds of divider window with screen based coordinate on the param Rect. @@ -93,7 +96,11 @@ class DesktopTilingDividerWindowManager( getDividerBounds(tmpDividerBounds) dividerView.setup(this, tmpDividerBounds) t.setRelativeLayer(leash, relativeLeash, 1) - .setPosition(leash, dividerBounds.left.toFloat(), dividerBounds.top.toFloat()) + .setPosition( + leash, + dividerBounds.left.toFloat() - maxRoundedCornerRadius, + dividerBounds.top.toFloat(), + ) .show(leash) syncQueue.runInSync { transaction -> transaction.merge(t) @@ -144,7 +151,7 @@ class DesktopTilingDividerWindowManager( */ override fun onDividerMove(pos: Int): Boolean { val t = transactionSupplier.get() - t.setPosition(leash, pos.toFloat(), dividerBounds.top.toFloat()) + t.setPosition(leash, pos.toFloat() - maxRoundedCornerRadius, dividerBounds.top.toFloat()) val dividerWidth = dividerBounds.width() dividerBounds.set(pos, dividerBounds.top, pos + dividerWidth, dividerBounds.bottom) return transitionHandler.onDividerHandleMoved(dividerBounds, t) @@ -157,7 +164,7 @@ class DesktopTilingDividerWindowManager( override fun onDividerMovedEnd(pos: Int) { setSlippery(true) val t = transactionSupplier.get() - t.setPosition(leash, pos.toFloat(), dividerBounds.top.toFloat()) + t.setPosition(leash, pos.toFloat() - maxRoundedCornerRadius, dividerBounds.top.toFloat()) val dividerWidth = dividerBounds.width() dividerBounds.set(pos, dividerBounds.top, pos + dividerWidth, dividerBounds.bottom) transitionHandler.onDividerHandleDragEnd(dividerBounds, t) @@ -166,7 +173,7 @@ class DesktopTilingDividerWindowManager( private fun getWindowManagerParams(): WindowManager.LayoutParams { val lp = WindowManager.LayoutParams( - dividerBounds.width(), + dividerBounds.width() + 2 * maxRoundedCornerRadius, dividerBounds.height(), TYPE_DOCK_DIVIDER, FLAG_NOT_FOCUSABLE or @@ -225,4 +232,15 @@ class DesktopTilingDividerWindowManager( } viewHost.relayout(lp) } + + private fun getMaxRoundedCornerRadius(): Int { + val display = displayContext.display + return listOf( + RoundedCorner.POSITION_TOP_LEFT, + RoundedCorner.POSITION_TOP_RIGHT, + RoundedCorner.POSITION_BOTTOM_RIGHT, + RoundedCorner.POSITION_BOTTOM_LEFT, + ) + .maxOf { position -> display.getRoundedCorner(position)?.getRadius() ?: 0 } + } } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingWindowDecoration.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingWindowDecoration.kt index 27d55ea1b412..c46767c3a51d 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingWindowDecoration.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingWindowDecoration.kt @@ -195,6 +195,7 @@ class DesktopTilingWindowDecoration( val builder = SurfaceControl.Builder() rootTdaOrganizer.attachToDisplayArea(displayId, builder) val leash = builder.setName(TILING_DIVIDER_TAG).setContainerLayer().build() + val displayContext = displayController.getDisplayContext(displayId) ?: return null val tilingManager = displayLayout?.let { dividerBounds = inflateDividerBounds(it) @@ -207,6 +208,7 @@ class DesktopTilingWindowDecoration( this, transactionSupplier, dividerBounds, + displayContext, ) } // a leash to present the divider on top of, without re-parenting. diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/TilingDividerView.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/TilingDividerView.kt index f8113c219bd1..89229051941c 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/TilingDividerView.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/tiling/TilingDividerView.kt @@ -118,7 +118,7 @@ class TilingDividerView : FrameLayout, View.OnTouchListener, DragDetector.Motion val dividerSize = resources.getDimensionPixelSize(R.dimen.split_divider_bar_width) val backgroundLeft = (width - dividerSize) / 2 val backgroundTop = 0 - val backgroundRight = left + dividerSize + val backgroundRight = backgroundLeft + dividerSize val backgroundBottom = height backgroundRect.set(backgroundLeft, backgroundTop, backgroundRight, backgroundBottom) } diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDividerWindowManagerTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDividerWindowManagerTest.kt index 0ee3f4695e85..3143946fa828 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDividerWindowManagerTest.kt +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/tiling/DesktopTilingDividerWindowManagerTest.kt @@ -16,9 +16,12 @@ package com.android.wm.shell.windowdecor.tiling +import android.content.Context import android.content.res.Configuration import android.graphics.Rect import android.testing.AndroidTestingRunner +import android.view.Display +import android.view.RoundedCorner import android.view.SurfaceControl import androidx.test.annotation.UiThreadTest import androidx.test.filters.SmallTest @@ -29,6 +32,7 @@ import kotlin.test.Test import org.junit.Before import org.junit.runner.RunWith import org.mockito.kotlin.any +import org.mockito.kotlin.eq import org.mockito.kotlin.mock import org.mockito.kotlin.times import org.mockito.kotlin.verify @@ -55,10 +59,17 @@ class DesktopTilingDividerWindowManagerTest : ShellTestCase() { private lateinit var desktopTilingWindowManager: DesktopTilingDividerWindowManager + private val context = mock<Context>() + private val display = mock<Display>() + private val roundedCorner = mock<RoundedCorner>() + @Before fun setup() { config = Configuration() config.setToDefaults() + whenever(context.display).thenReturn(display) + whenever(display.getRoundedCorner(any())).thenReturn(roundedCorner) + whenever(roundedCorner.radius).thenReturn(CORNER_RADIUS) desktopTilingWindowManager = DesktopTilingDividerWindowManager( config, @@ -69,6 +80,7 @@ class DesktopTilingDividerWindowManagerTest : ShellTestCase() { transitionHandlerMock, transactionSupplierMock, BOUNDS, + context, ) } @@ -85,7 +97,6 @@ class DesktopTilingDividerWindowManagerTest : ShellTestCase() { // Ensure a surfaceControl transaction runs to show the divider. verify(transactionSupplierMock, times(1)).get() - verify(syncQueueMock, times(1)).runInSync(any()) desktopTilingWindowManager.release() verify(transaction, times(1)).hide(any()) @@ -93,7 +104,24 @@ class DesktopTilingDividerWindowManagerTest : ShellTestCase() { verify(transaction, times(1)).apply() } + @Test + @UiThreadTest + fun testWindowManager_accountsForRoundedCornerDimensions() { + whenever(transactionSupplierMock.get()).thenReturn(transaction) + whenever(transaction.setRelativeLayer(any(), any(), any())).thenReturn(transaction) + whenever(transaction.setRelativeLayer(any(), any(), any())).thenReturn(transaction) + whenever(transaction.setPosition(any(), any(), any())).thenReturn(transaction) + whenever(transaction.show(any())).thenReturn(transaction) + + desktopTilingWindowManager.generateViewHost(surfaceControl) + + // Ensure a surfaceControl transaction runs to show the divider. + verify(transaction, times(1)) + .setPosition(any(), eq(BOUNDS.left.toFloat() - CORNER_RADIUS), any()) + } + companion object { private val BOUNDS = Rect(1, 2, 3, 4) + private val CORNER_RADIUS = 28 } } |