| Index: ui/events/ozone/gamepad/static_gamepad_mapping.cc
|
| diff --git a/ui/events/ozone/gamepad/gamepad_mapping.cc b/ui/events/ozone/gamepad/static_gamepad_mapping.cc
|
| similarity index 85%
|
| copy from ui/events/ozone/gamepad/gamepad_mapping.cc
|
| copy to ui/events/ozone/gamepad/static_gamepad_mapping.cc
|
| index be20d008c712826287248f10aaa5a1e14d707d5f..2c01d407bbc37c1ae14eeee7f12e2eddb5d0a914 100644
|
| --- a/ui/events/ozone/gamepad/gamepad_mapping.cc
|
| +++ b/ui/events/ozone/gamepad/static_gamepad_mapping.cc
|
| @@ -4,35 +4,21 @@
|
|
|
| #include <linux/input.h>
|
| #include <cstdint>
|
| +#include <list>
|
| #include <map>
|
| +#include <vector>
|
|
|
| #include "base/macros.h"
|
| -#include "ui/events/ozone/gamepad/gamepad_mapping.h"
|
| +#include "ui/events/ozone/evdev/event_device_info.h"
|
| +#include "ui/events/ozone/gamepad/static_gamepad_mapping.h"
|
| #include "ui/events/ozone/gamepad/webgamepad_constants.h"
|
|
|
| namespace ui {
|
|
|
| -// KeyMap maps evdev key code to web gamepad code.
|
| -struct KeyMapEntry {
|
| - uint16_t evdev_code;
|
| - uint16_t mapped_code;
|
| -};
|
| -
|
| -// AbsMap maps evdev abs code to web gamepad (type, code).
|
| -struct AbsMapEntry {
|
| - uint16_t evdev_code;
|
| - GamepadEventType mapped_type;
|
| - uint16_t mapped_code;
|
| -};
|
| -
|
| -using KeyMapType = const KeyMapEntry[];
|
| -using AbsMapType = const AbsMapEntry[];
|
| -
|
| -#define TO_BTN(code, mapped_code) \
|
| - { code, GamepadEventType::BUTTON, mapped_code }
|
| -
|
| -#define TO_ABS(code, mapped_code) \
|
| - { code, GamepadEventType::AXIS, mapped_code }
|
| +typedef bool (*GamepadMapperFunction)(uint16_t key,
|
| + uint16_t code,
|
| + GamepadEventType* mapped_type,
|
| + uint16_t* mapped_code);
|
|
|
| #define DO_MAPPING \
|
| DoGamepadMapping(key_mapping, arraysize(key_mapping), abs_mapping, \
|
| @@ -202,8 +188,8 @@ bool ADT1Mapper(uint16_t type,
|
| {BTN_X, WG_BUTTON_X}, {BTN_Y, WG_BUTTON_Y},
|
| {BTN_TL, WG_BUTTON_L1}, {BTN_TR, WG_BUTTON_R1},
|
| {BTN_THUMBL, WG_BUTTON_THUMBL}, {BTN_THUMBR, WG_BUTTON_THUMBR},
|
| - {BTN_MODE, WG_BUTTON_START}, {KEY_BACK, WG_BUTTON_SELECT},
|
| - {KEY_HOMEPAGE, WG_BUTTON_MODE}};
|
| + {BTN_MODE, WG_BUTTON_MODE}, {KEY_BACK, WG_BUTTON_SELECT},
|
| + {KEY_HOMEPAGE, WG_BUTTON_START}};
|
|
|
| static const AbsMapType abs_mapping = {
|
| TO_ABS(ABS_X, WG_ABS_X), TO_ABS(ABS_Y, WG_ABS_Y),
|
| @@ -355,43 +341,49 @@ bool Vendor_1689Product_fd00Mapper(uint16_t type,
|
| return DO_MAPPING;
|
| }
|
|
|
| -bool GenericMapper(uint16_t type,
|
| - uint16_t code,
|
| - GamepadEventType* mapped_type,
|
| - uint16_t* mapped_code) {
|
| - static const KeyMapType key_mapping = {{BTN_A, WG_BUTTON_A},
|
| - {BTN_B, WG_BUTTON_B},
|
| - {BTN_X, WG_BUTTON_X},
|
| - {BTN_Y, WG_BUTTON_Y},
|
| - {BTN_TL, WG_BUTTON_L1},
|
| - {BTN_TR, WG_BUTTON_R1},
|
| - {BTN_TL2, WG_BUTTON_LT},
|
| - {BTN_TR2, WG_BUTTON_RT},
|
| - {BTN_THUMBL, WG_BUTTON_THUMBL},
|
| - {BTN_THUMBR, WG_BUTTON_THUMBR},
|
| - {KEY_BACK, WG_BUTTON_SELECT},
|
| - {KEY_HOMEPAGE, WG_BUTTON_MODE},
|
| - {KEY_UP, WG_BUTTON_DPAD_UP},
|
| - {KEY_DOWN, WG_BUTTON_DPAD_DOWN},
|
| - {KEY_LEFT, WG_BUTTON_DPAD_LEFT},
|
| - {KEY_RIGHT, WG_BUTTON_DPAD_RIGHT},
|
| - {BTN_SELECT, WG_BUTTON_SELECT},
|
| - {BTN_START, WG_BUTTON_START},
|
| - {BTN_MODE, WG_BUTTON_MODE}};
|
| +bool JoydevLikeMapper(uint16_t type,
|
| + uint16_t code,
|
| + GamepadEventType* mapped_type,
|
| + uint16_t* mapped_code) {
|
| + static const KeyMapType key_mapping = {
|
| + {BTN_A, WG_BUTTON_A}, {BTN_B, WG_BUTTON_B},
|
| + {BTN_C, WG_BUTTON_X}, {BTN_X, WG_BUTTON_Y},
|
| + {BTN_Y, WG_BUTTON_L1}, {BTN_Z, WG_BUTTON_R1},
|
| + {BTN_TL, WG_BUTTON_LT}, {BTN_TR, WG_BUTTON_RT},
|
| + {BTN_TL2, WG_BUTTON_SELECT}, {BTN_TR2, WG_BUTTON_START},
|
| + {BTN_SELECT, WG_BUTTON_THUMBL}, {BTN_START, WG_BUTTON_THUMBR}};
|
|
|
| static const AbsMapType abs_mapping = {
|
| - TO_ABS(ABS_X, WG_ABS_X), TO_ABS(ABS_Y, WG_ABS_Y),
|
| - TO_ABS(ABS_RX, WG_ABS_RX), TO_ABS(ABS_RY, WG_ABS_RY),
|
| - TO_ABS(ABS_Z, WG_ABS_RX), TO_ABS(ABS_RZ, WG_ABS_RY),
|
| - TO_BTN(ABS_BRAKE, WG_BUTTON_LT), TO_BTN(ABS_GAS, WG_BUTTON_RT),
|
| - TO_BTN(ABS_HAT0X, kHAT_X), TO_BTN(ABS_HAT0Y, kHAT_Y)};
|
| + TO_ABS(ABS_X, WG_ABS_X), TO_ABS(ABS_Y, WG_ABS_Y),
|
| + TO_ABS(ABS_Z, WG_ABS_RX), TO_ABS(ABS_RZ, WG_ABS_RY),
|
| + TO_BTN(ABS_HAT0X, kHAT_X), TO_BTN(ABS_HAT0Y, kHAT_Y)};
|
| + return DO_MAPPING;
|
| +}
|
| +
|
| +bool DualShock4(uint16_t type,
|
| + uint16_t code,
|
| + GamepadEventType* mapped_type,
|
| + uint16_t* mapped_code) {
|
| + static const KeyMapType key_mapping = {
|
| + {BTN_A, WG_BUTTON_A}, {BTN_B, WG_BUTTON_B},
|
| + {BTN_C, WG_BUTTON_X}, {BTN_X, WG_BUTTON_Y},
|
| + {BTN_Y, WG_BUTTON_L1}, {BTN_Z, WG_BUTTON_R1},
|
| + {BTN_TL, WG_BUTTON_LT}, {BTN_TR, WG_BUTTON_RT},
|
| + {BTN_TL2, WG_BUTTON_SELECT}, {BTN_TR2, WG_BUTTON_START},
|
| + {BTN_SELECT, WG_BUTTON_THUMBL}, {BTN_START, WG_BUTTON_THUMBR}};
|
| +
|
| + static const AbsMapType abs_mapping = {
|
| + TO_ABS(ABS_X, WG_ABS_X), TO_ABS(ABS_Y, WG_ABS_Y),
|
| + TO_ABS(ABS_RX, WG_BUTTON_LT), TO_ABS(ABS_RY, WG_BUTTON_RT),
|
| + TO_ABS(ABS_Z, WG_ABS_RX), TO_ABS(ABS_RZ, WG_ABS_RY),
|
| + TO_BTN(ABS_HAT0X, kHAT_X), TO_BTN(ABS_HAT0Y, kHAT_Y)};
|
| return DO_MAPPING;
|
| }
|
|
|
| static const struct MappingData {
|
| uint16_t vendor_id;
|
| uint16_t product_id;
|
| - GamepadMapper mapper;
|
| + GamepadMapperFunction mapper;
|
| } AvailableMappings[] = {
|
| // Xbox style gamepad.
|
| {0x045e, 0x028e, XInputStyleMapper}, // Xbox 360 wired.
|
| @@ -415,6 +407,7 @@ static const struct MappingData {
|
| {0x1689, 0xfe00, XInputStyleMapper}, // Razer sabertooth elite.
|
| // Sony gamepads.
|
| {0x054c, 0x0268, PlaystationSixAxisMapper}, // Playstation 3.
|
| + {0x054c, 0x05c4, DualShock4}, // Dualshock 4.
|
| // NES style gamepad.
|
| {0x0583, 0x2060, IBuffalocClassicMapper}, // iBuffalo Classic.
|
| {0x0079, 0x0011, ClassicNESMapper}, // Classic NES controller.
|
| @@ -433,16 +426,33 @@ static const struct MappingData {
|
| {0x046d, 0xc219, Vendor_046dProduct_c219Mapper},
|
| {0x1038, 0x1412, Vendor_1038Product_1412Mapper}, // Steelseries free.
|
| // Razer onza tournment edition.
|
| - {0x1689, 0xfd00, Vendor_1689Product_fd00Mapper}};
|
| + {0x1689, 0xfd00, Vendor_1689Product_fd00Mapper},
|
| + {0x11c5, 0x5506, JoydevLikeMapper} // HJC Game ZD-V
|
| +};
|
| +
|
| +class StaticGamepadMapper : public GamepadMapper {
|
| + public:
|
| + StaticGamepadMapper(GamepadMapperFunction fp) : mapper_fp_(fp) {}
|
| +
|
| + bool Map(uint16_t type,
|
| + uint16_t code,
|
| + GamepadEventType* mapped_type,
|
| + uint16_t* mapped_code) const override {
|
| + return mapper_fp_(type, code, mapped_type, mapped_code);
|
| + };
|
| +
|
| + private:
|
| + GamepadMapperFunction mapper_fp_;
|
| +};
|
|
|
| -GamepadMapper GetGamepadMapper(uint16_t vendor_id, uint16_t product_id) {
|
| +GamepadMapper* GetStaticGamepadMapper(uint16_t vendor_id, uint16_t product_id) {
|
| for (size_t i = 0; i < arraysize(AvailableMappings); i++) {
|
| if (AvailableMappings[i].vendor_id == vendor_id &&
|
| AvailableMappings[i].product_id == product_id) {
|
| - return AvailableMappings[i].mapper;
|
| + return new StaticGamepadMapper(AvailableMappings[i].mapper);
|
| }
|
| }
|
| - return GenericMapper;
|
| + return nullptr;
|
| }
|
|
|
| } // namespace ui
|
|
|