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