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

Unverified Commit 6c534408 authored by nadlabak's avatar nadlabak Committed by Michael Bestas
Browse files

Forward port 'Swap volume buttons' (2/3)

[mikeioannina]: Adjust for 5.0 changes
[LuK1337]: Adjust for 8.1 changes
[mikeioannina]: Adjust for 10.0 changes
[LuK1337]: Adjust for 11.0 changes
[LuK1337]: Adjust for 14.0 changes

Change-Id: I5ed4ae2b7e69e2ada067ed1d3524b3d3fad30e2e
parent 8e4fb3d9
Loading
Loading
Loading
Loading
+9 −1
Original line number Original line Diff line number Diff line
@@ -91,6 +91,9 @@ struct InputReaderConfiguration {
        // The touchpad settings changed.
        // The touchpad settings changed.
        TOUCHPAD_SETTINGS = 1u << 13,
        TOUCHPAD_SETTINGS = 1u << 13,


        // Volume keys rotation option changed.
        VOLUME_KEYS_ROTATION = 1 << 10,

        // All devices must be reopened.
        // All devices must be reopened.
        MUST_REOPEN = 1u << 31,
        MUST_REOPEN = 1u << 31,
    };
    };
@@ -241,6 +244,10 @@ struct InputReaderConfiguration {
    // True if a pointer icon should be shown for direct stylus pointers.
    // True if a pointer icon should be shown for direct stylus pointers.
    bool stylusPointerIconEnabled;
    bool stylusPointerIconEnabled;


    // Remap volume keys according to display rotation
    // 0 - disabled, 1 - phone or hybrid rotation mode, 2 - tablet rotation mode
    int volumeKeysRotationMode;

    InputReaderConfiguration()
    InputReaderConfiguration()
          : virtualKeyQuietTime(0),
          : virtualKeyQuietTime(0),
            defaultPointerDisplayId(ui::LogicalDisplayId::DEFAULT),
            defaultPointerDisplayId(ui::LogicalDisplayId::DEFAULT),
@@ -270,7 +277,8 @@ struct InputReaderConfiguration {
            touchpadTapDraggingEnabled(false),
            touchpadTapDraggingEnabled(false),
            touchpadRightClickZoneEnabled(false),
            touchpadRightClickZoneEnabled(false),
            stylusButtonMotionEventsEnabled(true),
            stylusButtonMotionEventsEnabled(true),
            stylusPointerIconEnabled(false) {}
            stylusPointerIconEnabled(false),
            volumeKeysRotationMode(0) {}


    std::optional<DisplayViewport> getDisplayViewportByType(ViewportType type) const;
    std::optional<DisplayViewport> getDisplayViewportByType(ViewportType type) const;
    std::optional<DisplayViewport> getDisplayViewportByUniqueId(const std::string& uniqueDisplayId)
    std::optional<DisplayViewport> getDisplayViewportByUniqueId(const std::string& uniqueDisplayId)
+26 −4
Original line number Original line Diff line number Diff line
@@ -28,10 +28,20 @@ namespace android {


// --- Static Definitions ---
// --- Static Definitions ---


static int32_t rotateKeyCode(int32_t keyCode, ui::Rotation orientation) {
static int32_t rotateKeyCode(int32_t keyCode, ui::Rotation orientation, int rotationMapOffset) {
    static constexpr int32_t KEYCODE_ROTATION_MAP[][4] = {
    static constexpr int32_t KEYCODE_ROTATION_MAP[][4] = {
            // key codes enumerated counter-clockwise with the original (unrotated) key first
            // key codes enumerated counter-clockwise with the original (unrotated) key first
            // no rotation,        90 degree rotation,  180 degree rotation, 270 degree rotation
            // no rotation,        90 degree rotation,  180 degree rotation, 270 degree rotation

            // volume keys - tablet
            {AKEYCODE_VOLUME_UP, AKEYCODE_VOLUME_UP, AKEYCODE_VOLUME_DOWN, AKEYCODE_VOLUME_DOWN},
            {AKEYCODE_VOLUME_DOWN, AKEYCODE_VOLUME_DOWN, AKEYCODE_VOLUME_UP, AKEYCODE_VOLUME_UP},

            // volume keys - phone or hybrid
            {AKEYCODE_VOLUME_UP, AKEYCODE_VOLUME_DOWN, AKEYCODE_VOLUME_DOWN, AKEYCODE_VOLUME_UP},
            {AKEYCODE_VOLUME_DOWN, AKEYCODE_VOLUME_UP, AKEYCODE_VOLUME_UP, AKEYCODE_VOLUME_DOWN},

            // dpad keys - common
            {AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT},
            {AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT},
            {AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_DOWN},
            {AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_DOWN},
            {AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_RIGHT},
            {AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_RIGHT},
@@ -45,9 +55,12 @@ static int32_t rotateKeyCode(int32_t keyCode, ui::Rotation orientation) {
            {AKEYCODE_SYSTEM_NAVIGATION_LEFT, AKEYCODE_SYSTEM_NAVIGATION_DOWN,
            {AKEYCODE_SYSTEM_NAVIGATION_LEFT, AKEYCODE_SYSTEM_NAVIGATION_DOWN,
             AKEYCODE_SYSTEM_NAVIGATION_RIGHT, AKEYCODE_SYSTEM_NAVIGATION_UP},
             AKEYCODE_SYSTEM_NAVIGATION_RIGHT, AKEYCODE_SYSTEM_NAVIGATION_UP},
    };
    };
    static const size_t KEYCODE_ROTATION_MAP_SIZE =
            sizeof(KEYCODE_ROTATION_MAP) / sizeof(KEYCODE_ROTATION_MAP[0]);


    if (orientation != ui::ROTATION_0) {
    if (orientation != ui::ROTATION_0) {
        for (const auto& rotation : KEYCODE_ROTATION_MAP) {
        for (size_t i = rotationMapOffset; i < KEYCODE_ROTATION_MAP_SIZE; i++) {
            const auto& rotation = KEYCODE_ROTATION_MAP[i];
            if (rotation[static_cast<size_t>(ui::ROTATION_0)] == keyCode) {
            if (rotation[static_cast<size_t>(ui::ROTATION_0)] == keyCode) {
                return rotation[static_cast<size_t>(orientation)];
                return rotation[static_cast<size_t>(orientation)];
            }
            }
@@ -200,6 +213,14 @@ std::list<NotifyArgs> KeyboardInputMapper::reconfigure(nsecs_t when,
            bumpGeneration();
            bumpGeneration();
        }
        }
    }
    }

    if (!changes.any() || changes.test(InputReaderConfiguration::Change::VOLUME_KEYS_ROTATION)) {
        // mode 0 (disabled) ~ offset 4
        // mode 1 (phone) ~ offset 2
        // mode 2 (tablet) ~ offset 0
        mRotationMapOffset = 4 - 2 * config.volumeKeysRotationMode;
    }

    return out;
    return out;
}
}


@@ -215,7 +236,8 @@ bool KeyboardInputMapper::updateKeyboardLayoutOverlay() {


void KeyboardInputMapper::configureParameters() {
void KeyboardInputMapper::configureParameters() {
    const PropertyMap& config = getDeviceContext().getConfiguration();
    const PropertyMap& config = getDeviceContext().getConfiguration();
    mParameters.orientationAware = config.getBool("keyboard.orientationAware").value_or(false);
    mParameters.orientationAware = config.getBool("keyboard.orientationAware").value_or(
            !getDeviceContext().isExternal());
    mParameters.handlesKeyRepeat = config.getBool("keyboard.handlesKeyRepeat").value_or(false);
    mParameters.handlesKeyRepeat = config.getBool("keyboard.handlesKeyRepeat").value_or(false);
    mParameters.doNotWakeByDefault = config.getBool("keyboard.doNotWakeByDefault").value_or(false);
    mParameters.doNotWakeByDefault = config.getBool("keyboard.doNotWakeByDefault").value_or(false);
}
}
@@ -273,7 +295,7 @@ std::list<NotifyArgs> KeyboardInputMapper::processKey(nsecs_t when, nsecs_t read
    if (down) {
    if (down) {
        // Rotate key codes according to orientation if needed.
        // Rotate key codes according to orientation if needed.
        if (mParameters.orientationAware) {
        if (mParameters.orientationAware) {
            keyCode = rotateKeyCode(keyCode, getOrientation());
            keyCode = rotateKeyCode(keyCode, getOrientation(), mRotationMapOffset);
        }
        }


        // Add key down.
        // Add key down.
+2 −0
Original line number Original line Diff line number Diff line
@@ -63,6 +63,8 @@ private:
    uint32_t mSource{};
    uint32_t mSource{};
    std::optional<KeyboardLayoutInfo> mKeyboardLayoutInfo;
    std::optional<KeyboardLayoutInfo> mKeyboardLayoutInfo;


    int32_t mRotationMapOffset; // determines if and how volume keys rotate

    std::vector<KeyDown> mKeyDowns{}; // keys that are down
    std::vector<KeyDown> mKeyDowns{}; // keys that are down
    int32_t mMetaState{};
    int32_t mMetaState{};