Fix two doxygen errors
[platform/upstream/libinput.git] / src / evdev-mt-touchpad.h
1 /*
2  * Copyright © 2014 Red Hat, Inc.
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and
5  * its documentation for any purpose is hereby granted without fee, provided
6  * that the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation, and that the name of the copyright holders not be used in
9  * advertising or publicity pertaining to distribution of the software
10  * without specific, written prior permission.  The copyright holders make
11  * no representations about the suitability of this software for any
12  * purpose.  It is provided "as is" without express or implied warranty.
13  *
14  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16  * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21  */
22
23
24 #ifndef EVDEV_MT_TOUCHPAD_H
25 #define EVDEV_MT_TOUCHPAD_H
26
27 #include <stdbool.h>
28
29 #include "evdev.h"
30 #include "filter.h"
31 #include "timer.h"
32
33 #define TOUCHPAD_HISTORY_LENGTH 4
34 #define TOUCHPAD_MIN_SAMPLES 4
35
36 enum touchpad_event {
37         TOUCHPAD_EVENT_NONE             = 0,
38         TOUCHPAD_EVENT_MOTION           = (1 << 0),
39         TOUCHPAD_EVENT_BUTTON_PRESS     = (1 << 1),
40         TOUCHPAD_EVENT_BUTTON_RELEASE   = (1 << 2),
41 };
42
43 enum touch_state {
44         TOUCH_NONE = 0,
45         TOUCH_BEGIN,
46         TOUCH_UPDATE,
47         TOUCH_END
48 };
49
50 enum button_event {
51         BUTTON_EVENT_IN_BOTTOM_R = 30,
52         BUTTON_EVENT_IN_BOTTOM_L,
53         BUTTON_EVENT_IN_TOP_R,
54         BUTTON_EVENT_IN_TOP_M,
55         BUTTON_EVENT_IN_TOP_L,
56         BUTTON_EVENT_IN_AREA,
57         BUTTON_EVENT_UP,
58         BUTTON_EVENT_PRESS,
59         BUTTON_EVENT_RELEASE,
60         BUTTON_EVENT_TIMEOUT,
61 };
62
63 enum button_state {
64         BUTTON_STATE_NONE,
65         BUTTON_STATE_AREA,
66         BUTTON_STATE_BOTTOM,
67         BUTTON_STATE_TOP,
68         BUTTON_STATE_TOP_NEW,
69         BUTTON_STATE_TOP_TO_IGNORE,
70         BUTTON_STATE_IGNORE,
71 };
72
73 enum tp_tap_state {
74         TAP_STATE_IDLE = 4,
75         TAP_STATE_TOUCH,
76         TAP_STATE_HOLD,
77         TAP_STATE_TAPPED,
78         TAP_STATE_TOUCH_2,
79         TAP_STATE_TOUCH_2_HOLD,
80         TAP_STATE_TOUCH_3,
81         TAP_STATE_TOUCH_3_HOLD,
82         TAP_STATE_DRAGGING_OR_DOUBLETAP,
83         TAP_STATE_DRAGGING,
84         TAP_STATE_DRAGGING_WAIT,
85         TAP_STATE_DRAGGING_2,
86         TAP_STATE_DEAD, /**< finger count exceeded */
87 };
88
89 enum tp_tap_touch_state {
90         TAP_TOUCH_STATE_IDLE = 16,      /**< not in touch */
91         TAP_TOUCH_STATE_TOUCH,          /**< touching, may tap */
92         TAP_TOUCH_STATE_DEAD,           /**< exceeded motion/timeout */
93 };
94
95 struct tp_motion {
96         int32_t x;
97         int32_t y;
98 };
99
100 struct tp_touch {
101         struct tp_dispatch *tp;
102         enum touch_state state;
103         bool dirty;
104         bool fake;                              /* a fake touch */
105         bool is_pointer;                        /* the pointer-controlling touch */
106         int32_t x;
107         int32_t y;
108         uint64_t millis;
109
110         struct {
111                 struct tp_motion samples[TOUCHPAD_HISTORY_LENGTH];
112                 unsigned int index;
113                 unsigned int count;
114         } history;
115
116         struct {
117                 int32_t center_x;
118                 int32_t center_y;
119         } hysteresis;
120
121         /* A pinned touchpoint is the one that pressed the physical button
122          * on a clickpad. After the release, it won't move until the center
123          * moves more than a threshold away from the original coordinates
124          */
125         struct {
126                 bool is_pinned;
127                 int32_t center_x;
128                 int32_t center_y;
129         } pinned;
130
131         /* Software-button state and timeout if applicable */
132         struct {
133                 enum button_state state;
134                 /* We use button_event here so we can use == on events */
135                 enum button_event curr;
136                 struct libinput_timer timer;
137         } button;
138
139         struct {
140                 enum tp_tap_touch_state state;
141         } tap;
142
143         struct {
144                 bool is_palm;
145                 int32_t x, y;  /* first coordinates if is_palm == true */
146                 uint32_t time; /* first timestamp if is_palm == true */
147         } palm;
148 };
149
150 struct tp_dispatch {
151         struct evdev_dispatch base;
152         struct evdev_device *device;
153         unsigned int nfingers_down;             /* number of fingers down */
154         unsigned int slot;                      /* current slot */
155         bool has_mt;
156
157         unsigned int ntouches;                  /* number of slots */
158         struct tp_touch *touches;               /* len == ntouches */
159         unsigned int fake_touches;              /* fake touch mask */
160
161         struct {
162                 int32_t margin_x;
163                 int32_t margin_y;
164         } hysteresis;
165
166         struct motion_filter *filter;
167
168         struct {
169                 double x_scale_coeff;
170                 double y_scale_coeff;
171         } accel;
172
173         struct {
174                 bool is_clickpad;               /* true for clickpads */
175                 bool has_topbuttons;
176                 bool use_clickfinger;           /* number of fingers decides button number */
177                 bool click_pending;
178                 uint32_t state;
179                 uint32_t old_state;
180                 uint32_t motion_dist;           /* for pinned touches */
181                 unsigned int active;            /* currently active button, for release event */
182
183                 /* Only used for clickpads. The software button areas are
184                  * always 2 horizontal stripes across the touchpad.
185                  * The buttons are split according to the edge settings.
186                  */
187                 struct {
188                         int32_t top_edge;
189                         int32_t rightbutton_left_edge;
190                 } bottom_area;
191
192                 struct {
193                         int32_t bottom_edge;
194                         int32_t rightbutton_left_edge;
195                         int32_t leftbutton_right_edge;
196                 } top_area;
197         } buttons;                              /* physical buttons */
198
199         struct {
200                 enum libinput_pointer_axis direction;
201         } scroll;
202
203         enum touchpad_event queued;
204
205         struct {
206                 struct libinput_device_config_tap config;
207                 bool enabled;
208                 struct libinput_timer timer;
209                 enum tp_tap_state state;
210         } tap;
211
212         struct {
213                 int32_t right_edge;
214                 int32_t left_edge;
215         } palm;
216 };
217
218 #define tp_for_each_touch(_tp, _t) \
219         for (unsigned int _i = 0; _i < (_tp)->ntouches && (_t = &(_tp)->touches[_i]); _i++)
220
221 void
222 tp_get_delta(struct tp_touch *t, double *dx, double *dy);
223
224 void
225 tp_set_pointer(struct tp_dispatch *tp, struct tp_touch *t);
226
227 int
228 tp_tap_handle_state(struct tp_dispatch *tp, uint64_t time);
229
230 int
231 tp_init_tap(struct tp_dispatch *tp);
232
233 void
234 tp_destroy_tap(struct tp_dispatch *tp);
235
236 int
237 tp_init_buttons(struct tp_dispatch *tp, struct evdev_device *device);
238
239 void
240 tp_destroy_buttons(struct tp_dispatch *tp);
241
242 int
243 tp_process_button(struct tp_dispatch *tp,
244                   const struct input_event *e,
245                   uint64_t time);
246
247 int
248 tp_post_button_events(struct tp_dispatch *tp, uint64_t time);
249
250 int
251 tp_button_handle_state(struct tp_dispatch *tp, uint64_t time);
252
253 int
254 tp_button_touch_active(struct tp_dispatch *tp, struct tp_touch *t);
255
256 bool
257 tp_button_is_inside_softbutton_area(struct tp_dispatch *tp, struct tp_touch *t);
258
259 #endif