1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef JOYSTICK_TRANSFORM_PROCESSOR_H 17 #define JOYSTICK_TRANSFORM_PROCESSOR_H 18 19 #include "i_input_windows_manager.h" 20 #include "transform_processor.h" 21 22 namespace OHOS { 23 namespace MMI { 24 class JoystickTransformProcessor final : public TransformProcessor { 25 enum LIBINPUT_BUTTON_CODE : uint32_t { 26 LIBINPUT_HOMEPAGE_BUTTON_CODE = 172, 27 LIBINPUT_TRIGGER_BUTTON_CODE = 288, 28 LIBINPUT_THUMB_BUTTON_CODE = 289, 29 LIBINPUT_THUMB2_BUTTON_CODE = 290, 30 LIBINPUT_TOP_BUTTON_CODE = 291, 31 LIBINPUT_TOP2_BUTTON_CODE = 292, 32 LIBINPUT_PINKIE_BUTTON_CODE = 293, 33 LIBINPUT_BASE_BUTTON_CODE = 294, 34 LIBINPUT_BASE2_BUTTON_CODE = 295, 35 LIBINPUT_BASE3_BUTTON_CODE = 296, 36 LIBINPUT_BASE4_BUTTON_CODE = 297, 37 LIBINPUT_BASE5_BUTTON_CODE = 298, 38 LIBINPUT_BASE6_BUTTON_CODE = 299, 39 LIBINPUT_DEAD_BUTTON_CODE = 303, 40 LIBINPUT_SOUTH_BUTTON_CODE = 304, 41 LIBINPUT_EAST_BUTTON_CODE = 305, 42 LIBINPUT_C_BUTTON_CODE = 306, 43 LIBINPUT_NORTH_BUTTON_CODE = 307, 44 LIBINPUT_WEST_BUTTON_CODE = 308, 45 LIBINPUT_Z_BUTTON_CODE = 309, 46 LIBINPUT_TL_BUTTON_CODE = 310, 47 LIBINPUT_TR_BUTTON_CODE = 311, 48 LIBINPUT_TL2_BUTTON_CODE = 312, 49 LIBINPUT_TR2_BUTTON_CODE = 313, 50 LIBINPUT_SELECT_BUTTON_CODE = 314, 51 LIBINPUT_START_BUTTON_CODE = 315, 52 LIBINPUT_MODE_BUTTON_CODE = 316, 53 LIBINPUT_THUMBL_BUTTON_CODE = 317, 54 LIBINPUT_THUMBR_BUTTON_CODE = 318 55 }; 56 const std::map<uint32_t, int32_t> LibinputChangeToPointer = { 57 { LIBINPUT_TL2_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_TL2 }, 58 { LIBINPUT_TR2_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_TR2 }, 59 { LIBINPUT_TL_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_TL }, 60 { LIBINPUT_TR_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_TR }, 61 { LIBINPUT_SOUTH_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_SOUTH }, 62 { LIBINPUT_NORTH_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_NORTH }, 63 { LIBINPUT_WEST_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_WEST }, 64 { LIBINPUT_EAST_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_EAST }, 65 { LIBINPUT_SELECT_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_SELECT }, 66 { LIBINPUT_HOMEPAGE_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_HOMEPAGE }, 67 { LIBINPUT_THUMBL_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_THUMBL }, 68 { LIBINPUT_THUMBR_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_THUMBR }, 69 { LIBINPUT_THUMB2_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_THUMB2 }, 70 { LIBINPUT_THUMB_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_THUMB }, 71 { LIBINPUT_TOP_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_TOP }, 72 { LIBINPUT_TOP2_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_TOP2 }, 73 { LIBINPUT_PINKIE_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_PINKIE }, 74 { LIBINPUT_BASE_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_BASE }, 75 { LIBINPUT_BASE2_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_BASE2 }, 76 { LIBINPUT_BASE3_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_BASE3 }, 77 { LIBINPUT_BASE4_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_BASE4 }, 78 { LIBINPUT_BASE5_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_BASE5 }, 79 { LIBINPUT_BASE6_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_BASE6 }, 80 { LIBINPUT_DEAD_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_DEAD }, 81 { LIBINPUT_C_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_C }, 82 { LIBINPUT_Z_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_Z }, 83 { LIBINPUT_MODE_BUTTON_CODE, PointerEvent::JOYSTICK_BUTTON_MODE } 84 }; 85 86 public: 87 explicit JoystickTransformProcessor(int32_t deviceId); 88 DISALLOW_COPY_AND_MOVE(JoystickTransformProcessor); 89 ~JoystickTransformProcessor() = default; 90 std::shared_ptr<PointerEvent> OnEvent(struct libinput_event *event) override; GetPointerEvent()91 std::shared_ptr<PointerEvent> GetPointerEvent() override { return nullptr; } 92 93 private: 94 bool OnEventJoystickButton(struct libinput_event* event); 95 bool OnEventJoystickAxis(struct libinput_event *event); 96 int32_t LibinputButtonToPointer(const uint32_t button); 97 private: 98 int32_t deviceId_ { 0 }; 99 std::shared_ptr<PointerEvent> pointerEvent_ { nullptr }; 100 std::vector<std::pair<enum libinput_joystick_axis_source, PointerEvent::AxisType>> joystickType; 101 }; 102 } // namespace MMI 103 } // namespace OHOS 104 #endif // JOYSTICK_TRANSFORM_POINT_PROCESSOR_H