touchpad: add a struct for handling physical button event state changes
[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 struct tp_motion {
49         int32_t x;
50         int32_t y;
51 };
52
53 struct tp_touch {
54         enum touch_state state;
55         bool dirty;
56         int32_t x;
57         int32_t y;
58         uint32_t millis;
59
60         struct {
61                 struct tp_motion samples[TOUCHPAD_HISTORY_LENGTH];
62                 unsigned int index;
63                 unsigned int count;
64         } history;
65
66         struct {
67                 int32_t center_x;
68                 int32_t center_y;
69         } hysteresis;
70 };
71
72 struct tp_dispatch {
73         struct evdev_dispatch base;
74         struct evdev_device *device;
75         unsigned int nfingers_down;             /* number of fingers down */
76         unsigned int slot;                      /* current slot */
77
78         unsigned int ntouches;                  /* number of slots */
79         struct tp_touch *touches;               /* len == ntouches */
80
81         struct {
82                 int32_t margin_x;
83                 int32_t margin_y;
84         } hysteresis;
85
86         struct motion_filter *filter;
87
88         struct {
89                 double constant_factor;
90                 double min_factor;
91                 double max_factor;
92         } accel;
93
94         struct {
95                 uint32_t state;
96                 uint32_t old_state;
97         } buttons;                              /* physical buttons */
98
99         enum touchpad_event queued;
100 };
101
102 #define tp_for_each_touch(_tp, _t) \
103         for (unsigned int _i = 0; _i < (_tp)->ntouches && (_t = &(_tp)->touches[_i]); _i++)
104
105 #endif