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

Commit 353e4f27 authored by Steve Kondik's avatar Steve Kondik
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: I98b6e1ea929019ef12dbd4b2991c6c96c52cef5c
parent d83449d2
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -2018,6 +2018,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
+13 −5
Original line number Diff line number Diff line
@@ -2528,7 +2528,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);
@@ -4019,7 +4020,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:
@@ -4029,7 +4030,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:
@@ -4038,7 +4039,7 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlag
        if (mParameters.gestureMode == Parameters::GESTURE_MODE_SPOTS) {
            mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL);
        } else {
            mPointerController->unfade(PointerControllerInterface::TRANSITION_IMMEDIATE);
            unfadePointer(PointerControllerInterface::TRANSITION_IMMEDIATE);
        }
        break;
    }
@@ -5066,7 +5067,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);
        }
@@ -5254,6 +5255,13 @@ void TouchInputMapper::fadePointer() {
    }
}

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

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;
+10 −1
Original line number Diff line number Diff line
@@ -59,6 +59,9 @@ struct InputReaderConfiguration {
        // The visible touches option changed.
        CHANGE_SHOW_TOUCHES = 1 << 3,

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

        // All devices must be reopened.
        CHANGE_MUST_REOPEN = 1 << 31,
    };
@@ -146,6 +149,9 @@ 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;

    InputReaderConfiguration() :
            virtualKeyQuietTime(0),
            pointerVelocityControlParameters(1.0f, 500.0f, 3000.0f, 3.0f),
@@ -162,7 +168,8 @@ struct InputReaderConfiguration {
            pointerGestureSwipeMaxWidthRatio(0.25f),
            pointerGestureMovementSpeedRatio(0.8f),
            pointerGestureZoomSpeedRatio(0.3f),
            showTouches(false) { }
            showTouches(false),
            stylusIconEnabled(false) { }

    bool getDisplayInfo(int32_t displayId, bool external,
            int32_t* width, int32_t* height, int32_t* orientation) const;
@@ -1525,6 +1532,8 @@ private:
    const VirtualKey* findVirtualKeyHit(int32_t x, int32_t y);

    void assignPointerIds();

    void unfadePointer(PointerControllerInterface::Transition transition);
};


+34 −2
Original line number Diff line number Diff line
@@ -98,6 +98,7 @@ public class InputManager implements Watchdog.Monitor {
    private static native String nativeDump();
    private static native void nativeMonitor();
    private static native void nativeSetKeyLayout(String deviceName, String keyLayout);
    private static native void nativeSetStylusIconEnabled(boolean enabled);

    // Input event injection constants defined in InputDispatcher.h.
    static final int INPUT_EVENT_INJECTION_SUCCEEDED = 0;
@@ -151,10 +152,12 @@ public class InputManager implements Watchdog.Monitor {
        registerPointerSpeedSettingObserver();
        registerShowTouchesSettingObserver();
        registerKeyLayoutSettingObserver();
        registerStylusIconEnabledSettingObserver();

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

    public void setDisplaySize(int displayId, int width, int height,
@@ -461,6 +464,35 @@ public class InputManager implements Watchdog.Monitor {
        return speed;
    }

    /**
     * Show the pointer icon when a stylus is used
     * @param enabled
     */
    public void setStylusIconEnabled(boolean enabled) {
        nativeSetStylusIconEnabled(enabled);
    }

    public void updateStylusIconEnabledFromSettings() {
        boolean enabled = getStylusIconEnabled();
        setStylusIconEnabled(enabled);
    }

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

    private boolean getStylusIconEnabled() {
        return Settings.System.getInt(mContext.getContentResolver(),
                    Settings.System.STYLUS_ICON_ENABLED, 0) == 1;
    }

    public void updateShowTouchesFromSettings() {
        int setting = getShowTouchesSetting(0);
        nativeSetShowTouches(setting != 0);
+33 −0
Original line number Diff line number Diff line
@@ -188,6 +188,7 @@ public:
    void setPointerSpeed(int32_t speed);
    void setShowTouches(bool enabled);
    void setKeyLayout(const char* deviceName, const char* keyLayout);
    void setStylusIconEnabled(bool enabled);

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

@@ -246,6 +247,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;

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

    sp<EventHub> eventHub = new EventHub();
@@ -447,6 +452,8 @@ void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outCon

        outConfig->showTouches = mLocked.showTouches;

        outConfig->stylusIconEnabled = mLocked.stylusIconEnabled;

        outConfig->setDisplayInfo(0, false /*external*/,
                mLocked.displayWidth, mLocked.displayHeight, mLocked.displayOrientation);
        outConfig->setDisplayInfo(0, true /*external*/,
@@ -711,6 +718,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;
        }

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

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

void NativeInputManager::setKeyLayout(const char* deviceName, const char* keyLayout) {
    mInputManager->getReader()->setKeyLayout(deviceName, keyLayout);
    mInputManager->getReader()->requestRefreshConfiguration(
@@ -1366,6 +1389,14 @@ static void android_server_InputManager_nativeSetKeyLayout(JNIEnv* env,
    env->ReleaseStringUTFChars(keyLayout, cKeyLayout);
}

static void android_server_InputManager_nativeSetStylusIconEnabled(JNIEnv* env,
        jclass clazz, jboolean enabled) {
    if (checkInputManagerUnitialized(env)) {
        return;
    }

    gNativeInputManager->setStylusIconEnabled(enabled);
}
// ----------------------------------------------------------------------------

static JNINativeMethod gInputManagerMethods[] = {
@@ -1422,6 +1453,8 @@ static JNINativeMethod gInputManagerMethods[] = {
            (void*) android_server_InputManager_nativeMonitor },
    { "nativeSetKeyLayout", "(Ljava/lang/String;Ljava/lang/String;)V",
            (void*) android_server_InputManager_nativeSetKeyLayout },
    { "nativeSetStylusIconEnabled", "(Z)V",
            (void*) android_server_InputManager_nativeSetStylusIconEnabled },
};

#define FIND_CLASS(var, className) \