1 /* 2 * Copyright (c) 2021-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 MOUSE_EVENT_NORMALIZE_H 17 #define MOUSE_EVENT_NORMALIZE_H 18 19 #include <memory> 20 21 #include "libinput.h" 22 #include "singleton.h" 23 24 #include "define_multimodal.h" 25 #include "mouse_transform_processor.h" 26 #include "pointer_event.h" 27 28 namespace OHOS { 29 namespace MMI { 30 class MouseEventNormalize final : public std::enable_shared_from_this<MouseEventNormalize> { 31 DECLARE_DELAYED_SINGLETON(MouseEventNormalize); 32 public: 33 DISALLOW_COPY_AND_MOVE(MouseEventNormalize); 34 std::shared_ptr<PointerEvent> GetPointerEvent(); 35 std::shared_ptr<PointerEvent> GetPointerEvent(int32_t deviceId); 36 int32_t OnEvent(struct libinput_event *event); 37 void Dump(int32_t fd, const std::vector<std::string> &args); 38 int32_t NormalizeRotateEvent(struct libinput_event *event, int32_t type, double angle); 39 bool CheckAndPackageAxisEvent(libinput_event* event); 40 #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING 41 bool NormalizeMoveMouse(int32_t offsetX, int32_t offsetY); 42 #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING 43 int32_t SetMouseScrollRows(int32_t rows); 44 int32_t GetMouseScrollRows() const; 45 int32_t SetMousePrimaryButton(int32_t primaryButton); 46 int32_t GetMousePrimaryButton() const; 47 int32_t SetPointerSpeed(int32_t speed); 48 int32_t GetPointerSpeed() const; 49 void OnDisplayLost(int32_t displayId); 50 int32_t GetDisplayId() const; 51 int32_t SetPointerLocation(int32_t x, int32_t y); 52 int32_t SetTouchpadScrollSwitch(bool switchFlag) const; 53 void GetTouchpadScrollSwitch(bool &switchFlag) const; 54 int32_t SetTouchpadScrollDirection(bool state) const; 55 void GetTouchpadScrollDirection(bool &state) const; 56 int32_t SetTouchpadTapSwitch(bool switchFlag) const; 57 void GetTouchpadTapSwitch(bool &switchFlag) const; 58 int32_t SetTouchpadRightClickType(int32_t type) const; 59 void GetTouchpadRightClickType(int32_t &type) const; 60 int32_t SetTouchpadPointerSpeed(int32_t speed) const; 61 void GetTouchpadPointerSpeed(int32_t &speed) const; 62 63 private: 64 std::shared_ptr<MouseTransformProcessor> GetProcessor(int32_t deviceId) const; 65 std::shared_ptr<MouseTransformProcessor> GetCurrentProcessor() const; 66 void SetCurrentDeviceId(int32_t deviceId); 67 int32_t GetCurrentDeviceId() const; 68 69 private: 70 int32_t buttonId_ { -1 }; 71 bool isPressed_ { false }; 72 std::map<int32_t, std::shared_ptr<MouseTransformProcessor>> processors_; 73 int32_t currentDeviceId_ { -1 }; 74 }; 75 #define MouseEventHdr ::OHOS::DelayedSingleton<MouseEventNormalize>::GetInstance() 76 } // namespace MMI 77 } // namespace OHOS 78 #endif // MOUSE_EVENT_NORMALIZE_H