1 /*
2  * Copyright (C) 2010 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 #pragma once
18 
19 #include <input/Input.h>
20 #include <input/InputDevice.h>
21 #include <input/InputEventLabels.h>
22 #include <input/PropertyMap.h>
23 #include <utils/Errors.h>
24 
25 namespace android {
26 
27 class KeyLayoutMap;
28 class KeyCharacterMap;
29 
30 /**
31  * Loads the key layout map and key character map for a keyboard device.
32  */
33 class KeyMap {
34 public:
35     std::string keyLayoutFile;
36     std::shared_ptr<KeyLayoutMap> keyLayoutMap;
37 
38     std::string keyCharacterMapFile;
39     std::shared_ptr<KeyCharacterMap> keyCharacterMap;
40 
41     KeyMap();
42     ~KeyMap();
43 
44     status_t load(const InputDeviceIdentifier& deviceIdenfier,
45             const PropertyMap* deviceConfiguration);
46 
haveKeyLayout()47     inline bool haveKeyLayout() const {
48         return !keyLayoutFile.empty();
49     }
50 
haveKeyCharacterMap()51     inline bool haveKeyCharacterMap() const {
52         return !keyCharacterMapFile.empty();
53     }
54 
isComplete()55     inline bool isComplete() const {
56         return haveKeyLayout() && haveKeyCharacterMap();
57     }
58 
59 private:
60     bool probeKeyMap(const InputDeviceIdentifier& deviceIdentifier, const std::string& name);
61     status_t loadKeyLayout(const InputDeviceIdentifier& deviceIdentifier, const std::string& name);
62     status_t loadKeyCharacterMap(const InputDeviceIdentifier& deviceIdentifier,
63                                  const std::string& name);
64 };
65 
66 /**
67  * Returns true if the keyboard is eligible for use as a built-in keyboard.
68  */
69 extern bool isEligibleBuiltInKeyboard(const InputDeviceIdentifier& deviceIdentifier,
70         const PropertyMap* deviceConfiguration, const KeyMap* keyMap);
71 
72 /**
73  * Updates a meta state field when a key is pressed or released.
74  */
75 extern int32_t updateMetaState(int32_t keyCode, bool down, int32_t oldMetaState);
76 
77 /**
78  * Normalizes the meta state such that if either the left or right modifier
79  * meta state bits are set then the result will also include the universal
80  * bit for that modifier.
81  */
82 extern int32_t normalizeMetaState(int32_t oldMetaState);
83 
84 /**
85  * Returns true if a key is a meta key like ALT or CAPS_LOCK.
86  */
87 extern bool isMetaKey(int32_t keyCode);
88 
89 } // namespace android
90