touchpad: add support for multi-finger tapping
[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
32 #define TOUCHPAD_HISTORY_LENGTH 4
33
34 enum touchpad_event {
35         TOUCHPAD_EVENT_NONE             = 0,
36         TOUCHPAD_EVENT_MOTION           = (1 << 0),
37         TOUCHPAD_EVENT_BUTTON_PRESS     = (1 << 1),
38         TOUCHPAD_EVENT_BUTTON_RELEASE   = (1 << 2),
39 };
40
41 enum touch_state {
42         TOUCH_NONE = 0,
43         TOUCH_BEGIN,
44         TOUCH_UPDATE,
45         TOUCH_END
46 };
47
48 enum tp_tap_state {
49         TAP_STATE_IDLE = 4,
50         TAP_STATE_TOUCH,
51         TAP_STATE_HOLD,
52         TAP_STATE_TAPPED,
53         TAP_STATE_TOUCH_2,
54         TAP_STATE_TOUCH_2_HOLD,
55         TAP_STATE_TOUCH_3,
56         TAP_STATE_TOUCH_3_HOLD,
57         TAP_STATE_DRAGGING_OR_DOUBLETAP,
58         TAP_STATE_DRAGGING,
59         TAP_STATE_DRAGGING_WAIT,
60         TAP_STATE_DRAGGING_2,
61         TAP_STATE_DEAD, /**< finger count exceeded */
62 };
63
64 struct tp_motion {
65         int32_t x;
66         int32_t y;
67 };
68
69 struct tp_touch {
70         enum touch_state state;
71         bool dirty;
72         int32_t x;
73         int32_t y;
74         uint32_t millis;
75
76         struct {
77                 struct tp_motion samples[TOUCHPAD_HISTORY_LENGTH];
78                 unsigned int index;
79                 unsigned int count;
80         } history;
81
82         struct {
83                 int32_t center_x;
84                 int32_t center_y;
85         } hysteresis;
86 };
87
88 struct tp_dispatch {
89         struct evdev_dispatch base;
90         struct evdev_device *device;
91         unsigned int nfingers_down;             /* number of fingers down */
92         unsigned int slot;                      /* current slot */
93
94         unsigned int ntouches;                  /* number of slots */
95         struct tp_touch *touches;               /* len == ntouches */
96
97         struct {
98                 int32_t margin_x;
99                 int32_t margin_y;
100         } hysteresis;
101
102         struct motion_filter *filter;
103
104         struct {
105                 double constant_factor;
106                 double min_factor;
107                 double max_factor;
108         } accel;
109
110         struct {
111                 uint32_t state;
112                 uint32_t old_state;
113         } buttons;                              /* physical buttons */
114
115         enum touchpad_event queued;
116
117         struct {
118                 bool enabled;
119                 int timer_fd;
120                 struct libinput_source *source;
121                 unsigned int timeout;
122                 enum tp_tap_state state;
123         } tap;
124 };
125
126 #define tp_for_each_touch(_tp, _t) \
127         for (unsigned int _i = 0; _i < (_tp)->ntouches && (_t = &(_tp)->touches[_i]); _i++)
128
129 void
130 tp_get_delta(struct tp_touch *t, double *dx, double *dy);
131
132 int
133 tp_tap_handle_state(struct tp_dispatch *tp, uint32_t time);
134
135 unsigned int
136 tp_tap_handle_timeout(struct tp_dispatch *tp, uint32_t time);
137
138 int
139 tp_init_tap(struct tp_dispatch *tp);
140
141 #endif