• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 MOUSE_TRANSFORM_PROCESSOR_H
17 #define MOUSE_TRANSFORM_PROCESSOR_H
18 
19 #include <map>
20 #include <memory>
21 
22 #include "libinput.h"
23 #include "singleton.h"
24 #include "define_multimodal.h"
25 
26 #include "pointer_event.h"
27 #include "window_info.h"
28 
29 namespace OHOS {
30 
31 extern "C" {
32     struct Offset {
33         double dx;
34         double dy;
35     };
36     int32_t HandleMotionAccelerate(const Offset* offset, bool mode, double* abs_x, double* abs_y, int32_t speed);
37 }
38 
39 namespace MMI {
40 struct AccelerateCurve {
41     std::vector<int32_t> speeds;
42     std::vector<double> slopes;
43     std::vector<double> diffNums;
44 };
45 class MouseTransformProcessor final : public std::enable_shared_from_this<MouseTransformProcessor> {
46 public:
47     enum class RightClickType {
48         TP_RIGHT_BUTTON = 1,
49         TP_LEFT_BUTTON = 2,
50         TP_TWO_FINGER_TAP = 3,
51     };
52 
53     enum class PointerDataSource {
54         MOUSE = 1,
55         TOUCHPAD = 2,
56     };
57 
58 public:
59     DISALLOW_COPY_AND_MOVE(MouseTransformProcessor);
60     explicit MouseTransformProcessor(int32_t deviceId);
61     ~MouseTransformProcessor() = default;
62     std::shared_ptr<PointerEvent> GetPointerEvent() const;
63     int32_t Normalize(struct libinput_event *event);
64     int32_t NormalizeRotateEvent(struct libinput_event *event, int32_t type, double angle);
65     void Dump(int32_t fd, const std::vector<std::string> &args);
66 #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING
67     bool NormalizeMoveMouse(int32_t offsetX, int32_t offsetY);
68 #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING
69 private:
70     int32_t HandleMotionInner(struct libinput_event_pointer* data, struct libinput_event *event);
71     int32_t HandleButtonInner(struct libinput_event_pointer* data, struct libinput_event *event);
72     int32_t HandleAxisInner(struct libinput_event_pointer* data);
73     int32_t HandleAxisBeginEndInner(struct libinput_event *event);
74     void HandleAxisPostInner(PointerEvent::PointerItem &pointerItem);
75     void HandlePostInner(struct libinput_event_pointer* data, PointerEvent::PointerItem &pointerItem);
76     void HandleTouchPadAxisState(libinput_pointer_axis_source source, int32_t& direction, bool& tpScrollSwitch);
77     void HandleTouchpadRightButton(struct libinput_event_pointer* data, const int32_t evenType, uint32_t &button);
78     void HandleTouchpadLeftButton(struct libinput_event_pointer* data, const int32_t evenType, uint32_t &button);
79     void HandleTouchpadTwoFingerButton(struct libinput_event_pointer* data, const int32_t evenType, uint32_t &button);
80     void TransTouchpadRightButton(struct libinput_event_pointer* data, const int32_t type, uint32_t &button);
81     void CalculateOffset(Direction direction, Offset &offset);
82 #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING
83     void HandleMotionMoveMouse(int32_t offsetX, int32_t offsetY);
84     void HandlePostMoveMouse(PointerEvent::PointerItem &pointerItem);
85 #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING
86     int32_t HandleButtonValueInner(struct libinput_event_pointer* data, uint32_t button, int32_t type);
87     void DumpInner();
88     void SetDxDyForDInput(PointerEvent::PointerItem& pointerItem, struct libinput_event_pointer* data);
89     int32_t GetTouchpadSpeed(void);
90     static int32_t PutConfigDataToDatabase(std::string &key, bool value);
91     static int32_t GetConfigDataFromDatabase(std::string &key, bool &value);
92     static int32_t PutConfigDataToDatabase(std::string &key, int32_t value);
93     static int32_t GetConfigDataFromDatabase(std::string &key, int32_t &value);
94 
95 public:
96     static void InitAbsolution();
97     static void OnDisplayLost(int32_t displayId);
98     static int32_t GetDisplayId();
99     static int32_t SetMousePrimaryButton(int32_t primaryButton);
100     static int32_t GetMousePrimaryButton();
101     static int32_t SetMouseScrollRows(int rows);
102     static int32_t GetMouseScrollRows();
103     static int32_t SetPointerSpeed(int32_t speed);
104     static int32_t GetPointerSpeed();
105     static int32_t SetPointerLocation(int32_t x, int32_t y);
106     static int32_t SetTouchpadScrollSwitch(bool switchFlag);
107     static int32_t GetTouchpadScrollSwitch(bool &switchFlag);
108     static int32_t SetTouchpadScrollDirection(bool state);
109     static int32_t GetTouchpadScrollDirection(bool &state);
110     static int32_t SetTouchpadTapSwitch(bool switchFlag);
111     static int32_t GetTouchpadTapSwitch(bool &switchFlag);
112     static int32_t SetTouchpadRightClickType(int32_t type);
113     static int32_t GetTouchpadRightClickType(int32_t &type);
114     static int32_t SetTouchpadPointerSpeed(int32_t speed);
115     static int32_t GetTouchpadPointerSpeed(int32_t &speed);
116 
117 private:
118     static double absolutionX_;
119     static double absolutionY_;
120     static int32_t currentDisplayId_;
121     static int32_t globalPointerSpeed_;
122 
123     std::shared_ptr<PointerEvent> pointerEvent_ { nullptr };
124     int32_t timerId_ { -1 };
125     int32_t buttonId_ { -1 };
126     bool isPressed_ { false };
127     int32_t deviceId_ { -1 };
128     bool isAxisBegin_ { false };
129 };
130 } // namespace MMI
131 } // namespace OHOS
132 #endif // MOUSE_TRANSFORM_PROCESSOR_H