evdev: add a internal device notification mechanism
[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         char *syspath;
67         const char *devname;
68         int fd;
69         struct {
70                 const struct input_absinfo *absinfo_x, *absinfo_y;
71                 int fake_resolution;
72
73                 int32_t x, y;
74                 int32_t seat_slot;
75
76                 int apply_calibration;
77                 struct matrix calibration;
78                 struct matrix default_calibration; /* from LIBINPUT_CALIBRATION_MATRIX */
79                 struct matrix usermatrix; /* as supplied by the caller */
80         } abs;
81
82         struct {
83                 int slot;
84                 struct mt_slot *slots;
85                 size_t slots_len;
86         } mt;
87         struct mtdev *mtdev;
88
89         struct {
90                 int dx, dy;
91         } rel;
92
93         enum evdev_event_type pending_event;
94         enum evdev_device_seat_capability seat_caps;
95
96         int is_mt;
97
98         struct {
99                 struct motion_filter *filter;
100         } pointer;
101
102         /* Bitmask of pressed keys used to ignore initial release events from
103          * the kernel. */
104         unsigned long hw_key_mask[NLONGS(KEY_CNT)];
105         /* Key counter used for multiplexing button events internally in
106          * libinput. */
107         uint8_t key_count[KEY_CNT];
108 };
109
110 #define EVDEV_UNHANDLED_DEVICE ((struct evdev_device *) 1)
111
112 struct evdev_dispatch;
113
114 struct evdev_dispatch_interface {
115         /* Process an evdev input event. */
116         void (*process)(struct evdev_dispatch *dispatch,
117                         struct evdev_device *device,
118                         struct input_event *event,
119                         uint64_t time);
120
121         /* Destroy an event dispatch handler and free all its resources. */
122         void (*destroy)(struct evdev_dispatch *dispatch);
123
124         /* A new device was added */
125         void (*device_added)(struct evdev_device *device,
126                              struct evdev_device *added_device);
127
128         /* A device was removed */
129         void (*device_removed)(struct evdev_device *device,
130                                struct evdev_device *removed_device);
131 };
132
133 struct evdev_dispatch {
134         struct evdev_dispatch_interface *interface;
135         struct libinput_device_config_calibration calibration;
136
137         struct {
138                 struct libinput_device_config_send_events config;
139                 enum libinput_config_send_events_mode current_mode;
140         } sendevents;
141 };
142
143 struct evdev_device *
144 evdev_device_create(struct libinput_seat *seat,
145                     const char *devnode,
146                     const char *sysname,
147                     const char *syspath);
148
149 struct evdev_dispatch *
150 evdev_touchpad_create(struct evdev_device *device);
151
152 struct evdev_dispatch *
153 evdev_mt_touchpad_create(struct evdev_device *device);
154
155 void
156 evdev_device_proces_event(struct libinput_event *event);
157
158 void
159 evdev_device_led_update(struct evdev_device *device, enum libinput_led leds);
160
161 int
162 evdev_device_get_keys(struct evdev_device *device, char *keys, size_t size);
163
164 const char *
165 evdev_device_get_output(struct evdev_device *device);
166
167 const char *
168 evdev_device_get_sysname(struct evdev_device *device);
169
170 const char *
171 evdev_device_get_name(struct evdev_device *device);
172
173 unsigned int
174 evdev_device_get_id_product(struct evdev_device *device);
175
176 unsigned int
177 evdev_device_get_id_vendor(struct evdev_device *device);
178
179 void
180 evdev_device_set_default_calibration(struct evdev_device *device,
181                                      const float calibration[6]);
182 void
183 evdev_device_calibrate(struct evdev_device *device,
184                        const float calibration[6]);
185
186 int
187 evdev_device_has_capability(struct evdev_device *device,
188                             enum libinput_device_capability capability);
189
190 int
191 evdev_device_get_size(struct evdev_device *device,
192                       double *w,
193                       double *h);
194
195 double
196 evdev_device_transform_x(struct evdev_device *device,
197                          double x,
198                          uint32_t width);
199
200 double
201 evdev_device_transform_y(struct evdev_device *device,
202                          double y,
203                          uint32_t height);
204 int
205 evdev_device_suspend(struct evdev_device *device);
206
207 int
208 evdev_device_resume(struct evdev_device *device);
209
210 void
211 evdev_keyboard_notify_key(struct evdev_device *device,
212                           uint32_t time,
213                           int key,
214                           enum libinput_key_state state);
215
216 void
217 evdev_pointer_notify_button(struct evdev_device *device,
218                             uint32_t time,
219                             int button,
220                             enum libinput_button_state state);
221
222 void
223 evdev_device_remove(struct evdev_device *device);
224
225 void
226 evdev_device_destroy(struct evdev_device *device);
227
228 static inline double
229 evdev_convert_to_mm(const struct input_absinfo *absinfo, double v)
230 {
231         double value = v - absinfo->minimum;
232         return value/absinfo->resolution;
233 }
234
235 #endif /* EVDEV_H */