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

Commit 0710621b authored by Prabir Pradhan's avatar Prabir Pradhan Committed by Android (Google) Code Review
Browse files

Merge changes from topics "styluspointericon-config", "styluspointericon-presentation"

* changes:
  Add testcase for StylusPointer
  check config for showing a stylus pointer (native part)
  Separate default pointer for mouse and stylus (native part)
  [scribe] show stylus hover icon
parents 2652cc1b 356026cf
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1113,6 +1113,7 @@ public:
enum class PointerIconStyle : int32_t {
    TYPE_CUSTOM = -1,
    TYPE_NULL = 0,
    TYPE_NOT_SPECIFIED = 1,
    TYPE_ARROW = 1000,
    TYPE_CONTEXT_MENU = 1001,
    TYPE_HAND = 1002,
+5 −1
Original line number Diff line number Diff line
@@ -333,6 +333,9 @@ struct InputReaderConfiguration {
    // stylus button state changes are reported through motion events.
    bool stylusButtonMotionEventsEnabled;

    // True if a pointer icon should be shown for direct stylus pointers.
    bool stylusPointerIconEnabled;

    InputReaderConfiguration()
          : virtualKeyQuietTime(0),
            pointerVelocityControlParameters(1.0f, 500.0f, 3000.0f,
@@ -358,7 +361,8 @@ struct InputReaderConfiguration {
            touchpadNaturalScrollingEnabled(true),
            touchpadTapToClickEnabled(true),
            touchpadRightClickZoneEnabled(false),
            stylusButtonMotionEventsEnabled(true) {}
            stylusButtonMotionEventsEnabled(true),
            stylusPointerIconEnabled(false) {}

    static std::string changesToString(uint32_t changes);

+3 −1
Original line number Diff line number Diff line
@@ -79,8 +79,10 @@ public:
        POINTER,
        // Show spots and a spot anchor in place of the mouse pointer.
        SPOT,
        // Show the stylus hover pointer.
        STYLUS_HOVER,

        ftl_last = SPOT,
        ftl_last = STYLUS_HOVER,
    };

    /* Sets the mode of the pointer controller. */
+44 −7
Original line number Diff line number Diff line
@@ -977,12 +977,18 @@ void TouchInputMapper::configureInputDevice(nsecs_t when, bool* outResetNeeded)
        mOrientedRanges.clear();
    }

    // Create pointer controller if needed, and keep it around if Pointer Capture is enabled to
    // preserve the cursor position.
    if (mDeviceMode == DeviceMode::POINTER ||
        (mDeviceMode == DeviceMode::DIRECT && mConfig.showTouches) ||
    // Create and preserve the pointer controller in the following cases:
    const bool isPointerControllerNeeded =
            // - when the device is in pointer mode, to show the mouse cursor;
            (mDeviceMode == DeviceMode::POINTER) ||
            // - when pointer capture is enabled, to preserve the mouse cursor position;
            (mParameters.deviceType == Parameters::DeviceType::POINTER &&
         mConfig.pointerCaptureRequest.enable)) {
             mConfig.pointerCaptureRequest.enable) ||
            // - when we should be showing touches;
            (mDeviceMode == DeviceMode::DIRECT && mConfig.showTouches) ||
            // - when we should be showing a pointer icon for direct styluses.
            (mDeviceMode == DeviceMode::DIRECT && mConfig.stylusPointerIconEnabled && hasStylus());
    if (isPointerControllerNeeded) {
        if (mPointerController == nullptr) {
            mPointerController = getContext()->getPointerController(getDeviceId());
        }
@@ -3650,6 +3656,14 @@ std::list<NotifyArgs> TouchInputMapper::abortPointerSimple(nsecs_t when, nsecs_t
    return out;
}

static bool isStylusEvent(uint32_t source, int32_t action, const PointerProperties* properties) {
    if (!isFromSource(source, AINPUT_SOURCE_STYLUS)) {
        return false;
    }
    const auto actionIndex = action >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
    return isStylusToolType(properties[actionIndex].toolType);
}

NotifyMotionArgs TouchInputMapper::dispatchMotion(
        nsecs_t when, nsecs_t readTime, uint32_t policyFlags, uint32_t source, int32_t action,
        int32_t actionButton, int32_t flags, int32_t metaState, int32_t buttonState,
@@ -3691,12 +3705,35 @@ NotifyMotionArgs TouchInputMapper::dispatchMotion(
            ALOG_ASSERT(false);
        }
    }

    const int32_t displayId = getAssociatedDisplayId().value_or(ADISPLAY_ID_NONE);
    const bool showDirectStylusPointer = mConfig.stylusPointerIconEnabled &&
            mDeviceMode == DeviceMode::DIRECT && isStylusEvent(source, action, pointerProperties) &&
            mPointerController && displayId != ADISPLAY_ID_NONE &&
            displayId == mPointerController->getDisplayId();
    if (showDirectStylusPointer) {
        switch (action & AMOTION_EVENT_ACTION_MASK) {
            case AMOTION_EVENT_ACTION_HOVER_ENTER:
            case AMOTION_EVENT_ACTION_HOVER_MOVE:
                mPointerController->setPresentation(
                        PointerControllerInterface::Presentation::STYLUS_HOVER);
                mPointerController
                        ->setPosition(mCurrentCookedState.cookedPointerData.pointerCoords[0].getX(),
                                      mCurrentCookedState.cookedPointerData.pointerCoords[0]
                                              .getY());
                mPointerController->unfade(PointerControllerInterface::Transition::IMMEDIATE);
                break;
            case AMOTION_EVENT_ACTION_HOVER_EXIT:
                mPointerController->fade(PointerControllerInterface::Transition::IMMEDIATE);
                break;
        }
    }

    float xCursorPosition = AMOTION_EVENT_INVALID_CURSOR_POSITION;
    float yCursorPosition = AMOTION_EVENT_INVALID_CURSOR_POSITION;
    if (mDeviceMode == DeviceMode::POINTER) {
        mPointerController->getPosition(&xCursorPosition, &yCursorPosition);
    }
    const int32_t displayId = getAssociatedDisplayId().value_or(ADISPLAY_ID_NONE);
    const int32_t deviceId = getDeviceId();
    std::vector<TouchVideoFrame> frames = getDeviceContext().getVideoFrames();
    std::for_each(frames.begin(), frames.end(),
+4 −0
Original line number Diff line number Diff line
@@ -205,6 +205,10 @@ void FakeInputReaderPolicy::setStylusButtonMotionEventsEnabled(bool enabled) {
    mConfig.stylusButtonMotionEventsEnabled = enabled;
}

void FakeInputReaderPolicy::setStylusPointerIconEnabled(bool enabled) {
    mConfig.stylusPointerIconEnabled = enabled;
}

void FakeInputReaderPolicy::getReaderConfiguration(InputReaderConfiguration* outConfig) {
    *outConfig = mConfig;
}
Loading