evdev: Ignore key/button release events if key was never pressed
[platform/upstream/libinput.git] / src / evdev.h
1 /*
2  * Copyright © 2011, 2012 Intel Corporation
3  * Copyright © 2013 Jonas Ådahl
4  *
5  * Permission to use, copy, modify, distribute, and sell this software and
6  * its documentation for any purpose is hereby granted without fee, provided
7  * that the above copyright notice appear in all copies and that both that
8  * copyright notice and this permission notice appear in supporting
9  * documentation, and that the name of the copyright holders not be used in
10  * advertising or publicity pertaining to distribution of the software
11  * without specific, written prior permission.  The copyright holders make
12  * no representations about the suitability of this software for any
13  * purpose.  It is provided "as is" without express or implied warranty.
14  *
15  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
16  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
18  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
20  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22  */
23
24 #ifndef EVDEV_H
25 #define EVDEV_H
26
27 #include "config.h"
28
29 #include "linux/input.h"
30 #include <libevdev/libevdev.h>
31
32 #include "libinput-private.h"
33
34 enum evdev_event_type {
35         EVDEV_NONE,
36         EVDEV_ABSOLUTE_TOUCH_DOWN,
37         EVDEV_ABSOLUTE_MOTION,
38         EVDEV_ABSOLUTE_TOUCH_UP,
39         EVDEV_ABSOLUTE_MT_DOWN,
40         EVDEV_ABSOLUTE_MT_MOTION,
41         EVDEV_ABSOLUTE_MT_UP,
42         EVDEV_RELATIVE_MOTION,
43 };
44
45 enum evdev_device_seat_capability {
46         EVDEV_DEVICE_POINTER = (1 << 0),
47         EVDEV_DEVICE_KEYBOARD = (1 << 1),
48         EVDEV_DEVICE_TOUCH = (1 << 2)
49 };
50
51 struct mt_slot {
52         int32_t seat_slot;
53         int32_t x, y;
54 };
55
56 struct evdev_device {
57         struct libinput_device base;
58
59         struct libinput_source *source;
60
61         struct evdev_dispatch *dispatch;
62         struct libevdev *evdev;
63         char *output_name;
64         char *devnode;
65         char *sysname;
66         const char *devname;
67         int fd;
68         struct {
69                 const struct input_absinfo *absinfo_x, *absinfo_y;
70                 int fake_resolution;
71
72                 int32_t x, y;
73                 int32_t seat_slot;
74
75                 int apply_calibration;
76                 float calibration[6];
77         } abs;
78
79         struct {
80                 int slot;
81                 struct mt_slot *slots;
82                 size_t slots_len;
83         } mt;
84         struct mtdev *mtdev;
85
86         struct {
87                 int dx, dy;
88         } rel;
89
90         enum evdev_event_type pending_event;
91         enum evdev_device_seat_capability seat_caps;
92
93         int is_mt;
94
95         struct {
96                 struct motion_filter *filter;
97         } pointer;
98
99         /* Bitmask of pressed keys used to ignore initial release events from
100          * the kernel. */
101         unsigned long key_mask[NLONGS(KEY_CNT)];
102 };
103
104 #define EVDEV_UNHANDLED_DEVICE ((struct evdev_device *) 1)
105
106 struct evdev_dispatch;
107
108 struct evdev_dispatch_interface {
109         /* Process an evdev input event. */
110         void (*process)(struct evdev_dispatch *dispatch,
111                         struct evdev_device *device,
112                         struct input_event *event,
113                         uint64_t time);
114
115         /* Destroy an event dispatch handler and free all its resources. */
116         void (*destroy)(struct evdev_dispatch *dispatch);
117 };
118
119 struct evdev_dispatch {
120         struct evdev_dispatch_interface *interface;
121 };
122
123 struct evdev_device *
124 evdev_device_create(struct libinput_seat *seat,
125                     const char *devnode,
126                     const char *sysname);
127
128 struct evdev_dispatch *
129 evdev_touchpad_create(struct evdev_device *device);
130
131 struct evdev_dispatch *
132 evdev_mt_touchpad_create(struct evdev_device *device);
133
134 void
135 evdev_device_proces_event(struct libinput_event *event);
136
137 void
138 evdev_device_led_update(struct evdev_device *device, enum libinput_led leds);
139
140 int
141 evdev_device_get_keys(struct evdev_device *device, char *keys, size_t size);
142
143 const char *
144 evdev_device_get_output(struct evdev_device *device);
145
146 const char *
147 evdev_device_get_sysname(struct evdev_device *device);
148
149 const char *
150 evdev_device_get_name(struct evdev_device *device);
151
152 unsigned int
153 evdev_device_get_id_product(struct evdev_device *device);
154
155 unsigned int
156 evdev_device_get_id_vendor(struct evdev_device *device);
157
158 void
159 evdev_device_calibrate(struct evdev_device *device, float calibration[6]);
160
161 int
162 evdev_device_has_capability(struct evdev_device *device,
163                             enum libinput_device_capability capability);
164
165 int
166 evdev_device_get_size(struct evdev_device *device,
167                       double *w,
168                       double *h);
169
170 double
171 evdev_device_transform_x(struct evdev_device *device,
172                          double x,
173                          uint32_t width);
174
175 double
176 evdev_device_transform_y(struct evdev_device *device,
177                          double y,
178                          uint32_t height);
179
180 void
181 evdev_device_remove(struct evdev_device *device);
182
183 void
184 evdev_device_destroy(struct evdev_device *device);
185
186 static inline double
187 evdev_convert_to_mm(const struct input_absinfo *absinfo, double v)
188 {
189         double value = v - absinfo->minimum;
190         return value/absinfo->resolution;
191 }
192
193 #endif /* EVDEV_H */