1 /* 2 * Copyright (C) 2008 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_KEY_LAYOUT_MAP_H 18 #define _UI_KEY_LAYOUT_MAP_H 19 20 #include <stdint.h> 21 #include <utils/Errors.h> 22 #include <utils/KeyedVector.h> 23 #include <utils/Tokenizer.h> 24 25 namespace android { 26 27 struct AxisInfo { 28 enum Mode { 29 // Axis value is reported directly. 30 MODE_NORMAL = 0, 31 // Axis value should be inverted before reporting. 32 MODE_INVERT = 1, 33 // Axis value should be split into two axes 34 MODE_SPLIT = 2, 35 }; 36 37 // Axis mode. 38 Mode mode; 39 40 // Axis id. 41 // When split, this is the axis used for values smaller than the split position. 42 int32_t axis; 43 44 // When split, this is the axis used for values after higher than the split position. 45 int32_t highAxis; 46 47 // The split value, or 0 if not split. 48 int32_t splitValue; 49 50 // The flat value, or -1 if none. 51 int32_t flatOverride; 52 53 AxisInfo() : mode(MODE_NORMAL), axis(-1), highAxis(-1), splitValue(0), flatOverride(-1) { 54 } 55 }; 56 57 /** 58 * Describes a mapping from keyboard scan codes and joystick axes to Android key codes and axes. 59 */ 60 class KeyLayoutMap { 61 public: 62 ~KeyLayoutMap(); 63 64 static status_t load(const String8& filename, KeyLayoutMap** outMap); 65 66 status_t mapKey(int32_t scanCode, int32_t* keyCode, uint32_t* flags) const; 67 status_t findScanCodesForKey(int32_t keyCode, Vector<int32_t>* outScanCodes) const; 68 69 status_t mapAxis(int32_t scanCode, AxisInfo* outAxisInfo) const; 70 71 private: 72 struct Key { 73 int32_t keyCode; 74 uint32_t flags; 75 }; 76 77 KeyedVector<int32_t, Key> mKeys; 78 KeyedVector<int32_t, AxisInfo> mAxes; 79 80 KeyLayoutMap(); 81 82 class Parser { 83 KeyLayoutMap* mMap; 84 Tokenizer* mTokenizer; 85 86 public: 87 Parser(KeyLayoutMap* map, Tokenizer* tokenizer); 88 ~Parser(); 89 status_t parse(); 90 91 private: 92 status_t parseKey(); 93 status_t parseAxis(); 94 }; 95 }; 96 97 } // namespace android 98 99 #endif // _UI_KEY_LAYOUT_MAP_H 100