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

Commit 60656e32 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

Apply pointer capture changes only in mode POINTER_RELATIVE

Pointer Capture should not effect devices in NAVIGATION mode like
trackballs.

This CL also migrates the Pointer Mode enum to an enum class.

Bug: 233184154
Test: presubmit
Change-Id: Ic7a74588d44bd54086bd544c77880bd6037e5985
parent eb84c421
Loading
Loading
Loading
Loading
+19 −32
Original line number Original line Diff line number Diff line
@@ -76,7 +76,7 @@ uint32_t CursorInputMapper::getSources() const {
void CursorInputMapper::populateDeviceInfo(InputDeviceInfo* info) {
void CursorInputMapper::populateDeviceInfo(InputDeviceInfo* info) {
    InputMapper::populateDeviceInfo(info);
    InputMapper::populateDeviceInfo(info);


    if (mParameters.mode == Parameters::MODE_POINTER) {
    if (mParameters.mode == Parameters::Mode::POINTER) {
        float minX, minY, maxX, maxY;
        float minX, minY, maxX, maxY;
        if (mPointerController->getBounds(&minX, &minY, &maxX, &maxY)) {
        if (mPointerController->getBounds(&minX, &minY, &maxX, &maxY)) {
            info->addMotionRange(AMOTION_EVENT_AXIS_X, mSource, minX, maxX, 0.0f, 0.0f, 0.0f);
            info->addMotionRange(AMOTION_EVENT_AXIS_X, mSource, minX, maxX, 0.0f, 0.0f, 0.0f);
@@ -131,12 +131,12 @@ void CursorInputMapper::configure(nsecs_t when, const InputReaderConfiguration*


        // Configure device mode.
        // Configure device mode.
        switch (mParameters.mode) {
        switch (mParameters.mode) {
            case Parameters::MODE_POINTER_RELATIVE:
            case Parameters::Mode::POINTER_RELATIVE:
                // Should not happen during first time configuration.
                // Should not happen during first time configuration.
                ALOGE("Cannot start a device in MODE_POINTER_RELATIVE, starting in MODE_POINTER");
                ALOGE("Cannot start a device in MODE_POINTER_RELATIVE, starting in MODE_POINTER");
                mParameters.mode = Parameters::MODE_POINTER;
                mParameters.mode = Parameters::Mode::POINTER;
                [[fallthrough]];
                [[fallthrough]];
            case Parameters::MODE_POINTER:
            case Parameters::Mode::POINTER:
                mSource = AINPUT_SOURCE_MOUSE;
                mSource = AINPUT_SOURCE_MOUSE;
                mXPrecision = 1.0f;
                mXPrecision = 1.0f;
                mYPrecision = 1.0f;
                mYPrecision = 1.0f;
@@ -144,7 +144,7 @@ void CursorInputMapper::configure(nsecs_t when, const InputReaderConfiguration*
                mYScale = 1.0f;
                mYScale = 1.0f;
                mPointerController = getContext()->getPointerController(getDeviceId());
                mPointerController = getContext()->getPointerController(getDeviceId());
                break;
                break;
            case Parameters::MODE_NAVIGATION:
            case Parameters::Mode::NAVIGATION:
                mSource = AINPUT_SOURCE_TRACKBALL;
                mSource = AINPUT_SOURCE_TRACKBALL;
                mXPrecision = TRACKBALL_MOVEMENT_THRESHOLD;
                mXPrecision = TRACKBALL_MOVEMENT_THRESHOLD;
                mYPrecision = TRACKBALL_MOVEMENT_THRESHOLD;
                mYPrecision = TRACKBALL_MOVEMENT_THRESHOLD;
@@ -157,12 +157,13 @@ void CursorInputMapper::configure(nsecs_t when, const InputReaderConfiguration*
        mHWheelScale = 1.0f;
        mHWheelScale = 1.0f;
    }
    }


    const bool configurePointerCapture = (!changes && config->pointerCaptureRequest.enable) ||
    const bool configurePointerCapture = mParameters.mode != Parameters::Mode::NAVIGATION &&
            (changes & InputReaderConfiguration::CHANGE_POINTER_CAPTURE);
            ((!changes && config->pointerCaptureRequest.enable) ||
             (changes & InputReaderConfiguration::CHANGE_POINTER_CAPTURE));
    if (configurePointerCapture) {
    if (configurePointerCapture) {
        if (config->pointerCaptureRequest.enable) {
        if (config->pointerCaptureRequest.enable) {
            if (mParameters.mode == Parameters::MODE_POINTER) {
            if (mParameters.mode == Parameters::Mode::POINTER) {
                mParameters.mode = Parameters::MODE_POINTER_RELATIVE;
                mParameters.mode = Parameters::Mode::POINTER_RELATIVE;
                mSource = AINPUT_SOURCE_MOUSE_RELATIVE;
                mSource = AINPUT_SOURCE_MOUSE_RELATIVE;
                // Keep PointerController around in order to preserve the pointer position.
                // Keep PointerController around in order to preserve the pointer position.
                mPointerController->fade(PointerControllerInterface::Transition::IMMEDIATE);
                mPointerController->fade(PointerControllerInterface::Transition::IMMEDIATE);
@@ -170,8 +171,8 @@ void CursorInputMapper::configure(nsecs_t when, const InputReaderConfiguration*
                ALOGE("Cannot request pointer capture, device is not in MODE_POINTER");
                ALOGE("Cannot request pointer capture, device is not in MODE_POINTER");
            }
            }
        } else {
        } else {
            if (mParameters.mode == Parameters::MODE_POINTER_RELATIVE) {
            if (mParameters.mode == Parameters::Mode::POINTER_RELATIVE) {
                mParameters.mode = Parameters::MODE_POINTER;
                mParameters.mode = Parameters::Mode::POINTER;
                mSource = AINPUT_SOURCE_MOUSE;
                mSource = AINPUT_SOURCE_MOUSE;
            } else {
            } else {
                ALOGE("Cannot release pointer capture, device is not in MODE_POINTER_RELATIVE");
                ALOGE("Cannot release pointer capture, device is not in MODE_POINTER_RELATIVE");
@@ -186,8 +187,8 @@ void CursorInputMapper::configure(nsecs_t when, const InputReaderConfiguration*


    if (!changes || (changes & InputReaderConfiguration::CHANGE_POINTER_SPEED) ||
    if (!changes || (changes & InputReaderConfiguration::CHANGE_POINTER_SPEED) ||
        configurePointerCapture) {
        configurePointerCapture) {
        if (config->pointerCaptureRequest.enable) {
        if (mParameters.mode == Parameters::Mode::POINTER_RELATIVE) {
            // Disable any acceleration or scaling when Pointer Capture is enabled.
            // Disable any acceleration or scaling for the pointer when Pointer Capture is enabled.
            mPointerVelocityControl.setParameters(FLAT_VELOCITY_CONTROL_PARAMS);
            mPointerVelocityControl.setParameters(FLAT_VELOCITY_CONTROL_PARAMS);
            mWheelXVelocityControl.setParameters(FLAT_VELOCITY_CONTROL_PARAMS);
            mWheelXVelocityControl.setParameters(FLAT_VELOCITY_CONTROL_PARAMS);
            mWheelYVelocityControl.setParameters(FLAT_VELOCITY_CONTROL_PARAMS);
            mWheelYVelocityControl.setParameters(FLAT_VELOCITY_CONTROL_PARAMS);
@@ -221,12 +222,12 @@ void CursorInputMapper::configure(nsecs_t when, const InputReaderConfiguration*
}
}


void CursorInputMapper::configureParameters() {
void CursorInputMapper::configureParameters() {
    mParameters.mode = Parameters::MODE_POINTER;
    mParameters.mode = Parameters::Mode::POINTER;
    String8 cursorModeString;
    String8 cursorModeString;
    if (getDeviceContext().getConfiguration().tryGetProperty(String8("cursor.mode"),
    if (getDeviceContext().getConfiguration().tryGetProperty(String8("cursor.mode"),
                                                             cursorModeString)) {
                                                             cursorModeString)) {
        if (cursorModeString == "navigation") {
        if (cursorModeString == "navigation") {
            mParameters.mode = Parameters::MODE_NAVIGATION;
            mParameters.mode = Parameters::Mode::NAVIGATION;
        } else if (cursorModeString != "pointer" && cursorModeString != "default") {
        } else if (cursorModeString != "pointer" && cursorModeString != "default") {
            ALOGW("Invalid value for cursor.mode: '%s'", cursorModeString.string());
            ALOGW("Invalid value for cursor.mode: '%s'", cursorModeString.string());
        }
        }
@@ -237,7 +238,7 @@ void CursorInputMapper::configureParameters() {
                                                         mParameters.orientationAware);
                                                         mParameters.orientationAware);


    mParameters.hasAssociatedDisplay = false;
    mParameters.hasAssociatedDisplay = false;
    if (mParameters.mode == Parameters::MODE_POINTER || mParameters.orientationAware) {
    if (mParameters.mode == Parameters::Mode::POINTER || mParameters.orientationAware) {
        mParameters.hasAssociatedDisplay = true;
        mParameters.hasAssociatedDisplay = true;
    }
    }
}
}
@@ -246,21 +247,7 @@ void CursorInputMapper::dumpParameters(std::string& dump) {
    dump += INDENT3 "Parameters:\n";
    dump += INDENT3 "Parameters:\n";
    dump += StringPrintf(INDENT4 "HasAssociatedDisplay: %s\n",
    dump += StringPrintf(INDENT4 "HasAssociatedDisplay: %s\n",
                         toString(mParameters.hasAssociatedDisplay));
                         toString(mParameters.hasAssociatedDisplay));

    dump += StringPrintf(INDENT4 "Mode: %s\n", ftl::enum_string(mParameters.mode).c_str());
    switch (mParameters.mode) {
        case Parameters::MODE_POINTER:
            dump += INDENT4 "Mode: pointer\n";
            break;
        case Parameters::MODE_POINTER_RELATIVE:
            dump += INDENT4 "Mode: relative pointer\n";
            break;
        case Parameters::MODE_NAVIGATION:
            dump += INDENT4 "Mode: navigation\n";
            break;
        default:
            ALOG_ASSERT(false);
    }

    dump += StringPrintf(INDENT4 "OrientationAware: %s\n", toString(mParameters.orientationAware));
    dump += StringPrintf(INDENT4 "OrientationAware: %s\n", toString(mParameters.orientationAware));
}
}


@@ -486,7 +473,7 @@ int32_t CursorInputMapper::getScanCodeState(uint32_t sourceMask, int32_t scanCod


std::optional<int32_t> CursorInputMapper::getAssociatedDisplayId() {
std::optional<int32_t> CursorInputMapper::getAssociatedDisplayId() {
    if (mParameters.hasAssociatedDisplay) {
    if (mParameters.hasAssociatedDisplay) {
        if (mParameters.mode == Parameters::MODE_POINTER) {
        if (mParameters.mode == Parameters::Mode::POINTER) {
            return std::make_optional(mPointerController->getDisplayId());
            return std::make_optional(mPointerController->getDisplayId());
        } else {
        } else {
            // If the device is orientationAware and not a mouse,
            // If the device is orientationAware and not a mouse,
+11 −4
Original line number Original line Diff line number Diff line
@@ -74,10 +74,17 @@ private:


    // Immutable configuration parameters.
    // Immutable configuration parameters.
    struct Parameters {
    struct Parameters {
        enum Mode {
        enum class Mode {
            MODE_POINTER,
            // In POINTER mode, the device is a mouse that controls the mouse cursor on the screen,
            MODE_POINTER_RELATIVE,
            // reporting absolute screen locations using SOURCE_MOUSE.
            MODE_NAVIGATION,
            POINTER,
            // A mouse device in POINTER mode switches to the POINTER_RELATIVE mode when Pointer
            // Capture is enabled, and reports relative values only using SOURCE_MOUSE_RELATIVE.
            POINTER_RELATIVE,
            // A device in NAVIGATION mode emits relative values using SOURCE_TRACKBALL.
            NAVIGATION,

            ftl_last = NAVIGATION,
        };
        };


        Mode mode;
        Mode mode;