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

Commit 15b8613a authored by Chris Li's avatar Chris Li
Browse files

Use the window surface position in parent's coordinate for InsetsSource

Window frames is based on the display coordinate, but the surface
position should be based on the surface parent's coordinate.

On single display device, the parent is at (0,0) for most case, so it
doesn't cause any issue. However, on multi-display device, the system
and IME window can be placed in a DisplayArea that is not at (0,0).

Bug: 156355859
Test: manual: open IME on single and dual display device.
Change-Id: I42de9b8a12db56b2a9e0c2de0c1e1d7c5d0f25ba
parent dc2fe53e
Loading
Loading
Loading
Loading
+22 −15
Original line number Original line Diff line number Diff line
@@ -244,12 +244,12 @@ class InsetsSourceProvider {
        setServerVisible(mWin.wouldBeVisibleIfPolicyIgnored() && mWin.isVisibleByPolicy());
        setServerVisible(mWin.wouldBeVisibleIfPolicyIgnored() && mWin.isVisibleByPolicy());
        updateSourceFrame();
        updateSourceFrame();
        if (mControl != null) {
        if (mControl != null) {
            final Rect frame = mWin.getWindowFrames().mFrame;
            final Point position = getWindowFrameSurfacePosition();
            if (mControl.setSurfacePosition(frame.left, frame.top) && mControlTarget != null) {
            if (mControl.setSurfacePosition(position.x, position.y) && mControlTarget != null) {
                if (!mWin.getWindowFrames().didFrameSizeChange()) {
                if (!mWin.getWindowFrames().didFrameSizeChange()) {
                    updateLeashPosition(frame, -1 /* frameNumber */);
                    updateLeashPosition(-1 /* frameNumber */);
                } else if (mWin.mInRelayout) {
                } else if (mWin.mInRelayout) {
                    updateLeashPosition(frame, mWin.getFrameNumber());
                    updateLeashPosition(mWin.getFrameNumber());
                } else {
                } else {
                    mWin.mPendingPositionChanged = this;
                    mWin.mPendingPositionChanged = this;
                }
                }
@@ -258,20 +258,26 @@ class InsetsSourceProvider {
        }
        }
    }
    }


    void updateLeashPosition(Rect frame, long frameNumber) {
    void updateLeashPosition(long frameNumber) {
        if (mControl == null) {
        if (mControl == null) {
            return;
            return;
        }
        }
        final SurfaceControl leash = mControl.getLeash();
        final SurfaceControl leash = mControl.getLeash();
        if (leash != null) {
        if (leash != null) {
            final Transaction t = mDisplayContent.getPendingTransaction();
            final Transaction t = mDisplayContent.getPendingTransaction();
            Point position = new Point();
            final Point position = mControl.getSurfacePosition();
            mWin.transformFrameToSurfacePosition(frame.left, frame.top, position);
            t.setPosition(leash, position.x, position.y);
            t.setPosition(leash, position.x, position.y);
            deferTransactionUntil(t, leash, frameNumber);
            deferTransactionUntil(t, leash, frameNumber);
        }
        }
    }
    }


    private Point getWindowFrameSurfacePosition() {
        final Rect frame = mWin.getFrame();
        final Point position = new Point();
        mWin.transformFrameToSurfacePosition(frame.left, frame.top, position);
        return position;
    }

    private void deferTransactionUntil(Transaction t, SurfaceControl leash, long frameNumber) {
    private void deferTransactionUntil(Transaction t, SurfaceControl leash, long frameNumber) {
        if (frameNumber >= 0) {
        if (frameNumber >= 0) {
            final SurfaceControl barrier = mWin.getClientViewRootSurface();
            final SurfaceControl barrier = mWin.getClientViewRootSurface();
@@ -319,7 +325,8 @@ class InsetsSourceProvider {
            setClientVisible(InsetsState.getDefaultVisibility(mSource.getType()));
            setClientVisible(InsetsState.getDefaultVisibility(mSource.getType()));
            return;
            return;
        }
        }
        mAdapter = new ControlAdapter();
        final Point surfacePosition = getWindowFrameSurfacePosition();
        mAdapter = new ControlAdapter(surfacePosition);
        if (getSource().getType() == ITYPE_IME) {
        if (getSource().getType() == ITYPE_IME) {
            setClientVisible(InsetsState.getDefaultVisibility(mSource.getType()));
            setClientVisible(InsetsState.getDefaultVisibility(mSource.getType()));
        }
        }
@@ -343,8 +350,7 @@ class InsetsSourceProvider {
        }
        }
        mControlTarget = target;
        mControlTarget = target;
        updateVisibility();
        updateVisibility();
        mControl = new InsetsSourceControl(mSource.getType(), leash,
        mControl = new InsetsSourceControl(mSource.getType(), leash, surfacePosition);
                new Point(mWin.getWindowFrames().mFrame.left, mWin.getWindowFrames().mFrame.top));
        ProtoLog.d(WM_DEBUG_IME,
        ProtoLog.d(WM_DEBUG_IME,
                "InsetsSource Control %s for target %s", mControl, mControlTarget);
                "InsetsSource Control %s for target %s", mControl, mControlTarget);
    }
    }
@@ -527,8 +533,13 @@ class InsetsSourceProvider {


    private class ControlAdapter implements AnimationAdapter {
    private class ControlAdapter implements AnimationAdapter {


        private final Point mSurfacePosition;
        private SurfaceControl mCapturedLeash;
        private SurfaceControl mCapturedLeash;


        ControlAdapter(Point surfacePosition) {
            mSurfacePosition = surfacePosition;
        }

        @Override
        @Override
        public boolean getShowWallpaper() {
        public boolean getShowWallpaper() {
            return false;
            return false;
@@ -549,11 +560,7 @@ class InsetsSourceProvider {
                    mControlTarget);
                    mControlTarget);


            mCapturedLeash = animationLeash;
            mCapturedLeash = animationLeash;
            final Rect frame = mWin.getWindowFrames().mFrame;
            t.setPosition(mCapturedLeash, mSurfacePosition.x, mSurfacePosition.y);
            Point position = new Point();
            mWin.transformFrameToSurfacePosition(frame.left, frame.top, position);

            t.setPosition(mCapturedLeash, position.x, position.y);
        }
        }


        @Override
        @Override
+1 −1
Original line number Original line Diff line number Diff line
@@ -2195,7 +2195,7 @@ public class WindowManagerService extends IWindowManager.Stub
            }
            }


            if (win.mPendingPositionChanged != null) {
            if (win.mPendingPositionChanged != null) {
                win.mPendingPositionChanged.updateLeashPosition(win.getFrame(), frameNumber);
                win.mPendingPositionChanged.updateLeashPosition(frameNumber);
                win.mPendingPositionChanged = null;
                win.mPendingPositionChanged = null;
            }
            }