blob: d4903e98dfe3b6da968d7b81b24b68d2a9f8dde6 [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_KEYBOARD_H
18#define _LIBINPUT_KEYBOARD_H
19
20#include <input/Input.h>
21#include <input/InputDevice.h>
Michael Wright872db4f2014-04-22 15:03:51 -070022#include <input/InputEventLabels.h>
Jeff Brown5912f952013-07-01 19:10:31 -070023#include <utils/Errors.h>
24#include <utils/String8.h>
25#include <utils/PropertyMap.h>
26
27namespace android {
28
29enum {
30 /* Device id of the built in keyboard. */
31 DEVICE_ID_BUILT_IN_KEYBOARD = 0,
32
33 /* Device id of a generic virtual keyboard with a full layout that can be used
34 * to synthesize key events. */
35 DEVICE_ID_VIRTUAL_KEYBOARD = -1,
36};
37
38class KeyLayoutMap;
39class KeyCharacterMap;
40
41/**
42 * Loads the key layout map and key character map for a keyboard device.
43 */
44class KeyMap {
45public:
46 String8 keyLayoutFile;
47 sp<KeyLayoutMap> keyLayoutMap;
48
49 String8 keyCharacterMapFile;
50 sp<KeyCharacterMap> keyCharacterMap;
51
52 KeyMap();
53 ~KeyMap();
54
55 status_t load(const InputDeviceIdentifier& deviceIdenfier,
56 const PropertyMap* deviceConfiguration);
57
58 inline bool haveKeyLayout() const {
59 return !keyLayoutFile.isEmpty();
60 }
61
62 inline bool haveKeyCharacterMap() const {
63 return !keyCharacterMapFile.isEmpty();
64 }
65
66 inline bool isComplete() const {
67 return haveKeyLayout() && haveKeyCharacterMap();
68 }
69
70private:
71 bool probeKeyMap(const InputDeviceIdentifier& deviceIdentifier, const String8& name);
72 status_t loadKeyLayout(const InputDeviceIdentifier& deviceIdentifier, const String8& name);
73 status_t loadKeyCharacterMap(const InputDeviceIdentifier& deviceIdentifier,
74 const String8& name);
75 String8 getPath(const InputDeviceIdentifier& deviceIdentifier,
76 const String8& name, InputDeviceConfigurationFileType type);
77};
78
79/**
80 * Returns true if the keyboard is eligible for use as a built-in keyboard.
81 */
82extern bool isEligibleBuiltInKeyboard(const InputDeviceIdentifier& deviceIdentifier,
83 const PropertyMap* deviceConfiguration, const KeyMap* keyMap);
84
85/**
Jeff Brown5912f952013-07-01 19:10:31 -070086 * Updates a meta state field when a key is pressed or released.
87 */
88extern int32_t updateMetaState(int32_t keyCode, bool down, int32_t oldMetaState);
89
90/**
Dmitry Torokhov115f93e2015-09-17 18:04:50 -070091 * Normalizes the meta state such that if either the left or right modifier
92 * meta state bits are set then the result will also include the universal
93 * bit for that modifier.
94 */
95extern int32_t normalizeMetaState(int32_t oldMetaState);
96
97/**
Jeff Brown5912f952013-07-01 19:10:31 -070098 * Returns true if a key is a meta key like ALT or CAPS_LOCK.
99 */
100extern bool isMetaKey(int32_t keyCode);
101
102} // namespace android
103
104#endif // _LIBINPUT_KEYBOARD_H