| Jeff Brown | a3477c8 | 2010-11-10 16:03:06 -0800 | [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 _UI_KEYBOARD_H | 
|  | 18 | #define _UI_KEYBOARD_H | 
|  | 19 |  | 
|  | 20 | #include <ui/Input.h> | 
|  | 21 | #include <utils/Errors.h> | 
|  | 22 | #include <utils/String8.h> | 
| Jeff Brown | 6688837 | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 23 | #include <utils/PropertyMap.h> | 
| Jeff Brown | a3477c8 | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 24 |  | 
|  | 25 | namespace android { | 
|  | 26 |  | 
|  | 27 | enum { | 
|  | 28 | /* Device id of the built in keyboard. */ | 
|  | 29 | DEVICE_ID_BUILT_IN_KEYBOARD = 0, | 
|  | 30 |  | 
|  | 31 | /* Device id of a generic virtual keyboard with a full layout that can be used | 
|  | 32 | * to synthesize key events. */ | 
|  | 33 | DEVICE_ID_VIRTUAL_KEYBOARD = -1, | 
|  | 34 | }; | 
|  | 35 |  | 
| Jeff Brown | db36064 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 36 | class KeyLayoutMap; | 
|  | 37 | class KeyCharacterMap; | 
|  | 38 |  | 
|  | 39 | /** | 
|  | 40 | * Loads the key layout map and key character map for a keyboard device. | 
|  | 41 | */ | 
|  | 42 | class KeyMap { | 
|  | 43 | public: | 
| Jeff Brown | a3477c8 | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 44 | String8 keyLayoutFile; | 
| Jeff Brown | db36064 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 45 | KeyLayoutMap* keyLayoutMap; | 
|  | 46 |  | 
| Jeff Brown | a3477c8 | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 47 | String8 keyCharacterMapFile; | 
| Jeff Brown | db36064 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 48 | KeyCharacterMap* keyCharacterMap; | 
| Jeff Brown | a3477c8 | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 49 |  | 
| Jeff Brown | db36064 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 50 | KeyMap(); | 
|  | 51 | ~KeyMap(); | 
|  | 52 |  | 
|  | 53 | status_t load(const InputDeviceIdentifier& deviceIdenfier, | 
|  | 54 | const PropertyMap* deviceConfiguration); | 
|  | 55 |  | 
|  | 56 | inline bool haveKeyLayout() const { | 
|  | 57 | return !keyLayoutFile.isEmpty(); | 
| Jeff Brown | a3477c8 | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 58 | } | 
| Jeff Brown | 6688837 | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 59 |  | 
| Jeff Brown | db36064 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 60 | inline bool haveKeyCharacterMap() const { | 
|  | 61 | return !keyCharacterMapFile.isEmpty(); | 
| Jeff Brown | 6688837 | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 62 | } | 
| Jeff Brown | db36064 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 63 |  | 
|  | 64 | inline bool isComplete() const { | 
|  | 65 | return haveKeyLayout() && haveKeyCharacterMap(); | 
|  | 66 | } | 
|  | 67 |  | 
|  | 68 | private: | 
|  | 69 | bool probeKeyMap(const InputDeviceIdentifier& deviceIdentifier, const String8& name); | 
|  | 70 | status_t loadKeyLayout(const InputDeviceIdentifier& deviceIdentifier, const String8& name); | 
|  | 71 | status_t loadKeyCharacterMap(const InputDeviceIdentifier& deviceIdentifier, | 
|  | 72 | const String8& name); | 
|  | 73 | String8 getPath(const InputDeviceIdentifier& deviceIdentifier, | 
|  | 74 | const String8& name, InputDeviceConfigurationFileType type); | 
| Jeff Brown | a3477c8 | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 75 | }; | 
|  | 76 |  | 
|  | 77 | /** | 
| Jeff Brown | db36064 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 78 | * Returns true if the keyboard is eligible for use as a built-in keyboard. | 
| Jeff Brown | a3477c8 | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 79 | */ | 
| Jeff Brown | db36064 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 80 | extern bool isEligibleBuiltInKeyboard(const InputDeviceIdentifier& deviceIdentifier, | 
|  | 81 | const PropertyMap* deviceConfiguration, const KeyMap* keyMap); | 
| Jeff Brown | a3477c8 | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 82 |  | 
|  | 83 | /** | 
|  | 84 | * Sets keyboard system properties. | 
|  | 85 | */ | 
| Jeff Brown | db36064 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 86 | extern void setKeyboardProperties(int32_t deviceId, const InputDeviceIdentifier& deviceIdentifier, | 
|  | 87 | const String8& keyLayoutFile, const String8& keyCharacterMapFile); | 
| Jeff Brown | a3477c8 | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 88 |  | 
|  | 89 | /** | 
|  | 90 | * Clears keyboard system properties. | 
|  | 91 | */ | 
|  | 92 | extern void clearKeyboardProperties(int32_t deviceId); | 
|  | 93 |  | 
|  | 94 | /** | 
|  | 95 | * Gets the key character map filename for a device using inspecting system properties | 
|  | 96 | * and then falling back on a default key character map if necessary. | 
|  | 97 | * Returns a NAME_NOT_FOUND if none found. | 
|  | 98 | */ | 
|  | 99 | extern status_t getKeyCharacterMapFile(int32_t deviceId, String8& outKeyCharacterMapFile); | 
|  | 100 |  | 
|  | 101 | /** | 
|  | 102 | * Gets a key code by its short form label, eg. "HOME". | 
|  | 103 | * Returns 0 if unknown. | 
|  | 104 | */ | 
|  | 105 | extern int32_t getKeyCodeByLabel(const char* label); | 
|  | 106 |  | 
|  | 107 | /** | 
|  | 108 | * Gets a key flag by its short form label, eg. "WAKE". | 
|  | 109 | * Returns 0 if unknown. | 
|  | 110 | */ | 
|  | 111 | extern uint32_t getKeyFlagByLabel(const char* label); | 
|  | 112 |  | 
|  | 113 | /** | 
| Jeff Brown | 3ea4de8 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 114 | * Gets a axis by its short form label, eg. "X". | 
|  | 115 | * Returns -1 if unknown. | 
|  | 116 | */ | 
|  | 117 | extern int32_t getAxisByLabel(const char* label); | 
|  | 118 |  | 
|  | 119 | /** | 
|  | 120 | * Gets a axis label by its id. | 
|  | 121 | * Returns NULL if unknown. | 
|  | 122 | */ | 
|  | 123 | extern const char* getAxisLabel(int32_t axisId); | 
|  | 124 |  | 
|  | 125 | /** | 
| Jeff Brown | a3477c8 | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 126 | * Updates a meta state field when a key is pressed or released. | 
|  | 127 | */ | 
|  | 128 | extern int32_t updateMetaState(int32_t keyCode, bool down, int32_t oldMetaState); | 
|  | 129 |  | 
| Jeff Brown | 80f3e7c | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 130 | /** | 
|  | 131 | * Returns true if a key is a meta key like ALT or CAPS_LOCK. | 
|  | 132 | */ | 
|  | 133 | extern bool isMetaKey(int32_t keyCode); | 
|  | 134 |  | 
| Jeff Brown | a3477c8 | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 135 | } // namespace android | 
|  | 136 |  | 
|  | 137 | #endif // _UI_KEYBOARD_H |