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 | |
Prabir Pradhan | 84395e6 | 2022-10-26 19:52:00 +0000 | [diff] [blame] | 19 | #include "HidUsageAccumulator.h" |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 20 | #include "InputMapper.h" |
| 21 | |
| 22 | namespace android { |
| 23 | |
| 24 | class KeyboardInputMapper : public InputMapper { |
| 25 | public: |
Arpit Singh | 8e6fb25 | 2023-04-06 11:49:17 +0000 | [diff] [blame] | 26 | KeyboardInputMapper(InputDeviceContext& deviceContext, |
| 27 | const InputReaderConfiguration& readerConfig, uint32_t source, |
| 28 | int32_t keyboardType); |
Prabir Pradhan | 2197cb4 | 2022-10-11 02:56:14 +0000 | [diff] [blame] | 29 | ~KeyboardInputMapper() override = default; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 30 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 31 | uint32_t getSources() const override; |
Harry Cutts | d02ea10 | 2023-03-17 18:21:30 +0000 | [diff] [blame] | 32 | void populateDeviceInfo(InputDeviceInfo& deviceInfo) override; |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 33 | void dump(std::string& dump) override; |
Arpit Singh | 4be4eef | 2023-03-28 14:26:01 +0000 | [diff] [blame] | 34 | [[nodiscard]] std::list<NotifyArgs> reconfigure(nsecs_t when, |
Arpit Singh | ed6c3de | 2023-04-05 19:24:37 +0000 | [diff] [blame] | 35 | const InputReaderConfiguration& config, |
Prabir Pradhan | 4bf6d45 | 2023-04-18 21:26:56 +0000 | [diff] [blame^] | 36 | ConfigurationChanges changes) override; |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 37 | [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when) override; |
| 38 | [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvent) override; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 39 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 40 | int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode) override; |
| 41 | int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode) override; |
| 42 | bool markSupportedKeyCodes(uint32_t sourceMask, const std::vector<int32_t>& keyCodes, |
| 43 | uint8_t* outFlags) override; |
| 44 | int32_t getKeyCodeForKeyLocation(int32_t locationKeyCode) const override; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 45 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 46 | int32_t getMetaState() override; |
| 47 | bool updateMetaState(int32_t keyCode) override; |
| 48 | std::optional<int32_t> getAssociatedDisplayId() override; |
| 49 | void updateLedState(bool reset) override; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 50 | |
| 51 | private: |
| 52 | // The current viewport. |
Prabir Pradhan | 2197cb4 | 2022-10-11 02:56:14 +0000 | [diff] [blame] | 53 | std::optional<DisplayViewport> mViewport{}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 54 | |
| 55 | struct KeyDown { |
Prabir Pradhan | 2197cb4 | 2022-10-11 02:56:14 +0000 | [diff] [blame] | 56 | nsecs_t downTime{}; |
| 57 | int32_t keyCode{}; |
| 58 | int32_t scanCode{}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
Prabir Pradhan | 2197cb4 | 2022-10-11 02:56:14 +0000 | [diff] [blame] | 61 | uint32_t mSource{}; |
| 62 | int32_t mKeyboardType{}; |
Zixuan Qu | fecb606 | 2022-11-12 04:44:31 +0000 | [diff] [blame] | 63 | std::optional<KeyboardLayoutInfo> mKeyboardLayoutInfo; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 64 | |
Prabir Pradhan | 2197cb4 | 2022-10-11 02:56:14 +0000 | [diff] [blame] | 65 | std::vector<KeyDown> mKeyDowns{}; // keys that are down |
| 66 | int32_t mMetaState{}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 67 | |
Prabir Pradhan | 84395e6 | 2022-10-26 19:52:00 +0000 | [diff] [blame] | 68 | HidUsageAccumulator mHidUsageAccumulator; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 69 | |
| 70 | struct LedState { |
Prabir Pradhan | 2197cb4 | 2022-10-11 02:56:14 +0000 | [diff] [blame] | 71 | bool avail{}; // led is available |
| 72 | bool on{}; // we think the led is currently on |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 73 | }; |
Prabir Pradhan | 2197cb4 | 2022-10-11 02:56:14 +0000 | [diff] [blame] | 74 | LedState mCapsLockLedState{}; |
| 75 | LedState mNumLockLedState{}; |
| 76 | LedState mScrollLockLedState{}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 77 | |
| 78 | // Immutable configuration parameters. |
| 79 | struct Parameters { |
Prabir Pradhan | 2197cb4 | 2022-10-11 02:56:14 +0000 | [diff] [blame] | 80 | bool orientationAware{}; |
| 81 | bool handlesKeyRepeat{}; |
| 82 | bool doNotWakeByDefault{}; |
| 83 | } mParameters{}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 84 | |
| 85 | void configureParameters(); |
Prabir Pradhan | 2197cb4 | 2022-10-11 02:56:14 +0000 | [diff] [blame] | 86 | void dumpParameters(std::string& dump) const; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 87 | |
Michael Wright | a9cf419 | 2022-12-01 23:46:39 +0000 | [diff] [blame] | 88 | ui::Rotation getOrientation(); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 89 | int32_t getDisplayId(); |
| 90 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 91 | [[nodiscard]] std::list<NotifyArgs> processKey(nsecs_t when, nsecs_t readTime, bool down, |
| 92 | int32_t scanCode, int32_t usageCode); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 93 | |
| 94 | bool updateMetaStateIfNeeded(int32_t keyCode, bool down); |
| 95 | |
Prabir Pradhan | 2197cb4 | 2022-10-11 02:56:14 +0000 | [diff] [blame] | 96 | std::optional<size_t> findKeyDownIndex(int32_t scanCode); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 97 | |
| 98 | void resetLedState(); |
| 99 | void initializeLedState(LedState& ledState, int32_t led); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 100 | void updateLedStateForModifier(LedState& ledState, int32_t led, int32_t modifier, bool reset); |
Arpit Singh | ed6c3de | 2023-04-05 19:24:37 +0000 | [diff] [blame] | 101 | std::optional<DisplayViewport> findViewport(const InputReaderConfiguration& readerConfig); |
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 |