Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef _UI_INPUTREADER_KEYBOARD_INPUT_MAPPER_H |
| 18 | #define _UI_INPUTREADER_KEYBOARD_INPUT_MAPPER_H |
| 19 | |
| 20 | #include "InputMapper.h" |
| 21 | |
| 22 | namespace android { |
| 23 | |
| 24 | class KeyboardInputMapper : public InputMapper { |
| 25 | public: |
| 26 | KeyboardInputMapper(InputDevice* device, uint32_t source, int32_t keyboardType); |
| 27 | virtual ~KeyboardInputMapper(); |
| 28 | |
| 29 | virtual uint32_t getSources(); |
| 30 | virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo); |
| 31 | virtual void dump(std::string& dump); |
| 32 | virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes); |
| 33 | virtual void reset(nsecs_t when); |
| 34 | virtual void process(const RawEvent* rawEvent); |
| 35 | |
| 36 | virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode); |
| 37 | virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode); |
| 38 | virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, |
| 39 | const int32_t* keyCodes, uint8_t* outFlags); |
| 40 | |
| 41 | virtual int32_t getMetaState(); |
| 42 | virtual void updateMetaState(int32_t keyCode); |
| 43 | virtual std::optional<int32_t> getAssociatedDisplayId(); |
| 44 | |
| 45 | private: |
| 46 | // The current viewport. |
| 47 | std::optional<DisplayViewport> mViewport; |
| 48 | |
| 49 | struct KeyDown { |
| 50 | int32_t keyCode; |
| 51 | int32_t scanCode; |
| 52 | }; |
| 53 | |
| 54 | uint32_t mSource; |
| 55 | int32_t mKeyboardType; |
| 56 | |
| 57 | std::vector<KeyDown> mKeyDowns; // keys that are down |
| 58 | int32_t mMetaState; |
| 59 | nsecs_t mDownTime; // time of most recent key down |
| 60 | |
| 61 | int32_t mCurrentHidUsage; // most recent HID usage seen this packet, or 0 if none |
| 62 | |
| 63 | struct LedState { |
| 64 | bool avail; // led is available |
| 65 | bool on; // we think the led is currently on |
| 66 | }; |
| 67 | LedState mCapsLockLedState; |
| 68 | LedState mNumLockLedState; |
| 69 | LedState mScrollLockLedState; |
| 70 | |
| 71 | // Immutable configuration parameters. |
| 72 | struct Parameters { |
| 73 | bool orientationAware; |
| 74 | bool handlesKeyRepeat; |
| 75 | } mParameters; |
| 76 | |
| 77 | void configureParameters(); |
| 78 | void dumpParameters(std::string& dump); |
| 79 | |
| 80 | int32_t getOrientation(); |
| 81 | int32_t getDisplayId(); |
| 82 | |
| 83 | bool isKeyboardOrGamepadKey(int32_t scanCode); |
| 84 | bool isMediaKey(int32_t keyCode); |
| 85 | |
| 86 | void processKey(nsecs_t when, bool down, int32_t scanCode, int32_t usageCode); |
| 87 | |
| 88 | bool updateMetaStateIfNeeded(int32_t keyCode, bool down); |
| 89 | |
| 90 | ssize_t findKeyDown(int32_t scanCode); |
| 91 | |
| 92 | void resetLedState(); |
| 93 | void initializeLedState(LedState& ledState, int32_t led); |
| 94 | void updateLedState(bool reset); |
| 95 | void updateLedStateForModifier(LedState& ledState, int32_t led, int32_t modifier, bool reset); |
| 96 | std::optional<DisplayViewport> findViewport(nsecs_t when, |
| 97 | const InputReaderConfiguration* config); |
| 98 | }; |
| 99 | |
| 100 | } // namespace android |
| 101 | |
| 102 | #endif // _UI_INPUTREADER_KEYBOARD_INPUT_MAPPER_H |