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_DEVICE_STATE_H 17 #define MOUSE_DEVICE_STATE_H 18 19 #include <map> 20 21 #include "singleton.h" 22 23 #include "pointer_event.h" 24 #include "struct_multimodal.h" 25 26 namespace OHOS { 27 namespace MMI { 28 class MouseDeviceState final { 29 DECLARE_DELAYED_SINGLETON(MouseDeviceState); 30 public: 31 const int32_t mouseBtnMax = 8; 32 enum LIBINPUT_BUTTON_CODE { 33 LIBINPUT_LEFT_BUTTON_CODE = 272, 34 LIBINPUT_RIGHT_BUTTON_CODE, 35 LIBINPUT_MIDDLE_BUTTON_CODE, 36 LIBINPUT_SIDE_BUTTON_CODE, 37 LIBINPUT_EXTRA_BUTTON_CODE, 38 LIBINPUT_FORWARD_BUTTON_CODE, 39 LIBINPUT_BACK_BUTTON_CODE, 40 LIBINPUT_TASK_BUTTON_CODE 41 }; 42 struct MouseDeviceCoords { 43 int32_t physicalX { 0 }; 44 int32_t physicalY { 0 }; 45 }; 46 const std::map<uint32_t, int32_t> mapLibinputChangeToPointer = { 47 #ifndef OHOS_BUILD_ENABLE_WATCH 48 { LIBINPUT_LEFT_BUTTON_CODE, PointerEvent::MOUSE_BUTTON_LEFT }, 49 { LIBINPUT_RIGHT_BUTTON_CODE, PointerEvent::MOUSE_BUTTON_RIGHT }, 50 { LIBINPUT_MIDDLE_BUTTON_CODE, PointerEvent::MOUSE_BUTTON_MIDDLE }, 51 { LIBINPUT_SIDE_BUTTON_CODE, PointerEvent::MOUSE_BUTTON_SIDE }, 52 { LIBINPUT_EXTRA_BUTTON_CODE, PointerEvent::MOUSE_BUTTON_EXTRA }, 53 { LIBINPUT_FORWARD_BUTTON_CODE, PointerEvent::MOUSE_BUTTON_FORWARD }, 54 { LIBINPUT_BACK_BUTTON_CODE, PointerEvent::MOUSE_BUTTON_BACK }, 55 { LIBINPUT_TASK_BUTTON_CODE, PointerEvent::MOUSE_BUTTON_TASK }, 56 #endif // OHOS_BUILD_ENABLE_WATCH 57 }; 58 public: 59 DISALLOW_COPY_AND_MOVE(MouseDeviceState); 60 int32_t GetMouseCoordsX() const; 61 int32_t GetMouseCoordsY() const; 62 void SetMouseCoords(int32_t x, int32_t y); 63 bool IsLeftBtnPressed(); 64 void GetPressedButtons(std::vector<int32_t>& pressedButtons); 65 void MouseBtnStateCounts(uint32_t btnCode, const BUTTON_STATE btnState); 66 int32_t LibinputChangeToPointer(const uint32_t keyValue); 67 68 private: 69 void ChangeMouseState(const BUTTON_STATE btnState, int32_t& btnStateCount); 70 71 private: 72 MouseDeviceCoords mouseCoord_; 73 std::map<uint32_t, int32_t> mouseBtnState_; 74 }; 75 76 #define MouseState ::OHOS::DelayedSingleton<MouseDeviceState>::GetInstance() 77 } // namespace MMI 78 } // namespace OHOS 79 #endif // MOUSE_DEVICE_STATE_H