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

Commit 7a772305 authored by Mady Mellor's avatar Mady Mellor
Browse files

Fix hit targets, hopefully once and for all

When already in split screen we use the stage bounds from split screen
controller, however, these bounds really represent the draw region and
would be inset by taskbar etc. For the hit targets we really want the
whole side of the screen from the middle of the divider, rather than
the draw region.

This CL updates it so that the hit region is based of the display region
divided wherever the divider is.

Test: manual - have apps in split, drag a new one into split and observe
               that the animation is smooth
Bug: 207011867
Change-Id: I7142755febd7fe2f6c2db4cee2e08fa2f43c3b7f
parent fd015869
Loading
Loading
Loading
Loading
+20 −18
Original line number Diff line number Diff line
@@ -150,43 +150,45 @@ public class DragAndDropPolicy {

            if (inLandscape) {
                final Rect leftHitRegion = new Rect();
                final Rect leftDrawRegion = topOrLeftBounds;
                final Rect rightHitRegion = new Rect();
                final Rect rightDrawRegion = bottomOrRightBounds;

                // If we have existing split regions use those bounds, otherwise split it 50/50
                if (inSplitScreen) {
                    // Add the divider bounds to each side since that counts for the hit region.
                    leftHitRegion.set(topOrLeftBounds);
                    leftHitRegion.right += dividerWidth / 2;
                    rightHitRegion.set(bottomOrRightBounds);
                    rightHitRegion.left -= dividerWidth / 2;
                    // The bounds of the existing split will have a divider bar, the hit region
                    // should include that space. Find the center of the divider bar:
                    float centerX = topOrLeftBounds.right + (dividerWidth / 2);
                    // Now set the hit regions using that center.
                    leftHitRegion.set(displayRegion);
                    leftHitRegion.right = (int) centerX;
                    rightHitRegion.set(displayRegion);
                    rightHitRegion.left = (int) centerX;
                } else {
                    displayRegion.splitVertically(leftHitRegion, rightHitRegion);
                }

                mTargets.add(new Target(TYPE_SPLIT_LEFT, leftHitRegion, leftDrawRegion));
                mTargets.add(new Target(TYPE_SPLIT_RIGHT, rightHitRegion, rightDrawRegion));
                mTargets.add(new Target(TYPE_SPLIT_LEFT, leftHitRegion, topOrLeftBounds));
                mTargets.add(new Target(TYPE_SPLIT_RIGHT, rightHitRegion, bottomOrRightBounds));

            } else {
                final Rect topHitRegion = new Rect();
                final Rect topDrawRegion = topOrLeftBounds;
                final Rect bottomHitRegion = new Rect();
                final Rect bottomDrawRegion = bottomOrRightBounds;

                // If we have existing split regions use those bounds, otherwise split it 50/50
                if (inSplitScreen) {
                    // Add the divider bounds to each side since that counts for the hit region.
                    topHitRegion.set(topOrLeftBounds);
                    topHitRegion.bottom += dividerWidth / 2;
                    bottomHitRegion.set(bottomOrRightBounds);
                    bottomHitRegion.top -= dividerWidth / 2;
                    // The bounds of the existing split will have a divider bar, the hit region
                    // should include that space. Find the center of the divider bar:
                    float centerX = topOrLeftBounds.bottom + (dividerWidth / 2);
                    // Now set the hit regions using that center.
                    topHitRegion.set(displayRegion);
                    topHitRegion.bottom = (int) centerX;
                    bottomHitRegion.set(displayRegion);
                    bottomHitRegion.top = (int) centerX;
                } else {
                    displayRegion.splitHorizontally(topHitRegion, bottomHitRegion);
                }

                mTargets.add(new Target(TYPE_SPLIT_TOP, topHitRegion, topDrawRegion));
                mTargets.add(new Target(TYPE_SPLIT_BOTTOM, bottomHitRegion, bottomDrawRegion));
                mTargets.add(new Target(TYPE_SPLIT_TOP, topHitRegion, topOrLeftBounds));
                mTargets.add(new Target(TYPE_SPLIT_BOTTOM, bottomHitRegion, bottomOrRightBounds));
            }
        } else {
            // Split-screen not allowed, so only show the fullscreen target