blob: d82d0c8e0ef0cf5983b02400aec4b2098c76e517 [file] [log] [blame]
Jeff Brown6b53e8d2010-11-10 16:03:06 -08001/*
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
25namespace android {
26
Jeff Brown3a22fa02011-03-04 13:07:49 -080027struct 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
Jeff Brown6b53e8d2010-11-10 16:03:06 -080057/**
Jeff Brown6f2fba42011-02-19 01:08:02 -080058 * Describes a mapping from keyboard scan codes and joystick axes to Android key codes and axes.
Jeff Brown6b53e8d2010-11-10 16:03:06 -080059 */
60class KeyLayoutMap {
61public:
62 ~KeyLayoutMap();
63
64 static status_t load(const String8& filename, KeyLayoutMap** outMap);
65
Jeff Brown6f2fba42011-02-19 01:08:02 -080066 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
Jeff Brown3a22fa02011-03-04 13:07:49 -080069 status_t mapAxis(int32_t scanCode, AxisInfo* outAxisInfo) const;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080070
71private:
72 struct Key {
73 int32_t keyCode;
74 uint32_t flags;
75 };
76
Jeff Brown6f2fba42011-02-19 01:08:02 -080077 KeyedVector<int32_t, Key> mKeys;
Jeff Brown3a22fa02011-03-04 13:07:49 -080078 KeyedVector<int32_t, AxisInfo> mAxes;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080079
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();
Jeff Brown6f2fba42011-02-19 01:08:02 -080093 status_t parseAxis();
Jeff Brown6b53e8d2010-11-10 16:03:06 -080094 };
95};
96
97} // namespace android
98
99#endif // _UI_KEY_LAYOUT_MAP_H