blob: 4f7cfb6b75497657cc7dc4ca78e8b6e543062c28 [file] [log] [blame]
Jeff Brown5912f952013-07-01 19:10:31 -07001/*
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_VIRTUAL_KEY_MAP_H
18#define _LIBINPUT_VIRTUAL_KEY_MAP_H
19
20#include <stdint.h>
21
22#include <input/Input.h>
23#include <utils/Errors.h>
24#include <utils/KeyedVector.h>
25#include <utils/Tokenizer.h>
Jeff Brown5912f952013-07-01 19:10:31 -070026#include <utils/Unicode.h>
27
28namespace android {
29
30/* Describes a virtual key. */
31struct VirtualKeyDefinition {
32 int32_t scanCode;
33
34 // configured position data, specified in display coords
35 int32_t centerX;
36 int32_t centerY;
37 int32_t width;
38 int32_t height;
39};
40
41
42/**
43 * Describes a collection of virtual keys on a touch screen in terms of
44 * virtual scan codes and hit rectangles.
45 *
46 * This object is immutable after it has been loaded.
47 */
48class VirtualKeyMap {
49public:
50 ~VirtualKeyMap();
51
Siarhei Vishniakou3e78dec2019-02-20 16:21:46 -060052 static std::unique_ptr<VirtualKeyMap> load(const std::string& filename);
Jeff Brown5912f952013-07-01 19:10:31 -070053
54 inline const Vector<VirtualKeyDefinition>& getVirtualKeys() const {
55 return mVirtualKeys;
56 }
57
58private:
59 class Parser {
60 VirtualKeyMap* mMap;
61 Tokenizer* mTokenizer;
62
63 public:
64 Parser(VirtualKeyMap* map, Tokenizer* tokenizer);
65 ~Parser();
66 status_t parse();
67
68 private:
69 bool consumeFieldDelimiterAndSkipWhitespace();
70 bool parseNextIntField(int32_t* outValue);
71 };
72
73 Vector<VirtualKeyDefinition> mVirtualKeys;
74
75 VirtualKeyMap();
76};
77
78} // namespace android
79
80#endif // _LIBINPUT_KEY_CHARACTER_MAP_H