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

Commit ba761124 authored by Vladislav Kaznacheev's avatar Vladislav Kaznacheev
Browse files

Change mouse pointer when drag and drop is active

Mouse pointer is set to STYLE_GRAB when the drag has started and
reset to STYLE_DEFAULT when the drag has ended.

Resetting the pointer shape to the one defined by an underlying
view will be handled in a separate patch.

Bug: 24415739
Change-Id: I8df0a08c5701a34a48f10ec6b43c2cf2e6362d61
parent 1f0945e9
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -186,8 +186,8 @@ interface IWindowSession {
    /**
     * Initiate the drag operation itself
     */
    boolean performDrag(IWindow window, IBinder dragToken, float touchX, float touchY,
            float thumbCenterX, float thumbCenterY, in ClipData data);
    boolean performDrag(IWindow window, IBinder dragToken, int touchSource,
            float touchX, float touchY, float thumbCenterX, float thumbCenterY, in ClipData data);

   /**
     * Report the result of a drop action targeted to the given window.
+1 −1
Original line number Diff line number Diff line
@@ -19996,7 +19996,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                root.getLastTouchPoint(shadowSize);
                okay = mAttachInfo.mSession.performDrag(mAttachInfo.mWindow, mAttachInfo.mDragToken,
                        shadowSize.x, shadowSize.y,
                        root.getLastTouchSource(), shadowSize.x, shadowSize.y,
                        shadowTouchPoint.x, shadowTouchPoint.y, data);
                if (ViewDebug.DEBUG_DRAG) Log.d(VIEW_LOG_TAG, "performDrag returned " + okay);
            }
+6 −0
Original line number Diff line number Diff line
@@ -339,6 +339,7 @@ public final class ViewRootImpl implements ViewParent,
    volatile Object mLocalDragState;
    final PointF mDragPoint = new PointF();
    final PointF mLastTouchPoint = new PointF();
    int mLastTouchSource;

    private boolean mProfileRendering;
    private Choreographer.FrameCallback mRenderProfiler;
@@ -4124,6 +4125,7 @@ public final class ViewRootImpl implements ViewParent,
            if (event.isTouchEvent()) {
                mLastTouchPoint.x = event.getRawX();
                mLastTouchPoint.y = event.getRawY();
                mLastTouchSource = event.getSource();
            }
            return FORWARD;
        }
@@ -5477,6 +5479,10 @@ public final class ViewRootImpl implements ViewParent,
        outLocation.y = (int) mLastTouchPoint.y;
    }

    public int getLastTouchSource() {
        return mLastTouchSource;
    }

    public void setDragFocus(View newDragTarget) {
        if (mCurrentDragView != newDragTarget) {
            mCurrentDragView = newDragTarget;
+22 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.graphics.Matrix;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Region;
import android.hardware.input.InputManager;
import android.os.IBinder;
import android.os.Message;
import android.os.Process;
@@ -36,6 +37,8 @@ import android.util.Slog;
import android.view.Display;
import android.view.DragEvent;
import android.view.InputChannel;
import android.view.InputDevice;
import android.view.PointerIcon;
import android.view.SurfaceControl;
import android.view.View;
import android.view.WindowManager;
@@ -72,6 +75,7 @@ class DragState {
    int mUid;
    ClipData mData;
    ClipDescription mDataDescription;
    int mTouchSource;
    boolean mDragResult;
    float mOriginalAlpha;
    float mOriginalX, mOriginalY;
@@ -342,6 +346,7 @@ class DragState {

    private void cleanUpDragLw() {
        broadcastDragEndedLw();
        restorePointerIconLw();

        // stop intercepting input
        unregister();
@@ -573,4 +578,21 @@ class DragState {
        set.start();  // Will start on the first call to getTransformation.
        return set;
    }

    private boolean isFromSource(int source) {
        return (mTouchSource & source) == source;
    }

    void overridePointerIconLw(int touchSource) {
        mTouchSource = touchSource;
        if (isFromSource(InputDevice.SOURCE_MOUSE)) {
            InputManager.getInstance().setPointerIconShape(PointerIcon.STYLE_GRAB);
        }
    }

    private void restorePointerIconLw() {
        if (isFromSource(InputDevice.SOURCE_MOUSE)) {
            InputManager.getInstance().setPointerIconShape(PointerIcon.STYLE_DEFAULT);
        }
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -283,7 +283,7 @@ final class Session extends IWindowSession.Stub
    }

    public boolean performDrag(IWindow window, IBinder dragToken,
            float touchX, float touchY, float thumbCenterX, float thumbCenterY,
            int touchSource, float touchX, float touchY, float thumbCenterX, float thumbCenterY,
            ClipData data) {
        if (DEBUG_DRAG) {
            Slog.d(TAG_WM, "perform drag: win=" + window + " data=" + data);
@@ -336,6 +336,7 @@ final class Session extends IWindowSession.Stub

            mService.mDragState.mData = data;
            mService.mDragState.broadcastDragStartedLw(touchX, touchY);
            mService.mDragState.overridePointerIconLw(touchSource);

            // remember the thumb offsets for later
            mService.mDragState.mThumbOffsetX = thumbCenterX;
Loading