Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0bae1a0f authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Return Key* from getKey

The call getKey can fail. Rather than returning a separate bool that the
caller might ignore, return a pointer to simplify the code.

Bug: 278299254
Test: m libinput_tests && $ANDROID_HOST_OUT/nativetest64/libinput_tests/libinput_tests
Change-Id: I28c25bee8890bdc90ca7e069c803423a7420e6b4
parent 5af2834b
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -243,7 +243,7 @@ private:


    KeyCharacterMap(const std::string& filename);
    KeyCharacterMap(const std::string& filename);


    bool getKey(int32_t keyCode, const Key** outKey) const;
    const Key* getKey(int32_t keyCode) const;
    const Behavior* getKeyBehavior(int32_t keyCode, int32_t metaState) const;
    const Behavior* getKeyBehavior(int32_t keyCode, int32_t metaState) const;
    static bool matchesMetaState(int32_t eventMetaState, int32_t behaviorMetaState);
    static bool matchesMetaState(int32_t eventMetaState, int32_t behaviorMetaState);


+11 −12
Original line number Original line Diff line number Diff line
@@ -272,8 +272,8 @@ const std::string KeyCharacterMap::getLoadFileName() const {


char16_t KeyCharacterMap::getDisplayLabel(int32_t keyCode) const {
char16_t KeyCharacterMap::getDisplayLabel(int32_t keyCode) const {
    char16_t result = 0;
    char16_t result = 0;
    const Key* key;
    const Key* key = getKey(keyCode);
    if (getKey(keyCode, &key)) {
    if (key != nullptr) {
        result = key->label;
        result = key->label;
    }
    }
#if DEBUG_MAPPING
#if DEBUG_MAPPING
@@ -284,8 +284,8 @@ char16_t KeyCharacterMap::getDisplayLabel(int32_t keyCode) const {


char16_t KeyCharacterMap::getNumber(int32_t keyCode) const {
char16_t KeyCharacterMap::getNumber(int32_t keyCode) const {
    char16_t result = 0;
    char16_t result = 0;
    const Key* key;
    const Key* key = getKey(keyCode);
    if (getKey(keyCode, &key)) {
    if (key != nullptr) {
        result = key->number;
        result = key->number;
    }
    }
#if DEBUG_MAPPING
#if DEBUG_MAPPING
@@ -332,8 +332,8 @@ bool KeyCharacterMap::getFallbackAction(int32_t keyCode, int32_t metaState,
char16_t KeyCharacterMap::getMatch(int32_t keyCode, const char16_t* chars, size_t numChars,
char16_t KeyCharacterMap::getMatch(int32_t keyCode, const char16_t* chars, size_t numChars,
        int32_t metaState) const {
        int32_t metaState) const {
    char16_t result = 0;
    char16_t result = 0;
    const Key* key;
    const Key* key = getKey(keyCode);
    if (getKey(keyCode, &key)) {
    if (key != nullptr) {
        // Try to find the most general behavior that maps to this character.
        // Try to find the most general behavior that maps to this character.
        // For example, the base key behavior will usually be last in the list.
        // For example, the base key behavior will usually be last in the list.
        // However, if we find a perfect meta state match for one behavior then use that one.
        // However, if we find a perfect meta state match for one behavior then use that one.
@@ -493,19 +493,18 @@ std::pair<int32_t, int32_t> KeyCharacterMap::applyKeyBehavior(int32_t fromKeyCod
    return std::make_pair(toKeyCode, toMetaState);
    return std::make_pair(toKeyCode, toMetaState);
}
}


bool KeyCharacterMap::getKey(int32_t keyCode, const Key** outKey) const {
const KeyCharacterMap::Key* KeyCharacterMap::getKey(int32_t keyCode) const {
    ssize_t index = mKeys.indexOfKey(keyCode);
    ssize_t index = mKeys.indexOfKey(keyCode);
    if (index >= 0) {
    if (index >= 0) {
        *outKey = mKeys.valueAt(index);
        return mKeys.valueAt(index);
        return true;
    }
    }
    return false;
    return nullptr;
}
}


const KeyCharacterMap::Behavior* KeyCharacterMap::getKeyBehavior(int32_t keyCode,
const KeyCharacterMap::Behavior* KeyCharacterMap::getKeyBehavior(int32_t keyCode,
                                                                 int32_t metaState) const {
                                                                 int32_t metaState) const {
    const Key* key;
    const Key* key = getKey(keyCode);
    if (getKey(keyCode, &key)) {
    if (key != nullptr) {
        for (const Behavior& behavior : key->behaviors) {
        for (const Behavior& behavior : key->behaviors) {
            if (matchesMetaState(metaState, behavior.metaState)) {
            if (matchesMetaState(metaState, behavior.metaState)) {
                return &behavior;
                return &behavior;