diff options
Diffstat (limited to 'libs/input/InputEventLabels.cpp')
| -rw-r--r-- | libs/input/InputEventLabels.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/libs/input/InputEventLabels.cpp b/libs/input/InputEventLabels.cpp index 50efac1314..c218e1e858 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 } @@ -523,6 +524,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: @@ -572,4 +581,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 |