blob: f7f960f8e69ba0842fbfe064045c12540e85e512 [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
Prabir Pradhanc08b0db2022-09-10 00:57:15 +000017#pragma once
Jeff Brown5912f952013-07-01 19:10:31 -070018
19#include <input/Input.h>
20#include <input/InputDevice.h>
Michael Wright872db4f2014-04-22 15:03:51 -070021#include <input/InputEventLabels.h>
Siarhei Vishniakou32f36ae2020-09-02 20:17:10 -070022#include <input/PropertyMap.h>
Jeff Brown5912f952013-07-01 19:10:31 -070023#include <utils/Errors.h>
Jeff Brown5912f952013-07-01 19:10:31 -070024
25namespace android {
26
Jeff Brown5912f952013-07-01 19:10:31 -070027class KeyLayoutMap;
28class KeyCharacterMap;
29
30/**
31 * Loads the key layout map and key character map for a keyboard device.
32 */
33class KeyMap {
34public:
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010035 std::string keyLayoutFile;
Chris Ye1abffbd2020-08-18 12:50:12 -070036 std::shared_ptr<KeyLayoutMap> keyLayoutMap;
Jeff Brown5912f952013-07-01 19:10:31 -070037
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010038 std::string keyCharacterMapFile;
Chris Ye3a1e4462020-08-12 10:13:15 -070039 std::shared_ptr<KeyCharacterMap> keyCharacterMap;
Jeff Brown5912f952013-07-01 19:10:31 -070040
41 KeyMap();
42 ~KeyMap();
43
44 status_t load(const InputDeviceIdentifier& deviceIdenfier,
45 const PropertyMap* deviceConfiguration);
46
47 inline bool haveKeyLayout() const {
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010048 return !keyLayoutFile.empty();
Jeff Brown5912f952013-07-01 19:10:31 -070049 }
50
51 inline bool haveKeyCharacterMap() const {
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010052 return !keyCharacterMapFile.empty();
Jeff Brown5912f952013-07-01 19:10:31 -070053 }
54
55 inline bool isComplete() const {
56 return haveKeyLayout() && haveKeyCharacterMap();
57 }
58
59private:
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010060 bool probeKeyMap(const InputDeviceIdentifier& deviceIdentifier, const std::string& name);
61 status_t loadKeyLayout(const InputDeviceIdentifier& deviceIdentifier, const std::string& name);
Jeff Brown5912f952013-07-01 19:10:31 -070062 status_t loadKeyCharacterMap(const InputDeviceIdentifier& deviceIdentifier,
Siarhei Vishniakoua9fd82c2022-05-18 09:42:52 -070063 const std::string& name);
Jeff Brown5912f952013-07-01 19:10:31 -070064};
65
66/**
67 * Returns true if the keyboard is eligible for use as a built-in keyboard.
68 */
69extern bool isEligibleBuiltInKeyboard(const InputDeviceIdentifier& deviceIdentifier,
70 const PropertyMap* deviceConfiguration, const KeyMap* keyMap);
71
72/**
Jeff Brown5912f952013-07-01 19:10:31 -070073 * Updates a meta state field when a key is pressed or released.
74 */
75extern int32_t updateMetaState(int32_t keyCode, bool down, int32_t oldMetaState);
76
77/**
Dmitry Torokhov115f93e2015-09-17 18:04:50 -070078 * Normalizes the meta state such that if either the left or right modifier
79 * meta state bits are set then the result will also include the universal
80 * bit for that modifier.
81 */
82extern int32_t normalizeMetaState(int32_t oldMetaState);
83
84/**
Jeff Brown5912f952013-07-01 19:10:31 -070085 * Returns true if a key is a meta key like ALT or CAPS_LOCK.
86 */
87extern bool isMetaKey(int32_t keyCode);
88
89} // namespace android