Fix documentation for libinput_log_set_handler
[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 <stdbool.h>
30 #include "linux/input.h"
31 #include <libevdev/libevdev.h>
32
33 #include "libinput-private.h"
34 #include "timer.h"
35
36 enum evdev_event_type {
37         EVDEV_NONE,
38         EVDEV_ABSOLUTE_TOUCH_DOWN,
39         EVDEV_ABSOLUTE_MOTION,
40         EVDEV_ABSOLUTE_TOUCH_UP,
41         EVDEV_ABSOLUTE_MT_DOWN,
42         EVDEV_ABSOLUTE_MT_MOTION,
43         EVDEV_ABSOLUTE_MT_UP,
44         EVDEV_RELATIVE_MOTION,
45 };
46
47 enum evdev_device_seat_capability {
48         EVDEV_DEVICE_POINTER = (1 << 0),
49         EVDEV_DEVICE_KEYBOARD = (1 << 1),
50         EVDEV_DEVICE_TOUCH = (1 << 2)
51 };
52
53 enum evdev_device_tags {
54         EVDEV_TAG_EXTERNAL_MOUSE = (1 << 0),
55         EVDEV_TAG_INTERNAL_TOUCHPAD = (1 << 1),
56         EVDEV_TAG_TRACKPOINT = (1 << 2),
57 };
58
59 struct mt_slot {
60         int32_t seat_slot;
61         int32_t x, y;
62 };
63
64 struct evdev_device {
65         struct libinput_device base;
66
67         struct libinput_source *source;
68
69         struct evdev_dispatch *dispatch;
70         struct libevdev *evdev;
71         char *output_name;
72         char *devnode;
73         char *sysname;
74         char *syspath;
75         const char *devname;
76         int fd;
77         struct {
78                 const struct input_absinfo *absinfo_x, *absinfo_y;
79                 int fake_resolution;
80
81                 int32_t x, y;
82                 int32_t seat_slot;
83
84                 int apply_calibration;
85                 struct matrix calibration;
86                 struct matrix default_calibration; /* from LIBINPUT_CALIBRATION_MATRIX */
87                 struct matrix usermatrix; /* as supplied by the caller */
88         } abs;
89
90         struct {
91                 int slot;
92                 struct mt_slot *slots;
93                 size_t slots_len;
94         } mt;
95         struct mtdev *mtdev;
96
97         struct {
98                 int dx, dy;
99         } rel;
100
101         struct {
102                 struct libinput_timer timer;
103                 bool has_middle_button_scroll;
104                 bool middle_button_scroll_active;
105                 double threshold;
106                 uint32_t direction;
107         } scroll;
108
109         enum evdev_event_type pending_event;
110         enum evdev_device_seat_capability seat_caps;
111         enum evdev_device_tags tags;
112
113         int is_mt;
114         int suspended;
115
116         struct {
117                 struct libinput_device_config_accel config;
118                 struct motion_filter *filter;
119         } pointer;
120
121         /* Bitmask of pressed keys used to ignore initial release events from
122          * the kernel. */
123         unsigned long hw_key_mask[NLONGS(KEY_CNT)];
124         /* Key counter used for multiplexing button events internally in
125          * libinput. */
126         uint8_t key_count[KEY_CNT];
127
128         struct {
129                 struct libinput_device_config_left_handed config_left_handed;
130                 /* left-handed currently enabled */
131                 bool left_handed;
132                 /* set during device init if we want left_handed config,
133                  * used at runtime to delay the effect until buttons are up */
134                 bool want_left_handed;
135                 /* Checks if buttons are down and commits the setting */
136                 void (*change_to_left_handed)(struct evdev_device *device);
137         } buttons;
138
139         int dpi; /* HW resolution */
140         /* The number of times libevdev processes a SYN_DROPPED, so we can
141          * stop logging them to avoid flooding the logs. */
142         int syn_drops_received;
143 };
144
145 #define EVDEV_UNHANDLED_DEVICE ((struct evdev_device *) 1)
146
147 struct evdev_dispatch;
148
149 struct evdev_dispatch_interface {
150         /* Process an evdev input event. */
151         void (*process)(struct evdev_dispatch *dispatch,
152                         struct evdev_device *device,
153                         struct input_event *event,
154                         uint64_t time);
155
156         /* Destroy an event dispatch handler and free all its resources. */
157         void (*destroy)(struct evdev_dispatch *dispatch);
158
159         /* A new device was added */
160         void (*device_added)(struct evdev_device *device,
161                              struct evdev_device *added_device);
162
163         /* A device was removed */
164         void (*device_removed)(struct evdev_device *device,
165                                struct evdev_device *removed_device);
166
167         /* A device was suspended */
168         void (*device_suspended)(struct evdev_device *device,
169                                  struct evdev_device *suspended_device);
170
171         /* A device was resumed */
172         void (*device_resumed)(struct evdev_device *device,
173                                struct evdev_device *resumed_device);
174
175         /* Tag device with one of EVDEV_TAG */
176         void (*tag_device)(struct evdev_device *device,
177                            struct udev_device *udev_device);
178 };
179
180 struct evdev_dispatch {
181         struct evdev_dispatch_interface *interface;
182         struct libinput_device_config_calibration calibration;
183
184         struct {
185                 struct libinput_device_config_send_events config;
186                 enum libinput_config_send_events_mode current_mode;
187         } sendevents;
188 };
189
190 struct evdev_device *
191 evdev_device_create(struct libinput_seat *seat,
192                     const char *devnode,
193                     const char *sysname,
194                     const char *syspath);
195
196 int
197 evdev_device_init_pointer_acceleration(struct evdev_device *device);
198
199 struct evdev_dispatch *
200 evdev_touchpad_create(struct evdev_device *device);
201
202 struct evdev_dispatch *
203 evdev_mt_touchpad_create(struct evdev_device *device);
204
205 void
206 evdev_device_led_update(struct evdev_device *device, enum libinput_led leds);
207
208 int
209 evdev_device_get_keys(struct evdev_device *device, char *keys, size_t size);
210
211 const char *
212 evdev_device_get_output(struct evdev_device *device);
213
214 const char *
215 evdev_device_get_sysname(struct evdev_device *device);
216
217 const char *
218 evdev_device_get_name(struct evdev_device *device);
219
220 unsigned int
221 evdev_device_get_id_product(struct evdev_device *device);
222
223 unsigned int
224 evdev_device_get_id_vendor(struct evdev_device *device);
225
226 void
227 evdev_device_set_default_calibration(struct evdev_device *device,
228                                      const float calibration[6]);
229 void
230 evdev_device_calibrate(struct evdev_device *device,
231                        const float calibration[6]);
232
233 int
234 evdev_device_has_capability(struct evdev_device *device,
235                             enum libinput_device_capability capability);
236
237 int
238 evdev_device_get_size(struct evdev_device *device,
239                       double *w,
240                       double *h);
241
242 double
243 evdev_device_transform_x(struct evdev_device *device,
244                          double x,
245                          uint32_t width);
246
247 double
248 evdev_device_transform_y(struct evdev_device *device,
249                          double y,
250                          uint32_t height);
251 int
252 evdev_device_suspend(struct evdev_device *device);
253
254 int
255 evdev_device_resume(struct evdev_device *device);
256
257 void
258 evdev_notify_suspended_device(struct evdev_device *device);
259
260 void
261 evdev_notify_resumed_device(struct evdev_device *device);
262
263 void
264 evdev_keyboard_notify_key(struct evdev_device *device,
265                           uint32_t time,
266                           int key,
267                           enum libinput_key_state state);
268
269 void
270 evdev_pointer_notify_button(struct evdev_device *device,
271                             uint32_t time,
272                             int button,
273                             enum libinput_button_state state);
274
275 void
276 evdev_post_scroll(struct evdev_device *device,
277                   uint64_t time,
278                   double dx,
279                   double dy);
280
281
282 void
283 evdev_stop_scroll(struct evdev_device *device, uint64_t time);
284
285 void
286 evdev_device_remove(struct evdev_device *device);
287
288 void
289 evdev_device_destroy(struct evdev_device *device);
290
291 static inline double
292 evdev_convert_to_mm(const struct input_absinfo *absinfo, double v)
293 {
294         double value = v - absinfo->minimum;
295         return value/absinfo->resolution;
296 }
297
298 int
299 evdev_init_left_handed(struct evdev_device *device,
300                        void (*change_to_left_handed)(struct evdev_device *));
301
302 static inline uint32_t
303 evdev_to_left_handed(struct evdev_device *device,
304                      uint32_t button)
305 {
306         if (device->buttons.left_handed) {
307                 if (button == BTN_LEFT)
308                         return BTN_RIGHT;
309                 else if (button == BTN_RIGHT)
310                         return BTN_LEFT;
311         }
312         return button;
313 }
314
315 #endif /* EVDEV_H */