blob: ca41712f48c71989e4fbf417370f588ca1300694 [file] [log] [blame]
Prabir Pradhanbaa5c822019-08-30 15:27:05 -07001/*
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
17#ifndef _UI_INPUTREADER_KEYBOARD_INPUT_MAPPER_H
18#define _UI_INPUTREADER_KEYBOARD_INPUT_MAPPER_H
19
20#include "InputMapper.h"
21
22namespace android {
23
24class KeyboardInputMapper : public InputMapper {
25public:
Nathaniel R. Lewis26ec2222020-01-10 16:30:54 -080026 KeyboardInputMapper(InputDeviceContext& deviceContext, uint32_t source, int32_t keyboardType);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070027 virtual ~KeyboardInputMapper();
28
Prabir Pradhanf1fbf9e2019-09-04 16:29:40 -070029 virtual uint32_t getSources() override;
30 virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo) override;
31 virtual void dump(std::string& dump) override;
32 virtual void configure(nsecs_t when, const InputReaderConfiguration* config,
33 uint32_t changes) override;
34 virtual void reset(nsecs_t when) override;
35 virtual void process(const RawEvent* rawEvent) override;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070036
Prabir Pradhanf1fbf9e2019-09-04 16:29:40 -070037 virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode) override;
38 virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode) override;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070039 virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
Prabir Pradhanf1fbf9e2019-09-04 16:29:40 -070040 const int32_t* keyCodes, uint8_t* outFlags) override;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070041
Prabir Pradhanf1fbf9e2019-09-04 16:29:40 -070042 virtual int32_t getMetaState() override;
43 virtual void updateMetaState(int32_t keyCode) override;
44 virtual std::optional<int32_t> getAssociatedDisplayId() override;
arthurhungc903df12020-08-11 15:08:42 +080045 virtual void updateLedState(bool reset);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070046
47private:
48 // The current viewport.
49 std::optional<DisplayViewport> mViewport;
50
51 struct KeyDown {
52 int32_t keyCode;
53 int32_t scanCode;
54 };
55
56 uint32_t mSource;
57 int32_t mKeyboardType;
58
59 std::vector<KeyDown> mKeyDowns; // keys that are down
60 int32_t mMetaState;
61 nsecs_t mDownTime; // time of most recent key down
62
63 int32_t mCurrentHidUsage; // most recent HID usage seen this packet, or 0 if none
64
65 struct LedState {
66 bool avail; // led is available
67 bool on; // we think the led is currently on
68 };
69 LedState mCapsLockLedState;
70 LedState mNumLockLedState;
71 LedState mScrollLockLedState;
72
73 // Immutable configuration parameters.
74 struct Parameters {
75 bool orientationAware;
76 bool handlesKeyRepeat;
Powei Fengd041c5d2019-05-03 17:11:33 -070077 bool doNotWakeByDefault;
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070078 } mParameters;
79
80 void configureParameters();
81 void dumpParameters(std::string& dump);
82
83 int32_t getOrientation();
84 int32_t getDisplayId();
85
86 bool isKeyboardOrGamepadKey(int32_t scanCode);
87 bool isMediaKey(int32_t keyCode);
88
Siarhei Vishniakou58ba3d12021-02-11 01:31:07 +000089 void processKey(nsecs_t when, nsecs_t readTime, bool down, int32_t scanCode, int32_t usageCode);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070090
91 bool updateMetaStateIfNeeded(int32_t keyCode, bool down);
92
93 ssize_t findKeyDown(int32_t scanCode);
94
95 void resetLedState();
96 void initializeLedState(LedState& ledState, int32_t led);
Prabir Pradhanbaa5c822019-08-30 15:27:05 -070097 void updateLedStateForModifier(LedState& ledState, int32_t led, int32_t modifier, bool reset);
98 std::optional<DisplayViewport> findViewport(nsecs_t when,
99 const InputReaderConfiguration* config);
100};
101
102} // namespace android
103
104#endif // _UI_INPUTREADER_KEYBOARD_INPUT_MAPPER_H