evdev: Dynamically allocate slot array
[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                 int min_x, max_x, min_y, max_y;
70                 int32_t x, y;
71
72                 int32_t seat_slot;
73
74                 int apply_calibration;
75                 float calibration[6];
76         } abs;
77
78         struct {
79                 int slot;
80                 struct mt_slot *slots;
81                 size_t slots_len;
82         } mt;
83         struct mtdev *mtdev;
84
85         struct {
86                 li_fixed_t dx, dy;
87         } rel;
88
89         enum evdev_event_type pending_event;
90         enum evdev_device_seat_capability seat_caps;
91
92         int is_mt;
93 };
94
95 #define EVDEV_UNHANDLED_DEVICE ((struct evdev_device *) 1)
96
97 struct evdev_dispatch;
98
99 struct evdev_dispatch_interface {
100         /* Process an evdev input event. */
101         void (*process)(struct evdev_dispatch *dispatch,
102                         struct evdev_device *device,
103                         struct input_event *event,
104                         uint32_t time);
105
106         /* Destroy an event dispatch handler and free all its resources. */
107         void (*destroy)(struct evdev_dispatch *dispatch);
108 };
109
110 struct evdev_dispatch {
111         struct evdev_dispatch_interface *interface;
112 };
113
114 struct evdev_device *
115 evdev_device_create(struct libinput_seat *seat,
116                     const char *devnode,
117                     const char *sysname);
118
119 struct evdev_dispatch *
120 evdev_touchpad_create(struct evdev_device *device);
121
122 struct evdev_dispatch *
123 evdev_mt_touchpad_create(struct evdev_device *device);
124
125 void
126 evdev_device_proces_event(struct libinput_event *event);
127
128 void
129 evdev_device_led_update(struct evdev_device *device, enum libinput_led leds);
130
131 int
132 evdev_device_get_keys(struct evdev_device *device, char *keys, size_t size);
133
134 const char *
135 evdev_device_get_output(struct evdev_device *device);
136
137 const char *
138 evdev_device_get_sysname(struct evdev_device *device);
139
140 void
141 evdev_device_calibrate(struct evdev_device *device, float calibration[6]);
142
143 int
144 evdev_device_has_capability(struct evdev_device *device,
145                             enum libinput_device_capability capability);
146
147 li_fixed_t
148 evdev_device_transform_x(struct evdev_device *device,
149                          li_fixed_t x,
150                          uint32_t width);
151
152 li_fixed_t
153 evdev_device_transform_y(struct evdev_device *device,
154                          li_fixed_t y,
155                          uint32_t height);
156
157 void
158 evdev_device_remove(struct evdev_device *device);
159
160 void
161 evdev_device_destroy(struct evdev_device *device);
162
163 #endif /* EVDEV_H */