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 Diff line number Diff line
@@ -244,12 +244,12 @@ class InsetsSourceProvider {
        setServerVisible(mWin.wouldBeVisibleIfPolicyIgnored() && mWin.isVisibleByPolicy());
        updateSourceFrame();
        if (mControl != null) {
            final Rect frame = mWin.getWindowFrames().mFrame;
            if (mControl.setSurfacePosition(frame.left, frame.top) && mControlTarget != null) {
            final Point position = getWindowFrameSurfacePosition();
            if (mControl.setSurfacePosition(position.x, position.y) && mControlTarget != null) {
                if (!mWin.getWindowFrames().didFrameSizeChange()) {
                    updateLeashPosition(frame, -1 /* frameNumber */);
                    updateLeashPosition(-1 /* frameNumber */);
                } else if (mWin.mInRelayout) {
                    updateLeashPosition(frame, mWin.getFrameNumber());
                    updateLeashPosition(mWin.getFrameNumber());
                } else {
                    mWin.mPendingPositionChanged = this;
                }
@@ -258,20 +258,26 @@ class InsetsSourceProvider {
        }
    }

    void updateLeashPosition(Rect frame, long frameNumber) {
    void updateLeashPosition(long frameNumber) {
        if (mControl == null) {
            return;
        }
        final SurfaceControl leash = mControl.getLeash();
        if (leash != null) {
            final Transaction t = mDisplayContent.getPendingTransaction();
            Point position = new Point();
            mWin.transformFrameToSurfacePosition(frame.left, frame.top, position);
            final Point position = mControl.getSurfacePosition();
            t.setPosition(leash, position.x, position.y);
            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) {
        if (frameNumber >= 0) {
            final SurfaceControl barrier = mWin.getClientViewRootSurface();
@@ -319,7 +325,8 @@ class InsetsSourceProvider {
            setClientVisible(InsetsState.getDefaultVisibility(mSource.getType()));
            return;
        }
        mAdapter = new ControlAdapter();
        final Point surfacePosition = getWindowFrameSurfacePosition();
        mAdapter = new ControlAdapter(surfacePosition);
        if (getSource().getType() == ITYPE_IME) {
            setClientVisible(InsetsState.getDefaultVisibility(mSource.getType()));
        }
@@ -343,8 +350,7 @@ class InsetsSourceProvider {
        }
        mControlTarget = target;
        updateVisibility();
        mControl = new InsetsSourceControl(mSource.getType(), leash,
                new Point(mWin.getWindowFrames().mFrame.left, mWin.getWindowFrames().mFrame.top));
        mControl = new InsetsSourceControl(mSource.getType(), leash, surfacePosition);
        ProtoLog.d(WM_DEBUG_IME,
                "InsetsSource Control %s for target %s", mControl, mControlTarget);
    }
@@ -527,8 +533,13 @@ class InsetsSourceProvider {

    private class ControlAdapter implements AnimationAdapter {

        private final Point mSurfacePosition;
        private SurfaceControl mCapturedLeash;

        ControlAdapter(Point surfacePosition) {
            mSurfacePosition = surfacePosition;
        }

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

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

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

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

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