diff options
| author | 2024-09-18 22:55:45 +0000 | |
|---|---|---|
| committer | 2024-10-08 20:13:21 +0000 | |
| commit | d77178e48e652d5de8eee5d2db400e13e5dcf547 (patch) | |
| tree | 16cd331385045f7edb3977eab119522982081c96 /services/inputflinger/reader | |
| parent | 2ac7e8169faa060ac33deb48847d07fb9fc4e680 (diff) | |
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
Diffstat (limited to 'services/inputflinger/reader')
3 files changed, 13 insertions, 2 deletions
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(); }; |