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