From d77178e48e652d5de8eee5d2db400e13e5dcf547 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Wed, 18 Sep 2024 22:55:45 +0000 Subject: Mouse: Add support to swap mouse primary button Bug: 359349392 Bug: 352598211 Test: atest CursorInputMapperUnitTest Flag: com.android.hardware.input.mouse_swap_primary_button Change-Id: I37d70bc0ce37fc0832e6733a0a1c8936cab36ab1 --- services/inputflinger/reader/mapper/CursorInputMapper.cpp | 1 + .../reader/mapper/accumulator/CursorButtonAccumulator.cpp | 10 ++++++++-- .../reader/mapper/accumulator/CursorButtonAccumulator.h | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-) (limited to 'services/inputflinger/reader') diff --git a/services/inputflinger/reader/mapper/CursorInputMapper.cpp b/services/inputflinger/reader/mapper/CursorInputMapper.cpp index 302caa75a0..630bd9bcd8 100644 --- a/services/inputflinger/reader/mapper/CursorInputMapper.cpp +++ b/services/inputflinger/reader/mapper/CursorInputMapper.cpp @@ -548,6 +548,7 @@ void CursorInputMapper::configureOnChangeDisplayInfo(const InputReaderConfigurat void CursorInputMapper::configureOnChangeMouseSettings(const InputReaderConfiguration& config) { mMouseReverseVerticalScrolling = config.mouseReverseVerticalScrollingEnabled; + mCursorButtonAccumulator.setSwapLeftRightButtons(config.mouseSwapPrimaryButtonEnabled); } } // namespace android diff --git a/services/inputflinger/reader/mapper/accumulator/CursorButtonAccumulator.cpp b/services/inputflinger/reader/mapper/accumulator/CursorButtonAccumulator.cpp index 9e722d41e7..456562c196 100644 --- a/services/inputflinger/reader/mapper/accumulator/CursorButtonAccumulator.cpp +++ b/services/inputflinger/reader/mapper/accumulator/CursorButtonAccumulator.cpp @@ -47,6 +47,10 @@ void CursorButtonAccumulator::clearButtons() { mBtnTask = 0; } +void CursorButtonAccumulator::setSwapLeftRightButtons(bool shouldSwap) { + mSwapLeftRightButtons = shouldSwap; +} + void CursorButtonAccumulator::process(const RawEvent& rawEvent) { if (rawEvent.type == EV_KEY) { switch (rawEvent.code) { @@ -81,10 +85,12 @@ void CursorButtonAccumulator::process(const RawEvent& rawEvent) { uint32_t CursorButtonAccumulator::getButtonState() const { uint32_t result = 0; if (mBtnLeft) { - result |= AMOTION_EVENT_BUTTON_PRIMARY; + result |= mSwapLeftRightButtons ? AMOTION_EVENT_BUTTON_SECONDARY + : AMOTION_EVENT_BUTTON_PRIMARY; } if (mBtnRight) { - result |= AMOTION_EVENT_BUTTON_SECONDARY; + result |= mSwapLeftRightButtons ? AMOTION_EVENT_BUTTON_PRIMARY + : AMOTION_EVENT_BUTTON_SECONDARY; } if (mBtnMiddle) { result |= AMOTION_EVENT_BUTTON_TERTIARY; diff --git a/services/inputflinger/reader/mapper/accumulator/CursorButtonAccumulator.h b/services/inputflinger/reader/mapper/accumulator/CursorButtonAccumulator.h index 256b2bb994..69900309a5 100644 --- a/services/inputflinger/reader/mapper/accumulator/CursorButtonAccumulator.h +++ b/services/inputflinger/reader/mapper/accumulator/CursorButtonAccumulator.h @@ -41,6 +41,8 @@ public: inline bool isExtraPressed() const { return mBtnExtra; } inline bool isTaskPressed() const { return mBtnTask; } + void setSwapLeftRightButtons(bool shouldSwap); + private: bool mBtnLeft; bool mBtnRight; @@ -51,6 +53,8 @@ private: bool mBtnExtra; bool mBtnTask; + bool mSwapLeftRightButtons = false; + void clearButtons(); }; -- cgit v1.2.3-59-g8ed1b