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

Commit be9be6e4 authored by Chiou-Hao Hsu's avatar Chiou-Hao Hsu Committed by Steve Kondik
Browse files

Add Digital Pen hovering cursor support

Add digital pen hovering cursor support so
that whenever the digital pen is enabled,
the hovering cursor will be shown.

Change-Id: I1b57448603486292ac501fd46b0e8d815b9eb232
parent e0b83ae1
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -57,6 +57,12 @@
#define MSC_ANDROID_TIME_SEC 0x6
#define MSC_ANDROID_TIME_USEC 0x7

/**
 * code for a special button that is used to show/hide a
 * circular hovering cursor in the input framework.
 */
#define BTN_USF_HOVERING_CURSOR         0x230

namespace android {

enum {
+37 −1
Original line number Diff line number Diff line
@@ -2593,6 +2593,7 @@ void CursorInputMapper::fadePointer() {
TouchInputMapper::TouchInputMapper(InputDevice* device) :
        InputMapper(device),
        mSource(0), mDeviceMode(DEVICE_MODE_DISABLED),
        mHasExternalHoveringCursorControl(false), mExternalHoveringCursorVisible(false),
        mSurfaceWidth(-1), mSurfaceHeight(-1), mSurfaceLeft(0), mSurfaceTop(0),
        mSurfaceOrientation(DISPLAY_ORIENTATION_0) {
}
@@ -2864,6 +2865,8 @@ void TouchInputMapper::configureParameters() {
                        && getDevice()->isExternal();
    }

    mHasExternalHoveringCursorControl = getDevice()->hasKey(BTN_USF_HOVERING_CURSOR);

    // Initial downs on external touch devices should wake the device.
    // Normally we don't do this for internal touch screens to prevent them from waking
    // up in your pocket but you can enable it using the input device configuration.
@@ -3060,7 +3063,7 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
    }

    // Create pointer controller if needed.
    if (mDeviceMode == DEVICE_MODE_POINTER ||
    if (mDeviceMode == DEVICE_MODE_POINTER || mHasExternalHoveringCursorControl ||
            (mDeviceMode == DEVICE_MODE_DIRECT && mConfig.showTouches)) {
        if (mPointerController == NULL) {
            mPointerController = getPolicy()->obtainPointerController(getDeviceId());
@@ -3730,6 +3733,20 @@ void TouchInputMapper::process(const RawEvent* rawEvent) {
    if (rawEvent->type == EV_SYN && rawEvent->code == SYN_REPORT) {
        sync(rawEvent->when);
    }
    if (mHasExternalHoveringCursorControl && rawEvent->type == EV_KEY) {
        if (rawEvent->code == BTN_USF_HOVERING_CURSOR && mPointerController != NULL) {
            if (rawEvent->value) {
                // show a hover cursor
                mPointerController->setPresentation(PointerControllerInterface::PRESENTATION_STYLUS_HOVER);
                mPointerController->unfade(android::PointerControllerInterface::TRANSITION_IMMEDIATE);
                mExternalHoveringCursorVisible = true;
            } else {
                // hide the cursor
                mPointerController->fade(android::PointerControllerInterface::TRANSITION_IMMEDIATE);
                mExternalHoveringCursorVisible = false;
            }
        }
    }
}

void TouchInputMapper::sync(nsecs_t when) {
@@ -3861,6 +3878,25 @@ void TouchInputMapper::sync(nsecs_t when) {
                        mCurrentCookedPointerData.touchingIdBits);
            }

            if (mHasExternalHoveringCursorControl && mPointerController != NULL) {
                if (mExternalHoveringCursorVisible) {
                    // find the pointer position from the first touch point (either touching or hovering)
                    uint32_t index = MAX_POINTERS;
                    if (!mCurrentRawPointerData.touchingIdBits.isEmpty()) {
                        index = mCurrentCookedPointerData.idToIndex[mCurrentRawPointerData.touchingIdBits.firstMarkedBit()];
                    } else if (!mCurrentRawPointerData.hoveringIdBits.isEmpty()) {
                        index = mCurrentCookedPointerData.idToIndex[mCurrentRawPointerData.hoveringIdBits.firstMarkedBit()];
                    }
                    if (index < MAX_POINTERS)
                    {
                        float x = mCurrentCookedPointerData.pointerCoords[index].getX();
                        float y = mCurrentCookedPointerData.pointerCoords[index].getY();
                        mPointerController->setPosition(x, y);
                        mPointerController->unfade(android::PointerControllerInterface::TRANSITION_IMMEDIATE);
                    }
                }
            }

            dispatchHoverExit(when, policyFlags);
            dispatchTouches(when, policyFlags);
            dispatchHoverEnterAndMove(when, policyFlags);
+5 −0
Original line number Diff line number Diff line
@@ -1369,6 +1369,11 @@ protected:

    Vector<VirtualKey> mVirtualKeys;

    // true if we support external hovering cursor control
    bool mHasExternalHoveringCursorControl;
    // visibility state of hovering cursor (true=visible)
    bool mExternalHoveringCursorVisible;

    virtual void configureParameters();
    virtual void dumpParameters(String8& dump);
    virtual void configureRawPointerAxes();
+2 −0
Original line number Diff line number Diff line
@@ -79,6 +79,8 @@ public:
        PRESENTATION_POINTER,
        // Show spots and a spot anchor in place of the mouse pointer.
        PRESENTATION_SPOT,
        // Show a stylus hovering icon (small circle)
        PRESENTATION_STYLUS_HOVER,
    };

    /* Sets the mode of the pointer controller. */