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

Commit e760ae58 authored by Steve Kondik's avatar Steve Kondik Committed by Ricardo Cerqueira
Browse files

input: Add option to toggle pointer icon when using stylus

* The visible pointer icon when hovering or drawing with the stylus is
  quite annoying when trying to actually draw with it. Turn it off by
  default and add an option to turn it on.

Change-Id: Ib7f23e8b69589e3f875d150caf05065b64676e44

Conflicts:
	services/input/InputReader.cpp
	services/input/InputReader.h
	services/jni/com_android_server_input_InputManagerService.cpp
parent b9cb2961
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -2564,6 +2564,14 @@ public final class Settings {
         */
        public static final String POINTER_LOCATION = "pointer_location";

        /**
         * Show icon when stylus is used?
         * 0 = no
         * 1 = yes
         * @hide
         */
        public static final String STYLUS_ICON_ENABLED = "stylus_icon_enabled";

        /**
         * Show touch positions on screen?
         * 0 = no
+19 −4
Original line number Diff line number Diff line
@@ -2780,7 +2780,8 @@ void TouchInputMapper::configure(nsecs_t when,
    bool resetNeeded = false;
    if (!changes || (changes & (InputReaderConfiguration::CHANGE_DISPLAY_INFO
            | InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT
            | InputReaderConfiguration::CHANGE_SHOW_TOUCHES))) {
            | InputReaderConfiguration::CHANGE_SHOW_TOUCHES
            | InputReaderConfiguration::CHANGE_STYLUS_ICON_ENABLED))) {
        // Configure device sources, surface dimensions, orientation and
        // scaling factors.
        configureSurface(when, &resetNeeded);
@@ -4433,7 +4434,7 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlag
                && (mPointerGesture.lastGestureMode == PointerGesture::SWIPE
                        || mPointerGesture.lastGestureMode == PointerGesture::FREEFORM)) {
            // Remind the user of where the pointer is after finishing a gesture with spots.
            mPointerController->unfade(PointerControllerInterface::TRANSITION_GRADUAL);
            unfadePointer(PointerControllerInterface::TRANSITION_GRADUAL);
        }
        break;
    case PointerGesture::TAP:
@@ -4443,7 +4444,7 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlag
    case PointerGesture::PRESS:
        // Unfade the pointer when the current gesture manipulates the
        // area directly under the pointer.
        mPointerController->unfade(PointerControllerInterface::TRANSITION_IMMEDIATE);
        unfadePointer(PointerControllerInterface::TRANSITION_IMMEDIATE);
        break;
    case PointerGesture::SWIPE:
    case PointerGesture::FREEFORM:
@@ -5494,7 +5495,7 @@ void TouchInputMapper::dispatchPointerSimple(nsecs_t when, uint32_t policyFlags,
            mPointerController->setPresentation(PointerControllerInterface::PRESENTATION_POINTER);
            mPointerController->clearSpots();
            mPointerController->setButtonState(mCurrentButtonState);
            mPointerController->unfade(PointerControllerInterface::TRANSITION_IMMEDIATE);
            unfadePointer(PointerControllerInterface::TRANSITION_IMMEDIATE);
        } else if (!down && !hovering && (mPointerSimple.down || mPointerSimple.hovering)) {
            mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL);
        }
@@ -5698,6 +5699,20 @@ void TouchInputMapper::fadePointer() {
    }
}

void TouchInputMapper::unfadePointer(PointerControllerInterface::Transition transition) {
    if (mPointerController != NULL &&
            !(mPointerUsage == POINTER_USAGE_STYLUS && !mConfig.stylusIconEnabled)) {
        mPointerController->unfade(transition);
    }
}

nsecs_t TouchInputMapper::mLastStylusTime = 0;

bool TouchInputMapper::rejectPalm(nsecs_t when) {
  return (when - mLastStylusTime < mConfig.stylusPalmRejectionTime) &&
    mPointerSimple.currentProperties.toolType != AMOTION_EVENT_TOOL_TYPE_STYLUS;
}

bool TouchInputMapper::isPointInsideSurface(int32_t x, int32_t y) {
    return x >= mRawPointerAxes.x.minValue && x <= mRawPointerAxes.x.maxValue
            && y >= mRawPointerAxes.y.minValue && y <= mRawPointerAxes.y.maxValue;
+17 −1
Original line number Diff line number Diff line
@@ -137,6 +137,9 @@ struct InputReaderConfiguration {
        // The device name alias supplied by the may have changed for some devices.
        CHANGE_DEVICE_ALIAS = 1 << 5,

        // Stylus icon option changed.
        CHANGE_STYLUS_ICON_ENABLED = 1 << 6,

        // All devices must be reopened.
        CHANGE_MUST_REOPEN = 1 << 31,
    };
@@ -224,6 +227,12 @@ struct InputReaderConfiguration {
    // True to show the location of touches on the touch screen as spots.
    bool showTouches;

    // True to show the pointer icon when a stylus is used.
    bool stylusIconEnabled;

    // Ignore finger touches this long after the stylus has been used (including hover)
    nsecs_t stylusPalmRejectionTime;

    InputReaderConfiguration() :
            virtualKeyQuietTime(0),
            pointerVelocityControlParameters(1.0f, 500.0f, 3000.0f, 3.0f),
@@ -240,7 +249,10 @@ struct InputReaderConfiguration {
            pointerGestureSwipeMaxWidthRatio(0.25f),
            pointerGestureMovementSpeedRatio(0.8f),
            pointerGestureZoomSpeedRatio(0.3f),
            showTouches(false) { }
	    showTouches(false),
            stylusIconEnabled(false),
            stylusPalmRejectionTime(50 * 10000000LL) // 50 ms
    { }

    bool getDisplayInfo(bool external, DisplayViewport* outViewport) const;
    void setDisplayInfo(bool external, const DisplayViewport& viewport);
@@ -1685,6 +1697,10 @@ private:
    const VirtualKey* findVirtualKeyHit(int32_t x, int32_t y);

    void assignPointerIds();

    void unfadePointer(PointerControllerInterface::Transition transition);

    bool rejectPalm(nsecs_t when);
};


+29 −0
Original line number Diff line number Diff line
@@ -179,6 +179,7 @@ public class InputManagerService extends IInputManager.Stub
            InputChannel fromChannel, InputChannel toChannel);
    private static native void nativeSetPointerSpeed(int ptr, int speed);
    private static native void nativeSetShowTouches(int ptr, boolean enabled);
    private static native void nativeSetStylusIconEnabled(int ptr, boolean enabled);
    private static native void nativeVibrate(int ptr, int deviceId, long[] pattern,
            int repeat, int token);
    private static native void nativeCancelVibrate(int ptr, int deviceId, int token);
@@ -269,6 +270,7 @@ public class InputManagerService extends IInputManager.Stub

        registerPointerSpeedSettingObserver();
        registerShowTouchesSettingObserver();
        registerStylusIconEnabledSettingObserver();

        mContext.registerReceiver(new BroadcastReceiver() {
            @Override
@@ -280,6 +282,7 @@ public class InputManagerService extends IInputManager.Stub

        updatePointerSpeedFromSettings();
        updateShowTouchesFromSettings();
        updateStylusIconEnabledFromSettings();
    }

    // TODO(BT) Pass in paramter for bluetooth system
@@ -1123,6 +1126,32 @@ public class InputManagerService extends IInputManager.Stub
        return speed;
    }

    public void updateStylusIconEnabledFromSettings() {
        int enabled = getStylusIconEnabled(0);
        nativeSetStylusIconEnabled(mPtr, enabled != 0);
    }

    public void registerStylusIconEnabledSettingObserver() {
        mContext.getContentResolver().registerContentObserver(
                Settings.System.getUriFor(Settings.System.STYLUS_ICON_ENABLED), false,
                new ContentObserver(mHandler) {
                    @Override
                    public void onChange(boolean selfChange) {
                        updateStylusIconEnabledFromSettings();
                    }
                });
    }

    private int getStylusIconEnabled(int defaultValue) {
        int result = defaultValue;
        try {
            result = Settings.System.getInt(mContext.getContentResolver(),
                Settings.System.STYLUS_ICON_ENABLED);
        } catch (SettingNotFoundException snfe) {
        }
        return result;
    }

    public void updateShowTouchesFromSettings() {
        int setting = getShowTouchesSetting(0);
        nativeSetShowTouches(mPtr, setting != 0);
+33 −0
Original line number Diff line number Diff line
@@ -177,6 +177,7 @@ public:
    void setSystemUiVisibility(int32_t visibility);
    void setPointerSpeed(int32_t speed);
    void setShowTouches(bool enabled);
    void setStylusIconEnabled(bool enabled);

    /* --- InputReaderPolicyInterface implementation --- */

@@ -238,6 +239,9 @@ private:
        // Show touches feature enable/disable.
        bool showTouches;

        // Show icon when stylus is used
        bool stylusIconEnabled;

        // Sprite controller singleton, created on first use.
        sp<SpriteController> spriteController;

@@ -276,6 +280,7 @@ NativeInputManager::NativeInputManager(jobject contextObj,
        mLocked.pointerSpeed = 0;
        mLocked.pointerGesturesEnabled = true;
        mLocked.showTouches = false;
        mLocked.stylusIconEnabled = false;
    }

    sp<EventHub> eventHub = new EventHub();
@@ -408,8 +413,11 @@ void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outCon

        outConfig->showTouches = mLocked.showTouches;

        outConfig->stylusIconEnabled = mLocked.stylusIconEnabled;

        outConfig->setDisplayInfo(false /*external*/, mLocked.internalViewport);
        outConfig->setDisplayInfo(true /*external*/, mLocked.externalViewport);

    } // release lock
}

@@ -733,6 +741,22 @@ void NativeInputManager::setShowTouches(bool enabled) {
            InputReaderConfiguration::CHANGE_SHOW_TOUCHES);
}

void NativeInputManager::setStylusIconEnabled(bool enabled) {
    { // acquire lock
        AutoMutex _l(mLock);

        if (mLocked.stylusIconEnabled == enabled) {
            return;
        }

        ALOGI("Setting stylus icon enabled to %s.", enabled ? "enabled" : "disabled");
        mLocked.stylusIconEnabled = enabled;
    } // release lock

    mInputManager->getReader()->requestRefreshConfiguration(
            InputReaderConfiguration::CHANGE_STYLUS_ICON_ENABLED);
}

bool NativeInputManager::isScreenOn() {
    return android_server_PowerManagerService_isScreenOn();
}
@@ -1229,6 +1253,13 @@ static void nativeSetShowTouches(JNIEnv* env,
    im->setShowTouches(enabled);
}

static void nativeSetStylusIconEnabled(JNIEnv* env,
        jclass clazz, jint ptr, jboolean enabled) {
    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);

    im->setStylusIconEnabled(enabled);
}

static void nativeVibrate(JNIEnv* env,
        jclass clazz, jint ptr, jint deviceId, jlongArray patternObj,
        jint repeat, jint token) {
@@ -1334,6 +1365,8 @@ static JNINativeMethod gInputManagerMethods[] = {
            (void*) nativeSetPointerSpeed },
    { "nativeSetShowTouches", "(IZ)V",
            (void*) nativeSetShowTouches },
    { "nativeSetStylusIconEnabled", "(IZ)V",
            (void*) nativeSetStylusIconEnabled },
    { "nativeVibrate", "(II[JII)V",
            (void*) nativeVibrate },
    { "nativeCancelVibrate", "(III)V",