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

Commit 5c422333 authored by Steve Kondik's avatar Steve Kondik Committed by Gerrit Code Review
Browse files

Merge "input: Add option to toggle pointer icon when using stylus" into ics

parents 52211129 353e4f27
Loading
Loading
Loading
Loading
+8 −0
Original line number Original line Diff line number Diff line
@@ -2018,6 +2018,14 @@ public final class Settings {
         */
         */
        public static final String POINTER_LOCATION = "pointer_location";
        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?
         * Show touch positions on screen?
         * 0 = no
         * 0 = no
+13 −5
Original line number Original line Diff line number Diff line
@@ -2528,7 +2528,8 @@ void TouchInputMapper::configure(nsecs_t when,
    bool resetNeeded = false;
    bool resetNeeded = false;
    if (!changes || (changes & (InputReaderConfiguration::CHANGE_DISPLAY_INFO
    if (!changes || (changes & (InputReaderConfiguration::CHANGE_DISPLAY_INFO
            | InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT
            | 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
        // Configure device sources, surface dimensions, orientation and
        // scaling factors.
        // scaling factors.
        configureSurface(when, &resetNeeded);
        configureSurface(when, &resetNeeded);
@@ -4019,7 +4020,7 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlag
                && (mPointerGesture.lastGestureMode == PointerGesture::SWIPE
                && (mPointerGesture.lastGestureMode == PointerGesture::SWIPE
                        || mPointerGesture.lastGestureMode == PointerGesture::FREEFORM)) {
                        || mPointerGesture.lastGestureMode == PointerGesture::FREEFORM)) {
            // Remind the user of where the pointer is after finishing a gesture with spots.
            // Remind the user of where the pointer is after finishing a gesture with spots.
            mPointerController->unfade(PointerControllerInterface::TRANSITION_GRADUAL);
            unfadePointer(PointerControllerInterface::TRANSITION_GRADUAL);
        }
        }
        break;
        break;
    case PointerGesture::TAP:
    case PointerGesture::TAP:
@@ -4029,7 +4030,7 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlag
    case PointerGesture::PRESS:
    case PointerGesture::PRESS:
        // Unfade the pointer when the current gesture manipulates the
        // Unfade the pointer when the current gesture manipulates the
        // area directly under the pointer.
        // area directly under the pointer.
        mPointerController->unfade(PointerControllerInterface::TRANSITION_IMMEDIATE);
        unfadePointer(PointerControllerInterface::TRANSITION_IMMEDIATE);
        break;
        break;
    case PointerGesture::SWIPE:
    case PointerGesture::SWIPE:
    case PointerGesture::FREEFORM:
    case PointerGesture::FREEFORM:
@@ -4038,7 +4039,7 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlag
        if (mParameters.gestureMode == Parameters::GESTURE_MODE_SPOTS) {
        if (mParameters.gestureMode == Parameters::GESTURE_MODE_SPOTS) {
            mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL);
            mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL);
        } else {
        } else {
            mPointerController->unfade(PointerControllerInterface::TRANSITION_IMMEDIATE);
            unfadePointer(PointerControllerInterface::TRANSITION_IMMEDIATE);
        }
        }
        break;
        break;
    }
    }
@@ -5066,7 +5067,7 @@ void TouchInputMapper::dispatchPointerSimple(nsecs_t when, uint32_t policyFlags,
            mPointerController->setPresentation(PointerControllerInterface::PRESENTATION_POINTER);
            mPointerController->setPresentation(PointerControllerInterface::PRESENTATION_POINTER);
            mPointerController->clearSpots();
            mPointerController->clearSpots();
            mPointerController->setButtonState(mCurrentButtonState);
            mPointerController->setButtonState(mCurrentButtonState);
            mPointerController->unfade(PointerControllerInterface::TRANSITION_IMMEDIATE);
            unfadePointer(PointerControllerInterface::TRANSITION_IMMEDIATE);
        } else if (!down && !hovering && (mPointerSimple.down || mPointerSimple.hovering)) {
        } else if (!down && !hovering && (mPointerSimple.down || mPointerSimple.hovering)) {
            mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL);
            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) {
bool TouchInputMapper::isPointInsideSurface(int32_t x, int32_t y) {
    return x >= mRawPointerAxes.x.minValue && x <= mRawPointerAxes.x.maxValue
    return x >= mRawPointerAxes.x.minValue && x <= mRawPointerAxes.x.maxValue
            && y >= mRawPointerAxes.y.minValue && y <= mRawPointerAxes.y.maxValue;
            && y >= mRawPointerAxes.y.minValue && y <= mRawPointerAxes.y.maxValue;
+10 −1
Original line number Original line Diff line number Diff line
@@ -59,6 +59,9 @@ struct InputReaderConfiguration {
        // The visible touches option changed.
        // The visible touches option changed.
        CHANGE_SHOW_TOUCHES = 1 << 3,
        CHANGE_SHOW_TOUCHES = 1 << 3,


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

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


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

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


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


    void assignPointerIds();
    void assignPointerIds();

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




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


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


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


    public void setDisplaySize(int displayId, int width, int height,
    public void setDisplaySize(int displayId, int width, int height,
@@ -461,6 +464,35 @@ public class InputManager implements Watchdog.Monitor {
        return speed;
        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() {
    public void updateShowTouchesFromSettings() {
        int setting = getShowTouchesSetting(0);
        int setting = getShowTouchesSetting(0);
        nativeSetShowTouches(setting != 0);
        nativeSetShowTouches(setting != 0);
+33 −0
Original line number Original line Diff line number Diff line
@@ -188,6 +188,7 @@ public:
    void setPointerSpeed(int32_t speed);
    void setPointerSpeed(int32_t speed);
    void setShowTouches(bool enabled);
    void setShowTouches(bool enabled);
    void setKeyLayout(const char* deviceName, const char* keyLayout);
    void setKeyLayout(const char* deviceName, const char* keyLayout);
    void setStylusIconEnabled(bool enabled);


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


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


        // Show icon when stylus is used
        bool stylusIconEnabled;

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


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


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


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


        outConfig->stylusIconEnabled = mLocked.stylusIconEnabled;

        outConfig->setDisplayInfo(0, false /*external*/,
        outConfig->setDisplayInfo(0, false /*external*/,
                mLocked.displayWidth, mLocked.displayHeight, mLocked.displayOrientation);
                mLocked.displayWidth, mLocked.displayHeight, mLocked.displayOrientation);
        outConfig->setDisplayInfo(0, true /*external*/,
        outConfig->setDisplayInfo(0, true /*external*/,
@@ -711,6 +718,22 @@ void NativeInputManager::setShowTouches(bool enabled) {
            InputReaderConfiguration::CHANGE_SHOW_TOUCHES);
            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) {
void NativeInputManager::setKeyLayout(const char* deviceName, const char* keyLayout) {
    mInputManager->getReader()->setKeyLayout(deviceName, keyLayout);
    mInputManager->getReader()->setKeyLayout(deviceName, keyLayout);
    mInputManager->getReader()->requestRefreshConfiguration(
    mInputManager->getReader()->requestRefreshConfiguration(
@@ -1366,6 +1389,14 @@ static void android_server_InputManager_nativeSetKeyLayout(JNIEnv* env,
    env->ReleaseStringUTFChars(keyLayout, cKeyLayout);
    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[] = {
static JNINativeMethod gInputManagerMethods[] = {
@@ -1422,6 +1453,8 @@ static JNINativeMethod gInputManagerMethods[] = {
            (void*) android_server_InputManager_nativeMonitor },
            (void*) android_server_InputManager_nativeMonitor },
    { "nativeSetKeyLayout", "(Ljava/lang/String;Ljava/lang/String;)V",
    { "nativeSetKeyLayout", "(Ljava/lang/String;Ljava/lang/String;)V",
            (void*) android_server_InputManager_nativeSetKeyLayout },
            (void*) android_server_InputManager_nativeSetKeyLayout },
    { "nativeSetStylusIconEnabled", "(Z)V",
            (void*) android_server_InputManager_nativeSetStylusIconEnabled },
};
};


#define FIND_CLASS(var, className) \
#define FIND_CLASS(var, className) \