diff options
Diffstat (limited to 'include/input/KeyCharacterMap.h')
-rw-r--r-- | include/input/KeyCharacterMap.h | 79 |
1 files changed, 38 insertions, 41 deletions
diff --git a/include/input/KeyCharacterMap.h b/include/input/KeyCharacterMap.h index f6f8939b7a..b2e8baade3 100644 --- a/include/input/KeyCharacterMap.h +++ b/include/input/KeyCharacterMap.h @@ -14,10 +14,10 @@ * limitations under the License. */ -#ifndef _LIBINPUT_KEY_CHARACTER_MAP_H -#define _LIBINPUT_KEY_CHARACTER_MAP_H +#pragma once #include <stdint.h> +#include <list> #ifdef __linux__ #include <binder/IBinder.h> @@ -26,9 +26,9 @@ #include <android-base/result.h> #include <input/Input.h> #include <utils/Errors.h> -#include <utils/KeyedVector.h> #include <utils/Tokenizer.h> #include <utils/Unicode.h> +#include <map> // Maximum number of keys supported by KeyCharacterMaps #define MAX_KEYS 8192 @@ -87,6 +87,9 @@ public: /* Combines this key character map with the provided overlay. */ void combine(const KeyCharacterMap& overlay); + /* Clears already applied layout overlay */ + void clearLayoutOverlay(); + /* Gets the keyboard type. */ KeyboardType getKeyboardType() const; @@ -125,14 +128,21 @@ public: bool getEvents(int32_t deviceId, const char16_t* chars, size_t numChars, Vector<KeyEvent>& outEvents) const; + /* Maps an Android key code to another Android key code. This mapping is applied after scanCode + * and usageCodes are mapped to corresponding Android Keycode */ + void addKeyRemapping(int32_t fromKeyCode, int32_t toKeyCode); + /* Maps a scan code and usage code to a key code, in case this key map overrides * the mapping in some way. */ status_t mapKey(int32_t scanCode, int32_t usageCode, int32_t* outKeyCode) const; - /* Tries to find a replacement key code for a given key code and meta state - * in character map. */ - void tryRemapKey(int32_t scanCode, int32_t metaState, - int32_t* outKeyCode, int32_t* outMetaState) const; + /* Returns keycode after applying Android key code remapping defined in mKeyRemapping */ + int32_t applyKeyRemapping(int32_t fromKeyCode) const; + + /* Returns the <keyCode, metaState> pair after applying key behavior defined in the kcm file, + * that tries to find a replacement key code based on current meta state */ + std::pair<int32_t /*keyCode*/, int32_t /*metaState*/> applyKeyBehavior(int32_t keyCode, + int32_t metaState) const; #ifdef __linux__ /* Reads a key map from a parcel. */ @@ -142,49 +152,39 @@ public: void writeToParcel(Parcel* parcel) const; #endif - bool operator==(const KeyCharacterMap& other) const; - - bool operator!=(const KeyCharacterMap& other) const; - - KeyCharacterMap(const KeyCharacterMap& other); + bool operator==(const KeyCharacterMap& other) const = default; - virtual ~KeyCharacterMap(); + KeyCharacterMap(const KeyCharacterMap& other) = default; private: struct Behavior { - Behavior(); - Behavior(const Behavior& other); - - /* The next behavior in the list, or NULL if none. */ - Behavior* next; - /* The meta key modifiers for this behavior. */ - int32_t metaState; + int32_t metaState = 0; /* The character to insert. */ - char16_t character; + char16_t character = 0; /* The fallback keycode if the key is not handled. */ - int32_t fallbackKeyCode; + int32_t fallbackKeyCode = 0; /* The replacement keycode if the key has to be replaced outright. */ - int32_t replacementKeyCode; + int32_t replacementKeyCode = 0; + + bool operator==(const Behavior&) const = default; }; struct Key { - Key(); - Key(const Key& other); - ~Key(); + bool operator==(const Key&) const = default; /* The single character label printed on the key, or 0 if none. */ - char16_t label; + char16_t label = 0; /* The number or symbol character generated by the key, or 0 if none. */ - char16_t number; + char16_t number = 0; /* The list of key behaviors sorted from most specific to least specific * meta key binding. */ - Behavior* firstBehavior; + std::list<Behavior> behaviors; }; class Parser { @@ -215,7 +215,6 @@ private: public: Parser(KeyCharacterMap* map, Tokenizer* tokenizer, Format format); - ~Parser(); status_t parse(); private: @@ -224,24 +223,24 @@ private: status_t parseMapKey(); status_t parseKey(); status_t parseKeyProperty(); - status_t finishKey(Key* key); + status_t finishKey(Key& key); status_t parseModifier(const std::string& token, int32_t* outMetaState); status_t parseCharacterLiteral(char16_t* outCharacter); }; - KeyedVector<int32_t, Key*> mKeys; - KeyboardType mType; + std::map<int32_t, Key> mKeys; + KeyboardType mType = KeyboardType::UNKNOWN; std::string mLoadFileName; - bool mLayoutOverlayApplied; + bool mLayoutOverlayApplied = false; - KeyedVector<int32_t, int32_t> mKeysByScanCode; - KeyedVector<int32_t, int32_t> mKeysByUsageCode; + std::map<int32_t /* fromAndroidKeyCode */, int32_t /* toAndroidKeyCode */> mKeyRemapping; + std::map<int32_t /* fromScanCode */, int32_t /* toAndroidKeyCode */> mKeysByScanCode; + std::map<int32_t /* fromHidUsageCode */, int32_t /* toAndroidKeyCode */> mKeysByUsageCode; KeyCharacterMap(const std::string& filename); - bool getKey(int32_t keyCode, const Key** outKey) const; - bool getKeyBehavior(int32_t keyCode, int32_t metaState, - const Key** outKey, const Behavior** outBehavior) const; + const Key* getKey(int32_t keyCode) const; + const Behavior* getKeyBehavior(int32_t keyCode, int32_t metaState) const; static bool matchesMetaState(int32_t eventMetaState, int32_t behaviorMetaState); bool findKey(char16_t ch, int32_t* outKeyCode, int32_t* outMetaState) const; @@ -277,5 +276,3 @@ private: }; } // namespace android - -#endif // _LIBINPUT_KEY_CHARACTER_MAP_H |