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

Commit baa5c824 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

Split InputReader into multiple files

This CL:
1) Moves commonly used macros and shared definitions into Macros.h,
which is included as the first #include statement in the files that
require it.
2) Creates InputReaderContext.h and moves the context definition outside
the InputReader.h file.
3) Moves InputDevice, InputMapper, StylusState, and all of the
individual InputMappers into their own header and cpp file combinations.
4) Moves all Accumulator classes that are shared between multiple
InputMappers into their own header and cpp file combinations. The
definitions of Accumulators that are unique to a mapper are kept in the
header file of the mapper.
5) Moves constants and static methods that were shared between the
TouchInputMapper and CursorInputMapper to
TouchCursorInputMapperCommon.h.
6) Creates an 'include' directory, as well as a header library build rule,
to hold all the header files required by InputReader_test.cpp.
7) Runs clang-format on the newly create files to fix formatting
inconsistencies.

Bug: 140139676
Test: atest inputflinger_tests
Test: Touch, keyboard, trackpad, and mouse works on crosshatch
Change-Id: Ib1ac871c7f4199729bf6d0e6a53ed907af318986
parent da7c00cc
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -22,10 +22,26 @@ cc_library_shared {
    defaults: ["inputflinger_defaults"],

    srcs: [
        "CursorButtonAccumulator.cpp",
        "CursorInputMapper.cpp",
        "CursorScrollAccumulator.cpp",
        "EventHub.cpp",
        "ExternalStylusInputMapper.cpp",
        "InputDevice.cpp",
        "InputMapper.cpp",
        "InputReader.cpp",
        "InputReaderFactory.cpp",
        "JoystickInputMapper.cpp",
        "KeyboardInputMapper.cpp",
        "MultiTouchInputMapper.cpp",
        "RotaryEncoderInputMapper.cpp",
        "SingleTouchInputMapper.cpp",
        "SingleTouchMotionAccumulator.cpp",
        "SwitchInputMapper.cpp",
        "TouchButtonAccumulator.cpp",
        "TouchInputMapper.cpp",
        "TouchVideoDevice.cpp",
        "VibratorInputMapper.cpp",
    ],

    shared_libs: [
+101 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "CursorButtonAccumulator.h"

#include "EventHub.h"
#include "InputDevice.h"

namespace android {

CursorButtonAccumulator::CursorButtonAccumulator() {
    clearButtons();
}

void CursorButtonAccumulator::reset(InputDevice* device) {
    mBtnLeft = device->isKeyPressed(BTN_LEFT);
    mBtnRight = device->isKeyPressed(BTN_RIGHT);
    mBtnMiddle = device->isKeyPressed(BTN_MIDDLE);
    mBtnBack = device->isKeyPressed(BTN_BACK);
    mBtnSide = device->isKeyPressed(BTN_SIDE);
    mBtnForward = device->isKeyPressed(BTN_FORWARD);
    mBtnExtra = device->isKeyPressed(BTN_EXTRA);
    mBtnTask = device->isKeyPressed(BTN_TASK);
}

void CursorButtonAccumulator::clearButtons() {
    mBtnLeft = 0;
    mBtnRight = 0;
    mBtnMiddle = 0;
    mBtnBack = 0;
    mBtnSide = 0;
    mBtnForward = 0;
    mBtnExtra = 0;
    mBtnTask = 0;
}

void CursorButtonAccumulator::process(const RawEvent* rawEvent) {
    if (rawEvent->type == EV_KEY) {
        switch (rawEvent->code) {
            case BTN_LEFT:
                mBtnLeft = rawEvent->value;
                break;
            case BTN_RIGHT:
                mBtnRight = rawEvent->value;
                break;
            case BTN_MIDDLE:
                mBtnMiddle = rawEvent->value;
                break;
            case BTN_BACK:
                mBtnBack = rawEvent->value;
                break;
            case BTN_SIDE:
                mBtnSide = rawEvent->value;
                break;
            case BTN_FORWARD:
                mBtnForward = rawEvent->value;
                break;
            case BTN_EXTRA:
                mBtnExtra = rawEvent->value;
                break;
            case BTN_TASK:
                mBtnTask = rawEvent->value;
                break;
        }
    }
}

uint32_t CursorButtonAccumulator::getButtonState() const {
    uint32_t result = 0;
    if (mBtnLeft) {
        result |= AMOTION_EVENT_BUTTON_PRIMARY;
    }
    if (mBtnRight) {
        result |= AMOTION_EVENT_BUTTON_SECONDARY;
    }
    if (mBtnMiddle) {
        result |= AMOTION_EVENT_BUTTON_TERTIARY;
    }
    if (mBtnBack || mBtnSide) {
        result |= AMOTION_EVENT_BUTTON_BACK;
    }
    if (mBtnForward || mBtnExtra) {
        result |= AMOTION_EVENT_BUTTON_FORWARD;
    }
    return result;
}

} // namespace android
+479 −0

File added.

Preview size limit exceeded, changes collapsed.

+59 −0

File added.

Preview size limit exceeded, changes collapsed.

+92 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading