diff options
author | 2024-01-29 12:47:18 -0800 | |
---|---|---|
committer | 2024-01-29 12:47:18 -0800 | |
commit | 2d701e14093b2e699d7dca00db3d7d66d0c96e29 (patch) | |
tree | c1b5916d12ac356ec1732e50293b335475ea83d0 /libs/input/InputEventLabels.cpp | |
parent | c6e22d8533cee1d044b88f2eb4a94a8b6c041761 (diff) | |
parent | b507b71cc52f9203657f221808eef04d58dd6398 (diff) |
Merge Android 24Q1 Release (ab/11220357)
Bug: 319669529
Merged-In: I264e728c49f0500f2f868c3a25b0910d0d527340
Change-Id: I0de5ae0000a29e4b9735e6c4f381f680eb0723cd
Diffstat (limited to 'libs/input/InputEventLabels.cpp')
-rw-r--r-- | libs/input/InputEventLabels.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/libs/input/InputEventLabels.cpp b/libs/input/InputEventLabels.cpp index b25e06c869..0e627e56fd 100644 --- a/libs/input/InputEventLabels.cpp +++ b/libs/input/InputEventLabels.cpp @@ -18,6 +18,7 @@ #include <linux/input-event-codes.h> #include <linux/input.h> +#include <strings.h> #define DEFINE_KEYCODE(key) { #key, AKEYCODE_##key } #define DEFINE_AXIS(axis) { #axis, AMOTION_EVENT_AXIS_##axis } @@ -524,6 +525,14 @@ std::string getLabel(const label* labels, int value) { return labels->name != nullptr ? labels->name : std::to_string(value); } +std::optional<int> getValue(const label* labels, const char* searchLabel) { + if (labels == nullptr) return {}; + while (labels->name != nullptr && ::strcasecmp(labels->name, searchLabel) != 0) { + labels++; + } + return labels->name != nullptr ? std::make_optional(labels->value) : std::nullopt; +} + const label* getCodeLabelsForType(int32_t type) { switch (type) { case EV_SYN: @@ -557,7 +566,7 @@ const label* getValueLabelsForTypeAndCode(int32_t type, int32_t code) { if (type == EV_KEY) { return ev_key_value_labels; } - if (type == EV_MSC && code == ABS_MT_TOOL_TYPE) { + if (type == EV_ABS && code == ABS_MT_TOOL_TYPE) { return mt_tool_labels; } return nullptr; @@ -573,4 +582,17 @@ EvdevEventLabel InputEventLookup::getLinuxEvdevLabel(int32_t type, int32_t code, }; } +std::optional<int> InputEventLookup::getLinuxEvdevEventTypeByLabel(const char* label) { + return getValue(ev_labels, label); +} + +std::optional<int> InputEventLookup::getLinuxEvdevEventCodeByLabel(int32_t type, + const char* label) { + return getValue(getCodeLabelsForType(type), label); +} + +std::optional<int> InputEventLookup::getLinuxEvdevInputPropByLabel(const char* label) { + return getValue(input_prop_labels, label); +} + } // namespace android |