Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 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> |
Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 22 | #include <input/InputEventLabels.h> |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 23 | #include <utils/Errors.h> |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 24 | #include <utils/PropertyMap.h> |
| 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | enum { |
| 29 | /* Device id of the built in keyboard. */ |
| 30 | DEVICE_ID_BUILT_IN_KEYBOARD = 0, |
| 31 | |
| 32 | /* Device id of a generic virtual keyboard with a full layout that can be used |
| 33 | * to synthesize key events. */ |
| 34 | DEVICE_ID_VIRTUAL_KEYBOARD = -1, |
| 35 | }; |
| 36 | |
| 37 | class KeyLayoutMap; |
| 38 | class KeyCharacterMap; |
| 39 | |
| 40 | /** |
| 41 | * Loads the key layout map and key character map for a keyboard device. |
| 42 | */ |
| 43 | class KeyMap { |
| 44 | public: |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 45 | std::string keyLayoutFile; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 46 | sp<KeyLayoutMap> keyLayoutMap; |
| 47 | |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 48 | std::string keyCharacterMapFile; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 49 | sp<KeyCharacterMap> keyCharacterMap; |
| 50 | |
| 51 | KeyMap(); |
| 52 | ~KeyMap(); |
| 53 | |
| 54 | status_t load(const InputDeviceIdentifier& deviceIdenfier, |
| 55 | const PropertyMap* deviceConfiguration); |
| 56 | |
| 57 | inline bool haveKeyLayout() const { |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 58 | return !keyLayoutFile.empty(); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | inline bool haveKeyCharacterMap() const { |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 62 | return !keyCharacterMapFile.empty(); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | inline bool isComplete() const { |
| 66 | return haveKeyLayout() && haveKeyCharacterMap(); |
| 67 | } |
| 68 | |
| 69 | private: |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 70 | bool probeKeyMap(const InputDeviceIdentifier& deviceIdentifier, const std::string& name); |
| 71 | status_t loadKeyLayout(const InputDeviceIdentifier& deviceIdentifier, const std::string& name); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 72 | status_t loadKeyCharacterMap(const InputDeviceIdentifier& deviceIdentifier, |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 73 | const std::string& name); |
| 74 | std::string getPath(const InputDeviceIdentifier& deviceIdentifier, |
| 75 | const std::string& name, InputDeviceConfigurationFileType type); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | /** |
| 79 | * Returns true if the keyboard is eligible for use as a built-in keyboard. |
| 80 | */ |
| 81 | extern bool isEligibleBuiltInKeyboard(const InputDeviceIdentifier& deviceIdentifier, |
| 82 | const PropertyMap* deviceConfiguration, const KeyMap* keyMap); |
| 83 | |
| 84 | /** |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 85 | * Updates a meta state field when a key is pressed or released. |
| 86 | */ |
| 87 | extern int32_t updateMetaState(int32_t keyCode, bool down, int32_t oldMetaState); |
| 88 | |
| 89 | /** |
Dmitry Torokhov | 115f93e | 2015-09-17 18:04:50 -0700 | [diff] [blame] | 90 | * Normalizes the meta state such that if either the left or right modifier |
| 91 | * meta state bits are set then the result will also include the universal |
| 92 | * bit for that modifier. |
| 93 | */ |
| 94 | extern int32_t normalizeMetaState(int32_t oldMetaState); |
| 95 | |
| 96 | /** |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 97 | * Returns true if a key is a meta key like ALT or CAPS_LOCK. |
| 98 | */ |
| 99 | extern bool isMetaKey(int32_t keyCode); |
| 100 | |
| 101 | } // namespace android |
| 102 | |
| 103 | #endif // _LIBINPUT_KEYBOARD_H |