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