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