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; |
| 30 | void populateDeviceInfo(InputDeviceInfo* deviceInfo) override; |
| 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{}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 61 | |
Prabir Pradhan | 2197cb4 | 2022-10-11 02:56:14 +0000 | [diff] [blame] | 62 | std::vector<KeyDown> mKeyDowns{}; // keys that are down |
| 63 | int32_t mMetaState{}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 64 | |
Prabir Pradhan | 84395e6 | 2022-10-26 19:52:00 +0000 | [diff] [blame^] | 65 | HidUsageAccumulator mHidUsageAccumulator; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 66 | |
| 67 | struct LedState { |
Prabir Pradhan | 2197cb4 | 2022-10-11 02:56:14 +0000 | [diff] [blame] | 68 | bool avail{}; // led is available |
| 69 | bool on{}; // we think the led is currently on |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 70 | }; |
Prabir Pradhan | 2197cb4 | 2022-10-11 02:56:14 +0000 | [diff] [blame] | 71 | LedState mCapsLockLedState{}; |
| 72 | LedState mNumLockLedState{}; |
| 73 | LedState mScrollLockLedState{}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 74 | |
| 75 | // Immutable configuration parameters. |
| 76 | struct Parameters { |
Prabir Pradhan | 2197cb4 | 2022-10-11 02:56:14 +0000 | [diff] [blame] | 77 | bool orientationAware{}; |
| 78 | bool handlesKeyRepeat{}; |
| 79 | bool doNotWakeByDefault{}; |
| 80 | } mParameters{}; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 81 | |
| 82 | void configureParameters(); |
Prabir Pradhan | 2197cb4 | 2022-10-11 02:56:14 +0000 | [diff] [blame] | 83 | void dumpParameters(std::string& dump) const; |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 84 | |
| 85 | int32_t getOrientation(); |
| 86 | int32_t getDisplayId(); |
| 87 | |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 88 | [[nodiscard]] std::list<NotifyArgs> processKey(nsecs_t when, nsecs_t readTime, bool down, |
| 89 | int32_t scanCode, int32_t usageCode); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 90 | |
| 91 | bool updateMetaStateIfNeeded(int32_t keyCode, bool down); |
| 92 | |
Prabir Pradhan | 2197cb4 | 2022-10-11 02:56:14 +0000 | [diff] [blame] | 93 | std::optional<size_t> findKeyDownIndex(int32_t scanCode); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 94 | |
| 95 | void resetLedState(); |
| 96 | void initializeLedState(LedState& ledState, int32_t led); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 97 | void updateLedStateForModifier(LedState& ledState, int32_t led, int32_t modifier, bool reset); |
Prabir Pradhan | 2197cb4 | 2022-10-11 02:56:14 +0000 | [diff] [blame] | 98 | std::optional<DisplayViewport> findViewport(const InputReaderConfiguration* config); |
Siarhei Vishniakou | 2935db7 | 2022-09-22 13:35:22 -0700 | [diff] [blame] | 99 | [[nodiscard]] std::list<NotifyArgs> cancelAllDownKeys(nsecs_t when); |
Prabir Pradhan | baa5c82 | 2019-08-30 15:27:05 -0700 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | } // namespace android |