• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef MOUSE_DEVICE_STATE_H
16 #define MOUSE_DEVICE_STATE_H
17 
18 #include <map>
19 #include <mutex>
20 
21 #include "nocopyable.h"
22 #include "singleton.h"
23 
24 #include "pointer_event.h"
25 #include "struct_multimodal.h"
26 
27 namespace OHOS {
28 namespace MMI {
29 class MouseDeviceState final {
30     DECLARE_DELAYED_SINGLETON(MouseDeviceState);
31 public:
32     const int32_t mouseBtnMax = 8;
33     enum LIBINPUT_BUTTON_CODE {
34         LIBINPUT_LEFT_BUTTON_CODE = 272,
35         LIBINPUT_RIGHT_BUTTON_CODE,
36         LIBINPUT_MIDDLE_BUTTON_CODE,
37         LIBINPUT_SIDE_BUTTON_CODE,
38         LIBINPUT_EXTRA_BUTTON_CODE,
39         LIBINPUT_FORWARD_BUTTON_CODE,
40         LIBINPUT_BACK_BUTTON_CODE,
41         LIBINPUT_TASK_BUTTON_CODE
42     };
43     struct MouseDeviceCoords {
44         int32_t physicalX { 0 };
45         int32_t physicalY { 0 };
46     };
47     const std::map<uint32_t, int32_t> mapLibinputChangeToPointer = {
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     };
57 public:
58     DISALLOW_COPY_AND_MOVE(MouseDeviceState);
59     int32_t GetMouseCoordsX() const;
60     int32_t GetMouseCoordsY() const;
61     void SetMouseCoords(const int32_t x, const int32_t y);
62     bool IsLeftBtnPressed();
63     void GetPressedButtons(std::vector<int32_t>& pressedButtons);
64     std::map<uint32_t, int32_t> GetMouseBtnState() const;
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