touchpad: move structs into a header file
[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 touch_state {
35         TOUCH_NONE = 0,
36         TOUCH_BEGIN,
37         TOUCH_UPDATE,
38         TOUCH_END
39 };
40
41 struct tp_motion {
42         int32_t x;
43         int32_t y;
44 };
45
46 struct tp_touch {
47         enum touch_state state;
48         bool dirty;
49         int32_t x;
50         int32_t y;
51         uint32_t millis;
52
53         struct {
54                 struct tp_motion samples[TOUCHPAD_HISTORY_LENGTH];
55                 unsigned int index;
56                 unsigned int count;
57         } history;
58
59         struct {
60                 int32_t center_x;
61                 int32_t center_y;
62         } hysteresis;
63 };
64
65 struct tp_dispatch {
66         struct evdev_dispatch base;
67         struct evdev_device *device;
68         unsigned int nfingers_down;             /* number of fingers down */
69         unsigned int slot;                      /* current slot */
70
71         unsigned int ntouches;                  /* number of slots */
72         struct tp_touch *touches;               /* len == ntouches */
73
74         struct {
75                 int32_t margin_x;
76                 int32_t margin_y;
77         } hysteresis;
78
79         struct motion_filter *filter;
80
81         struct {
82                 double constant_factor;
83                 double min_factor;
84                 double max_factor;
85         } accel;
86 };
87
88 #define tp_for_each_touch(_tp, _t) \
89         for (unsigned int _i = 0; _i < (_tp)->ntouches && (_t = &(_tp)->touches[_i]); _i++)
90
91 #endif