blob: 08ad8c6e5ae380886f9da6f2dbe54ebeb38ebf57 [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>
Siarhei Vishniakou32f36ae2020-09-02 20:17:10 -070023#include <input/PropertyMap.h>
Jeff Brown5912f952013-07-01 19:10:31 -070024#include <utils/Errors.h>
Jeff Brown5912f952013-07-01 19:10:31 -070025
26namespace android {
27
Jeff Brown5912f952013-07-01 19:10:31 -070028class KeyLayoutMap;
29class KeyCharacterMap;
30
31/**
32 * Loads the key layout map and key character map for a keyboard device.
33 */
34class KeyMap {
35public:
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010036 std::string keyLayoutFile;
Chris Ye1abffbd2020-08-18 12:50:12 -070037 std::shared_ptr<KeyLayoutMap> keyLayoutMap;
Jeff Brown5912f952013-07-01 19:10:31 -070038
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010039 std::string keyCharacterMapFile;
Chris Ye3a1e4462020-08-12 10:13:15 -070040 std::shared_ptr<KeyCharacterMap> keyCharacterMap;
Jeff Brown5912f952013-07-01 19:10:31 -070041
42 KeyMap();
43 ~KeyMap();
44
45 status_t load(const InputDeviceIdentifier& deviceIdenfier,
46 const PropertyMap* deviceConfiguration);
47
48 inline bool haveKeyLayout() const {
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010049 return !keyLayoutFile.empty();
Jeff Brown5912f952013-07-01 19:10:31 -070050 }
51
52 inline bool haveKeyCharacterMap() const {
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010053 return !keyCharacterMapFile.empty();
Jeff Brown5912f952013-07-01 19:10:31 -070054 }
55
56 inline bool isComplete() const {
57 return haveKeyLayout() && haveKeyCharacterMap();
58 }
59
60private:
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010061 bool probeKeyMap(const InputDeviceIdentifier& deviceIdentifier, const std::string& name);
62 status_t loadKeyLayout(const InputDeviceIdentifier& deviceIdentifier, const std::string& name);
Jeff Brown5912f952013-07-01 19:10:31 -070063 status_t loadKeyCharacterMap(const InputDeviceIdentifier& deviceIdentifier,
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010064 const std::string& name);
65 std::string getPath(const InputDeviceIdentifier& deviceIdentifier,
66 const std::string& name, InputDeviceConfigurationFileType type);
Jeff Brown5912f952013-07-01 19:10:31 -070067};
68
69/**
70 * Returns true if the keyboard is eligible for use as a built-in keyboard.
71 */
72extern bool isEligibleBuiltInKeyboard(const InputDeviceIdentifier& deviceIdentifier,
73 const PropertyMap* deviceConfiguration, const KeyMap* keyMap);
74
75/**
Jeff Brown5912f952013-07-01 19:10:31 -070076 * Updates a meta state field when a key is pressed or released.
77 */
78extern int32_t updateMetaState(int32_t keyCode, bool down, int32_t oldMetaState);
79
80/**
Dmitry Torokhov115f93e2015-09-17 18:04:50 -070081 * Normalizes the meta state such that if either the left or right modifier
82 * meta state bits are set then the result will also include the universal
83 * bit for that modifier.
84 */
85extern int32_t normalizeMetaState(int32_t oldMetaState);
86
87/**
Jeff Brown5912f952013-07-01 19:10:31 -070088 * Returns true if a key is a meta key like ALT or CAPS_LOCK.
89 */
90extern bool isMetaKey(int32_t keyCode);
91
92} // namespace android
93
94#endif // _LIBINPUT_KEYBOARD_H