1*38e8c45fSAndroid Build Coastguard Worker /* 2*38e8c45fSAndroid Build Coastguard Worker * Copyright (C) 2010 The Android Open Source Project 3*38e8c45fSAndroid Build Coastguard Worker * 4*38e8c45fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*38e8c45fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*38e8c45fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*38e8c45fSAndroid Build Coastguard Worker * 8*38e8c45fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*38e8c45fSAndroid Build Coastguard Worker * 10*38e8c45fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*38e8c45fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*38e8c45fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*38e8c45fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*38e8c45fSAndroid Build Coastguard Worker * limitations under the License. 15*38e8c45fSAndroid Build Coastguard Worker */ 16*38e8c45fSAndroid Build Coastguard Worker 17*38e8c45fSAndroid Build Coastguard Worker #pragma once 18*38e8c45fSAndroid Build Coastguard Worker 19*38e8c45fSAndroid Build Coastguard Worker #include <input/Input.h> 20*38e8c45fSAndroid Build Coastguard Worker #include <input/InputDevice.h> 21*38e8c45fSAndroid Build Coastguard Worker #include <input/InputEventLabels.h> 22*38e8c45fSAndroid Build Coastguard Worker #include <input/PropertyMap.h> 23*38e8c45fSAndroid Build Coastguard Worker #include <utils/Errors.h> 24*38e8c45fSAndroid Build Coastguard Worker 25*38e8c45fSAndroid Build Coastguard Worker namespace android { 26*38e8c45fSAndroid Build Coastguard Worker 27*38e8c45fSAndroid Build Coastguard Worker class KeyLayoutMap; 28*38e8c45fSAndroid Build Coastguard Worker class KeyCharacterMap; 29*38e8c45fSAndroid Build Coastguard Worker 30*38e8c45fSAndroid Build Coastguard Worker /** 31*38e8c45fSAndroid Build Coastguard Worker * Loads the key layout map and key character map for a keyboard device. 32*38e8c45fSAndroid Build Coastguard Worker */ 33*38e8c45fSAndroid Build Coastguard Worker class KeyMap { 34*38e8c45fSAndroid Build Coastguard Worker public: 35*38e8c45fSAndroid Build Coastguard Worker std::string keyLayoutFile; 36*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<KeyLayoutMap> keyLayoutMap; 37*38e8c45fSAndroid Build Coastguard Worker 38*38e8c45fSAndroid Build Coastguard Worker std::string keyCharacterMapFile; 39*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<KeyCharacterMap> keyCharacterMap; 40*38e8c45fSAndroid Build Coastguard Worker 41*38e8c45fSAndroid Build Coastguard Worker KeyMap(); 42*38e8c45fSAndroid Build Coastguard Worker ~KeyMap(); 43*38e8c45fSAndroid Build Coastguard Worker 44*38e8c45fSAndroid Build Coastguard Worker status_t load(const InputDeviceIdentifier& deviceIdenfier, 45*38e8c45fSAndroid Build Coastguard Worker const PropertyMap* deviceConfiguration); 46*38e8c45fSAndroid Build Coastguard Worker haveKeyLayout()47*38e8c45fSAndroid Build Coastguard Worker inline bool haveKeyLayout() const { 48*38e8c45fSAndroid Build Coastguard Worker return !keyLayoutFile.empty(); 49*38e8c45fSAndroid Build Coastguard Worker } 50*38e8c45fSAndroid Build Coastguard Worker haveKeyCharacterMap()51*38e8c45fSAndroid Build Coastguard Worker inline bool haveKeyCharacterMap() const { 52*38e8c45fSAndroid Build Coastguard Worker return !keyCharacterMapFile.empty(); 53*38e8c45fSAndroid Build Coastguard Worker } 54*38e8c45fSAndroid Build Coastguard Worker isComplete()55*38e8c45fSAndroid Build Coastguard Worker inline bool isComplete() const { 56*38e8c45fSAndroid Build Coastguard Worker return haveKeyLayout() && haveKeyCharacterMap(); 57*38e8c45fSAndroid Build Coastguard Worker } 58*38e8c45fSAndroid Build Coastguard Worker 59*38e8c45fSAndroid Build Coastguard Worker private: 60*38e8c45fSAndroid Build Coastguard Worker bool probeKeyMap(const InputDeviceIdentifier& deviceIdentifier, const std::string& name); 61*38e8c45fSAndroid Build Coastguard Worker status_t loadKeyLayout(const InputDeviceIdentifier& deviceIdentifier, const std::string& name); 62*38e8c45fSAndroid Build Coastguard Worker status_t loadKeyCharacterMap(const InputDeviceIdentifier& deviceIdentifier, 63*38e8c45fSAndroid Build Coastguard Worker const std::string& name); 64*38e8c45fSAndroid Build Coastguard Worker }; 65*38e8c45fSAndroid Build Coastguard Worker 66*38e8c45fSAndroid Build Coastguard Worker /** 67*38e8c45fSAndroid Build Coastguard Worker * Returns true if the keyboard is eligible for use as a built-in keyboard. 68*38e8c45fSAndroid Build Coastguard Worker */ 69*38e8c45fSAndroid Build Coastguard Worker extern bool isEligibleBuiltInKeyboard(const InputDeviceIdentifier& deviceIdentifier, 70*38e8c45fSAndroid Build Coastguard Worker const PropertyMap* deviceConfiguration, const KeyMap* keyMap); 71*38e8c45fSAndroid Build Coastguard Worker 72*38e8c45fSAndroid Build Coastguard Worker /** 73*38e8c45fSAndroid Build Coastguard Worker * Updates a meta state field when a key is pressed or released. 74*38e8c45fSAndroid Build Coastguard Worker */ 75*38e8c45fSAndroid Build Coastguard Worker extern int32_t updateMetaState(int32_t keyCode, bool down, int32_t oldMetaState); 76*38e8c45fSAndroid Build Coastguard Worker 77*38e8c45fSAndroid Build Coastguard Worker /** 78*38e8c45fSAndroid Build Coastguard Worker * Normalizes the meta state such that if either the left or right modifier 79*38e8c45fSAndroid Build Coastguard Worker * meta state bits are set then the result will also include the universal 80*38e8c45fSAndroid Build Coastguard Worker * bit for that modifier. 81*38e8c45fSAndroid Build Coastguard Worker */ 82*38e8c45fSAndroid Build Coastguard Worker extern int32_t normalizeMetaState(int32_t oldMetaState); 83*38e8c45fSAndroid Build Coastguard Worker 84*38e8c45fSAndroid Build Coastguard Worker /** 85*38e8c45fSAndroid Build Coastguard Worker * Returns true if a key is a meta key like ALT or CAPS_LOCK. 86*38e8c45fSAndroid Build Coastguard Worker */ 87*38e8c45fSAndroid Build Coastguard Worker extern bool isMetaKey(int32_t keyCode); 88*38e8c45fSAndroid Build Coastguard Worker 89*38e8c45fSAndroid Build Coastguard Worker } // namespace android 90