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 | |
| 36 | struct KeyMapInfo { |
Jeff Brown | a3477c8 | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 37 | String8 keyLayoutFile; |
| 38 | String8 keyCharacterMapFile; |
| 39 | bool isDefaultKeyMap; |
| 40 | |
| 41 | KeyMapInfo() : isDefaultKeyMap(false) { |
| 42 | } |
Jeff Brown | 6688837 | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 43 | |
| 44 | bool isComplete() { |
| 45 | return !keyLayoutFile.isEmpty() && !keyCharacterMapFile.isEmpty(); |
| 46 | } |
Jeff Brown | a3477c8 | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | /** |
| 50 | * Resolves the key map to use for a particular keyboard device. |
| 51 | */ |
Jeff Brown | 6688837 | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 52 | extern status_t resolveKeyMap(const String8& deviceName, |
| 53 | const PropertyMap* deviceConfiguration, KeyMapInfo& outKeyMapInfo); |
Jeff Brown | a3477c8 | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 54 | |
| 55 | /** |
| 56 | * Sets keyboard system properties. |
| 57 | */ |
| 58 | extern void setKeyboardProperties(int32_t deviceId, const String8& deviceName, |
| 59 | const KeyMapInfo& keyMapInfo); |
| 60 | |
| 61 | /** |
| 62 | * Clears keyboard system properties. |
| 63 | */ |
| 64 | extern void clearKeyboardProperties(int32_t deviceId); |
| 65 | |
| 66 | /** |
| 67 | * Gets the key character map filename for a device using inspecting system properties |
| 68 | * and then falling back on a default key character map if necessary. |
| 69 | * Returns a NAME_NOT_FOUND if none found. |
| 70 | */ |
| 71 | extern status_t getKeyCharacterMapFile(int32_t deviceId, String8& outKeyCharacterMapFile); |
| 72 | |
| 73 | /** |
| 74 | * Gets a key code by its short form label, eg. "HOME". |
| 75 | * Returns 0 if unknown. |
| 76 | */ |
| 77 | extern int32_t getKeyCodeByLabel(const char* label); |
| 78 | |
| 79 | /** |
| 80 | * Gets a key flag by its short form label, eg. "WAKE". |
| 81 | * Returns 0 if unknown. |
| 82 | */ |
| 83 | extern uint32_t getKeyFlagByLabel(const char* label); |
| 84 | |
| 85 | /** |
| 86 | * Updates a meta state field when a key is pressed or released. |
| 87 | */ |
| 88 | extern int32_t updateMetaState(int32_t keyCode, bool down, int32_t oldMetaState); |
| 89 | |
| 90 | } // namespace android |
| 91 | |
| 92 | #endif // _UI_KEYBOARD_H |