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

Commit dc160454 authored by Steve Kondik's avatar Steve Kondik Committed by Steve Kondik
Browse files

input: Add option to toggle pointer icon when using stylus(2/3)

* 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: I26ba2ca8b92511799033759ca85c36f4ba2b7833
parent 66e8606f
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -3485,6 +3485,14 @@ public final class Settings {
        public static final Validator POINTER_SPEED_VALIDATOR =
                new InclusiveFloatRangeValidator(-7, 7);

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

        /**
         * Enable Stylus Gestures
         *
+29 −0
Original line number Diff line number Diff line
@@ -188,6 +188,7 @@ public class InputManagerService extends IInputManager.Stub
            InputChannel fromChannel, InputChannel toChannel);
    private static native void nativeSetPointerSpeed(long ptr, int speed);
    private static native void nativeSetShowTouches(long ptr, boolean enabled);
    private static native void nativeSetStylusIconEnabled(long ptr, boolean enabled);
    private static native void nativeSetVolumeKeysRotation(long ptr, int mode);
    private static native void nativeSetInteractive(long ptr, boolean interactive);
    private static native void nativeReloadCalibration(long ptr);
@@ -291,6 +292,7 @@ public class InputManagerService extends IInputManager.Stub

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

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

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

@@ -1333,6 +1336,32 @@ public class InputManagerService extends IInputManager.Stub
        return result;
    }

    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 updateVolumeKeysRotationFromSettings() {
        int mode = getVolumeKeysRotationSetting(0);
        nativeSetVolumeKeysRotation(mPtr, mode);
+31 −0
Original line number Diff line number Diff line
@@ -197,6 +197,7 @@ public:
    void setSystemUiVisibility(int32_t visibility);
    void setPointerSpeed(int32_t speed);
    void setShowTouches(bool enabled);
    void setStylusIconEnabled(bool enabled);
    void setVolumeKeysRotation(int mode);
    void setInteractive(bool interactive);
    void reloadCalibration();
@@ -264,6 +265,9 @@ private:
        // Show touches feature enable/disable.
        bool showTouches;

        // Show icon when stylus is used
        bool stylusIconEnabled;

        // Volume keys rotation mode (0 - off, 1 - phone, 2 - tablet)
        int32_t volumeKeysRotationMode;

@@ -303,6 +307,7 @@ NativeInputManager::NativeInputManager(jobject contextObj,
        mLocked.pointerSpeed = 0;
        mLocked.pointerGesturesEnabled = true;
        mLocked.showTouches = false;
        mLocked.stylusIconEnabled = false;
        mLocked.volumeKeysRotationMode = 0;
    }
    mInteractive = true;
@@ -451,6 +456,7 @@ void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outCon
        outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled;

        outConfig->showTouches = mLocked.showTouches;
        outConfig->stylusIconEnabled = mLocked.stylusIconEnabled;
        outConfig->volumeKeysRotationMode = mLocked.volumeKeysRotationMode;

        outConfig->setDisplayInfo(false /*external*/, mLocked.internalViewport);
@@ -776,6 +782,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);
}

void NativeInputManager::setVolumeKeysRotation(int mode) {
    { // acquire lock
        AutoMutex _l(mLock);
@@ -1314,6 +1336,13 @@ static void nativeSetShowTouches(JNIEnv* /* env */,
    im->setShowTouches(enabled);
}

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

    im->setStylusIconEnabled(enabled);
}

static void nativeSetVolumeKeysRotation(JNIEnv* env,
        jclass clazz, jlong ptr, int mode) {
    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
@@ -1438,6 +1467,8 @@ static JNINativeMethod gInputManagerMethods[] = {
            (void*) nativeSetPointerSpeed },
    { "nativeSetShowTouches", "(JZ)V",
            (void*) nativeSetShowTouches },
    { "nativeSetStylusIconEnabled", "(JZ)V",
            (void*) nativeSetStylusIconEnabled },
    { "nativeSetVolumeKeysRotation", "(JI)V",
            (void*) nativeSetVolumeKeysRotation },
    { "nativeSetInteractive", "(JZ)V",