1 /*
2  * Copyright (c) 2024 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 LIBINPUT_INTERFACE_H
17 #define LIBINPUT_INTERFACE_H
18 
19 #include <memory>
20 #include <string>
21 
22 #include "libinput.h"
23 
24 struct udev_device {
25     uint32_t tags;
26 };
27 
28 struct libinput_device {
29     struct udev_device udevDev;
30     unsigned int busType;
31     unsigned int version;
32     unsigned int product;
33     unsigned int vendor;
34     std::string name;
35 };
36 
37 struct libinput_event {
38     uint64_t time;
39     enum libinput_event_type type;
40     libinput_device dev;
41 };
42 
43 struct libinput_event_pointer {
44     struct libinput_event base;
45     enum libinput_button_state buttonState;
46 };
47 
48 struct libinput_event_keyboard {
49     struct libinput_event base;
50     uint32_t key;
51     enum libinput_key_state keyState;
52 };
53 
54 struct libinput_event_tablet_tool {
55     struct libinput_event base;
56     enum libinput_tablet_tool_tip_state tipState;
57 };
58 
59 struct libinput_tablet_tool {
60     struct libinput_event_tablet_tool base;
61     enum libinput_tablet_tool_type toolType;
62 };
63 
64 struct libinput_event_touch {
65     struct libinput_event base;
66     int32_t seatSlot;
67     int32_t longAxis;
68     int32_t shortAxis;
69     int32_t toolType;
70     double x;
71     double y;
72     double pressure;
73     double toolX;
74     double toolY;
75     double toolWidth;
76     double toolHeight;
77 };
78 
79 struct device_coords {
80     int32_t x;
81     int32_t y;
82 };
83 
84 constexpr uint32_t N_GESTURE_DEVICE_COORDS { 5 };
85 
86 struct libinput_event_gesture {
87     struct libinput_event base;
88     double scale;
89     double angle;
90     struct device_coords coords[N_GESTURE_DEVICE_COORDS];
91 };
92 
93 
94 namespace OHOS {
95 namespace MMI {
96 
97 class LibinputInterface {
98 public:
99     LibinputInterface();
100     virtual ~LibinputInterface() = default;
101 
102     virtual enum libinput_event_type GetEventType(struct libinput_event *event) = 0;
103     virtual struct libinput_device* GetDevice(struct libinput_event *event) = 0;
104     virtual uint64_t GetSensorTime(struct libinput_event *event) = 0;
105     virtual struct libinput_event_touch* GetTouchEvent(struct libinput_event *event) = 0;
106     virtual struct libinput_event_tablet_tool* GetTabletToolEvent(struct libinput_event *event) = 0;
107     virtual struct libinput_event_gesture* GetGestureEvent(struct libinput_event *event) = 0;
108     virtual struct libinput_tablet_tool* TabletToolGetTool(struct libinput_event_tablet_tool *event) = 0;
109     virtual enum libinput_tablet_tool_tip_state TabletToolGetTipState(struct libinput_event_tablet_tool *event) = 0;
110     virtual enum libinput_tablet_tool_type TabletToolGetType(struct libinput_tablet_tool *tool) = 0;
111     virtual enum libinput_pointer_axis_source GetAxisSource(struct libinput_event_pointer *event) = 0;
112     virtual struct libinput_event_pointer* LibinputGetPointerEvent(struct libinput_event *event) = 0;
113     virtual int32_t TabletToolGetToolType(struct libinput_event_tablet_tool *event) = 0;
114     virtual double TabletToolGetTiltX(struct libinput_event_tablet_tool *event) = 0;
115     virtual double TabletToolGetTiltY(struct libinput_event_tablet_tool *event) = 0;
116     virtual uint64_t TabletToolGetTimeUsec(struct libinput_event_tablet_tool *event) = 0;
117     virtual double TabletToolGetPressure(struct libinput_event_tablet_tool *event) = 0;
118     virtual uint64_t TouchEventGetTime(struct libinput_event_touch *event) = 0;
119     virtual int32_t TouchEventGetSeatSlot(struct libinput_event_touch *event) = 0;
120     virtual double TouchEventGetPressure(struct libinput_event_touch* event) = 0;
121     virtual int32_t TouchEventGetContactLongAxis(struct libinput_event_touch *event) = 0;
122     virtual int32_t TouchEventGetContactShortAxis(struct libinput_event_touch *event) = 0;
123     virtual int32_t TouchEventGetToolType(struct libinput_event_touch *event) = 0;
124     virtual int TouchEventGetBtnToolTypeDown(struct libinput_device *device, int32_t btnToolType) = 0;
125     virtual uint32_t GestureEventGetTime(struct libinput_event_gesture *event) = 0;
126     virtual int GestureEventGetFingerCount(struct libinput_event_gesture *event) = 0;
127     virtual int GestureEventGetDevCoordsX(struct libinput_event_gesture *event, uint32_t idx) = 0;
128     virtual int GestureEventGetDevCoordsY(struct libinput_event_gesture *event, uint32_t idx) = 0;
129     virtual uint32_t PointerEventGetFingerCount(struct libinput_event_pointer *event) = 0;
130     virtual double PointerGetDxUnaccelerated(struct libinput_event_pointer *event) = 0;
131     virtual double PointerGetDyUnaccelerated(struct libinput_event_pointer *event) = 0;
132     virtual uint32_t PointerGetButton(struct libinput_event_pointer *event) = 0;
133     virtual int PointerHasAxis(struct libinput_event_pointer *event, enum libinput_pointer_axis axis) = 0;
134     virtual double PointerGetAxisValue(struct libinput_event_pointer *event, enum libinput_pointer_axis axis) = 0;
135     virtual struct libinput_event_touch* GetTouchpadEvent(struct libinput_event *event) = 0;
136     virtual int32_t TouchpadGetTool(struct libinput_event_touch *event) = 0;
137     virtual char* DeviceGetName(struct libinput_device *device) = 0;
138     virtual struct libinput_event_keyboard* LibinputEventGetKeyboardEvent (struct libinput_event *event) = 0;
139     virtual uint32_t LibinputEventKeyboardGetKey (struct libinput_event_keyboard *event) = 0;
140     virtual enum libinput_key_state LibinputEventKeyboardGetKeyState (struct libinput_event_keyboard *event) = 0;
141 };
142 } // namespace MMI
143 } // namespace OHOS
144 #endif // LIBINPUT_INTERFACE_H