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 | |
Prabir Pradhan | 4810866 | 2022-09-09 21:22:04 +0000 | [diff] [blame] | 17 | #pragma once |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 18 | |
| 19 | #include "InputMapper.h" |
| 20 | |
| 21 | namespace android { |
| 22 | |
| 23 | class KeyboardInputMapper : public InputMapper { |
| 24 | public: |
Nathaniel R. Lewis | 26ec222 | 2020-01-10 16:30:54 -0800 | [diff] [blame] | 25 | KeyboardInputMapper(InputDeviceContext& deviceContext, uint32_t source, int32_t keyboardType); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 26 | virtual ~KeyboardInputMapper(); |
| 27 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame^] | 28 | uint32_t getSources() const override; |
| 29 | void populateDeviceInfo(InputDeviceInfo* deviceInfo) override; |
| 30 | void dump(std::string& dump) override; |
| 31 | [[nodiscard]] std::list<NotifyArgs> configure(nsecs_t when, |
| 32 | const InputReaderConfiguration* config, |
| 33 | uint32_t changes) override; |
| 34 | [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when) override; |
| 35 | [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvent) override; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 36 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame^] | 37 | int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode) override; |
| 38 | int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode) override; |
| 39 | bool markSupportedKeyCodes(uint32_t sourceMask, const std::vector<int32_t>& keyCodes, |
| 40 | uint8_t* outFlags) override; |
| 41 | int32_t getKeyCodeForKeyLocation(int32_t locationKeyCode) const override; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 42 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame^] | 43 | int32_t getMetaState() override; |
| 44 | bool updateMetaState(int32_t keyCode) override; |
| 45 | std::optional<int32_t> getAssociatedDisplayId() override; |
| 46 | void updateLedState(bool reset) override; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 47 | |
| 48 | private: |
| 49 | // The current viewport. |
| 50 | std::optional<DisplayViewport> mViewport; |
| 51 | |
| 52 | struct KeyDown { |
Arthur Hung | 2141d54 | 2022-08-23 07:45:21 +0000 | [diff] [blame] | 53 | nsecs_t downTime; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 54 | int32_t keyCode; |
| 55 | int32_t scanCode; |
| 56 | }; |
| 57 | |
| 58 | uint32_t mSource; |
| 59 | int32_t mKeyboardType; |
| 60 | |
| 61 | std::vector<KeyDown> mKeyDowns; // keys that are down |
| 62 | int32_t mMetaState; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 63 | |
| 64 | int32_t mCurrentHidUsage; // most recent HID usage seen this packet, or 0 if none |
| 65 | |
| 66 | struct LedState { |
| 67 | bool avail; // led is available |
| 68 | bool on; // we think the led is currently on |
| 69 | }; |
| 70 | LedState mCapsLockLedState; |
| 71 | LedState mNumLockLedState; |
| 72 | LedState mScrollLockLedState; |
| 73 | |
| 74 | // Immutable configuration parameters. |
| 75 | struct Parameters { |
| 76 | bool orientationAware; |
| 77 | bool handlesKeyRepeat; |
Powei Feng | d041c5d | 2019-05-03 17:11:33 -0700 | [diff] [blame] | 78 | bool doNotWakeByDefault; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 79 | } mParameters; |
| 80 | |
| 81 | void configureParameters(); |
| 82 | void dumpParameters(std::string& dump); |
| 83 | |
| 84 | int32_t getOrientation(); |
| 85 | int32_t getDisplayId(); |
| 86 | |
| 87 | bool isKeyboardOrGamepadKey(int32_t scanCode); |
| 88 | bool isMediaKey(int32_t keyCode); |
| 89 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame^] | 90 | [[nodiscard]] std::list<NotifyArgs> processKey(nsecs_t when, nsecs_t readTime, bool down, |
| 91 | int32_t scanCode, int32_t usageCode); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 92 | |
| 93 | bool updateMetaStateIfNeeded(int32_t keyCode, bool down); |
| 94 | |
| 95 | ssize_t findKeyDown(int32_t scanCode); |
| 96 | |
| 97 | void resetLedState(); |
| 98 | void initializeLedState(LedState& ledState, int32_t led); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 99 | void updateLedStateForModifier(LedState& ledState, int32_t led, int32_t modifier, bool reset); |
| 100 | std::optional<DisplayViewport> findViewport(nsecs_t when, |
| 101 | const InputReaderConfiguration* config); |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame^] | 102 | [[nodiscard]] std::list<NotifyArgs> cancelAllDownKeys(nsecs_t when); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | } // namespace android |